• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
getaddrinfo for "localhost" gives a strange IP-address
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getaddrinfo for "localhost" gives a strange IP-address


  • Subject: getaddrinfo for "localhost" gives a strange IP-address
  • From: Ville Mattila <email@hidden>
  • Date: Sun, 3 Jun 2007 20:52:52 +0300

Hello,

In my imac I've got this strange problem. Executing ruby's testsuite will take a very long time.
I've isolated the reason to resolving of "localhost" address. The ruby uses getaddrinfo.
At the end o fthis mailis a test code that show this strange behaviour.
Running it will give the following output


./test localhost
resolving name=localhost
family=30 sock_type=1 protocol=6 flags=0x0 canonname=(null)
ip=::1 serv=0
family=2 sock_type=1 protocol=6 flags=0x0 canonname=(null)
ip=173.19.2.144 serv=0
family=2 sock_type=1 protocol=6 flags=0x0 canonname=(null)
ip=127.0.0.1 serv=0.

Eg. the first localhost ip is "173.19.2.144". This IP is not configured in my mac. Here is the
ifconfig -a
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 00:17:f2:cd:43:55
media: autoselect status: inactive
supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full- duplex,hw-loopback> 1000baseT <full-duplex,flow-control> none
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
tunnel inet -->
inet 192.168.222.2 netmask 0xffffff00 broadcast 192.168.222.255
ether 00:19:e3:0c:b2:d4
media: autoselect status: active
supported media: autoselect
vlan: 0 parent interface: <none>
bond interfaces: <none>
wlt1: flags=41<UP,RUNNING> mtu 1500
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 2030
lladdr 00:16:cb:ff:fe:76:5c:12
media: autoselect <full-duplex> status: inactive
supported media: autoselect <full-duplex>
vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 172.16.47.1 netmask 0xffffff00 broadcast 172.16.47.255
ether 00:50:56:c0:00:08
vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 192.168.91.1 netmask 0xffffff00 broadcast 192.168.91.255
ether 00:50:56:c0:00:01
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
inet6 fe80::201:23ff:fe45:6789%en2 prefixlen 64 scopeid 0xa
inet 10.37.129.2 netmask 0xffffff00 broadcast 10.37.129.255
ether 00:01:23:45:67:89
media: autoselect status: active
supported media: autoselect
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
inet6 fe80::210:32ff:fe54:7698%en3 prefixlen 64 scopeid 0xb
inet 10.211.55.100 netmask 0xffffff00 broadcast 10.211.55.255
ether 00:10:32:54:76:98
media: autoselect status: active
supported media: autoselect



I've got both vmware fusion and parallels installed neither of them was not running when
I run the test program.


Here is the contests of /etc/hosts
cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost Iso-Imakki
255.255.255.255 broadcasthost
::1             localhost
#127.0.0.1 localhost localhost. localhost.local localhost.localdomain

And here is the ouput of "nidump hosts /"
::1     localhost
127.0.0.1       localhost
255.255.255.255 broadcasthost


Finally the test program code. --- cut -- #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <string.h> #include <stdio.h> static char rcsid[] = "$Header$"; int main(int argc, char *argv[]) { struct addrinfo hints, *res, *res0; int error; char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; char *name = "localhost";


memset(&hints, 0, sizeof(hints)); if (argc == 2) { name = argv[1]; } printf("resolving name=%s\n", name);

hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(name, NULL, &hints, &res0);
if (error) {
errx(1, "%s", gai_strerror(error));
/*NOTREACHED*/
}
for (res = res0; res; res = res->ai_next) {
printf("family=%d sock_type=%d protocol=%d flags=0x%x canonname=% s\n",
res->ai_family, res->ai_socktype,
res->ai_protocol, res->ai_flags, res->ai_canonname);
memset(hbuf, 0, sizeof(hbuf));
memset(sbuf, 0, sizeof(sbuf));
error =getnameinfo(res->ai_addr, res->ai_addr->sa_len, hbuf, sizeof(hbuf), sbuf,
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV/ * NI_NAMEREQD*/);
if (error) {
errx(1, "%s", gai_strerror(error));
}



printf("ip=%s serv=%s\n", hbuf, sbuf); } freeaddrinfo(res0); return (0); } --- cut --


- Ville

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: getaddrinfo for "localhost" gives a strange IP-address
      • From: email@hidden (Jun-ichiro itojun Hagino)
  • Prev by Date: NKE - Socket filter - get local address problem.
  • Next by Date: NKE - Socket filter - get local address problem.
  • Previous by thread: Re: NKE - Socket filter - get local address problem.
  • Next by thread: Re: getaddrinfo for "localhost" gives a strange IP-address
  • Index(es):
    • Date
    • Thread