diff options
Diffstat (limited to 'src/lib/libc/net/inet_addr.c')
-rw-r--r-- | src/lib/libc/net/inet_addr.c | 82 |
1 files changed, 57 insertions, 25 deletions
diff --git a/src/lib/libc/net/inet_addr.c b/src/lib/libc/net/inet_addr.c index 99a6f66ad2..ef8ee4963b 100644 --- a/src/lib/libc/net/inet_addr.c +++ b/src/lib/libc/net/inet_addr.c | |||
@@ -1,7 +1,11 @@ | |||
1 | /* $OpenBSD: inet_addr.c,v 1.4 1997/03/13 19:07:29 downsj Exp $ */ | ||
2 | |||
1 | /* | 3 | /* |
4 | * ++Copyright++ 1983, 1990, 1993 | ||
5 | * - | ||
2 | * Copyright (c) 1983, 1990, 1993 | 6 | * Copyright (c) 1983, 1990, 1993 |
3 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
4 | * | 8 | * |
5 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
7 | * are met: | 11 | * are met: |
@@ -12,12 +16,12 @@ | |||
12 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
14 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
15 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
16 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
17 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
18 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 23 | * without specific prior written permission. |
20 | * | 24 | * |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -29,12 +33,38 @@ | |||
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | * SUCH DAMAGE. | 35 | * SUCH DAMAGE. |
36 | * - | ||
37 | * Portions Copyright (c) 1993 by Digital Equipment Corporation. | ||
38 | * | ||
39 | * Permission to use, copy, modify, and distribute this software for any | ||
40 | * purpose with or without fee is hereby granted, provided that the above | ||
41 | * copyright notice and this permission notice appear in all copies, and that | ||
42 | * the name of Digital Equipment Corporation not be used in advertising or | ||
43 | * publicity pertaining to distribution of the document or software without | ||
44 | * specific, written prior permission. | ||
45 | * | ||
46 | * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL | ||
47 | * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES | ||
48 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT | ||
49 | * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
50 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
51 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
52 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
53 | * SOFTWARE. | ||
54 | * - | ||
55 | * --Copyright-- | ||
32 | */ | 56 | */ |
33 | 57 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char rcsid[] = "$OpenBSD: inet_addr.c,v 1.3 1996/08/19 08:29:08 tholo Exp $"; | 59 | #if 0 |
60 | static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; | ||
61 | static char rcsid[] = "$From: inet_addr.c,v 8.5 1996/08/05 08:31:35 vixie Exp $"; | ||
62 | #else | ||
63 | static char rcsid[] = "$OpenBSD: inet_addr.c,v 1.4 1997/03/13 19:07:29 downsj Exp $"; | ||
64 | #endif | ||
36 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
37 | 66 | ||
67 | #include <sys/types.h> | ||
38 | #include <sys/param.h> | 68 | #include <sys/param.h> |
39 | #include <netinet/in.h> | 69 | #include <netinet/in.h> |
40 | #include <arpa/inet.h> | 70 | #include <arpa/inet.h> |
@@ -73,50 +103,52 @@ inet_aton(cp, addr) | |||
73 | u_int parts[4]; | 103 | u_int parts[4]; |
74 | register u_int *pp = parts; | 104 | register u_int *pp = parts; |
75 | 105 | ||
106 | c = *cp; | ||
76 | for (;;) { | 107 | for (;;) { |
77 | /* | 108 | /* |
78 | * Collect number up to ``.''. | 109 | * Collect number up to ``.''. |
79 | * Values are specified as for C: | 110 | * Values are specified as for C: |
80 | * 0x=hex, 0=octal, other=decimal. | 111 | * 0x=hex, 0=octal, isdigit=decimal. |
81 | */ | 112 | */ |
113 | if (!isdigit(c)) | ||
114 | return (0); | ||
82 | val = 0; base = 10; | 115 | val = 0; base = 10; |
83 | if (*cp == '0') { | 116 | if (c == '0') { |
84 | if (*++cp == 'x' || *cp == 'X') | 117 | c = *++cp; |
85 | base = 16, cp++; | 118 | if (c == 'x' || c == 'X') |
119 | base = 16, c = *++cp; | ||
86 | else | 120 | else |
87 | base = 8; | 121 | base = 8; |
88 | } | 122 | } |
89 | while ((c = *cp) != '\0') { | 123 | for (;;) { |
90 | if (isascii(c) && isdigit(c)) { | 124 | if (isascii(c) && isdigit(c)) { |
91 | val = (val * base) + (c - '0'); | 125 | val = (val * base) + (c - '0'); |
92 | cp++; | 126 | c = *++cp; |
93 | continue; | 127 | } else if (base == 16 && isascii(c) && isxdigit(c)) { |
94 | } | 128 | val = (val << 4) | |
95 | if (base == 16 && isascii(c) && isxdigit(c)) { | ||
96 | val = (val << 4) + | ||
97 | (c + 10 - (islower(c) ? 'a' : 'A')); | 129 | (c + 10 - (islower(c) ? 'a' : 'A')); |
98 | cp++; | 130 | c = *++cp; |
99 | continue; | 131 | } else |
100 | } | 132 | break; |
101 | break; | ||
102 | } | 133 | } |
103 | if (*cp == '.') { | 134 | if (c == '.') { |
104 | /* | 135 | /* |
105 | * Internet format: | 136 | * Internet format: |
106 | * a.b.c.d | 137 | * a.b.c.d |
107 | * a.b.c (with c treated as 16-bits) | 138 | * a.b.c (with c treated as 16 bits) |
108 | * a.b (with b treated as 24 bits) | 139 | * a.b (with b treated as 24 bits) |
109 | */ | 140 | */ |
110 | if (pp >= parts + 3 || val > 0xff) | 141 | if (pp >= parts + 3) |
111 | return (0); | 142 | return (0); |
112 | *pp++ = val, cp++; | 143 | *pp++ = val; |
144 | c = *++cp; | ||
113 | } else | 145 | } else |
114 | break; | 146 | break; |
115 | } | 147 | } |
116 | /* | 148 | /* |
117 | * Check for trailing characters. | 149 | * Check for trailing characters. |
118 | */ | 150 | */ |
119 | if (*cp && (!isascii(*cp) || !isspace(*cp))) | 151 | if (c != '\0' && (!isascii(c) || !isspace(c))) |
120 | return (0); | 152 | return (0); |
121 | /* | 153 | /* |
122 | * Concoct the address according to | 154 | * Concoct the address according to |