From: Eric Blake Date: Wed, 5 Sep 2012 20:28:47 +0000 (-0600) Subject: net_if: new module X-Git-Tag: v0.1~451 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=440a1dbe523e37f206252cb034c3a62f26867e42 net_if: new module OpenBSD's is not self-contained; this should compile: | #define _POSIX_C_SOURCE 200809L | #include | 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 . Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index dea1f8667..d9f6f89f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2012-09-05 Eric Blake + + 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 . + 2012-09-05 Mats Erik Andersson (tiny change) readutmp: fix non-portable UT_PID use diff --git a/MODULES.html.sh b/MODULES.html.sh index 8ced61175..0e3453182 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 38a52f4ae..fa01b6e77 100644 --- a/doc/posix-headers/net_if.texi +++ b/doc/posix-headers/net_if.texi @@ -3,10 +3,13 @@ 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 000000000..24f9f83fb --- /dev/null +++ b/lib/net_if.in.h @@ -0,0 +1,53 @@ +/* Substitute for . + 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 . */ + +#ifndef _@GUARD_PREFIX@_NET_IF_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if @HAVE_NET_IF_H@ + +/* On some platforms, assumes prior inclusion of + . */ +# include + +/* 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 . */ + +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 000000000..171101f51 --- /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 is self-contained], + [gl_cv_header_net_if_h_selfcontained], + [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[]])], + [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 ]]) + 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 000000000..9e30f0151 --- /dev/null +++ b/modules/net_if @@ -0,0 +1,49 @@ +Description: +A 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 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: + + +License: +LGPLv2+ + +Maintainer: +Eric Blake diff --git a/tests/test-net_if.c b/tests/test-net_if.c index ee3cdbdf4..f50864232 100644 --- a/tests/test-net_if.c +++ b/tests/test-net_if.c @@ -20,11 +20,17 @@ #include -#include "signature.h" +static struct if_nameindex ni; + +/* We do not yet have replacements for if_* functions on systems that + lack a native . */ +#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 /* NULL */ #include /* 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; }