From e4fb7014c416916f0c9d4f582ccc0da4b5a55e83 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 6 Jun 2020 02:27:05 +0200 Subject: idevice: Slightly improve connectivity logic and fix IPv6 for network devices This change removes copying the scope id for IPv6 connections which caused problems if the usbmux connection data is used on different hosts or context. --- src/idevice.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/idevice.c') diff --git a/src/idevice.c b/src/idevice.c index 74e9d77..1f8972f 100644 --- a/src/idevice.c +++ b/src/idevice.c @@ -435,17 +435,19 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t *connection = new_connection; return IDEVICE_E_SUCCESS; } else if (device->conn_type == CONNECTION_NETWORK) { - unsigned char saddr_[32]; - memset(saddr_, '\0', sizeof(saddr_)); - struct sockaddr* saddr = (struct sockaddr*)&saddr_[0]; + struct sockaddr_storage saddr_storage; + struct sockaddr* saddr = (struct sockaddr*)&saddr_storage; + + /* FIXME: Improve handling of this platform/host dependent connection data */ if (((char*)device->conn_data)[1] == 0x02) { // AF_INET saddr->sa_family = AF_INET; - memcpy(&saddr->sa_data[0], (char*)device->conn_data+2, 14); + memcpy(&saddr->sa_data[0], (char*)device->conn_data + 2, 14); } - else if (((char*)device->conn_data)[1] == 0x1E) { //AF_INET6 (bsd) + else if (((char*)device->conn_data)[1] == 0x1E) { // AF_INET6 (bsd) #ifdef AF_INET6 saddr->sa_family = AF_INET6; - memcpy(&saddr->sa_data[0], (char*)device->conn_data+2, 26); + /* copy just the address without the scope id as it might be from a different host */ + memcpy(&saddr->sa_data[0], (char*)device->conn_data + 2, 22); #else debug_info("ERROR: Got an IPv6 address but this system doesn't support IPv6"); return IDEVICE_E_UNKNOWN_ERROR; -- cgit v1.1-32-gdbae