1 # $NetBSD: t_getaddrinfo.sh,v 1.2 2011/06/15 07:54:32 jmmv Exp $
4 # Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. Neither the name of the project nor the names of its contributors
16 # may be used to endorse or promote products derived from this software
17 # without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 if [ "$2" = "none" ] ; then
36 elif [ "$2" = "hosts" ] ; then
37 # Determine if localhost has an IPv6 address or not
38 lcl
=$
( cat /etc
/hosts | \
39 sed -e 's/#.*$//' -e 's/[ ][ ]*/ /g' | \
40 awk '/ localhost($| )/ {printf "%s ", $1}' )
41 if [ "${lcl%*::*}" = "${lcl}" ] ; then
46 elif [ "$2" = "ifconfig" ] ; then
47 lcl
=$
( ifconfig lo0 |
grep inet6
)
48 if [ -n "${lcl}" ] ; then
54 atf_fail
"Invalid family_match_type $2 requested."
57 cmp -s $
(atf_get_srcdir
)/data
/${exp} out
&& return
58 diff -u $
(atf_get_srcdir
)/data
/${exp} out
&& \
59 atf_fail
"Actual output does not match expected output"
65 atf_set
"descr" "Testing basic ones"
69 TEST
=$
(atf_get_srcdir
)/h_gai
79 $TEST localhost
echo ) > out
2>&1
81 check_output basics hosts
84 atf_test_case specific
87 atf_set
"descr" "Testing specific address family"
91 TEST
=$
(atf_get_srcdir
)/h_gai
93 ( $TEST -4 localhost http
94 $TEST -6 localhost http
) > out
2>&1
96 check_output spec_fam hosts
99 atf_test_case empty_hostname
100 empty_hostname_head
()
102 atf_set
"descr" "Testing empty hostname"
104 empty_hostname_body
()
106 TEST
=$
(atf_get_srcdir
)/h_gai
117 $TEST -D '' 80 ) > out
2>&1
119 check_output no_host ifconfig
122 atf_test_case empty_servname
123 empty_servname_head
()
125 atf_set
"descr" "Testing empty service name"
127 empty_servname_body
()
129 TEST
=$
(atf_get_srcdir
)/h_gai
134 $TEST '' '' ) > out
2>&1
136 check_output no_serv hosts
139 atf_test_case sock_raw
142 atf_set
"descr" "Testing raw socket"
146 TEST
=$
(atf_get_srcdir
)/h_gai
148 ( $TEST -R -p 0 localhost
''
149 $TEST -R -p 59 localhost
''
150 $TEST -R -p 59 localhost
80
151 $TEST -R -p 59 localhost www
152 $TEST -R -p 59 ::1 '' ) > out
2>&1
154 check_output sock_raw hosts
157 atf_test_case unsupported_family
158 unsupported_family_head
()
160 atf_set
"descr" "Testing unsupported family"
162 unsupported_family_body
()
164 TEST
=$
(atf_get_srcdir
)/h_gai
166 ( $TEST -f 99 localhost
'' ) > out
2>&1
168 check_output unsup_fam none
171 atf_test_case scopeaddr
174 atf_set
"descr" "Testing scoped address format"
178 TEST
=$
(atf_get_srcdir
)/h_gai
180 ( $TEST fe80
::1%lo0 http
181 # IF=`ifconfig -a | grep -v '^ ' | \
182 # sed -e 's/:.*//' | head -1 | awk '{print $1}'`
183 # $TEST fe80::1%$IF http
186 check_output scoped none
189 atf_init_test_cases
()
191 atf_add_test_case basic
192 atf_add_test_case specific
193 atf_add_test_case empty_hostname
194 atf_add_test_case empty_servname
195 atf_add_test_case sock_raw
196 atf_add_test_case unsupported_family
197 atf_add_test_case scopeaddr