mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 14:00:30 +00:00
inet_pton: Reformat in GNU style
Generated machine code is identical on x86-64.
This commit is contained in:
parent
8ec69bb7ec
commit
d53b865288
@ -1,3 +1,8 @@
|
|||||||
|
2017-05-11 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* resolv/inet_pton.c: Reformat in GNU style. Remove
|
||||||
|
internal_function on static functions.
|
||||||
|
|
||||||
2017-05-11 Florian Weimer <fweimer@redhat.com>
|
2017-05-11 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
* support/support_format_addrinfo.c (format_ai_flags_1): Renamed
|
* support/support_format_addrinfo.c (format_ai_flags_1): Renamed
|
||||||
|
@ -25,188 +25,192 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/*
|
static int inet_pton4 (const char *src, unsigned char *dst);
|
||||||
* WARNING: Don't even consider trying to compile this on a system where
|
static int inet_pton6 (const char *src, unsigned char *dst);
|
||||||
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int inet_pton4 (const char *src, u_char *dst) internal_function;
|
/* Convert from presentation format (which usually means ASCII printable)
|
||||||
static int inet_pton6 (const char *src, u_char *dst) internal_function;
|
* to network format (which is usually some kind of binary format).
|
||||||
|
*
|
||||||
/* int
|
|
||||||
* inet_pton(af, src, dst)
|
|
||||||
* convert from presentation format (which usually means ASCII printable)
|
|
||||||
* to network format (which is usually some kind of binary format).
|
|
||||||
* return:
|
* return:
|
||||||
* 1 if the address was valid for the specified address family
|
* 1 if the address was valid for the specified address family
|
||||||
* 0 if the address wasn't valid (`dst' is untouched in this case)
|
* 0 if the address wasn't valid (`dst' is untouched in this case)
|
||||||
* -1 if some other error occurred (`dst' is untouched in this case, too)
|
* -1 if some other error occurred (`dst' is untouched in this case, too)
|
||||||
* author:
|
* author:
|
||||||
* Paul Vixie, 1996.
|
* Paul Vixie, 1996.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
__inet_pton (int af, const char *src, void *dst)
|
__inet_pton (int af, const char *src, void *dst)
|
||||||
{
|
{
|
||||||
switch (af) {
|
switch (af)
|
||||||
case AF_INET:
|
{
|
||||||
return (inet_pton4(src, dst));
|
case AF_INET:
|
||||||
case AF_INET6:
|
return inet_pton4 (src, dst);
|
||||||
return (inet_pton6(src, dst));
|
case AF_INET6:
|
||||||
default:
|
return inet_pton6 (src, dst);
|
||||||
__set_errno (EAFNOSUPPORT);
|
default:
|
||||||
return (-1);
|
__set_errno (EAFNOSUPPORT);
|
||||||
}
|
return -1;
|
||||||
/* NOTREACHED */
|
}
|
||||||
}
|
}
|
||||||
libc_hidden_def (__inet_pton)
|
libc_hidden_def (__inet_pton)
|
||||||
weak_alias (__inet_pton, inet_pton)
|
weak_alias (__inet_pton, inet_pton)
|
||||||
libc_hidden_weak (inet_pton)
|
libc_hidden_weak (inet_pton)
|
||||||
|
|
||||||
/* int
|
/* Like inet_atonbut without all the hexadecimal, octal and shorthand.
|
||||||
* inet_pton4(src, dst)
|
*
|
||||||
* like inet_aton() but without all the hexadecimal, octal (with the
|
|
||||||
* exception of 0) and shorthand.
|
|
||||||
* return:
|
* return:
|
||||||
* 1 if `src' is a valid dotted quad, else 0.
|
* 1 if `src' is a valid dotted quad, else 0.
|
||||||
* notice:
|
* notice:
|
||||||
* does not touch `dst' unless it's returning 1.
|
* does not touch `dst' unless it's returning 1.
|
||||||
* author:
|
* author:
|
||||||
* Paul Vixie, 1996.
|
* Paul Vixie, 1996.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
internal_function
|
inet_pton4 (const char *src, unsigned char *dst)
|
||||||
inet_pton4 (const char *src, u_char *dst)
|
|
||||||
{
|
{
|
||||||
int saw_digit, octets, ch;
|
int saw_digit, octets, ch;
|
||||||
u_char tmp[NS_INADDRSZ], *tp;
|
unsigned char tmp[NS_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')
|
||||||
|
{
|
||||||
|
if (ch >= '0' && ch <= '9')
|
||||||
|
{
|
||||||
|
unsigned int new = *tp * 10 + (ch - '0');
|
||||||
|
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (saw_digit && *tp == 0)
|
||||||
u_int new = *tp * 10 + (ch - '0');
|
return 0;
|
||||||
|
if (new > 255)
|
||||||
if (saw_digit && *tp == 0)
|
return 0;
|
||||||
return (0);
|
*tp = new;
|
||||||
if (new > 255)
|
if (! saw_digit)
|
||||||
return (0);
|
{
|
||||||
*tp = new;
|
if (++octets > 4)
|
||||||
if (! saw_digit) {
|
return 0;
|
||||||
if (++octets > 4)
|
saw_digit = 1;
|
||||||
return (0);
|
}
|
||||||
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
|
}
|
||||||
return (0);
|
else
|
||||||
}
|
return 0;
|
||||||
if (octets < 4)
|
}
|
||||||
return (0);
|
if (octets < 4)
|
||||||
memcpy(dst, tmp, NS_INADDRSZ);
|
return 0;
|
||||||
return (1);
|
memcpy (dst, tmp, NS_INADDRSZ);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* int
|
/* Cconvert presentation level address to network order binary form.
|
||||||
* inet_pton6(src, dst)
|
*
|
||||||
* convert presentation level address to network order binary form.
|
|
||||||
* return:
|
* return:
|
||||||
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
|
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
|
||||||
* notice:
|
* notice:
|
||||||
* (1) does not touch `dst' unless it's returning 1.
|
* (1) does not touch `dst' unless it's returning 1.
|
||||||
* (2) :: in a full address is silently ignored.
|
* (2) :: in a full address is silently ignored.
|
||||||
* credit:
|
* credit:
|
||||||
* inspired by Mark Andrews.
|
* inspired by Mark Andrews.
|
||||||
* author:
|
* author:
|
||||||
* Paul Vixie, 1996.
|
* Paul Vixie, 1996.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
internal_function
|
inet_pton6 (const char *src, unsigned char *dst)
|
||||||
inet_pton6 (const char *src, u_char *dst)
|
|
||||||
{
|
{
|
||||||
static const char xdigits[] = "0123456789abcdef";
|
static const char xdigits[] = "0123456789abcdef";
|
||||||
u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
||||||
const char *curtok;
|
const char *curtok;
|
||||||
int ch, saw_xdigit;
|
int ch, saw_xdigit;
|
||||||
u_int val;
|
unsigned int val;
|
||||||
|
|
||||||
tp = memset(tmp, '\0', NS_IN6ADDRSZ);
|
tp = memset (tmp, '\0', NS_IN6ADDRSZ);
|
||||||
endp = tp + NS_IN6ADDRSZ;
|
endp = tp + NS_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 = tolower (*src++)) != '\0') {
|
while ((ch = tolower (*src++)) != '\0')
|
||||||
const char *pch;
|
{
|
||||||
|
const char *pch;
|
||||||
|
|
||||||
pch = strchr(xdigits, ch);
|
pch = strchr (xdigits, ch);
|
||||||
if (pch != NULL) {
|
if (pch != NULL)
|
||||||
val <<= 4;
|
{
|
||||||
val |= (pch - xdigits);
|
val <<= 4;
|
||||||
if (val > 0xffff)
|
val |= (pch - xdigits);
|
||||||
return (0);
|
if (val > 0xffff)
|
||||||
saw_xdigit = 1;
|
return 0;
|
||||||
continue;
|
saw_xdigit = 1;
|
||||||
}
|
continue;
|
||||||
if (ch == ':') {
|
|
||||||
curtok = src;
|
|
||||||
if (!saw_xdigit) {
|
|
||||||
if (colonp)
|
|
||||||
return (0);
|
|
||||||
colonp = tp;
|
|
||||||
continue;
|
|
||||||
} else if (*src == '\0') {
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
if (tp + NS_INT16SZ > endp)
|
|
||||||
return (0);
|
|
||||||
*tp++ = (u_char) (val >> 8) & 0xff;
|
|
||||||
*tp++ = (u_char) val & 0xff;
|
|
||||||
saw_xdigit = 0;
|
|
||||||
val = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
|
|
||||||
inet_pton4(curtok, tp) > 0) {
|
|
||||||
tp += NS_INADDRSZ;
|
|
||||||
saw_xdigit = 0;
|
|
||||||
break; /* '\0' was seen by inet_pton4(). */
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
if (saw_xdigit) {
|
if (ch == ':')
|
||||||
if (tp + NS_INT16SZ > endp)
|
{
|
||||||
return (0);
|
curtok = src;
|
||||||
*tp++ = (u_char) (val >> 8) & 0xff;
|
if (!saw_xdigit)
|
||||||
*tp++ = (u_char) val & 0xff;
|
{
|
||||||
|
if (colonp)
|
||||||
|
return 0;
|
||||||
|
colonp = tp;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (*src == '\0')
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (tp + NS_INT16SZ > endp)
|
||||||
|
return 0;
|
||||||
|
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||||
|
*tp++ = (unsigned char) val & 0xff;
|
||||||
|
saw_xdigit = 0;
|
||||||
|
val = 0;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (colonp != NULL) {
|
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
|
||||||
/*
|
inet_pton4 (curtok, tp) > 0)
|
||||||
* Since some memmove()'s erroneously fail to handle
|
{
|
||||||
* overlapping regions, we'll do the shift by hand.
|
tp += NS_INADDRSZ;
|
||||||
*/
|
saw_xdigit = 0;
|
||||||
const int n = tp - colonp;
|
break; /* '\0' was seen by inet_pton4. */
|
||||||
int i;
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (saw_xdigit)
|
||||||
|
{
|
||||||
|
if (tp + NS_INT16SZ > endp)
|
||||||
|
return 0;
|
||||||
|
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||||
|
*tp++ = (unsigned char) val & 0xff;
|
||||||
|
}
|
||||||
|
if (colonp != NULL)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Since some memmove's erroneously fail to handle
|
||||||
|
* overlapping regions, we'll do the shift by hand.
|
||||||
|
*/
|
||||||
|
const int n = tp - colonp;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (tp == endp)
|
if (tp == endp)
|
||||||
return (0);
|
return 0;
|
||||||
for (i = 1; i <= n; i++) {
|
for (i = 1; i <= n; i++)
|
||||||
endp[- i] = colonp[n - i];
|
{
|
||||||
colonp[n - i] = 0;
|
endp[- i] = colonp[n - i];
|
||||||
}
|
colonp[n - i] = 0;
|
||||||
tp = endp;
|
|
||||||
}
|
}
|
||||||
if (tp != endp)
|
tp = endp;
|
||||||
return (0);
|
}
|
||||||
memcpy(dst, tmp, NS_IN6ADDRSZ);
|
if (tp != endp)
|
||||||
return (1);
|
return 0;
|
||||||
|
memcpy (dst, tmp, NS_IN6ADDRSZ);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user