diff options
author | Tim Rühsen <tim.ruehsen@gmx.de> | 2019-02-08 13:04:47 +0000 |
---|---|---|
committer | Tim Rühsen <tim.ruehsen@gmx.de> | 2019-02-08 13:04:47 +0000 |
commit | aa33d738ec96f86671c2d4bb254d8e30a57213cc (patch) | |
tree | a52b2fa219a5484bc315e10c4fd3638ce1fc67d7 /lib | |
parent | 71afdf09b820180f3125eeefaeb787155e7333fc (diff) | |
parent | db5ac39e61fe1fc20bf3f69f603516803631cbeb (diff) | |
download | gnutls-aa33d738ec96f86671c2d4bb254d8e30a57213cc.tar.gz |
Merge branch 'tmp-gnulib-ntop' into 'master'
Use inet_ntop() from gnulib
See merge request gnutls/gnutls!912
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/system.h | 7 | ||||
-rw-r--r-- | lib/system/inet_ntop.c | 250 | ||||
-rw-r--r-- | lib/x509/ip.c | 5 |
4 files changed, 2 insertions, 262 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 9f140469da..d29e415720 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -72,7 +72,7 @@ COBJECTS = range.c record.c compress.c debug.c cipher.c gthreads.h handshake-tls pk.c cert-cred.c global.c constate.c anon_cred.c pkix_asn1_tab.c gnutls_asn1_tab.c \ mem.c fingerprint.c tls-sig.c ecc.c alert.c privkey_raw.c atomic.h \ system/certs.c system/threads.c system/fastopen.c system/sockets.c \ - system/inet_ntop.c str-iconv.c system.c \ + str-iconv.c system.c \ str.c str-unicode.c str-idna.c state.c cert-cred-x509.c file.c supplemental.c \ random.c crypto-api.c crypto-api.h privkey.c pcert.c pubkey.c locks.c dtls.c \ system_override.c crypto-backend.c verify-tofu.c pin.c tpm.c fips.c \ diff --git a/lib/system.h b/lib/system.h index 6a948f858d..18c2603bec 100644 --- a/lib/system.h +++ b/lib/system.h @@ -124,11 +124,4 @@ int inet_aton(const char *cp, struct in_addr *inp); int inet_pton(int af, const char *src, void *dst); #endif -#ifndef HAVE_INET_NTOP -# undef inet_ntop -# define inet_ntop _gnutls_inet_ntop -const char *inet_ntop(int af, const void *src, - char *dst, unsigned size); -#endif - #endif /* SYSTEM_H */ diff --git a/lib/system/inet_ntop.c b/lib/system/inet_ntop.c deleted file mode 100644 index 87760ebf11..0000000000 --- a/lib/system/inet_ntop.c +++ /dev/null @@ -1,250 +0,0 @@ -/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form - - Copyright (C) 2005-2006, 2008-2015 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. */ - -/* - * Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include <config.h> - -#ifndef HAVE_INET_NTOP - -# include <stdio.h> -# include <string.h> -# include <errno.h> -# include <sys/socket.h> -# include "system.h" - -# ifndef IF_LINT -# define IF_LINT -#endif - -# ifndef HAVE_IPV6 -# define HAVE_IPV6 1 -# endif - -# ifndef HAVE_IPV4 -# define HAVE_IPV4 1 -# endif - -# define NS_IN6ADDRSZ 16 -# define NS_INT16SZ 2 - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ -typedef int verify_int_size[4 <= sizeof (int) ? 1 : -1]; - -static const char *inet_ntop4 (const unsigned char *src, char *dst, unsigned size); -# if HAVE_IPV6 -static const char *inet_ntop6 (const unsigned char *src, char *dst, unsigned size); -# endif - - -/* char * - * inet_ntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: - * pointer to presentation format address ('dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. - */ -const char * -inet_ntop (int af, const void *restrict src, - char *restrict dst, unsigned cnt) -{ - switch (af) - { -# if HAVE_IPV4 - case AF_INET: - return (inet_ntop4 (src, dst, cnt)); -# endif - -# if HAVE_IPV6 - case AF_INET6: - return (inet_ntop6 (src, dst, cnt)); -# endif - - default: - errno = EAFNOSUPPORT; - return (NULL); - } - /* NOTREACHED */ -} - -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address - * return: - * 'dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop4 (const unsigned char *src, char *dst, unsigned size) -{ - char tmp[sizeof "255.255.255.255"]; - int len; - - len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]); - if (len < 0) - return NULL; - - if ((unsigned)len > size) - { - errno = ENOSPC; - return NULL; - } - - return strcpy (dst, tmp); -} - -# if HAVE_IPV6 - -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop6 (const unsigned char *src, char *dst, unsigned size) -{ - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; - struct - { - int base, len; - } best, cur; - unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset (words, '\0', sizeof words); - for (i = 0; i < NS_IN6ADDRSZ; i += 2) - words[i / 2] = (src[i] << 8) | src[i + 1]; - best.base = -1; - cur.base = -1; - IF_LINT(best.len = 0); - IF_LINT(cur.len = 0); - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) - { - if (words[i] == 0) - { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } - else - { - if (cur.base != -1) - { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) - { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) - { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && i < (best.base + best.len)) - { - if (i == best.base) - *tp++ = ':'; - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) - *tp++ = ':'; - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) - { - if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp))) - return (NULL); - tp += strlen (tp); - break; - } - { - int len = sprintf (tp, "%x", words[i]); - if (len < 0) - return NULL; - tp += len; - } - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == - (NS_IN6ADDRSZ / NS_INT16SZ)) - *tp++ = ':'; - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((unsigned) (tp - tmp) > size) - { - errno = ENOSPC; - return NULL; - } - - return strcpy (dst, tmp); -} - -# endif - -#endif diff --git a/lib/x509/ip.c b/lib/x509/ip.c index b4b31a4f94..644d2f58f5 100644 --- a/lib/x509/ip.c +++ b/lib/x509/ip.c @@ -24,10 +24,7 @@ #include "gnutls_int.h" #include "ip.h" #include <gnutls/x509.h> - -#ifdef HAVE_INET_NTOP -# include <arpa/inet.h> -#endif +#include <arpa/inet.h> /*- * _gnutls_mask_to_prefix: |