diff options
author | Brad King <brad.king@kitware.com> | 2014-10-08 20:30:41 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-10-29 20:43:21 (GMT) |
commit | 80c881f7938969dab169f4fc4fbf8bc3d4355fc2 (patch) | |
tree | 77abe643bf8fcb388056480350b99b666f543965 /Utilities/cmcurl/lib/inet_pton.c | |
parent | ff67d2b57946a29e18d1947efe71f26ece9e1747 (diff) | |
parent | 3fe5d9bff98b4716e219516c30d71462495324f4 (diff) | |
download | CMake-80c881f7938969dab169f4fc4fbf8bc3d4355fc2.zip CMake-80c881f7938969dab169f4fc4fbf8bc3d4355fc2.tar.gz CMake-80c881f7938969dab169f4fc4fbf8bc3d4355fc2.tar.bz2 |
Merge branch 'curl-upstream' into update-curl
Resolve all conflicts in favor of the upstream side.
We can re-apply specific changes later.
Diffstat (limited to 'Utilities/cmcurl/lib/inet_pton.c')
-rw-r--r-- | Utilities/cmcurl/lib/inet_pton.c | 95 |
1 files changed, 44 insertions, 51 deletions
diff --git a/Utilities/cmcurl/lib/inet_pton.c b/Utilities/cmcurl/lib/inet_pton.c index 9b9f88b..f50b365 100644 --- a/Utilities/cmcurl/lib/inet_pton.c +++ b/Utilities/cmcurl/lib/inet_pton.c @@ -16,27 +16,19 @@ * SOFTWARE. */ -#include "setup.h" +#include "curl_setup.h" #ifndef HAVE_INET_PTON #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #endif -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif -#include <string.h> -#include <errno.h> #include "inet_pton.h" @@ -44,10 +36,6 @@ #define INADDRSZ 4 #define INT16SZ 2 -#ifdef USE_WINSOCK -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#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. @@ -66,6 +54,11 @@ static int inet_pton6(const char *src, unsigned char *dst); * 1 if the address was valid for the specified address family * 0 if the address wasn't valid (`dst' is untouched in this case) * -1 if some other error occurred (`dst' is untouched in this case, too) + * notice: + * On Windows we store the error in the thread errno, not + * in the winsock error code. This is to avoid losing the + * actual last winsock error. So use macro ERRNO to fetch the + * errno this function sets when returning (-1), not SOCKERRNO. * author: * Paul Vixie, 1996. */ @@ -76,14 +69,11 @@ Curl_inet_pton(int af, const char *src, void *dst) case AF_INET: return (inet_pton4(src, (unsigned char *)dst)); #ifdef ENABLE_IPV6 -#ifndef AF_INET6 -#define AF_INET6 (AF_MAX+1) /* just to let this compile */ -#endif case AF_INET6: return (inet_pton6(src, (unsigned char *)dst)); #endif default: - errno = EAFNOSUPPORT; + SET_ERRNO(EAFNOSUPPORT); return (-1); } /* NOTREACHED */ @@ -110,31 +100,34 @@ inet_pton4(const char *src, unsigned char *dst) octets = 0; tp = tmp; *tp = 0; - while ((ch = *src++) != '\0') { + while((ch = *src++) != '\0') { const char *pch; - if ((pch = strchr(digits, ch)) != NULL) { + if((pch = strchr(digits, ch)) != NULL) { unsigned int val = *tp * 10 + (unsigned int)(pch - digits); - if (val > 255) + if(saw_digit && *tp == 0) + return (0); + if(val > 255) return (0); - *tp = val; - if (! saw_digit) { - if (++octets > 4) + *tp = (unsigned char)val; + if(! saw_digit) { + if(++octets > 4) return (0); saw_digit = 1; } - } else if (ch == '.' && saw_digit) { - if (octets == 4) + } + else if(ch == '.' && saw_digit) { + if(octets == 4) return (0); *++tp = 0; saw_digit = 0; - } else + } + else return (0); } - if (octets < 4) + if(octets < 4) return (0); - /* bcopy(tmp, dst, INADDRSZ); */ memcpy(dst, tmp, INADDRSZ); return (1); } @@ -161,40 +154,39 @@ inet_pton6(const char *src, unsigned char *dst) unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; const char *xdigits, *curtok; int ch, saw_xdigit; - unsigned int val; + size_t val; memset((tp = tmp), 0, IN6ADDRSZ); endp = tp + IN6ADDRSZ; colonp = NULL; /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') + if(*src == ':') + if(*++src != ':') return (0); curtok = src; saw_xdigit = 0; val = 0; - while ((ch = *src++) != '\0') { + while((ch = *src++) != '\0') { const char *pch; - if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) + if((pch = strchr((xdigits = xdigits_l), ch)) == NULL) pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { + if(pch != NULL) { val <<= 4; val |= (pch - xdigits); - if (val > 0xffff) + if(++saw_xdigit > 4) return (0); - saw_xdigit = 1; continue; } - if (ch == ':') { + if(ch == ':') { curtok = src; - if (!saw_xdigit) { - if (colonp) + if(!saw_xdigit) { + if(colonp) return (0); colonp = tp; continue; } - if (tp + INT16SZ > endp) + if(tp + INT16SZ > endp) return (0); *tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) val & 0xff; @@ -202,7 +194,7 @@ inet_pton6(const char *src, unsigned char *dst) val = 0; continue; } - if (ch == '.' && ((tp + INADDRSZ) <= endp) && + if(ch == '.' && ((tp + INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) { tp += INADDRSZ; saw_xdigit = 0; @@ -210,29 +202,30 @@ inet_pton6(const char *src, unsigned char *dst) } return (0); } - if (saw_xdigit) { - if (tp + INT16SZ > endp) + if(saw_xdigit) { + if(tp + INT16SZ > endp) return (0); *tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) val & 0xff; } - if (colonp != NULL) { + if(colonp != NULL) { /* * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; - int i; + const ssize_t n = tp - colonp; + ssize_t i; - for (i = 1; i <= n; i++) { - endp[- i] = colonp[n - i]; - colonp[n - i] = 0; + if(tp == endp) + return (0); + for(i = 1; i <= n; i++) { + *(endp - i) = *(colonp + n - i); + *(colonp + n - i) = 0; } tp = endp; } - if (tp != endp) + if(tp != endp) return (0); - /* bcopy(tmp, dst, IN6ADDRSZ); */ memcpy(dst, tmp, IN6ADDRSZ); return (1); } |