summaryrefslogtreecommitdiff
path: root/inet_ntop.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2010-12-16 21:12:14 +0100
committerYang Tse <yangsita@gmail.com>2010-12-16 21:12:14 +0100
commit52f493c9311be2a76e7bf0c7e41e3f3ee85419cc (patch)
treed55f61be784e5b768bdfbac35b0415b2ed2057b0 /inet_ntop.c
parent2c9bdd78566a7215416e9db076e36d4c77a04da0 (diff)
downloadc-ares-52f493c9311be2a76e7bf0c7e41e3f3ee85419cc.tar.gz
c-ares-52f493c9311be2a76e7bf0c7e41e3f3ee85419cc.tar.bz2
c-ares-52f493c9311be2a76e7bf0c7e41e3f3ee85419cc.zip
ares_inet_ntop: reapply changes from previous c-ares version (III)
- Replace 'u_char' with 'unsigned char'. - Replace 'u_int' with 'unsigned int'. - use macros ERRNO and SET_ERRNO() for errno handling.
Diffstat (limited to 'inet_ntop.c')
-rw-r--r--inet_ntop.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/inet_ntop.c b/inet_ntop.c
index cdd1a40..6de0a6d 100644
--- a/inet_ntop.c
+++ b/inet_ntop.c
@@ -59,14 +59,19 @@
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
-static const char *inet_ntop4(const u_char *src, char *dst, size_t size);
-static const char *inet_ntop6(const u_char *src, char *dst, size_t size);
+static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size);
+static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size);
/* char *
* inet_ntop(af, src, dst, size)
* convert a network format address to presentation format.
* return:
* pointer to presentation format address (`dst'), or NULL (see errno).
+ * note:
+ * On Windows we store the error in the thread errno, not
+ * in the winsock error code. This is to avoid loosing the
+ * actual last winsock error. So use macro ERRNO to fetch the
+ * errno this funtion sets when returning NULL, not SOCKERRNO.
* author:
* Paul Vixie, 1996.
*/
@@ -79,7 +84,7 @@ ares_inet_ntop(int af, const void *src, char *dst, size_t size)
case AF_INET6:
return (inet_ntop6(src, dst, size));
default:
- errno = EAFNOSUPPORT;
+ SET_ERRNO(EAFNOSUPPORT);
return (NULL);
}
/* NOTREACHED */
@@ -92,18 +97,18 @@ ares_inet_ntop(int af, const void *src, char *dst, size_t size)
* `dst' (as a const)
* notes:
* (1) uses no statics
- * (2) takes a u_char* not an in_addr as input
+ * (2) takes a unsigned char* not an in_addr as input
* author:
* Paul Vixie, 1996.
*/
static const char *
-inet_ntop4(const u_char *src, char *dst, size_t size)
+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) {
- errno = ENOSPC;
+ SET_ERRNO(ENOSPC);
return (NULL);
}
strcpy(dst, tmp);
@@ -117,7 +122,7 @@ inet_ntop4(const u_char *src, char *dst, size_t size)
* Paul Vixie, 1996.
*/
static const char *
-inet_ntop6(const u_char *src, char *dst, size_t size)
+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
@@ -126,9 +131,10 @@ 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")], *tp;
+ char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
+ char *tp;
struct { int base, len; } best, cur;
- u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
+ unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
int i;
/*
@@ -200,7 +206,7 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
* Check for overflow, copy, and we're done.
*/
if ((size_t)(tp - tmp) > size) {
- errno = ENOSPC;
+ SET_ERRNO(ENOSPC);
return (NULL);
}
strcpy(dst, tmp);