1
0
mirror of https://github.com/moparisthebest/curl synced 2025-03-11 07:39:50 -04:00

Remove usage of inet_ntoa and inet_ntoa_r

This commit is contained in:
Yang Tse 2008-09-23 19:17:19 +00:00
parent c9ad952604
commit 3800be3898

View File

@ -42,12 +42,6 @@
#include "inet_ntop.h" #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 IN6ADDRSZ 16
#define INADDRSZ 4 #define INADDRSZ 4
#define INT16SZ 2 #define INT16SZ 2
@ -62,30 +56,26 @@
*/ */
static char *inet_ntop4 (const unsigned char *src, char *dst, size_t size) static char *inet_ntop4 (const unsigned char *src, char *dst, size_t size)
{ {
#if defined(HAVE_INET_NTOA_R_2_ARGS) char tmp[sizeof "255.255.255.255"];
const char *ptr; size_t len;
DEBUGASSERT(size >= 16); 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) 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 defined(HAVE_INT_INET_NTOA_R) len = strlen(tmp);
return inet_ntoa_r(*(struct in_addr*)src, dst, size)? NULL: dst; if(len == 0 || len >= size)
#else
return inet_ntoa_r(*(struct in_addr*)src, dst, size);
#endif
#else
const char *addr = inet_ntoa(*(struct in_addr*)src);
if(strlen(addr) >= size)
{ {
SET_ERRNO(ENOSPC); SET_ERRNO(ENOSPC);
return (NULL); return (NULL);
} }
return strcpy(dst, addr); strcpy(dst, tmp);
#endif return dst;
} }
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
@ -192,7 +182,8 @@ static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
SET_ERRNO(ENOSPC); SET_ERRNO(ENOSPC);
return (NULL); return (NULL);
} }
return strcpy (dst, tmp); strcpy(dst, tmp);
return dst;
} }
#endif /* ENABLE_IPV6 */ #endif /* ENABLE_IPV6 */