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.c41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/lib/libc/net/inet_network.c b/src/lib/libc/net/inet_network.c
index 35105fa75a..8b26ba8ff9 100644
--- a/src/lib/libc/net/inet_network.c
+++ b/src/lib/libc/net/inet_network.c
@@ -1,5 +1,4 @@
1/* $NetBSD: inet_network.c,v 1.4 1995/02/25 06:20:45 cgd Exp $ */ 1/* $OpenBSD: inet_network.c,v 1.10 2005/08/06 20:30:03 espie Exp $ */
2
3/* 2/*
4 * Copyright (c) 1983, 1993 3 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 4 * The Regents of the University of California. All rights reserved.
@@ -12,11 +11,7 @@
12 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 14 * 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 15 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission. 16 * without specific prior written permission.
22 * 17 *
@@ -33,14 +28,6 @@
33 * SUCH DAMAGE. 28 * SUCH DAMAGE.
34 */ 29 */
35 30
36#if defined(LIBC_SCCS) && !defined(lint)
37#if 0
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 */
43
44#include <sys/types.h> 31#include <sys/types.h>
45#include <netinet/in.h> 32#include <netinet/in.h>
46#include <arpa/inet.h> 33#include <arpa/inet.h>
@@ -51,14 +38,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 38 * The library routines call this routine to interpret
52 * network numbers. 39 * network numbers.
53 */ 40 */
54u_long 41in_addr_t
55inet_network(cp) 42inet_network(const char *cp)
56 register const char *cp;
57{ 43{
58 register u_long val, base, n; 44 in_addr_t val, base, n;
59 register char c; 45 char c;
60 u_long parts[4], *pp = parts; 46 in_addr_t parts[4], *pp = parts;
61 register int i; 47 int i;
62 48
63again: 49again:
64 val = 0; base = 10; 50 val = 0; base = 10;
@@ -66,7 +52,7 @@ again:
66 base = 8, cp++; 52 base = 8, cp++;
67 if (*cp == 'x' || *cp == 'X') 53 if (*cp == 'x' || *cp == 'X')
68 base = 16, cp++; 54 base = 16, cp++;
69 while (c = *cp) { 55 while ((c = *cp)) {
70 if (isdigit(c)) { 56 if (isdigit(c)) {
71 val = (val * base) + (c - '0'); 57 val = (val * base) + (c - '0');
72 cp++; 58 cp++;
@@ -80,7 +66,7 @@ again:
80 break; 66 break;
81 } 67 }
82 if (*cp == '.') { 68 if (*cp == '.') {
83 if (pp >= parts + 4) 69 if (pp >= parts + 3)
84 return (INADDR_NONE); 70 return (INADDR_NONE);
85 *pp++ = val, cp++; 71 *pp++ = val, cp++;
86 goto again; 72 goto again;
@@ -89,11 +75,10 @@ again:
89 return (INADDR_NONE); 75 return (INADDR_NONE);
90 *pp++ = val; 76 *pp++ = val;
91 n = pp - parts; 77 n = pp - parts;
92 if (n > 4) 78 for (val = 0, i = 0; i < 4; i++) {
93 return (INADDR_NONE);
94 for (val = 0, i = 0; i < n; i++) {
95 val <<= 8; 79 val <<= 8;
96 val |= parts[i] & 0xff; 80 if (i < n)
81 val |= parts[i] & 0xff;
97 } 82 }
98 return (val); 83 return (val);
99} 84}