diff options
-rw-r--r-- | include/libimobiledevice-glue/socket.h | 6 | ||||
-rw-r--r-- | src/socket.c | 21 |
2 files changed, 24 insertions, 3 deletions
diff --git a/include/libimobiledevice-glue/socket.h b/include/libimobiledevice-glue/socket.h index fac5df5..53f58b8 100644 --- a/include/libimobiledevice-glue/socket.h +++ b/include/libimobiledevice-glue/socket.h @@ -56,11 +56,11 @@ int socket_close(int fd); int socket_receive(int fd, void *data, size_t length); int socket_peek(int fd, void *data, size_t length); -int socket_receive_timeout(int fd, void *data, size_t length, int flags, - unsigned int timeout); - +int socket_receive_timeout(int fd, void *data, size_t length, int flags, unsigned int timeout); int socket_send(int fd, void *data, size_t length); +int socket_get_socket_port(int fd, uint16_t *port); + void socket_set_verbose(int level); const char *socket_addr_to_string(struct sockaddr *addr, char *addr_out, size_t addr_out_size); 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; +} |