- Continue to use inet_pton() until we add full ipv6 support, but at least
authormichael <michael@82007160-df01-0410-b94d-b575c5fd34c7>
Fri, 26 Dec 2014 20:53:09 +0000 (20:53 +0000)
committermichael <michael@82007160-df01-0410-b94d-b575c5fd34c7>
Fri, 26 Dec 2014 20:53:09 +0000 (20:53 +0000)
  replace all occurrences of inet_aton() with inet_pton()

git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/trunk@5170 82007160-df01-0410-b94d-b575c5fd34c7

src/compat.c
src/compat.h
src/dnsbl.c
src/firedns.c
src/irc.c
src/libopm/src/compat.c
src/libopm/src/compat.h
src/libopm/src/config.c
src/libopm/src/proxy.c
src/negcache.c
src/scan.c

index 3686f82ecdb4837b530661553ef19bd963adca32..c2bc98c831268a94b80d39a2845bbc8567ba6029 100644 (file)
@@ -27,42 +27,8 @@ along with this program; if not, write to the
 # include <string.h>
 #endif
 
-#ifndef HAVE_INET_ATON
-# include <netinet/in.h>
-#endif
-
 #include "compat.h"
 
-#ifndef HAVE_INET_ATON
-int bopm_inet_aton(const char *cp, struct in_addr *inp)
-{
-   unsigned int a1, a2, a3, a4;
-   unsigned long ret;
-
-   if (strcmp(cp, "255.255.255.255") == 0)
-   {
-      inp->s_addr = (unsigned) -1;
-      return 0;
-   }
-
-   if (sscanf(cp, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4 ||
-         a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255)
-   {
-      return 0;
-   }
-
-   ret = (a1 << 24) | (a2 << 16) | (a3 << 8) | a4;
-
-   inp->s_addr = htonl(ret);
-
-   if (inp->s_addr == (unsigned) -1)
-   {
-      return 0;
-   }
-   return 1;
-}
-#endif
-
 /*
  * strlcat and strlcpy were ripped from openssh 2.5.1p2
  * They had the following Copyright info:
index 799dabde521aa64edda2edb06ca141ff1827f011..e45947e04c766347e00006465cb9aa646467582b 100644 (file)
@@ -1,16 +1,6 @@
 #ifndef COMPAT_H
 #define COMPAT_H
 
-#ifndef INADDR_NONE
-#define INADDR_NONE 0xffffffff
-#endif
-
-#ifndef HAVE_INET_ATON
-#undef inet_aton
-#define inet_aton bopm_inet_aton
-extern int bopm_inet_aton(const char *cp, struct in_addr *inp);
-#endif
-
 #ifndef HAVE_STRLCPY
 extern size_t strlcpy(char *, const char *, size_t);
 #endif
index b66e590d28899413d495c5bcd4d6f6a3344c3782..a4b0cd102c134369c7d835f2f61e90c17513d3eb 100644 (file)
@@ -63,7 +63,7 @@ dnsbl_add(struct scan_struct *ss)
   struct dnsbl_scan *ds;
 
 
-  if (!inet_aton(ss->ip, &in))
+  if (inet_pton(AF_INET, ss->ip, &in) <= 0)
   {
     log_printf("DNSBL -> Invalid address '%s', ignoring.", ss->ip);
     return;
index 620516ec08c7101b00bc015d2588a6d517fb015e..a239b9498b13a7218c18e504ca399e6fbc699307 100644 (file)
@@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include <time.h>
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <netdb.h>
 #include <sys/poll.h>
 #include <sys/time.h>
 #include <netinet/in.h>
@@ -205,7 +204,7 @@ void firedns_init(void)
             /* glibc /etc/resolv.conf seems to allow ipv6 server names */
             if (i6 < FDNS_MAX)
             {
-               if (inet_pton6(&buf[i], (char *)&addr6) != NULL)
+               if (inet_pton(AF_INET6, &buf[i], &addr6) > 0)
                {
                   memcpy(&servers6[i6++],&addr6,sizeof(struct in6_addr));
                   continue;
@@ -214,18 +213,8 @@ void firedns_init(void)
 #endif
             if (i4 < FDNS_MAX)
             {
-              struct addrinfo hints, *res;
-
-              memset(&hints, 0, sizeof(hints));
-              hints.ai_family   = AF_INET;
-              hints.ai_socktype = SOCK_STREAM;
-              hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
-
-              if (!getaddrinfo(&buf[i], NULL, &hints, &res))
-              {
-                memcpy(&servers4[i4++], &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr));
-                freeaddrinfo(res);
-              }
+              if (inet_pton(AF_INET, &buf[i], &addr4) > 0)
+                memcpy(&servers4[i4++],&addr4,sizeof(struct in_addr));
            }
          }
       }
@@ -239,7 +228,7 @@ void firedns_init(void)
 #ifdef IPV6
          if (i6 < FDNS_MAX)
          {
-            if (inet_pton(AF_INET6, buf, (char *)&addr6))
+            if (inet_pton(AF_INET6, buf, &addr6) > 0)
             {
                memcpy(&servers6[i6++], &addr6, sizeof(struct in6_addr));
                continue;
@@ -248,18 +237,8 @@ void firedns_init(void)
 #endif
          if (i4 < FDNS_MAX)
          {
-              struct addrinfo hints, *res;
-
-              memset(&hints, 0, sizeof(hints));
-              hints.ai_family   = AF_INET;
-              hints.ai_socktype = SOCK_STREAM;
-              hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
-
-              if (!getaddrinfo(&buf[i], NULL, &hints, &res))
-              {
-                memcpy(&servers4[i4++], &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr));
-                freeaddrinfo(res);
-              }
+              if (inet_pton(AF_INET, buf, &addr4) > 0)
+                memcpy(&servers4[i4++],&addr4,sizeof(struct in_addr));
          }
       }
    }
@@ -280,7 +259,7 @@ struct in_addr *firedns_resolveip4(const char * const name)
 { /* immediate A query */
    static struct in_addr addr;
 
-   if(inet_aton(name, &addr))
+   if (inet_pton(AF_INET, name, &addr) > 0)
       return &addr;
    
    return (struct in_addr *) firedns_resolveip(FDNS_QRY_A, name);
index f91b65079c5ac1aa96a0c85b65e0058d441786b9..f3065d96ab6c864056593178d3d95129ddde0a6d 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -39,7 +39,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <netdb.h>
 
 #ifdef TIME_WITH_SYS_TIME
 # include <sys/time.h>
@@ -259,23 +258,14 @@ irc_init(void)
   /* Bind */
   if (!EmptyString(IRCItem->vhost))
   {
-    struct addrinfo hints, *res;
     int bindret = 0;
 
-    memset(&hints, 0, sizeof(hints));
-    hints.ai_family   = AF_INET;
-    hints.ai_socktype = SOCK_STREAM;
-    hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
-
-    if (getaddrinfo(IRCItem->vhost, NULL, &hints, &res))
+    if (inet_pton(AF_INET, IRCItem->vhost, &(IRC_LOCAL.in4.s_addr)) <= 0)
     {
       log_printf("IRC -> bind(): %s is an invalid address", IRCItem->vhost);
       exit(EXIT_FAILURE);
     }
 
-    memcpy(&IRC_LOCAL.in4.s_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr));
-    freeaddrinfo(res);
-
     bsaddr.sa4.sin_addr.s_addr = IRC_LOCAL.in4.s_addr;
     bsaddr.sa4.sin_family = AF_INET;
     bsaddr.sa4.sin_port = htons(0);
index 681bb154e61824b329b2d8e53af24c776bef116e..a4333698b502621f3be1b2c7c94088da1a02fa76 100644 (file)
 # include <string.h>
 #endif
 
-#ifndef HAVE_INET_ATON
-# include <netinet/in.h>
-#endif
-
 #include "compat.h"
 #include "opm.h"
-
-
-#ifndef HAVE_INET_ATON
-/*
- * An implementation of inet_aton for those systems that don't have it
- * (Solaris, ...)
- */
-int libopm_inet_aton(const char *cp, struct in_addr *inp)
-{
-       unsigned int a1, a2, a3, a4;
-       unsigned long ret;
-
-       if (strcmp(cp, "255.255.255.255") == 0) {
-               inp->s_addr = (unsigned) -1;
-               return 0;
-       }
-
-       if (sscanf(cp, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4 ||
-           a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255) {
-               return 0;
-       }
-
-       ret = (a1 << 24) | (a2 << 16) | (a3 << 8) | a4;
-
-       inp->s_addr = htonl(ret);
-       
-       if (inp->s_addr == (unsigned) -1) {
-               return 0;
-       }
-       return 1;
-}
-#endif
index 95bd4b75dcc9eabeab00a0a7884b19ee31f6997b..d7de8add9fe3fa7920a242e49fe9bcdf5ce1271a 100644 (file)
@@ -1,13 +1,4 @@
 #ifndef COMPAT_H
 #define COMPAT_H
 
-#ifndef INADDR_NONE
-#define INADDR_NONE 0xffffffff
-#endif
-
-#ifndef HAVE_INET_ATON
-#undef inet_aton
-#define inet_aton libopm_inet_aton
-extern int libopm_inet_aton(const char *cp, struct in_addr *inp);
-#endif
 #endif
index f68c3e852beaa57003e2434973e38ed6a0260404..12f3fa88a113aab9357a476b4f21f994f4439719 100644 (file)
@@ -195,21 +195,10 @@ OPM_ERR_T libopm_config_set(OPM_CONFIG_T *config, int key, const void *value)
          break;
 
       case OPM_TYPE_ADDRESS:
-      {
-        struct addrinfo hints, *res;
-
-        memset(&hints, 0, sizeof(hints));
-        hints.ai_family   = AF_INET;
-        hints.ai_socktype = SOCK_STREAM;
-        hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
-
-        if (getaddrinfo(value, NULL, &hints, &res))
+        if (inet_pton(AF_INET, value, &(((opm_sockaddr *)config->vars[key])->sa4.sin_addr)) <= 0)
           return OPM_ERR_BADVALUE;  /* return appropriate err code */
 
-        memcpy(&(((opm_sockaddr *)config->vars[key])->sa4.sin_addr), &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr));
-        freeaddrinfo(res);
         break; 
-      }
 
       case OPM_TYPE_STRINGLIST:
          node = libopm_node_create(libopm_xstrdup(value));
index 2078915e1185e1b7e7db22d7bfe5ce4a8e6a0af4..0d3464503298741d5fd57bbf71cbe83253cd36ff 100644 (file)
@@ -75,7 +75,7 @@ int libopm_proxy_socks4_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T
    scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
    scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
 
-   if (inet_aton(scan_ip, &addr) == 0)   
+   if (inet_pton(AF_INET, scan_ip, &addr) <= 0)
       ; /* handle error */ 
 
    laddr = htonl(addr.s_addr);
@@ -142,7 +142,7 @@ int libopm_proxy_socks5_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T
    scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
    scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
 
-   if (inet_aton(scan_ip, &addr) == 0)   
+   if (inet_pton(AF_INET, scan_ip, &addr) <= 0)
       ; /* handle error */ 
 
    laddr = htonl(addr.s_addr);
index 833580743f3f9f87291855de874ad8215d47fd0c..8ce19c10a971ac35eb28141057980657ccbef39b 100644 (file)
@@ -45,7 +45,6 @@ along with this program; if not, write to:
 #ifdef STDC_HEADERS
 #include <stdlib.h>
 #endif
-#include <string.h>
 
 #ifdef TIME_WITH_SYS_TIME
 #include <sys/time.h>
@@ -58,10 +57,6 @@ along with this program; if not, write to:
 # endif
 #endif
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
 #include "inet.h"
 #include "irc.h"
 #include "negcache.h"
@@ -215,22 +210,13 @@ void negcache_insert(const char *ipstr)
 {
    struct bopm_sockaddr ip;
    struct cnode *n;
-   struct addrinfo hints, *res;
-
-   memset(&hints, 0, sizeof(hints));
-   hints.ai_family   = AF_INET;
-   hints.ai_socktype = SOCK_STREAM;
-   hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
 
-   if (getaddrinfo(ipstr, NULL, &hints, &res))
+   if (!inet_pton(AF_INET, ipstr, &(ip.sa4.sin_addr)))
    {
       log_printf("NEGCACHE -> Invalid IPv4 address '%s'", ipstr);
       return;
    }
 
-   memcpy(&ip.sa4.sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr));
-   freeaddrinfo(res);
-
    n = nc_insert(nc_head, ip.sa4.sin_addr.s_addr);
 
    if (n)
index 701c005ffa9ea540f4ff9883912037cabd279fd3..dc8c534bda0006eac5098c6119ddbf61281252a7 100644 (file)
 #include <errno.h>
 #include <fcntl.h>
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
 #ifdef HAVE_SYS_POLL_H
 # include <sys/poll.h>
 #endif
@@ -345,23 +341,13 @@ scan_connect(char **user, char *msg)
   /* Check negcache before anything */
   if (OptionsItem->negcache > 0)
   {
-    struct addrinfo hints, *res;
-
-    memset(&hints, 0, sizeof(hints));
-    hints.ai_family   = AF_INET;
-    hints.ai_socktype = SOCK_STREAM;
-    hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
-
-      if (getaddrinfo(user[3], NULL, &hints, &res))
+      if (inet_pton(AF_INET, user[3], &(ip.sa4.sin_addr)) <= 0)
       {
          log_printf("SCAN -> Invalid IPv4 address '%s'!", user[3]);
          return;
       }
       else
       {
-         memcpy(&ip.sa4.sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr));
-         freeaddrinfo(res);
-
          if (check_neg_cache(ip.sa4.sin_addr.s_addr))
          {
             if (OPT_DEBUG)