0

The man page says:

The getaddrinfo(3) function is not limited to creating IPv4 socket address structures; IPv6 socket address structures can be created if IPv6 support is available. These socket address structures can be used directly by bind(2) or connect(2), to prepare a client or a server socket.

What should I do to force getaddrinfo to not create IPv6 socket address structures?

Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
Derui Si
  • 779
  • 5
  • 4

2 Answers2

1

Interestingly enough, the first question I ever asked on this site turned out to have an answer you might find useful.

To summarize, the file /etc/gai.conf is used by the getaddrinfo() system call to determine how to respond. For your particular case, adding

precedence ::ffff:0:0/96  100

to the end of the config file should be sufficient.

Shadur
  • 30,641
  • 11
  • 58
  • 69
  • Thanks for your answer, but in my CentOS 5.5 final, there is no /etc/gai.conf, do I need to create one? – Derui Si Aug 16 '12 at 09:55
  • Possibly. According to `dpkg` the file is part of the `libc-bin` package, which is pretty deep down the essential packages list in Debian... – Shadur Aug 16 '12 at 10:00
1

According to the manpage for getaddrinfo(), you can pass the address family in the hints parameter, so something like

struct addrinfo hints, *result;
int s;

memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;        /* or AF_INET6 for ipv6 addresses */
s = getaddrinfo(NULL, "ftp", &hints, &result);
...

I haven't tried this, but the approach seems to be right.

Flup
  • 8,017
  • 2
  • 33
  • 50