| @@ -1,38 +1,38 @@ | | | @@ -1,38 +1,38 @@ |
1 | /* $NetBSD: inet_ntop.c,v 1.6 2008/06/21 20:41:48 christos Exp $ */ | | 1 | /* $NetBSD: inet_ntop.c,v 1.7 2008/09/11 15:40:43 christos Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") | | 4 | * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") |
5 | * Copyright (c) 1996-1999 by Internet Software Consortium. | | 5 | * Copyright (c) 1996-1999 by Internet Software Consortium. |
6 | * | | 6 | * |
7 | * Permission to use, copy, modify, and distribute this software for any | | 7 | * Permission to use, copy, modify, and distribute this software for any |
8 | * purpose with or without fee is hereby granted, provided that the above | | 8 | * purpose with or without fee is hereby granted, provided that the above |
9 | * copyright notice and this permission notice appear in all copies. | | 9 | * copyright notice and this permission notice appear in all copies. |
10 | * | | 10 | * |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES | | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR | | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | | 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | | 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
17 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | | 17 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
18 | */ | | 18 | */ |
19 | | | 19 | |
20 | #include <sys/cdefs.h> | | 20 | #include <sys/cdefs.h> |
21 | #if defined(LIBC_SCCS) && !defined(lint) | | 21 | #if defined(LIBC_SCCS) && !defined(lint) |
22 | #if 0 | | 22 | #if 0 |
23 | static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp"; | | 23 | static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp"; |
24 | #else | | 24 | #else |
25 | __RCSID("$NetBSD: inet_ntop.c,v 1.6 2008/06/21 20:41:48 christos Exp $"); | | 25 | __RCSID("$NetBSD: inet_ntop.c,v 1.7 2008/09/11 15:40:43 christos Exp $"); |
26 | #endif | | 26 | #endif |
27 | #endif /* LIBC_SCCS and not lint */ | | 27 | #endif /* LIBC_SCCS and not lint */ |
28 | | | 28 | |
29 | #include "port_before.h" | | 29 | #include "port_before.h" |
30 | | | 30 | |
31 | #include "namespace.h" | | 31 | #include "namespace.h" |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/types.h> | | 33 | #include <sys/types.h> |
34 | #include <sys/socket.h> | | 34 | #include <sys/socket.h> |
35 | | | 35 | |
36 | #include <netinet/in.h> | | 36 | #include <netinet/in.h> |
37 | #include <arpa/inet.h> | | 37 | #include <arpa/inet.h> |
38 | #include <arpa/nameser.h> | | 38 | #include <arpa/nameser.h> |
| @@ -197,28 +197,27 @@ inet_ntop6(src, dst, size) | | | @@ -197,28 +197,27 @@ inet_ntop6(src, dst, size) |
197 | continue; | | 197 | continue; |
198 | } | | 198 | } |
199 | /* Are we following an initial run of 0x00s or any real hex? */ | | 199 | /* Are we following an initial run of 0x00s or any real hex? */ |
200 | if (i != 0) { | | 200 | if (i != 0) { |
201 | if (tp + 1 >= ep) | | 201 | if (tp + 1 >= ep) |
202 | return (NULL); | | 202 | return (NULL); |
203 | *tp++ = ':'; | | 203 | *tp++ = ':'; |
204 | } | | 204 | } |
205 | /* Is this address an encapsulated IPv4? */ | | 205 | /* Is this address an encapsulated IPv4? */ |
206 | if (i == 6 && best.base == 0 && | | 206 | if (i == 6 && best.base == 0 && |
207 | (best.len == 6 || | | 207 | (best.len == 6 || |
208 | (best.len == 7 && words[7] != 0x0001) || | | 208 | (best.len == 7 && words[7] != 0x0001) || |
209 | (best.len == 5 && words[5] == 0xffff))) { | | 209 | (best.len == 5 && words[5] == 0xffff))) { |
210 | if (!inet_ntop4(src+12, tp, | | 210 | if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp))) |
211 | (socklen_t)(sizeof(tmp) - (ep - tp)))) | | | |
212 | return (NULL); | | 211 | return (NULL); |
213 | tp += strlen(tp); | | 212 | tp += strlen(tp); |
214 | break; | | 213 | break; |
215 | } | | 214 | } |
216 | advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]); | | 215 | advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]); |
217 | if (advance <= 0 || advance >= ep - tp) | | 216 | if (advance <= 0 || advance >= ep - tp) |
218 | return (NULL); | | 217 | return (NULL); |
219 | tp += advance; | | 218 | tp += advance; |
220 | } | | 219 | } |
221 | /* Was it a trailing run of 0x00's? */ | | 220 | /* Was it a trailing run of 0x00's? */ |
222 | if (best.base != -1 && (best.base + best.len) == | | 221 | if (best.base != -1 && (best.base + best.len) == |
223 | (NS_IN6ADDRSZ / NS_INT16SZ)) { | | 222 | (NS_IN6ADDRSZ / NS_INT16SZ)) { |
224 | if (tp + 1 >= ep) | | 223 | if (tp + 1 >= ep) |