xref: /minix3/tests/lib/libc/net/t_hostent.sh (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc# $NetBSD: t_hostent.sh,v 1.10 2014/01/13 11:08:14 gson Exp $
284d9c625SLionel Sambuc#
384d9c625SLionel Sambuc# Copyright (c) 2008 The NetBSD Foundation, Inc.
484d9c625SLionel Sambuc# All rights reserved.
584d9c625SLionel Sambuc#
684d9c625SLionel Sambuc# Redistribution and use in source and binary forms, with or without
784d9c625SLionel Sambuc# modification, are permitted provided that the following conditions
884d9c625SLionel Sambuc# are met:
984d9c625SLionel Sambuc# 1. Redistributions of source code must retain the above copyright
1084d9c625SLionel Sambuc#    notice, this list of conditions and the following disclaimer.
1184d9c625SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright
1284d9c625SLionel Sambuc#    notice, this list of conditions and the following disclaimer in the
1384d9c625SLionel Sambuc#    documentation and/or other materials provided with the distribution.
1484d9c625SLionel Sambuc#
1584d9c625SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1684d9c625SLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1784d9c625SLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1884d9c625SLionel Sambuc# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1984d9c625SLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2084d9c625SLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2184d9c625SLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2284d9c625SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2384d9c625SLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2484d9c625SLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2584d9c625SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE.
2684d9c625SLionel Sambuc#
2784d9c625SLionel Sambuc
2884d9c625SLionel Sambucn6="sixthavenue.astron.com"
29*0a6a1f1dSLionel Sambuca6="2620:106:3003:1f00:3e4a:92ff:fef4:e180"
3084d9c625SLionel Sambucans6="name=$n6, length=16, addrtype=24, aliases=[] addr_list=[$a6]\n"
3184d9c625SLionel Sambuc
3284d9c625SLionel Sambucn4="sixthavenue.astron.com"
33*0a6a1f1dSLionel Sambuca4="38.117.134.16"
3484d9c625SLionel Sambucans4="name=$n4, length=4, addrtype=2, aliases=[] addr_list=[$a4]\n"
3584d9c625SLionel Sambuc
3684d9c625SLionel Sambucl6="localhost"
3784d9c625SLionel Sambucal6="::1"
3884d9c625SLionel Sambucloc6="name=$l6, length=16, addrtype=24, aliases=[localhost. localhost.localdomain.] addr_list=[$al6]\n"
3984d9c625SLionel Sambuc
4084d9c625SLionel Sambucl4="localhost"
4184d9c625SLionel Sambucal4="127.0.0.1"
4284d9c625SLionel Sambucloc4="name=$l4, length=4, addrtype=2, aliases=[localhost. localhost.localdomain.] addr_list=[$al4]\n"
4384d9c625SLionel Sambuc
44*0a6a1f1dSLionel Sambucdir="$(atf_get_srcdir)"
45*0a6a1f1dSLionel Sambucres="-r ${dir}/resolv.conf"
46*0a6a1f1dSLionel Sambuc
47*0a6a1f1dSLionel Sambuc# Hijack DNS traffic using a single rump server instance and a DNS
48*0a6a1f1dSLionel Sambuc# server listening on its loopback address.
49*0a6a1f1dSLionel Sambuc
50*0a6a1f1dSLionel Sambucstart_dns_server() {
51*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=unix:///tmp/rumpserver
52*0a6a1f1dSLionel Sambuc	rump_server -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \
53*0a6a1f1dSLionel Sambuc	    -lrumpnet_netinet6 -lrumpnet_local $RUMP_SERVER
54*0a6a1f1dSLionel Sambuc	HIJACK_DNS="LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK='socket=inet:inet6'"
55*0a6a1f1dSLionel Sambuc	eval $HIJACK_DNS ${dir}/h_dns_server $1
56*0a6a1f1dSLionel Sambuc}
57*0a6a1f1dSLionel Sambuc
58*0a6a1f1dSLionel Sambucstop_dns_server() {
59*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=unix:///tmp/rumpserver
60*0a6a1f1dSLionel Sambuc	kill $(cat dns_server_$1.pid)
61*0a6a1f1dSLionel Sambuc	rump.halt
62*0a6a1f1dSLionel Sambuc}
63*0a6a1f1dSLionel Sambuc
64*0a6a1f1dSLionel Sambucatf_test_case gethostbyname4 cleanup
6584d9c625SLionel Sambucgethostbyname4_head()
6684d9c625SLionel Sambuc{
6784d9c625SLionel Sambuc	atf_set "descr" "Checks gethostbyname2(3) for AF_INET (auto, as determined by nsswitch.conf(5)"
6884d9c625SLionel Sambuc}
6984d9c625SLionel Sambucgethostbyname4_body()
7084d9c625SLionel Sambuc{
71*0a6a1f1dSLionel Sambuc	start_dns_server 4
72*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -4 $n4"
73*0a6a1f1dSLionel Sambuc}
74*0a6a1f1dSLionel Sambucgethostbyname4_cleanup()
75*0a6a1f1dSLionel Sambuc{
76*0a6a1f1dSLionel Sambuc	stop_dns_server 4
7784d9c625SLionel Sambuc}
7884d9c625SLionel Sambuc
79*0a6a1f1dSLionel Sambucatf_test_case gethostbyname6 cleanup cleanup
8084d9c625SLionel Sambucgethostbyname6_head()
8184d9c625SLionel Sambuc{
8284d9c625SLionel Sambuc	atf_set "descr" "Checks gethostbyname2(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)"
8384d9c625SLionel Sambuc}
8484d9c625SLionel Sambucgethostbyname6_body()
8584d9c625SLionel Sambuc{
86*0a6a1f1dSLionel Sambuc	start_dns_server 4
87*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -6 $n6"
88*0a6a1f1dSLionel Sambuc}
89*0a6a1f1dSLionel Sambucgethostbyname6_cleanup()
90*0a6a1f1dSLionel Sambuc{
91*0a6a1f1dSLionel Sambuc	stop_dns_server 4
9284d9c625SLionel Sambuc}
9384d9c625SLionel Sambuc
94*0a6a1f1dSLionel Sambucatf_test_case gethostbyaddr4 cleanup
9584d9c625SLionel Sambucgethostbyaddr4_head()
9684d9c625SLionel Sambuc{
9784d9c625SLionel Sambuc	atf_set "descr" "Checks gethostbyaddr(3) for AF_INET (auto, as determined by nsswitch.conf(5)"
9884d9c625SLionel Sambuc}
9984d9c625SLionel Sambucgethostbyaddr4_body()
10084d9c625SLionel Sambuc{
101*0a6a1f1dSLionel Sambuc	start_dns_server 4
102*0a6a1f1dSLionel Sambuc        atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a4"
103*0a6a1f1dSLionel Sambuc}
104*0a6a1f1dSLionel Sambucgethostbyaddr4_cleanup()
105*0a6a1f1dSLionel Sambuc{
106*0a6a1f1dSLionel Sambuc	stop_dns_server 4
10784d9c625SLionel Sambuc}
10884d9c625SLionel Sambuc
109*0a6a1f1dSLionel Sambucatf_test_case gethostbyaddr6 cleanup
11084d9c625SLionel Sambucgethostbyaddr6_head()
11184d9c625SLionel Sambuc{
11284d9c625SLionel Sambuc	atf_set "descr" "Checks gethostbyaddr(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)"
11384d9c625SLionel Sambuc}
11484d9c625SLionel Sambucgethostbyaddr6_body()
11584d9c625SLionel Sambuc{
116*0a6a1f1dSLionel Sambuc	start_dns_server 4
117*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a6"
118*0a6a1f1dSLionel Sambuc}
119*0a6a1f1dSLionel Sambucgethostbyaddr6_cleanup()
120*0a6a1f1dSLionel Sambuc{
121*0a6a1f1dSLionel Sambuc	stop_dns_server 4
12284d9c625SLionel Sambuc}
12384d9c625SLionel Sambuc
12484d9c625SLionel Sambucatf_test_case hostsbynamelookup4
12584d9c625SLionel Sambuchostsbynamelookup4_head()
12684d9c625SLionel Sambuc{
12784d9c625SLionel Sambuc	atf_set "descr" "Checks /etc/hosts name lookup for AF_INET"
12884d9c625SLionel Sambuc}
12984d9c625SLionel Sambuchostsbynamelookup4_body()
13084d9c625SLionel Sambuc{
131*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 $l4"
13284d9c625SLionel Sambuc}
13384d9c625SLionel Sambuc
13484d9c625SLionel Sambucatf_test_case hostsbynamelookup6
13584d9c625SLionel Sambuchostsbynamelookup6_head()
13684d9c625SLionel Sambuc{
13784d9c625SLionel Sambuc	atf_set "descr" "Checks /etc/hosts name lookup for AF_INET6"
13884d9c625SLionel Sambuc}
13984d9c625SLionel Sambuchostsbynamelookup6_body()
14084d9c625SLionel Sambuc{
141*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 $l6"
14284d9c625SLionel Sambuc}
14384d9c625SLionel Sambuc
14484d9c625SLionel Sambucatf_test_case hostsbyaddrlookup4
14584d9c625SLionel Sambuchostsbyaddrlookup4_head()
14684d9c625SLionel Sambuc{
14784d9c625SLionel Sambuc	atf_set "descr" "Checks /etc/hosts address lookup for AF_INET"
14884d9c625SLionel Sambuc}
14984d9c625SLionel Sambuchostsbyaddrlookup4_body()
15084d9c625SLionel Sambuc{
151*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 -a $al4"
15284d9c625SLionel Sambuc}
15384d9c625SLionel Sambuc
15484d9c625SLionel Sambucatf_test_case hostsbyaddrlookup6
15584d9c625SLionel Sambuchostsbyaddrlookup6_head()
15684d9c625SLionel Sambuc{
15784d9c625SLionel Sambuc	atf_set "descr" "Checks /etc/hosts address lookup for AF_INET6"
15884d9c625SLionel Sambuc}
15984d9c625SLionel Sambuchostsbyaddrlookup6_body()
16084d9c625SLionel Sambuc{
161*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 -a $al6"
16284d9c625SLionel Sambuc}
16384d9c625SLionel Sambuc
164*0a6a1f1dSLionel Sambucatf_test_case dnsbynamelookup4 cleanup
16584d9c625SLionel Sambucdnsbynamelookup4_head()
16684d9c625SLionel Sambuc{
16784d9c625SLionel Sambuc	atf_set "descr" "Checks DNS name lookup for AF_INET"
16884d9c625SLionel Sambuc}
16984d9c625SLionel Sambucdnsbynamelookup4_body()
17084d9c625SLionel Sambuc{
171*0a6a1f1dSLionel Sambuc	start_dns_server 4
172*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 $n4"
173*0a6a1f1dSLionel Sambuc}
174*0a6a1f1dSLionel Sambucdnsbynamelookup4_cleanup()
175*0a6a1f1dSLionel Sambuc{
176*0a6a1f1dSLionel Sambuc	stop_dns_server 4
17784d9c625SLionel Sambuc}
17884d9c625SLionel Sambuc
179*0a6a1f1dSLionel Sambucatf_test_case dnsbynamelookup6 cleanup
18084d9c625SLionel Sambucdnsbynamelookup6_head()
18184d9c625SLionel Sambuc{
18284d9c625SLionel Sambuc	atf_set "descr" "Checks DNS name lookup for AF_INET6"
18384d9c625SLionel Sambuc}
18484d9c625SLionel Sambucdnsbynamelookup6_body()
18584d9c625SLionel Sambuc{
186*0a6a1f1dSLionel Sambuc	start_dns_server 4
187*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 $n6"
188*0a6a1f1dSLionel Sambuc}
189*0a6a1f1dSLionel Sambucdnsbynamelookup6_cleanup()
190*0a6a1f1dSLionel Sambuc{
191*0a6a1f1dSLionel Sambuc	stop_dns_server 4
19284d9c625SLionel Sambuc}
19384d9c625SLionel Sambuc
194*0a6a1f1dSLionel Sambucatf_test_case dnsbyaddrlookup4 cleanup
19584d9c625SLionel Sambucdnsbyaddrlookup4_head()
19684d9c625SLionel Sambuc{
19784d9c625SLionel Sambuc	atf_set "descr" "Checks DNS address lookup for AF_INET"
19884d9c625SLionel Sambuc}
19984d9c625SLionel Sambucdnsbyaddrlookup4_body()
20084d9c625SLionel Sambuc{
201*0a6a1f1dSLionel Sambuc	start_dns_server 4
202*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 -a $a4"
203*0a6a1f1dSLionel Sambuc}
204*0a6a1f1dSLionel Sambucdnsbyaddrlookup4_cleanup()
205*0a6a1f1dSLionel Sambuc{
206*0a6a1f1dSLionel Sambuc	stop_dns_server 4
20784d9c625SLionel Sambuc}
20884d9c625SLionel Sambuc
209*0a6a1f1dSLionel Sambucatf_test_case dnsbyaddrlookup6 cleanup
21084d9c625SLionel Sambucdnsbyaddrlookup6_head()
21184d9c625SLionel Sambuc{
21284d9c625SLionel Sambuc	atf_set "descr" "Checks dns address lookup for AF_INET6"
21384d9c625SLionel Sambuc}
21484d9c625SLionel Sambucdnsbyaddrlookup6_body()
21584d9c625SLionel Sambuc{
216*0a6a1f1dSLionel Sambuc	start_dns_server 4
217*0a6a1f1dSLionel Sambuc	atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 -a $a6"
218*0a6a1f1dSLionel Sambuc}
219*0a6a1f1dSLionel Sambucdnsbyaddrlookup6_cleanup()
220*0a6a1f1dSLionel Sambuc{
221*0a6a1f1dSLionel Sambuc	stop_dns_server 4
22284d9c625SLionel Sambuc}
22384d9c625SLionel Sambuc
22484d9c625SLionel Sambucatf_init_test_cases()
22584d9c625SLionel Sambuc{
22684d9c625SLionel Sambuc	atf_add_test_case gethostbyname4
22784d9c625SLionel Sambuc	atf_add_test_case gethostbyname6
22884d9c625SLionel Sambuc	atf_add_test_case gethostbyaddr4
22984d9c625SLionel Sambuc	atf_add_test_case gethostbyaddr6
23084d9c625SLionel Sambuc
23184d9c625SLionel Sambuc	atf_add_test_case hostsbynamelookup4
23284d9c625SLionel Sambuc	atf_add_test_case hostsbynamelookup6
23384d9c625SLionel Sambuc	atf_add_test_case hostsbyaddrlookup4
23484d9c625SLionel Sambuc	atf_add_test_case hostsbyaddrlookup6
23584d9c625SLionel Sambuc
23684d9c625SLionel Sambuc	atf_add_test_case dnsbynamelookup4
23784d9c625SLionel Sambuc	atf_add_test_case dnsbynamelookup6
23884d9c625SLionel Sambuc	atf_add_test_case dnsbyaddrlookup4
23984d9c625SLionel Sambuc	atf_add_test_case dnsbyaddrlookup6
24084d9c625SLionel Sambuc}
241