Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/ntp/lib/isc/inet_aton.c
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
* of an Internet address and convert to a binary address. | * of an Internet address and convert to a binary address. | ||||
* Returns 1 if the address is valid, 0 if not. | * Returns 1 if the address is valid, 0 if not. | ||||
* This replaces inet_addr, the return value from which | * This replaces inet_addr, the return value from which | ||||
* cannot distinguish between failure and a local broadcast address. | * cannot distinguish between failure and a local broadcast address. | ||||
*/ | */ | ||||
int | int | ||||
isc_net_aton(const char *cp, struct in_addr *addr) { | isc_net_aton(const char *cp, struct in_addr *addr) { | ||||
unsigned long val; | unsigned long val; | ||||
int base, n; | int base; | ||||
unsigned char c; | unsigned char c; | ||||
isc_uint8_t parts[4]; | isc_uint8_t parts[4]; | ||||
isc_uint8_t *pp = parts; | isc_uint8_t *pp = parts; | ||||
int digit; | int digit; | ||||
c = *cp; | c = *cp; | ||||
for (;;) { | for (;;) { | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | isc_net_aton(const char *cp, struct in_addr *addr) { | ||||
* Did we get a valid digit? | * Did we get a valid digit? | ||||
*/ | */ | ||||
if (!digit) | if (!digit) | ||||
return (0); | return (0); | ||||
/* | /* | ||||
* Concoct the address according to | * Concoct the address according to | ||||
* the number of parts specified. | * the number of parts specified. | ||||
*/ | */ | ||||
n = pp - parts + 1; | switch (pp - parts + 1) { | ||||
switch (n) { | |||||
case 1: /* a -- 32 bits */ | case 1: /* a -- 32 bits */ | ||||
break; | break; | ||||
case 2: /* a.b -- 8.24 bits */ | case 2: /* a.b -- 8.24 bits */ | ||||
if (val > 0xffffffU) | if (val > 0xffffffU) | ||||
return (0); | return (0); | ||||
val |= parts[0] << 24; | val |= parts[0] << 24; | ||||
break; | break; | ||||
Show All 18 Lines |