2
2
* inet_aton.c -- provides inet_aton() if necessary.
4
* $Id: inet_aton.c,v 1.7 2002/01/02 03:46:36 guppy Exp $
4
* $Id: inet_aton.c,v 1.15 2004/01/09 05:56:37 wcc Exp $
7
* Portions Copyright (C) 2000, 2001, 2002 Eggheads Development Team
7
* Portions Copyright (C) 2000, 2001, 2002, 2003, 2004 Eggheads Development Team
9
9
* This program is free software; you can redistribute it and/or
10
10
* modify it under the terms of the GNU General Public License
46
47
* documentation and/or other materials provided with the distribution.
47
48
* 3. All advertising materials mentioning features or use of this software
48
49
* must display the following acknowledgement:
49
* This product includes software developed by the University of
50
* California, Berkeley and its contributors.
50
* This product includes software developed by the University of
51
* California, Berkeley and its contributors.
51
52
* 4. Neither the name of the University nor the names of its contributors
52
53
* may be used to endorse or promote products derived from this software
53
54
* without specific prior written permission.
100
101
* This replaces inet_addr, the return value from which
101
102
* cannot distinguish between failure and a local broadcast address.
104
egg_inet_aton(cp, addr)
106
struct in_addr *addr;
104
int egg_inet_aton(cp, addr)
106
struct in_addr *addr;
108
static const u_32bit_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff };
109
register u_32bit_t val; /* changed from u_long --david */
114
register u_32bit_t *pp = parts;
116
egg_bzero(parts, sizeof (parts));
121
* Collect number up to ``.''.
122
* Values are specified as for C:
123
* 0x=hex, 0=octal, isdigit=decimal.
130
if (c == 'x' || c == 'X')
131
base = 16, c = *++cp;
137
if (isascii(c) && isdigit(c)) {
138
val = (val * base) + (c - '0');
140
} else if (base == 16 && isascii(c) && isxdigit(c)) {
142
(c + 10 - (islower(c) ? 'a' : 'A'));
151
* a.b.c (with c treated as 16 bits)
152
* a.b (with b treated as 24 bits)
162
* Check for trailing characters.
164
if (c != '\0' && (!isascii(c) || !isspace(c)))
167
* Concoct the address according to
168
* the number of parts specified.
172
if (n == 0 /* initial nondigit */
173
|| parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xff
177
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
180
addr->s_addr = htonl(val);
108
static const u_32bit_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff };
109
register u_32bit_t val; /* changed from u_long --david */
114
register u_32bit_t *pp = parts;
116
egg_bzero(parts, sizeof(parts));
121
* Collect number up to ``.''.
122
* Values are specified as for C:
123
* 0x=hex, 0=octal, isdigit=decimal.
130
if (c == 'x' || c == 'X')
131
base = 16, c = *++cp;
137
if (inet_isascii(c) && egg_isdigit(c)) {
138
val = (val * base) + (c - '0');
140
} else if (base == 16 && inet_isascii(c) && egg_isxdigit(c)) {
141
val = (val << 4) | (c + 10 - (egg_islower(c) ? 'a' : 'A'));
150
* a.b.c (with c treated as 16 bits)
151
* a.b (with b treated as 24 bits)
161
* Check for trailing characters.
163
if (c != '\0' && (!inet_isascii(c) || !egg_isspace(c)))
166
* Concoct the address according to
167
* the number of parts specified.
171
if (n == 0 || /* initial nondigit */
172
parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xff ||
176
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
179
addr->s_addr = htonl(val);
186
#endif /* HAVE_INET_ATON */
185
#endif /* !HAVE_INET_ATON */