Home | History | Annotate | Line # | Download | only in getaddrinfo
t_getaddrinfo.sh revision 1.1.4.1
      1  1.1.4.1    cherry #	$NetBSD: t_getaddrinfo.sh,v 1.1.4.1 2011/06/23 14:20:39 cherry Exp $
      2      1.1  pgoyette 
      3      1.1  pgoyette #
      4      1.1  pgoyette # Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project.
      5      1.1  pgoyette # All rights reserved.
      6      1.1  pgoyette #
      7      1.1  pgoyette # Redistribution and use in source and binary forms, with or without
      8      1.1  pgoyette # modification, are permitted provided that the following conditions
      9      1.1  pgoyette # are met:
     10      1.1  pgoyette # 1. Redistributions of source code must retain the above copyright
     11      1.1  pgoyette #    notice, this list of conditions and the following disclaimer.
     12      1.1  pgoyette # 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  pgoyette #    notice, this list of conditions and the following disclaimer in the
     14      1.1  pgoyette #    documentation and/or other materials provided with the distribution.
     15      1.1  pgoyette # 3. Neither the name of the project nor the names of its contributors
     16      1.1  pgoyette #    may be used to endorse or promote products derived from this software
     17      1.1  pgoyette #    without specific prior written permission.
     18      1.1  pgoyette #
     19      1.1  pgoyette # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20      1.1  pgoyette # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21      1.1  pgoyette # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22      1.1  pgoyette # ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23      1.1  pgoyette # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24      1.1  pgoyette # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25      1.1  pgoyette # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26      1.1  pgoyette # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27      1.1  pgoyette # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28      1.1  pgoyette # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29      1.1  pgoyette # SUCH DAMAGE.
     30      1.1  pgoyette #
     31      1.1  pgoyette 
     32      1.1  pgoyette check_output()
     33      1.1  pgoyette {
     34      1.1  pgoyette 	if [ "$2" = "none" ] ; then
     35      1.1  pgoyette 		exp="${1}.exp"
     36      1.1  pgoyette 	elif [ "$2" = "hosts" ] ; then
     37      1.1  pgoyette 		# Determine if localhost has an IPv6 address or not
     38      1.1  pgoyette 		lcl=$( cat /etc/hosts					| \
     39      1.1  pgoyette 			 sed -e 's/#.*$//' -e 's/[ 	][ 	]*/ /g'	| \
     40      1.1  pgoyette 			 awk '/ localhost($| )/ {printf "%s ", $1}' )
     41      1.1  pgoyette 		if [ "${lcl%*::*}" = "${lcl}" ] ; then
     42      1.1  pgoyette 			exp="${1}_v4.exp"
     43      1.1  pgoyette 		else
     44      1.1  pgoyette 			exp="${1}_v4v6.exp"
     45      1.1  pgoyette 		fi
     46      1.1  pgoyette 	elif [ "$2" = "ifconfig" ] ; then
     47      1.1  pgoyette 		lcl=$( ifconfig lo0 | grep inet6 )
     48      1.1  pgoyette 		if [ -n "${lcl}" ] ; then
     49      1.1  pgoyette 			exp="${1}_v4v6.exp"
     50      1.1  pgoyette 		else
     51      1.1  pgoyette 			exp="${1}_v4.exp"
     52      1.1  pgoyette 		fi
     53      1.1  pgoyette 	else
     54      1.1  pgoyette 		atf_fail "Invalid family_match_type $2 requested."
     55      1.1  pgoyette 	fi
     56      1.1  pgoyette 
     57      1.1  pgoyette 	cmp  -s $(atf_get_srcdir)/data/${exp} out && return
     58      1.1  pgoyette 	diff -u $(atf_get_srcdir)/data/${exp} out && \
     59      1.1  pgoyette 	atf_fail "Actual output does not match expected output"
     60      1.1  pgoyette }
     61      1.1  pgoyette 
     62      1.1  pgoyette atf_test_case basic
     63      1.1  pgoyette basic_head()
     64      1.1  pgoyette {
     65      1.1  pgoyette 	atf_set "descr" "Testing basic ones"
     66      1.1  pgoyette }
     67      1.1  pgoyette basic_body()
     68      1.1  pgoyette {
     69      1.1  pgoyette 	TEST=$(atf_get_srcdir)/h_gai
     70      1.1  pgoyette 
     71      1.1  pgoyette 	( $TEST ::1 http
     72      1.1  pgoyette 	  $TEST 127.0.0.1 http
     73      1.1  pgoyette 	  $TEST localhost http
     74      1.1  pgoyette 	  $TEST ::1 tftp
     75      1.1  pgoyette 	  $TEST 127.0.0.1 tftp
     76      1.1  pgoyette 	  $TEST localhost tftp
     77      1.1  pgoyette 	  $TEST ::1 echo
     78      1.1  pgoyette 	  $TEST 127.0.0.1 echo
     79      1.1  pgoyette 	  $TEST localhost echo ) > out 2>&1
     80      1.1  pgoyette 
     81      1.1  pgoyette 	check_output basics hosts
     82      1.1  pgoyette }
     83      1.1  pgoyette 
     84      1.1  pgoyette atf_test_case specific
     85      1.1  pgoyette specific_head()
     86      1.1  pgoyette {
     87      1.1  pgoyette 	atf_set "descr" "Testing specific address family"
     88      1.1  pgoyette }
     89      1.1  pgoyette specific_body()
     90      1.1  pgoyette {
     91      1.1  pgoyette 	TEST=$(atf_get_srcdir)/h_gai
     92      1.1  pgoyette 
     93      1.1  pgoyette 	( $TEST -4 localhost http
     94      1.1  pgoyette 	  $TEST -6 localhost http ) > out 2>&1
     95      1.1  pgoyette 
     96      1.1  pgoyette 	check_output spec_fam hosts
     97      1.1  pgoyette }
     98      1.1  pgoyette 
     99      1.1  pgoyette atf_test_case empty_hostname
    100      1.1  pgoyette empty_hostname_head()
    101      1.1  pgoyette {
    102      1.1  pgoyette 	atf_set "descr" "Testing empty hostname"
    103      1.1  pgoyette }
    104      1.1  pgoyette empty_hostname_body()
    105      1.1  pgoyette {
    106      1.1  pgoyette 	TEST=$(atf_get_srcdir)/h_gai
    107      1.1  pgoyette 
    108      1.1  pgoyette 	( $TEST '' http
    109      1.1  pgoyette 	  $TEST '' echo
    110      1.1  pgoyette 	  $TEST '' tftp
    111      1.1  pgoyette 	  $TEST '' 80
    112      1.1  pgoyette 	  $TEST -P '' http
    113      1.1  pgoyette 	  $TEST -P '' echo
    114      1.1  pgoyette 	  $TEST -P '' tftp
    115      1.1  pgoyette 	  $TEST -P '' 80
    116      1.1  pgoyette 	  $TEST -S '' 80
    117      1.1  pgoyette 	  $TEST -D '' 80 ) > out 2>&1
    118      1.1  pgoyette 
    119      1.1  pgoyette 	check_output no_host ifconfig
    120      1.1  pgoyette }
    121      1.1  pgoyette 
    122      1.1  pgoyette atf_test_case empty_servname
    123      1.1  pgoyette empty_servname_head()
    124      1.1  pgoyette {
    125      1.1  pgoyette 	atf_set "descr" "Testing empty service name"
    126      1.1  pgoyette }
    127      1.1  pgoyette empty_servname_body()
    128      1.1  pgoyette {
    129      1.1  pgoyette 	TEST=$(atf_get_srcdir)/h_gai
    130      1.1  pgoyette 
    131      1.1  pgoyette 	( $TEST ::1 ''
    132      1.1  pgoyette 	  $TEST 127.0.0.1 ''
    133      1.1  pgoyette 	  $TEST localhost ''
    134      1.1  pgoyette 	  $TEST '' '' ) > out 2>&1
    135      1.1  pgoyette 
    136      1.1  pgoyette 	check_output no_serv hosts
    137      1.1  pgoyette }
    138      1.1  pgoyette 
    139      1.1  pgoyette atf_test_case sock_raw
    140      1.1  pgoyette sock_raw_head()
    141      1.1  pgoyette {
    142      1.1  pgoyette 	atf_set "descr" "Testing raw socket"
    143      1.1  pgoyette }
    144      1.1  pgoyette sock_raw_body()
    145      1.1  pgoyette {
    146      1.1  pgoyette 	TEST=$(atf_get_srcdir)/h_gai
    147      1.1  pgoyette 
    148      1.1  pgoyette 	( $TEST -R -p 0 localhost ''
    149      1.1  pgoyette 	  $TEST -R -p 59 localhost ''
    150      1.1  pgoyette 	  $TEST -R -p 59 localhost 80
    151      1.1  pgoyette 	  $TEST -R -p 59 localhost www
    152      1.1  pgoyette 	  $TEST -R -p 59 ::1 '' ) > out 2>&1
    153      1.1  pgoyette 
    154      1.1  pgoyette 	check_output sock_raw hosts
    155      1.1  pgoyette }
    156      1.1  pgoyette 
    157  1.1.4.1    cherry atf_test_case unsupported_family
    158      1.1  pgoyette unsupported_family_head()
    159      1.1  pgoyette {
    160      1.1  pgoyette 	atf_set "descr" "Testing unsupported family"
    161      1.1  pgoyette }
    162      1.1  pgoyette unsupported_family_body()
    163      1.1  pgoyette {
    164      1.1  pgoyette 	TEST=$(atf_get_srcdir)/h_gai
    165      1.1  pgoyette 
    166      1.1  pgoyette 	( $TEST -f 99 localhost '' ) > out 2>&1
    167      1.1  pgoyette 
    168      1.1  pgoyette 	check_output unsup_fam none
    169      1.1  pgoyette }
    170      1.1  pgoyette 
    171      1.1  pgoyette atf_test_case scopeaddr
    172      1.1  pgoyette scopeaddr_head()
    173      1.1  pgoyette {
    174      1.1  pgoyette 	atf_set "descr" "Testing scoped address format"
    175      1.1  pgoyette }
    176      1.1  pgoyette scopeaddr_body()
    177      1.1  pgoyette {
    178      1.1  pgoyette 	TEST=$(atf_get_srcdir)/h_gai
    179      1.1  pgoyette 
    180      1.1  pgoyette 	( $TEST fe80::1%lo0 http
    181      1.1  pgoyette #	  IF=`ifconfig -a | grep -v '^	' | \
    182      1.1  pgoyette #		sed -e 's/:.*//' | head -1 | awk '{print $1}'`
    183      1.1  pgoyette #	  $TEST fe80::1%$IF http
    184      1.1  pgoyette 	) > out 2>&1
    185      1.1  pgoyette 
    186      1.1  pgoyette 	check_output scoped none
    187      1.1  pgoyette }
    188      1.1  pgoyette 
    189      1.1  pgoyette atf_init_test_cases()
    190      1.1  pgoyette {
    191      1.1  pgoyette 	atf_add_test_case basic
    192      1.1  pgoyette 	atf_add_test_case specific
    193      1.1  pgoyette 	atf_add_test_case empty_hostname
    194      1.1  pgoyette 	atf_add_test_case empty_servname
    195      1.1  pgoyette 	atf_add_test_case sock_raw
    196  1.1.4.1    cherry 	atf_add_test_case unsupported_family
    197      1.1  pgoyette 	atf_add_test_case scopeaddr
    198      1.1  pgoyette }
    199