11.1Smsaitoh/*	$NetBSD: t_if_nametoindex.c,v 1.1 2018/08/06 04:50:11 msaitoh Exp $	*/
21.1Smsaitoh
31.1Smsaitoh/*-
41.1Smsaitoh * Copyright (c) 2010 The NetBSD Foundation, Inc.
51.1Smsaitoh * All rights reserved.
61.1Smsaitoh *
71.1Smsaitoh * This code is derived from software contributed to The NetBSD Foundation
81.1Smsaitoh * by Christos Zoulas.
91.1Smsaitoh *
101.1Smsaitoh * Redistribution and use in source and binary forms, with or without
111.1Smsaitoh * modification, are permitted provided that the following conditions
121.1Smsaitoh * are met:
131.1Smsaitoh * 1. Redistributions of source code must retain the above copyright
141.1Smsaitoh *    notice, this list of conditions and the following disclaimer.
151.1Smsaitoh * 2. Redistributions in binary form must reproduce the above copyright
161.1Smsaitoh *    notice, this list of conditions and the following disclaimer in the
171.1Smsaitoh *    documentation and/or other materials provided with the distribution.
181.1Smsaitoh * 3. All advertising materials mentioning features or use of this software
191.1Smsaitoh *    must display the following acknowledgement:
201.1Smsaitoh *        This product includes software developed by the NetBSD
211.1Smsaitoh *        Foundation, Inc. and its contributors.
221.1Smsaitoh * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Smsaitoh *    contributors may be used to endorse or promote products derived
241.1Smsaitoh *    from this software without specific prior written permission.
251.1Smsaitoh *
261.1Smsaitoh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Smsaitoh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Smsaitoh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Smsaitoh * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Smsaitoh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Smsaitoh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Smsaitoh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Smsaitoh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Smsaitoh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Smsaitoh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Smsaitoh * POSSIBILITY OF SUCH DAMAGE.
371.1Smsaitoh */
381.1Smsaitoh#include <sys/cdefs.h>
391.1Smsaitoh__RCSID("$NetBSD: t_if_nametoindex.c,v 1.1 2018/08/06 04:50:11 msaitoh Exp $");
401.1Smsaitoh
411.1Smsaitoh#include <atf-c.h>
421.1Smsaitoh#include <stdio.h>
431.1Smsaitoh#include <ctype.h>
441.1Smsaitoh#include <sys/types.h>
451.1Smsaitoh#include <net/if.h>
461.1Smsaitoh#include <err.h>
471.1Smsaitoh#include <string.h>
481.1Smsaitoh#include <errno.h>
491.1Smsaitoh
501.1SmsaitohATF_TC(tc_if_nametoindex);
511.1SmsaitohATF_TC_HEAD(tc_if_nametoindex, tc)
521.1Smsaitoh{
531.1Smsaitoh	atf_tc_set_md_var(tc, "descr", "Check that if_nametoindex(3) works");
541.1Smsaitoh}
551.1Smsaitoh
561.1SmsaitohATF_TC_BODY(tc_if_nametoindex, tc)
571.1Smsaitoh{
581.1Smsaitoh	unsigned int r;
591.1Smsaitoh
601.1Smsaitoh	r = if_nametoindex("lo0");
611.1Smsaitoh	if (r == 0)
621.1Smsaitoh		atf_tc_fail("failed on lo0");
631.1Smsaitoh
641.1Smsaitoh	r = if_nametoindex("foo");
651.1Smsaitoh	if (errno != ENXIO)
661.1Smsaitoh		atf_tc_fail("foo's errno != ENXIO");
671.1Smsaitoh}
681.1Smsaitoh
691.1SmsaitohATF_TP_ADD_TCS(tp)
701.1Smsaitoh{
711.1Smsaitoh
721.1Smsaitoh	ATF_TP_ADD_TC(tp, tc_if_nametoindex);
731.1Smsaitoh
741.1Smsaitoh        return atf_no_error();
751.1Smsaitoh}
76