GNOME Bugzilla – Bug 704704
AI_NUMERICSERV cannot be used with ai_socktype = 0
Last modified: 2013-07-24 14:46:50 UTC
On illumos (OpenSolaris) g_network_address_parse_sockaddr() returns FALSE after getaddrinfo() failure. Because "hints" only specifies ai_flags = AI_NUMERICHOST | AI_NUMERICSERV and ai_socktype = 0: https://git.gnome.org/browse/glib/tree/gio/gnetworkaddress.c#n250 From libsocket on illumos (ANY = 0): 396 if (aip->ai_socktype == ANY) { 397 if (aip->ai_flags & AI_NUMERICSERV) { 398 /* 399 * RFC 2553bis doesn't allow us to use the 400 * any resolver to find out if there is a 401 * match. We could walk the service file 402 * with *servent(). Given the commonality of 403 * calling getaddrinfo() with a number and 404 * ANY protocol we won't add that at this time. 405 */ 406 return (EAI_NONAME); 407 } This simple program works on linux (glibc), but does not on illumos: #include <netdb.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> int main () { struct sockaddr_in6 *sin6; struct addrinfo hints; struct addrinfo *result, *rp; memset (&hints, 0, sizeof (struct addrinfo)); hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; int s = getaddrinfo ("fe80::42%5", "99", &hints, &result); if (0 != s) { fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s)); return EXIT_FAILURE; } for (rp = result; rp != NULL; rp = rp->ai_next) { sin6 = (struct sockaddr_in6 *) rp->ai_addr; printf ("%d\n", sin6->sin6_scope_id); } return EXIT_SUCCESS; } On linux: # ./a.out 5 5 5 On illumos: $ ./a.out getaddrinfo: node name or service name not known
What about just setting hints.ai_socktype = SOCK_STREAM; ? This function seems to be used only to parse socket address, so ai_socktype does nto really matter.
yes. that should be fine. it works on solaris?
(In reply to comment #2) > it works on solaris? Can't check exactly glib, but only setting ai_socktype works.
Pretty sure that code in Solaris is just broken. But it's an easy workaround on our side. Fixed in master.