summaryrefslogtreecommitdiffstats
path: root/src/socket.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2022-03-29 11:16:29 +0200
committerGravatar Nikias Bassen2022-03-29 11:16:29 +0200
commit5950ea6d4139394c38c7bdc445725d04113c1fee (patch)
treebcab66ea0f869a1041b9baa635f6e0ef32c3f362 /src/socket.c
parent78c121323158f5fa7fe6137d7a49f9cc58ab6f7d (diff)
downloadlibimobiledevice-glue-5950ea6d4139394c38c7bdc445725d04113c1fee.tar.gz
libimobiledevice-glue-5950ea6d4139394c38c7bdc445725d04113c1fee.tar.bz2
socket: Add socket_get_socket_port function
Diffstat (limited to 'src/socket.c')
-rw-r--r--src/socket.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/socket.c b/src/socket.c
index ad6135f..1029a71 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1233,3 +1233,24 @@ LIBIMOBILEDEVICE_GLUE_API int socket_send(int fd, void *data, size_t length)
#endif
return send(fd, data, length, flags);
}
+
+LIBIMOBILEDEVICE_GLUE_API int socket_get_socket_port(int fd, uint16_t *port)
+{
+#ifdef WIN32
+ int addr_len;
+#else
+ socklen_t addr_len;
+#endif
+ struct sockaddr_in addr;
+
+ memset(&addr, 0, sizeof(addr));
+
+ addr_len = sizeof(addr);
+ if (0 > getsockname(fd, (struct sockaddr*)&addr, &addr_len)) {
+ perror("getsockname()");
+ return -1;
+ }
+
+ *port = ntohs(addr.sin_port);
+ return 0;
+}