summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2020-06-06 02:27:05 +0200
committerGravatar Martin Szulecki2020-06-06 02:27:05 +0200
commite4fb7014c416916f0c9d4f582ccc0da4b5a55e83 (patch)
tree61f473ea4129d77e748a2e90d93db30c0713f40a /src
parent2abfb1eb26974a4a7d93c20525ec03941b168da7 (diff)
downloadlibimobiledevice-e4fb7014c416916f0c9d4f582ccc0da4b5a55e83.tar.gz
libimobiledevice-e4fb7014c416916f0c9d4f582ccc0da4b5a55e83.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/idevice.c14
1 files changed, 8 insertions, 6 deletions
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;