I have a small c program which basically calls getaddrinfo. According to /etc/hosts localhost can be resolved to "127.0.0.1" and "::1".
Now when running the program the output depends on whether I compiled and linked using:
gcc -static test.c
$ a.out
127.0.0.1 2
gcc test.c
$ a.out
::1 10
127.0.0.1 2
I was checking which system calls have been done, and it seems that among other things the config file /etc/gai.conf was not used in the first case. However I wouldnt expect that gai.conf matters, because it is almost empty (except of a lot of comments.) And indeed if I remove the file, I am still able to correctly resolve (according to /etc/hosts) both ips with the dynmically linked program.
On the other hand does statically linking means in this case that even config files are evaluated at linking time ??
Question: Why the output of both program is different ?
test.c :
#include <netdb.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
struct addrinfo *result, *rp;
int s = getaddrinfo("localhost", "", NULL, &result);
char host[INET6_ADDRSTRLEN];
for (rp = result; rp != NULL ; rp = rp->ai_next) {
inet_ntop(rp->ai_family,
(rp->ai_family == AF_INET ?
&(((struct sockaddr_in*)rp->ai_addr)->sin_addr):
&(((struct sockaddr_in6*)rp->ai_addr)->sin6_addr)),
host, sizeof host);
printf("%s %d\n", host, rp->ai_family);
}
}