=== modified file 'TODO' --- TODO 2014-03-06 02:26:04 +0000 +++ TODO 2014-03-09 03:02:43 +0000 @@ -23,7 +23,6 @@ ** TODO [#B] Use capabilities instead of seteuid(). ** TODO [#B] Use struct sockaddr_storage instead of a union ** TODO [#B] Use getaddrinfo(hints=AI_NUMERICHOST) instead of inet_pton() -** TODO [#B] Use getnameinfo(serv=NULL, NI_NUMERICHOST) instead of inet_ntop() ** TODO [#B] Prefer /run/tmp over /tmp, if it exists ** TODO [#C] Make start_mandos_communication() take "struct server". === modified file 'plugins.d/mandos-client.c' --- plugins.d/mandos-client.c 2014-03-06 02:26:04 +0000 +++ plugins.d/mandos-client.c 2014-03-09 03:02:43 +0000 @@ -55,7 +55,8 @@ opendir(), DIR */ #include /* open(), S_ISREG */ #include /* socket(), struct sockaddr_in6, - inet_pton(), connect() */ + inet_pton(), connect(), + getnameinfo() */ #include /* open() */ #include /* opendir(), struct dirent, readdir() */ @@ -73,7 +74,7 @@ #include /* close(), SEEK_SET, off_t, write(), getuid(), getgid(), seteuid(), setgid(), pause(), _exit() */ -#include /* inet_pton(), htons, inet_ntop() */ +#include /* inet_pton(), htons() */ #include /* not, or, and */ #include /* struct argp_option, error_t, struct argp_state, struct argp, @@ -91,6 +92,8 @@ argz_delete(), argz_append(), argz_stringify(), argz_add(), argz_count() */ +#include /* getnameinfo(), NI_NUMERICHOST, + EAI_SYSTEM, gai_strerror() */ #ifdef __linux__ #include /* klogctl() */ @@ -783,20 +786,21 @@ } char addrstr[(INET_ADDRSTRLEN > INET6_ADDRSTRLEN) ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN] = ""; - const char *pcret; if(af == AF_INET6){ - pcret = inet_ntop(af, &(to.in6.sin6_addr), addrstr, - sizeof(addrstr)); + ret = getnameinfo((struct sockaddr *)&(to.in6), sizeof(to.in6), + addrstr, sizeof(addrstr), NULL, 0, + NI_NUMERICHOST); } else { - pcret = inet_ntop(af, &(to.in.sin_addr), addrstr, - sizeof(addrstr)); + ret = getnameinfo((struct sockaddr *)&(to.in), sizeof(to.in), + addrstr, sizeof(addrstr), NULL, 0, + NI_NUMERICHOST); } - if(pcret == NULL){ - perror_plus("inet_ntop"); - } else { - if(strcmp(addrstr, ip) != 0){ - fprintf_plus(stderr, "Canonical address form: %s\n", addrstr); - } + if(ret == EAI_SYSTEM){ + perror_plus("getnameinfo"); + } else if(ret != 0) { + fprintf_plus(stderr, "getnameinfo: %s", gai_strerror(ret)); + } else if(strcmp(addrstr, ip) != 0){ + fprintf_plus(stderr, "Canonical address form: %s\n", addrstr); } }