From 8b81106e1d0833c5592695fa00d18e2193031216 Mon Sep 17 00:00:00 2001 From: christos Date: Thu, 22 Jan 2015 02:42:27 +0000 Subject: [PATCH] more portability fixes, MacOS/X --- external/bsd/blacklist/bin/conf.c | 14 ++++- external/bsd/blacklist/port/configure.ac | 3 +- .../bsd/blacklist/port/sockaddr_snprintf.c | 58 +++++++++++++++---- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/external/bsd/blacklist/bin/conf.c b/external/bsd/blacklist/bin/conf.c index 7cf8396d0d51..bd1c3f83935a 100644 --- a/external/bsd/blacklist/bin/conf.c +++ b/external/bsd/blacklist/bin/conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.7 2015/01/21 23:26:26 christos Exp $ */ +/* $NetBSD: conf.c,v 1.8 2015/01/22 02:42:27 christos Exp $ */ /*- * Copyright (c) 2015 The NetBSD Foundation, Inc. @@ -28,8 +28,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "port.h" +#endif #include -__RCSID("$NetBSD: conf.c,v 1.7 2015/01/21 23:26:26 christos Exp $"); +__RCSID("$NetBSD: conf.c,v 1.8 2015/01/22 02:42:27 christos Exp $"); #include #include @@ -167,7 +171,9 @@ gethostport(const char *f, size_t l, void *v, const char *p) if (inet_pton(AF_INET6, p, &s6->sin6_addr) == -1) goto out; s6->sin6_family = AF_INET6; +#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN s6->sin6_len = sizeof(*s6); +#endif port = &s6->sin6_port; } p = ++d; @@ -180,7 +186,9 @@ gethostport(const char *f, size_t l, void *v, const char *p) if (inet_pton(AF_INET, p, &s->sin_addr) == -1) goto out; s->sin_family = AF_INET; +#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN s->sin_len = sizeof(*s); +#endif port = &s->sin_port; } p = d; @@ -249,7 +257,7 @@ getuid(const char *f, size_t l, void *r, const char *p) } static int -getname(const char *f, size_t l, void *r, const char *p) +getname(const char *f __unused, size_t l __unused, void *r, const char *p) { snprintf(r, CONFNAMESZ, "%s%s", *p == '-' ? rulename : "", p); return 0; diff --git a/external/bsd/blacklist/port/configure.ac b/external/bsd/blacklist/port/configure.ac index 1c3c3357ceb5..a51c0f58bb97 100644 --- a/external/bsd/blacklist/port/configure.ac +++ b/external/bsd/blacklist/port/configure.ac @@ -32,8 +32,7 @@ AC_C_CONST AC_TYPE_OFF_T AC_TYPE_SIZE_T AC_SYS_LARGEFILE -AC_CHECK_MEMBERS([struct sockaddr_in.sin_len]) - +AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [], [#include ]) AC_TYPE_PID_T AC_TYPE_UINT8_T diff --git a/external/bsd/blacklist/port/sockaddr_snprintf.c b/external/bsd/blacklist/port/sockaddr_snprintf.c index 10666526ad94..cd10b44d9a40 100644 --- a/external/bsd/blacklist/port/sockaddr_snprintf.c +++ b/external/bsd/blacklist/port/sockaddr_snprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: sockaddr_snprintf.c,v 1.2 2015/01/22 02:27:16 christos Exp $ */ +/* $NetBSD: sockaddr_snprintf.c,v 1.3 2015/01/22 02:42:27 christos Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -28,11 +28,16 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "port.h" +#endif #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.2 2015/01/22 02:27:16 christos Exp $"); +__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.3 2015/01/22 02:42:27 christos Exp $"); #endif /* LIBC_SCCS and not lint */ +#include #include #include #include @@ -54,6 +59,36 @@ __RCSID("$NetBSD: sockaddr_snprintf.c,v 1.2 2015/01/22 02:27:16 christos Exp $") #endif #include +#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN +#define SLEN(a) (a)->a ## _len +#else +static size_t +socklen(u_int af) +{ + switch (af) { + case AF_INET: + return sizeof(struct sockaddr_in); + case AF_INET6: + return sizeof(struct sockaddr_in6); + case AF_LOCAL: + return sizeof(struct sockaddr_un); +#ifdef HAVE_NET_IF_DL_H + case AF_LINK: + return sizeof(struct sockaddr_dl); +#endif +#ifdef HAVE_NETATALK_AT_H + case AF_APPLETALK: + return sizeof(struct sockaddr_at); +#endif + default: + return sizeof(struct sockaddr_storage); + } +} + +#define SLEN(a) (uint8_t)MAX(sizeof(*(a), socklen((a)->a ## _family) +#endif + + #ifdef HAVE_NETATALK_AT_H static int debug_at(char *str, size_t len, const struct sockaddr_at *sat) @@ -63,7 +98,7 @@ debug_at(char *str, size_t len, const struct sockaddr_at *sat) "sat_range.r_netrange.nr_phase=%u, " "sat_range.r_netrange.nr_firstnet=%u, " "sat_range.r_netrange.nr_lastnet=%u", - sat->sat_len, sat->sat_family, sat->sat_port, + SLEN(sat), sat->sat_family, sat->sat_port, sat->sat_addr.s_net, sat->sat_addr.s_node, sat->sat_range.r_netrange.nr_phase, sat->sat_range.r_netrange.nr_firstnet, @@ -76,7 +111,7 @@ debug_in(char *str, size_t len, const struct sockaddr_in *sin) { return snprintf(str, len, "sin_len=%u, sin_family=%u, sin_port=%u, " "sin_addr.s_addr=%08x", - sin->sin_len, sin->sin_family, sin->sin_port, + SLEN(sin), sin->sin_family, sin->sin_port, sin->sin_addr.s_addr); } @@ -89,7 +124,7 @@ debug_in6(char *str, size_t len, const struct sockaddr_in6 *sin6) "sin6_flowinfo=%u, " "sin6_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:" "%02x:%02x:%02x:%02x:%02x:%02x, sin6_scope_id=%u", - sin6->sin6_len, sin6->sin6_family, sin6->sin6_port, + SLEN(sin6), sin6->sin6_family, sin6->sin6_port, sin6->sin6_flowinfo, s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5], s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb], s[0xc], s[0xd], s[0xe], s[0xf], sin6->sin6_scope_id); @@ -99,7 +134,7 @@ static int debug_un(char *str, size_t len, const struct sockaddr_un *sun) { return snprintf(str, len, "sun_len=%u, sun_family=%u, sun_path=%*s", - sun->sun_len, sun->sun_family, (int)sizeof(sun->sun_path), + SLEN(sun), sun->sun_family, (int)sizeof(sun->sun_path), sun->sun_path); } @@ -112,11 +147,12 @@ debug_dl(char *str, size_t len, const struct sockaddr_dl *sdl) return snprintf(str, len, "sdl_len=%u, sdl_family=%u, sdl_index=%u, " "sdl_type=%u, sdl_nlen=%u, sdl_alen=%u, sdl_slen=%u, sdl_data=" "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", - sdl->sdl_len, sdl->sdl_family, sdl->sdl_index, + SLEN(sdl), sdl->sdl_family, sdl->sdl_index, sdl->sdl_type, sdl->sdl_nlen, sdl->sdl_alen, sdl->sdl_slen, s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5], s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb]); } +#endif int sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt, @@ -188,7 +224,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt, if (addr == abuf) name = addr; - if (a && getnameinfo(sa, (socklen_t)sa->sa_len, addr = abuf, + if (a && getnameinfo(sa, (socklen_t)SLEN(sa), addr = abuf, (unsigned int)sizeof(abuf), NULL, 0, NI_NUMERICHOST|NI_NUMERICSERV) != 0) return -1; @@ -218,7 +254,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt, ADDS(nbuf); break; case 'l': - (void)snprintf(nbuf, sizeof(nbuf), "%d", sa->sa_len); + (void)snprintf(nbuf, sizeof(nbuf), "%d", SLEN(sa)); ADDS(nbuf); break; case 'A': @@ -227,7 +263,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt, else if (!a) ADDNA(); else { - getnameinfo(sa, (socklen_t)sa->sa_len, + getnameinfo(sa, (socklen_t)SLEN(sa), name = Abuf, (unsigned int)sizeof(nbuf), NULL, 0, 0); ADDS(name); @@ -239,7 +275,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt, else if (p == -1) ADDNA(); else { - getnameinfo(sa, (socklen_t)sa->sa_len, NULL, 0, + getnameinfo(sa, (socklen_t)SLEN(sa), NULL, 0, port = pbuf, (unsigned int)sizeof(pbuf), 0); ADDS(port);