]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
MinGW: various fixes in libcompat addrinfo API
authorDennis Felippa <dennis@infologika.com.br>
Tue, 13 Jan 2015 08:22:55 +0000 (00:22 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 13 Jan 2015 08:22:55 +0000 (00:22 -0800)
compat/getaddrinfo.cc
compat/getnameinfo.cc
compat/inet_ntop.cc
compat/inet_pton.cc

index f363fea621e71e4a0c0ab3f1d09cbbe019f416d2..114d8c0a296269d6e1659c0c65a4c74c15190d4d 100644 (file)
@@ -20,6 +20,8 @@
  *
  *    06-Oct-2007 : Various fixes to allow the build on MinGW
  *
+ *    13-Jan-2015 : Various fixed for C++ and MinGW native build
+ *
  *  Original License and code follows.
  */
 #include "squid.h"
@@ -81,11 +83,11 @@ static struct addrinfo *
 dup_addrinfo (struct addrinfo *info, void *addr, size_t addrlen) {
     struct addrinfo *ret;
 
-    ret = malloc (sizeof (struct addrinfo));
+    ret = (struct addrinfo *)malloc(sizeof (struct addrinfo));
     if (ret == NULL)
         return NULL;
     memcpy (ret, info, sizeof (struct addrinfo));
-    ret->ai_addr = malloc (addrlen);
+    ret->ai_addr = (struct sockaddr*)malloc(addrlen);
     if (ret->ai_addr == NULL) {
         free (ret);
         return NULL;
@@ -176,7 +178,7 @@ xgetaddrinfo (const char *nodename, const char *servname,
 
         sin.sin_family = result.ai_family;
         sin.sin_port = htons (port);
-        if (inet_pton(result.ai_family, nodename, &sin.sin_addr))
+        if (inet_pton(result.ai_family, nodename, &sin.sin_addr) != 1)
             return EAI_NONAME;
         sin.sin_addr.s_addr = inet_addr (nodename);
         /* Duplicate result and addr and return */
@@ -277,7 +279,7 @@ xgetaddrinfo (const char *nodename, const char *servname,
     }
 
     if (hints->ai_flags & AI_CANONNAME) {
-        sai->ai_canonname = malloc (strlen (hp->h_name) + 1);
+        sai->ai_canonname = (char *)malloc(strlen(hp->h_name) + 1);
         if (sai->ai_canonname == NULL) {
             xfreeaddrinfo (sai);
             return EAI_MEMORY;
index ff93eab1d7831f42f28c52b4456b18e67fc1db7d..41868d3b7d3aa8d49f06f7fc2f08bcefc3eb6b43 100644 (file)
@@ -22,6 +22,8 @@
  *                      - use xinet_ntop instead of inet_ntop
  *                      - use SQUIDHOSTNAMELEN instead of MAXHOSTNAMELEN
  *
+ *    13-Jan-2015 : Various fixed for C++ and MinGW native build
+ *
  *  Original License and code follows.
  */
 #include "squid.h"
@@ -149,14 +151,7 @@ static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int));
 #endif
 
 int
-xgetnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
-const struct sockaddr *sa;
-socklen_t salen;
-char *host;
-size_t hostlen;
-char *serv;
-size_t servlen;
-int flags;
+xgetnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
 {
     const struct afd *afd;
     struct servent *sp;
index 6003865422530f290878431bc7addb205bbba6e7..50d569e9b24a4249f82ee0f5d9e56495850b4d91 100644 (file)
@@ -24,6 +24,8 @@
  *
  *    04-Nov-2010: drop SPRINTF casting macro
  *
+ *    13-Jan-2015 : Various fixed for C++ and MinGW native build
+ *
  *  Original License and code follows.
  */
 
@@ -106,17 +108,13 @@ static const char *inet_ntop6 (const u_char *src, char *dst, size_t size);
  *  Paul Vixie, 1996.
  */
 const char *
-xinet_ntop(af, src, dst, size)
-int af;
-const void *src;
-char *dst;
-size_t size;
+xinet_ntop(int af, const void *src, char *dst, size_t size)
 {
     switch (af) {
     case AF_INET:
-        return (inet_ntop4(src, dst, size));
+        return (inet_ntop4((const u_char*)src, dst, size));
     case AF_INET6:
-        return (inet_ntop6(src, dst, size));
+        return (inet_ntop6((const u_char*)src, dst, size));
     default:
         errno = EAFNOSUPPORT;
         return (NULL);
@@ -136,15 +134,12 @@ size_t size;
  *  Paul Vixie, 1996.
  */
 static const char *
-inet_ntop4(src, dst, size)
-const u_char *src;
-char *dst;
-size_t size;
+inet_ntop4(const u_char *src, char *dst, size_t size)
 {
     static const char fmt[] = "%u.%u.%u.%u";
-    char tmp[sizeof "255.255.255.255"];
+    char tmp[sizeof("255.255.255.255")+1];
 
-    if (snprintf(tmp, min(sizeof("255.255.255.255"),size), fmt, src[0], src[1], src[2], src[3]) >= size) {
+    if ((size_t)snprintf(tmp, min(sizeof(tmp),size), fmt, src[0], src[1], src[2], src[3]) >= size) {
         errno = ENOSPC;
         return (NULL);
     }
@@ -159,10 +154,7 @@ size_t size;
  *  Paul Vixie, 1996.
  */
 static const char *
-inet_ntop6(src, dst, size)
-const u_char *src;
-char *dst;
-size_t size;
+inet_ntop6(const u_char *src, char *dst, size_t size)
 {
     /*
      * Note that int32_t and int16_t need only be "at least" large enough
index 65dc87782031b703c6be86704110e6ab9e9c4521..fc1bf925e995bc0f49ea425d262a34de7118c09a 100644 (file)
@@ -21,6 +21,8 @@
  *
  *    28-Oct-2007: drop some dead code. now tested working without.
  *
+ *    13-Jan-2015 : Various fixed for C++ and MinGW native build
+ *
  *  Original License and code follows.
  */
 
@@ -104,16 +106,13 @@ static int  inet_pton6 (const char *src, u_char *dst);
  *  Paul Vixie, 1996.
  */
 int
-xinet_pton(af, src, dst)
-int af;
-const char *src;
-void *dst;
+xinet_pton(int af, const char *src, void *dst)
 {
     switch (af) {
     case AF_INET:
-        return (inet_pton4(src, dst));
+        return (inet_pton4(src, (u_char*)dst));
     case AF_INET6:
-        return (inet_pton6(src, dst));
+        return (inet_pton6(src, (u_char*)dst));
     default:
         errno = EAFNOSUPPORT;
         return (-1);
@@ -132,9 +131,7 @@ void *dst;
  *  Paul Vixie, 1996.
  */
 static int
-inet_pton4(src, dst)
-const char *src;
-u_char *dst;
+inet_pton4(const char *src, u_char *dst)
 {
     static const char digits[] = "0123456789";
     int saw_digit, octets, ch;
@@ -147,13 +144,13 @@ u_char *dst;
         const char *pch;
 
         if ((pch = strchr(digits, ch)) != NULL) {
-            u_int new = *tp * 10 + (pch - digits);
+            u_int nw = *tp * 10 + (pch - digits);
 
             if (saw_digit && *tp == 0)
                 return (0);
-            if (new > 255)
+            if (nw > 255)
                 return (0);
-            *tp = new;
+            *tp = nw;
             if (!saw_digit) {
                 if (++octets > 4)
                     return (0);
@@ -187,9 +184,7 @@ u_char *dst;
  *  Paul Vixie, 1996.
  */
 static int
-inet_pton6(src, dst)
-const char *src;
-u_char *dst;
+inet_pton6(const char *src, u_char *dst)
 {
     static const char xdigits_l[] = "0123456789abcdef",
                                     xdigits_u[] = "0123456789ABCDEF";