indented the code curl-style

This commit is contained in:
Daniel Stenberg 2004-08-18 06:12:01 +00:00
parent d0dcb3b554
commit d72ca96a43
1 changed files with 117 additions and 117 deletions

View File

@ -72,21 +72,21 @@ static int inet_pton6(const char *src, unsigned char *dst);
int int
Curl_inet_pton(int af, const char *src, void *dst) Curl_inet_pton(int af, const char *src, void *dst)
{ {
switch (af) { switch (af) {
case AF_INET: case AF_INET:
return (inet_pton4(src, dst)); return (inet_pton4(src, dst));
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
#ifndef AF_INET6 #ifndef AF_INET6
#define AF_INET6 AF_MAX+1 /* just to let this compile */ #define AF_INET6 AF_MAX+1 /* just to let this compile */
#endif #endif
case AF_INET6: case AF_INET6:
return (inet_pton6(src, dst)); return (inet_pton6(src, dst));
#endif #endif
default: default:
errno = EAFNOSUPPORT; errno = EAFNOSUPPORT;
return (-1); return (-1);
} }
/* NOTREACHED */ /* NOTREACHED */
} }
/* int /* int
@ -102,40 +102,40 @@ Curl_inet_pton(int af, const char *src, void *dst)
static int static int
inet_pton4(const char *src, unsigned char *dst) inet_pton4(const char *src, unsigned char *dst)
{ {
static const char digits[] = "0123456789"; static const char digits[] = "0123456789";
int saw_digit, octets, ch; int saw_digit, octets, ch;
unsigned char tmp[INADDRSZ], *tp; unsigned char tmp[INADDRSZ], *tp;
saw_digit = 0; saw_digit = 0;
octets = 0; octets = 0;
*(tp = tmp) = 0; *(tp = tmp) = 0;
while ((ch = *src++) != '\0') { while ((ch = *src++) != '\0') {
const char *pch; const char *pch;
if ((pch = strchr(digits, ch)) != NULL) { if ((pch = strchr(digits, ch)) != NULL) {
u_int new = *tp * 10 + (pch - digits); u_int new = *tp * 10 + (pch - digits);
if (new > 255) if (new > 255)
return (0); return (0);
*tp = new; *tp = new;
if (! saw_digit) { if (! saw_digit) {
if (++octets > 4) if (++octets > 4)
return (0); return (0);
saw_digit = 1; saw_digit = 1;
} }
} else if (ch == '.' && saw_digit) { } else if (ch == '.' && saw_digit) {
if (octets == 4) if (octets == 4)
return (0); return (0);
*++tp = 0; *++tp = 0;
saw_digit = 0; saw_digit = 0;
} else } else
return (0); return (0);
} }
if (octets < 4) if (octets < 4)
return (0); return (0);
/* bcopy(tmp, dst, INADDRSZ); */ /* bcopy(tmp, dst, INADDRSZ); */
memcpy(dst, tmp, INADDRSZ); memcpy(dst, tmp, INADDRSZ);
return (1); return (1);
} }
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
@ -155,85 +155,85 @@ inet_pton4(const char *src, unsigned char *dst)
static int static int
inet_pton6(const char *src, unsigned char *dst) inet_pton6(const char *src, unsigned char *dst)
{ {
static const char xdigits_l[] = "0123456789abcdef", static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF"; xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
const char *xdigits, *curtok; const char *xdigits, *curtok;
int ch, saw_xdigit; int ch, saw_xdigit;
u_int val; u_int val;
memset((tp = tmp), 0, IN6ADDRSZ); memset((tp = tmp), 0, IN6ADDRSZ);
endp = tp + IN6ADDRSZ; endp = tp + IN6ADDRSZ;
colonp = NULL; colonp = NULL;
/* Leading :: requires some special handling. */ /* Leading :: requires some special handling. */
if (*src == ':') if (*src == ':')
if (*++src != ':') if (*++src != ':')
return (0); return (0);
curtok = src; curtok = src;
saw_xdigit = 0; saw_xdigit = 0;
val = 0; val = 0;
while ((ch = *src++) != '\0') { while ((ch = *src++) != '\0') {
const char *pch; const char *pch;
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
pch = strchr((xdigits = xdigits_u), ch); pch = strchr((xdigits = xdigits_u), ch);
if (pch != NULL) { if (pch != NULL) {
val <<= 4; val <<= 4;
val |= (pch - xdigits); val |= (pch - xdigits);
if (val > 0xffff) if (val > 0xffff)
return (0); return (0);
saw_xdigit = 1; saw_xdigit = 1;
continue; continue;
} }
if (ch == ':') { if (ch == ':') {
curtok = src; curtok = src;
if (!saw_xdigit) { if (!saw_xdigit) {
if (colonp) if (colonp)
return (0); return (0);
colonp = tp; colonp = tp;
continue; continue;
} }
if (tp + INT16SZ > endp) if (tp + INT16SZ > endp)
return (0); return (0);
*tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff; *tp++ = (unsigned char) val & 0xff;
saw_xdigit = 0; saw_xdigit = 0;
val = 0; val = 0;
continue; continue;
} }
if (ch == '.' && ((tp + INADDRSZ) <= endp) && if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
inet_pton4(curtok, tp) > 0) { inet_pton4(curtok, tp) > 0) {
tp += INADDRSZ; tp += INADDRSZ;
saw_xdigit = 0; saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */ break; /* '\0' was seen by inet_pton4(). */
} }
return (0); return (0);
} }
if (saw_xdigit) { if (saw_xdigit) {
if (tp + INT16SZ > endp) if (tp + INT16SZ > endp)
return (0); return (0);
*tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff; *tp++ = (unsigned char) val & 0xff;
} }
if (colonp != NULL) { if (colonp != NULL) {
/* /*
* Since some memmove()'s erroneously fail to handle * Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand. * overlapping regions, we'll do the shift by hand.
*/ */
const int n = tp - colonp; const int n = tp - colonp;
int i; int i;
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
endp[- i] = colonp[n - i]; endp[- i] = colonp[n - i];
colonp[n - i] = 0; colonp[n - i] = 0;
} }
tp = endp; tp = endp;
} }
if (tp != endp) if (tp != endp)
return (0); return (0);
/* bcopy(tmp, dst, IN6ADDRSZ); */ /* bcopy(tmp, dst, IN6ADDRSZ); */
memcpy(dst, tmp, IN6ADDRSZ); memcpy(dst, tmp, IN6ADDRSZ);
return (1); return (1);
} }
#endif /* ENABLE_IPV6 */ #endif /* ENABLE_IPV6 */