From cf4b806dff1003e56b8219367bbb29cb01c3f619 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 18 Nov 2026 00:32:05 +0100 Subject: Convert network device address in conn_data to native sockaddr layout usbmuxd reports the network address of a device as a BSD sockaddr ([sa_len][sa_family]...), even when it runs on a different OS than the client (e.g. macOS usbmuxd reached over TCP from Linux). libusbmuxd passed it through unchanged, so consumers casting conn_data to struct sockaddr (like libimobiledevice) got the wrong family on Linux and Windows. Convert the address when parsing it, so conn_data holds a native sockaddr for the platform the library runs on. On macOS nothing changes, on the other BSDs only the family value is adjusted. iproxy and inetcat now use conn_data directly and require this version of the library. The format is documented in usbmuxd.h. --- tools/inetcat.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'tools/inetcat.c') diff --git a/tools/inetcat.c b/tools/inetcat.c index 220a8a7..906b5c9 100644 --- a/tools/inetcat.c +++ b/tools/inetcat.c @@ -224,25 +224,16 @@ int main(int argc, char **argv) int devfd = -1; if (dev->conn_type == CONNECTION_TYPE_NETWORK) { - unsigned char saddr_[32]; - memset(saddr_, '\0', sizeof(saddr_)); - struct sockaddr* saddr = (struct sockaddr*)&saddr_[0]; - if (dev->conn_data[1] == 0x02) { // AF_INET - saddr->sa_family = AF_INET; - memcpy(&saddr->sa_data[0], (uint8_t*)dev->conn_data+2, 14); - } - else if (dev->conn_data[1] == 0x1E) { //AF_INET6 (bsd) + struct sockaddr_storage saddr_storage; + struct sockaddr* saddr = (struct sockaddr*)&saddr_storage; + /* conn_data holds the address in the native sockaddr layout */ + memcpy(saddr, dev->conn_data, sizeof(saddr_storage)); + if (saddr->sa_family != AF_INET #ifdef AF_INET6 - saddr->sa_family = AF_INET6; - memcpy(&saddr->sa_data[0], (uint8_t*)dev->conn_data+2, 26); -#else - fprintf(stderr, "ERROR: Got an IPv6 address but this system doesn't support IPv6\n"); - free(dev_list); - return 1; + && saddr->sa_family != AF_INET6 #endif - } - else { - fprintf(stderr, "Unsupported address family 0x%02x\n", dev->conn_data[1]); + ) { + fprintf(stderr, "Unsupported address family 0x%02x\n", saddr->sa_family); free(dev_list); return 1; } -- cgit v1.1-32-gdbae