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)
#ifdef AF_INET6
saddr->sa_family = AF_INET6;
/* copy the address and the host dependent scope id */
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");
CDATA_FREE(cdata);
return NULL;
#endif
}
While at first i thought it's odd that you hardcode 0x1E for AF_INET6 (bsd), i realized it may be due to compatibility reasons on original Apple usbmuxd on windows (as on linux either would work just fine).
....
After looking through more code it looks like libimobiledevice style is more sane (libimobiledevice-glue also assumes this structure).
So i recomment to change the libusmuxd code to match libimobiledevice and libimobiledevice-glue.
If 0x1E) { //AF_INET6 (bsd) is needed for compatibility reasons, i recommend to add a small compatibility layer inside libusbmuxd which converts that format into the system-standard format
In libusbmuxd tools the parsing code found here: https://github.com/libimobiledevice/libusbmuxd/blob/master/tools/iproxy.c#L132-L145 and here: https://github.com/libimobiledevice/libusbmuxd/blob/master/tools/inetcat.c#L219-L231 Looks like this:
While at first i thought it's odd that you hardcode
0x1E
forAF_INET6 (bsd)
, i realized it may be due to compatibility reasons on original Apple usbmuxd on windows (as on linux either would work just fine).But in libimobiledevice the same code is parsed differently, which is problematic! Looking here: https://github.com/libimobiledevice/libimobiledevice/blob/master/src/idevice.c#L333-L345 we find:
Note: even
sockaddr
is different between macOS and Linux..... After looking through more code it looks like libimobiledevice style is more sane (libimobiledevice-glue also assumes this structure). So i recomment to change the libusmuxd code to match libimobiledevice and libimobiledevice-glue.
If
0x1E) { //AF_INET6 (bsd)
is needed for compatibility reasons, i recommend to add a small compatibility layer inside libusbmuxd which converts that format into the system-standard format