------------------------------------------------------------ revno: 13721 revision-id: squid3@treenet.co.nz-20150113090035-vvmohoi06jnx9bdf parent: squid3@treenet.co.nz-20150113085612-2j6u5zj7t8n7g38z author: Dennis Felippa committer: Amos Jeffries branch nick: 3.5 timestamp: Tue 2015-01-13 01:00:35 -0800 message: MinGW: various fixes in libcompat addrinfo API ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20150113090035-vvmohoi06jnx9bdf # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # testament_sha1: 0a45d47ffcb237e5f0b6b50a248f779c4b2961b6 # timestamp: 2015-01-13 09:01:28 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # base_revision_id: squid3@treenet.co.nz-20150113085612-\ # 2j6u5zj7t8n7g38z # # Begin patch === modified file 'compat/getaddrinfo.cc' --- compat/getaddrinfo.cc 2014-12-29 01:27:04 +0000 +++ compat/getaddrinfo.cc 2015-01-13 09:00:35 +0000 @@ -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 @@ 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 @@ 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 @@ } 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; === modified file 'compat/getnameinfo.cc' --- compat/getnameinfo.cc 2014-12-29 01:27:04 +0000 +++ compat/getnameinfo.cc 2015-01-13 09:00:35 +0000 @@ -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 @@ #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; === modified file 'compat/inet_ntop.cc' --- compat/inet_ntop.cc 2014-12-29 01:27:04 +0000 +++ compat/inet_ntop.cc 2015-01-13 09:00:35 +0000 @@ -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 @@ * 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 @@ * 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 @@ * 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 === modified file 'compat/inet_pton.cc' --- compat/inet_pton.cc 2014-12-29 01:27:04 +0000 +++ compat/inet_pton.cc 2015-01-13 09:00:35 +0000 @@ -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 @@ * 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 @@ * 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 @@ 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 @@ * 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";