aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2008-09-23 19:17:19 +0000
committerYang Tse <yangsita@gmail.com>2008-09-23 19:17:19 +0000
commit3800be3898f8b37d139ac997fbe79125a1727e5a (patch)
treec344d3891d399fd62e15dee263b2b6c7c02ec611
parentc9ad95260400f0dbf056d44e0eccc8b0a351f504 (diff)
Remove usage of inet_ntoa and inet_ntoa_r
-rw-r--r--lib/inet_ntop.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
index 9501bfa6b..26867f4d2 100644
--- a/lib/inet_ntop.c
+++ b/lib/inet_ntop.c
@@ -42,12 +42,6 @@
#include "inet_ntop.h"
-#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
-/* this platform has a inet_ntoa_r() function, but no proto declared anywhere
- so we include our own proto to make compilers happy */
-#include "inet_ntoa_r.h"
-#endif
-
#define IN6ADDRSZ 16
#define INADDRSZ 4
#define INT16SZ 2
@@ -62,30 +56,26 @@
*/
static char *inet_ntop4 (const unsigned char *src, char *dst, size_t size)
{
-#if defined(HAVE_INET_NTOA_R_2_ARGS)
- const char *ptr;
- DEBUGASSERT(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)
+ char tmp[sizeof "255.255.255.255"];
+ size_t len;
-#if defined(HAVE_INT_INET_NTOA_R)
- return inet_ntoa_r(*(struct in_addr*)src, dst, size)? NULL: dst;
-#else
- return inet_ntoa_r(*(struct in_addr*)src, dst, size);
-#endif
+ DEBUGASSERT(size >= 16);
-#else
- const char *addr = inet_ntoa(*(struct in_addr*)src);
+ tmp[0] = '\0';
+ (void)snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d",
+ ((int)((unsigned char)src[0])) & 0xff,
+ ((int)((unsigned char)src[1])) & 0xff,
+ ((int)((unsigned char)src[2])) & 0xff,
+ ((int)((unsigned char)src[3])) & 0xff);
- if(strlen(addr) >= size)
+ len = strlen(tmp);
+ if(len == 0 || len >= size)
{
SET_ERRNO(ENOSPC);
return (NULL);
}
- return strcpy(dst, addr);
-#endif
+ strcpy(dst, tmp);
+ return dst;
}
#ifdef ENABLE_IPV6
@@ -192,7 +182,8 @@ static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
SET_ERRNO(ENOSPC);
return (NULL);
}
- return strcpy (dst, tmp);
+ strcpy(dst, tmp);
+ return dst;
}
#endif /* ENABLE_IPV6 */