Open pwn0rz opened 6 months ago
Oh... the reason for the changes was this: https://github.com/libimobiledevice/libimobiledevice-glue/issues/40
I guess I misunderstood (and subsequently failed to properly test) what NULL would mean for getaddrinfo, and assumed we'd get a single socket capable of listening to both IPv4 and IPv6, but I was wrong apparently... Now the break obviously prevents creating further sockets, and that makes perfect sense, since the function create_socket
returns a single socket and I don't see a way to change it. However, I can just change the code in iproxy to the old behavior, creating two listening sockets.
Ok I know how to fix this, but I am not sure if this is the best way to do it. In https://github.com/libimobiledevice/libimobiledevice-glue/blob/fde8946a3988790fd5d3f01fc0a1fd43609ab1d1/src/socket.c#L517
I am setting IPV6_V6ONLY
to 1. Setting this to NO would end up creating a single socket that would also be reachable with IPv4.
I tried this:
diff --git a/src/socket.c b/src/socket.c
index d4dedd1..3375e5b 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -463,6 +463,7 @@ int socket_create(const char* addr, uint16_t port)
{
int sfd = -1;
int yes = 1;
+ int no = 0;
struct addrinfo hints;
struct addrinfo *result, *rp;
char portstr[8];
@@ -514,7 +515,7 @@ int socket_create(const char* addr, uint16_t port)
#if defined(AF_INET6) && defined(IPV6_V6ONLY)
if (rp->ai_family == AF_INET6) {
- if (setsockopt(sfd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&yes, sizeof(int)) == -1) {
+ if (setsockopt(sfd, IPPROTO_IPV6, IPV6_V6ONLY, (addr) ? (void*)&yes : (void*)&no, sizeof(int)) == -1) {
perror("setsockopt() IPV6_V6ONLY");
}
}
And it will make it work. It would set IPV6_V6ONLY
to 0 only if addr
is NULL but 1 in any other case. Not sure if it would be needed in any other case?
That looks great 💯
This commit https://github.com/libimobiledevice/libusbmuxd/commit/303ece5fa462713552e0013b48b66a08955a12d4 uses
socket_create
to bind and listen address, however by default it seems to bind to IPv6 address only on my mac device.IPv4 loopback
IPv6 loopback
Default: IPv6 any
Env
According to the code at https://github.com/libimobiledevice/libimobiledevice-glue/blob/fde8946a3988790fd5d3f01fc0a1fd43609ab1d1/src/socket.c#L534
On my device, I will get 2 address which are
[::]:2222
and0.0.0.0:2222
by callinggetaddrinfo
, however due to thebreak
, the second address will not bebind
, which does not match the help (127.0.0.1) / commit (ipv4+ipv6) description.