From: Dennis Felippa Date: Tue, 13 Jan 2015 08:22:55 +0000 (-0800) Subject: MinGW: various fixes in libcompat addrinfo API X-Git-Tag: merge-candidate-3-v1~350 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4ddbe0543b072d9a630ca02180943c7521bdac6;p=thirdparty%2Fsquid.git MinGW: various fixes in libcompat addrinfo API --- diff --git a/compat/getaddrinfo.cc b/compat/getaddrinfo.cc index f363fea621..114d8c0a29 100644 --- a/compat/getaddrinfo.cc +++ b/compat/getaddrinfo.cc @@ -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; diff --git a/compat/getnameinfo.cc b/compat/getnameinfo.cc index ff93eab1d7..41868d3b7d 100644 --- a/compat/getnameinfo.cc +++ b/compat/getnameinfo.cc @@ -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; diff --git a/compat/inet_ntop.cc b/compat/inet_ntop.cc index 6003865422..50d569e9b2 100644 --- a/compat/inet_ntop.cc +++ b/compat/inet_ntop.cc @@ -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 diff --git a/compat/inet_pton.cc b/compat/inet_pton.cc index 65dc877820..fc1bf925e9 100644 --- a/compat/inet_pton.cc +++ b/compat/inet_pton.cc @@ -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";