this should be okay.
itojun
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netdb.h>
int
main(argc, argv)
int argc;
char **argv;
{
char hbuf[NI_MAXHOST];
struct addrinfo hints, *res;
int error;
#ifdef NI_WITHSCOPEID /*KAME*/
const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
#else
const int niflags = NI_NUMERICHOST;
#endif
if (argc != 2) {
fprintf(stderr, "usage: foo addr\n");
exit(1);
}
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_INET6;
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
hints.ai_flags = AI_NUMERICHOST;
error = getaddrinfo(argv[1], "0", &hints, &res);
if (error) {
fprintf(stderr, "foo: getaddrinfo: %s\n", gai_strerror(error));
exit(1);
}
error = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
NULL, 0, niflags);
if (error) {
fprintf(stderr, "foo: getnameinfo: %s\n", gai_strerror(error));
exit(1);
}
printf("%s\n", hbuf);
exit(0);
}