[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#671789: libc6: getaddrinfo returns EAI_NONAME when only the loopback interface is up



Package: libc6
Version: 2.13-32
Severity: normal

When only the loopback interface is available, getaddrinfo incorrectly returns
EAI_NONAME when looking up localhost/127.0.0.1.
The following code snippet normally prints
0: Unknown error
0: Unknown error
when connected to the internet, but prints
-2: Name or service not known
-2: Name or service not known
when no non-loopback interface is available.


#include <netdb.h>
#include <string.h>
#include <stdio.h>

int main() {
	char* ip = "127.0.0.1";
	char* name = "localhost";

	struct addrinfo aiHint;
	memset(&aiHint, 0, sizeof(struct addrinfo));

	aiHint.ai_socktype = SOCK_STREAM;
	aiHint.ai_protocol = IPPROTO_TCP;
	aiHint.ai_family = AF_INET;
	aiHint.ai_flags = AI_ADDRCONFIG | AI_NUMERICHOST;

	struct addrinfo *aiRes = NULL;

	int nErr = getaddrinfo(ip, NULL, &aiHint, &aiRes);
	printf("%d: %s\n", nErr, gai_strerror(nErr));

	aiHint.ai_flags = AI_ADDRCONFIG;
	nErr = getaddrinfo(name, NULL, &aiHint, &aiRes);
	printf("%d: %s\n", nErr, gai_strerror(nErr));

	return 0;
}



-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (700, 'testing'), (600, 'testing'), (500, 'testing'), (400, 'unstable'), (300, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 3.2.0-2-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages libc6 depends on:
ii  libc-bin  2.13-32
ii  libgcc1   1:4.6.3-1

libc6 recommends no packages.

Versions of packages libc6 suggests:
ii  debconf [debconf-2.0]  1.5.41
ii  glibc-doc              <none>
ii  locales                2.13-27

-- debconf information:
  glibc/upgrade: true
  glibc/restart-services:
  libraries/restart-without-asking: false
  glibc/disable-screensaver:
  glibc/restart-failed:



Reply to: