Build issue for geoip.c on NetBSD
Summary
The build errors out on bin/named/geoip.c
when the geoip
feature has been detected on NetBSD 9.0.
BIND version used
BIND 9.16.12
Steps to reproduce
Have the libmaxminddb package installed.
This will auto-enable geoip, and try to build bin/named/geoip.c
.
What is the current bug behavior?
The build errors out with
/usr/local/src/bind-9.16.12/lib/isc/include/isc/sockaddr.h:31:27: error: field 'ss' has incomplete type
struct sockaddr_storage ss;
^~
*** Error code 1
What is the expected correct behavior?
The build ought to succeed...
Relevant configuration files
n/a
Relevant logs and/or screenshots
n/a -- see end of build log above.
Possible fixes
The libmaxminddb package's maxminddb.h
starts by doing
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
and NetBSD's sys/featuretest.h
file does not turn on
the _NETBSD_SOURCE
variable if _POSIX_C_SOURCE
is defined, ref.
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
!defined(_XOPEN_SOURCE) && !defined(_NETBSD_SOURCE)
#define _NETBSD_SOURCE 1
#endif
However, sys/socket.h
does not declare sockaddr_storage
when _POSIX_C_SOURCE
has been defined, ref.
#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
struct sockaddr_storage {
__uint8_t ss_len; /* address length */
sa_family_t ss_family; /* address family */
char __ss_pad1[_SS_PAD1SIZE];
__int64_t __ss_align;/* force desired structure storage alignment */
char __ss_pad2[_SS_PAD2SIZE];
};
#define sstosa(__ss) ((struct sockaddr *)(__ss))
#define sstocsa(__ss) ((const struct sockaddr *)(__ss))
#endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
So we end up with the error as described.
I'm not entirely certain what the correct way to deal with this is. I can think of an ugly and wrong way, i.e. do
--- bin/named/geoip.c.orig 2021-02-04 11:35:16.000000000 +0000
+++ bin/named/geoip.c
@@ -11,6 +11,11 @@
/*! \file */
+/* Circumvent effect of _POSIX_C_SOURCE define in <maxminddb.h> */
+#if defined(__NetBSD__)
+#define _NETBSD_SOURCE 1
+#endif
+
#if defined(HAVE_GEOIP2)
#include <maxminddb.h>
#endif /* if defined(HAVE_GEOIP2) */
One isn't supposed to (have to) mess with the _
-prefixed names, which
are implementation-defined.
At least it makes the build succeed...
Another way would be to define the _XOPEN_SRC
as appropriate, that's
probably a bit less gross, ref.
--- bin/named/geoip.c.orig 2021-02-04 11:35:16.000000000 +0000
+++ bin/named/geoip.c
@@ -12,6 +12,8 @@
/*! \file */
#if defined(HAVE_GEOIP2)
+/* We need more than the _POSIX_C_SOURCE version maxminddb.h defines */
+#define _XOPEN_SOURCE 700
#include <maxminddb.h>
#endif /* if defined(HAVE_GEOIP2) */
(which also builds).