[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: On OpenBSD and if_freenameindex(3).
From: |
Simon Josefsson |
Subject: |
Re: On OpenBSD and if_freenameindex(3). |
Date: |
Tue, 21 Sep 2010 14:22:03 +0200 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux) |
As an initial response to this problem, I'm installing a self check of
the net/if.h interface. See below. Mats, if you could quote the
compiler errors you get when building the self-check below on OpenBSD,
that would be useful. The next step is to see how gnulib can provide a
replacement that works on various systems. Perhaps OpenBSD isn't the
only system not working here.
/Simon
>From 3f130a97c39ecb2c388fa34f4123a33c27c66213 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Tue, 21 Sep 2010 14:19:58 +0200
Subject: [PATCH] New module to test <net/if.h> interfaces.
---
ChangeLog | 5 +++
modules/net_if-tests | 10 ++++++
tests/test-net_if.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 98 insertions(+), 0 deletions(-)
create mode 100644 modules/net_if-tests
create mode 100644 tests/test-net_if.c
diff --git a/ChangeLog b/ChangeLog
index ec48b91..4a62029 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-21 Simon Josefsson <address@hidden>
+
+ * tests/test-net_if.c: New file.
+ * modules/net_if-tests: New file.
+
2010-09-20 Paul Eggert <address@hidden>
pthread: add pthread_spin_destroy
diff --git a/modules/net_if-tests b/modules/net_if-tests
new file mode 100644
index 0000000..4349e85
--- /dev/null
+++ b/modules/net_if-tests
@@ -0,0 +1,10 @@
+Files:
+tests/test-net_if.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-net_if
+check_PROGRAMS += test-net_if
diff --git a/tests/test-net_if.c b/tests/test-net_if.c
new file mode 100644
index 0000000..f1cdb99
--- /dev/null
+++ b/tests/test-net_if.c
@@ -0,0 +1,83 @@
+/* Test of <net/if.h> functions.
+ Copyright (C) 2010 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 3 of the License, 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/>. */
+
+/* Written by Simon Josefsson <address@hidden>, 2010. */
+
+#include <config.h>
+#include <net/if.h>
+#include <stddef.h> /* NULL */
+#include <stdio.h> /* printf */
+
+int
+main (int argc, char *argv[])
+{
+ struct if_nameindex ifn, *ifnp, *p;
+ void (*if_fni) (struct if_nameindex *) = if_freenameindex;
+ char *(*if_itn)(unsigned, char *) = if_indextoname;
+ struct if_nameindex *(*if_ni)(void) = if_nameindex;
+ unsigned (*if_nti)(const char *) = if_nametoindex;
+
+ ifn.if_index = 42;
+ ifn.if_name = "foo";
+
+ p = ifnp = if_nameindex ();
+ if (ifnp == NULL)
+ {
+ printf ("if_nameindex returned NULL\n");
+ return 1;
+ }
+
+ while (p->if_index)
+ {
+ unsigned idx;
+ char buf[IF_NAMESIZE];
+ char *q;
+
+ if (argc > 1)
+ printf ("index %d name %s\n", p->if_index, p->if_name);
+
+ idx = if_nametoindex (p->if_name);
+ if (idx != p->if_index)
+ {
+ printf ("if_nametoindex (%s) = %d != %d\n",
+ p->if_name, idx, p->if_index);
+ return 1;
+ }
+
+ q = if_indextoname (p->if_index, buf);
+ if (q == NULL)
+ {
+ printf ("if_indextoname (%d) returned NULL\n", p->if_index);
+ return 1;
+ }
+ if (q != buf)
+ {
+ printf ("if_indextoname (%d) buffer mismatch?\n", p->if_index);
+ return 1;
+ }
+ if (strcmp (p->if_name, q) != 0)
+ {
+ printf ("if_indextoname (%s) = %s ?!\n", p->if_name, q);
+ return 1;
+ }
+
+ p++;
+ }
+
+ if_freenameindex (ifnp);
+
+ return 0;
+}
--
1.7.1
Re: On OpenBSD and if_freenameindex(3)., Eric Blake, 2010/09/21
Re: On OpenBSD and if_freenameindex(3)., Bruno Haible, 2010/09/21