Subject: Re: emacs server with X11 build on OSX

From: YAMAMOTO Mitsuharu <[email-masked]>
Date: Wed, 04 Aug 2010 09:52:23 +0900

>>>>> On Tue, 3 Aug 2010 15:03:08 +0200, Juanma Barranquero <[email-masked]> said:

> On Tue, Aug 3, 2010 at 15:01, Andreas Schwab <[email-masked]>
> wrote:
>> gethostbyname works quite different from getaddrinfo.

> Still a problem that (make-network-process ... :host 'local) fails.
> Something's obviously not right.

I suspect there is a bug in getaddrinfo on Mac OS X 10.6.4.  At least,
the behavior of the following program is incompatible with that on Mac
OS X 10.5.8.

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

main ()
{
  struct addrinfo hints, *res;
  char *servnames[] = {"0", "1", NULL};
  int error, i;

  memset (&hints, 0, sizeof (hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  for (i = 0; i < sizeof (servnames) / sizeof (servnames[0]); i++)
    {
      if (servnames[i])
	printf ("servname = \"%s\":\n", servnames[i]);
      else
	printf ("servname = (null):\n");
      error = getaddrinfo ("localhost", servnames[i], &hints, &res);
      if (error != 0)
	puts (gai_strerror (error));
      else
	{
	  struct addrinfo *r;

	  for (r = res; r; r = r->ai_next)
	    {
	      printf ("family = %d, socktype = %d, protocol = %d\n",
		      r->ai_family, r->ai_socktype, r->ai_protocol);
	    }
	  freeaddrinfo (res);
	}
      puts ("");
    }
}

*** Mac OS X 10.6.4 ***
servname = "0":
nodename nor servname provided, or not known

servname = "1":
family = 30, socktype = 1, protocol = 6
family = 30, socktype = 1, protocol = 6
family = 2, socktype = 1, protocol = 6

servname = (null):
family = 30, socktype = 1, protocol = 6
family = 30, socktype = 1, protocol = 6
family = 2, socktype = 1, protocol = 6

*** Mac OS X 10.5.8 ***
servname = "0":
family = 30, socktype = 1, protocol = 6
family = 30, socktype = 1, protocol = 6
family = 2, socktype = 1, protocol = 6

servname = "1":
family = 30, socktype = 1, protocol = 6
family = 30, socktype = 1, protocol = 6
family = 2, socktype = 1, protocol = 6

servname = (null):
family = 30, socktype = 1, protocol = 6
family = 30, socktype = 1, protocol = 6
family = 2, socktype = 1, protocol = 6

Actually, one can find a major rewrite in getaddrinfo's
implementation.  (Libinfo in
http://opensource.apple.com/release/mac-os-x-1064/ and
http://opensource.apple.com/release/mac-os-x-1058/ )

				     YAMAMOTO Mitsuharu
				[email-masked]