summaryrefslogtreecommitdiffstats
path: root/Utilities/cmcurl/inet_ntop.c
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/cmcurl/inet_ntop.c')
-rw-r--r--Utilities/cmcurl/inet_ntop.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/Utilities/cmcurl/inet_ntop.c b/Utilities/cmcurl/inet_ntop.c
index 6809a92..9381963 100644
--- a/Utilities/cmcurl/inet_ntop.c
+++ b/Utilities/cmcurl/inet_ntop.c
@@ -1,4 +1,20 @@
/*
+ * Copyright (C) 1996-2001 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
* Original code by Paul Vixie. "curlified" by Gisle Vanem.
*/
@@ -39,7 +55,7 @@
#define INADDRSZ 4
#define INT16SZ 2
-#ifdef WIN32
+#ifdef USE_WINSOCK
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#define SET_ERRNO(e) WSASetLastError(errno = (e))
#else
@@ -52,20 +68,21 @@
* Returns `dst' (as a const)
* Note:
* - uses no statics
- * - takes a u_char* not an in_addr as input
+ * - takes a unsigned char* not an in_addr as input
*/
-static const char *inet_ntop4 (const u_char *src, char *dst, size_t size)
+static char *inet_ntop4 (const unsigned char *src, char *dst, size_t size)
{
-#ifdef HAVE_INET_NTOA_R
+#if defined(HAVE_INET_NTOA_R_2_ARGS)
+ const char *ptr;
+ curlassert(size >= 16);
+ ptr = inet_ntoa_r(*(struct in_addr*)src, dst);
+ return (char *)memmove(dst, ptr, strlen(ptr)+1);
+
+#elif defined(HAVE_INET_NTOA_R)
return inet_ntoa_r(*(struct in_addr*)src, dst, size);
+
#else
- union {
- const u_char* uch;
- const struct in_addr* iad;
- } srcaddr;
- const char *addr;
- srcaddr.uch = src;
- addr = inet_ntoa(*srcaddr.iad);
+ const char *addr = inet_ntoa(*(struct in_addr*)src);
if (strlen(addr) >= size)
{
@@ -80,7 +97,7 @@ static const char *inet_ntop4 (const u_char *src, char *dst, size_t size)
/*
* Convert IPv6 binary address into presentation (printable) format.
*/
-static const char *inet_ntop6 (const u_char *src, char *dst, size_t size)
+static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
{
/*
* Note that int32_t and int16_t need only be "at least" large enough
@@ -89,25 +106,28 @@ static const char *inet_ntop6 (const u_char *src, char *dst, size_t size)
* Keep this in mind if you think this function should have been coded
* to use pointer overlays. All the world's not a VAX.
*/
- char tmp [sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
+ char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
char *tp;
struct {
long base;
long len;
} best, cur;
- u_long words [IN6ADDRSZ / INT16SZ];
- int i;
+ unsigned long words[IN6ADDRSZ / INT16SZ];
+ int i;
/* Preprocess:
* Copy the input (bytewise) array into a wordwise array.
* Find the longest run of 0x00's in src[] for :: shorthanding.
*/
- memset(words, 0, sizeof(words));
+ memset(words, '\0', sizeof(words));
for (i = 0; i < IN6ADDRSZ; i++)
words[i/2] |= (src[i] << ((1 - (i % 2)) << 3));
best.base = -1;
cur.base = -1;
+ best.len = 0;
+ cur.len = 0;
+
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
{
if (words[i] == 0)
@@ -184,17 +204,17 @@ static const char *inet_ntop6 (const u_char *src, char *dst, size_t size)
/*
* Convert a network format address to presentation format.
*
- * Returns pointer to presentation format address (`dst'),
+ * Returns pointer to presentation format address (`buf'),
* Returns NULL on error (see errno).
*/
-const char *Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
+char *Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
{
switch (af) {
case AF_INET:
- return inet_ntop4((const u_char*)src, buf, size);
+ return inet_ntop4((const unsigned char*)src, buf, size);
#ifdef ENABLE_IPV6
case AF_INET6:
- return inet_ntop6((const u_char*)src, buf, size);
+ return inet_ntop6((const unsigned char*)src, buf, size);
#endif
default:
SET_ERRNO(EAFNOSUPPORT);