summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;