summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclaudio <>2015-10-22 15:47:00 +0000
committerclaudio <>2015-10-22 15:47:00 +0000
commitfade978361a46e40e536507c555c496dc408eeaf (patch)
tree7c2028fc6423438ca06457499f61c73ca39d68b6
parentca8f4781e1e4eb0cbcd85f1b12896c0233628d5c (diff)
downloadopenbsd-fade978361a46e40e536507c555c496dc408eeaf.tar.gz
openbsd-fade978361a46e40e536507c555c496dc408eeaf.tar.bz2
openbsd-fade978361a46e40e536507c555c496dc408eeaf.zip
Add a regress test for if_indextoname() and if_nametoindex()
-rw-r--r--src/regress/lib/libc/ifnameindex/Makefile12
-rw-r--r--src/regress/lib/libc/ifnameindex/ifnitest.c30
2 files changed, 42 insertions, 0 deletions
diff --git a/src/regress/lib/libc/ifnameindex/Makefile b/src/regress/lib/libc/ifnameindex/Makefile
new file mode 100644
index 0000000000..1f21973a10
--- /dev/null
+++ b/src/regress/lib/libc/ifnameindex/Makefile
@@ -0,0 +1,12 @@
1# $OpenBSD: Makefile,v 1.1 2015/10/22 15:47:00 claudio Exp $
2
3PROG= ifnitest
4SRCS= ifnitest.c
5NOMAN= # defined
6
7REGRESS_TARGETS=do-test
8
9do-test: ${PROG}
10 ./${PROG}
11
12.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/ifnameindex/ifnitest.c b/src/regress/lib/libc/ifnameindex/ifnitest.c
new file mode 100644
index 0000000000..61102f77a9
--- /dev/null
+++ b/src/regress/lib/libc/ifnameindex/ifnitest.c
@@ -0,0 +1,30 @@
1/* $OpenBSD: ifnitest.c,v 1.1 2015/10/22 15:47:00 claudio Exp $ */
2
3/* Public domain. 2015, Claudio Jeker */
4
5#include <sys/types.h>
6#include <sys/socket.h>
7#include <net/if.h>
8#include <err.h>
9
10int
11main(int argc, char *argv[])
12{
13 char name[IF_NAMESIZE], *ifname;
14 unsigned int lo0index;
15
16 lo0index = if_nametoindex("lo0");
17 if (lo0index == 0)
18 err(1, "if_nametoindex(lo0)");
19 ifname = if_indextoname(lo0index, name);
20 if (ifname == NULL || strcmp("lo0", ifname) != 0)
21 err(1, "if_indextoname(%u)", lo0index);
22
23 /* test failures */
24 if (if_nametoindex("4kingbula") != 0)
25 err(1, "if_nametoindex(4kingbula)");
26 if (if_indextoname(65536, name) != NULL)
27 err(1, "if_indextoname(%u)", 65536);
28
29 return 0;
30}