4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1987 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
28 /* from UCB 4.5 82/11/14 */
30 #include <sys/types.h>
32 #include <netinet/in.h>
35 * Internet address interpretation routine.
36 * All the network library routines call this
37 * routine to interpret entries in the data bases
38 * which are expected to be an address.
39 * The value returned is in network order.
45 register u_long val
, base
, n
;
47 u_long parts
[4], *pp
= parts
;
51 * Collect number up to ``.''.
52 * Values are specified as for C:
53 * 0x=hex, 0=octal, other=decimal.
57 if (*++cp
== 'x' || *cp
== 'X')
64 if ((c
- '0') >= base
)
66 val
= (val
* base
) + (c
- '0');
70 if (base
== 16 && isxdigit(c
)) {
71 val
= (val
<< 4) + (c
+ 10 - (islower(c
) ? 'a' : 'A'));
81 * a.b.c (with c treated as 16-bits)
82 * a.b (with b treated as 24 bits)
90 * Check for trailing characters.
92 if (*cp
&& !isspace(*cp
))
96 * Concoct the address according to
97 * the number of parts specified.
102 case 1: /* a -- 32 bits */
106 case 2: /* a.b -- 8.24 bits */
107 val
= (parts
[0] << 24) | (parts
[1] & 0xffffff);
110 case 3: /* a.b.c -- 8.8.16 bits */
111 val
= (parts
[0] << 24) | ((parts
[1] & 0xff) << 16) |
115 case 4: /* a.b.c.d -- 8.8.8.8 bits */
116 val
= (parts
[0] << 24) | ((parts
[1] & 0xff) << 16) |
117 ((parts
[2] & 0xff) << 8) | (parts
[3] & 0xff);