/[svn]/hopm/trunk/src/scan.c
ViewVC logotype

Diff of /hopm/trunk/src/scan.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8106 by michael, Sat Dec 31 13:59:46 2016 UTC revision 8107 by michael, Sun Apr 2 16:01:08 2017 UTC
# Line 30  Line 30 
30  #include <errno.h>  #include <errno.h>
31  #include <fcntl.h>  #include <fcntl.h>
32  #include <sys/socket.h>  #include <sys/socket.h>
33    #include <netdb.h>
34  #include <netinet/in.h>  #include <netinet/in.h>
35  #include <arpa/inet.h>  #include <arpa/inet.h>
36    
# Line 849  scan_manual(char *param, const struct Ch Line 850  scan_manual(char *param, const struct Ch
850    const char *ip = NULL;    const char *ip = NULL;
851    char *scannername;    char *scannername;
852    node_t *node;    node_t *node;
853    int ret;    int ret, n;
854      struct sockaddr_storage storage;
855      socklen_t storage_len = 0;
856    
857    /* If there were no parameters sent, simply alert the user and return */    /* If there were no parameters sent, simply alert the user and return */
858    if (param == NULL)    if (param == NULL)
# Line 870  scan_manual(char *param, const struct Ch Line 873  scan_manual(char *param, const struct Ch
873      scannername++;      scannername++;
874    }    }
875    
876    /* If IP is a hostname, resolve it using gethostbyname (which will block!) */    memset(&storage, 0, sizeof(storage));
877    if ((addr = firedns_resolveip4(ip)) == NULL)  
878      if ((addr = firedns_resolveip6(ip)))
879      {
880        struct sockaddr_in6 *in = (struct sockaddr_in6 *)&storage;
881    
882        storage_len = sizeof(*in);
883        storage.ss_family = AF_INET6;
884        memcpy(&in->sin6_addr, addr, sizeof(in->sin6_addr));
885      }
886      else if ((addr = firedns_resolveip4(ip)))
887      {
888        struct sockaddr_in *in = (struct sockaddr_in *)&storage;
889    
890        storage_len = sizeof(*in);
891        storage.ss_family = AF_INET;
892        memcpy(&in->sin_addr, addr, sizeof(in->sin_addr));
893      }
894      else
895    {    {
896      irc_send("PRIVMSG %s :CHECK -> Error resolving host '%s': %s",      irc_send("PRIVMSG %s :CHECK -> Error resolving host '%s': %s",
897               target->name, ip, firedns_strerror(firedns_errno));               target->name, ip, firedns_strerror(firedns_errno));
898      return;      return;
899    }    }
900    
901    /* IP = the resolved IP now (it was the IP or hostname before) */    if ((n = getnameinfo((const struct sockaddr *)&storage, storage_len, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST)))
   if ((ip = inet_ntop(AF_INET, addr, buf, sizeof(buf))) == NULL)  
902    {    {
903      irc_send("PRIVMSG %s :CHECK -> invalid address: %s",      irc_send("PRIVMSG %s :CHECK -> invalid address: %s",
904               target->name, strerror(errno));               target->name, gai_strerror(n));
905      return;      return;
906    }    }
907    
908      ip = buf;
909    
910    ss = xcalloc(sizeof(*ss));    ss = xcalloc(sizeof(*ss));
911    ss->ip = xstrdup(ip);    ss->ip = xstrdup(ip);
912    ss->remote = opm_remote_create(ss->ip);    ss->remote = opm_remote_create(ss->ip);

Legend:
Removed from v.8106  
changed lines
  Added in v.8107

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28