Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/blacklist more portability fixes, MacOS/X
details: https://anonhg.NetBSD.org/src/rev/08d55db5efb2
branches: trunk
changeset: 805854:08d55db5efb2
user: christos <christos%NetBSD.org@localhost>
date: Thu Jan 22 02:42:27 2015 +0000
description:
more portability fixes, MacOS/X
diffstat:
external/bsd/blacklist/bin/conf.c | 14 ++++-
external/bsd/blacklist/port/configure.ac | 3 +-
external/bsd/blacklist/port/sockaddr_snprintf.c | 58 ++++++++++++++++++++----
3 files changed, 59 insertions(+), 16 deletions(-)
diffs (215 lines):
diff -r 935e822155de -r 08d55db5efb2 external/bsd/blacklist/bin/conf.c
--- a/external/bsd/blacklist/bin/conf.c Thu Jan 22 02:35:44 2015 +0000
+++ b/external/bsd/blacklist/bin/conf.c Thu Jan 22 02:42:27 2015 +0000
@@ -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 <sys/cdefs.h>
-__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 <stdio.h>
#include <string.h>
@@ -167,7 +171,9 @@
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 @@
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 @@
}
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 -r 935e822155de -r 08d55db5efb2 external/bsd/blacklist/port/configure.ac
--- a/external/bsd/blacklist/port/configure.ac Thu Jan 22 02:35:44 2015 +0000
+++ b/external/bsd/blacklist/port/configure.ac Thu Jan 22 02:42:27 2015 +0000
@@ -32,8 +32,7 @@
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 <sys/socket.h>])
AC_TYPE_PID_T
AC_TYPE_UINT8_T
diff -r 935e822155de -r 08d55db5efb2 external/bsd/blacklist/port/sockaddr_snprintf.c
--- a/external/bsd/blacklist/port/sockaddr_snprintf.c Thu Jan 22 02:35:44 2015 +0000
+++ b/external/bsd/blacklist/port/sockaddr_snprintf.c Thu Jan 22 02:42:27 2015 +0000
@@ -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 <sys/cdefs.h>
#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 <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -54,6 +59,36 @@
#endif
#include <netdb.h>
+#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 @@
"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 @@
{
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 @@
"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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);
Home |
Main Index |
Thread Index |
Old Index