--------------------- PatchSet 5921 Date: 2007/10/06 20:25:51 Author: serassio Branch: squid3-ipv6 Tag: (none) Log: Various fixes to allow the build on MinGW - use srtncpy instead of strlcpy - use xinet_ntop instead of inet_ntop - use SQUIDHOSTNAMELEN instead of MAXHOSTNAMELEN Members: lib/getaddrinfo.c:1.1.2.4->1.1.2.5 lib/getnameinfo.c:1.1.2.2->1.1.2.3 lib/inet_ntop.c:1.1.2.1->1.1.2.2 lib/inet_pton.c:1.1.2.1->1.1.2.2 Index: squid3/lib/getaddrinfo.c =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/getaddrinfo.c,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid3/lib/getaddrinfo.c 17 Aug 2007 02:53:13 -0000 1.1.2.4 +++ squid3/lib/getaddrinfo.c 6 Oct 2007 20:25:51 -0000 1.1.2.5 @@ -10,7 +10,9 @@ * 16-Aug-2007 : Altered configure checks * Un-hacked slightly to use system gethostbyname() * - * Squid CVS $Id: getaddrinfo.c,v 1.1.2.4 2007/08/17 02:53:13 amosjeffries Exp $ + * 06-Oct-2007 : Various fixes to allow the build on MinGW + * + * Squid CVS $Id: getaddrinfo.c,v 1.1.2.5 2007/10/06 20:25:51 serassio Exp $ * * Original License and code follows. */ @@ -72,9 +74,9 @@ #if HAVE_NETDB_H #include #endif - -#ifndef HAVE_GETHOSTBYNAME -#include "gethostbyname.h" +#ifdef _SQUID_MSWIN_ +#undef IN_ADDR +#include #endif #include "getaddrinfo.h" @@ -110,7 +112,6 @@ struct addrinfo hint, result; struct addrinfo *ai, *sai, *eai; char **addrs; - int code; if (servname == NULL && nodename == NULL) return EAI_NONAME; @@ -195,9 +196,11 @@ hp = gethostbyname(nodename); if (hp == NULL) { +#ifdef EAI_SYSTEM if (errno != 0) { return EAI_SYSTEM; } +#endif switch (h_errno) { case HOST_NOT_FOUND: return EAI_NODATA; @@ -251,9 +254,9 @@ break; #if USE_IPV6 case AF_INET6: -# if SIN6_LEN +#if SIN6_LEN ((struct sockaddr_in6 *) &sa)->sin6_len = hp->h_length; -# endif +#endif ((struct sockaddr_in6 *) &sa)->sin6_port = htons (port); memcpy (&((struct sockaddr_in6 *) &sa)->sin6_addr, *addrs, hp->h_length); Index: squid3/lib/getnameinfo.c =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/getnameinfo.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid3/lib/getnameinfo.c 16 Aug 2007 11:35:06 -0000 1.1.2.2 +++ squid3/lib/getnameinfo.c 6 Oct 2007 20:25:51 -0000 1.1.2.3 @@ -9,7 +9,12 @@ * - added use of alternative name xgetnameinfo * to split from any OS-provided. * - * Squid CVS $Id: getnameinfo.c,v 1.1.2.2 2007/08/16 11:35:06 amosjeffries Exp $ + * 06-Oct-2007 : Various fixes to allow the build on MinGW + * - use srtncpy instead of strlcpy + * - use xinet_ntop instead of inet_ntop + * - use SQUIDHOSTNAMELEN instead of MAXHOSTNAMELEN + * + * Squid CVS $Id: getnameinfo.c,v 1.1.2.3 2007/10/06 20:25:51 serassio Exp $ * * Original License and code follows. */ @@ -75,6 +80,9 @@ #if HAVE_SYS_TYPES_H #include #endif +#if HAVE_STDIO_H +#include +#endif #if HAVE_SYS_SOCKET_H #include #endif @@ -109,8 +117,17 @@ #include #endif +#ifdef _SQUID_MSWIN_ +#undef IN_ADDR +#include +#endif + #include "getaddrinfo.h" +#if !HAVE_INET_NTOP +#include "inet_ntop.h" +#endif + static const struct afd { int a_af; int a_addrlen; @@ -138,11 +155,7 @@ int xgetnameinfo(sa, salen, host, hostlen, serv, servlen, flags) const struct sockaddr *sa; -#ifdef HAVE_SOCKLEN_T socklen_t salen; -#else - unsigned int salen; -#endif char *host; size_t hostlen; char *serv; @@ -158,7 +171,6 @@ u_int32_t v4a; int h_error; char numserv[512]; - char numaddr[512]; if (sa == NULL) return EAI_FAIL; @@ -201,12 +213,12 @@ if (sp) { if (strlen(sp->s_name) + 1 > servlen) return EAI_OVERFLOW; - strlcpy(serv, sp->s_name, servlen); + strncpy(serv, sp->s_name, servlen); } else { snprintf(numserv, sizeof(numserv), "%u", ntohs(port)); if (strlen(numserv) + 1 > servlen) return EAI_OVERFLOW; - strlcpy(serv, numserv, servlen); + strncpy(serv, numserv, servlen); } } @@ -297,7 +309,7 @@ #endif return EAI_OVERFLOW; } - strlcpy(host, hp->h_name, hostlen); + strncpy(host, hp->h_name, hostlen); #ifdef USE_GETIPNODEBY freehostent(hp); #endif @@ -320,16 +332,9 @@ } #endif default: -#ifdef HAVE_INET_NTOP - if (inet_ntop(afd->a_af, addr, host, + if (xinet_ntop(afd->a_af, addr, host, hostlen) == NULL) return EAI_SYSTEM; -#else - if (afd->a_af == AF_INET) - strlcpy(host, inet_ntoa(addr), hostlen); - else - return EAI_FAMILY; -#endif break; } } @@ -349,16 +354,16 @@ int numaddrlen; char numaddr[512]; - if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL) + if (xinet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL) return EAI_SYSTEM; numaddrlen = strlen(numaddr); if (numaddrlen + 1 > hostlen) /* don't forget terminator */ return EAI_OVERFLOW; - strlcpy(host, numaddr, hostlen); + strncpy(host, numaddr, hostlen); if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) { - char zonebuf[MAXHOSTNAMELEN]; + char zonebuf[SQUIDHOSTNAMELEN]; int zonelen; zonelen = ip6_sa2str( Index: squid3/lib/inet_ntop.c =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/inet_ntop.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/lib/inet_ntop.c 24 Sep 2007 02:15:47 -0000 1.1.2.1 +++ squid3/lib/inet_ntop.c 6 Oct 2007 20:25:51 -0000 1.1.2.2 @@ -10,7 +10,9 @@ * - Altered configure checks * - Un-hacked slightly to use system gethostbyname() * - * Squid CVS $Id: inet_ntop.c,v 1.1.2.1 2007/09/24 02:15:47 amosjeffries Exp $ + * 06-Oct-2007 : Various fixes to allow the build on MinGW + * + * Squid CVS $Id: inet_ntop.c,v 1.1.2.2 2007/10/06 20:25:51 serassio Exp $ * * Original License and code follows. */ @@ -80,13 +82,23 @@ # define SPRINTF(x) ((size_t)sprintf x) #endif +#if ! defined(NS_INADDRSZ) +#define NS_INADDRSZ 4 +#endif +#if ! defined(NS_IN6ADDRSZ) +#define NS_IN6ADDRSZ 16 +#endif +#if ! defined(NS_INT16SZ) +#define NS_INT16SZ 2 +#endif + /* * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size)); -static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); +static const char *inet_ntop4 (const u_char *src, char *dst, size_t size); +static const char *inet_ntop6 (const u_char *src, char *dst, size_t size); /* char * * inet_ntop(af, src, dst, size) Index: squid3/lib/inet_pton.c =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/inet_pton.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/lib/inet_pton.c 24 Sep 2007 02:15:47 -0000 1.1.2.1 +++ squid3/lib/inet_pton.c 6 Oct 2007 20:25:51 -0000 1.1.2.2 @@ -9,7 +9,9 @@ * - Added protection around libray headers * - Altered configure checks to import * - * Squid CVS $Id: inet_pton.c,v 1.1.2.1 2007/09/24 02:15:47 amosjeffries Exp $ + * 06-Oct-2007 : Various fixes to allow the build on MinGW + * + * Squid CVS $Id: inet_pton.c,v 1.1.2.2 2007/10/06 20:25:51 serassio Exp $ * * Original License and code follows. */ @@ -68,13 +70,23 @@ //AYJ: #include "port_after.h" +#if ! defined(NS_INADDRSZ) +#define NS_INADDRSZ 4 +#endif +#if ! defined(NS_IN6ADDRSZ) +#define NS_IN6ADDRSZ 16 +#endif +#if ! defined(NS_INT16SZ) +#define NS_INT16SZ 2 +#endif + /* * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static int inet_pton4 __P((const char *src, u_char *dst)); -static int inet_pton6 __P((const char *src, u_char *dst)); +static int inet_pton4 (const char *src, u_char *dst); +static int inet_pton6 (const char *src, u_char *dst); /* int * inet_pton(af, src, dst)