1 # 2 # CDDL HEADER START 3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the "License"). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets "[]" replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # ident "@(#)tp_portranges_020_pos.ksh 1.1 09/05/04 SMI" 27 # 28 29 function duplicate_port_one_connect_only 30 { 31 tc_id="port-range-with-2-identical-ports-should-yield-one-connect" 32 tc_desc="The client should connect to each port in the list just once" 33 init_test 34 35 typeset -r pattern="succeeded" 36 typeset -r range="$STC2_NC_TEST_PORT-$STC2_NC_TEST_PORT" 37 38 # 39 # Start the server first. It uses -k in case the client tries to 40 # connect twice. 41 # 42 start_nc "-k -l $STC2_NC_TEST_PORT" 43 if (( $? != 0 )); then 44 tet_result UNINITIATED 45 return 46 fi 47 48 # 49 # There should be exactly one line printed by the client to stderr 50 # and should contain "succeeded". 51 # 52 typeset -r client_err=$( nc_mktemp dup_ports-client_err ) 53 if [[ -z $client_err ]]; then 54 finish_test 55 return 56 fi 57 tet_infoline "connecting with client to port range '$range'" 58 eval ${NC} -4 -z -v localhost $range 2>$client_err >/dev/null 59 if (( $? != 0 )); then 60 tet_infoline "client failed to connect to range $range" 61 tet_printfile $client_err 62 tet_result FAIL 63 $RM -f $client_err 64 finish_test 65 return 66 fi 67 tet_infoline "connection suceeded, checking stderr contents" 68 debug_printfile $client_err 69 $GREP $pattern $client_err >/dev/null 2>&1 70 if (( $? != 0 )); then 71 tet_infoline "client stderr output does not contain $pattern" 72 tet_printfile $client_err 73 tet_result FAIL 74 $RM -f $client_err 75 finish_test 76 return 77 fi 78 integer -r lines=$( $SED -n '$=' $client_err ) 79 tet_infoline "checking number of lines in stderr output ($lines)" 80 if (( $lines != 1 )); then 81 tet_infoline "client stderr output does not contain exactly" \ 82 "one line:" 83 tet_printfile $client_err 84 tet_result FAIL 85 $RM -f $client_err 86 finish_test 87 return 88 fi 89 90 $RM -f $client_err 91 finish_test 92 } 93