- Replaced all occurrences of inet_pton() with getaddrinfo()
authormichael <michael@82007160-df01-0410-b94d-b575c5fd34c7>
Fri, 26 Dec 2014 18:53:10 +0000 (18:53 +0000)
committermichael <michael@82007160-df01-0410-b94d-b575c5fd34c7>
Fri, 26 Dec 2014 18:53:10 +0000 (18:53 +0000)
git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/branches/1.0.x@5165 82007160-df01-0410-b94d-b575c5fd34c7

src/firedns.c
src/irc.c
src/libopm/src/config.c
src/negcache.c
src/scan.c

index 880f2d74043d15756b3d5018c1fc8be1cf829aec..620516ec08c7101b00bc015d2588a6d517fb015e 100644 (file)
@@ -26,6 +26,7 @@ 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>
@@ -213,11 +214,19 @@ void firedns_init(void)
 #endif
             if (i4 < FDNS_MAX)
             {
-               if (inet_aton(&buf[i], &addr4))
-               {
-                  memcpy(&servers4[i4++],&addr4,sizeof(struct in_addr));
-               }
-            }
+              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);
+              }
+           }
          }
       }
    }
@@ -239,8 +248,18 @@ void firedns_init(void)
 #endif
          if (i4 < FDNS_MAX)
          {
-            if (inet_pton(AF_INET, buf, (char *)&addr4))
-               memcpy(&servers4[i4++],&addr4,sizeof(struct in_addr));
+              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);
+              }
          }
       }
    }
index 1fa6af70ab75a356df791f1229b008ce18c0a509..3085148dc1c3dc322c38fcd731636a6e0e6503bb 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -39,6 +39,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <netdb.h>
 
 #ifdef TIME_WITH_SYS_TIME
 # include <sys/time.h>
@@ -258,14 +259,23 @@ irc_init(void)
   /* Bind */
   if (!EmptyString(IRCItem->vhost))
   {
+    struct addrinfo hints, *res;
     int bindret = 0;
 
-    if (!inet_pton(AF_INET, IRCItem->vhost, &(IRC_LOCAL.in4.s_addr)))
+    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))
     {
       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, res->ai_addrlen);
+    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 cc3188a0a72badbbe620be0131d7810ff04af651..f68c3e852beaa57003e2434973e38ed6a0260404 100644 (file)
@@ -195,10 +195,21 @@ OPM_ERR_T libopm_config_set(OPM_CONFIG_T *config, int key, const void *value)
          break;
 
       case OPM_TYPE_ADDRESS:
-         if( inet_pton(AF_INET, value, &( ((opm_sockaddr *)config->vars[key])->sa4.sin_addr))
-                  <= 0)
-            return OPM_ERR_BADVALUE; /* return appropriate err code */
-         break; 
+      {
+        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))
+          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 8ce19c10a971ac35eb28141057980657ccbef39b..9f8dd9147219ecfa04462a2c3f421191ac314e65 100644 (file)
@@ -45,6 +45,7 @@ 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>
@@ -57,6 +58,10 @@ 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"
@@ -210,13 +215,22 @@ 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 (!inet_pton(AF_INET, ipstr, &(ip.sa4.sin_addr)))
+   if (getaddrinfo(ipstr, NULL, &hints, &res))
    {
       log_printf("NEGCACHE -> Invalid IPv4 address '%s'", ipstr);
       return;
    }
 
+   memcpy(&ip.sa4.sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, res->ai_addrlen);
+   freeaddrinfo(res);
+
    n = nc_insert(nc_head, ip.sa4.sin_addr.s_addr);
 
    if (n)
index 2839ceb45a198c34ebde2df87ca550dcd6bb440b..452cfbfb53c69a6c52e7d040e22e2e368f28be4e 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
@@ -341,13 +345,23 @@ scan_connect(char **user, char *msg)
   /* Check negcache before anything */
   if (OptionsItem->negcache > 0)
   {
-      if (!inet_pton(AF_INET, user[3], &(ip.sa4.sin_addr)))
+    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))
       {
          log_printf("SCAN -> Invalid IPv4 address '%s'!", user[3]);
          return;
       }
       else
       {
+         memcpy(&ip.sa4.sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, res->ai_addrlen);
+         freeaddrinfo(res);
+
          if (check_neg_cache(ip.sa4.sin_addr.s_addr))
          {
             if (OPT_DEBUG)