Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket API mismatch between libimobiledevice and libusbmuxd #1248

Open
MarSoft opened this issue Dec 6, 2021 · 4 comments
Open

Socket API mismatch between libimobiledevice and libusbmuxd #1248

MarSoft opened this issue Dec 6, 2021 · 4 comments

Comments

@MarSoft
Copy link
Contributor

MarSoft commented Dec 6, 2021

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 usbmuxd gave us in plist data for NetworkAddress;
  • 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:

  1. Change libusbmuxd to include data size as a first byte;
  2. Change libimobiledevice to 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 libimobiledevice/libusbmuxd#95 (comment) - 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 2c83cae). I don't like this particular workaround implementation tough because it makes impossible to distinguish between networked and USB devices for client code.

MarSoft added a commit to MarSoft/libimobiledevice that referenced this issue Dec 9, 2021
In sync with idevice_from_mux_device, line 384.
Without this fix, data size 128 (the common value) is treated as -128, resulting in incorrect allocation.
Related to libimobiledevice#1248 but doesn't fully fix it.
MarSoft added a commit to MarSoft/libimobiledevice that referenced this issue Dec 9, 2021
In sync with idevice_from_mux_device, line 384.
Without this fix, data size 128 (the common value) is treated as -128, resulting in incorrect allocation.
Related to libimobiledevice#1248 but doesn't fully fix it.
@AiXanadu
Copy link
Contributor

AiXanadu commented Jan 5, 2022

libimobiledevice/libusbmuxd#121

nikias pushed a commit that referenced this issue May 2, 2022
In sync with idevice_from_mux_device, line 384.
Without this fix, data size 128 (the common value) is treated as -128, resulting in incorrect allocation.
Related to #1248 but doesn't fully fix it.
@beni20
Copy link

beni20 commented May 11, 2023

libimobiledevice/libusbmuxd#121

Without it restore mode device was not detected in my case

@AiXanadu
Copy link
Contributor

If there is a problem, you can force a USB connection, and the WIFI forwarding is handled by the driver.

@nikias
Copy link
Member

nikias commented Jun 27, 2023

I pushed commit a172604 which would just take the buffer that we get from libusbmuxd. It's the platform-dependent address that should just allow to connect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants