From ec912e45a8c8757b044354d4e8a6416491fe6ba6 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 23 May 2019 22:12:04 +0200 Subject: [PATCH] Assume getaddrinfo() and IPv6 are supported. All major operating systems of the last 10 years have supported IPv6 and provide getaddrinfo(). --- configure.ac | 15 ------ src/Makefile.am | 3 -- src/dropin.h | 8 +-- src/fake-gai-errnos.h | 20 -------- src/fake-getaddrinfo.c | 107 ----------------------------------------- src/fake-getaddrinfo.h | 46 ------------------ src/fake-getnameinfo.c | 64 ------------------------ src/fake-getnameinfo.h | 15 ------ src/system.h | 4 -- 9 files changed, 5 insertions(+), 277 deletions(-) delete mode 100644 src/fake-gai-errnos.h delete mode 100644 src/fake-getaddrinfo.c delete mode 100644 src/fake-getaddrinfo.h delete mode 100644 src/fake-getnameinfo.c delete mode 100644 src/fake-getnameinfo.h diff --git a/configure.ac b/configure.ac index 1b0b2e06..b1b1118d 100644 --- a/configure.ac +++ b/configure.ac @@ -124,14 +124,6 @@ dnl Checks for typedefs, structures, and compiler characteristics. MeshLink_ATTRIBUTE(__malloc__) MeshLink_ATTRIBUTE(__warn_unused_result__) -AC_CHECK_TYPES([socklen_t, struct addrinfo, struct sockaddr_in6], , , - [#include "$srcdir/src/have.h"] -) - -AC_CHECK_TYPES([struct sockaddr_storage], ,AC_MSG_ERROR([System must support struct sockaddr_storage.]), - [#include "$srcdir/src/have.h"] -) - dnl Checks for library functions. AC_TYPE_SIGNAL AC_CHECK_FUNCS([asprintf fchmod fork gettimeofday random pselect select setns strdup usleep getifaddrs freeifaddrs], @@ -143,13 +135,6 @@ dnl Support for SunOS AC_CHECK_FUNC(socket, [], [ AC_CHECK_LIB(socket, connect) ]) -AC_CHECK_FUNC(gethostbyname, [], [ - AC_CHECK_LIB(nsl, gethostbyname) -]) - -AC_CHECK_DECLS([freeaddrinfo, gai_strerror, getaddrinfo, getnameinfo], - [], [], [#include "$srcdir/src/have.h"] -) AC_CACHE_SAVE diff --git a/src/Makefile.am b/src/Makefile.am index 8decac75..bfbee514 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,9 +46,6 @@ libmeshlink_la_SOURCES = \ ecdsagen.h \ edge.c edge.h \ event.c event.h \ - fake-gai-errnos.h \ - fake-getaddrinfo.c fake-getaddrinfo.h \ - fake-getnameinfo.c fake-getnameinfo.h \ graph.c graph.h \ hash.c hash.h \ have.h \ diff --git a/src/dropin.h b/src/dropin.h index 568a6e52..f7a42975 100644 --- a/src/dropin.h +++ b/src/dropin.h @@ -20,9 +20,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "fake-getaddrinfo.h" -#include "fake-getnameinfo.h" - #ifndef HAVE_ASPRINTF extern int asprintf(char **, const char *, ...); extern int vasprintf(char **, const char *, va_list ap); @@ -30,9 +27,14 @@ extern int vasprintf(char **, const char *, va_list ap); #ifdef HAVE_MINGW #define mkdir(a, b) mkdir(a) + #ifndef SHUT_RDWR #define SHUT_RDWR SD_BOTH #endif + +#ifndef EAI_SYSTEM +#define EAI_SYSTEM 0 +#endif #endif #endif diff --git a/src/fake-gai-errnos.h b/src/fake-gai-errnos.h deleted file mode 100644 index 5ec371ca..00000000 --- a/src/fake-gai-errnos.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MESHLINK_FAKE_GAI_ERRNOS_H -#define MESHLINK_FAKE_GAI_ERRNOS_H - -#ifndef EAI_NODATA -#define EAI_NODATA 1 -#endif - -#ifndef EAI_MEMORY -#define EAI_MEMORY 2 -#endif - -#ifndef EAI_FAMILY -#define EAI_FAMILY 3 -#endif - -#ifndef EAI_SYSTEM -#define EAI_SYSTEM 4 -#endif - -#endif diff --git a/src/fake-getaddrinfo.c b/src/fake-getaddrinfo.c deleted file mode 100644 index 576d79f4..00000000 --- a/src/fake-getaddrinfo.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * fake library for ssh - * - * This file includes getaddrinfo(), freeaddrinfo() and gai_strerror(). - * These functions are defined in rfc2133. - * - * But these functions are not implemented correctly. The minimum subset - * is implemented for ssh use only. For example, this routine assumes - * that ai_family is AF_INET. Don't use it for another purpose. - */ - -#include "system.h" - -#include "fake-getaddrinfo.h" -#include "xalloc.h" - - -#if !HAVE_DECL_GAI_STRERROR -char *gai_strerror(int ecode) { - switch(ecode) { - case EAI_NODATA: - return "No address associated with hostname"; - - case EAI_MEMORY: - return "Memory allocation failure"; - - case EAI_FAMILY: - return "Address family not supported"; - - default: - return "Unknown error"; - } -} -#endif /* !HAVE_GAI_STRERROR */ - -#if !HAVE_DECL_FREEADDRINFO -void freeaddrinfo(struct addrinfo *ai) { - struct addrinfo *next; - - while(ai) { - next = ai->ai_next; - free(ai); - ai = next; - } -} -#endif /* !HAVE_FREEADDRINFO */ - -#if !HAVE_DECL_GETADDRINFO -static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) { - struct addrinfo *ai; - - ai = xzalloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); - - ai->ai_addr = (struct sockaddr *)(ai + 1); - ai->ai_addrlen = sizeof(struct sockaddr_in); - ai->ai_addr->sa_family = ai->ai_family = AF_INET; - - ((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port; - ((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr; - - return ai; -} - -int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) { - struct addrinfo *prev = NULL; - struct hostent *hp; - struct in_addr in = {0}; - int i; - uint16_t port = 0; - - if(hints && hints->ai_family != AF_INET && hints->ai_family != AF_UNSPEC) { - return EAI_FAMILY; - } - - if(servname) { - port = htons(atoi(servname)); - } - - if(hints && hints->ai_flags & AI_PASSIVE) { - *res = malloc_ai(port, htonl(0x00000000)); - return 0; - } - - if(!hostname) { - *res = malloc_ai(port, htonl(0x7f000001)); - return 0; - } - - hp = gethostbyname(hostname); - - if(!hp || !hp->h_addr_list || !hp->h_addr_list[0]) { - return EAI_NODATA; - } - - for(i = 0; hp->h_addr_list[i]; i++) { - *res = malloc_ai(port, ((struct in_addr *)hp->h_addr_list[i])->s_addr); - - if(prev) { - prev->ai_next = *res; - } - - prev = *res; - } - - return 0; -} -#endif /* !HAVE_GETADDRINFO */ diff --git a/src/fake-getaddrinfo.h b/src/fake-getaddrinfo.h deleted file mode 100644 index 7fbd91b5..00000000 --- a/src/fake-getaddrinfo.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef MESHLINK_FAKE_GETADDRINFO_H -#define MESHLINK_FAKE_GETADDRINFO_H - -#include "fake-gai-errnos.h" - -#ifndef AI_PASSIVE -# define AI_PASSIVE 1 -# define AI_CANONNAME 2 -#endif - -#ifndef NI_NUMERICHOST -# define NI_NUMERICHOST 2 -# define NI_NAMEREQD 4 -# define NI_NUMERICSERV 8 -#endif - -#ifndef AI_NUMERICHOST -#define AI_NUMERICHOST 4 -#endif - -#ifndef HAVE_STRUCT_ADDRINFO -struct addrinfo { - int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ - int ai_family; /* PF_xxx */ - int ai_socktype; /* SOCK_xxx */ - int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ - size_t ai_addrlen; /* length of ai_addr */ - char *ai_canonname; /* canonical name for hostname */ - struct sockaddr *ai_addr; /* binary address */ - struct addrinfo *ai_next; /* next structure in linked list */ -}; -#endif /* !HAVE_STRUCT_ADDRINFO */ - -#if !HAVE_DECL_GETADDRINFO -int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) __attribute__((__warn_unused_result__)); -#endif /* !HAVE_GETADDRINFO */ - -#if !HAVE_DECL_GAI_STRERROR -char *gai_strerror(int ecode) __attribute__((__warn_unused_result__)); -#endif /* !HAVE_GAI_STRERROR */ - -#if !HAVE_DECL_FREEADDRINFO -void freeaddrinfo(struct addrinfo *ai); -#endif /* !HAVE_FREEADDRINFO */ - -#endif diff --git a/src/fake-getnameinfo.c b/src/fake-getnameinfo.c deleted file mode 100644 index e51bce24..00000000 --- a/src/fake-getnameinfo.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * fake library for ssh - * - * This file includes getnameinfo(). - * These functions are defined in rfc2133. - * - * But these functions are not implemented correctly. The minimum subset - * is implemented for ssh use only. For example, this routine assumes - * that ai_family is AF_INET. Don't use it for another purpose. - */ - -#include "system.h" - -#include "fake-getnameinfo.h" -#include "fake-getaddrinfo.h" - -#if !HAVE_DECL_GETNAMEINFO - -int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { - struct sockaddr_in *sin = (struct sockaddr_in *)sa; - struct hostent *hp; - int len; - - if(sa->sa_family != AF_INET) { - return EAI_FAMILY; - } - - if(serv && servlen) { - len = snprintf(serv, servlen, "%d", ntohs(sin->sin_port)); - - if(len < 0 || len >= servlen) { - return EAI_MEMORY; - } - } - - if(!host || !hostlen) { - return 0; - } - - if(flags & NI_NUMERICHOST) { - len = snprintf(host, hostlen, "%s", inet_ntoa(sin->sin_addr)); - - if(len < 0 || len >= hostlen) { - return EAI_MEMORY; - } - - return 0; - } - - hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET); - - if(!hp || !hp->h_name || !hp->h_name[0]) { - return EAI_NODATA; - } - - len = snprintf(host, hostlen, "%s", hp->h_name); - - if(len < 0 || len >= hostlen) { - return EAI_MEMORY; - } - - return 0; -} -#endif /* !HAVE_GETNAMEINFO */ diff --git a/src/fake-getnameinfo.h b/src/fake-getnameinfo.h deleted file mode 100644 index fc1f1d40..00000000 --- a/src/fake-getnameinfo.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MESHLINK_FAKE_GETNAMEINFO_H -#define MESHLINK_FAKE_GETNAMEINFO_H - -#if !HAVE_DECL_GETNAMEINFO -int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) __attribute__((__warn_unused_result__)); -#endif /* !HAVE_GETNAMEINFO */ - -#ifndef NI_MAXSERV -# define NI_MAXSERV 32 -#endif /* !NI_MAXSERV */ -#ifndef NI_MAXHOST -# define NI_MAXHOST 1025 -#endif /* !NI_MAXHOST */ - -#endif diff --git a/src/system.h b/src/system.h index dc392874..a31ba7a3 100644 --- a/src/system.h +++ b/src/system.h @@ -32,8 +32,4 @@ #include "dropin.h" -#ifndef HAVE_SOCKLEN_T -typedef int socklen_t; -#endif - #endif -- 2.39.2