summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2015-10-22 15:47:01 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2015-10-22 15:47:01 +0000
commit5ed7f14944e4379d50f3db38b14b93d04c52180a (patch)
treed16ee0825a33e19ca7fb2b863f1c9846643a8f2f
parent0bd95f0b63ec5e10ae7865b0db80ef56345fd9c2 (diff)
Add a regress test for if_indextoname() and if_nametoindex()
-rw-r--r--regress/lib/libc/ifnameindex/Makefile12
-rw-r--r--regress/lib/libc/ifnameindex/ifnitest.c30
2 files changed, 42 insertions, 0 deletions
diff --git a/regress/lib/libc/ifnameindex/Makefile b/regress/lib/libc/ifnameindex/Makefile
new file mode 100644
index 00000000000..1f21973a10e
--- /dev/null
+++ b/regress/lib/libc/ifnameindex/Makefile
@@ -0,0 +1,12 @@
+# $OpenBSD: Makefile,v 1.1 2015/10/22 15:47:00 claudio Exp $
+
+PROG= ifnitest
+SRCS= ifnitest.c
+NOMAN= # defined
+
+REGRESS_TARGETS=do-test
+
+do-test: ${PROG}
+ ./${PROG}
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libc/ifnameindex/ifnitest.c b/regress/lib/libc/ifnameindex/ifnitest.c
new file mode 100644
index 00000000000..61102f77a96
--- /dev/null
+++ b/regress/lib/libc/ifnameindex/ifnitest.c
@@ -0,0 +1,30 @@
+/* $OpenBSD: ifnitest.c,v 1.1 2015/10/22 15:47:00 claudio Exp $ */
+
+/* Public domain. 2015, Claudio Jeker */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <err.h>
+
+int
+main(int argc, char *argv[])
+{
+ char name[IF_NAMESIZE], *ifname;
+ unsigned int lo0index;
+
+ lo0index = if_nametoindex("lo0");
+ if (lo0index == 0)
+ err(1, "if_nametoindex(lo0)");
+ ifname = if_indextoname(lo0index, name);
+ if (ifname == NULL || strcmp("lo0", ifname) != 0)
+ err(1, "if_indextoname(%u)", lo0index);
+
+ /* test failures */
+ if (if_nametoindex("4kingbula") != 0)
+ err(1, "if_nametoindex(4kingbula)");
+ if (if_indextoname(65536, name) != NULL)
+ err(1, "if_indextoname(%u)", 65536);
+
+ return 0;
+}