Socket API mismatch between libimobiledevice and libusbmuxd
Important note: this error happens on 64-bit Windows with iTunes installed.
The code in libimobiledevice expects that libusbmuxd will provide conn_data for networked devices in the following format:
- byte 0: number of meaningful bytes in the 200-byte buffer ref
- byte 1: address family as provided by MacOS (0x02 or 0x1E) ref
- bytes from 2: 14 or 26 bytes containing address itself.
Now, if we peek into libusbmuxd code, it has different logic:
- take what
usbmuxdgave us in plist data forNetworkAddress; - put it into the buffer, unless it exceeds buffer size. ref
And looking ad the data provided by iTunes implementation of usbmuxd, it looks as follows (for IPv4 addresses):
02 00 00 00 // address family, 4 bytes, little endian
0c a8 00 8e // hex representation of 192.168.0.142 IP address
00 00 00 00 00 00 00 00 ... // zero-padding to reach 128 bytes in total
So we try to interpret first byte of address family (0x02) as data size, and second byte of address family (0x00) as address family value. This leads to Unsupported address family 0x00 error message, and makes it impossible to connect iDevices over network.
Possible solution:
- Change
libusbmuxdto include data size as a first byte; - Change
libimobiledeviceto look for IP address data at the right offset (5, not 2: skip 1 byte for length and 4 bytes for family).
Possible workaround is proposed in https://github.com/libimobiledevice/libusbmuxd/issues/95#issuecomment-714297655 - we can patch libusbmuxd to report Networked devices as if they are USB ones, forcing libimobiledevice to proxy connections to them via usbmuxd (as it was before 2c83cae88c50217f0fbbff5c3d2eab5f252f164e). I don't like this particular workaround implementation tough because it makes impossible to distinguish between networked and USB devices for client code.
https://github.com/libimobiledevice/libusbmuxd/pull/121
If there is a problem, you can force a USB connection, and the WIFI forwarding is handled by the driver.
I pushed commit a172604e5afaded8f0db1eb765be443984752400 which would just take the buffer that we get from libusbmuxd. It's the platform-dependent address that should just allow to connect.