1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #if defined(LIBC_SCCS) && !defined(lint)
8: static char sccsid[] = "@(#)inet_addr.c 5.2.1 (2.11BSD GTE) 1/1/94";
9: #endif
10:
11: #include <sys/types.h>
12: #include <ctype.h>
13: #include <netinet/in.h>
14:
15: /*
16: * Internet address interpretation routine.
17: * All the network library routines call this
18: * routine to interpret entries in the data bases
19: * which are expected to be an address.
20: * The value returned is in network order.
21: */
22: u_long
23: inet_addr(cp)
24: register char *cp;
25: {
26: register u_long val, base;
27: register u_int n; /* can't switch on longs - should be an int anyway */
28: register char c;
29: u_long parts[4], *pp = parts;
30:
31: again:
32: /*
33: * Collect number up to ``.''.
34: * Values are specified as for C:
35: * 0x=hex, 0=octal, other=decimal.
36: */
37: val = 0; base = 10;
38: if (*cp == '0')
39: base = 8, cp++;
40: if (*cp == 'x' || *cp == 'X')
41: base = 16, cp++;
42: while (c = *cp) {
43: if (isdigit(c)) {
44: val = (val * base) + (c - '0');
45: cp++;
46: continue;
47: }
48: if (base == 16 && isxdigit(c)) {
49: val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
50: cp++;
51: continue;
52: }
53: break;
54: }
55: if (*cp == '.') {
56: /*
57: * Internet format:
58: * a.b.c.d
59: * a.b.c (with c treated as 16-bits)
60: * a.b (with b treated as 24 bits)
61: */
62: if (pp >= parts + 4)
63: return (-1);
64: *pp++ = val, cp++;
65: goto again;
66: }
67: /*
68: * Check for trailing characters.
69: */
70: if (*cp && !isspace(*cp))
71: return (-1);
72: *pp++ = val;
73: /*
74: * Concoct the address according to
75: * the number of parts specified.
76: */
77: n = pp - parts;
78: switch (n) {
79:
80: case 1: /* a -- 32 bits */
81: val = parts[0];
82: break;
83:
84: case 2: /* a.b -- 8.24 bits */
85: val = (parts[0] << 24) | (parts[1] & 0xffffff);
86: break;
87:
88: case 3: /* a.b.c -- 8.8.16 bits */
89: val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) |
90: (parts[2] & 0xffffL);
91: break;
92:
93: case 4: /* a.b.c.d -- 8.8.8.8 bits */
94: val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) |
95: ((parts[2] & 0xff) << 8) | (parts[3] & 0xff);
96: break;
97:
98: default:
99: return (-1);
100: }
101: val = htonl(val);
102: return (val);
103: }
Defined functions
inet_addr
defined in line
22; used 62 times
- in /usr/include/arpa/inet.h line
24
- in /usr/src/bin/hostid.c line
41
- in /usr/src/bin/ping/ping.c line
244
- in /usr/src/include/arpa/inet.h line
24
- in /usr/src/lib/libc/net/hosttable/gethostent.c line
88
- in /usr/src/lib/libc/net/named/gethnamadr.c line
327
- in /usr/src/lib/libc/net/res_init.c line
60,
96
- in /usr/src/libexec/identd/src/identd.c line
560
- in /usr/src/libexec/identd/src/itest.c line
138,
148
- in /usr/src/libexec/identd/src/parse.c line
278-280(2),
365
- in /usr/src/libexec/identd/testdir/test1.c line
83-85(2)
- in /usr/src/new/nntp/xfer/nntpxfer.c line
50,
153
- in /usr/src/sbin/ifconfig/ifconfig.c line
434
- in /usr/src/sbin/route/route.c line
492
- in /usr/src/sbin/routed/startup.c line
329,
353
- in /usr/src/sbin/routed/tools/query.c line
107
- in /usr/src/sbin/routed/tools/trace.c line
83
- in /usr/src/ucb/PORT/systat/netcmds.c line
99
- in /usr/src/ucb/finger/net.c line
44,
50
- in /usr/src/ucb/ftp/ftp.c line
103
- in /usr/src/ucb/telnet.c line
2033
- in /usr/src/ucb/tftp/main.c line
177
- in /usr/src/ucb/tn3270/tn3270.c line
243
- in /usr/src/usr.bin/uucp/cico.c line
159
- in /usr/src/usr.sbin/arp/arp.c line
116,
170,
221
- in /usr/src/usr.sbin/htable/htable.c line
415
- in /usr/src/usr.sbin/named/named/db_load.c line
277,
363,
866
- in /usr/src/usr.sbin/named/named/ns_init.c line
221,
228,
441
- in /usr/src/usr.sbin/named/tools/nslookup/main.c line
209,
333,
406
- in /usr/src/usr.sbin/named/tools/nstest.c line
91,
111,
241
- in /usr/src/usr.sbin/ntp/ntp.c line
179
- in /usr/src/usr.sbin/ntp/ntpd.c line
1088
- in /usr/src/usr.sbin/ntp/ntpdc.c line
270
- in /usr/src/usr.sbin/sendmail.MX/aux/mconnect.c line
50,
90
- in /usr/src/usr.sbin/sendmail.MX/src/daemon.c line
321,
512
- in /usr/src/usr.sbin/sendmail/aux/mconnect.c line
47,
94
- in /usr/src/usr.sbin/sendmail/src/daemon.c line
321,
512
- in /usr/src/usr.sbin/traceroute/traceroute.c line
229,
360,
438
Defined variables
sccsid
defined in line
8;
never used