getaddrinfo and AF_UNSPEC w/ IPv4/6 messes up ai_canonname?
Pekka Savola
pekkas@netcore.fi
Mon Aug 12 23:30:00 GMT 2002
Hello,
I noticed something strange when using getaddrinfo to get both IPv4 and
IPv6 addresses w/ AI_CANONNAME.
I wrote (or parsed together) a small, attached test program to demonstrate
this.
On Linux I get like:
pekkas: /home/pekkas$ ./test-canonname
host: ftp.kame.net, canon (if any): 3ffe:501:4819:2000:210:f3ff:fe03:4d0
pekkas: /home/pekkas$ ./test-canonname
host: ftp.kame.net, canon (if any): 2001:200:0:4819:210:f3ff:fe03:4d0
On e.g. FreeBSD I get like:
$ ./test-canonname
host: ftp.kame.net, canon (if any): kame220.kame.net
2001:200:0:4819:210:f3ff:fe03:4d0 or 3ffe:501:4819:2000:210:f3ff:fe03:4d
are _not_ canonical names, so it looks like a bug.
Thanks,
--
Pekka Savola "Tell me of difficulties surmounted,
Netcore Oy not those you stumble over and fall"
Systems. Networks. Security. -- Robert Jordan: A Crown of Swords
-------------- next part --------------
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <err.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
int main(void) {
int error;
struct addrinfo hints, *res0;
static char hostnamebuf[MAXHOSTNAMELEN];
char *port = "21";
char *host = "ftp.kame.net";
memset(&hints, 0, sizeof(hints));
memset(&res0, 0, sizeof(res0));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
error = getaddrinfo(host, port, &hints, &res0);
if (error) {
warnx("%s: %s", host, gai_strerror(error));
if (error == EAI_SYSTEM)
warnx("%s: %s", host, strerror(errno));
return (0);
}
if (res0->ai_canonname)
(void) strncpy(hostnamebuf, res0->ai_canonname,
sizeof(hostnamebuf));
printf("host: %s, canon (if any): %s\n", host, hostnamebuf);
return (0);
}
More information about the Libc-alpha
mailing list