ares_build.h.dist: enhance non-configure GCC ABI detection logic
[platform/upstream/c-ares.git] / inet_ntop.c
index 6de0a6d..9420f6c 100644 (file)
@@ -17,9 +17,6 @@
 
 #include "ares_setup.h"
 
-#ifdef HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
 #ifdef HAVE_NETINET_IN_H
 #  include <netinet/in.h>
 #endif
 #  include <arpa/nameser_compat.h>
 #endif
 
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
 #include "ares.h"
 #include "ares_ipv6.h"
-#include "inet_ntop.h"
-
 
 #ifndef HAVE_INET_NTOP
 
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#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.
@@ -76,13 +59,13 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size);
  *     Paul Vixie, 1996.
  */
 const char *
-ares_inet_ntop(int af, const void *src, char *dst, size_t size)
+ares_inet_ntop(int af, const void *src, char *dst, ares_socklen_t size)
 {
   switch (af) {
   case AF_INET:
-    return (inet_ntop4(src, dst, size));
+    return (inet_ntop4(src, dst, (size_t)size));
   case AF_INET6:
-    return (inet_ntop6(src, dst, size));
+    return (inet_ntop6(src, dst, (size_t)size));
   default:
     SET_ERRNO(EAFNOSUPPORT);
     return (NULL);
@@ -107,7 +90,7 @@ inet_ntop4(const unsigned char *src, char *dst, size_t size)
   static const char fmt[] = "%u.%u.%u.%u";
   char tmp[sizeof("255.255.255.255")];
 
-  if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) >= size) {
+  if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size) {
     SET_ERRNO(ENOSPC);
     return (NULL);
   }
@@ -194,7 +177,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
       tp += strlen(tp);
       break;
     }
-    tp += SPRINTF((tp, "%x", words[i]));
+    tp += sprintf(tp, "%x", words[i]);
   }
   /* Was it a trailing run of 0x00's? */
   if (best.base != -1 && (best.base + best.len) == 
@@ -212,4 +195,14 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
   strcpy(dst, tmp);
   return (dst);
 }
-#endif
+
+#else /* HAVE_INET_NTOP */
+
+const char *
+ares_inet_ntop(int af, const void *src, char *dst, ares_socklen_t size)
+{
+  /* just relay this to the underlying function */
+  return inet_ntop(af, src, dst, size);
+}
+
+#endif /* HAVE_INET_NTOP */