After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 704704 - AI_NUMERICSERV cannot be used with ai_socktype = 0
AI_NUMERICSERV cannot be used with ai_socktype = 0
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.36.x
Other opensolaris
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-07-22 19:49 UTC by Igor Pashev
Modified: 2013-07-24 14:46 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Igor Pashev 2013-07-22 19:49:57 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
Comment 1 Igor Pashev 2013-07-23 22:25:05 UTC
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.
Comment 2 Dan Winship 2013-07-24 11:38:39 UTC
yes. that should be fine. it works on solaris?
Comment 3 Igor Pashev 2013-07-24 11:42:26 UTC
(In reply to comment #2)
> it works on solaris?

Can't check exactly glib, but only setting ai_socktype works.
Comment 4 Dan Winship 2013-07-24 14:46:50 UTC
Pretty sure that code in Solaris is just broken. But it's an easy
workaround on our side. Fixed in master.