xref: /freebsd/contrib/netbsd-tests/lib/libc/net/t_hostent.sh (revision 9268022b74279434ed6300244e3f977e56a8ceb5)
1*57718be8SEnji Cooper# $NetBSD: t_hostent.sh,v 1.10 2014/01/13 11:08:14 gson Exp $
2*57718be8SEnji Cooper#
3*57718be8SEnji Cooper# Copyright (c) 2008 The NetBSD Foundation, Inc.
4*57718be8SEnji Cooper# All rights reserved.
5*57718be8SEnji Cooper#
6*57718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without
7*57718be8SEnji Cooper# modification, are permitted provided that the following conditions
8*57718be8SEnji Cooper# are met:
9*57718be8SEnji Cooper# 1. Redistributions of source code must retain the above copyright
10*57718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer.
11*57718be8SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
12*57718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
13*57718be8SEnji Cooper#    documentation and/or other materials provided with the distribution.
14*57718be8SEnji Cooper#
15*57718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16*57718be8SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17*57718be8SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18*57718be8SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19*57718be8SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20*57718be8SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21*57718be8SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*57718be8SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23*57718be8SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24*57718be8SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*57718be8SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
26*57718be8SEnji Cooper#
27*57718be8SEnji Cooper
28*57718be8SEnji Coopern6="sixthavenue.astron.com"
29*57718be8SEnji Coopera6="2620:106:3003:1f00:3e4a:92ff:fef4:e180"
30*57718be8SEnji Cooperans6="name=$n6, length=16, addrtype=24, aliases=[] addr_list=[$a6]\n"
31*57718be8SEnji Cooper
32*57718be8SEnji Coopern4="sixthavenue.astron.com"
33*57718be8SEnji Coopera4="38.117.134.16"
34*57718be8SEnji Cooperans4="name=$n4, length=4, addrtype=2, aliases=[] addr_list=[$a4]\n"
35*57718be8SEnji Cooper
36*57718be8SEnji Cooperl6="localhost"
37*57718be8SEnji Cooperal6="::1"
38*57718be8SEnji Cooperloc6="name=$l6, length=16, addrtype=24, aliases=[localhost. localhost.localdomain.] addr_list=[$al6]\n"
39*57718be8SEnji Cooper
40*57718be8SEnji Cooperl4="localhost"
41*57718be8SEnji Cooperal4="127.0.0.1"
42*57718be8SEnji Cooperloc4="name=$l4, length=4, addrtype=2, aliases=[localhost. localhost.localdomain.] addr_list=[$al4]\n"
43*57718be8SEnji Cooper
44*57718be8SEnji Cooperdir="$(atf_get_srcdir)"
45*57718be8SEnji Cooperres="-r ${dir}/resolv.conf"
46*57718be8SEnji Cooper
47*57718be8SEnji Cooper# Hijack DNS traffic using a single rump server instance and a DNS
48*57718be8SEnji Cooper# server listening on its loopback address.
49*57718be8SEnji Cooper
50*57718be8SEnji Cooperstart_dns_server() {
51*57718be8SEnji Cooper	export RUMP_SERVER=unix:///tmp/rumpserver
52*57718be8SEnji Cooper	rump_server -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \
53*57718be8SEnji Cooper	    -lrumpnet_netinet6 -lrumpnet_local $RUMP_SERVER
54*57718be8SEnji Cooper	HIJACK_DNS="LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK='socket=inet:inet6'"
55*57718be8SEnji Cooper	eval $HIJACK_DNS ${dir}/h_dns_server $1
56*57718be8SEnji Cooper}
57*57718be8SEnji Cooper
58*57718be8SEnji Cooperstop_dns_server() {
59*57718be8SEnji Cooper	export RUMP_SERVER=unix:///tmp/rumpserver
60*57718be8SEnji Cooper	kill $(cat dns_server_$1.pid)
61*57718be8SEnji Cooper	rump.halt
62*57718be8SEnji Cooper}
63*57718be8SEnji Cooper
64*57718be8SEnji Cooperatf_test_case gethostbyname4 cleanup
65*57718be8SEnji Coopergethostbyname4_head()
66*57718be8SEnji Cooper{
67*57718be8SEnji Cooper	atf_set "descr" "Checks gethostbyname2(3) for AF_INET (auto, as determined by nsswitch.conf(5)"
68*57718be8SEnji Cooper}
69*57718be8SEnji Coopergethostbyname4_body()
70*57718be8SEnji Cooper{
71*57718be8SEnji Cooper	start_dns_server 4
72*57718be8SEnji Cooper	atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -4 $n4"
73*57718be8SEnji Cooper}
74*57718be8SEnji Coopergethostbyname4_cleanup()
75*57718be8SEnji Cooper{
76*57718be8SEnji Cooper	stop_dns_server 4
77*57718be8SEnji Cooper}
78*57718be8SEnji Cooper
79*57718be8SEnji Cooperatf_test_case gethostbyname6 cleanup cleanup
80*57718be8SEnji Coopergethostbyname6_head()
81*57718be8SEnji Cooper{
82*57718be8SEnji Cooper	atf_set "descr" "Checks gethostbyname2(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)"
83*57718be8SEnji Cooper}
84*57718be8SEnji Coopergethostbyname6_body()
85*57718be8SEnji Cooper{
86*57718be8SEnji Cooper	start_dns_server 4
87*57718be8SEnji Cooper	atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -6 $n6"
88*57718be8SEnji Cooper}
89*57718be8SEnji Coopergethostbyname6_cleanup()
90*57718be8SEnji Cooper{
91*57718be8SEnji Cooper	stop_dns_server 4
92*57718be8SEnji Cooper}
93*57718be8SEnji Cooper
94*57718be8SEnji Cooperatf_test_case gethostbyaddr4 cleanup
95*57718be8SEnji Coopergethostbyaddr4_head()
96*57718be8SEnji Cooper{
97*57718be8SEnji Cooper	atf_set "descr" "Checks gethostbyaddr(3) for AF_INET (auto, as determined by nsswitch.conf(5)"
98*57718be8SEnji Cooper}
99*57718be8SEnji Coopergethostbyaddr4_body()
100*57718be8SEnji Cooper{
101*57718be8SEnji Cooper	start_dns_server 4
102*57718be8SEnji Cooper        atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a4"
103*57718be8SEnji Cooper}
104*57718be8SEnji Coopergethostbyaddr4_cleanup()
105*57718be8SEnji Cooper{
106*57718be8SEnji Cooper	stop_dns_server 4
107*57718be8SEnji Cooper}
108*57718be8SEnji Cooper
109*57718be8SEnji Cooperatf_test_case gethostbyaddr6 cleanup
110*57718be8SEnji Coopergethostbyaddr6_head()
111*57718be8SEnji Cooper{
112*57718be8SEnji Cooper	atf_set "descr" "Checks gethostbyaddr(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)"
113*57718be8SEnji Cooper}
114*57718be8SEnji Coopergethostbyaddr6_body()
115*57718be8SEnji Cooper{
116*57718be8SEnji Cooper	start_dns_server 4
117*57718be8SEnji Cooper	atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a6"
118*57718be8SEnji Cooper}
119*57718be8SEnji Coopergethostbyaddr6_cleanup()
120*57718be8SEnji Cooper{
121*57718be8SEnji Cooper	stop_dns_server 4
122*57718be8SEnji Cooper}
123*57718be8SEnji Cooper
124*57718be8SEnji Cooperatf_test_case hostsbynamelookup4
125*57718be8SEnji Cooperhostsbynamelookup4_head()
126*57718be8SEnji Cooper{
127*57718be8SEnji Cooper	atf_set "descr" "Checks /etc/hosts name lookup for AF_INET"
128*57718be8SEnji Cooper}
129*57718be8SEnji Cooperhostsbynamelookup4_body()
130*57718be8SEnji Cooper{
131*57718be8SEnji Cooper	atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 $l4"
132*57718be8SEnji Cooper}
133*57718be8SEnji Cooper
134*57718be8SEnji Cooperatf_test_case hostsbynamelookup6
135*57718be8SEnji Cooperhostsbynamelookup6_head()
136*57718be8SEnji Cooper{
137*57718be8SEnji Cooper	atf_set "descr" "Checks /etc/hosts name lookup for AF_INET6"
138*57718be8SEnji Cooper}
139*57718be8SEnji Cooperhostsbynamelookup6_body()
140*57718be8SEnji Cooper{
141*57718be8SEnji Cooper	atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 $l6"
142*57718be8SEnji Cooper}
143*57718be8SEnji Cooper
144*57718be8SEnji Cooperatf_test_case hostsbyaddrlookup4
145*57718be8SEnji Cooperhostsbyaddrlookup4_head()
146*57718be8SEnji Cooper{
147*57718be8SEnji Cooper	atf_set "descr" "Checks /etc/hosts address lookup for AF_INET"
148*57718be8SEnji Cooper}
149*57718be8SEnji Cooperhostsbyaddrlookup4_body()
150*57718be8SEnji Cooper{
151*57718be8SEnji Cooper	atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 -a $al4"
152*57718be8SEnji Cooper}
153*57718be8SEnji Cooper
154*57718be8SEnji Cooperatf_test_case hostsbyaddrlookup6
155*57718be8SEnji Cooperhostsbyaddrlookup6_head()
156*57718be8SEnji Cooper{
157*57718be8SEnji Cooper	atf_set "descr" "Checks /etc/hosts address lookup for AF_INET6"
158*57718be8SEnji Cooper}
159*57718be8SEnji Cooperhostsbyaddrlookup6_body()
160*57718be8SEnji Cooper{
161*57718be8SEnji Cooper	atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 -a $al6"
162*57718be8SEnji Cooper}
163*57718be8SEnji Cooper
164*57718be8SEnji Cooperatf_test_case dnsbynamelookup4 cleanup
165*57718be8SEnji Cooperdnsbynamelookup4_head()
166*57718be8SEnji Cooper{
167*57718be8SEnji Cooper	atf_set "descr" "Checks DNS name lookup for AF_INET"
168*57718be8SEnji Cooper}
169*57718be8SEnji Cooperdnsbynamelookup4_body()
170*57718be8SEnji Cooper{
171*57718be8SEnji Cooper	start_dns_server 4
172*57718be8SEnji Cooper	atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 $n4"
173*57718be8SEnji Cooper}
174*57718be8SEnji Cooperdnsbynamelookup4_cleanup()
175*57718be8SEnji Cooper{
176*57718be8SEnji Cooper	stop_dns_server 4
177*57718be8SEnji Cooper}
178*57718be8SEnji Cooper
179*57718be8SEnji Cooperatf_test_case dnsbynamelookup6 cleanup
180*57718be8SEnji Cooperdnsbynamelookup6_head()
181*57718be8SEnji Cooper{
182*57718be8SEnji Cooper	atf_set "descr" "Checks DNS name lookup for AF_INET6"
183*57718be8SEnji Cooper}
184*57718be8SEnji Cooperdnsbynamelookup6_body()
185*57718be8SEnji Cooper{
186*57718be8SEnji Cooper	start_dns_server 4
187*57718be8SEnji Cooper	atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 $n6"
188*57718be8SEnji Cooper}
189*57718be8SEnji Cooperdnsbynamelookup6_cleanup()
190*57718be8SEnji Cooper{
191*57718be8SEnji Cooper	stop_dns_server 4
192*57718be8SEnji Cooper}
193*57718be8SEnji Cooper
194*57718be8SEnji Cooperatf_test_case dnsbyaddrlookup4 cleanup
195*57718be8SEnji Cooperdnsbyaddrlookup4_head()
196*57718be8SEnji Cooper{
197*57718be8SEnji Cooper	atf_set "descr" "Checks DNS address lookup for AF_INET"
198*57718be8SEnji Cooper}
199*57718be8SEnji Cooperdnsbyaddrlookup4_body()
200*57718be8SEnji Cooper{
201*57718be8SEnji Cooper	start_dns_server 4
202*57718be8SEnji Cooper	atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 -a $a4"
203*57718be8SEnji Cooper}
204*57718be8SEnji Cooperdnsbyaddrlookup4_cleanup()
205*57718be8SEnji Cooper{
206*57718be8SEnji Cooper	stop_dns_server 4
207*57718be8SEnji Cooper}
208*57718be8SEnji Cooper
209*57718be8SEnji Cooperatf_test_case dnsbyaddrlookup6 cleanup
210*57718be8SEnji Cooperdnsbyaddrlookup6_head()
211*57718be8SEnji Cooper{
212*57718be8SEnji Cooper	atf_set "descr" "Checks dns address lookup for AF_INET6"
213*57718be8SEnji Cooper}
214*57718be8SEnji Cooperdnsbyaddrlookup6_body()
215*57718be8SEnji Cooper{
216*57718be8SEnji Cooper	start_dns_server 4
217*57718be8SEnji Cooper	atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 -a $a6"
218*57718be8SEnji Cooper}
219*57718be8SEnji Cooperdnsbyaddrlookup6_cleanup()
220*57718be8SEnji Cooper{
221*57718be8SEnji Cooper	stop_dns_server 4
222*57718be8SEnji Cooper}
223*57718be8SEnji Cooper
224*57718be8SEnji Cooperatf_init_test_cases()
225*57718be8SEnji Cooper{
226*57718be8SEnji Cooper	atf_add_test_case gethostbyname4
227*57718be8SEnji Cooper	atf_add_test_case gethostbyname6
228*57718be8SEnji Cooper	atf_add_test_case gethostbyaddr4
229*57718be8SEnji Cooper	atf_add_test_case gethostbyaddr6
230*57718be8SEnji Cooper
231*57718be8SEnji Cooper	atf_add_test_case hostsbynamelookup4
232*57718be8SEnji Cooper	atf_add_test_case hostsbynamelookup6
233*57718be8SEnji Cooper	atf_add_test_case hostsbyaddrlookup4
234*57718be8SEnji Cooper	atf_add_test_case hostsbyaddrlookup6
235*57718be8SEnji Cooper
236*57718be8SEnji Cooper	atf_add_test_case dnsbynamelookup4
237*57718be8SEnji Cooper	atf_add_test_case dnsbynamelookup6
238*57718be8SEnji Cooper	atf_add_test_case dnsbyaddrlookup4
239*57718be8SEnji Cooper	atf_add_test_case dnsbyaddrlookup6
240*57718be8SEnji Cooper}
241