xref: /netbsd-src/tests/lib/libc/net/t_if_nametoindex.c (revision dcdcd796aae69ec6fd9a46f590bf2d9a6d9058d9)
1*dcdcd796Smsaitoh /*	$NetBSD: t_if_nametoindex.c,v 1.1 2018/08/06 04:50:11 msaitoh Exp $	*/
2*dcdcd796Smsaitoh 
3*dcdcd796Smsaitoh /*-
4*dcdcd796Smsaitoh  * Copyright (c) 2010 The NetBSD Foundation, Inc.
5*dcdcd796Smsaitoh  * All rights reserved.
6*dcdcd796Smsaitoh  *
7*dcdcd796Smsaitoh  * This code is derived from software contributed to The NetBSD Foundation
8*dcdcd796Smsaitoh  * by Christos Zoulas.
9*dcdcd796Smsaitoh  *
10*dcdcd796Smsaitoh  * Redistribution and use in source and binary forms, with or without
11*dcdcd796Smsaitoh  * modification, are permitted provided that the following conditions
12*dcdcd796Smsaitoh  * are met:
13*dcdcd796Smsaitoh  * 1. Redistributions of source code must retain the above copyright
14*dcdcd796Smsaitoh  *    notice, this list of conditions and the following disclaimer.
15*dcdcd796Smsaitoh  * 2. Redistributions in binary form must reproduce the above copyright
16*dcdcd796Smsaitoh  *    notice, this list of conditions and the following disclaimer in the
17*dcdcd796Smsaitoh  *    documentation and/or other materials provided with the distribution.
18*dcdcd796Smsaitoh  * 3. All advertising materials mentioning features or use of this software
19*dcdcd796Smsaitoh  *    must display the following acknowledgement:
20*dcdcd796Smsaitoh  *        This product includes software developed by the NetBSD
21*dcdcd796Smsaitoh  *        Foundation, Inc. and its contributors.
22*dcdcd796Smsaitoh  * 4. Neither the name of The NetBSD Foundation nor the names of its
23*dcdcd796Smsaitoh  *    contributors may be used to endorse or promote products derived
24*dcdcd796Smsaitoh  *    from this software without specific prior written permission.
25*dcdcd796Smsaitoh  *
26*dcdcd796Smsaitoh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27*dcdcd796Smsaitoh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28*dcdcd796Smsaitoh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29*dcdcd796Smsaitoh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30*dcdcd796Smsaitoh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31*dcdcd796Smsaitoh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32*dcdcd796Smsaitoh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33*dcdcd796Smsaitoh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34*dcdcd796Smsaitoh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35*dcdcd796Smsaitoh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36*dcdcd796Smsaitoh  * POSSIBILITY OF SUCH DAMAGE.
37*dcdcd796Smsaitoh  */
38*dcdcd796Smsaitoh #include <sys/cdefs.h>
39*dcdcd796Smsaitoh __RCSID("$NetBSD: t_if_nametoindex.c,v 1.1 2018/08/06 04:50:11 msaitoh Exp $");
40*dcdcd796Smsaitoh 
41*dcdcd796Smsaitoh #include <atf-c.h>
42*dcdcd796Smsaitoh #include <stdio.h>
43*dcdcd796Smsaitoh #include <ctype.h>
44*dcdcd796Smsaitoh #include <sys/types.h>
45*dcdcd796Smsaitoh #include <net/if.h>
46*dcdcd796Smsaitoh #include <err.h>
47*dcdcd796Smsaitoh #include <string.h>
48*dcdcd796Smsaitoh #include <errno.h>
49*dcdcd796Smsaitoh 
50*dcdcd796Smsaitoh ATF_TC(tc_if_nametoindex);
ATF_TC_HEAD(tc_if_nametoindex,tc)51*dcdcd796Smsaitoh ATF_TC_HEAD(tc_if_nametoindex, tc)
52*dcdcd796Smsaitoh {
53*dcdcd796Smsaitoh 	atf_tc_set_md_var(tc, "descr", "Check that if_nametoindex(3) works");
54*dcdcd796Smsaitoh }
55*dcdcd796Smsaitoh 
ATF_TC_BODY(tc_if_nametoindex,tc)56*dcdcd796Smsaitoh ATF_TC_BODY(tc_if_nametoindex, tc)
57*dcdcd796Smsaitoh {
58*dcdcd796Smsaitoh 	unsigned int r;
59*dcdcd796Smsaitoh 
60*dcdcd796Smsaitoh 	r = if_nametoindex("lo0");
61*dcdcd796Smsaitoh 	if (r == 0)
62*dcdcd796Smsaitoh 		atf_tc_fail("failed on lo0");
63*dcdcd796Smsaitoh 
64*dcdcd796Smsaitoh 	r = if_nametoindex("foo");
65*dcdcd796Smsaitoh 	if (errno != ENXIO)
66*dcdcd796Smsaitoh 		atf_tc_fail("foo's errno != ENXIO");
67*dcdcd796Smsaitoh }
68*dcdcd796Smsaitoh 
ATF_TP_ADD_TCS(tp)69*dcdcd796Smsaitoh ATF_TP_ADD_TCS(tp)
70*dcdcd796Smsaitoh {
71*dcdcd796Smsaitoh 
72*dcdcd796Smsaitoh 	ATF_TP_ADD_TC(tp, tc_if_nametoindex);
73*dcdcd796Smsaitoh 
74*dcdcd796Smsaitoh         return atf_no_error();
75*dcdcd796Smsaitoh }
76