Skip to content

Commit 65f2036

Browse files
DCNick3fincs
authored andcommitted
Return the full length of sockaddr_in in getaddrinfo
1 parent 5ff34cd commit 65f2036

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

libctru/source/services/soc/soc_getaddrinfo.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ static struct addrinfo * buffer2addrinfo(addrinfo_3ds_t * entry)
5353

5454
memcpy(ai->ai_canonname, entry->ai_canonname, ai_canonname_len);
5555
memcpy(ai->ai_addr, &entry->ai_addr, ai->ai_addrlen);
56+
57+
// the sizes of hos-native sock_addr_in and the one we expose from libc are not the same
58+
// because the libc one has a `sin_zero` member for better compatibility with linux
59+
// it is located at the tail of the structure and will be zero-initilized due to use of `calloc` above
60+
// so it is fine that we did not `memcpy` anything into it above
61+
if(ai->ai_family == AF_INET)
62+
ai->ai_addrlen = sizeof(struct sockaddr_in);
63+
5664
ai->ai_addr->sa_family = ntohs(ai->ai_addr->sa_family) & 0xFF; // Clear sa_len to match the API
5765
}
5866
return ai;

0 commit comments

Comments
 (0)