diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libc/ifnameindex/Makefile | 12 | ||||
| -rw-r--r-- | src/regress/lib/libc/ifnameindex/ifnitest.c | 30 |
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 | |||
| 3 | PROG= ifnitest | ||
| 4 | SRCS= ifnitest.c | ||
| 5 | NOMAN= # defined | ||
| 6 | |||
| 7 | REGRESS_TARGETS=do-test | ||
| 8 | |||
| 9 | do-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 | |||
| 10 | int | ||
| 11 | main(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 | } | ||
