1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 15:48:49 -05:00

Added CVS id, Detabified, applied c-ares coding-style.

This commit is contained in:
Gisle Vanem 2005-11-12 14:59:33 +00:00
parent ec65c3fd53
commit b09d5c3135

View File

@ -1,3 +1,5 @@
/* $Id$ */
/* Copyright (c) 1996 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
@ -72,8 +74,8 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size);
const char *
ares_inet_ntop(int af, const void *src, char *dst, size_t size)
{
switch (af) {
switch (af)
{
case AF_INET:
return (inet_ntop4(src, dst, size));
case AF_INET6:
@ -102,7 +104,8 @@ 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 (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size)
{
errno = ENOSPC;
return (NULL);
}
@ -141,21 +144,27 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
best.base = -1;
cur.base = -1;
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
if (words[i] == 0) {
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
{
if (words[i] == 0)
{
if (cur.base == -1)
cur.base = i, cur.len = 1;
else
cur.len++;
} else {
if (cur.base != -1) {
}
else
{
if (cur.base != -1)
{
if (best.base == -1 || cur.len > best.len)
best = cur;
cur.base = -1;
}
}
}
if (cur.base != -1) {
if (cur.base != -1)
{
if (best.base == -1 || cur.len > best.len)
best = cur;
}
@ -166,10 +175,12 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
* Format the result.
*/
tp = tmp;
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
{
/* Are we inside the best run of 0x00's? */
if (best.base != -1 && i >= best.base &&
i < (best.base + best.len)) {
i < (best.base + best.len))
{
if (i == best.base)
*tp++ = ':';
continue;
@ -179,7 +190,8 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
*tp++ = ':';
/* Is this address an encapsulated IPv4? */
if (i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
(best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
{
if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
return (NULL);
tp += strlen(tp);
@ -187,6 +199,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
}
tp += SPRINTF((tp, "%x", words[i]));
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) == (NS_IN6ADDRSZ / NS_INT16SZ))
*tp++ = ':';
@ -195,12 +208,13 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
/*
* Check for overflow, copy, and we're done.
*/
if ((size_t)(tp - tmp) > size) {
if ((size_t)(tp - tmp) > size)
{
errno = ENOSPC;
return (NULL);
}
strcpy(dst, tmp);
return (dst);
}
#endif