From fade978361a46e40e536507c555c496dc408eeaf Mon Sep 17 00:00:00 2001 From: claudio <> Date: Thu, 22 Oct 2015 15:47:00 +0000 Subject: Add a regress test for if_indextoname() and if_nametoindex() --- src/regress/lib/libc/ifnameindex/Makefile | 12 ++++++++++++ src/regress/lib/libc/ifnameindex/ifnitest.c | 30 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/regress/lib/libc/ifnameindex/Makefile create mode 100644 src/regress/lib/libc/ifnameindex/ifnitest.c (limited to 'src') 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 @@ +# $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 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 @@ +/* $OpenBSD: ifnitest.c,v 1.1 2015/10/22 15:47:00 claudio Exp $ */ + +/* Public domain. 2015, Claudio Jeker */ + +#include +#include +#include +#include + +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; +} -- cgit v1.2.3-55-g6feb