summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/inet_network.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/inet_network.c')
-rw-r--r--src/lib/libc/net/inet_network.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/lib/libc/net/inet_network.c b/src/lib/libc/net/inet_network.c
index 35105fa75a..5e36f78069 100644
--- a/src/lib/libc/net/inet_network.c
+++ b/src/lib/libc/net/inet_network.c
@@ -1,5 +1,3 @@
1/* $NetBSD: inet_network.c,v 1.4 1995/02/25 06:20:45 cgd Exp $ */
2
3/* 1/*
4 * Copyright (c) 1983, 1993 2 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 3 * The Regents of the University of California. All rights reserved.
@@ -12,11 +10,7 @@
12 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 13 * 3. Neither the name of the University nor the names of its contributors
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software 14 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission. 15 * without specific prior written permission.
22 * 16 *
@@ -34,11 +28,7 @@
34 */ 28 */
35 29
36#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
37#if 0 31static char rcsid[] = "$OpenBSD: inet_network.c,v 1.8 2003/06/02 20:18:35 millert Exp $";
38static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93";
39#else
40static char rcsid[] = "$NetBSD: inet_network.c,v 1.4 1995/02/25 06:20:45 cgd Exp $";
41#endif
42#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
43 33
44#include <sys/types.h> 34#include <sys/types.h>
@@ -51,13 +41,13 @@ static char rcsid[] = "$NetBSD: inet_network.c,v 1.4 1995/02/25 06:20:45 cgd Exp
51 * The library routines call this routine to interpret 41 * The library routines call this routine to interpret
52 * network numbers. 42 * network numbers.
53 */ 43 */
54u_long 44in_addr_t
55inet_network(cp) 45inet_network(cp)
56 register const char *cp; 46 register const char *cp;
57{ 47{
58 register u_long val, base, n; 48 register in_addr_t val, base, n;
59 register char c; 49 register char c;
60 u_long parts[4], *pp = parts; 50 in_addr_t parts[4], *pp = parts;
61 register int i; 51 register int i;
62 52
63again: 53again:
@@ -66,7 +56,7 @@ again:
66 base = 8, cp++; 56 base = 8, cp++;
67 if (*cp == 'x' || *cp == 'X') 57 if (*cp == 'x' || *cp == 'X')
68 base = 16, cp++; 58 base = 16, cp++;
69 while (c = *cp) { 59 while ((c = *cp)) {
70 if (isdigit(c)) { 60 if (isdigit(c)) {
71 val = (val * base) + (c - '0'); 61 val = (val * base) + (c - '0');
72 cp++; 62 cp++;
@@ -80,7 +70,7 @@ again:
80 break; 70 break;
81 } 71 }
82 if (*cp == '.') { 72 if (*cp == '.') {
83 if (pp >= parts + 4) 73 if (pp >= parts + 3)
84 return (INADDR_NONE); 74 return (INADDR_NONE);
85 *pp++ = val, cp++; 75 *pp++ = val, cp++;
86 goto again; 76 goto again;
@@ -89,11 +79,10 @@ again:
89 return (INADDR_NONE); 79 return (INADDR_NONE);
90 *pp++ = val; 80 *pp++ = val;
91 n = pp - parts; 81 n = pp - parts;
92 if (n > 4) 82 for (val = 0, i = 0; i < 4; i++) {
93 return (INADDR_NONE);
94 for (val = 0, i = 0; i < n; i++) {
95 val <<= 8; 83 val <<= 8;
96 val |= parts[i] & 0xff; 84 if (i < n)
85 val |= parts[i] & 0xff;
97 } 86 }
98 return (val); 87 return (val);
99} 88}