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
435 *connection = new_connection; 435 *connection = new_connection;
436 return IDEVICE_E_SUCCESS; 436 return IDEVICE_E_SUCCESS;
437 } else if (device->conn_type == CONNECTION_NETWORK) { 437 } else if (device->conn_type == CONNECTION_NETWORK) {
438 unsigned char saddr_[32]; 438 struct sockaddr_storage saddr_storage;
439 memset(saddr_, '\0', sizeof(saddr_)); 439 struct sockaddr* saddr = (struct sockaddr*)&saddr_storage;
440 struct sockaddr* saddr = (struct sockaddr*)&saddr_[0]; 440
441 /* FIXME: Improve handling of this platform/host dependent connection data */
441 if (((char*)device->conn_data)[1] == 0x02) { // AF_INET 442 if (((char*)device->conn_data)[1] == 0x02) { // AF_INET
442 saddr->sa_family = AF_INET; 443 saddr->sa_family = AF_INET;
443 memcpy(&saddr->sa_data[0], (char*)device->conn_data+2, 14); 444 memcpy(&saddr->sa_data[0], (char*)device->conn_data + 2, 14);
444 } 445 }
445 else if (((char*)device->conn_data)[1] == 0x1E) { //AF_INET6 (bsd) 446 else if (((char*)device->conn_data)[1] == 0x1E) { // AF_INET6 (bsd)
446#ifdef AF_INET6 447#ifdef AF_INET6
447 saddr->sa_family = AF_INET6; 448 saddr->sa_family = AF_INET6;
448 memcpy(&saddr->sa_data[0], (char*)device->conn_data+2, 26); 449 /* copy just the address without the scope id as it might be from a different host */
450 memcpy(&saddr->sa_data[0], (char*)device->conn_data + 2, 22);
449#else 451#else
450 debug_info("ERROR: Got an IPv6 address but this system doesn't support IPv6"); 452 debug_info("ERROR: Got an IPv6 address but this system doesn't support IPv6");
451 return IDEVICE_E_UNKNOWN_ERROR; 453 return IDEVICE_E_UNKNOWN_ERROR;