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

Inconsistency between libusbmuxd and libimobiledevice in network structure parsing #134

Open
tihmstar opened this issue Nov 28, 2023 · 0 comments

Comments

@tihmstar
Copy link

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:

		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).

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:

			switch (saddr->sa_family) {
				case AF_INET:
					addrlen = sizeof(struct sockaddr_in);
					break;
#ifdef AF_INET6
				case AF_INET6:
					addrlen = sizeof(struct sockaddr_in6);
					break;
#endif
				default:
					debug_info("Unsupported address family 0x%02x\n", saddr->sa_family);
					continue;
			}

Note: even sockaddr is different between macOS and Linux.

struct sockaddr{ //macOS
   uint8_t sa_len;
   uint8_t sa_family;
   char sa_data[14];
};
struct sockaddr{ //linux
   uint16_t sa_family;
   char sa_data[14];
};

....
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

bitxeno added a commit to bitxeno/libimobiledevice that referenced this issue Sep 18, 2024
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

1 participant