diff options
| author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-19 23:27:12 +0200 |
|---|---|---|
| committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-19 23:27:12 +0200 |
| commit | 26fbe7f1e68bb0c96da32491efcf3696fe6c299b (patch) | |
| tree | c4d95289187a64e9c7517bf73d8208026c3d2fb3 /gl/inet_ntop.c | |
| parent | 5f79e3e9f62ca5487d9881973149136ba1d19d3e (diff) | |
| download | monitoring-plugins-26fbe7f1e68bb0c96da32491efcf3696fe6c299b.tar.gz | |
Sync with the latest Gnulib code (6f2d632)
Diffstat (limited to 'gl/inet_ntop.c')
| -rw-r--r-- | gl/inet_ntop.c | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c index baaa23f8..fdfd21dc 100644 --- a/gl/inet_ntop.c +++ b/gl/inet_ntop.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form | 1 | /* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form |
| 2 | 2 | ||
| 3 | Copyright (C) 2005-2006, 2008-2010 Free Software Foundation, Inc. | 3 | Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
| @@ -13,8 +13,7 @@ | |||
| 13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
| 14 | 14 | ||
| 15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software Foundation, | 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
| 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 18 | 17 | ||
| 19 | /* | 18 | /* |
| 20 | * Copyright (c) 1996-1999 by Internet Software Consortium. | 19 | * Copyright (c) 1996-1999 by Internet Software Consortium. |
| @@ -38,30 +37,53 @@ | |||
| 38 | /* Specification. */ | 37 | /* Specification. */ |
| 39 | #include <arpa/inet.h> | 38 | #include <arpa/inet.h> |
| 40 | 39 | ||
| 41 | #include <stdio.h> | 40 | /* Use this to suppress gcc's "...may be used before initialized" warnings. |
| 42 | #include <string.h> | 41 | Beware: The Code argument must not contain commas. */ |
| 43 | #include <errno.h> | 42 | #ifndef IF_LINT |
| 43 | # ifdef lint | ||
| 44 | # define IF_LINT(Code) Code | ||
| 45 | # else | ||
| 46 | # define IF_LINT(Code) /* empty */ | ||
| 47 | # endif | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #if HAVE_DECL_INET_NTOP | ||
| 51 | |||
| 52 | # undef inet_ntop | ||
| 53 | |||
| 54 | const char * | ||
| 55 | rpl_inet_ntop (int af, const void *restrict src, | ||
| 56 | char *restrict dst, socklen_t cnt) | ||
| 57 | { | ||
| 58 | return inet_ntop (af, src, dst, cnt); | ||
| 59 | } | ||
| 44 | 60 | ||
| 45 | #define NS_IN6ADDRSZ 16 | 61 | #else |
| 46 | #define NS_INT16SZ 2 | 62 | |
| 63 | # include <stdio.h> | ||
| 64 | # include <string.h> | ||
| 65 | # include <errno.h> | ||
| 66 | |||
| 67 | # define NS_IN6ADDRSZ 16 | ||
| 68 | # define NS_INT16SZ 2 | ||
| 47 | 69 | ||
| 48 | /* | 70 | /* |
| 49 | * WARNING: Don't even consider trying to compile this on a system where | 71 | * WARNING: Don't even consider trying to compile this on a system where |
| 50 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | 72 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. |
| 51 | */ | 73 | */ |
| 52 | typedef int verify_int_size[2 * sizeof (int) - 7]; | 74 | typedef int verify_int_size[4 <= sizeof (int) ? 1 : -1]; |
| 53 | 75 | ||
| 54 | static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t size); | 76 | static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t size); |
| 55 | #if HAVE_IPV6 | 77 | # if HAVE_IPV6 |
| 56 | static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t size); | 78 | static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t size); |
| 57 | #endif | 79 | # endif |
| 58 | 80 | ||
| 59 | 81 | ||
| 60 | /* char * | 82 | /* char * |
| 61 | * inet_ntop(af, src, dst, size) | 83 | * inet_ntop(af, src, dst, size) |
| 62 | * convert a network format address to presentation format. | 84 | * convert a network format address to presentation format. |
| 63 | * return: | 85 | * return: |
| 64 | * pointer to presentation format address (`dst'), or NULL (see errno). | 86 | * pointer to presentation format address ('dst'), or NULL (see errno). |
| 65 | * author: | 87 | * author: |
| 66 | * Paul Vixie, 1996. | 88 | * Paul Vixie, 1996. |
| 67 | */ | 89 | */ |
| @@ -71,15 +93,15 @@ inet_ntop (int af, const void *restrict src, | |||
| 71 | { | 93 | { |
| 72 | switch (af) | 94 | switch (af) |
| 73 | { | 95 | { |
| 74 | #if HAVE_IPV4 | 96 | # if HAVE_IPV4 |
| 75 | case AF_INET: | 97 | case AF_INET: |
| 76 | return (inet_ntop4 (src, dst, cnt)); | 98 | return (inet_ntop4 (src, dst, cnt)); |
| 77 | #endif | 99 | # endif |
| 78 | 100 | ||
| 79 | #if HAVE_IPV6 | 101 | # if HAVE_IPV6 |
| 80 | case AF_INET6: | 102 | case AF_INET6: |
| 81 | return (inet_ntop6 (src, dst, cnt)); | 103 | return (inet_ntop6 (src, dst, cnt)); |
| 82 | #endif | 104 | # endif |
| 83 | 105 | ||
| 84 | default: | 106 | default: |
| 85 | errno = EAFNOSUPPORT; | 107 | errno = EAFNOSUPPORT; |
| @@ -92,7 +114,7 @@ inet_ntop (int af, const void *restrict src, | |||
| 92 | * inet_ntop4(src, dst, size) | 114 | * inet_ntop4(src, dst, size) |
| 93 | * format an IPv4 address | 115 | * format an IPv4 address |
| 94 | * return: | 116 | * return: |
| 95 | * `dst' (as a const) | 117 | * 'dst' (as a const) |
| 96 | * notes: | 118 | * notes: |
| 97 | * (1) uses no statics | 119 | * (1) uses no statics |
| 98 | * (2) takes a u_char* not an in_addr as input | 120 | * (2) takes a u_char* not an in_addr as input |
| @@ -118,7 +140,7 @@ inet_ntop4 (const unsigned char *src, char *dst, socklen_t size) | |||
| 118 | return strcpy (dst, tmp); | 140 | return strcpy (dst, tmp); |
| 119 | } | 141 | } |
| 120 | 142 | ||
| 121 | #if HAVE_IPV6 | 143 | # if HAVE_IPV6 |
| 122 | 144 | ||
| 123 | /* const char * | 145 | /* const char * |
| 124 | * inet_ntop6(src, dst, size) | 146 | * inet_ntop6(src, dst, size) |
| @@ -154,6 +176,8 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) | |||
| 154 | words[i / 2] = (src[i] << 8) | src[i + 1]; | 176 | words[i / 2] = (src[i] << 8) | src[i + 1]; |
| 155 | best.base = -1; | 177 | best.base = -1; |
| 156 | cur.base = -1; | 178 | cur.base = -1; |
| 179 | IF_LINT(best.len = 0); | ||
| 180 | IF_LINT(cur.len = 0); | ||
| 157 | for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) | 181 | for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) |
| 158 | { | 182 | { |
| 159 | if (words[i] == 0) | 183 | if (words[i] == 0) |
| @@ -231,4 +255,6 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) | |||
| 231 | return strcpy (dst, tmp); | 255 | return strcpy (dst, tmp); |
| 232 | } | 256 | } |
| 233 | 257 | ||
| 258 | # endif | ||
| 259 | |||
| 234 | #endif | 260 | #endif |
