2
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3
* Copyright (c) 1996,1999 by Internet Software Consortium.
5
* Permission to use, copy, modify, and distribute this software for any
6
* purpose with or without fee is hereby granted, provided that the above
7
* copyright notice and this permission notice appear in all copies.
9
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
/* modified to make it compile with kdewin32 */
19
//#include "kdewin32/port_before.h"
20
#include <sys/param.h>
21
#include "kdewin32/sys/types.h"
22
#include "kdewin32/sys/socket.h"
23
#include "kdewin32/netinet/in.h"
24
#include "kdewin32/arpa/inet.h"
25
//#include "kdewin32/arpa/nameser.h"
26
#include "kdewin32/string.h"
27
#include "kdewin32/errno.h"
28
//#include "kdewin32/port_after.h"
30
#define NS_INADDRSZ 4 /*%< IPv4 T_A */
31
#define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */
32
#define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */
35
* WARNING: Don't even consider trying to compile this on a system where
36
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
39
static int inet_pton4 __P((const char *src, u_char *dst));
40
static int inet_pton6 __P((const char *src, u_char *dst));
43
* inet_pton(af, src, dst)
44
* convert from presentation format (which usually means ASCII printable)
45
* to network format (which is usually some kind of binary format).
47
* 1 if the address was valid for the specified address family
48
* 0 if the address wasn't valid (`dst' is untouched in this case)
49
* -1 if some other error occurred (`dst' is untouched in this case, too)
54
kde_inet_pton(af, src, dst)
61
return (inet_pton4(src, dst));
63
return (inet_pton6(src, dst));
72
* inet_pton4(src, dst)
73
* like inet_aton() but without all the hexadecimal and shorthand.
75
* 1 if `src' is a valid dotted quad, else 0.
77
* does not touch `dst' unless it's returning 1.
86
static const char digits[] = "0123456789";
87
int saw_digit, octets, ch;
88
u_char tmp[NS_INADDRSZ], *tp;
93
while ((ch = *src++) != '\0') {
96
if ((pch = strchr(digits, ch)) != NULL) {
97
u_int new = *tp * 10 + (pch - digits);
99
if (saw_digit && *tp == 0)
109
} else if (ch == '.' && saw_digit) {
119
memcpy(dst, tmp, NS_INADDRSZ);
124
* inet_pton6(src, dst)
125
* convert presentation level address to network order binary form.
127
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
129
* (1) does not touch `dst' unless it's returning 1.
130
* (2) :: in a full address is silently ignored.
132
* inspired by Mark Andrews.
141
static const char xdigits_l[] = "0123456789abcdef",
142
xdigits_u[] = "0123456789ABCDEF";
143
u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
144
const char *xdigits, *curtok;
145
int ch, seen_xdigits;
148
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
149
endp = tp + NS_IN6ADDRSZ;
151
/* Leading :: requires some special handling. */
158
while ((ch = *src++) != '\0') {
161
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
162
pch = strchr((xdigits = xdigits_u), ch);
165
val |= (pch - xdigits);
166
if (++seen_xdigits > 4)
177
} else if (*src == '\0') {
180
if (tp + NS_INT16SZ > endp)
182
*tp++ = (u_char) (val >> 8) & 0xff;
183
*tp++ = (u_char) val & 0xff;
188
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
189
inet_pton4(curtok, tp) > 0) {
192
break; /*%< '\\0' was seen by inet_pton4(). */
197
if (tp + NS_INT16SZ > endp)
199
*tp++ = (u_char) (val >> 8) & 0xff;
200
*tp++ = (u_char) val & 0xff;
202
if (colonp != NULL) {
204
* Since some memmove()'s erroneously fail to handle
205
* overlapping regions, we'll do the shift by hand.
207
const int n = tp - colonp;
212
for (i = 1; i <= n; i++) {
213
endp[- i] = colonp[n - i];
220
memcpy(dst, tmp, NS_IN6ADDRSZ);