/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2014-03-09 03:02:43 UTC
  • Revision ID: teddy@recompile.se-20140309030243-0gc6l2yuqbzgyuyt
Use getnameinfo() instead of inet_ntop() in mandos-client.

* plugins.d/mandos-client.c (start_mandos_communication): Use
                                                          getnameinfo()
                                                          instead of
                                                          inet_ntop().

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
                                   opendir(), DIR */
56
56
#include <sys/stat.h>           /* open(), S_ISREG */
57
57
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
58
 
                                   inet_pton(), connect() */
 
58
                                   inet_pton(), connect(),
 
59
                                   getnameinfo() */
59
60
#include <fcntl.h>              /* open() */
60
61
#include <dirent.h>             /* opendir(), struct dirent, readdir()
61
62
                                 */
73
74
#include <unistd.h>             /* close(), SEEK_SET, off_t, write(),
74
75
                                   getuid(), getgid(), seteuid(),
75
76
                                   setgid(), pause(), _exit() */
76
 
#include <arpa/inet.h>          /* inet_pton(), htons, inet_ntop() */
 
77
#include <arpa/inet.h>          /* inet_pton(), htons() */
77
78
#include <iso646.h>             /* not, or, and */
78
79
#include <argp.h>               /* struct argp_option, error_t, struct
79
80
                                   argp_state, struct argp,
91
92
                                   argz_delete(), argz_append(),
92
93
                                   argz_stringify(), argz_add(),
93
94
                                   argz_count() */
 
95
#include <netdb.h>              /* getnameinfo(), NI_NUMERICHOST,
 
96
                                   EAI_SYSTEM, gai_strerror() */
94
97
 
95
98
#ifdef __linux__
96
99
#include <sys/klog.h>           /* klogctl() */
783
786
    }
784
787
    char addrstr[(INET_ADDRSTRLEN > INET6_ADDRSTRLEN) ?
785
788
                 INET_ADDRSTRLEN : INET6_ADDRSTRLEN] = "";
786
 
    const char *pcret;
787
789
    if(af == AF_INET6){
788
 
      pcret = inet_ntop(af, &(to.in6.sin6_addr), addrstr,
789
 
                        sizeof(addrstr));
 
790
      ret = getnameinfo((struct sockaddr *)&(to.in6), sizeof(to.in6),
 
791
                        addrstr, sizeof(addrstr), NULL, 0,
 
792
                        NI_NUMERICHOST);
790
793
    } else {
791
 
      pcret = inet_ntop(af, &(to.in.sin_addr), addrstr,
792
 
                        sizeof(addrstr));
 
794
      ret = getnameinfo((struct sockaddr *)&(to.in), sizeof(to.in),
 
795
                        addrstr, sizeof(addrstr), NULL, 0,
 
796
                        NI_NUMERICHOST);
793
797
    }
794
 
    if(pcret == NULL){
795
 
      perror_plus("inet_ntop");
796
 
    } else {
797
 
      if(strcmp(addrstr, ip) != 0){
798
 
        fprintf_plus(stderr, "Canonical address form: %s\n", addrstr);
799
 
      }
 
798
    if(ret == EAI_SYSTEM){
 
799
      perror_plus("getnameinfo");
 
800
    } else if(ret != 0) {
 
801
      fprintf_plus(stderr, "getnameinfo: %s", gai_strerror(ret));
 
802
    } else if(strcmp(addrstr, ip) != 0){
 
803
      fprintf_plus(stderr, "Canonical address form: %s\n", addrstr);
800
804
    }
801
805
  }
802
806