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
  • 93,103
  • 40
  • 240
  • 233
Derui Si
  • 799

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.

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,145