+2012-09-05 Eric Blake <eblake@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 <jasper@humppa.nl>.
+
2012-09-05 Mats Erik Andersson <gnu@gisladisker.se> (tiny change)
readutmp: fix non-portable UT_PID use
func_module mkfifo
func_module mknod
func_module mkstemp
+ func_module net_if
func_module netdb
func_module netinet_in
func_module nl_langinfo
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:
--- /dev/null
+/* 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 */
--- /dev/null
+# 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"])
+])
--- /dev/null
+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
#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 */
int
main (int argc, char *argv[])
{
+#if HAVE_NET_IF_H
struct if_nameindex *ifnp, *p;
p = ifnp = if_nameindex ();
}
if_freenameindex (ifnp);
+#endif /* HAVE_NET_IF_H */
- return 0;
+ return !IF_NAMESIZE + ni.if_index + !!ni.if_name;
}