On Wed, Sep 05, 2012 at 03:59:10PM -0600, Eric Blake wrote: > OpenBSD's <net/if.h> is not self-contained; this should compile: > > | #define _POSIX_C_SOURCE 200809L > | #include <net/if.h> > | struct if_nameindex i; > > but fails with: > > In file included from foo.c:2: > /usr/include/net/if.h:112: error: expected specifier-qualifier-list before > 'u_int' > ... > /usr/include/net/if.h:674: error: field 'dstaddr' has incomplete type > In file included from /usr/include/net/if.h:691, > from foo.c:2: > /usr/include/net/if_arp.h:79: error: field 'arp_pa' has incomplete type > /usr/include/net/if_arp.h:80: error: field 'arp_ha' has incomplete type > *** Error code 1 > > We already had a test program for systems with the if_* functions > (including OpenBSD); but in adding this module, I had to enhance > that test to also work on platforms like mingw where we are now > providing a new header. > > * modules/net_if: New module, borrowing ideas from netinet_in. > * m4/net_if_h.m4: New file. > * lib/net_if.in.h: Likewise. > * doc/posix-headers/net_if.texi (net/if.h): Document it. > * MODULES.html.sh (lacking POSIX:2008): Likewise. > * tests/test-net_if.c: Make function checks conditional. > Reported by Jasper Lievisse Adriaanse <jas...@humppa.nl>. > > Signed-off-by: Eric Blake <ebl...@redhat.com>
Although the entry in net_if.texi is correct for OpenBSD, it may be ammended to include 5.2 too? As that is the version I'm testing with (OpenBSD -current). > --- > ChangeLog | 11 +++++++++ > MODULES.html.sh | 1 + > doc/posix-headers/net_if.texi | 5 +++- > lib/net_if.in.h | 53 > +++++++++++++++++++++++++++++++++++++++++++ > m4/net_if_h.m4 | 31 +++++++++++++++++++++++++ > modules/net_if | 49 +++++++++++++++++++++++++++++++++++++++ > tests/test-net_if.c | 12 ++++++++-- > 7 files changed, 159 insertions(+), 3 deletions(-) > create mode 100644 lib/net_if.in.h > create mode 100644 m4/net_if_h.m4 > create mode 100644 modules/net_if > > diff --git a/ChangeLog b/ChangeLog > index dea1f86..d9f6f89 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,14 @@ > +2012-09-05 Eric Blake <ebl...@redhat.com> > + > + net_if: new module > + * modules/net_if: New module, borrowing ideas from netinet_in. > + * m4/net_if_h.m4: New file. > + * lib/net_if.in.h: Likewise. > + * doc/posix-headers/net_if.texi (net/if.h): Document it. > + * MODULES.html.sh (lacking POSIX:2008): Likewise. > + * tests/test-net_if.c: Make function checks conditional. > + Reported by Jasper Lievisse Adriaanse <jas...@humppa.nl>. > + > 2012-09-05 Mats Erik Andersson <g...@gisladisker.se> (tiny change) > > readutmp: fix non-portable UT_PID use > diff --git a/MODULES.html.sh b/MODULES.html.sh > index 8ced611..0e34531 100755 > --- a/MODULES.html.sh > +++ b/MODULES.html.sh > @@ -2430,6 +2430,7 @@ func_all_modules () > func_module mkfifo > func_module mknod > func_module mkstemp > + func_module net_if > func_module netdb > func_module netinet_in > func_module nl_langinfo > diff --git a/doc/posix-headers/net_if.texi b/doc/posix-headers/net_if.texi > index 38a52f4..fa01b6e 100644 > --- a/doc/posix-headers/net_if.texi > +++ b/doc/posix-headers/net_if.texi > @@ -3,10 +3,13 @@ net/if.h > > POSIX specification:@* > @url{http://www.opengroup.org/onlinepubs/9699919799/basedefs/net_if.h.html} > > -Gnulib module: --- > +Gnulib module: net_if > > Portability problems fixed by Gnulib: > @itemize > +@item > +This header file is not self-contained on some platforms: > +FreeBSD 8.2, OpenBSD 5.1. > @end itemize > > Portability problems not fixed by Gnulib: > diff --git a/lib/net_if.in.h b/lib/net_if.in.h > new file mode 100644 > index 0000000..24f9f83 > --- /dev/null > +++ b/lib/net_if.in.h > @@ -0,0 +1,53 @@ > +/* Substitute for <net/if.h>. > + Copyright (C) 2007-2012 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/>. */ > + > +#ifndef _@GUARD_PREFIX@_NET_IF_H > + > +#if __GNUC__ >= 3 > +@PRAGMA_SYSTEM_HEADER@ > +#endif > +@PRAGMA_COLUMNS@ > + > +#if @HAVE_NET_IF_H@ > + > +/* On some platforms, <net/if.h> assumes prior inclusion of > + <sys/socket.h>. */ > +# include <sys/socket.h> > + > +/* The include_next requires a split double-inclusion guard. */ > +# @INCLUDE_NEXT@ @NEXT_NET_IF_H@ > + > +#endif > + > +#ifndef _@GUARD_PREFIX@_NET_IF_H > +#define _@GUARD_PREFIX@_NET_IF_H > + > +#if !@HAVE_NET_IF_H@ > + > +/* A platform that lacks <net/if.h>. */ > + > +struct if_nameindex > +{ > + unsigned if_index; > + char *if_name; > +}; > + > +# define IF_NAMESIZE 1 /* Without if_* functions, this supports only "". */ > + > +#endif > + > +#endif /* _@GUARD_PREFIX@_NET_IF_H */ > +#endif /* _@GUARD_PREFIX@_NET_IF_H */ > diff --git a/m4/net_if_h.m4 b/m4/net_if_h.m4 > new file mode 100644 > index 0000000..171101f > --- /dev/null > +++ b/m4/net_if_h.m4 > @@ -0,0 +1,31 @@ > +# net_if_h.m4 serial 1 > +dnl Copyright (C) 2006-2012 Free Software Foundation, Inc. > +dnl This file is free software; the Free Software Foundation > +dnl gives unlimited permission to copy and/or distribute it, > +dnl with or without modifications, as long as this notice is preserved. > + > +AC_DEFUN([gl_HEADER_NET_IF], > +[ > + AC_CACHE_CHECK([whether <net/if.h> is self-contained], > + [gl_cv_header_net_if_h_selfcontained], > + [ > + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <net/if.h>]], [[]])], > + [gl_cv_header_net_if_h_selfcontained=yes], > + [gl_cv_header_net_if_h_selfcontained=no]) > + ]) > + if test $gl_cv_header_net_if_h_selfcontained = yes; then > + NET_IF_H='' > + else > + NET_IF_H='net/if.h' > + AC_CHECK_HEADERS([net/if.h], [], [], [[#include <sys/socket.h>]]) > + gl_NEXT_HEADERS([net/if.h]) > + if test $ac_cv_header_net_if_h = yes; then > + HAVE_NET_IF_H=1 > + else > + HAVE_NET_IF_H=0 > + fi > + AC_SUBST([HAVE_NET_IF_H]) > + fi > + AC_SUBST([NET_IF_H]) > + AM_CONDITIONAL([GL_GENERATE_NET_IF_H], [test -n "$NET_IF_H"]) > +]) > diff --git a/modules/net_if b/modules/net_if > new file mode 100644 > index 0000000..9e30f01 > --- /dev/null > +++ b/modules/net_if > @@ -0,0 +1,49 @@ > +Description: > +A <net/if.h> for systems lacking it. > + > +Files: > +lib/net_if.in.h > +m4/net_if_h.m4 > + > +Depends-on: > +include_next > +sys_socket > + > +configure.ac: > +gl_HEADER_NET_IF > +AC_PROG_MKDIR_P > + > +Makefile.am: > +BUILT_SOURCES += $(NET_IF_H) > + > +# We need the following in order to create <net/if.h> when the system > +# doesn't have one. > +if GL_GENERATE_NET_IF_H > +net/if.h: net_if.in.h $(top_builddir)/config.status > + $(AM_V_at)$(MKDIR_P) net > + $(AM_V_GEN)rm -f $@-t $@ && \ > + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ > + sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \ > + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ > + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ > + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ > + -e 's|@''NEXT_NET_IF_H''@|$(NEXT_NET_IF_H)|g' \ > + -e 's|@''HAVE_NET_IF_H''@|$(HAVE_NET_IF_H)|g' \ > + < $(srcdir)/net_if.in.h; \ > + } > $@-t && \ > + mv $@-t $@ > +else > +net/if.h: $(top_builddir)/config.status > + rm -f $@ > +endif > +MOSTLYCLEANFILES += net/if.h net/if.h-t > +MOSTLYCLEANDIRS += net > + > +Include: > +<net/if.h> > + > +License: > +LGPLv2+ > + > +Maintainer: > +Eric Blake > diff --git a/tests/test-net_if.c b/tests/test-net_if.c > index ee3cdbd..f508642 100644 > --- a/tests/test-net_if.c > +++ b/tests/test-net_if.c > @@ -20,11 +20,17 @@ > > #include <net/if.h> > > -#include "signature.h" > +static struct if_nameindex ni; > + > +/* We do not yet have replacements for if_* functions on systems that > + lack a native <net/if.h>. */ > +#if HAVE_NET_IF_H > +# include "signature.h" > SIGNATURE_CHECK (if_freenameindex, void, (struct if_nameindex *)); > SIGNATURE_CHECK (if_indextoname, char *, (unsigned int, char *)); > SIGNATURE_CHECK (if_nameindex, struct if_nameindex *, (void)); > SIGNATURE_CHECK (if_nametoindex, unsigned int, (const char *)); > +#endif > > #include <stddef.h> /* NULL */ > #include <stdio.h> /* fprintf */ > @@ -32,6 +38,7 @@ SIGNATURE_CHECK (if_nametoindex, unsigned int, (const char > *)); > int > main (int argc, char *argv[]) > { > +#if HAVE_NET_IF_H > struct if_nameindex *ifnp, *p; > > p = ifnp = if_nameindex (); > @@ -80,6 +87,7 @@ main (int argc, char *argv[]) > } > > if_freenameindex (ifnp); > +#endif /* HAVE_NET_IF_H */ > > - return 0; > + return !IF_NAMESIZE + ni.if_index + !!ni.if_name; > } > -- > 1.7.11.4 > -- Cheers, Jasper "Stay Hungry. Stay Foolish"