/[cvs]/eggdrop1.8/src/compat/inet_aton.c
ViewVC logotype

Contents of /eggdrop1.8/src/compat/inet_aton.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.1.1 - (show annotations) (download) (as text) (vendor branch)
Mon Jul 26 21:11:06 2010 UTC (9 years, 1 month ago) by simple
Branch: eggheads, MAIN
CVS Tags: v1, HEAD
Branch point for: gettext
Changes since 1.1: +0 -0 lines
File MIME type: text/x-chdr
Imported Eggdrop 1.6.20

1 /*
2 * inet_aton.c -- provides inet_aton() if necessary.
3 *
4 * $Id: inet_aton.c,v 1.1.1.1 2010/07/26 21:11:06 simple Exp $
5 */
6 /*
7 * Portions Copyright (C) 2000 - 2010 Eggheads Development Team
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 #include "main.h"
25 #include "inet_aton.h"
26
27 #ifndef HAVE_ISASCII
28 # define inet_isascii(x) 1 /* Let checks succeed if we don't have isascii(). */
29 #else
30 # define inet_isascii(x) egg_isascii(x)
31 #endif
32
33 #ifndef HAVE_INET_ATON
34 /*
35 * ++Copyright++ 1983, 1990, 1993
36 * -
37 * Copyright (c) 1983, 1990, 1993
38 * The Regents of the University of California. All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * SUCH DAMAGE.
67 * -
68 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
69 *
70 * Permission to use, copy, modify, and distribute this software for any
71 * purpose with or without fee is hereby granted, provided that the above
72 * copyright notice and this permission notice appear in all copies, and that
73 * the name of Digital Equipment Corporation not be used in advertising or
74 * publicity pertaining to distribution of the document or software without
75 * specific, written prior permission.
76 *
77 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
78 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
79 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
80 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
81 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
82 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
83 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
84 * SOFTWARE.
85 * --Copyright--
86 */
87
88 #if defined(LIBC_SCCS) && !defined(lint)
89 static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
90 static char rcsid[] = "$-Id: inet_addr.c,v 1.11 1999/04/29 18:19:53 drepper Exp $";
91 #endif /* LIBC_SCCS and not lint */
92
93 #include <sys/types.h>
94 #include <sys/param.h>
95 #include <ctype.h>
96
97 /*
98 * Check whether "cp" is a valid ascii representation
99 * of an Internet address and convert to a binary address.
100 * Returns 1 if the address is valid, 0 if not.
101 * This replaces inet_addr, the return value from which
102 * cannot distinguish between failure and a local broadcast address.
103 */
104 int egg_inet_aton(cp, addr)
105 const char *cp;
106 struct in_addr *addr;
107 {
108 static const u_32bit_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff };
109 register u_32bit_t val; /* changed from u_long --david */
110 register int base;
111 register int n;
112 register char c;
113 u_32bit_t parts[4];
114 register u_32bit_t *pp = parts;
115
116 egg_bzero(parts, sizeof(parts));
117
118 c = *cp;
119 for (;;) {
120 /*
121 * Collect number up to ``.''.
122 * Values are specified as for C:
123 * 0x=hex, 0=octal, isdigit=decimal.
124 */
125 if (!egg_isdigit(c))
126 goto ret_0;
127 base = 10;
128 if (c == '0') {
129 c = *++cp;
130 if (c == 'x' || c == 'X')
131 base = 16, c = *++cp;
132 else
133 base = 8;
134 }
135 val = 0;
136 for (;;) {
137 if (inet_isascii(c) && egg_isdigit(c)) {
138 val = (val * base) + (c - '0');
139 c = *++cp;
140 } else if (base == 16 && inet_isascii(c) && egg_isxdigit(c)) {
141 val = (val << 4) | (c + 10 - (egg_islower(c) ? 'a' : 'A'));
142 c = *++cp;
143 } else
144 break;
145 }
146 if (c == '.') {
147 /*
148 * Internet format:
149 * a.b.c.d
150 * a.b.c (with c treated as 16 bits)
151 * a.b (with b treated as 24 bits)
152 */
153 if (pp >= parts + 3)
154 goto ret_0;
155 *pp++ = val;
156 c = *++cp;
157 } else
158 break;
159 }
160 /*
161 * Check for trailing characters.
162 */
163 if (c != '\0' && (!inet_isascii(c) || !egg_isspace(c)))
164 goto ret_0;
165 /*
166 * Concoct the address according to
167 * the number of parts specified.
168 */
169 n = pp - parts + 1;
170
171 if (n == 0 || /* initial nondigit */
172 parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xff ||
173 val > max[n - 1])
174 goto ret_0;
175
176 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
177
178 if (addr)
179 addr->s_addr = htonl(val);
180 return 1;
181
182 ret_0:
183 return 0;
184 }
185 #endif /* !HAVE_INET_ATON */

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23