More corrections to test.sh: language; netstat; reuseaddr; usleep; force IPv4; timeout
[socat.git] / test.sh
blob961171db4a9ec8f4aedd019a70f034e505fdf6a9
1 #! /usr/bin/env bash
2 # source: test.sh
3 # Copyright Gerhard Rieger and contributors (see file CHANGES)
4 # Published under the GNU General Public License V.2, see file COPYING
6 # perform lots of tests on socat
8 # this script uses functions; you need a shell that supports them
10 # you can pass general options to socat: export OPTS="-d -d -d -d -lu"
11 # you can eg strace socat with: export TRACE="strace -v -tt -ff -D -x -s 1024 -o /tmp/$USER/socat.strace"
12 #set -vx
14 val_t=0.1
15 NUMCOND=true
16 #NUMCOND="test \$N -gt 70"
17 VERBOSE=
18 while [ "$1" ]; do
19 case "X$1" in
20 X-t?*) val_t="${1#-t}" ;;
21 X-t) shift; val_t="$1" ;;
22 X-v) VERBOSE=1 ;; # show commands
23 X-n?*) NUMCOND="test \$N -eq ${1#-n}" ;;
24 X-n) shift; NUMCOND="test \$N -eq $1" ;;
25 X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;;
26 X-N) shift; NUMCOND="test \$N -ge $1" ;;
27 X-C) rm -f testcert*.conf testcert.dh testcli*.* testsrv*.* ;;
28 *) break;
29 esac
30 shift
31 done
33 opt_t="-t $val_t"
35 UNAME=`uname`
37 #MICROS=100000
38 case "X$val_t" in
39 X*.???????*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS:0:6}" ;;
40 X*.*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS}000000"; uS="${uS:0:6}" ;;
41 X*) S="${val_t}"; uS="000000" ;;
42 esac
43 MICROS=${S}${uS}
44 MICROS=${MICROS##0000}; MICROS=${MICROS##00}; MICROS=${MICROS##0}
46 _MICROS=$((MICROS+999999)); SECONDs="${_MICROS%??????}"
47 [ -z "$SECONDs" ] && SECONDs=0
49 withroot=0 # perform privileged tests even if not run by root
50 #PATH=$PATH:/opt/freeware/bin
51 #PATH=$PATH:/usr/local/ssl/bin
52 PATH=$PATH:/sbin # RHEL6:ip
53 case "$0" in
54 */*) PATH="${0%/*}:$PATH"
55 esac
56 #OPENSSL_RAND="-rand /dev/egd-pool"
57 #SOCAT_EGD="egd=/dev/egd-pool"
58 MISCDELAY=1
59 [ -z "$SOCAT" ] && SOCAT="./socat"
60 if ! [ -x "$SOCAT" ] && ! type $SOCAT >/dev/null 2>&1; then
61 echo "$SOCAT does not exist" >&2; exit 1;
63 [ -z "$PROCAN" ] && PROCAN="./procan"
64 [ -z "$FILAN" ] && FILAN="./filan"
65 opts="$opt_t $OPTS"
66 export SOCAT_OPTS="$opts"
67 #debug="1"
68 debug=
69 TESTS="$@"; export TESTS
70 # for some tests we need a network interface
71 if type ip >/dev/null 2>&1; then
72 INTERFACE=$(ip r get 8.8.8.8 |grep ' dev ' |head -n 1 |sed "s/.*dev[[:space:]][[:space:]]*\([^[:space:]][^[:space:]]*\).*/\1/")
73 else
74 case "$UNAME" in
75 Linux)
76 if [ "$IP" ]; then
77 INTERFACE="$($IP route get 8.8.8.8 |grep ' dev ' |sed -e 's/.* dev //' -e 's/ .*//')"
78 else
79 INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($8);}')"
80 fi ;;
81 FreeBSD) INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($4);}')" ;;
82 *) INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($4);}')" ;;
83 esac
85 MCINTERFACE=$INTERFACE
86 [ -z "$MCINTERFACE" ] && MCINTERFACE=lo # !!! Linux only - and not always
87 #LOCALHOST=192.168.58.1
88 LOCALHOST=localhost
89 #LOCALHOST=127.0.0.1
90 LOCALHOST6=[::1]
91 #PROTO=$(awk '{print($2);}' /etc/protocols |sort -n |tail -n 1)
92 #PROTO=$(($PROTO+1))
93 PROTO=$((144+RANDOM/2048))
94 PORT=12002
95 SOURCEPORT=2002
96 REUSEADDR=reuseaddr # use this with LISTEN addresses and bind options
98 # SSL certificate contents
99 TESTCERT_CONF=testcert.conf
100 TESTCERT6_CONF=testcert6.conf
102 TESTCERT_COMMONNAME="$LOCALHOST"
103 TESTCERT_COMMONNAME6="$LOCALHOST6"
104 TESTCERT_COUNTRYNAME="XY"
105 TESTCERT_LOCALITYNAME="Lunar Base"
106 TESTCERT_ORGANIZATIONALUNITNAME="socat"
107 TESTCERT_ORGANIZATIONNAME="dest-unreach"
108 TESTCERT_SUBJECT="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
109 TESTCERT_ISSUER="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
110 RSABITS=1024
111 cat >$TESTCERT_CONF <<EOF
112 prompt=no
114 [ req ]
115 default_bits = $RSABITS
116 distinguished_name=Test
118 [ Test ]
119 countryName=$TESTCERT_COUNTRYNAME
120 commonName=$TESTCERT_COMMONNAME
121 O=$TESTCERT_ORGANIZATIONNAME
122 OU=$TESTCERT_ORGANIZATIONALUNITNAME
123 L=$TESTCERT_LOCALITYNAME
126 cat >$TESTCERT6_CONF <<EOF
127 prompt=no
129 [ req ]
130 default_bits = $RESBITS
131 distinguished_name=Test
133 [ Test ]
134 countryName=$TESTCERT_COUNTRYNAME
135 commonName=$TESTCERT_COMMONNAME6
136 O=$TESTCERT_ORGANIZATIONNAME
137 OU=$TESTCERT_ORGANIZATIONALUNITNAME
138 L=$TESTCERT_LOCALITYNAME
141 # clean up from previous runs
142 rm -f testcli.{crt,key,pem}
143 rm -f testsrv.{crt,key,pem}
144 rm -f testcli6.{crt,key,pem}
145 rm -f testsrv6.{crt,key,pem}
148 CAT=cat
149 OD_C="od -c"
151 # precision sleep; takes seconds with fractional part
152 psleep () {
153 local T="$1"
154 [ "$T" = 0 ] && T=0.000002
155 $SOCAT -T "$T" pipe pipe
157 # time in microseconds to wait in some situations
158 if ! type usleep >/dev/null 2>&1 ||
159 usleep 0 2>&1 |grep -q deprecated; then
160 usleep () {
161 local n="$1"
162 case "$n" in
163 *???????) S="${n%??????}"; uS="${n:${#n}-6}" ;;
164 *) S=0; uS="00000$n"; uS="${uS:${#uS}-6}" ;;
165 esac
166 $SOCAT -T $S.$uS pipe pipe
169 #USLEEP=usleep
171 if type ping6; then
172 PING6=ping6
173 else
174 PING6="ping -6"
177 F_n="%3d" # format string for test numbers
178 export LC_ALL=C # for timestamps format...
179 export LANG=C
180 export LANGUAGE=C # knoppix
181 case "$UNAME" in
182 HP-UX|OSF1)
183 echo "$SOCAT -u stdin stdout" >cat.sh
184 chmod a+x cat.sh
185 CAT=./cat.sh
187 SunOS)
188 # /usr/bin/tr doesn't handle the a-z range syntax (needs [a-z]), use
189 # /usr/xpg4/bin/tr instead
190 alias tr=/usr/xpg4/bin/tr
193 CAT=cat
195 esac
197 case "$UNAME" in
198 #HP-UX)
199 # # on HP-UX, the default options (below) hang some tests (former 14, 15)
200 # PTYOPTS=
201 # PTYOPTS2=
202 # ;;
204 PTYOPTS="echo=0,opost=0"
205 #PTYOPTS2="raw,echo=0"
206 PTYOPTS2="cfmakeraw"
207 #PTYOPTS2="rawer"
209 esac
211 # for some tests we need an unprivileged user id to su to
212 if [ "$SUDO_USER" ]; then
213 SUBSTUSER="$SUDO_USER"
214 else
215 SUBSTUSER="$(grep -v '^[^:]*:^[^:]*:0:' /etc/passwd |tail -n 1 |cut -d: -f1)"
218 if type ip; then
219 if ip -V |grep -q "^ip utility, iproute2-ss"; then
220 IP=$(which ip)
221 else
222 unset IP
226 if type ss; then
227 if ss -V |grep -q "^ss utility, iproute2-ss"; then
228 SS=$(which ss)
229 else
230 unset SS
234 if [ -z "$SS" ]; then
235 # non-root users might miss ifconfig in their path
236 case "$UNAME" in
237 AIX) IFCONFIG=/usr/sbin/ifconfig ;;
238 FreeBSD) IFCONFIG=/sbin/ifconfig ;;
239 HP-UX) IFCONFIG=/usr/sbin/ifconfig ;;
240 Linux) IFCONFIG=/sbin/ifconfig ;;
241 NetBSD)IFCONFIG=/sbin/ifconfig ;;
242 OpenBSD)IFCONFIG=/sbin/ifconfig ;;
243 OSF1) IFCONFIG=/sbin/ifconfig ;;
244 SunOS) IFCONFIG=/sbin/ifconfig ;;
245 Darwin)IFCONFIG=/sbin/ifconfig ;;
246 DragonFly) IFCONFIG=/sbin/ifconfig ;;
247 *) IFCONFIG=/sbin/ifconfig ;;
248 esac
251 # need output like "644"
252 case "$UNAME" in
253 Linux) fileperms() { stat -L --print "%a\n" "$1" 2>/dev/null; } ;;
254 FreeBSD) fileperms() { stat -L -x "$1" |grep ' Mode:' |sed 's/.* Mode:[[:space:]]*([0-9]\([0-7][0-7][0-7]\).*/\1/'; } ;;
255 *) fileperms() {
256 local p s=0 c
257 p="$(ls -l -L "$1" |awk '{print($1);}')"
258 p="${p:1:9}"
259 while [ "$p" ]; do c=${p:0:1}; p=${p:1}; [ "x$c" == x- ]; let "s=2*s+$?"; done
260 printf "%03o\n" $s;
261 } ;;
262 esac
264 # need user (owner) of filesystem entry
265 case "$UNAME" in
266 Linux) fileuser() { stat -L --print "%U\n" "$tsock" 2>/dev/null; } ;;
267 FreeBSD) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
268 *) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
269 esac
271 if2addr4() {
272 local IF="$1"
273 if [ "$IP" ]; then
274 $IP address show dev $IF |grep "inet " |sed -e "s/.*inet //" -e "s/ .*//"
275 else
276 $IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}' |cut -d: -f2
280 if2bc4() {
281 local IF="$1"
282 if [ "$IP" ]; then
283 $IP address show dev $IF |grep ' inet .* brd ' |awk '{print($4);}'
284 else
285 $IFCONFIG $IF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}'
289 # for some tests we need a second local IPv4 address
290 case "$UNAME" in
291 Linux)
292 if [ "$IP" ]; then
293 BROADCASTIF=$($IP r get 8.8.8.8 |grep ' dev ' |sed 's/.*\<dev[[:space:]][[:space:]]*\([a-z0-9][a-z0-9]*\).*/\1/')
294 else
295 BROADCASTIF=$(route -n |grep '^0.0.0.0 ' |awk '{print($8);}')
297 [ -z "$BROADCASTIF" ] && BROADCASTIF=eth0
298 SECONDADDR=127.1.0.1
299 SECONDMASK=255.255.0.0
300 BCADDR=127.255.255.255
301 BCIFADDR=$(if2addr4 $BROADCASTIF) ;;
302 FreeBSD|NetBSD|OpenBSD)
303 MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
304 BROADCASTIF="$MAINIF"
305 SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
306 BCIFADDR="$SECONDADDR"
307 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
308 HP-UX)
309 MAINIF=lan0 # might use "netstat -ni" for this
310 BROADCASTIF="$MAINIF"
311 SECONDADDR=$($IFCONFIG $MAINIF |tail -n 1 |awk '{print($2);}')
312 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
313 SunOS)
314 MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
315 BROADCASTIF="$MAINIF"
316 #BROADCASTIF=hme0
317 #BROADCASTIF=eri0
318 #SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
319 SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
320 #BCIFADDR="$SECONDADDR"
321 #BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}')
323 DragonFly)
324 MAINIF=$($IFCONFIG -a |grep -v ^lp |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
325 BROADCASTIF="$MAINIF"
326 SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
327 BCIFADDR="$SECONDADDR"
328 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
329 #AIX|FreeBSD|Solaris)
331 SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 ' |head -n 1)" : '.*inet \([0-9.]*\) .*')
333 esac
334 # for generic sockets we need this address in hex form
335 if [ "$SECONDADDR" ]; then
336 SECONDADDRHEX="$(printf "%02x%02x%02x%02x\n" $(echo "$SECONDADDR" |tr '.' '
337 '))"
340 # for some tests we need a second local IPv6 address
341 case "$UNAME" in
342 Linux) if [ "$IP" ]; then
343 SECONDIP6ADDR=$(expr "$($IP address |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet6 \([0-9a-f:][0-9a-f:]*\)/.*')
344 else
345 SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
346 fi ;;
348 SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
350 esac
351 if [ -z "$SECONDIP6ADDR" ]; then
352 # case "$TESTS" in
353 # *%root2%*) $IFCONFIG eth0 ::2/128
354 # esac
355 SECONDIP6ADDR="$LOCALHOST6"
356 else
357 SECONDIP6ADDR="[$SECONDIP6ADDR]"
360 TRUE=$(which true)
361 #E=-e # Linux
362 if [ $(echo "x\c") = "x" ]; then E=""
363 elif [ $(echo -e "x\c") = "x" ]; then E="-e"
364 else
365 echo "cannot suppress trailing newline on echo" >&2
366 exit 1
368 ECHO="echo $E"
369 PRINTF="printf"
371 case "$TERM" in
372 vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color)
373 # there are different behaviours of printf (and echo)
374 # on some systems, echo behaves different than printf...
375 if [ $($PRINTF "\0101") = "A" ]; then
376 RED="\0033[31m"
377 GREEN="\0033[32m"
378 YELLOW="\0033[33m"
379 # if [ "$UNAME" = SunOS ]; then
380 # NORMAL="\0033[30m"
381 # else
382 NORMAL="\0033[39m"
383 # fi
384 else
385 RED="\033[31m"
386 GREEN="\033[32m"
387 YELLOW="\033[33m"
388 # if [ "$UNAME" = SunOS ]; then
389 # NORMAL="\033[30m"
390 # else
391 NORMAL="\033[39m"
392 # fi
394 OK="${GREEN}OK${NORMAL}"
395 FAILED="${RED}FAILED${NORMAL}"
396 NO_RESULT="${YELLOW}NO RESULT${NORMAL}"
398 *) OK="OK"
399 FAILED="FAILED"
400 NO_RESULT="NO RESULT"
402 esac
405 if [ -x /usr/xpg4/bin/id ]; then
406 # SunOS has rather useless tools in its default path
407 PATH="/usr/xpg4/bin:$PATH"
410 [ -z "$TESTS" ] && TESTS="consistency functions filan"
411 # use '%' as separation char
412 TESTS="%$(echo "$TESTS" |tr ' ' '%')%"
414 [ -z "$USER" ] && USER="$LOGNAME" # HP-UX
415 if [ -z "$TMPDIR" ]; then
416 if [ -z "$TMP" ]; then
417 TMP=/tmp
419 TMPDIR="$TMP"
421 TD="$TMPDIR/$USER/$$"; td="$TD"
422 rm -rf "$TD" || (echo "cannot rm $TD" >&2; exit 1)
423 mkdir -p "$TD"
424 #trap "rm -r $TD" 0 3
426 echo "using temp directory $TD"
428 case "$TESTS" in
429 *%consistency%*)
430 # test if addresses are sorted alphabetically:
431 $ECHO "testing if address array is sorted...\c"
432 TF="$TD/socat-q"
433 IFS="$($ECHO ' \n\t')"
434 $SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done >"$TF"
435 $SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done |LC_ALL=C sort |diff "$TF" - >"$TF-diff"
436 if [ -s "$TF-diff" ]; then
437 $ECHO "\n*** address array is not sorted. Wrong entries:" >&2
438 cat "$TD/socat-q-diff" >&2
439 exit 1
440 else
441 echo " ok"
443 #/bin/rm "$TF"
444 #/bin/rm "$TF-diff"
445 esac
447 case "$TESTS" in
448 *%consistency%*)
449 # test if address options array ("optionnames") is sorted alphabetically:
450 $ECHO "testing if address options are sorted...\c"
451 TF="$TD/socat-qq"
452 $SOCAT -??? |sed '1,/opt:/ d' |awk '{print($1);}' >"$TF"
453 LC_ALL=C sort "$TF" |diff "$TF" - >"$TF-diff"
454 if [ -s "$TF-diff" ]; then
455 $ECHO "\n*** option array is not sorted. Wrong entries:" >&2
456 cat "$TD/socat-qq-diff" >&2
457 exit 1
458 else
459 echo " ok"
461 /bin/rm "$TF"
462 /bin/rm "$TF-diff"
463 esac
465 #==============================================================================
466 case "$TESTS" in
467 *%options%*)
469 # inquire which options are available
470 OPTS_ANY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*ANY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
471 OPTS_BLK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*BLK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
472 OPTS_CHILD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHILD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
473 OPTS_CHR=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHR' |awk '{print($1);}' |xargs echo |tr ' ' ',')
474 OPTS_DEVICE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*DEVICE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
475 OPTS_EXEC=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*EXEC' |awk '{print($1);}' |xargs echo |tr ' ' ',')
476 OPTS_FD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
477 OPTS_FIFO=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FIFO' |awk '{print($1);}' |xargs echo |tr ' ' ',')
478 OPTS_FORK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FORK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
479 OPTS_LISTEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*LISTEN' |awk '{print($1);}' |xargs echo |tr ' ' ',')
480 OPTS_NAMED=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*NAMED' |awk '{print($1);}' |xargs echo |tr ' ' ',')
481 OPTS_OPEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPEN[^S]' |awk '{print($1);}' |xargs echo |tr ' ' ',')
482 OPTS_PARENT=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PARENT' |awk '{print($1);}' |xargs echo |tr ' ' ',')
483 OPTS_READLINE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*READLINE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
484 OPTS_RETRY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RETRY' |awk '{print($1);}' |grep -v forever|xargs echo |tr ' ' ',')
485 OPTS_RANGE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RANGE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
486 OPTS_FILE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*REG' |awk '{print($1);}' |xargs echo |tr ' ' ',')
487 OPTS_UNIX=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UNIX' |awk '{print($1);}' |xargs echo |tr ' ' ',')
488 OPTS_SOCKET=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKET' |awk '{print($1);}' |xargs echo |tr ' ' ',')
489 OPTS_TERMIOS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TERMIOS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
490 OPTS_IP4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
491 OPTS_IP6=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP6' |awk '{print($1);}' |xargs echo |tr ' ' ',')
492 OPTS_TCP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TCP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
493 OPTS_UDP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UDP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
494 OPTS_SOCKS4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKS4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
495 OPTS_PROCESS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PROCESS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
496 OPTS_OPENSSL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPENSSL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
497 OPTS_PTY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PTY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
498 OPTS_HTTP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*HTTP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
499 OPTS_APPL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*APPL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
501 # find user ids to setown to; non-root only can setown to itself
502 if [ $(id -u) = 0 ]; then
503 # up to now, it is not a big problem when these do not exist
504 _UID=nobody
505 _GID=staff
506 else
507 _UID=$(id -u)
508 _GID=$(id -g)
511 # some options require values; here we try to replace these bare options with
512 # valid forms.
513 filloptionvalues() {
514 local OPTS=",$1,"
516 case "$OPTS" in
517 *,umask,*) OPTS=$(echo "$OPTS" |sed "s/,umask,/,umask=0026,/g");;
518 esac
519 case "$OPTS" in
520 *,user,*) OPTS=$(echo "$OPTS" |sed "s/,user,/,user=$_UID,/g");;
521 esac
522 case "$OPTS" in
523 *,user-early,*) OPTS=$(echo "$OPTS" |sed "s/,user-early,/,user-early=$_UID,/g");;
524 esac
525 case "$OPTS" in
526 *,user-late,*) OPTS=$(echo "$OPTS" |sed "s/,user-late,/,user-late=$_UID,/g");;
527 esac
528 case "$OPTS" in
529 *,owner,*) OPTS=$(echo "$OPTS" |sed "s/,owner,/,owner=$_UID,/g");;
530 esac
531 case "$OPTS" in
532 *,uid,*) OPTS=$(echo "$OPTS" |sed "s/,uid,/,uid=$_UID,/g");;
533 esac
534 case "$OPTS" in
535 *,uid-l,*) OPTS=$(echo "$OPTS" |sed "s/,uid-l,/,uid-l=$_UID,/g");;
536 esac
537 case "$OPTS" in
538 *,setuid,*) OPTS=$(echo "$OPTS" |sed "s/,setuid,/,setuid=$_UID,/g");;
539 esac
540 case "$OPTS" in
541 *,group,*) OPTS=$(echo "$OPTS" |sed "s/,group,/,group=$_GID,/g");;
542 esac
543 case "$OPTS" in
544 *,group-early,*) OPTS=$(echo "$OPTS" |sed "s/,group-early,/,group-early=$_GID,/g");;
545 esac
546 case "$OPTS" in
547 *,group-late,*) OPTS=$(echo "$OPTS" |sed "s/,group-late,/,group-late=$_GID,/g");;
548 esac
549 case "$OPTS" in
550 *,gid,*) OPTS=$(echo "$OPTS" |sed "s/,gid,/,gid=$_GID,/g");;
551 esac
552 case "$OPTS" in
553 *,gid-l,*) OPTS=$(echo "$OPTS" |sed "s/,gid-l,/,gid-l=$_GID,/g");;
554 esac
555 case "$OPTS" in
556 *,setgid,*) OPTS=$(echo "$OPTS" |sed "s/,setgid,/,setgid=$_GID,/g");;
557 esac
558 case "$OPTS" in
559 *,mode,*) OPTS=$(echo "$OPTS" |sed "s/,mode,/,mode=0700,/g");;
560 esac
561 case "$OPTS" in
562 *,perm,*) OPTS=$(echo "$OPTS" |sed "s/,perm,/,perm=0700,/g");;
563 esac
564 case "$OPTS" in
565 *,perm-early,*) OPTS=$(echo "$OPTS" |sed "s/,perm-early,/,perm-early=0700,/g");;
566 esac
567 case "$OPTS" in
568 *,perm-late,*) OPTS=$(echo "$OPTS" |sed "s/,perm-late,/,perm-late=0700,/g");;
569 esac
570 case "$OPTS" in
571 *,path,*) OPTS=$(echo "$OPTS" |sed "s/,path,/,path=.,/g");;
572 esac
573 # SOCKET
574 case "$OPTS" in
575 *,bind,*) OPTS=$(echo "$OPTS" |sed "s/,bind,/,bind=:,/g");;
576 esac
577 case "$OPTS" in
578 *,linger,*) OPTS=$(echo "$OPTS" |sed "s/,linger,/,linger=2,/g");;
579 esac
580 case "$OPTS" in
581 *,connect-timeout,*) OPTS=$(echo "$OPTS" |sed "s/,connect-timeout,/,connect-timeout=1,/g");;
582 esac
583 # IP
584 case "$OPTS" in
585 *,ipoptions,*) OPTS=$(echo "$OPTS" |sed "s|,ipoptions,|,ipoptions=x01,|g");;
586 esac
587 case "$OPTS" in
588 *,pf,*) OPTS=$(echo "$OPTS" |sed "s|,pf,|,pf=ip4,|g");;
589 esac
590 case "$OPTS" in
591 *,range,*) OPTS=$(echo "$OPTS" |sed "s|,range,|,range=127.0.0.1/32,|g");;
592 esac
593 case "$OPTS" in
594 *,if,*) OPTS=$(echo "$OPTS" |sed "s/,if,/,if=$INTERFACE,/g");;
595 esac
596 # PTY
597 case "$OPTS" in
598 *,pty-interval,*) OPTS=$(echo "$OPTS" |sed "s/,pty-interval,/,pty-interval=$INTERFACE,/g");;
599 esac
600 # RETRY
601 case "$OPTS" in
602 *,interval,*) OPTS=$(echo "$OPTS" |sed "s/,interval,/,interval=1,/g");;
603 esac
604 # READLINE
605 case "$OPTS" in
606 *,history,*) OPTS=$(echo "$OPTS" |sed "s/,history,/,history=.history,/g");;
607 esac
608 case "$OPTS" in
609 *,noecho,*) OPTS=$(echo "$OPTS" |sed "s/,noecho,/,noecho=password,/g");;
610 esac
611 case "$OPTS" in
612 *,prompt,*) OPTS=$(echo "$OPTS" |sed "s/,prompt,/,prompt=CMD,/g");;
613 esac
614 # IPAPP
615 case "$OPTS" in
616 *,sp,*) OPTS=$(echo "$OPTS" |sed "s/,sp,/,sp=$SOURCEPORT,/g");;
617 esac
618 # OPENSSL
619 case "$OPTS" in
620 *,ciphers,*) OPTS=$(echo "$OPTS" |sed "s/,ciphers,/,ciphers=NULL,/g");;
621 esac
622 case "$OPTS" in
623 *,method,*) OPTS=$(echo "$OPTS" |sed "s/,method,/,method=SSLv3,/g");;
624 esac
625 case "$OPTS" in
626 *,cafile,*) OPTS=$(echo "$OPTS" |sed "s/,cafile,/,cafile=/tmp/hugo,/g");;
627 esac
628 case "$OPTS" in
629 *,capath,*) OPTS=$(echo "$OPTS" |sed "s/,capath,/,capath=/tmp/hugo,/g");;
630 esac
631 case "$OPTS" in
632 *,cert,*) OPTS=$(echo "$OPTS" |sed "s/,cert,/,cert=/tmp/hugo,/g");;
633 esac
634 case "$OPTS" in
635 *,key,*) OPTS=$(echo "$OPTS" |sed "s/,key,/,key=/tmp/hugo,/g");;
636 esac
637 case "$OPTS" in
638 *,dh,*) OPTS=$(echo "$OPTS" |sed "s/,dh,/,dh=/tmp/hugo,/g");;
639 esac
640 case "$OPTS" in
641 *,egd,*) OPTS=$(echo "$OPTS" |sed "s/,egd,/,egd=/tmp/hugo,/g");;
642 esac
643 case "$OPTS" in
644 *,compress,*) OPTS=$(echo "$OPTS" |sed "s/,compress,/,compress=none,/g");;
645 esac
646 # PROXY
647 case "$OPTS" in
648 *,proxyauth,*) OPTS=$(echo "$OPTS" |sed "s/,proxyauth,/,proxyauth=user:pass,/g");;
649 esac
650 case "$OPTS" in
651 *,proxyport,*) OPTS=$(echo "$OPTS" |sed "s/,proxyport,/,proxyport=3128,/g");;
652 esac
653 case "$OPTS" in
654 *,link,*) OPTS=$(echo "$OPTS" |sed "s/,link,/,link=testlink,/g");;
655 esac
656 # TCP-WRAPPERS
657 case "$OPTS" in
658 *,allow-table,*) OPTS=$(echo "$OPTS" |sed "s|,allow-table,|,allow-table=/tmp/hugo,|g");;
659 esac
660 case "$OPTS" in
661 *,deny-table,*) OPTS=$(echo "$OPTS" |sed "s|,deny-table,|,deny-table=/tmp/hugo,|g");;
662 esac
663 case "$OPTS" in
664 *,tcpwrap-dir,*) OPTS=$(echo "$OPTS" |sed "s|,tcpwrap-dir,|,tcpwrap-dir=/tmp,|g");;
665 esac
666 echo $OPTS >&2
667 expr "$OPTS" : ',\(.*\),'
669 # OPTS_FIFO: nothing yet
671 # OPTS_CHR: nothing yet
673 # OPTS_BLK: nothing yet
675 # OPTS_REG: nothing yet
677 OPTS_SOCKET=",$OPTS_SOCKET,"
678 OPTS_SOCKET=$(expr "$OPTS_SOCKET" : ',\(.*\),')
681 #------------------------------------------------------------------------------
683 #method=open
684 #METHOD=$(echo "$method" |tr a-z A-Z)
685 #TEST="$METHOD on file accepts all its options"
686 # echo "### $TEST"
687 #TF=$TD/file$N
688 #DA="test$N $(date) $RANDOM"
689 #OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//')
690 #for g in $(echo $OPTGROUPS |tr ',' ' '); do
691 # eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)";
692 # OPTS="$OPTS,$OPTG";
693 #done
694 ##echo $OPTS
696 #for o in $(filloptionvalues $OPTS|tr ',' ' '); do
697 # echo testing if $METHOD accepts option $o
698 # touch $TF
699 # $SOCAT $opts -!!$method:$TF,$o /dev/null,ignoreof </dev/null
700 # rm -f $TF
701 #done
703 #------------------------------------------------------------------------------
705 # test openssl connect
707 #set -vx
708 if true; then
709 #if false; then
710 #opts="-s -d -d -d -d"
711 pid=$!
712 for addr in openssl; do
713 ADDR=$(echo "$addr" |tr a-z A-Z)
714 TEST="$ADDR accepts all its options"
715 echo "### $TEST"
716 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
717 # echo OPTGROUPS=$OPTGROUPS
718 OPTS=
719 for g in $(echo $OPTGROUPS |tr ',' ' '); do
720 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
721 OPTS="$OPTS,$OPTG";
722 done
723 echo $OPTS
724 openssl s_server -www -accept $PORT || echo "cannot start s_server" >&2 &
725 pid=$!
726 sleep 1
727 #waittcp4port $PORT
728 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
729 echo "testing if $ADDR accepts option $o"
730 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
731 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
732 done
733 kill $pid
734 done
735 kill $pid 2>/dev/null
736 opts=
737 PORT=$((PORT+1))
740 #------------------------------------------------------------------------------
742 # test proxy connect
744 #set -vx
745 if true; then
746 #if false; then
747 #opts="-s -d -d -d -d"
748 pid=$!
749 for addr in proxy; do
750 ADDR=$(echo "$addr" |tr a-z A-Z)
751 TEST="$ADDR accepts all its options"
752 echo "### $TEST"
753 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
754 # echo OPTGROUPS=$OPTGROUPS
755 OPTS=
756 for g in $(echo $OPTGROUPS |tr ',' ' '); do
757 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
758 OPTS="$OPTS,$OPTG";
759 done
760 echo $OPTS
761 # prepare dummy server
762 $SOCAT tcp-l:$PORT,reuseaddr,crlf exec:"/usr/bin/env bash proxyecho.sh" || echo "cannot start proxyecho.sh" >&2 &
763 pid=$!
764 sleep 1
765 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
766 echo "testing if $ADDR accepts option $o"
767 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$PORT,$o
768 $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$((PORT+1)),proxyport=$PORT,$o
769 done
770 kill $pid 2>/dev/null
771 done
772 kill $pid 2>/dev/null
773 opts=
774 PORT=$((PORT+2))
777 #------------------------------------------------------------------------------
779 # test tcp4
781 #set -vx
782 if true; then
783 #if false; then
784 #opts="-s -d -d -d -d"
785 $SOCAT $opts tcp4-listen:$PORT,reuseaddr,fork,$o echo </dev/null &
786 pid=$!
787 for addr in tcp4; do
788 ADDR=$(echo "$addr" |tr a-z A-Z)
789 TEST="$ADDR accepts all its options"
790 echo "### $TEST"
791 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
792 # echo OPTGROUPS=$OPTGROUPS
793 OPTS=
794 for g in $(echo $OPTGROUPS |tr ',' ' '); do
795 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
796 OPTS="$OPTS,$OPTG";
797 done
798 echo $OPTS
799 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
800 echo "testing if $ADDR accepts option $o"
801 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
802 done
803 done
804 kill $pid 2>/dev/null
805 opts=
806 PORT=$((PORT+1))
809 #------------------------------------------------------------------------------
811 # test udp4-connect
813 #set -vx
814 if true; then
815 #if false; then
816 #opts="-s -d -d -d -d"
817 $SOCAT $opts udp4-listen:$PORT,fork,$o echo </dev/null &
818 pid=$!
819 for addr in udp4-connect; do
820 ADDR=$(echo "$addr" |tr a-z A-Z)
821 TEST="$ADDR accepts all its options"
822 echo "### $TEST"
823 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
824 # echo OPTGROUPS=$OPTGROUPS
825 OPTS=
826 for g in $(echo $OPTGROUPS |tr ',' ' '); do
827 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
828 OPTS="$OPTS,$OPTG";
829 done
830 echo $OPTS
831 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
832 echo "testing if $ADDR accepts option $o"
833 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
834 done
835 done
836 kill $pid 2>/dev/null
837 opts=
838 PORT=$((PORT+1))
841 #------------------------------------------------------------------------------
843 # test tcp4-listen
845 #set -vx
846 if true; then
847 #if false; then
848 #opts="-s -d -d -d -d"
849 for addr in tcp4-listen; do
850 ADDR=$(echo "$addr" |tr a-z A-Z)
851 TEST="$ADDR accepts all its options"
852 echo "### $TEST"
853 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
854 OPTS=
855 for g in $(echo $OPTGROUPS |tr ',' ' '); do
856 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
857 OPTS="$OPTS,$OPTG";
858 done
859 echo $OPTS
860 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
861 echo "testing if $ADDR accepts option $o"
862 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
863 pid=$!
864 $SOCAT /dev/null tcp4:$LOCALHOST:$PORT 2>/dev/null
865 kill $pid 2>/dev/null
866 done
867 done
868 opts=
869 PORT=$((PORT+1))
872 #------------------------------------------------------------------------------
874 # test udp4-listen
876 #set -vx
877 if true; then
878 #if false; then
879 #opts="-s -d -d -d -d"
880 for addr in udp4-listen; do
881 ADDR=$(echo "$addr" |tr a-z A-Z)
882 TEST="$ADDR accepts all its options"
883 echo "### $TEST"
884 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
885 OPTS=
886 for g in $(echo $OPTGROUPS |tr ',' ' '); do
887 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
888 OPTS="$OPTS,$OPTG";
889 done
890 echo $OPTS
891 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
892 echo "testing if $ADDR accepts option $o"
893 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
894 pid=$!
895 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
896 kill $pid 2>/dev/null
897 done
898 done
899 opts=
900 PORT=$((PORT+1))
903 #------------------------------------------------------------------------------
905 # test udp4-sendto
907 #set -vx
908 if true; then
909 #if false; then
910 #opts="-s -d -d -d -d"
911 $SOCAT $opts udp4-recv:$PORT,fork,$o echo </dev/null &
912 pid=$!
913 for addr in udp4-sendto; do
914 ADDR=$(echo "$addr" |tr a-z A-Z)
915 TEST="$ADDR accepts all its options"
916 echo "### $TEST"
917 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
918 # echo OPTGROUPS=$OPTGROUPS
919 OPTS=
920 for g in $(echo $OPTGROUPS |tr ',' ' '); do
921 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
922 OPTS="$OPTS,$OPTG";
923 done
924 echo $OPTS
925 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
926 echo "testing if $ADDR accepts option $o"
927 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
928 done
929 done
930 kill $pid 2>/dev/null
931 opts=
932 PORT=$((PORT+1))
935 #------------------------------------------------------------------------------
937 # test udp4-datagram
939 #set -vx
940 if true; then
941 #if false; then
942 #opts="-s -d -d -d -d"
943 #$SOCAT $opts udp4-recvfrom:$PORT,fork,$o echo </dev/null &
944 #pid=$!
945 for addr in udp4-datagram; do
946 ADDR=$(echo "$addr" |tr a-z A-Z)
947 TEST="$ADDR accepts all its options"
948 echo "### $TEST"
949 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
950 # echo OPTGROUPS=$OPTGROUPS
951 OPTS=
952 for g in $(echo $OPTGROUPS |tr ',' ' '); do
953 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
954 OPTS="$OPTS,$OPTG";
955 done
956 echo $OPTS
957 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
958 echo "testing if $ADDR accepts option $o"
959 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
960 done
961 done
962 #kill $pid 2>/dev/null
963 opts=
964 PORT=$((PORT+1))
967 #------------------------------------------------------------------------------
969 # test udp4-recv
971 #set -vx
972 if true; then
973 #if false; then
974 #opts="-s -d -d -d -d"
975 for addr in udp4-recv; do
976 ADDR=$(echo "$addr" |tr a-z A-Z)
977 TEST="$ADDR accepts all its options"
978 echo "### $TEST"
979 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
980 OPTS=
981 for g in $(echo $OPTGROUPS |tr ',' ' '); do
982 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
983 OPTS="$OPTS,$OPTG";
984 done
985 echo $OPTS
986 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
987 echo "testing if $ADDR accepts option $o"
988 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
989 pid=$!
990 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
991 kill $pid 2>/dev/null
992 done
993 done
994 opts=
995 PORT=$((PORT+1))
998 #------------------------------------------------------------------------------
1000 # test udp4-recvfrom
1002 #set -vx
1003 if true; then
1004 #if false; then
1005 #opts="-s -d -d -d -d"
1006 for addr in udp4-recvfrom; do
1007 ADDR=$(echo "$addr" |tr a-z A-Z)
1008 TEST="$ADDR accepts all its options"
1009 echo "### $TEST"
1010 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1011 OPTS=
1012 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1013 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1014 OPTS="$OPTS,$OPTG";
1015 done
1016 echo $OPTS
1017 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1018 echo "testing if $ADDR accepts option $o"
1019 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1020 pid=$!
1021 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
1022 kill $pid 2>/dev/null
1023 done
1024 done
1025 opts=
1026 PORT=$((PORT+1))
1029 #------------------------------------------------------------------------------
1031 # test ip4-sendto
1033 #set -vx
1034 if true; then
1035 #if false; then
1036 #opts="-s -d -d -d -d"
1037 $SOCAT $opts ip4-recv:$PORT,fork,$o echo </dev/null &
1038 pid=$!
1039 for addr in ip4-sendto; do
1040 ADDR=$(echo "$addr" |tr a-z A-Z)
1041 TEST="$ADDR accepts all its options"
1042 echo "### $TEST"
1043 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1044 # echo OPTGROUPS=$OPTGROUPS
1045 OPTS=
1046 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1047 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1048 OPTS="$OPTS,$OPTG";
1049 done
1050 echo $OPTS
1051 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1052 echo "testing if $ADDR accepts option $o"
1053 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
1054 done
1055 done
1056 kill $pid 2>/dev/null
1057 opts=
1058 PORT=$((PORT+1))
1061 #------------------------------------------------------------------------------
1063 # test ip4-recv
1065 #set -vx
1066 if true; then
1067 #if false; then
1068 #opts="-s -d -d -d -d"
1069 for addr in ip4-recv; do
1070 ADDR=$(echo "$addr" |tr a-z A-Z)
1071 TEST="$ADDR accepts all its options"
1072 echo "### $TEST"
1073 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1074 OPTS=
1075 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1076 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1077 OPTS="$OPTS,$OPTG";
1078 done
1079 echo $OPTS
1080 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1081 echo "testing if $ADDR accepts option $o"
1082 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1083 pid=$!
1084 $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
1085 kill $pid 2>/dev/null
1086 done
1087 done
1088 opts=
1089 PORT=$((PORT+1))
1092 #------------------------------------------------------------------------------
1094 # test ip4-recvfrom
1096 #set -vx
1097 if true; then
1098 #if false; then
1099 #opts="-s -d -d -d -d"
1100 for addr in ip4-recvfrom; do
1101 ADDR=$(echo "$addr" |tr a-z A-Z)
1102 TEST="$ADDR accepts all its options"
1103 echo "### $TEST"
1104 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1105 OPTS=
1106 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1107 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1108 OPTS="$OPTS,$OPTG";
1109 done
1110 echo $OPTS
1111 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1112 echo "testing if $ADDR accepts option $o"
1113 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1114 pid=$!
1115 $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
1116 kill $pid 2>/dev/null
1117 done
1118 done
1119 opts=
1120 PORT=$((PORT+1))
1123 #------------------------------------------------------------------------------
1125 # test READLINE
1127 if true; then
1128 #if false; then
1129 #opts="-s -d -d -d -d"
1130 for addr in readline; do
1131 ADDR=$(echo "$addr" |tr a-z A-Z)
1132 TEST="$ADDR accepts all its options"
1133 echo "### $TEST"
1134 TS=$TD/script$N
1135 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1136 OPTS=
1137 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1138 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1139 OPTS="$OPTS,$OPTG";
1140 done
1141 #echo $OPTS
1142 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1143 # for o in bs0; do
1144 echo "testing if $ADDR accepts option $o"
1145 echo "$SOCAT $opts readline,$o /dev/null" >$TS
1146 chmod u+x $TS
1147 $SOCAT /dev/null,ignoreeof exec:$TS,pty
1148 #stty sane
1149 done
1150 #reset 1>&0 2>&0
1151 done
1152 opts=
1155 #------------------------------------------------------------------------------
1157 # unnamed pipe
1158 #if false; then
1159 if true; then
1160 for addr in pipe; do
1161 ADDR=$(echo "$addr" |tr a-z A-Z)
1162 TEST="unnamed $ADDR accepts all its options"
1163 echo "### $TEST"
1164 OPTGROUPS=$($SOCAT -? |egrep " $addr[^:]" |sed 's/.*=//')
1165 OPTS=
1166 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1167 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1168 OPTS="$OPTS,$OPTG";
1169 done
1170 #echo $OPTS
1172 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1173 echo testing if unnamed $ADDR accepts option $o
1174 $SOCAT $opts $addr,$o /dev/null </dev/null
1175 done
1176 done
1179 #------------------------------------------------------------------------------
1181 # test addresses on files
1184 #if false; then
1185 if true; then
1186 for addr in create; do
1187 ADDR=$(echo "$addr" |tr a-z A-Z)
1188 TEST="$ADDR on new file accepts all its options"
1189 echo "### $TEST"
1190 TF=$TD/file$N
1191 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1192 OPTS=
1193 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1194 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1195 OPTS="$OPTS,$OPTG";
1196 done
1197 #echo $OPTS
1199 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1200 echo testing if $ADDR accepts option $o
1201 rm -f $TF
1202 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1203 rm -f $TF
1204 done
1205 done
1207 #------------------------------------------------------------------------------
1209 #if false; then
1210 if true; then
1211 for addr in exec system; do
1212 ADDR=$(echo "$addr" |tr a-z A-Z)
1214 TEST="$ADDR with socketpair accepts all its options"
1215 echo "### $TEST"
1216 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1217 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g')
1218 OPTS=
1219 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1220 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1221 OPTS="$OPTS,$OPTG";
1222 done
1223 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1224 #echo $OPTS
1225 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1226 echo testing if $ADDR with socketpair accepts option $o
1227 $SOCAT $opts $addr:$TRUE,$o /dev/null,ignoreof </dev/null
1228 done
1230 TEST="$ADDR with pipes accepts all its options"
1231 echo "### $TEST"
1232 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1233 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1234 OPTS=
1235 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1236 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1237 OPTS="$OPTS,$OPTG";
1238 done
1239 # flock tends to hang, so dont test it
1240 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g' -e 's/,flock,/,/g')
1241 #echo $OPTS
1242 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1243 echo testing if $ADDR with pipes accepts option $o
1244 $SOCAT $opts $addr:$TRUE,pipes,$o /dev/null,ignoreof </dev/null
1245 done
1247 TEST="$ADDR with pty accepts all its options"
1248 echo "### $TEST"
1249 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1250 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1251 OPTS=
1252 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1253 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1254 OPTS="$OPTS,$OPTG";
1255 done
1256 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1257 #echo $OPTS
1258 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1259 echo testing if $ADDR with pty accepts option $o
1260 $SOCAT $opts $addr:$TRUE,pty,$o /dev/null,ignoreof </dev/null
1261 done
1263 TEST="$ADDR with nofork accepts all its options"
1264 echo "### $TEST"
1265 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1266 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,PTY,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1267 OPTS=
1268 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1269 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1270 OPTS="$OPTS,$OPTG";
1271 done
1272 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1273 #echo $OPTS
1274 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1275 echo testing if $ADDR with nofork accepts option $o
1276 $SOCAT /dev/null $opts $addr:$TRUE,nofork,$o </dev/null
1277 done
1279 done
1282 #------------------------------------------------------------------------------
1284 #if false; then
1285 if true; then
1286 for addr in fd; do
1287 ADDR=$(echo "$addr" |tr a-z A-Z)
1288 TEST="$ADDR accepts all its options"
1289 echo "### $TEST"
1290 TF=$TD/file$N
1291 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1292 OPTS=
1293 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1294 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1295 OPTS="$OPTS,$OPTG";
1296 done
1297 #echo $OPTS
1298 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1299 echo "testing if $ADDR (to file) accepts option $o"
1300 rm -f $TF
1301 $SOCAT $opts -u /dev/null $addr:3,$o 3>$TF
1302 done
1303 done
1306 #------------------------------------------------------------------------------
1308 # test OPEN address
1310 #! test it on pipe, device, new file
1313 #if false; then
1314 if true; then
1315 for addr in open; do
1316 ADDR=$(echo "$addr" |tr a-z A-Z)
1317 TEST="$ADDR on file accepts all its options"
1318 echo "### $TEST"
1319 TF=$TD/file$N
1320 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1321 OPTS=
1322 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1323 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1324 OPTS="$OPTS,$OPTG";
1325 done
1326 #echo $OPTS
1327 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1328 echo testing if $ADDR on file accepts option $o
1329 touch $TF
1330 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1331 rm -f $TF
1332 done
1333 done
1336 #------------------------------------------------------------------------------
1338 # test GOPEN address on files, sockets, pipes, devices
1341 #if false; then
1342 if true; then
1343 for addr in gopen; do
1344 ADDR=$(echo "$addr" |tr a-z A-Z)
1346 TEST="$ADDR on new file accepts all its options"
1347 echo "### $TEST"
1348 TF=$TD/file$N
1349 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1350 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1351 OPTS=
1352 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1353 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1354 OPTS="$OPTS,$OPTG";
1355 done
1356 #echo $OPTS
1357 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1358 echo testing if $ADDR on new file accepts option $o
1359 rm -f $TF
1360 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1361 rm -f $TF
1362 done
1364 TEST="$ADDR on existing file accepts all its options"
1365 echo "### $TEST"
1366 TF=$TD/file$N
1367 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1368 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1369 OPTS=
1370 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1371 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1372 OPTS="$OPTS,$OPTG";
1373 done
1374 #echo $OPTS
1375 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1376 echo testing if $ADDR on existing file accepts option $o
1377 rm -f $TF; touch $TF
1378 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1379 rm -f $TF
1380 done
1382 TEST="$ADDR on existing pipe accepts all its options"
1383 echo "### $TEST"
1384 TF=$TD/pipe$N
1385 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1386 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1387 OPTS=
1388 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1389 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1390 OPTS="$OPTS,$OPTG";
1391 done
1392 #echo $OPTS
1393 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1394 echo testing if $ADDR on named pipe accepts option $o
1395 rm -f $TF; mkfifo $TF
1396 $SOCAT $opts $addr:$TF,$o,nonblock /dev/null </dev/null
1397 rm -f $TF
1398 done
1400 TEST="$ADDR on existing socket accepts all its options"
1401 echo "### $TEST"
1402 TF=$TD/sock$N
1403 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1404 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1405 OPTS=
1406 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1407 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1408 OPTS="$OPTS,$OPTG";
1409 done
1410 #echo $OPTS
1411 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1412 echo testing if $ADDR on socket accepts option $o
1413 rm -f $TF; $SOCAT - UNIX-L:$TF & pid=$!
1414 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1415 kill $pid 2>/dev/null
1416 rm -f $TF
1417 done
1419 if [ $(id -u) -eq 0 ]; then
1420 TEST="$ADDR on existing device accepts all its options"
1421 echo "### $TEST"
1422 TF=$TD/null
1423 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1424 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1425 OPTS=
1426 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1427 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1428 OPTS="$OPTS,$OPTG";
1429 done
1430 #echo $OPTS
1431 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1432 echo testing if $ADDR on existing device accepts option $o
1433 rm -f $TF; mknod $TF c 1 3
1434 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1435 done
1436 else
1437 TEST="$ADDR on existing device accepts all its options"
1438 echo "### $TEST"
1439 TF=/dev/null
1440 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1441 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1442 OPTS=
1443 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1444 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1445 OPTS="$OPTS,$OPTG";
1446 done
1447 #echo $OPTS
1448 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1449 echo testing if $ADDR on existing device accepts option $o
1450 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1451 done
1454 done
1457 #------------------------------------------------------------------------------
1459 # test named pipe
1462 #if false; then
1463 if true; then
1464 for addr in pipe; do
1465 ADDR=$(echo "$addr" |tr a-z A-Z)
1466 TEST="$ADDR on file accepts all its options"
1467 echo "### $TEST"
1468 TF=$TD/pipe$N
1469 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1470 OPTS=
1471 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1472 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1473 OPTS="$OPTS,$OPTG";
1474 done
1475 #echo $OPTS
1477 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1478 echo testing if named $ADDR accepts option $o
1479 rm -f $TF
1480 # blocks with rdonly, wronly
1481 case "$o" in rdonly|wronly) o="$o,nonblock" ;; esac
1482 $SOCAT $opts $addr:$TF,$o /dev/null </dev/null
1483 rm -f $TF
1484 done
1485 done
1487 #------------------------------------------------------------------------------
1489 # test STDIO
1491 #! test different stream types
1493 #if false; then
1494 if true; then
1495 for addr in stdio; do
1496 ADDR=$(echo "$addr" |tr a-z A-Z)
1497 TEST="$ADDR accepts all its options"
1498 echo "### $TEST"
1499 OPTGROUPS=$($SOCAT -? |fgrep " $addr" |sed 's/.*=//')
1500 OPTS=
1501 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1502 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1503 OPTS="$OPTS,$OPTG";
1504 done
1505 #echo $OPTS
1507 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1508 echo "testing if $ADDR (/dev/null, stdout) accepts option $o"
1509 $SOCAT $opts $addr,$o /dev/null,ignoreof </dev/null
1510 done
1511 done
1514 #------------------------------------------------------------------------------
1516 # test STDIN
1518 #if false; then
1519 if true; then
1520 for addr in stdin; do
1521 ADDR=$(echo "$addr" |tr a-z A-Z)
1522 TEST="$ADDR accepts all its options"
1523 echo "### $TEST"
1524 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1525 OPTS=
1526 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1527 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1528 OPTS="$OPTS,$OPTG";
1529 done
1530 #echo $OPTS
1532 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1533 echo "testing if $ADDR (/dev/null) accepts option $o"
1534 $SOCAT $opts -u $addr,$o /dev/null </dev/null
1535 done
1536 done
1539 #------------------------------------------------------------------------------
1541 # test STDOUT, STDERR
1543 if true; then
1544 #if false; then
1545 for addr in stdout stderr; do
1546 ADDR=$(echo "$addr" |tr a-z A-Z)
1547 TEST="$ADDR accepts all its options"
1548 echo "### $TEST"
1549 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1550 OPTS=
1551 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1552 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1553 OPTS="$OPTS,$OPTG";
1554 done
1555 #echo $OPTS
1556 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1557 echo "testing if $ADDR accepts option $o"
1558 $SOCAT $opts -u /dev/null $addr,$o
1559 done
1560 done
1563 #------------------------------------------------------------------------------
1564 # REQUIRES ROOT
1566 if [ "$withroot" ]; then
1567 for addr in ip4; do
1568 ADDR=$(echo "$addr" |tr a-z A-Z)
1569 TEST="$ADDR accepts all its options"
1570 echo "### $TEST"
1571 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1572 OPTS=
1573 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1574 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1575 OPTS="$OPTS,$OPTG";
1576 done
1577 #echo $OPTS
1578 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1579 echo "testing if $ADDR accepts option $o"
1580 $SOCAT $opts $addr:127.0.0.1:200 /dev/null,ignoreof </dev/null
1581 done
1582 done
1585 #------------------------------------------------------------------------------
1586 # REQUIRES ROOT
1588 if [ "$withroot" ]; then
1589 for addr in ip6; do
1590 ADDR=$(echo "$addr" |tr a-z A-Z)
1591 TEST="$ADDR accepts all its options"
1592 echo "### $TEST"
1593 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1594 OPTS=
1595 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1596 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1597 OPTS="$OPTS,$OPTG";
1598 done
1599 #echo $OPTS
1600 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1601 echo "testing if $ADDR accepts option $o"
1602 $SOCAT $opts $addr:[::1]:200 /dev/null,ignoreof </dev/null
1603 done
1604 done
1607 #==============================================================================
1609 #TEST="stdio accepts all options of GROUP_ANY"
1610 #echo "### $TEST"
1611 #CMD="$SOCAT $opts -,$OPTS_ANY /dev/null"
1612 #$CMD
1613 #if [ $? = 0 ]; then
1614 # echo "... test $N ($TEST) succeeded"
1615 ## echo "CMD=$CMD"
1616 #else
1617 # echo "*** test $N ($TEST) FAILED"
1618 # echo "CMD=$CMD"
1621 #N=$((N+1))
1622 ##------------------------------------------------------------------------------
1624 #TEST="exec accepts all options of GROUP_ANY and GROUP_SOCKET"
1625 #echo "### $TEST"
1626 #CMD="$SOCAT $opts exec:$TRUE,$OPTS_ANY,$OPTS_SOCKET /dev/null"
1627 #$CMD
1628 #if [ $? = 0 ]; then
1629 # echo "... test $N ($TEST) succeeded"
1630 ## echo "CMD=$CMD"
1631 #else
1632 # echo "*** test $N ($TEST) FAILED"
1633 # echo "CMD=$CMD"
1636 #------------------------------------------------------------------------------
1638 esac
1640 #==============================================================================
1643 numOK=0
1644 numFAIL=0
1645 numCANT=0
1646 listFAIL=
1648 #==============================================================================
1649 # test if selected socat features work ("FUNCTIONS")
1651 testecho () {
1652 local N="$1"
1653 local title="$2"
1654 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1655 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1656 local opts="$5"
1657 local T="$6"; [ -z "$T" ] && T=0
1658 local tf="$td/test$N.stdout"
1659 local te="$td/test$N.stderr"
1660 local tdiff="$td/test$N.diff"
1661 local da="test$N $(date) $RANDOM"
1662 if ! eval $NUMCOND; then :; else
1663 #local cmd="$TRACE $SOCAT $opts $arg1 $arg2"
1664 #$ECHO "testing $title (test $N)... \c"
1665 $PRINTF "test $F_n %s... " $N "$title"
1666 #echo "$da" |$cmd >"$tf" 2>"$te"
1667 (psleep $T; echo "$da"; psleep $T) |($TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"; echo $? >"$td/test$N.rc") &
1668 export rc1=$!
1669 #sleep 5 && kill $rc1 2>/dev/null &
1670 # rc2=$!
1671 wait $rc1
1672 # kill $rc2 2>/dev/null
1673 if [ "$(cat "$td/test$N.rc")" != 0 ]; then
1674 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1675 echo "$TRACE $SOCAT $opts $arg1 $arg2" >&2
1676 cat "$te" >&2
1677 numFAIL=$((numFAIL+1))
1678 listFAIL="$listFAIL $N"
1679 elif echo "$da" |diff - "$tf" >"$tdiff" 2>&1; then
1680 $PRINTF "$OK\n"
1681 if [ "$verbose" ]; then echo "$SOCAT $opts $arg1 $arg2" >&2; fi
1682 if [ -n "$debug" ]; then cat $te >&2; fi
1683 numOK=$((numOK+1))
1684 else
1685 $PRINTF "$FAILED:\n"
1686 echo "$TRACE $SOCAT $opts $arg1 $arg2" >&2
1687 cat "$te" >&2
1688 echo diff: >&2
1689 cat "$tdiff" >&2
1690 numFAIL=$((numFAIL+1))
1691 listFAIL="$listFAIL $N"
1693 fi # NUMCOND
1696 # test if call to od and throughput of data works - with graceful shutdown and
1697 # flush of od buffers
1698 testod () {
1699 local num="$1"
1700 local title="$2"
1701 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1702 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1703 local opts="$5"
1704 local T="$6"; [ -z "$T" ] && T=0
1705 local tf="$td/test$N.stdout"
1706 local te="$td/test$N.stderr"
1707 local tr="$td/test$N.ref"
1708 local tdiff="$td/test$N.diff"
1709 local dain="$(date) $RANDOM"
1710 if ! eval $NUMCOND; then :; else
1711 echo "$dain" |$OD_C >"$tr"
1712 # local daout="$(echo "$dain" |$OD_C)"
1713 $PRINTF "test $F_n %s... " $num "$title"
1714 (psleep $T; echo "$dain"; psleep $T) |$TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"
1715 if [ "$?" != 0 ]; then
1716 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1717 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1718 cat "$te"
1719 numFAIL=$((numFAIL+1))
1720 listFAIL="$listFAIL $num"
1721 # elif echo "$daout" |diff - "$tf" >"$tdiff" 2>&1; then
1722 elif diff "$tr" "$tf" >"$tdiff" 2>&1; then
1723 $PRINTF "$OK\n"
1724 if [ -n "$debug" ]; then cat $te; fi
1725 numOK=$((numOK+1))
1726 else
1727 $PRINTF "$FAILED: diff:\n"
1728 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1729 cat "$te"
1730 cat "$tdiff"
1731 numFAIL=$((numFAIL+1))
1732 listFAIL="$listFAIL $num"
1734 fi # NUMCOND
1737 # test if the socat executable has these address types compiled in
1738 # print the first missing address type
1739 testaddrs () {
1740 local a A;
1741 for a in $@; do
1742 A=$(echo "$a" |tr 'a-z-' 'A-Z_')
1743 if $TRACE $SOCAT -V |grep "#define WITH_$A 1\$" >/dev/null; then
1744 if [[ "$A" =~ OPENSSL.* ]]; then
1745 gentestcert testsrv
1746 gentestcert testcli
1748 shift
1749 continue
1751 echo "$a"
1752 return 1
1753 done
1754 return 0
1757 # test if the socat executable has these options compiled in
1758 # print the first missing option
1759 testoptions () {
1760 local a A;
1761 for a in $@; do
1762 A=$(echo "$a" |tr 'a-z' 'A-Z')
1763 if $SOCAT -??? |grep "[^a-z0-9-]$a[^a-z0-9-]" >/dev/null; then
1764 shift
1765 continue
1767 echo "$a"
1768 return 1
1769 done
1770 return 0
1773 # check if the given pid exists and has child processes
1774 # if yes: prints child process lines to stdout, returns 0
1775 # if not: prints ev.message to stderr, returns 1
1776 childprocess () {
1777 local l
1778 case "$UNAME" in
1779 AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)")" ;;
1780 FreeBSD) l="$(ps -faje |grep "^........ ..... $(printf %5u $1)")" ;;
1781 HP-UX) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1782 Linux) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1783 # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)")" ;;
1784 NetBSD) l="$(ps -aj |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
1785 OpenBSD) l="$(ps -aj |grep "^........ ..... $(printf %5u $1)")" ;;
1786 SunOS) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1787 DragonFly)l="$(ps -faje |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
1788 CYGWIN*) l="$(ps -pafe |grep "^[^ ]*[ ][ ]*[^ ][^ ]*[ ][ ]*$1[ ]")" ;;
1789 *) l="$(ps -fade |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]**[ ][ ]*$(printf %5u $1) ")" ;; esac
1790 if [ -z "$l" ]; then
1791 return 1;
1793 echo "$l"
1794 return 0
1797 # return a list of child process pids
1798 childpids () {
1799 case "$UNAME" in
1800 AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)" |awk '{print($2);}')" ;;
1801 FreeBSD) l="$(ps -fl |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]*[ ][ ]*$(printf %5u $1)" |awk '{print($2);}')" ;;
1802 HP-UX) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1803 Linux) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1804 # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)" |awk '{print($2);}')" ;;
1805 NetBSD) l="$(ps -aj |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1806 OpenBSD) l="$(ps -aj |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1807 SunOS) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1808 DragonFly)l="$(ps -faje |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)" |awk '{print($2);}')" ;;
1809 CYGWIN*) l="$(ps -pafe |grep "^[^ ]*[ ][ ]*[^ ][^ ]*[ ][ ]*$1[ ]" |awk '{print($2)';})" ;;
1810 *) l="$(ps -fade |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]*[ ][ ]*$(printf %5u $1) " |awk '{print($2)';})" ;; esac
1811 if [ -z "$l" ]; then
1812 return 1;
1814 echo "$l"
1815 return 0
1818 # check if the given process line refers to a defunct (zombie) process
1819 # yes: returns 0
1820 # no: returns 1
1821 isdefunct () {
1822 local l
1823 case "$UNAME" in
1824 AIX) l="$(echo "$1" |grep ' <defunct>$')" ;;
1825 FreeBSD) l="$(echo "$1" |grep ' <defunct>$')" ;;
1826 HP-UX) l="$(echo "$1" |grep ' <defunct>$')" ;;
1827 Linux) l="$(echo "$1" |grep ' <defunct>$')" ;;
1828 SunOS) l="$(echo "$1" |grep ' <defunct>$')" ;;
1829 DragonFly)l="$(echo "$1" |grep ' <defunct>$')" ;;
1830 *) l="$(echo "$1" |grep ' <defunct>$')" ;;
1831 esac
1832 [ -n "$l" ];
1835 # check if UNIX socket protocol is available on host
1836 runsunix () {
1837 return 0;
1838 $TRACE $SOCAT /dev/null UNIX-LISTEN:"$td/unix.socket" 2>"$td/unix.stderr" &
1839 pid=$!
1840 usleep $MICROS
1841 kill "$pid" 2>/dev/null
1842 test ! -s "$td/unix.stderr"
1845 unset HAVENOT_IP4
1846 # check if an IP4 loopback interface exists
1847 runsip4 () {
1848 [ -n "$HAVENOT_IP4" ] && return $HAVENOT_IP4
1849 local l
1850 case "$UNAME" in
1851 AIX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1852 FreeBSD) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1853 HP-UX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1854 Linux) if [ "$IP" ]; then
1855 l=$($IP address |egrep ' inet 127.0.0.1/')
1856 else
1857 l=$($IFCONFIG |egrep 'inet (addr:)?127\.0\.0\.1 ')
1858 fi ;;
1859 NetBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1860 OpenBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1861 OSF1) l=$($IFCONFIG -a |grep ' inet ') ;;
1862 SunOS) l=$($IFCONFIG -a |grep 'inet ') ;;
1863 Darwin)l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1864 DragonFly)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1865 CYGWIN*) l=$(ipconfig |grep IPv4);;
1866 *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
1867 esac
1868 [ -z "$l" ] && return 1
1869 # existence of interface might not suffice, check for routeability:
1870 case "$UNAME" in
1871 Darwin) ping -c 1 127.0.0.1 >/dev/null 2>&1; l="$?" ;;
1872 Linux) ping -c 1 127.0.0.1 >/dev/null 2>&1; l="$?" ;;
1873 *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
1874 esac
1875 HAVENOT_IP4=$l
1876 return $l;
1879 unset HAVENOT_IP6
1880 # check if an IP6 loopback interface exists
1881 runsip6 () {
1882 [ -n "$HAVENOT_IP6" ] && return $HAVENOT_IP6
1883 local l
1884 case "$UNAME" in
1885 AIX) l=$($IFCONFIG lo0 |grep 'inet6 ::1/0') ;;
1886 HP-UX) l=$($IFCONFIG lo0 |grep ' inet6 ') ;;
1887 Linux) if [ "$IP" ]; then
1888 l=$($IP address |egrep 'inet6 ::1/128')
1889 else
1890 l=$($IFCONFIG |egrep 'inet6 (addr: )?::1/?')
1891 fi ;;
1892 NetBSD)l=$($IFCONFIG -a |grep 'inet6 ::1 ');;
1893 OSF1) l=$($IFCONFIG -a |grep ' inet6 ') ;;
1894 SunOS) l=$($IFCONFIG -a |grep 'inet6 ') ;;
1895 Darwin)l=$($IFCONFIG lo0 |grep 'inet6 ::1 ') ;;
1896 CYGWIN*) l=$(ipconfig |grep IPv6);;
1897 *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
1898 esac
1899 [ -z "$l" ] && return 1
1900 # existence of interface might not suffice, check for routeability:
1901 case "$UNAME" in
1902 Darwin) $PING6 -c 1 ::1 >/dev/null 2>&1; l="$?" ;;
1903 Linux) $PING6 -c 1 ::1 >/dev/null 2>&1; l="$?" ;;
1904 *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
1905 esac
1906 HAVENOT_IP6=$l
1907 return $l;
1910 # check if TCP on IPv4 is available on host
1911 runstcp4 () {
1912 runsip4 || return 1
1913 $SOCAT -h |grep '\<tcp4-' >/dev/null || return 1
1914 return 0;
1917 # check if TCP on IPv6 is available on host
1918 runstcp6 () {
1919 runsip6 || return 1
1920 $SOCAT -h |grep '\<tcp6-' >/dev/null || return 1
1921 return 0;
1924 # check if UDP on IPv4 is available on host
1925 runsudp4 () {
1926 runsip4 || return 1
1927 $SOCAT -h |grep '\<udp4-' >/dev/null || return 1
1928 return 0;
1931 # check if UDP on IPv6 is available on host
1932 runsudp6 () {
1933 runsip6 || return 1
1934 $SOCAT -h |grep '\<udp6-' >/dev/null || return 1
1935 return 0;
1938 # check if SCTP on IPv4 is available on host
1939 runssctp4 () {
1940 runsip4 || return 1
1941 $SOCAT -h |grep '\<sctp4-' >/dev/null || return 1
1942 return 0;
1945 # check if SCTP on IPv6 is available on host
1946 runssctp6 () {
1947 runsip6 || return 1
1948 $SOCAT -h |grep '\<sctp6-' >/dev/null || return 1
1949 return 0;
1952 # wait until an IP4 protocol is ready
1953 waitip4proto () {
1954 local proto="$1"
1955 local logic="$2" # 0..wait until free; 1..wait until listening
1956 local timeout="$3"
1957 local l
1958 [ "$logic" ] || logic=1
1959 [ "$timeout" ] || timeout=5
1960 while [ $timeout -gt 0 ]; do
1961 case "$UNAME" in
1962 Linux) if [ "$SS" ]; then
1963 l=$($SS -n -w -l |grep '^\(raw\|UNCONN\) .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*')
1964 else
1965 l=$(netstat -n -w -l |grep '^raw .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*')
1966 fi ;;
1967 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
1968 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1969 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1970 # Darwin) case "$(uname -r)" in
1971 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
1972 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
1973 # esac ;;
1974 AIX) # does not seem to show raw sockets in netstat
1975 sleep 1; return 0 ;;
1976 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
1977 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
1978 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
1979 *) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;;
1980 sleep 1; return 0 ;;
1981 esac
1982 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
1983 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
1984 sleep 1
1985 timeout=$((timeout-1))
1986 done
1988 $ECHO "!protocol $proto timed out! \c" >&2
1989 return 1
1992 # we need this misleading function name for canonical reasons
1993 waitip4port () {
1994 waitip4proto "$1" "$2" "$3"
1997 # wait until an IP6 protocol is ready
1998 waitip6proto () {
1999 local proto="$1"
2000 local logic="$2" # 0..wait until free; 1..wait until listening
2001 local timeout="$3"
2002 local l
2003 [ "$logic" ] || logic=1
2004 [ "$timeout" ] || timeout=5
2005 while [ $timeout -gt 0 ]; do
2006 case "$UNAME" in
2007 Linux)
2008 if [ "$SS" ]; then
2009 l=$($SS -n -w -l |grep '^\(raw\|UNCONN\) .* \*:'$proto' [ ]*\*:\*')
2010 else
2011 l=$(netstat -n -w -l |grep '^raw[6 ] .* .*:[0-9*]*:'$proto' [ ]*:::\*')
2012 fi ;;
2013 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
2014 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2015 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2016 # Darwin) case "$(uname -r)" in
2017 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
2018 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
2019 # esac ;;
2020 AIX) # does not seem to show raw sockets in netstat
2021 sleep 1; return 0 ;;
2022 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
2023 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
2024 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
2025 *) #l=$(netstat -an |egrep -i 'raw6? .*[0-9*][:.]'$proto' ') ;;
2026 sleep 1; return 0 ;;
2027 esac
2028 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2029 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
2030 sleep 1
2031 timeout=$((timeout-1))
2032 done
2034 $ECHO "!protocol $proto timed out! \c" >&2
2035 return 1
2038 # we need this misleading function name for canonical reasons
2039 waitip6port () {
2040 waitip6proto "$1" "$2" "$3"
2043 # check if a TCP4 port is in use
2044 # exits with 0 when it is not used
2045 checktcp4port () {
2046 local port="$1"
2047 local l
2048 case "$UNAME" in
2049 Linux) if [ "$SS" ]; then
2050 l=$($SS -4 -l -n -t |grep "^LISTEN .*:$port\>")
2051 else
2052 l=$(netstat -a -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN')
2053 fi ;;
2054 FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2055 NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2056 Darwin) case "$(uname -r)" in
2057 [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2058 *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2059 esac ;;
2060 AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2061 SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2062 HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2063 OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2064 CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2065 DragonFly)l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2066 *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2067 esac
2068 [ -z "$l" ] && return 0
2069 return 1
2072 # wait until a TCP4 listen port is ready
2073 waittcp4port () {
2074 local port="$1"
2075 local logic="$2" # 0..wait until free; 1..wait until listening (default)
2076 local timeout="$3"
2077 local l
2078 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2079 [ "$logic" ] || logic=1
2080 [ "$timeout" ] || timeout=5
2081 while [ $timeout -gt 0 ]; do
2082 case "$UNAME" in
2083 Linux) if [ "$SS" ]; then
2084 l=$($SS -l -n -t |grep "^LISTEN .*:$port\>")
2085 else
2086 l=$(netstat -a -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN')
2087 fi ;;
2088 FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2089 NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2090 Darwin) case "$(uname -r)" in
2091 [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2092 *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2093 esac ;;
2094 AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2095 SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2096 HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2097 OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2098 CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2099 DragonFly) l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2100 *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2101 esac
2102 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2103 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2104 set ${vx}vx
2105 return 0
2107 sleep 1
2108 timeout=$((timeout-1))
2109 done
2111 $ECHO "!port $port timed out! \c" >&2
2112 set ${vx}vx
2113 return 1
2116 # wait until a UDP4 port is ready
2117 waitudp4port () {
2118 local port="$1"
2119 local logic="$2" # 0..wait until free; 1..wait until listening
2120 local timeout="$3"
2121 local l
2122 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2123 [ "$logic" ] || logic=1
2124 [ "$timeout" ] || timeout=5
2125 while [ $timeout -gt 0 ]; do
2126 case "$UNAME" in
2127 Linux) if [ "$SS" ]; then
2128 l=$($SS -4 -l -n -u |grep "^UNCONN .*:$port\>")
2129 else
2130 l=$(netstat -a -n -u -l |grep '^udp .* .*[0-9*]:'$port' [ ]*0\.0\.0\.0:\*')
2131 fi ;;
2132 FreeBSD) l=$(netstat -an |egrep '^udp46? .*[0-9*]\.'$port' .* \*\.\*') ;;
2133 NetBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2134 OpenBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2135 Darwin) case "$(uname -r)" in
2136 [1-5]*) l=$(netstat -an |grep '^udp.* .*[0-9*]\.'$port' .* \*\.\*') ;;
2137 *) l=$(netstat -an |grep '^udp4.* .*[0-9*]\.'$port' .* \*\.\* .*') ;;
2138 esac ;;
2139 AIX) l=$(netstat -an |grep '^udp[4 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2140 SunOS) l=$(netstat -an -f inet -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2141 HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' .* \*\.\* ') ;;
2142 OSF1) l=$(/usr/sbin/netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2143 DragonFly) l=$(netstat -an |grep '^udp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2144 *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2145 esac
2146 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2147 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2148 set ${vx}vx
2149 return 0
2151 sleep 1
2152 timeout=$((timeout-1))
2153 done
2155 $ECHO "!port $port timed out! \c" >&2
2156 set ${vx}vx
2157 return 1
2160 # wait until an SCTP4 listen port is ready
2161 waitsctp4port () {
2162 local port="$1"
2163 local logic="$2" # 0..wait until free; 1..wait until listening
2164 local timeout="$3"
2165 local l
2166 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2167 [ "$logic" ] || logic=1
2168 [ "$timeout" ] || timeout=5
2169 while [ $timeout -gt 0 ]; do
2170 case "$UNAME" in
2171 Linux) if [ "$SS" ]; then
2172 l=$($SS -4 -n -A sctp 2>/dev/null |grep "^LISTEN .*:$port\>")
2173 else
2174 l=$(netstat -n -a |grep '^sctp .* .*[0-9*]:'$port' .* LISTEN')
2175 fi ;;
2176 # FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2177 # NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2178 # Darwin) case "$(uname -r)" in
2179 # [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2180 # *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2181 # esac ;;
2182 # AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2183 SunOS) l=$(netstat -an -f inet -P sctp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2184 # HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2185 # OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2186 # CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2187 *) l=$(netstat -an |grep -i 'sctp .*[0-9*][:.]'$port' .* listen') ;;
2188 esac
2189 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2190 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2191 set ${vx}vx
2192 return 0
2194 sleep 1
2195 timeout=$((timeout-1))
2196 done
2198 $ECHO "!port $port timed out! \c" >&2
2199 set ${vx}vx
2200 return 1
2203 # wait until a tcp6 listen port is ready
2204 waittcp6port () {
2205 local port="$1"
2206 local logic="$2" # 0..wait until free; 1..wait until listening
2207 local timeout="$3"
2208 local l
2209 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2210 [ "$logic" ] || logic=1
2211 [ "$timeout" ] || timeout=5
2212 while [ $timeout -gt 0 ]; do
2213 case "$UNAME" in
2214 Linux) if [ "$SS" ]; then
2215 l=$($SS -6 -n -t -l |grep "^LISTEN .*:$port\>")
2216 else
2217 l=$(netstat -an |grep -E '^tcp6? .* [0-9a-f:%]*:'$port' .* LISTEN')
2218 fi ;;
2219 FreeBSD) l=$(netstat -an |egrep -i 'tcp(6|46) .*[0-9*][:.]'$port' .* listen') ;;
2220 NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2221 OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2222 Darwin) l=$(netstat -an |egrep '^tcp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+ +LISTEN') ;;
2223 AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2224 SunOS) l=$(netstat -an -f inet6 -P tcp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2225 #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2226 DragonFly) l=$(netstat -ant |grep '^tcp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2227 *) l=$(netstat -an |grep -i 'tcp6 .*:'$port' .* listen') ;;
2228 esac
2229 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2230 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2231 set ${vx}vx
2232 return 0
2234 sleep 1
2235 timeout=$((timeout-1))
2236 done
2238 $ECHO "!port $port timed out! \c" >&2
2239 #echo set ${vx}vx >&2
2240 set ${vx}vx
2241 return 1
2244 # wait until a UDP6 port is ready
2245 waitudp6port () {
2246 local port="$1"
2247 local logic="$2" # 0..wait until free; 1..wait until listening
2248 local timeout="$3"
2249 local l
2250 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2251 [ "$logic" ] || logic=1
2252 [ "$timeout" ] || timeout=5
2253 while [ $timeout -gt 0 ]; do
2254 case "$UNAME" in
2255 Linux) if [ "$SS" ]; then
2256 l=$($SS -6 -u -l -n |grep "^UNCONN .*:$port\>")
2257 else
2258 l=$(netstat -an |grep -E '^udp6? .* .*[0-9*:%]:'$port' [ ]*:::\*')
2259 fi ;;
2260 FreeBSD) l=$(netstat -an |egrep '^udp(6|46) .*[0-9*]\.'$port' .* \*\.\*') ;;
2261 NetBSD) l=$(netstat -an |grep '^udp6 .* \*\.'$port' [ ]* \*\.\*') ;;
2262 OpenBSD) l=$(netstat -an |grep '^udp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2263 Darwin) l=$(netstat -an |egrep '^udp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+') ;;
2264 AIX) l=$(netstat -an |grep '^udp[6 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2265 SunOS) l=$(netstat -an -f inet6 -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2266 #HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' ') ;;
2267 #OSF1) l=$(/usr/sbin/netstat -an |grep '^udp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2268 DragonFly) l=$(netstat -ant |grep '^udp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2269 *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2270 esac
2271 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2272 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2273 set ${vx}vx
2274 return 0
2276 sleep 1
2277 timeout=$((timeout-1))
2278 done
2280 $ECHO "!port $port timed out! \c" >&2
2281 set ${vx}vx
2282 return 1
2285 # wait until a sctp6 listen port is ready
2286 # not all (Linux) variants show this in netstat
2287 waitsctp6port () {
2288 local port="$1"
2289 local logic="$2" # 0..wait until free; 1..wait until listening
2290 local timeout="$3"
2291 local l
2292 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2293 [ "$logic" ] || logic=1
2294 [ "$timeout" ] || timeout=5
2295 while [ $timeout -gt 0 ]; do
2296 case "$UNAME" in
2297 Linux) if [ "$SS" ]; then
2298 l=$($SS -6 -n -A sctp 2>/dev/null |grep "^LISTEN .*:$port\>")
2299 else
2300 l=$(netstat -an |grep '^sctp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN')
2301 fi ;;
2302 # FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;;
2303 # NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2304 # OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2305 # AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2306 SunOS) l=$(netstat -an -f inet6 -P sctp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2307 # #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2308 *) l=$(netstat -an |grep -i 'stcp6 .*:'$port' .* listen') ;;
2309 esac
2310 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2311 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2312 set ${vx}vx
2313 return 0
2315 sleep 1
2316 timeout=$((timeout-1))
2317 done
2319 $ECHO "!port $port timed out! \c" >&2
2320 set ${vx}vx
2321 return 1
2324 # we need this misleading function name for canonical reasons
2325 waitunixport () {
2326 waitfile "$1" "$2" "$3"
2329 # wait until a filesystem entry exists
2330 waitfile () {
2331 local crit=-e
2332 case "X$1" in X-*) crit="$1"; shift ;; esac
2333 local file="$1"
2334 local logic="$2" # 0..wait until gone; 1..wait until exists (default);
2335 # 2..wait until not empty
2336 local timeout="$3"
2337 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2338 [ "$logic" ] || logic=1
2339 [ "$logic" -eq 2 ] && crit=-s
2340 [ "$timeout" ] || timeout=5
2341 while [ $timeout -gt 0 ]; do
2342 if [ \( \( $logic -ne 0 \) -a $crit "$file" \) -o \
2343 \( \( $logic -eq 0 \) -a ! $crit "$file" \) ]; then
2344 set ${vx}vx
2345 return 0
2347 sleep 1
2348 timeout=$((timeout-1))
2349 done
2351 echo "file $file timed out" >&2
2352 set ${vx}vx
2353 return 1
2356 # generate a test certificate and key
2357 gentestcert () {
2358 local name="$1"
2359 if ! [ -f testcert.dh ]; then
2360 openssl dhparam -out testcert.dh $RSABITS
2362 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2363 openssl genrsa $OPENSSL_RAND -out $name.key $RSABITS >/dev/null 2>&1
2364 openssl req -new -config $TESTCERT_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
2365 cat $name.key $name.crt testcert.dh >$name.pem
2368 # generate a test DSA key and certificate
2369 gentestdsacert () {
2370 local name="$1"
2371 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2372 openssl dsaparam -out $name-dsa.pem 1024 >/dev/null 2>&1
2373 openssl dhparam -dsaparam -out $name-dh.pem 1024 >/dev/null 2>&1
2374 openssl req -newkey dsa:$name-dsa.pem -keyout $name.key -nodes -x509 -config $TESTCERT_CONF -out $name.crt -days 3653 >/dev/null 2>&1
2375 cat $name-dsa.pem $name-dh.pem $name.key $name.crt >$name.pem
2378 # generate a test EC key and certificate
2379 gentesteccert () {
2380 local name="$1"
2381 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2382 openssl ecparam -name secp521r1 -out $name-ec.pem >/dev/null 2>&1
2383 chmod 0400 $name-ec.pem
2384 openssl req -newkey ec:$name-ec.pem -keyout $name.key -nodes -x509 -config $TESTCERT_CONF -out $name.crt -days 3653 >/dev/null 2>&1
2385 cat $name-ec.pem $name.key $name.crt >$name.pem
2388 gentestcert6 () {
2389 local name="$1"
2390 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2391 cat $TESTCERT_CONF |
2392 { echo "# automatically generated by $0"; cat; } |
2393 sed 's/\(commonName\s*=\s*\).*/\1[::1]/' >$TESTCERT6_CONF
2394 openssl genrsa $OPENSSL_RAND -out $name.key $RSABITS >/dev/null 2>&1
2395 openssl req -new -config $TESTCERT6_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
2396 cat $name.key $name.crt >$name.pem
2400 NAME=UNISTDIO
2401 case "$TESTS " in
2402 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2403 TEST="$NAME: unidirectional throughput from stdin to stdout"
2404 testecho "$N" "$TEST" "stdin" "stdout" "$opts -u"
2405 esac
2406 N=$((N+1))
2409 NAME=UNPIPESTDIO
2410 case "$TESTS" in
2411 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2412 TEST="$NAME: stdio with simple echo via internal pipe"
2413 testecho "$N" "$TEST" "stdio" "pipe" "$opts"
2414 esac
2415 N=$((N+1))
2418 NAME=UNPIPESHORT
2419 case "$TESTS" in
2420 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2421 TEST="$NAME: short form of stdio ('-') with simple echo via internal pipe"
2422 testecho "$N" "$TEST" "-" "pipe" "$opts"
2423 esac
2424 N=$((N+1))
2427 NAME=DUALSTDIO
2428 case "$TESTS" in
2429 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2430 TEST="$NAME: splitted form of stdio ('stdin!!stdout') with simple echo via internal pipe"
2431 testecho "$N" "$TEST" "stdin!!stdout" "pipe" "$opts"
2432 esac
2433 N=$((N+1))
2436 NAME=DUALSHORTSTDIO
2437 case "$TESTS" in
2438 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2439 TEST="$NAME: short splitted form of stdio ('-!!-') with simple echo via internal pipe"
2440 testecho "$N" "$TEST" "-!!-" "pipe" "$opts"
2441 esac
2442 N=$((N+1))
2445 NAME=DUALFDS
2446 case "$TESTS" in
2447 *%$N%*|*%functions%*|*%fd%*|*%$NAME%*)
2448 TEST="$NAME: file descriptors with simple echo via internal pipe"
2449 testecho "$N" "$TEST" "0!!1" "pipe" "$opts"
2450 esac
2451 N=$((N+1))
2454 NAME=NAMEDPIPE
2455 case "$TESTS" in
2456 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2457 TEST="$NAME: simple echo via named pipe"
2458 # with MacOS, this test hangs if nonblock is not used. Is an OS bug.
2459 tp="$td/pipe$N"
2460 # note: the nonblock is required by MacOS 10.1(?), otherwise it hangs (OS bug?)
2461 testecho "$N" "$TEST" "" "pipe:$tp,nonblock" "$opts"
2462 esac
2463 N=$((N+1))
2466 NAME=DUALPIPE
2467 case "$TESTS" in
2468 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2469 TEST="$NAME: simple echo via named pipe, specified twice"
2470 tp="$td/pipe$N"
2471 testecho "$N" "$TEST" "" "pipe:$tp,nonblock!!pipe:$tp" "$opts"
2472 esac
2473 N=$((N+1))
2476 NAME=FILE
2477 case "$TESTS" in
2478 *%$N%*|*%functions%*|*%engine%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
2479 TEST="$NAME: simple echo via file"
2480 tf="$td/file$N"
2481 testecho "$N" "$TEST" "" "$tf,ignoreeof!!$tf" "$opts"
2482 esac
2483 N=$((N+1))
2486 NAME=EXECSOCKET
2487 case "$TESTS" in
2488 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2489 TEST="$NAME: simple echo via exec of cat with socketpair"
2490 testecho "$N" "$TEST" "" "exec:$CAT" "$opts"
2491 esac
2492 N=$((N+1))
2495 NAME=SYSTEMSOCKET
2496 case "$TESTS" in
2497 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2498 TEST="$NAME: simple echo via system() of cat with socketpair"
2499 testecho "$N" "$TEST" "" "system:$CAT" "$opts" "$val_t"
2500 esac
2501 N=$((N+1))
2504 NAME=EXECPIPES
2505 case "$TESTS" in
2506 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2507 TEST="$NAME: simple echo via exec of cat with pipes"
2508 testecho "$N" "$TEST" "" "exec:$CAT,pipes" "$opts"
2509 esac
2510 N=$((N+1))
2513 NAME=SYSTEMPIPES
2514 case "$TESTS" in
2515 *%$N%*|*%functions%*|*%pipes%*|*%$NAME%*)
2516 TEST="$NAME: simple echo via system() of cat with pipes"
2517 testecho "$N" "$TEST" "" "system:$CAT,pipes" "$opts"
2518 esac
2519 N=$((N+1))
2522 NAME=EXECPTY
2523 case "$TESTS" in
2524 *%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
2525 TEST="$NAME: simple echo via exec of cat with pseudo terminal"
2526 if ! eval $NUMCOND; then :;
2527 elif ! testaddrs pty >/dev/null; then
2528 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2529 numCANT=$((numCANT+1))
2530 else
2531 testecho "$N" "$TEST" "" "exec:$CAT,pty,$PTYOPTS" "$opts"
2533 esac
2534 N=$((N+1))
2537 NAME=SYSTEMPTY
2538 case "$TESTS" in
2539 *%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
2540 TEST="$NAME: simple echo via system() of cat with pseudo terminal"
2541 if ! eval $NUMCOND; then :;
2542 elif ! testaddrs pty >/dev/null; then
2543 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2544 numCANT=$((numCANT+1))
2545 else
2546 testecho "$N" "$TEST" "" "system:$CAT,pty,$PTYOPTS" "$opts"
2548 esac
2549 N=$((N+1))
2552 NAME=SYSTEMPIPESFDS
2553 case "$TESTS" in
2554 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2555 TEST="$NAME: simple echo via system() of cat with pipes, non stdio"
2556 testecho "$N" "$TEST" "" "system:$CAT>&9 <&8,pipes,fdin=8,fdout=9" "$opts"
2557 esac
2558 N=$((N+1))
2561 NAME=DUALSYSTEMFDS
2562 case "$TESTS" in
2563 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2564 TEST="$NAME: echo via dual system() of cat"
2565 testecho "$N" "$TEST" "system:$CAT>&6,fdout=6!!system:$CAT<&7,fdin=7" "" "$opts" "$val_t"
2566 esac
2567 N=$((N+1))
2570 # test: send EOF to exec'ed sub process, let it finish its operation, and
2571 # check if the sub process returns its data before terminating.
2572 NAME=EXECSOCKETFLUSH
2573 # idea: have socat exec'ing od; send data and EOF, and check if the od'ed data
2574 # arrives.
2575 case "$TESTS" in
2576 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2577 TEST="$NAME: call to od via exec with socketpair"
2578 testod "$N" "$TEST" "" "exec:$OD_C" "$opts"
2579 esac
2580 N=$((N+1))
2583 NAME=SYSTEMSOCKETFLUSH
2584 case "$TESTS" in
2585 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2586 TEST="$NAME: call to od via system() with socketpair"
2587 testod "$N" "$TEST" "" "system:$OD_C" "$opts" $val_t
2588 esac
2589 N=$((N+1))
2592 NAME=EXECPIPESFLUSH
2593 case "$TESTS" in
2594 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2595 TEST="$NAME: call to od via exec with pipes"
2596 testod "$N" "$TEST" "" "exec:$OD_C,pipes" "$opts"
2597 esac
2598 N=$((N+1))
2601 NAME=SYSTEMPIPESFLUSH
2602 case "$TESTS" in
2603 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2604 TEST="$NAME: call to od via system() with pipes"
2605 testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" "$val_t"
2606 esac
2607 N=$((N+1))
2610 ## LATER:
2611 #NAME=EXECPTYFLUSH
2612 #case "$TESTS" in
2613 #*%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
2614 #TEST="$NAME: call to od via exec with pseudo terminal"
2615 #if ! testaddrs pty >/dev/null; then
2616 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2617 # numCANT=$((numCANT+1))
2618 #else
2619 #testod "$N" "$TEST" "" "exec:$OD_C,pty,$PTYOPTS" "$opts"
2621 #esac
2622 #N=$((N+1))
2625 ## LATER:
2626 #NAME=SYSTEMPTYFLUSH
2627 #case "$TESTS" in
2628 #*%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
2629 #TEST="$NAME: call to od via system() with pseudo terminal"
2630 #if ! testaddrs pty >/dev/null; then
2631 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2632 # numCANT=$((numCANT+1))
2633 #else
2634 #testod "$N" "$TEST" "" "system:$OD_C,pty,$PTYOPTS" "$opts"
2636 #esac
2637 #N=$((N+1))
2640 NAME=SYSTEMPIPESFDSFLUSH
2641 case "$TESTS" in
2642 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2643 TEST="$NAME: call to od via system() with pipes, non stdio"
2644 testod "$N" "$TEST" "" "system:$OD_C>&9 <&8,pipes,fdin=8,fdout=9" "$opts" "$val_t"
2645 esac
2646 N=$((N+1))
2649 NAME=DUALSYSTEMFDSFLUSH
2650 case "$TESTS" in
2651 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2652 TEST="$NAME: call to od via dual system()"
2653 testod "$N" "$TEST" "system:$OD_C>&6,fdout=6!!system:$CAT<&7,fdin=7" "pipe" "$opts" "$val_t"
2654 esac
2655 N=$((N+1))
2658 case "$UNAME" in
2659 Linux) IPPROTO=254 ;;
2660 Darwin) IPPROTO=255 ;;
2661 *) IPPROTO=254 ;; # just a guess
2662 esac
2664 NAME=RAWIP4SELF
2665 case "$TESTS" in
2666 *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
2667 TEST="$NAME: simple echo via self receiving raw IPv4 protocol"
2668 if ! eval $NUMCOND; then :;
2669 elif ! feat=$(testaddrs ip4) || ! runsip4 >/dev/null; then
2670 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2671 numCANT=$((numCANT+1))
2672 elif ! feat=$(testaddrs rawip) >/dev/null; then
2673 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2674 numCANT=$((numCANT+1))
2675 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2676 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2677 numCANT=$((numCANT+1))
2678 else
2679 testecho "$N" "$TEST" "" "ip4:127.0.0.1:$IPPROTO" "$opts"
2681 esac
2682 N=$((N+1))
2684 NAME=RAWIPX4SELF
2685 case "$TESTS" in
2686 *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
2687 TEST="$NAME: simple echo via self receiving raw IP protocol, v4 by target"
2688 if ! eval $NUMCOND; then :;
2689 elif ! feat=$(testaddrs ip4) || ! runsip4 >/dev/null; then
2690 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2691 numCANT=$((numCANT+1))
2692 elif ! feat=$(testaddrs rawip) >/dev/null; then
2693 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2694 numCANT=$((numCANT+1))
2695 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2696 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2697 numCANT=$((numCANT+1))
2698 else
2699 testecho "$N" "$TEST" "" "ip:127.0.0.1:$IPPROTO" "$opts"
2700 fi ;; # NUMCOND, feats
2701 esac
2702 N=$((N+1))
2704 NAME=RAWIP6SELF
2705 case "$TESTS" in
2706 *%$N%*|*%functions%*|*%ip6%*|*%rawip%*|*%root%*|*%$NAME%*)
2707 TEST="$NAME: simple echo via self receiving raw IPv6 protocol"
2708 if ! eval $NUMCOND; then :;
2709 elif ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null; then
2710 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2711 numCANT=$((numCANT+1))
2712 elif ! feat=$(testaddrs rawip) || ! runsip6 >/dev/null; then
2713 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2714 numCANT=$((numCANT+1))
2715 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2716 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2717 numCANT=$((numCANT+1))
2718 else
2719 testecho "$N" "$TEST" "" "ip6:[::1]:$IPPROTO" "$opts"
2720 fi ;; # NUMCOND, feats
2721 esac
2722 N=$((N+1))
2724 NAME=RAWIPX6SELF
2725 case "$TESTS" in
2726 *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%root%*|*%$NAME%*)
2727 TEST="$NAME: simple echo via self receiving raw IP protocol, v6 by target"
2728 if ! eval $NUMCOND; then :;
2729 elif ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null; then
2730 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2731 numCANT=$((numCANT+1))
2732 elif ! feat=$(testaddrs rawip) || ! runsip6 >/dev/null; then
2733 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2734 numCANT=$((numCANT+1))
2735 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2736 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2737 numCANT=$((numCANT+1))
2738 else
2739 testecho "$N" "$TEST" "" "ip:[::1]:$IPPROTO" "$opts"
2741 esac
2742 N=$((N+1))
2745 NAME=TCPSELF
2746 case "$TESTS" in
2747 *%$N%*|*%functions%*|*%$NAME%*)
2748 TEST="$NAME: echo via self connection of TCP IPv4 socket"
2749 if ! eval $NUMCOND; then :;
2750 elif [ "$UNAME" != Linux ]; then
2751 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2752 numCANT=$((numCANT+1))
2753 else
2754 #ts="127.0.0.1:$tsl"
2755 testecho "$N" "$TEST" "" "tcp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR,reuseaddr" "$opts"
2757 esac
2758 PORT=$((PORT+1))
2759 N=$((N+1))
2762 NAME=UDPSELF
2763 if ! eval $NUMCOND; then :; else
2764 case "$TESTS" in
2765 *%$N%*|*%functions%*|*%$NAME%*)
2766 TEST="$NAME: echo via self connection of UDP IPv4 socket"
2767 if [ "$UNAME" != Linux ]; then
2768 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2769 numCANT=$((numCANT+1))
2770 else
2771 testecho "$N" "$TEST" "" "udp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR" "$opts"
2773 esac
2774 fi # NUMCOND
2775 PORT=$((PORT+1))
2776 N=$((N+1))
2779 NAME=UDP6SELF
2780 case "$TESTS" in
2781 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%$NAME%*)
2782 TEST="$NAME: echo via self connection of UDP IPv6 socket"
2783 if ! eval $NUMCOND; then :;
2784 elif [ "$UNAME" != Linux ]; then
2785 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
2786 numCANT=$((numCANT+1))
2787 elif ! testaddrs udp ip6 >/dev/null || ! runsip6 >/dev/null; then
2788 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
2789 numCANT=$((numCANT+1))
2790 else
2791 tf="$td/file$N"
2792 testecho "$N" "$TEST" "" "udp6:[::1]:$PORT,sp=$PORT,bind=[::1]" "$opts"
2794 esac
2795 PORT=$((PORT+1))
2796 N=$((N+1))
2799 NAME=DUALUDPSELF
2800 if ! eval $NUMCOND; then :; else
2801 case "$TESTS" in
2802 *%$N%*|*%functions%*|*%$NAME%*)
2803 TEST="$NAME: echo via two unidirectional UDP IPv4 sockets"
2804 tf="$td/file$N"
2805 p1=$PORT
2806 p2=$((PORT+1))
2807 testecho "$N" "$TEST" "" "udp:127.0.0.1:$p2,sp=$p1!!udp:127.0.0.1:$p1,sp=$p2" "$opts"
2808 esac
2809 fi # NUMCOND
2810 PORT=$((PORT+2))
2811 N=$((N+1))
2814 #function testdual {
2815 # local
2819 NAME=UNIXSTREAM
2820 if ! eval $NUMCOND; then :; else
2821 case "$TESTS" in
2822 *%$N%*|*%functions%*|*%unix%*|*%$NAME%*)
2823 TEST="$NAME: echo via connection to UNIX domain socket"
2824 tf="$td/test$N.stdout"
2825 te="$td/test$N.stderr"
2826 ts="$td/test$N.socket"
2827 tdiff="$td/test$N.diff"
2828 da="test$N $(date) $RANDOM"
2829 CMD1="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
2830 CMD2="$TRACE $SOCAT $opts -!!- UNIX-CONNECT:$ts"
2831 printf "test $F_n $TEST... " $N
2832 $CMD1 </dev/null >$tf 2>"${te}1" &
2833 bg=$! # background process id
2834 waitfile "$ts"
2835 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2836 rc2=$?
2837 if [ "$rc2" -ne 0 ]; then
2838 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2839 echo "$CMD1 &"
2840 echo "$CMD2"
2841 echo "rc=$rc2"
2842 cat "${te}1"
2843 cat "${te}2"
2844 numFAIL=$((numFAIL+1))
2845 listFAIL="$listFAIL $N"
2846 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2847 $PRINTF "$FAILED: diff:\n"
2848 cat "$tdiff"
2849 numFAIL=$((numFAIL+1))
2850 listFAIL="$listFAIL $N"
2851 else
2852 $PRINTF "$OK\n"
2853 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2854 numOK=$((numOK+1))
2856 kill $bg 2>/dev/null
2857 esac
2858 fi # NUMCOND
2859 N=$((N+1))
2862 NAME=TCP4
2863 if ! eval $NUMCOND; then :; else
2864 case "$TESTS" in
2865 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2866 TEST="$NAME: echo via connection to TCP V4 socket"
2867 tf="$td/test$N.stdout"
2868 te="$td/test$N.stderr"
2869 tdiff="$td/test$N.diff"
2870 tsl=$PORT
2871 ts="127.0.0.1:$tsl"
2872 da="test$N $(date) $RANDOM"
2873 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
2874 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
2875 printf "test $F_n $TEST... " $N
2876 $CMD1 >"$tf" 2>"${te}1" &
2877 pid1=$!
2878 waittcp4port $tsl 1
2879 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2880 if [ $? -ne 0 ]; then
2881 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2882 echo "$CMD1 &"
2883 cat "${te}1"
2884 echo "$CMD2"
2885 cat "${te}2"
2886 numFAIL=$((numFAIL+1))
2887 listFAIL="$listFAIL $N"
2888 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2889 $PRINTF "$FAILED\n"
2890 cat "$tdiff"
2891 numFAIL=$((numFAIL+1))
2892 listFAIL="$listFAIL $N"
2893 else
2894 $PRINTF "$OK\n"
2895 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2896 numOK=$((numOK+1))
2898 kill $pid1 2>/dev/null
2899 wait ;;
2900 esac
2901 PORT=$((PORT+1))
2902 fi # NUMCOND
2903 N=$((N+1))
2906 #et -xv
2907 NAME=TCP6
2908 case "$TESTS" in
2909 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2910 TEST="$NAME: echo via connection to TCP V6 socket"
2911 if ! eval $NUMCOND; then :;
2912 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
2913 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
2914 numCANT=$((numCANT+1))
2915 else
2916 tf="$td/test$N.stdout"
2917 te="$td/test$N.stderr"
2918 tdiff="$td/test$N.diff"
2919 tsl=$PORT
2920 ts="[::1]:$tsl"
2921 da="test$N $(date) $RANDOM"
2922 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,$REUSEADDR PIPE"
2923 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
2924 printf "test $F_n $TEST... " $N
2925 $CMD1 >"$tf" 2>"${te}1" &
2926 pid=$! # background process id
2927 waittcp6port $tsl 1
2928 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2929 if [ $? -ne 0 ]; then
2930 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2931 echo "$CMD1 &"
2932 echo "$CMD2"
2933 cat "$te"
2934 numFAIL=$((numFAIL+1))
2935 listFAIL="$listFAIL $N"
2936 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2937 $PRINTF "$FAILED: diff:\n"
2938 cat "$tdiff"
2939 numFAIL=$((numFAIL+1))
2940 listFAIL="$listFAIL $N"
2941 else
2942 $PRINTF "$OK\n"
2943 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2944 numOK=$((numOK+1))
2946 kill $pid 2>/dev/null
2948 esac
2949 PORT=$((PORT+1))
2950 N=$((N+1))
2951 #set +vx
2954 NAME=TCPX4
2955 case "$TESTS" in
2956 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2957 TEST="$NAME: echo via connection to TCP socket, v4 by target"
2958 if ! eval $NUMCOND; then :;
2959 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2960 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2961 numCANT=$((numCANT+1))
2962 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
2963 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2964 numCANT=$((numCANT+1))
2965 else
2966 tf="$td/test$N.stdout"
2967 te="$td/test$N.stderr"
2968 tdiff="$td/test$N.diff"
2969 tsl=$PORT
2970 ts="127.0.0.1:$tsl"
2971 da="test$N $(date) $RANDOM"
2972 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip4,$REUSEADDR PIPE"
2973 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
2974 printf "test $F_n $TEST... " $N
2975 $CMD1 >"$tf" 2>"${te}1" &
2976 pid=$! # background process id
2977 waittcp4port $tsl 1
2978 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2979 if [ $? -ne 0 ]; then
2980 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2981 echo "$CMD1 &"
2982 echo "$CMD2"
2983 cat "$te"
2984 numFAIL=$((numFAIL+1))
2985 listFAIL="$listFAIL $N"
2986 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2987 $PRINTF "$FAILED: diff:\n"
2988 cat "$tdiff"
2989 numFAIL=$((numFAIL+1))
2990 listFAIL="$listFAIL $N"
2991 else
2992 $PRINTF "$OK\n"
2993 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2994 numOK=$((numOK+1))
2996 kill $pid 2>/dev/null
2998 esac
2999 PORT=$((PORT+1))
3000 N=$((N+1))
3003 NAME=TCPX6
3004 case "$TESTS" in
3005 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3006 TEST="$NAME: echo via connection to TCP socket, v6 by target"
3007 if ! eval $NUMCOND; then :;
3008 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3009 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3010 numCANT=$((numCANT+1))
3011 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3012 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3013 numCANT=$((numCANT+1))
3014 else
3015 tf="$td/test$N.stdout"
3016 te="$td/test$N.stderr"
3017 tdiff="$td/test$N.diff"
3018 tsl=$PORT
3019 ts="[::1]:$tsl"
3020 da="test$N $(date) $RANDOM"
3021 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip6,$REUSEADDR PIPE"
3022 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
3023 printf "test $F_n $TEST... " $N
3024 $CMD1 >"$tf" 2>"${te}1" &
3025 pid=$! # background process id
3026 waittcp6port $tsl 1
3027 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3028 if [ $? -ne 0 ]; then
3029 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3030 echo "$CMD1 &"
3031 echo "$CMD2"
3032 cat "$te"
3033 numFAIL=$((numFAIL+1))
3034 listFAIL="$listFAIL $N"
3035 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3036 $PRINTF "$FAILED: diff:\n"
3037 cat "$tdiff"
3038 numFAIL=$((numFAIL+1))
3039 listFAIL="$listFAIL $N"
3040 else
3041 $PRINTF "$OK\n"
3042 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3043 numOK=$((numOK+1))
3045 kill $pid 2>/dev/null
3047 esac
3048 PORT=$((PORT+1))
3049 N=$((N+1))
3051 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
3052 # ipv6-v6only=0 shows this behaviour.
3053 NAME=IPV6ONLY0
3054 case "$TESTS" in
3055 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3056 TEST="$NAME: option ipv6-v6only=0 listens on IPv4"
3057 # create a listening TCP6 socket and try to connect to the port using TCP4
3058 if ! eval $NUMCOND; then :;
3059 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3060 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3061 numCANT=$((numCANT+1))
3062 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3063 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3064 numCANT=$((numCANT+1))
3065 elif ! feat=$(testoptions ipv6-v6only); then
3066 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3067 numCANT=$((numCANT+1))
3068 else
3069 tf="$td/test$N.stdout"
3070 te="$td/test$N.stderr"
3071 tdiff="$td/test$N.diff"
3072 tsl=$PORT
3073 ts="127.0.0.1:$tsl"
3074 da="test$N $(date) $RANDOM"
3075 CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$tsl,ipv6-v6only=0,$REUSEADDR PIPE"
3076 CMD2="$TRACE $SOCAT $opts STDIN!!STDOUT TCP4:$ts"
3077 printf "test $F_n $TEST... " $N
3078 $CMD1 >"$tf" 2>"${te}1" &
3079 pid=$! # background process id
3080 waittcp6port $tsl 1
3081 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3082 if [ $? -ne 0 ]; then
3083 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3084 echo "$CMD1 &"
3085 echo "$CMD2"
3086 cat "${te}1" "${te}2"
3087 numFAIL=$((numFAIL+1))
3088 listFAIL="$listFAIL $N"
3089 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3090 $PRINTF "$FAILED: diff:\n"
3091 cat "$tdiff"
3092 numFAIL=$((numFAIL+1))
3093 listFAIL="$listFAIL $N"
3094 else
3095 $PRINTF "$OK\n"
3096 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3097 numOK=$((numOK+1))
3099 kill $pid 2>/dev/null
3101 esac
3102 PORT=$((PORT+1))
3103 N=$((N+1))
3105 #set -vx
3106 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
3107 # ipv6-v6only=1 turns off this behaviour.
3108 NAME=IPV6ONLY1
3109 case "$TESTS" in
3110 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3111 TEST="$NAME: option ipv6-v6only=1 does not listen on IPv4"
3112 if ! eval $NUMCOND; then :;
3113 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3114 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3115 numCANT=$((numCANT+1))
3116 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3117 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3118 numCANT=$((numCANT+1))
3119 elif ! feat=$(testoptions ipv6-v6only); then
3120 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3121 numCANT=$((numCANT+1))
3122 else
3123 tf="$td/test$N.stdout"
3124 te="$td/test$N.stderr"
3125 tdiff="$td/test$N.diff"
3126 tsl=$PORT
3127 ts="127.0.0.1:$tsl"
3128 da="test$N $(date) $RANDOM"
3129 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,ipv6-v6only=1,$REUSEADDR PIPE"
3130 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3131 printf "test $F_n $TEST... " $N
3132 $CMD1 >"$tf" 2>"${te}1" &
3133 pid=$! # background process id
3134 waittcp6port $tsl 1
3135 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3136 if [ $? -eq 0 ]; then
3137 $PRINTF "$FAILED:\n"
3138 cat "${te}1" "${te}2"
3139 numFAIL=$((numFAIL+1))
3140 listFAIL="$listFAIL $N"
3141 elif echo "$da" |diff - "$tf" >"$tdiff"; then
3142 $PRINTF "$FAILED:\n"
3143 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3144 numFAIL=$((numFAIL+1))
3145 listFAIL="$listFAIL $N"
3146 else
3147 $PRINTF "$OK\n"
3148 numOK=$((numOK+1))
3150 kill $pid; wait
3151 wait
3153 esac
3154 PORT=$((PORT+1))
3155 N=$((N+1))
3156 #set +vx
3158 NAME=ENV_LISTEN_4
3159 case "$TESTS" in
3160 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3161 TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv4 preference on listen"
3162 if ! eval $NUMCOND; then :;
3163 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3164 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3165 numCANT=$((numCANT+1))
3166 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3167 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3168 numCANT=$((numCANT+1))
3169 elif ! feat=$(testoptions ipv6-v6only); then
3170 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3171 numCANT=$((numCANT+1))
3172 else
3173 tf="$td/test$N.stdout"
3174 te="$td/test$N.stderr"
3175 tdiff="$td/test$N.diff"
3176 tsl=$PORT
3177 ts="127.0.0.1:$tsl"
3178 da="test$N $(date) $RANDOM"
3179 CMD1="$TRACE $SOCAT $opts TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3180 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3181 printf "test $F_n $TEST... " $N
3182 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3183 pid=$! # background process id
3184 waittcp4port $tsl 1
3185 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3186 if [ $? -ne 0 ]; then
3187 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3188 echo "$CMD1 &"
3189 echo "$CMD2"
3190 cat "${te}1" "${te}2"
3191 numFAIL=$((numFAIL+1))
3192 listFAIL="$listFAIL $N"
3193 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3194 $PRINTF "$FAILED: diff:\n"
3195 cat "$tdiff"
3196 numFAIL=$((numFAIL+1))
3197 listFAIL="$listFAIL $N"
3198 else
3199 $PRINTF "$OK\n"
3200 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3201 numOK=$((numOK+1))
3203 kill $pid 2>/dev/null; wait
3205 esac
3206 PORT=$((PORT+1))
3207 N=$((N+1))
3209 NAME=ENV_LISTEN_6
3210 case "$TESTS" in
3211 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3212 TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv6 preference on listen"
3213 if ! eval $NUMCOND; then :;
3214 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3215 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3216 numCANT=$((numCANT+1))
3217 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3218 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3219 numCANT=$((numCANT+1))
3220 else
3221 tf="$td/test$N.stdout"
3222 te="$td/test$N.stderr"
3223 tdiff="$td/test$N.diff"
3224 tsl=$PORT
3225 ts="[::1]:$tsl"
3226 da="test$N $(date) $RANDOM"
3227 CMD1="$TRACE $SOCAT $opts TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3228 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3229 printf "test $F_n $TEST... " $N
3230 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3231 pid=$! # background process id
3232 waittcp6port $tsl 1
3233 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3234 if [ $? -ne 0 ]; then
3235 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3236 echo "$CMD1 &"
3237 echo "$CMD2"
3238 cat "${te}1" "${te}2"
3239 numFAIL=$((numFAIL+1))
3240 listFAIL="$listFAIL $N"
3241 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3242 $PRINTF "$FAILED: diff:\n"
3243 cat "$tdiff"
3244 numFAIL=$((numFAIL+1))
3245 listFAIL="$listFAIL $N"
3246 else
3247 $PRINTF "$OK\n"
3248 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3249 numOK=$((numOK+1))
3251 kill $pid 2>/dev/null; wait
3253 esac
3254 PORT=$((PORT+1))
3255 N=$((N+1))
3257 NAME=LISTEN_OPTION_4
3258 case "$TESTS" in
3259 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3260 TEST="$NAME: option -4 for IPv4 preference on listen"
3261 if ! eval $NUMCOND; then :;
3262 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3263 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3264 numCANT=$((numCANT+1))
3265 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3266 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3267 numCANT=$((numCANT+1))
3268 elif ! feat=$(testoptions ipv6-v6only); then
3269 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3270 numCANT=$((numCANT+1))
3271 else
3272 tf="$td/test$N.stdout"
3273 te="$td/test$N.stderr"
3274 tdiff="$td/test$N.diff"
3275 tsl=$PORT
3276 ts="127.0.0.1:$tsl"
3277 da="test$N $(date) $RANDOM"
3278 CMD1="$TRACE $SOCAT $opts -4 TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3279 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3280 printf "test $F_n $TEST... " $N
3281 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3282 pid=$! # background process id
3283 waittcp4port $tsl 1
3284 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3285 if [ $? -ne 0 ]; then
3286 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3287 echo "$CMD1 &"
3288 echo "$CMD2"
3289 cat "${te}1" "${te}2"
3290 numFAIL=$((numFAIL+1))
3291 listFAIL="$listFAIL $N"
3292 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3293 $PRINTF "$FAILED: diff:\n"
3294 cat "$tdiff"
3295 numFAIL=$((numFAIL+1))
3296 listFAIL="$listFAIL $N"
3297 else
3298 $PRINTF "$OK\n"
3299 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3300 numOK=$((numOK+1))
3302 kill $pid 2>/dev/null; wait
3304 esac
3305 PORT=$((PORT+1))
3306 N=$((N+1))
3308 NAME=LISTEN_OPTION_6
3309 case "$TESTS" in
3310 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3311 TEST="$NAME: option -6 for IPv6 preference on listen"
3312 if ! eval $NUMCOND; then :;
3313 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3314 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3315 numCANT=$((numCANT+1))
3316 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3317 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3318 numCANT=$((numCANT+1))
3319 else
3320 tf="$td/test$N.stdout"
3321 te="$td/test$N.stderr"
3322 tdiff="$td/test$N.diff"
3323 tsl=$PORT
3324 ts="[::1]:$tsl"
3325 da="test$N $(date) $RANDOM"
3326 CMD1="$TRACE $SOCAT $opts -6 TCP-listen:$tsl,$REUSEADDR PIPE"
3327 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3328 printf "test $F_n $TEST... " $N
3329 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3330 pid=$! # background process id
3331 waittcp6port $tsl 1
3332 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3333 if [ $? -ne 0 ]; then
3334 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3335 echo "$CMD1 &"
3336 echo "$CMD2"
3337 cat "${te}1" "${te}2"
3338 numFAIL=$((numFAIL+1))
3339 listFAIL="$listFAIL $N"
3340 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3341 $PRINTF "$FAILED: diff:\n"
3342 cat "$tdiff"
3343 numFAIL=$((numFAIL+1))
3344 listFAIL="$listFAIL $N"
3345 else
3346 $PRINTF "$OK\n"
3347 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3348 numOK=$((numOK+1))
3350 kill $pid 2>/dev/null; wait
3351 wait
3352 fi # feats
3353 esac
3354 PORT=$((PORT+1))
3355 N=$((N+1))
3357 NAME=LISTEN_PF_IP4
3358 case "$TESTS" in
3359 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3360 TEST="$NAME: pf=4 overrides option -6 on listen"
3361 if ! eval $NUMCOND; then :;
3362 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3363 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3364 numCANT=$((numCANT+1))
3365 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3366 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3367 numCANT=$((numCANT+1))
3368 elif ! feat=$(testoptions ipv6-v6only); then
3369 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3370 numCANT=$((numCANT+1))
3371 else
3372 tf="$td/test$N.stdout"
3373 te="$td/test$N.stderr"
3374 tdiff="$td/test$N.diff"
3375 tsl=$PORT
3376 ts="127.0.0.1:$tsl"
3377 da="test$N $(date) $RANDOM"
3378 CMD1="$TRACE $SOCAT $opts -6 TCP-LISTEN:$tsl,pf=ip4,$REUSEADDR PIPE"
3379 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3380 printf "test $F_n $TEST... " $N
3381 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3382 pid=$! # background process id
3383 waittcp4port $tsl 1
3384 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3385 if [ $? -ne 0 ]; then
3386 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3387 echo "$CMD1 &"
3388 echo "$CMD2"
3389 cat "${te}1" "${te}2"
3390 numFAIL=$((numFAIL+1))
3391 listFAIL="$listFAIL $N"
3392 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3393 $PRINTF "$FAILED: diff:\n"
3394 cat "$tdiff"
3395 numFAIL=$((numFAIL+1))
3396 listFAIL="$listFAIL $N"
3397 else
3398 $PRINTF "$OK\n"
3399 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3400 numOK=$((numOK+1))
3402 kill $pid 2>/dev/null; wait
3404 esac
3405 PORT=$((PORT+1))
3406 N=$((N+1))
3408 NAME=LISTEN_PF_IP6
3409 case "$TESTS" in
3410 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3411 TEST="$NAME: pf=6 overrides option -4 on listen"
3412 if ! eval $NUMCOND; then :;
3413 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3414 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3415 numCANT=$((numCANT+1))
3416 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3417 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3418 numCANT=$((numCANT+1))
3419 else
3420 tf="$td/test$N.stdout"
3421 te="$td/test$N.stderr"
3422 tdiff="$td/test$N.diff"
3423 tsl=$PORT
3424 ts="[::1]:$tsl"
3425 da="test$N $(date) $RANDOM"
3426 CMD1="$TRACE $SOCAT $opts -4 TCP-LISTEN:$tsl,pf=ip6,$REUSEADDR PIPE"
3427 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3428 printf "test $F_n $TEST... " $N
3429 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3430 pid=$! # background process id
3431 waittcp6port $tsl 1
3432 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3433 if [ $? -ne 0 ]; then
3434 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3435 echo "$CMD1 &"
3436 echo "$CMD2"
3437 cat "${te}1" "${te}2"
3438 numFAIL=$((numFAIL+1))
3439 listFAIL="$listFAIL $N"
3440 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3441 $PRINTF "$FAILED: diff:\n"
3442 cat "$tdiff"
3443 numFAIL=$((numFAIL+1))
3444 listFAIL="$listFAIL $N"
3445 else
3446 $PRINTF "$OK\n"
3447 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3448 numOK=$((numOK+1))
3450 kill $pid 2>/dev/null; wait
3451 fi ;; # NUMCOND, feats
3452 esac
3453 PORT=$((PORT+1))
3454 N=$((N+1))
3457 NAME=UDP4STREAM
3458 case "$TESTS" in
3459 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%$NAME%*)
3460 TEST="$NAME: echo via connection to UDP V4 socket"
3461 if ! eval $NUMCOND; then :; else
3462 tf="$td/test$N.stdout"
3463 te="$td/test$N.stderr"
3464 tdiff="$td/test$N.diff"
3465 tsl=$PORT
3466 ts="$LOCALHOST:$tsl"
3467 da="test$N $(date) $RANDOM"
3468 CMD1="$TRACE $SOCAT $opts UDP4-LISTEN:$tsl,$REUSEADDR PIPE"
3469 CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
3470 printf "test $F_n $TEST... " $N
3471 $CMD1 >"$tf" 2>"${te}1" &
3472 pid1=$!
3473 waitudp4port $tsl 1
3474 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3475 rc2=$?
3476 kill $pid1 2>/dev/null; wait
3477 if [ $rc2 -ne 0 ]; then
3478 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3479 echo "$CMD1 &"
3480 echo "$CMD2"
3481 cat "${te}1" "${te}2"
3482 numFAIL=$((numFAIL+1))
3483 listFAIL="$listFAIL $N"
3484 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3485 $PRINTF "$FAILED\n"
3486 echo "$CMD1 &"
3487 cat "${te}1"
3488 echo "$CMD2"
3489 cat "${te}2"
3490 cat "$tdiff"
3491 numFAIL=$((numFAIL+1))
3492 listFAIL="$listFAIL $N"
3493 else
3494 $PRINTF "$OK\n"
3495 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3496 numOK=$((numOK+1))
3498 fi ;; # NUMCOND
3499 esac
3500 PORT=$((PORT+1))
3501 N=$((N+1))
3504 NAME=UDP6STREAM
3505 case "$TESTS" in
3506 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%udp%*|*%$NAME%*)
3507 TEST="$NAME: echo via connection to UDP V6 socket"
3508 if ! eval $NUMCOND; then :;
3509 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
3510 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
3511 numCANT=$((numCANT+1))
3512 else
3513 tf="$td/test$N.stdout"
3514 te="$td/test$N.stderr"
3515 tdiff="$td/test$N.diff"
3516 tsl=$PORT
3517 ts="$LOCALHOST6:$tsl"
3518 da="test$N $(date) $RANDOM"
3519 CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,$REUSEADDR PIPE"
3520 CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
3521 printf "test $F_n $TEST... " $N
3522 $CMD1 >"$tf" 2>"${te}1" &
3523 pid1=$!
3524 waitudp6port $tsl 1
3525 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3526 rc2=$?
3527 kill $pid1 2>/dev/null; wait
3528 if [ $rc2 -ne 0 ]; then
3529 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3530 echo "$CMD1 &"
3531 echo "$CMD2"
3532 cat "${te}1" "${te}2"
3533 numFAIL=$((numFAIL+1))
3534 listFAIL="$listFAIL $N"
3535 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3536 $PRINTF "$FAILED\n"
3537 cat "$tdiff"
3538 numFAIL=$((numFAIL+1))
3539 listFAIL="$listFAIL $N"
3540 else
3541 $PRINTF "$OK\n"
3542 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3543 numOK=$((numOK+1))
3545 fi ;; # ! testaddrs
3546 esac
3547 PORT=$((PORT+1))
3548 N=$((N+1))
3551 NAME=GOPENFILE
3552 case "$TESTS" in
3553 *%$N%*|*%functions%*|*%engine%*|*%gopen%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
3554 TEST="$NAME: file opening with gopen"
3555 if ! eval $NUMCOND; then :; else
3556 tf1="$td/test$N.1.stdout"
3557 tf2="$td/test$N.2.stdout"
3558 te="$td/test$N.stderr"
3559 tdiff="$td/test$N.diff"
3560 da="test$N $(date) $RANDOM"
3561 echo "$da" >$tf1
3562 CMD="$TRACE $SOCAT $opts $tf1!!/dev/null /dev/null,ignoreeof!!-"
3563 printf "test $F_n $TEST... " $N
3564 $CMD >"$tf2" 2>"$te"
3565 if [ $? -ne 0 ]; then
3566 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3567 echo "$CMD"
3568 cat "$te"
3569 numFAIL=$((numFAIL+1))
3570 listFAIL="$listFAIL $N"
3571 elif ! diff "$tf1" "$tf2" >"$tdiff"; then
3572 $PRINTF "$FAILED: diff:\n"
3573 cat "$tdiff"
3574 numFAIL=$((numFAIL+1))
3575 listFAIL="$listFAIL $N"
3576 else
3577 $PRINTF "$OK\n"
3578 if [ -n "$debug" ]; then cat $te; fi
3579 numOK=$((numOK+1))
3581 fi # NUMCOND
3582 esac
3583 N=$((N+1))
3586 NAME=GOPENPIPE
3587 case "$TESTS" in
3588 *%$N%*|*%functions%*|*%gopen%*|*%pipe%*|*%ignoreeof%*|*%$NAME%*)
3589 TEST="$NAME: pipe opening with gopen for reading"
3590 if ! eval $NUMCOND; then :; else
3591 tp="$td/pipe$N"
3592 tf="$td/test$N.stdout"
3593 te="$td/test$N.stderr"
3594 tdiff="$td/test$N.diff"
3595 da="test$N $(date) $RANDOM"
3596 CMD="$TRACE $SOCAT $opts $tp!!/dev/null /dev/null,ignoreeof!!$tf"
3597 printf "test $F_n $TEST... " $N
3598 #mknod $tp p # no mknod p on FreeBSD
3599 mkfifo $tp
3600 $CMD >$tf 2>"$te" &
3601 #($CMD >$tf 2>"$te" || rm -f "$tp") 2>/dev/null &
3602 bg=$! # background process id
3603 usleep $MICROS
3604 if [ ! -p "$tp" ]; then
3605 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3606 echo "$CMD"
3607 cat "$te"
3608 numFAIL=$((numFAIL+1))
3609 listFAIL="$listFAIL $N"
3610 else
3611 #echo "$da" >"$tp" # might hang forever
3612 echo "$da" >"$tp" & export pid=$!; (sleep 1; kill $pid 2>/dev/null) &
3613 # Solaris needs more time:
3614 sleep 1
3615 kill "$bg" 2>/dev/null; wait
3616 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3617 if [ -s "$te" ]; then
3618 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3619 echo "$CMD"
3620 cat "$te"
3621 else
3622 $PRINTF "$FAILED: diff:\n"
3623 cat "$tdiff"
3625 numFAIL=$((numFAIL+1))
3626 listFAIL="$listFAIL $N"
3627 else
3628 $PRINTF "$OK\n"
3629 if [ -n "$debug" ]; then cat $te; fi
3630 numOK=$((numOK+1))
3633 wait
3634 fi # NUMCOND
3635 esac
3636 N=$((N+1))
3639 NAME=GOPENUNIXSTREAM
3640 case "$TESTS" in
3641 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%listen%*|*%$NAME%*)
3642 TEST="$NAME: GOPEN on UNIX stream socket"
3643 if ! eval $NUMCOND; then :; else
3644 ts="$td/test$N.socket"
3645 tf="$td/test$N.stdout"
3646 te="$td/test$N.stderr"
3647 tdiff="$td/test$N.diff"
3648 da1="test$N $(date) $RANDOM"
3649 #establish a listening unix socket in background
3650 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
3651 #make a connection
3652 CMD="$TRACE $SOCAT $opts - $ts"
3653 $PRINTF "test $F_n $TEST... " $N
3654 eval "$SRV 2>${te}s &"
3655 pids=$!
3656 waitfile "$ts"
3657 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
3658 if [ $? -ne 0 ]; then
3659 kill "$pids" 2>/dev/null
3660 $PRINTF "$FAILED:\n"
3661 echo "$SRV &"
3662 cat "${te}s"
3663 echo "$CMD"
3664 cat "${te}1"
3665 numFAIL=$((numFAIL+1))
3666 listFAIL="$listFAIL $N"
3667 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
3668 kill "$pids" 2>/dev/null
3669 $PRINTF "$FAILED:\n"
3670 echo "$SRV &"
3671 cat "${te}s"
3672 echo "$CMD"
3673 cat "${te}1"
3674 cat "$tdiff"
3675 numFAIL=$((numFAIL+1))
3676 listFAIL="$listFAIL $N"
3677 else
3678 $PRINTF "$OK\n"
3679 if [ -n "$debug" ]; then cat $te; fi
3680 numOK=$((numOK+1))
3681 fi # !(rc -ne 0)
3682 wait
3683 fi # NUMCOND
3684 esac
3685 N=$((N+1))
3688 NAME=GOPENUNIXDGRAM
3689 case "$TESTS" in
3690 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%dgram%*|*%$NAME%*)
3691 TEST="$NAME: GOPEN on UNIX datagram socket"
3692 if ! eval $NUMCOND; then :; else
3693 ts="$td/test$N.socket"
3694 tf="$td/test$N.stdout"
3695 te="$td/test$N.stderr"
3696 tdiff="$td/test$N.diff"
3697 da1="test$N $(date) $RANDOM"
3698 #establish a receiving unix socket in background
3699 SRV="$TRACE $SOCAT $opts -u -lpserver UNIX-RECV:\"$ts\" file:\"$tf\",create"
3700 #make a connection
3701 CMD="$TRACE $SOCAT $opts -u - $ts"
3702 $PRINTF "test $F_n $TEST... " $N
3703 eval "$SRV 2>${te}s &"
3704 pids=$!
3705 waitfile "$ts"
3706 echo "$da1" |eval "$CMD" 2>"${te}1"
3707 waitfile -s "$tf"
3708 if [ $? -ne 0 ]; then
3709 $PRINTF "$FAILED:\n"
3710 echo "$SRV &"
3711 cat "${te}s"
3712 echo "$CMD"
3713 cat "${te}1"
3714 numFAIL=$((numFAIL+1))
3715 listFAIL="$listFAIL $N"
3716 elif ! echo "$da1" |diff - "${tf}" >"$tdiff"; then
3717 $PRINTF "$FAILED:\n"
3718 echo "$SRV &"
3719 cat "${te}s"
3720 echo "$CMD"
3721 cat "${te}1"
3722 cat "$tdiff"
3723 numFAIL=$((numFAIL+1))
3724 listFAIL="$listFAIL $N"
3725 else
3726 $PRINTF "$OK\n"
3727 if [ -n "$debug" ]; then cat $te; fi
3728 numOK=$((numOK+1))
3729 fi # !(rc -ne 0)
3730 kill "$pids" 2>/dev/null; wait
3731 fi ;; # NUMCOND
3732 esac
3733 N=$((N+1))
3736 NAME=IGNOREEOF
3737 case "$TESTS" in
3738 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3739 TEST="$NAME: ignoreeof on file"
3740 if ! eval $NUMCOND; then :; else
3741 ti="$td/test$N.file"
3742 tf="$td/test$N.stdout"
3743 te="$td/test$N.stderr"
3744 tdiff="$td/test$N.diff"
3745 da="test$N $(date) $RANDOM"
3746 CMD="$TRACE $SOCAT $opts -u file:\"$ti\",ignoreeof -"
3747 printf "test $F_n $TEST... " $N
3748 touch "$ti"
3749 $CMD >"$tf" 2>"$te" &
3750 bg=$!
3751 usleep 500000
3752 echo "$da" >>"$ti"
3753 sleep 1
3754 kill $bg 2>/dev/null; wait
3755 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3756 $PRINTF "$FAILED: diff:\n"
3757 cat "$tdiff"
3758 listFAIL="$listFAIL $N"
3759 numFAIL=$((numFAIL+1))
3760 else
3761 $PRINTF "$OK\n"
3762 if [ -n "$debug" ]; then cat $te; fi
3763 numOK=$((numOK+1))
3765 fi ;; # NUMCOND
3766 esac
3767 N=$((N+1))
3769 NAME=IGNOREEOF_REV
3770 case "$TESTS" in
3771 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3772 TEST="$NAME: ignoreeof on file right-to-left"
3773 if ! eval $NUMCOND; then :; else
3774 ti="$td/test$N.file"
3775 tf="$td/test$N.stdout"
3776 te="$td/test$N.stderr"
3777 tdiff="$td/test$N.diff"
3778 da="test$N $(date) $RANDOM"
3779 CMD="$SOCAT $opts -U - file:\"$ti\",ignoreeof"
3780 printf "test $F_n $TEST... " $N
3781 touch "$ti"
3782 $CMD >"$tf" 2>"$te" &
3783 bg=$!
3784 usleep 500000
3785 echo "$da" >>"$ti"
3786 sleep 1
3787 kill $bg 2>/dev/null
3788 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3789 $PRINTF "$FAILED: diff:\n"
3790 cat "$tdiff"
3791 listFAIL="$listFAIL $N"
3792 numFAIL=$((numFAIL+1))
3793 else
3794 $PRINTF "$OK\n"
3795 if [ -n "$debug" ]; then cat $te; fi
3796 numOK=$((numOK+1))
3798 wait
3799 fi ;; # NUMCOND
3800 esac
3801 N=$((N+1))
3804 NAME=EXECIGNOREEOF
3805 case "$TESTS" in
3806 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3807 TEST="$NAME: exec against address with ignoreeof"
3808 if ! eval $NUMCOND; then :; else
3809 tf="$td/test$N.stdout"
3810 te="$td/test$N.stderr"
3811 CMD="$TRACE $SOCAT $opts -lf /dev/null EXEC:$TRUE /dev/null,ignoreeof"
3812 printf "test $F_n $TEST... " $N
3813 $CMD >"$tf" 2>"$te"
3814 if [ -s "$te" ]; then
3815 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3816 echo "$CMD"
3817 cat "$te"
3818 numFAIL=$((numFAIL+1))
3819 listFAIL="$listFAIL $N"
3820 else
3821 $PRINTF "$OK\n"
3822 if [ -n "$debug" ]; then cat $te; fi
3823 numOK=$((numOK+1))
3825 fi ;; # NUMCOND
3826 esac
3827 N=$((N+1))
3830 NAME=FAKEPTY
3831 case "$TESTS" in
3832 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
3833 TEST="$NAME: generation of pty for other processes"
3834 if ! eval $NUMCOND; then :;
3835 elif ! testaddrs pty >/dev/null; then
3836 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
3837 numCANT=$((numCANT+1))
3838 else
3839 tt="$td/pty$N"
3840 tf="$td/test$N.stdout"
3841 te="$td/test$N.stderr"
3842 tdiff="$td/test$N.diff"
3843 da="test$N $(date) $RANDOM"
3844 CMD1="$TRACE $SOCAT $opts pty,link=$tt pipe"
3845 CMD2="$TRACE $SOCAT $opts - $tt,$PTYOPTS2"
3846 printf "test $F_n $TEST... " $N
3847 $CMD1 2>"${te}1" &
3848 pid=$! # background process id
3849 waitfile "$tt"
3850 # this hangs on HP-UX, so we use a timeout
3851 (echo "$da"; sleep 1) |$CMD2 >$tf 2>"${te}2" &
3852 rc2=$!
3853 #sleep 5 && kill $rc2 2>/dev/null &
3854 wait $rc2
3855 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3856 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3857 echo "$CMD1 &"
3858 sleep 1
3859 echo "$CMD2"
3860 cat "${te}1"
3861 cat "${te}2"
3862 cat "$tdiff"
3863 numFAIL=$((numFAIL+1))
3864 listFAIL="$listFAIL $N"
3865 else
3866 $PRINTF "$OK\n"
3867 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3868 numOK=$((numOK+1))
3870 kill $pid 2>/dev/null; wait
3871 fi ;; # NUMCOND, feats
3872 esac
3873 N=$((N+1))
3876 NAME=O_TRUNC
3877 case "$TESTS" in
3878 *%$N%*|*%functions%*|*%$NAME%*)
3879 TEST="$NAME: option o-trunc"
3880 if ! eval $NUMCOND; then :; else
3881 ff="$td/test$N.file"
3882 tf="$td/test$N.stdout"
3883 te="$td/test$N.stderr"
3884 tdiff="$td/test$N.diff"
3885 da="test$N $(date) $RANDOM"
3886 CMD="$TRACE $SOCAT -u $opts - open:$ff,append,o-trunc"
3887 printf "test $F_n $TEST... " $N
3888 rm -f $ff; $ECHO "prefix-\c" >$ff
3889 echo "$da" |$CMD >$tf 2>"$te"
3890 rc0=$?
3891 if ! [ $rc0 = 0 ] ||
3892 ! echo "$da" |diff - $ff >"$tdiff"; then
3893 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3894 echo "$CMD"
3895 cat "$te"
3896 cat "$tdiff"
3897 numFAIL=$((numFAIL+1))
3898 listFAIL="$listFAIL $N"
3899 else
3900 $PRINTF "$OK\n"
3901 if [ -n "$debug" ]; then cat $te; fi
3902 numOK=$((numOK+1))
3904 fi ;; # NUMCOND
3905 esac
3906 N=$((N+1))
3909 NAME=FTRUNCATE
3910 case "$TESTS" in
3911 *%$N%*|*%functions%*|*%$NAME%*)
3912 TEST="$NAME: option ftruncate"
3913 if ! eval $NUMCOND; then :; else
3914 ff="$td/test$N.file"
3915 tf="$td/test$N.stdout"
3916 te="$td/test$N.stderr"
3917 tdiff="$td/test$N.diff"
3918 da="test$N $(date) $RANDOM"
3919 CMD="$TRACE $SOCAT -u $opts - open:$ff,append,ftruncate=0"
3920 printf "test $F_n $TEST... " $N
3921 rm -f $ff; $ECHO "prefix-\c" >$ff
3922 if ! echo "$da" |$CMD >$tf 2>"$te" ||
3923 ! echo "$da" |diff - $ff >"$tdiff"; then
3924 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3925 echo "$CMD"
3926 cat "$te"
3927 cat "$tdiff"
3928 numFAIL=$((numFAIL+1))
3929 listFAIL="$listFAIL $N"
3930 else
3931 $PRINTF "$OK\n"
3932 if [ -n "$debug" ]; then cat $te; fi
3933 numOK=$((numOK+1))
3935 fi ;; # NUMCOND
3936 esac
3937 N=$((N+1))
3940 NAME=RIGHTTOLEFT
3941 case "$TESTS" in
3942 *%$N%*|*%functions%*|*%$NAME%*)
3943 TEST="$NAME: unidirectional throughput from stdin to stdout, right to left"
3944 testecho "$N" "$TEST" "stdout" "stdin" "$opts -U"
3945 esac
3946 N=$((N+1))
3949 NAME=CHILDDEFAULT
3950 case "$TESTS" in
3951 *%$N%*|*%functions%*|*%$NAME%*)
3952 if ! eval $NUMCOND; then :; else
3953 TEST="$NAME: child process default properties"
3954 tf="$td/test$N.stdout"
3955 te="$td/test$N.stderr"
3956 CMD="$TRACE $SOCAT $opts -u exec:$PROCAN -"
3957 printf "test $F_n $TEST... " $N
3958 $CMD >$tf 2>$te
3959 MYPID=`expr "\`grep "process id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3960 MYPPID=`expr "\`grep "process parent id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3961 MYPGID=`expr "\`grep "process group id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3962 MYSID=`expr "\`grep "process session id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3963 #echo "PID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3964 if [ "$MYPID" = "$MYPPID" -o "$MYPID" = "$MYPGID" -o "$MYPID" = "$MYSID" -o \
3965 "$MYPPID" = "$MYPGID" -o "$MYPPID" = "$MYSID" -o "$MYPGID" = "$MYSID" ];
3966 then
3967 $PRINTF "$FAILED:\n"
3968 echo "$CMD"
3969 cat "$te"
3970 numFAIL=$((numFAIL+1))
3971 listFAIL="$listFAIL $N"
3972 else
3973 $PRINTF "$OK\n"
3974 numOK=$((numOK+1))
3976 fi ;; # NUMCOND
3977 esac
3978 N=$((N+1))
3981 NAME=CHILDSETSID
3982 case "$TESTS" in
3983 *%$N%*|*%functions%*|*%$NAME%*)
3984 TEST="$NAME: child process with setsid"
3985 if ! eval $NUMCOND; then :; else
3986 tf="$td/test$N.stdout"
3987 te="$td/test$N.stderr"
3988 CMD="$TRACE $SOCAT $opts -u exec:$PROCAN,setsid -"
3989 printf "test $F_n $TEST... " $N
3990 $CMD >$tf 2>$te
3991 MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3992 MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3993 MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3994 MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3995 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3996 # PID, PGID, and SID must be the same
3997 if [ "$MYPID" = "$MYPPID" -o \
3998 "$MYPID" != "$MYPGID" -o "$MYPID" != "$MYSID" ];
3999 then
4000 $PRINTF "$FAILED\n"
4001 echo "$CMD"
4002 cat "$te"
4003 numFAIL=$((numFAIL+1))
4004 listFAIL="$listFAIL $N"
4005 else
4006 $PRINTF "$OK\n"
4007 numOK=$((numOK+1))
4009 fi ;; # NUMCOND
4010 esac
4011 N=$((N+1))
4014 NAME=MAINSETSID
4015 case "$TESTS" in
4016 *%$N%*|*%functions%*|*%$NAME%*)
4017 TEST="$NAME: main process with setsid"
4018 if ! eval $NUMCOND; then :; else
4019 tf="$td/test$N.stdout"
4020 te="$td/test$N.stderr"
4021 CMD="$TRACE $SOCAT $opts -U -,setsid exec:$PROCAN"
4022 printf "test $F_n $TEST... " $N
4023 $CMD >$tf 2>$te
4024 MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4025 MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4026 MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4027 MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
4028 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
4029 # PPID, PGID, and SID must be the same
4030 if [ "$MYPID" = "$MYPPID" -o \
4031 "$MYPPID" != "$MYPGID" -o "$MYPPID" != "$MYSID" ];
4032 then
4033 $PRINTF "$FAILED\n"
4034 echo "$CMD"
4035 cat "$te"
4036 numFAIL=$((numFAIL+1))
4037 listFAIL="$listFAIL $N"
4038 else
4039 $PRINTF "$OK\n"
4040 numOK=$((numOK+1))
4042 fi ;; # NUMCOND
4043 esac
4044 N=$((N+1))
4047 NAME=OPENSSL_TCP4
4048 case "$TESTS" in
4049 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4050 TEST="$NAME: openssl connect"
4051 if ! eval $NUMCOND; then :;
4052 elif ! testaddrs openssl >/dev/null; then
4053 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4054 numCANT=$((numCANT+1))
4055 elif ! type openssl >/dev/null 2>&1; then
4056 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
4057 numCANT=$((numCANT+1))
4058 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4059 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4060 numCANT=$((numCANT+1))
4061 else
4062 gentestcert testsrv
4063 tf="$td/test$N.stdout"
4064 te="$td/test$N.stderr"
4065 tdiff="$td/test$N.diff"
4066 da="test$N $(date) $RANDOM"
4067 CMD2="$TRACE $SOCAT $opts exec:'openssl s_server -accept "$PORT" -quiet -cert testsrv.pem' pipe"
4068 #! CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT"
4069 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
4070 printf "test $F_n $TEST... " $N
4071 eval "$CMD2 2>\"${te}1\" &"
4072 pid=$! # background process id
4073 # this might timeout when openssl opens tcp46 port like " :::$PORT"
4074 waittcp4port $PORT
4075 echo "$da" |$CMD >$tf 2>"${te}2"
4076 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4077 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4078 echo "$CMD2 &"
4079 echo "$CMD"
4080 cat "${te}1"
4081 cat "${te}2"
4082 cat "$tdiff"
4083 numFAIL=$((numFAIL+1))
4084 listFAIL="$listFAIL $N"
4085 else
4086 $PRINTF "$OK\n"
4087 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4088 numOK=$((numOK+1))
4090 kill $pid 2>/dev/null; wait
4091 fi ;; # NUMCOND, feats
4092 esac
4093 PORT=$((PORT+1))
4094 N=$((N+1))
4097 NAME=OPENSSLLISTEN_TCP4
4098 case "$TESTS" in
4099 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4100 TEST="$NAME: openssl listen"
4101 if ! eval $NUMCOND; then :;
4102 elif ! testaddrs openssl >/dev/null; then
4103 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4104 numCANT=$((numCANT+1))
4105 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4106 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4107 numCANT=$((numCANT+1))
4108 else
4109 gentestcert testsrv
4110 tf="$td/test$N.stdout"
4111 te="$td/test$N.stderr"
4112 tdiff="$td/test$N.diff"
4113 da="test$N $(date) $RANDOM"
4114 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4115 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
4116 printf "test $F_n $TEST... " $N
4117 eval "$CMD2 2>\"${te}1\" &"
4118 pid=$! # background process id
4119 waittcp4port $PORT
4120 echo "$da" |$CMD >$tf 2>"${te}2"
4121 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4122 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4123 echo "$CMD2 &"
4124 echo "$CMD"
4125 cat "${te}1"
4126 cat "${te}2"
4127 cat "$tdiff"
4128 numFAIL=$((numFAIL+1))
4129 listFAIL="$listFAIL $N"
4130 else
4131 $PRINTF "$OK\n"
4132 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4133 numOK=$((numOK+1))
4135 kill $pid 2>/dev/null
4136 wait
4137 fi ;; # NUMCOND, feats
4138 esac
4139 PORT=$((PORT+1))
4140 N=$((N+1))
4142 NAME=OPENSSLLISTEN_TCP6
4143 case "$TESTS" in
4144 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4145 TEST="$NAME: openssl listen"
4146 if ! eval $NUMCOND; then :;
4147 elif ! testaddrs openssl >/dev/null; then
4148 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4149 numCANT=$((numCANT+1))
4150 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4151 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4152 numCANT=$((numCANT+1))
4153 else
4154 gentestcert testsrv
4155 tf="$td/test$N.stdout"
4156 te="$td/test$N.stderr"
4157 tdiff="$td/test$N.diff"
4158 da="test$N $(date) $RANDOM"
4159 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4160 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST6:$PORT,verify=0,$SOCAT_EGD"
4161 printf "test $F_n $TEST... " $N
4162 eval "$CMD2 2>\"${te}1\" &"
4163 pid=$! # background process id
4164 waittcp6port $PORT
4165 echo "$da" |$CMD >$tf 2>"${te}2"
4166 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4167 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4168 echo "$CMD2 &"
4169 echo "$CMD"
4170 cat "${te}1"
4171 cat "${te}2"
4172 cat "$tdiff"
4173 numFAIL=$((numFAIL+1))
4174 listFAIL="$listFAIL $N"
4175 else
4176 $PRINTF "$OK\n"
4177 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4178 numOK=$((numOK+1))
4180 kill $pid 2>/dev/null
4181 wait
4182 fi ;; # NUMCOND, feats
4183 esac
4184 PORT=$((PORT+1))
4185 N=$((N+1))
4188 while read NAMEKEYW FEAT RUNS TESTTMPL PEERTMPL WAITTMPL; do
4189 if [ -z "$NAMEKEYW" ] || [[ "$NAMEKEYW" == \#* ]]; then continue; fi
4191 export ts="$td/test$N.socket"
4192 WAITTMPL="$(echo "$WAITTMPL" |sed -e 's/\040/ /g')"
4193 TESTADDR=$(eval echo $TESTTMPL)
4194 PEERADDR=$(eval echo $PEERTMPL)
4195 WAITCMD=$(eval echo $WAITTMPL)
4196 TESTKEYW=${TESTADDR%%:*}
4198 # does our address implementation support halfclose?
4199 NAME=${NAMEKEYW}_HALFCLOSE
4200 case "$TESTS" in
4201 *%$N%*|*%functions%*|*%$FEAT%*|*%socket%*|*%halfclose%*|*%$NAME%*)
4202 TEST="$NAME: $TESTKEYW half close"
4203 # have a "peer" socat "peer" that executes "$OD_C" and see if EOF on the
4204 # connecting socat brings the result of od
4205 if ! eval $NUMCOND; then :;
4206 elif [ "$FEAT" != ',' ] && ! testaddrs "$FEAT" >/dev/null; then
4207 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
4208 numCANT=$((numCANT+1))
4209 elif ! runs$RUNS; then
4210 $PRINTF "test $F_n $TEST... ${YELLOW}$RUNS not available${NORMAL}\n" $N
4211 numCANT=$((numCANT+1))
4212 else
4213 tf="$td/test$N.stdout"
4214 te="$td/test$N.stderr"
4215 tdiff="$td/test$N.diff"
4216 da="test$N $(date) $RANDOM"
4217 CMD2="$TRACE $SOCAT $opts \"$PEERADDR\" EXEC:'$OD_C'"
4218 CMD="$TRACE $SOCAT -T1 $opts - $TESTADDR"
4219 printf "test $F_n $TEST... " $N
4220 eval "$CMD2 2>\"${te}1\" &"
4221 pid=$! # background process id
4222 $WAITCMD
4223 echo "$da" |$CMD >$tf 2>"${te}2"
4224 if ! echo "$da" |$OD_C |diff - "$tf" >"$tdiff"; then
4225 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4226 echo "$CMD2 &"
4227 echo "$CMD"
4228 cat "${te}1"
4229 cat "${te}2"
4230 cat "$tdiff"
4231 numFAIL=$((numFAIL+1))
4232 listFAIL="$listFAIL $N"
4233 else
4234 $PRINTF "$OK\n"
4235 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4236 numOK=$((numOK+1))
4238 kill $pid 2>/dev/null
4239 wait
4240 fi ;; # NUMCOND, feats
4241 esac
4242 PORT=$((PORT+1))
4243 N=$((N+1))
4245 done <<<"
4246 UNIXCONNECT , unix UNIX-CONNECT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4247 UNIXCLIENT , unix UNIX-CLIENT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4248 GOPEN_UNIXSTREAM , unix GOPEN:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4249 UNIXLISTEN , unix UNIX-LISTEN:\$ts UNIX-CONNECT:\$ts,retry=3 sleep\040\1
4250 TCP4CONNECT , tcp4 TCP4-CONNECT:\$LOCALHOST:\$PORT TCP4-LISTEN:\$PORT,$REUSEADDR waittcp4port\040\$PORT
4251 TCP4LISTEN , tcp4 TCP4-LISTEN:\$PORT,$REUSEADDR TCP4-CONNECT:\$LOCALHOST:\$PORT,retry=3
4252 TCP6CONNECT , tcp6 TCP6-CONNECT:\$LOCALHOST6:\$PORT TCP6-LISTEN:\$PORT,$REUSEADDR waittcp6port\040\$PORT
4253 TCP6LISTEN , tcp6 TCP6-LISTEN:\$PORT,$REUSEADDR TCP6-CONNECT:\$LOCALHOST6:\$PORT,retry=3
4254 OPENSSL4CLIENT OPENSSL tcp4 OPENSSL:\$LOCALHOST:\$PORT,verify=0 OPENSSL-LISTEN:\$PORT,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp4port\040\$PORT
4255 OPENSSL4SERVER OPENSSL tcp4 OPENSSL-LISTEN:\$PORT,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST:\$PORT,$REUSEADDR,verify=0,retry=3
4256 OPENSSL6CLIENT OPENSSL tcp6 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,verify=0 OPENSSL-LISTEN:\$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp6port\040\$PORT
4257 OPENSSL6SERVER OPENSSL tcp6 OPENSSL-LISTEN:\$PORT,pf=ip6,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,$REUSEADDR,verify=0,retry=3
4261 NAME=OPENSSL_SERVERAUTH
4262 case "$TESTS" in
4263 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4264 TEST="$NAME: openssl server authentication"
4265 if ! eval $NUMCOND; then :;
4266 elif ! testaddrs openssl >/dev/null; then
4267 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4268 numCANT=$((numCANT+1))
4269 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4270 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4271 numCANT=$((numCANT+1))
4272 else
4273 gentestcert testsrv
4274 gentestcert testcli
4275 tf="$td/test$N.stdout"
4276 te="$td/test$N.stderr"
4277 tdiff="$td/test$N.diff"
4278 da="test$N $(date) $RANDOM"
4279 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4280 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=1,cafile=testsrv.crt,$SOCAT_EGD"
4281 printf "test $F_n $TEST... " $N
4282 eval "$CMD2 2>\"${te}1\" &"
4283 pid=$! # background process id
4284 waittcp4port $PORT
4285 echo "$da" |$CMD >$tf 2>"${te}2"
4286 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4287 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4288 echo "$CMD2 &"
4289 echo "$CMD"
4290 cat "${te}1"
4291 cat "${te}2"
4292 cat "$tdiff"
4293 numFAIL=$((numFAIL+1))
4294 listFAIL="$listFAIL $N"
4295 else
4296 $PRINTF "$OK\n"
4297 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4298 numOK=$((numOK+1))
4300 kill $pid 2>/dev/null
4301 wait
4302 fi ;; # NUMCOND, feats
4303 esac
4304 PORT=$((PORT+1))
4305 N=$((N+1))
4307 NAME=OPENSSL_CLIENTAUTH
4308 case "$TESTS" in
4309 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4310 TEST="$NAME: openssl client authentication"
4311 if ! eval $NUMCOND; then :;
4312 elif ! testaddrs openssl >/dev/null; then
4313 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4314 numCANT=$((numCANT+1))
4315 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4316 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4317 numCANT=$((numCANT+1))
4318 else
4319 gentestcert testsrv
4320 gentestcert testcli
4321 tf="$td/test$N.stdout"
4322 te="$td/test$N.stderr"
4323 tdiff="$td/test$N.diff"
4324 da="test$N $(date) $RANDOM"
4325 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,verify=1,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt,$SOCAT_EGD pipe"
4326 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=0,cert=testcli.crt,key=testcli.key,$SOCAT_EGD"
4327 printf "test $F_n $TEST... " $N
4328 eval "$CMD2 2>\"${te}1\" &"
4329 pid=$! # background process id
4330 waittcp4port $PORT
4331 echo "$da" |$CMD >$tf 2>"${te}2"
4332 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4333 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4334 echo "$CMD2 &"
4335 echo "$CMD"
4336 cat "${te}1"
4337 cat "${te}2"
4338 cat "$tdiff"
4339 numFAIL=$((numFAIL+1))
4340 listFAIL="$listFAIL $N"
4341 else
4342 $PRINTF "$OK\n"
4343 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4344 numOK=$((numOK+1))
4346 kill $pid 2>/dev/null
4347 wait
4348 fi ;; # NUMCOND, feats
4349 esac
4350 PORT=$((PORT+1))
4351 N=$((N+1))
4353 NAME=OPENSSL_FIPS_BOTHAUTH
4354 case "$TESTS" in
4355 *%$N%*|*%functions%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4356 TEST="$NAME: OpenSSL+FIPS client and server authentication"
4357 if ! eval $NUMCOND; then :;
4358 elif ! testaddrs openssl >/dev/null; then
4359 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4360 numCANT=$((numCANT+1))
4361 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4362 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4363 numCANT=$((numCANT+1))
4364 elif ! testoptions fips >/dev/null; then
4365 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
4366 numCANT=$((numCANT+1))
4367 else
4368 OPENSSL_FIPS=1 gentestcert testsrvfips
4369 OPENSSL_FIPS=1 gentestcert testclifips
4370 tf="$td/test$N.stdout"
4371 te="$td/test$N.stderr"
4372 tdiff="$td/test$N.diff"
4373 da="test$N $(date) $RANDOM"
4374 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,fips,$SOCAT_EGD,cert=testsrvfips.crt,key=testsrvfips.key,cafile=testclifips.crt pipe"
4375 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,fips,verify=1,cert=testclifips.crt,key=testclifips.key,cafile=testsrvfips.crt,$SOCAT_EGD"
4376 printf "test $F_n $TEST... " $N
4377 eval "$CMD2 2>\"${te}1\" &"
4378 pid=$! # background process id
4379 waittcp4port $PORT
4380 echo "$da" |$CMD >$tf 2>"${te}2"
4381 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4382 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4383 echo "$CMD2 &"
4384 echo "$CMD"
4385 cat "${te}1"
4386 cat "${te}2"
4387 cat "$tdiff"
4388 numFAIL=$((numFAIL+1))
4389 listFAIL="$listFAIL $N"
4390 else
4391 $PRINTF "$OK\n"
4392 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4393 numOK=$((numOK+1))
4395 kill $pid 2>/dev/null
4396 wait
4397 fi ;; # NUMCOND, feats
4398 esac
4399 PORT=$((PORT+1))
4400 N=$((N+1))
4403 NAME=OPENSSL_COMPRESS
4404 case "$TESTS" in
4405 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4406 TEST="$NAME: OpenSSL compression"
4407 if ! eval $NUMCOND; then :;
4408 elif ! testaddrs openssl >/dev/null; then
4409 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4410 numCANT=$((numCANT+1))
4411 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4412 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4413 numCANT=$((numCANT+1))
4414 elif ! testoptions openssl-compress >/dev/null; then
4415 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL compression option not available${NORMAL}\n" $N
4416 numCANT=$((numCANT+1))
4417 else
4418 gentestcert testsrv
4419 printf "test $F_n $TEST... " $N
4420 tf="$td/test$N.stdout"
4421 te="$td/test$N.stderr"
4422 tdiff="$td/test$N.diff"
4423 da="test$N $(date) $RANDOM"
4424 success=yes
4425 for srccompr in '' compress=auto compress=none; do
4426 for dstcompr in '' compress=auto compress=none; do
4427 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0,$dstcompr pipe"
4428 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD,$srccompr"
4429 eval "$CMD2 2>\"${te}1\" &"
4430 pid=$! # background process id
4431 waittcp4port $PORT
4432 echo "$da" | $CMD >$tf 2>"${te}2"
4433 kill $pid 2>/dev/null
4434 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4435 success=
4436 break
4438 done
4439 done
4440 if test -z "$success"; then
4441 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4442 echo "$CMD2 &"
4443 echo "$CMD"
4444 cat "${te}1"
4445 cat "${te}2"
4446 cat "$tdiff"
4447 numFAIL=$((numFAIL+1))
4448 listFAIL="$listFAIL $N"
4449 else
4450 $PRINTF "$OK\n"
4451 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4452 numOK=$((numOK+1))
4454 fi ;; # NUMCOND, feats
4455 esac
4456 PORT=$((PORT+1))
4457 N=$((N+1))
4460 NAME=SOCKS4CONNECT_TCP4
4461 case "$TESTS" in
4462 *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4463 TEST="$NAME: socks4 connect over TCP/IPv4"
4464 if ! eval $NUMCOND; then :;
4465 elif ! testaddrs socks4 >/dev/null; then
4466 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4467 numCANT=$((numCANT+1))
4468 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4469 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4470 numCANT=$((numCANT+1))
4471 else
4472 tf="$td/test$N.stdout"
4473 te="$td/test$N.stderr"
4474 tdiff="$td/test$N.diff"
4475 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4476 # we have a normal tcp echo listening - so the socks header must appear in answer
4477 CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR exec:\"./socks4echo.sh\""
4478 CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST:32.98.76.54:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
4479 printf "test $F_n $TEST... " $N
4480 eval "$CMD2 2>\"${te}1\" &"
4481 pid=$! # background process id
4482 waittcp4port $PORT 1
4483 echo "$da" |$CMD >$tf 2>"${te}2"
4484 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4485 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4486 echo "$CMD2 &"
4487 echo "$CMD"
4488 cat "${te}1"
4489 cat "${te}2"
4490 cat "$tdiff"
4491 numFAIL=$((numFAIL+1))
4492 listFAIL="$listFAIL $N"
4493 else
4494 $PRINTF "$OK\n"
4495 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4496 numOK=$((numOK+1))
4498 kill $pid 2>/dev/null
4499 wait
4500 fi ;; # NUMCOND, feats
4501 esac
4502 PORT=$((PORT+1))
4503 N=$((N+1))
4505 NAME=SOCKS4CONNECT_TCP6
4506 case "$TESTS" in
4507 *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4508 TEST="$NAME: socks4 connect over TCP/IPv6"
4509 if ! eval $NUMCOND; then :;
4510 elif ! testaddrs socks4 >/dev/null; then
4511 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4512 numCANT=$((numCANT+1))
4513 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4514 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4515 numCANT=$((numCANT+1))
4516 else
4517 tf="$td/test$N.stdout"
4518 te="$td/test$N.stderr"
4519 tdiff="$td/test$N.diff"
4520 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4521 # we have a normal tcp echo listening - so the socks header must appear in answer
4522 CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR exec:\"./socks4echo.sh\""
4523 CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST6:32.98.76.54:32109,socksport=$PORT",socksuser="nobody"
4524 printf "test $F_n $TEST... " $N
4525 eval "$CMD2 2>\"${te}1\" &"
4526 pid=$! # background process id
4527 waittcp6port $PORT 1
4528 echo "$da" |$CMD >$tf 2>"${te}2"
4529 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4530 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4531 echo "$CMD2 &"
4532 echo "$CMD"
4533 cat "${te}1"
4534 cat "${te}2"
4535 cat "$tdiff"
4536 numFAIL=$((numFAIL+1))
4537 listFAIL="$listFAIL $N"
4538 else
4539 $PRINTF "$OK\n"
4540 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4541 numOK=$((numOK+1))
4543 kill $pid 2>/dev/null
4544 wait
4545 fi ;; # NUMCOND, feats
4546 esac
4547 PORT=$((PORT+1))
4548 N=$((N+1))
4551 NAME=SOCKS4ACONNECT_TCP4
4552 case "$TESTS" in
4553 *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4554 TEST="$NAME: socks4a connect over TCP/IPv4"
4555 if ! eval $NUMCOND; then :;
4556 elif ! testaddrs socks4a >/dev/null; then
4557 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4558 numCANT=$((numCANT+1))
4559 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4560 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4561 numCANT=$((numCANT+1))
4562 else
4563 tf="$td/test$N.stdout"
4564 te="$td/test$N.stderr"
4565 tdiff="$td/test$N.diff"
4566 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4567 # we have a normal tcp echo listening - so the socks header must appear in answer
4568 CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR exec:\"./socks4a-echo.sh\""
4569 CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST:localhost:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
4570 printf "test $F_n $TEST... " $N
4571 eval "$CMD2 2>\"${te}1\" &"
4572 pid=$! # background process id
4573 waittcp4port $PORT 1
4574 echo "$da" |$CMD >$tf 2>"${te}2"
4575 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4576 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4577 echo "$CMD2 &"
4578 echo "$CMD"
4579 cat "${te}1"
4580 cat "${te}2"
4581 cat "$tdiff"
4582 numFAIL=$((numFAIL+1))
4583 listFAIL="$listFAIL $N"
4584 else
4585 $PRINTF "$OK\n"
4586 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4587 numOK=$((numOK+1))
4589 kill $pid 2>/dev/null
4590 wait
4591 fi ;; # NUMCOND, feats
4592 esac
4593 PORT=$((PORT+1))
4594 N=$((N+1))
4596 NAME=SOCKS4ACONNECT_TCP6
4597 case "$TESTS" in
4598 *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4599 TEST="$NAME: socks4a connect over TCP/IPv6"
4600 if ! eval $NUMCOND; then :;
4601 elif ! testaddrs socks4a >/dev/null; then
4602 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4603 numCANT=$((numCANT+1))
4604 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4605 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4606 numCANT=$((numCANT+1))
4607 else
4608 tf="$td/test$N.stdout"
4609 te="$td/test$N.stderr"
4610 tdiff="$td/test$N.diff"
4611 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4612 # we have a normal tcp echo listening - so the socks header must appear in answer
4613 CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR exec:\"./socks4a-echo.sh\""
4614 CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST6:localhost:32109,socksport=$PORT",socksuser="nobody"
4615 printf "test $F_n $TEST... " $N
4616 eval "$CMD2 2>\"${te}1\" &"
4617 pid=$! # background process id
4618 waittcp6port $PORT 1
4619 echo "$da" |$CMD >$tf 2>"${te}2"
4620 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4621 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4622 echo "$CMD2 &"
4623 echo "$CMD"
4624 cat "${te}1"
4625 cat "${te}2"
4626 cat "$tdiff"
4627 numFAIL=$((numFAIL+1))
4628 listFAIL="$listFAIL $N"
4629 else
4630 $PRINTF "$OK\n"
4631 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4632 numOK=$((numOK+1))
4634 kill $pid 2>/dev/null
4635 wait
4636 fi ;; # NUMCOND, feats
4637 esac
4638 PORT=$((PORT+1))
4639 N=$((N+1))
4642 NAME=PROXYCONNECT_TCP4
4643 case "$TESTS" in
4644 *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4645 TEST="$NAME: proxy connect over TCP/IPv4"
4646 if ! eval $NUMCOND; then :;
4647 elif ! testaddrs proxy >/dev/null; then
4648 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4649 numCANT=$((numCANT+1))
4650 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4651 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4652 numCANT=$((numCANT+1))
4653 else
4654 ts="$td/test$N.sh"
4655 tf="$td/test$N.stdout"
4656 te="$td/test$N.stderr"
4657 tdiff="$td/test$N.diff"
4658 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4659 #CMD2="$TRACE $SOCAT tcp4-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4660 CMD2="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR,crlf exec:\"/usr/bin/env bash proxyecho.sh\""
4661 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4662 printf "test $F_n $TEST... " $N
4663 eval "$CMD2 2>\"${te}2\" &"
4664 pid=$! # background process id
4665 waittcp4port $PORT 1
4666 echo "$da" |$CMD >"$tf" 2>"${te}1"
4667 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4668 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4669 echo "$CMD2 &"
4670 echo "$CMD"
4671 cat "${te}1"
4672 cat "${te}2"
4673 cat "$tdiff"
4674 numFAIL=$((numFAIL+1))
4675 listFAIL="$listFAIL $N"
4676 else
4677 $PRINTF "$OK\n"
4678 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4679 numOK=$((numOK+1))
4681 kill $pid 2>/dev/null
4682 wait
4683 fi ;; # NUMCOND, feats
4684 esac
4685 PORT=$((PORT+1))
4686 N=$((N+1))
4688 NAME=PROXYCONNECT_TCP6
4689 case "$TESTS" in
4690 *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4691 TEST="$NAME: proxy connect over TCP/IPv6"
4692 if ! eval $NUMCOND; then :;
4693 elif ! testaddrs proxy >/dev/null; then
4694 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4695 numCANT=$((numCANT+1))
4696 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4697 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4698 numCANT=$((numCANT+1))
4699 else
4700 ts="$td/test$N.sh"
4701 tf="$td/test$N.stdout"
4702 te="$td/test$N.stderr"
4703 tdiff="$td/test$N.diff"
4704 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4705 #CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4706 CMD2="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR,crlf exec:\"/usr/bin/env bash proxyecho.sh\""
4707 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST6:127.0.0.1:1000,proxyport=$PORT"
4708 printf "test $F_n $TEST... " $N
4709 eval "$CMD2 2>\"${te}2\" &"
4710 pid=$! # background process id
4711 waittcp6port $PORT 1
4712 echo "$da" |$CMD >"$tf" 2>"${te}1"
4713 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4714 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4715 echo "$CMD2 &"
4716 echo "$CMD"
4717 cat "${te}1"
4718 cat "${te}2"
4719 cat "$tdiff"
4720 numFAIL=$((numFAIL+1))
4721 listFAIL="$listFAIL $N"
4722 else
4723 $PRINTF "$OK\n"
4724 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4725 numOK=$((numOK+1))
4727 kill $pid 2>/dev/null
4728 wait
4729 fi ;; # NUMCOND, feats
4730 esac
4731 PORT=$((PORT+1))
4732 N=$((N+1))
4735 NAME=TCP4NOFORK
4736 case "$TESTS" in
4737 *%$N%*|*%functions%*|*%$NAME%*)
4738 TEST="$NAME: echo via connection to TCP V4 socket with nofork'ed exec"
4739 if ! eval $NUMCOND; then :; else
4740 tf="$td/test$N.stdout"
4741 te="$td/test$N.stderr"
4742 tdiff="$td/test$N.diff"
4743 tsl=$PORT
4744 ts="127.0.0.1:$tsl"
4745 da="test$N $(date) $RANDOM"
4746 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR exec:$CAT,nofork"
4747 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
4748 printf "test $F_n $TEST... " $N
4749 #$CMD1 >"$tf" 2>"${te}1" &
4750 $CMD1 >/dev/null 2>"${te}1" &
4751 waittcp4port $tsl
4752 #usleep $MICROS
4753 echo "$da" |$CMD2 >"$tf" 2>>"${te}2"
4754 if [ $? -ne 0 ]; then
4755 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4756 echo "$CMD1 &"
4757 echo "$CMD2"
4758 cat "${te}1"
4759 cat "${te}2"
4760 numFAIL=$((numFAIL+1))
4761 listFAIL="$listFAIL $N"
4762 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
4763 $PRINTF "$FAILED\n"
4764 cat "$tdiff"
4765 numFAIL=$((numFAIL+1))
4766 listFAIL="$listFAIL $N"
4767 else
4768 $PRINTF "$OK\n"
4769 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4770 numOK=$((numOK+1))
4772 fi ;; # NUMCOND
4773 esac
4774 PORT=$((PORT+1))
4775 N=$((N+1))
4778 NAME=EXECCATNOFORK
4779 case "$TESTS" in
4780 *%$N%*|*%functions%*|*%$NAME%*)
4781 TEST="$NAME: simple echo via exec of cat with nofork"
4782 testecho "$N" "$TEST" "" "exec:$CAT,nofork" "$opts"
4783 esac
4784 N=$((N+1))
4787 NAME=SYSTEMCATNOFORK
4788 case "$TESTS" in
4789 *%$N%*|*%functions%*|*%$NAME%*)
4790 TEST="$NAME: simple echo via system() of cat with nofork"
4791 testecho "$N" "$TEST" "" "system:$CAT,nofork" "$opts"
4792 esac
4793 N=$((N+1))
4796 NAME=NOFORKSETSID
4797 case "$TESTS" in
4798 *%$N%*|*%functions%*|*%$NAME%*)
4799 TEST="$NAME: simple echo via exec() of cat with nofork and setsid"
4800 testecho "$N" "$TEST" "" "system:$CAT,nofork,setsid" "$opts"
4801 esac
4802 N=$((N+1))
4804 #==============================================================================
4805 #TEST="$NAME: echo via 'connection' to UDP V4 socket"
4806 #if ! eval $NUMCOND; then :; else
4807 #tf="$td/file$N"
4808 #tsl=65534
4809 #ts="127.0.0.1:$tsl"
4810 #da="test$N $(date) $RANDOM"
4811 #$TRACE $SOCAT UDP-listen:$tsl,$REUSEADDR PIPE &
4812 #sleep 2
4813 #echo "$da" |$TRACE $SOCAT stdin!!stdout UDP:$ts >"$tf"
4814 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
4815 # $ECHO "... test $N succeeded"
4816 # numOK=$((numOK+1))
4817 #else
4818 # $ECHO "*** test $N $FAILED"
4819 # numFAIL=$((numFAIL+1))
4820 # listFAIL="$listFAIL $N"
4822 #fi ;; # NUMCOND
4823 #N=$((N+1))
4824 #==============================================================================
4825 # TEST 4 - simple echo via new file
4826 #if ! eval $NUMCOND; then :; else
4827 #N=4
4828 #tf="$td/file$N"
4829 #tp="$td/pipe$N"
4830 #da="test$N $(date) $RANDOM"
4831 #rm -f "$tf.tmp"
4832 #echo "$da" |$TRACE $SOCAT - FILE:$tf.tmp,ignoreeof >"$tf"
4833 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
4834 # $ECHO "... test $N succeeded"
4835 # numOK=$((numOK+1))
4836 #else
4837 # $ECHO "*** test $N $FAILED"
4838 # numFAIL=$((numFAIL+1))
4839 # listFAIL="$listFAIL $N"
4841 #fi ;; # NUMCOND
4843 #==============================================================================
4845 NAME=TOTALTIMEOUT
4846 case "$TESTS" in
4847 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%$NAME%*)
4848 TEST="$NAME: socat inactivity timeout"
4849 if ! eval $NUMCOND; then :; else
4850 #set -vx
4851 tf="$td/test$N.stdout"
4852 te="$td/test$N.stderr"
4853 tdiff="$td/test$N.diff"
4854 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4855 CMD2="$TRACE $SOCAT $opts -T 1 TCP4-LISTEN:$PORT,$REUSEADDR pipe"
4856 CMD="$TRACE $SOCAT $opts - tcp4-connect:$LOCALHOST:$PORT"
4857 printf "test $F_n $TEST... " $N
4858 eval "$CMD2 2>${te}1 &"
4859 pid=$! # background process id
4860 waittcp4port $PORT 1
4861 (echo "$da"; sleep 2; echo X) |$CMD >"$tf" 2>"${te}2"
4862 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4863 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4864 echo "$CMD2 &"
4865 echo "$CMD"
4866 cat "${te}1"
4867 cat "${te}2"
4868 cat "$tdiff"
4869 numFAIL=$((numFAIL+1))
4870 listFAIL="$listFAIL $N"
4871 else
4872 $PRINTF "$OK\n"
4873 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4874 numOK=$((numOK+1))
4876 kill $pid 2>/dev/null
4877 wait
4878 #set +vx
4879 fi ;; # NUMCOND
4880 esac
4881 PORT=$((PORT+1))
4882 N=$((N+1))
4885 NAME=IGNOREEOF+TOTALTIMEOUT
4886 case "$TESTS" in
4887 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%ignoreeof%*|*%$NAME%*)
4888 TEST="$NAME: ignoreeof and inactivity timeout"
4889 if ! eval $NUMCOND; then :; else
4890 #set -vx
4891 ti="$td/test$N.file"
4892 tf="$td/test$N.stdout"
4893 te="$td/test$N.stderr"
4894 tdiff="$td/test$N.diff"
4895 da="test$N $(date) $RANDOM"
4896 CMD="$TRACE $SOCAT $opts -T 2 -u file:\"$ti\",ignoreeof -"
4897 printf "test $F_n $TEST... " $N
4898 touch "$ti"
4899 $CMD >"$tf" 2>"$te" &
4900 bg=$! # background process id
4901 psleep 0.5
4902 echo "$da" >>"$ti"
4903 sleep 4
4904 echo X >>"$ti"
4905 sleep 1
4906 kill $bg 2>/dev/null
4907 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4908 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4909 echo "$CMD &"
4910 cat "$te"
4911 cat "$tdiff"
4912 numFAIL=$((numFAIL+1))
4913 listFAIL="$listFAIL $N"
4914 else
4915 $PRINTF "$OK\n"
4916 if [ -n "$debug" ]; then cat "$te"; fi
4917 numOK=$((numOK+1))
4919 wait
4920 fi ;; # NUMCOND, feats
4921 esac
4922 N=$((N+1))
4925 NAME=PROXY2SPACES
4926 case "$TESTS" in
4927 *%$N%*|*%functions%*|*%proxy%*|*%$NAME%*)
4928 TEST="$NAME: proxy connect accepts status with multiple spaces"
4929 if ! eval $NUMCOND; then :;
4930 elif ! testaddrs proxy >/dev/null; then
4931 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4932 numCANT=$((numCANT+1))
4933 else
4934 ts="$td/test$N.sh"
4935 tf="$td/test$N.stdout"
4936 te="$td/test$N.stderr"
4937 tdiff="$td/test$N.diff"
4938 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4939 #CMD2="$TRACE $SOCAT $opts tcp-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4940 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr,crlf exec:\"/usr/bin/env bash proxyecho.sh -w 2\""
4941 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4942 printf "test $F_n $TEST... " $N
4943 eval "$CMD2 2>\"${te}1\" &"
4944 pid=$! # background process id
4945 waittcp4port $PORT 1
4946 echo "$da" |$CMD >"$tf" 2>"${te}2"
4947 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4948 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4949 echo "$CMD2 &"
4950 echo "$CMD"
4951 cat "${te}1"
4952 cat "${te}2"
4953 cat "$tdiff"
4954 numFAIL=$((numFAIL+1))
4955 listFAIL="$listFAIL $N"
4956 else
4957 $PRINTF "$OK\n"
4958 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4959 numOK=$((numOK+1))
4961 kill $pid 2>/dev/null
4962 wait
4963 fi ;; # NUMCOND, feats
4964 esac
4965 PORT=$((PORT+1))
4966 N=$((N+1))
4969 NAME=BUG-UNISTDIO
4970 case "$TESTS" in
4971 *%$N%*|*%functions%*|*%$NAME%*)
4972 TEST="$NAME: for bug with address options on both stdin/out in unidirectional mode"
4973 if ! eval $NUMCOND; then :; else
4974 tf="$td/test$N.stdout"
4975 te="$td/test$N.stderr"
4976 ff="$td/file$N"
4977 printf "test $F_n $TEST... " $N
4978 >"$ff"
4979 #$TRACE $SOCAT $opts -u /dev/null -,setlk <"$ff" 2>"$te"
4980 CMD="$TRACE $SOCAT $opts -u /dev/null -,setlk"
4981 $CMD <"$ff" 2>"$te"
4982 if [ "$?" -eq 0 ]; then
4983 $PRINTF "$OK\n"
4984 numOK=$((numOK+1))
4985 else
4986 if [ "$UNAME" = "Linux" ]; then
4987 $PRINTF "$FAILED\n"
4988 echo "$CMD"
4989 cat "$te"
4990 numFAIL=$((numFAIL+1))
4991 listFAIL="$listFAIL $N"
4992 else
4993 $PRINTF "${YELLOW}failed (don't care)${NORMAL}\n"
4994 numCANT=$((numCANT+1))
4997 fi ;; # NUMCOND
4998 esac
4999 N=$((N+1))
5002 NAME=SINGLEEXECOUTSOCKETPAIR
5003 case "$TESTS" in
5004 *%$N%*|*%functions%*|*%$NAME%*)
5005 TEST="$NAME: inheritance of stdout to single exec with socketpair"
5006 testecho "$N" "$TEST" "-!!exec:cat" "" "$opts" 1
5007 esac
5008 N=$((N+1))
5010 NAME=SINGLEEXECOUTPIPE
5011 case "$TESTS" in
5012 *%$N%*|*%functions%*|*%$NAME%*)
5013 TEST="$NAME: inheritance of stdout to single exec with pipe"
5014 testecho "$N" "$TEST" "-!!exec:cat,pipes" "" "$opts" 1
5015 esac
5016 N=$((N+1))
5018 NAME=SINGLEEXECOUTPTY
5019 case "$TESTS" in
5020 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5021 TEST="$NAME: inheritance of stdout to single exec with pty"
5022 if ! eval $NUMCOND; then :;
5023 elif ! testaddrs pty >/dev/null; then
5024 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5025 numCANT=$((numCANT+1))
5026 else
5027 testecho "$N" "$TEST" "-!!exec:cat,pty,raw" "" "$opts" 1
5028 fi ;; # NUMCOND, feats
5029 esac
5030 N=$((N+1))
5032 NAME=SINGLEEXECINSOCKETPAIR
5033 case "$TESTS" in
5034 *%$N%*|*%functions%*|*%$NAME%*)
5035 TEST="$NAME: inheritance of stdin to single exec with socketpair"
5036 testecho "$N" "$TEST" "exec:cat!!-" "" "$opts"
5037 esac
5038 N=$((N+1))
5040 NAME=SINGLEEXECINPIPE
5041 case "$TESTS" in
5042 *%$N%*|*%functions%*|*%$NAME%*)
5043 TEST="$NAME: inheritance of stdin to single exec with pipe"
5044 testecho "$N" "$TEST" "exec:cat,pipes!!-" "" "$opts"
5045 esac
5046 N=$((N+1))
5048 NAME=SINGLEEXECINPTYDELAY
5049 case "$TESTS" in
5050 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5051 TEST="$NAME: inheritance of stdin to single exec with pty, with delay"
5052 if ! eval $NUMCOND; then :;
5053 elif ! testaddrs pty >/dev/null; then
5054 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5055 numCANT=$((numCANT+1))
5056 else
5057 testecho "$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts" $MISCDELAY
5058 fi ;; # NUMCOND, feats
5059 esac
5060 N=$((N+1))
5062 NAME=SINGLEEXECINPTY
5063 case "$TESTS" in
5064 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
5065 TEST="$NAME: inheritance of stdin to single exec with pty"
5066 if ! eval $NUMCOND; then :;
5067 elif ! testaddrs pty >/dev/null; then
5068 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5069 numCANT=$((numCANT+1))
5070 else
5071 testecho "$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts"
5072 fi ;; # NUMCOND, feats
5073 esac
5074 N=$((N+1))
5077 NAME=READLINE
5078 #set -vx
5079 case "$TESTS" in
5080 *%$N%*|*%functions%*|*%pty%*|*%readline%*|*%$NAME%*)
5081 TEST="$NAME: readline with password and sigint"
5082 if ! eval $NUMCOND; then :;
5083 elif ! feat=$(testaddrs readline pty); then
5084 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5085 numCANT=$((numCANT+1))
5086 else
5087 SAVETERM="$TERM"; TERM= # 'cause konsole might print controls even in raw
5088 SAVEMICS=$MICROS
5089 #MICROS=2000000
5090 ts="$td/test$N.sh"
5091 to="$td/test$N.stdout"
5092 tpi="$td/test$N.inpipe"
5093 tpo="$td/test$N.outpipe"
5094 te="$td/test$N.stderr"
5095 tr="$td/test$N.ref"
5096 tdiff="$td/test$N.diff"
5097 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
5098 # the feature that we really want to test is in the readline.sh script:
5099 CMD="$TRACE $SOCAT $opts -t1 open:$tpi,nonblock!!open:$tpo exec:\"./readline.sh -nh ./readline-test.sh\",pty,ctty,setsid,raw,echo=0,isig"
5100 #echo "$CMD" >"$ts"
5101 #chmod a+x "$ts"
5102 printf "test $F_n $TEST... " $N
5103 rm -f "$tpi" "$tpo"
5104 mkfifo "$tpi"
5105 touch "$tpo"
5107 # during development of this test, the following command line succeeded:
5108 # (sleep 1; $ECHO "user\n\c"; sleep 1; $ECHO "password\c"; sleep 1; $ECHO "\n\c"; sleep 1; $ECHO "test 1\n\c"; sleep 1; $ECHO "\003\c"; sleep 1; $ECHO "test 2\n\c"; sleep 1; $ECHO "exit\n\c"; sleep 1) |$TRACE $SOCAT -d -d -d -d -lf/tmp/gerhard/debug1 -v -x - exec:'./readline.sh ./readline-test.sh',pty,ctty,setsid,raw,echo=0,isig
5110 PATH=${SOCAT%socat}:$PATH eval "$CMD 2>$te &"
5111 pid=$! # background process id
5112 usleep $MICROS
5115 usleep $((3*MICROS))
5116 $ECHO "user\n\c"
5117 usleep $MICROS
5118 $ECHO "password\c"
5119 usleep $MICROS
5120 $ECHO "\n\c"
5121 usleep $MICROS
5122 $ECHO "test 1\n\c"
5123 usleep $MICROS
5124 $ECHO "\003\c"
5125 usleep $MICROS
5126 $ECHO "test 2\n\c"
5127 usleep $MICROS
5128 $ECHO "exit\n\c"
5129 usleep $MICROS
5130 ) >"$tpi"
5132 cat >$tr <<EOF
5133 readline feature test program
5134 Authentication required
5135 Username: user
5136 Password:
5137 prog> test 1
5138 executing test 1
5139 prog> ./readline-test.sh got SIGINT
5140 test 2
5141 executing test 2
5142 prog> exit
5145 #0 if ! sed 's/.*\r//g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5146 #0 if ! sed 's/.*'"$($ECHO '\r\c')"'/</g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5147 wait
5148 if ! tr "$($ECHO '\r \c')" "% " <$tpo |sed 's/%$//g' |sed 's/.*%//g' |diff "$tr" - >"$tdiff" 2>&1; then
5149 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5150 echo "$CMD"
5151 cat "$te"
5152 cat "$tdiff"
5153 numFAIL=$((numFAIL+1))
5154 listFAIL="$listFAIL $N"
5155 else
5156 $PRINTF "$OK\n"
5157 if [ -n "$debug" ]; then cat $te; fi
5158 numOK=$((numOK+1))
5160 kill $pid 2>/dev/null # necc on OpenBSD
5161 wait
5162 MICROS=$SAVEMICS
5163 TERM="$SAVETERM"
5164 fi ;; # NUMCOND, feats
5165 esac
5166 PORT=$((PORT+1))
5167 N=$((N+1))
5170 NAME=GENDERCHANGER
5171 case "$TESTS" in
5172 *%$N%*|*%functions%*|*%$NAME%*)
5173 TEST="$NAME: TCP4 \"gender changer\""
5174 if ! eval $NUMCOND; then :; else
5175 tf="$td/test$N.stdout"
5176 te="$td/test$N.stderr"
5177 tdiff="$td/test$N.diff"
5178 da="test$N $(date) $RANDOM"
5179 # this is the server in the protected network that we want to reach
5180 CMD1="$TRACE $SOCAT -lpserver $opts tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5181 # this is the double client in the protected network
5182 CMD2="$TRACE $SOCAT -lp2client $opts tcp4:$LOCALHOST:$((PORT+1)),retry=10,interval=1 tcp4:$LOCALHOST:$PORT"
5183 # this is the double server in the outside network
5184 CMD3="$TRACE $SOCAT -lp2server $opts tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST"
5185 # this is the outside client that wants to use the protected server
5186 CMD4="$TRACE $SOCAT -lpclient $opts -t1 - tcp4:$LOCALHOST:$((PORT+2))"
5187 printf "test $F_n $TEST... " $N
5188 eval "$CMD1 2>${te}1 &"
5189 pid1=$!
5190 eval "$CMD2 2>${te}2 &"
5191 pid2=$!
5192 eval "$CMD3 2>${te}3 &"
5193 pid3=$!
5194 waittcp4port $PORT 1 &&
5195 waittcp4port $((PORT+2)) 1
5196 sleep 1
5197 echo "$da" |$CMD4 >$tf 2>"${te}4"
5198 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
5199 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5200 echo "$CMD1 &"
5201 echo "$CMD2 &"
5202 echo "$CMD3 &"
5203 echo "$CMD4"
5204 cat "${te}1" "${te}2" "${te}3" "${te}4"
5205 cat "$tdiff"
5206 numFAIL=$((numFAIL+1))
5207 listFAIL="$listFAIL $N"
5208 else
5209 $PRINTF "$OK\n"
5210 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4"; fi
5211 numOK=$((numOK+1))
5213 kill $pid1 $pid2 $pid3 $pid4 2>/dev/null
5214 wait
5215 fi ;; # NUMCOND
5216 esac
5217 PORT=$((PORT+3))
5218 N=$((N+1))
5222 #PORT=10000
5224 NAME=OUTBOUNDIN
5225 case "$TESTS" in
5226 *%$N%*|*%functions%*|*%openssl%*|*%proxy%*|*%$NAME%*)
5227 TEST="$NAME: gender changer via SSL through HTTP proxy, oneshot"
5228 if ! eval $NUMCOND; then :;
5229 elif ! feat=$(testaddrs openssl proxy); then
5230 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5231 numCANT=$((numCANT+1))
5232 else
5233 gentestcert testsrv
5234 gentestcert testcli
5235 tf="$td/test$N.stdout"
5236 te="$td/test$N.stderr"
5237 tdiff="$td/test$N.diff"
5238 da="test$N $(date) $RANDOM"
5239 # this is the server in the protected network that we want to reach
5240 CMD1="$TRACE $SOCAT $opts -lpserver tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5241 # this is the proxy in the protected network that provides a way out
5242 CMD2="$TRACE $SOCAT $opts -lpproxy tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5243 # this is our proxy connect wrapper in the protected network
5244 CMD3="$TRACE $SOCAT $opts -lpwrapper tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
5245 # this is our double client in the protected network using SSL
5246 #CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5247 CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5248 # this is the double server in the outside network
5249 CMD5="$TRACE $SOCAT $opts -lp2server -t1 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt"
5250 # this is the outside client that wants to use the protected server
5251 CMD6="$TRACE $SOCAT $opts -lpclient -t5 - tcp4:$LOCALHOST:$((PORT+4))"
5252 printf "test $F_n $TEST... " $N
5253 eval "$CMD1 2>${te}1 &"
5254 pid1=$!
5255 eval "$CMD2 2>${te}2 &"
5256 pid2=$!
5257 eval "$CMD3 2>${te}3 &"
5258 pid3=$!
5259 waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
5260 waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
5261 waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
5262 eval "$CMD5 2>${te}5 &"
5263 pid5=$!
5264 waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
5265 echo "$da" |$CMD6 >$tf 2>"${te}6" &
5266 pid6=$!
5267 waittcp4port $((PORT+3)) 1 || $PRINTF "$FAILED: port $((PORT+3))\n" >&2 </dev/null
5268 eval "$CMD4 2>${te}4 &"
5269 pid4=$!
5270 wait $pid6
5271 if ! (echo "$da"; sleep 2) |diff - "$tf" >"$tdiff"; then
5272 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5273 echo "$CMD1 &"
5274 cat "${te}1"
5275 echo "$CMD2 &"
5276 cat "${te}2"
5277 echo "$CMD3 &"
5278 cat "${te}3"
5279 echo "$CMD5 &"
5280 cat "${te}5"
5281 echo "$CMD6"
5282 cat "${te}6"
5283 echo "$CMD4 &"
5284 cat "${te}4"
5285 cat "$tdiff"
5286 numFAIL=$((numFAIL+1))
5287 listFAIL="$listFAIL $N"
5288 else
5289 $PRINTF "$OK\n"
5290 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" "${te}6"; fi
5291 numOK=$((numOK+1))
5293 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
5294 wait
5295 fi ;; # NUMCOND, feats
5296 esac
5297 PORT=$((PORT+5))
5298 N=$((N+1))
5301 # test the TCP gender changer with almost production requirements: a double
5302 # client repeatedly tries to connect to a double server via SSL through an HTTP
5303 # proxy. the double servers SSL port becomes active for one connection only
5304 # after a (real) client has connected to its TCP port. when the double client
5305 # succeeded to establish an SSL connection, it connects with its second client
5306 # side to the specified (protected) server. all three consecutive connections
5307 # must function for full success of this test.
5308 PORT=$((RANDOM+16184))
5310 NAME=INTRANETRIPPER
5311 case "$TESTS" in
5312 *%$N%*|*%functions%*|*%openssl%*|*%proxy%*|*%$NAME%*)
5313 TEST="$NAME: gender changer via SSL through HTTP proxy, daemons"
5314 if ! eval $NUMCOND; then :;
5315 elif ! feat=$(testaddrs openssl proxy); then
5316 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5317 numCANT=$((numCANT+1))
5318 else
5319 gentestcert testsrv
5320 gentestcert testcli
5321 tf="$td/test$N.stdout"
5322 te="$td/test$N.stderr"
5323 tdiff="$td/test$N.diff"
5324 da1="test$N.1 $(date) $RANDOM"
5325 da2="test$N.2 $(date) $RANDOM"
5326 da3="test$N.3 $(date) $RANDOM"
5327 # this is the server in the protected network that we want to reach
5328 CMD1="$TRACE $SOCAT $opts -lpserver -t1 tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST,fork echo"
5329 # this is the proxy in the protected network that provides a way out
5330 # note: the proxy.sh script starts one or two more socat processes without
5331 # setting the program name
5332 CMD2="$TRACE $SOCAT $opts -lpproxy -t1 tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5333 # this is our proxy connect wrapper in the protected network
5334 CMD3="$TRACE $SOCAT $opts -lpwrapper -t3 tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
5335 # this is our double client in the protected network using SSL
5336 CMD4="$TRACE $SOCAT $opts -lp2client -t3 ssl:$LOCALHOST:$((PORT+2)),retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,verify,fork,$SOCAT_EGD tcp4:$LOCALHOST:$PORT,forever,interval=0.1"
5337 # this is the double server in the outside network
5338 CMD5="$TRACE $SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,backlog=3,fork ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt,retry=20,interval=0.5"
5339 # this is the outside client that wants to use the protected server
5340 CMD6="$TRACE $SOCAT $opts -lpclient -t6 - tcp4:$LOCALHOST:$((PORT+4)),retry=3"
5341 printf "test $F_n $TEST... " $N
5342 # start the intranet infrastructure
5343 eval "$CMD1 2>\"${te}1\" &"
5344 pid1=$!
5345 eval "$CMD2 2>\"${te}2\" &"
5346 pid2=$!
5347 waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
5348 waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
5349 # initiate our internal measures
5350 eval "$CMD3 2>\"${te}3\" &"
5351 pid3=$!
5352 eval "$CMD4 2>\"${te}4\" &"
5353 pid4=$!
5354 waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
5355 # now we start the external daemon
5356 eval "$CMD5 2>\"${te}5\" &"
5357 pid5=$!
5358 waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
5359 # and this is the outside client:
5360 echo "$da1" |$CMD6 >${tf}_1 2>"${te}6_1" &
5361 pid6_1=$!
5362 echo "$da2" |$CMD6 >${tf}_2 2>"${te}6_2" &
5363 pid6_2=$!
5364 echo "$da3" |$CMD6 >${tf}_3 2>"${te}6_3" &
5365 pid6_3=$!
5366 wait $pid6_1 $pid6_2 $pid6_3
5368 (echo "$da1"; sleep 2) |diff - "${tf}_1" >"${tdiff}1"
5369 (echo "$da2"; sleep 2) |diff - "${tf}_2" >"${tdiff}2"
5370 (echo "$da3"; sleep 2) |diff - "${tf}_3" >"${tdiff}3"
5371 if test -s "${tdiff}1" -o -s "${tdiff}2" -o -s "${tdiff}3"; then
5372 # FAILED only when none of the three transfers succeeded
5373 if test -s "${tdiff}1" -a -s "${tdiff}2" -a -s "${tdiff}3"; then
5374 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5375 echo "$CMD1 &"
5376 cat "${te}1"
5377 echo "$CMD2 &"
5378 cat "${te}2"
5379 echo "$CMD3 &"
5380 cat "${te}3"
5381 echo "$CMD4 &"
5382 cat "${te}4"
5383 echo "$CMD5 &"
5384 cat "${te}5"
5385 echo "$CMD6 &"
5386 cat "${te}6_1"
5387 cat "${tdiff}1"
5388 echo "$CMD6 &"
5389 cat "${te}6_2"
5390 cat "${tdiff}2"
5391 echo "$CMD6 &"
5392 cat "${te}6_3"
5393 cat "${tdiff}3"
5394 numFAIL=$((numFAIL+1))
5395 listFAIL="$listFAIL $N"
5396 else
5397 $PRINTF "$OK ${YELLOW}(partial failure)${NORMAL}\n"
5398 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5399 numOK=$((numOK+1))
5401 else
5402 $PRINTF "$OK\n"
5403 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5404 numOK=$((numOK+1))
5406 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
5407 wait
5408 fi ;; # NUMCOND, feats
5409 esac
5410 PORT=$((PORT+5))
5411 N=$((N+1))
5414 # let us test the security features with -s, retry, and fork
5415 # method: first test without security feature if it works
5416 # then try with security feature, must fail
5418 # test the security features of a server address
5419 testserversec () {
5420 local N="$1"
5421 local title="$2"
5422 local opts="$3"
5423 local arg1="$4" # the server address
5424 local secopt0="$5" # option without security for server, mostly empty
5425 local secopt1="$6" # the security option for server, to be tested
5426 local arg2="$7" # the client address
5427 local ipvers="$8" # IP version, for check of listen port
5428 local proto="$9" # protocol, for check of listen port
5429 local port="${10}" # start client when this port is listening
5430 local expect="${11}" # expected behaviour of client: 0..empty output; -1..error
5431 local T="${12}"; [ -z "$T" ] && T=0
5432 local tf="$td/test$N.stdout"
5433 local te="$td/test$N.stderr"
5434 local tdiff1="$td/test$N.diff1"
5435 local tdiff2="$td/test$N.diff2"
5436 local da="test$N.1 $(date) $RANDOM"
5437 local stat result
5439 $PRINTF "test $F_n %s... " $N "$title"
5440 # first: without security
5441 # start server
5442 $TRACE $SOCAT $opts "$arg1,$secopt0" echo 2>"${te}1" &
5443 spid=$!
5444 if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
5445 kill $spid 2>/dev/null
5446 $PRINTF "$NO_RESULT (ph.1 server not working):\n"
5447 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5448 cat "${te}1"
5449 numCANT=$((numCANT+1))
5450 wait; return
5452 # now use client
5453 (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}2"
5454 stat="$?"
5455 kill $spid 2>/dev/null
5456 #killall $TRACE $SOCAT 2>/dev/null
5457 if [ "$stat" != 0 ]; then
5458 $PRINTF "$NO_RESULT (ph.1 function fails): $TRACE $SOCAT:\n"
5459 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5460 cat "${te}1"
5461 echo "$TRACE $SOCAT $opts - \"$arg2\""
5462 cat "${te}2"
5463 numCANT=$((numCANT+1))
5464 wait; return
5465 elif echo "$da" |diff - "$tf" >"$tdiff1" 2>&1; then
5466 : # function without security is ok, go on
5467 else
5468 $PRINTF "$NO_RESULT (ph.1 function fails): diff:\n"
5469 echo "$TRACE $SOCAT $opts $arg1,$secopt0 echo &"
5470 cat "${te}1"
5471 echo "$TRACE $SOCAT $opts - $arg2"
5472 cat "${te}2"
5473 cat "$tdiff1"
5474 numCANT=$((numCANT+1))
5475 wait; return
5478 # then: with security
5479 if [ "$port" ] && ! wait${proto}${ipvers}port $port 0; then
5480 $PRINTF "$NO_RESULT (ph.1 port remains in use)\n"
5481 numCANT=$((numCANT+1))
5482 wait; return
5484 wait
5486 #set -vx
5487 # assemble address w/ security option; on dual, take read part:
5488 case "$arg1" in
5489 *!!*) arg="${arg1%!!*},$secopt1!!${arg1#*!!}" ;;
5490 *) arg="$arg1,$secopt1" ;;
5491 esac
5492 # start server
5493 # use -s to make sure that it fails due to a sec violation, not some other failure
5494 CMD3="$TRACE $SOCAT $opts -s $arg echo"
5495 $CMD3 2>"${te}3" &
5496 spid=$!
5497 if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
5498 kill $spid 2>/dev/null
5499 $PRINTF "$NO_RESULT (ph.2 server not working)\n"
5500 wait
5501 echo "$CMD3"
5502 cat "${te}3"
5503 numCANT=$((numCANT+1))
5504 return
5506 # now use client
5507 da="test$N.2 $(date) $RANDOM"
5508 (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}4"
5509 stat=$?
5510 kill $spid 2>/dev/null
5511 #set +vx
5512 #killall $TRACE $SOCAT 2>/dev/null
5513 if [ "$stat" != 0 ]; then
5514 result=-1; # socat had error
5515 elif [ ! -s "$tf" ]; then
5516 result=0; # empty output
5517 elif echo "$da" |diff - "$tf" >"$tdiff2" 2>&1; then
5518 result=1; # output is copy of input
5519 else
5520 result=2; # output differs from input
5522 if [ X$result != X$expect ]; then
5523 case X$result in
5524 X-1) $PRINTF "$NO_RESULT (ph.2 client error): $TRACE $SOCAT:\n"
5525 echo "$TRACE $SOCAT $opts $arg echo"
5526 cat "${te}3"
5527 echo "$TRACE $SOCAT $opts - $arg2"
5528 cat "${te}4"
5529 numCANT=$((numCANT+1)) ;;
5530 X0) $PRINTF "$NO_RESULT (ph.2 diff failed): diff:\n"
5531 echo "$TRACE $SOCAT $opts $arg echo"
5532 cat "${te}3"
5533 echo "$TRACE $SOCAT $opts - $arg2"
5534 cat "${te}4"
5535 cat "$tdiff2"
5536 numCANT=$((numCANT+1)) ;;
5537 X1) $PRINTF "$FAILED: SECURITY BROKEN\n"
5538 echo "$TRACE $SOCAT $opts $arg echo"
5539 cat "${te}3"
5540 echo "$TRACE $SOCAT $opts - $arg2"
5541 cat "${te}4"
5542 cat "$tdiff2"
5543 numFAIL=$((numFAIL+1))
5544 listFAIL="$listFAIL $N" ;;
5545 X2) $PRINTF "$FAILED: diff:\n"
5546 echo "$TRACE $SOCAT $opts $arg echo"
5547 cat "${te}3"
5548 echo "$TRACE $SOCAT $opts - $arg2"
5549 cat "${te}4"
5550 cat "$tdiff2"
5551 numFAIL=$((numFAIL+1))
5552 listFAIL="$listFAIL $N" ;;
5553 esac
5554 else
5555 $PRINTF "$OK\n"
5556 [ "$VERBOSE" ] && echo " $TRACE $SOCAT $opts $arg echo"
5557 [ "$debug" ] && cat ${te}3
5558 [ "$VERBOSE" ] && echo " $TRACE $SOCAT $opts - $arg2"
5559 [ "$debug" ] && cat ${te}4
5560 numOK=$((numOK+1))
5562 wait
5563 #set +vx
5567 NAME=TCP4RANGEBITS
5568 case "$TESTS" in
5569 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5570 TEST="$NAME: security of TCP4-L with RANGE option"
5571 if ! eval $NUMCOND; then :;
5572 elif [ -z "$SECONDADDR" ]; then
5573 # we need access to a second addresses
5574 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5575 numCANT=$((numCANT+1))
5576 else
5577 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5578 fi ;; # $SECONDADDR, NUMCOND
5579 esac
5580 PORT=$((PORT+1))
5581 N=$((N+1))
5583 NAME=TCP4RANGEMASK
5584 case "$TESTS" in
5585 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5586 TEST="$NAME: security of TCP4-L with RANGE option"
5587 if ! eval $NUMCOND; then :;
5588 elif [ -z "$SECONDADDR" ]; then
5589 # we need access to a second addresses
5590 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5591 numCANT=$((numCANT+1))
5592 else
5593 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR:255.255.255.255" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5594 fi ;; # $SECONDADDR, NUMCOND
5595 esac
5596 PORT=$((PORT+1))
5597 N=$((N+1))
5599 # like TCP4RANGEMASK, but the "bad" address is within the same class A network
5600 NAME=TCP4RANGEMASKHAIRY
5601 case "$TESTS" in
5602 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5603 TEST="$NAME: security of TCP4-L with RANGE option"
5604 if ! eval $NUMCOND; then :; else
5605 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=127.0.0.0:255.255.0.0" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp $PORT 0
5606 fi ;; # Linux, NUMCOND
5607 esac
5608 PORT=$((PORT+1))
5609 N=$((N+1))
5612 NAME=TCP4SOURCEPORT
5613 case "$TESTS" in
5614 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
5615 TEST="$NAME: security of TCP4-L with SOURCEPORT option"
5616 if ! eval $NUMCOND; then :; else
5617 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5618 fi ;; # NUMCOND
5619 esac
5620 PORT=$((PORT+1))
5621 N=$((N+1))
5623 NAME=TCP4LOWPORT
5624 case "$TESTS" in
5625 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
5626 TEST="$NAME: security of TCP4-L with LOWPORT option"
5627 if ! eval $NUMCOND; then :; else
5628 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5629 fi ;; # NUMCOND
5630 esac
5631 PORT=$((PORT+1))
5632 N=$((N+1))
5634 NAME=TCP4WRAPPERS_ADDR
5635 case "$TESTS" in
5636 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5637 TEST="$NAME: security of TCP4-L with TCPWRAP option"
5638 if ! eval $NUMCOND; then :;
5639 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
5640 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5641 numCANT=$((numCANT+1))
5642 else
5643 ha="$td/hosts.allow"
5644 hd="$td/hosts.deny"
5645 $ECHO "socat: $SECONDADDR" >"$ha"
5646 $ECHO "ALL: ALL" >"$hd"
5647 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5648 fi ;; # NUMCOND, feats
5649 esac
5650 PORT=$((PORT+1))
5651 N=$((N+1))
5653 NAME=TCP4WRAPPERS_NAME
5654 case "$TESTS" in
5655 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5656 TEST="$NAME: security of TCP4-L with TCPWRAP option"
5657 if ! eval $NUMCOND; then :;
5658 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
5659 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5660 numCANT=$((numCANT+1))
5661 else
5662 ha="$td/hosts.allow"
5663 hd="$td/hosts.deny"
5664 $ECHO "socat: $LOCALHOST" >"$ha"
5665 $ECHO "ALL: ALL" >"$hd"
5666 testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp $PORT 0
5667 fi ;; # NUMCOND, feats
5668 esac
5669 PORT=$((PORT+1))
5670 N=$((N+1))
5673 NAME=TCP6RANGE
5674 case "$TESTS" in
5675 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%range%*|*%$NAME%*)
5676 TEST="$NAME: security of TCP6-L with RANGE option"
5677 if ! eval $NUMCOND; then :;
5678 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5679 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5680 numCANT=$((numCANT+1))
5681 else
5682 testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "range=[::2]/128" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5683 fi ;; # NUMCOND, feats
5684 esac
5685 PORT=$((PORT+1))
5686 N=$((N+1))
5688 NAME=TCP6SOURCEPORT
5689 case "$TESTS" in
5690 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
5691 TEST="$NAME: security of TCP6-L with SOURCEPORT option"
5692 if ! eval $NUMCOND; then :;
5693 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5694 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5695 numCANT=$((numCANT+1))
5696 else
5697 testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5698 fi ;; # NUMCOND, feats
5699 esac
5700 PORT=$((PORT+1))
5701 N=$((N+1))
5703 NAME=TCP6LOWPORT
5704 case "$TESTS" in
5705 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
5706 TEST="$NAME: security of TCP6-L with LOWPORT option"
5707 if ! eval $NUMCOND; then :;
5708 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5709 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5710 numCANT=$((numCANT+1))
5711 else
5712 testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5713 fi ;; # NUMCOND, feats
5714 esac
5715 PORT=$((PORT+1))
5716 N=$((N+1))
5718 NAME=TCP6TCPWRAP
5719 case "$TESTS" in
5720 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
5721 TEST="$NAME: security of TCP6-L with TCPWRAP option"
5722 if ! eval $NUMCOND; then :;
5723 elif ! feat=$(testaddrs tcp ip6 libwrap) || ! runsip6 >/dev/null; then
5724 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5725 numCANT=$((numCANT+1))
5726 else
5727 ha="$td/hosts.allow"
5728 hd="$td/hosts.deny"
5729 $ECHO "socat: [::2]" >"$ha"
5730 $ECHO "ALL: ALL" >"$hd"
5731 testserversec "$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5732 fi ;; # NUMCOND, feats
5733 esac
5734 PORT=$((PORT+1))
5735 N=$((N+1))
5738 NAME=UDP4RANGE
5739 case "$TESTS" in
5740 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5741 TEST="$NAME: security of UDP4-L with RANGE option"
5742 if ! eval $NUMCOND; then :; else
5743 #testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5744 testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5745 fi ;; # NUMCOND
5746 esac
5747 PORT=$((PORT+1))
5748 N=$((N+1))
5750 NAME=UDP4SOURCEPORT
5751 case "$TESTS" in
5752 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
5753 TEST="$NAME: security of UDP4-L with SOURCEPORT option"
5754 if ! eval $NUMCOND; then :; else
5755 testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "sp=$PORT" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5756 fi ;; # NUMCOND
5757 esac
5758 PORT=$((PORT+1))
5759 N=$((N+1))
5761 NAME=UDP4LOWPORT
5762 case "$TESTS" in
5763 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
5764 TEST="$NAME: security of UDP4-L with LOWPORT option"
5765 if ! eval $NUMCOND; then :; else
5766 testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "lowport" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5767 fi ;; # NUMCOND
5768 esac
5769 PORT=$((PORT+1))
5770 N=$((N+1))
5772 NAME=UDP4TCPWRAP
5773 case "$TESTS" in
5774 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5775 TEST="$NAME: security of UDP4-L with TCPWRAP option"
5776 if ! eval $NUMCOND; then :;
5777 elif ! feat=$(testaddrs udp ip4 libwrap) || ! runsip4 >/dev/null; then
5778 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5779 numCANT=$((numCANT+1))
5780 else
5781 ha="$td/hosts.allow"
5782 hd="$td/hosts.deny"
5783 $ECHO "socat: $SECONDADDR" >"$ha"
5784 $ECHO "ALL: ALL" >"$hd"
5785 testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5786 fi ;; # NUMCOND, feats
5787 esac
5788 PORT=$((PORT+1))
5789 N=$((N+1))
5792 NAME=UDP6RANGE
5793 case "$TESTS" in
5794 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
5795 TEST="$NAME: security of UDP6-L with RANGE option"
5796 if ! eval $NUMCOND; then :;
5797 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5798 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5799 numCANT=$((numCANT+1))
5800 else
5801 #testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr,fork" "" "range=[::2]/128" "udp6:[::1]:$PORT" 6 udp $PORT 0
5802 testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "range=[::2]/128" "udp6:[::1]:$PORT" 6 udp $PORT 0
5803 fi ;; # NUMCOND, feats
5804 esac
5805 PORT=$((PORT+1))
5806 N=$((N+1))
5808 NAME=UDP6SOURCEPORT
5809 case "$TESTS" in
5810 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
5811 TEST="$NAME: security of UDP6-L with SOURCEPORT option"
5812 if ! eval $NUMCOND; then :;
5813 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
5814 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
5815 numCANT=$((numCANT+1))
5816 else
5817 testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "sp=$PORT" "udp6:[::1]:$PORT" 6 udp $PORT 0
5818 fi ;; # NUMCOND, feats
5819 esac
5820 PORT=$((PORT+1))
5821 N=$((N+1))
5823 NAME=UDP6LOWPORT
5824 case "$TESTS" in
5825 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
5826 TEST="$NAME: security of UDP6-L with LOWPORT option"
5827 if ! eval $NUMCOND; then :;
5828 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
5829 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
5830 numCANT=$((numCANT+1))
5831 else
5832 testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
5833 fi ;; # NUMCOND, feats
5834 esac
5835 PORT=$((PORT+1))
5836 N=$((N+1))
5838 NAME=UDP6TCPWRAP
5839 case "$TESTS" in
5840 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
5841 TEST="$NAME: security of UDP6-L with TCPWRAP option"
5842 if ! eval $NUMCOND; then :;
5843 elif ! feat=$(testaddrs tcp ip6 libwrap) || ! runsip6 >/dev/null; then
5844 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5845 numCANT=$((numCANT+1))
5846 else
5847 ha="$td/hosts.allow"
5848 hd="$td/hosts.deny"
5849 $ECHO "socat: [::2]" >"$ha"
5850 $ECHO "ALL: ALL" >"$hd"
5851 testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
5852 fi ;; # NUMCOND, feats
5853 esac
5854 PORT=$((PORT+1))
5855 N=$((N+1))
5858 NAME=OPENSSLTCP4_RANGE
5859 case "$TESTS" in
5860 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%range%*|*%$NAME%*)
5861 TEST="$NAME: security of SSL-L over TCP/IPv4 with RANGE option"
5862 if ! eval $NUMCOND; then :;
5863 elif ! testaddrs openssl >/dev/null; then
5864 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5865 numCANT=$((numCANT+1))
5866 else
5867 gentestcert testsrv
5868 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "range=$SECONDADDR/32" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
5869 fi ;; # NUMCOND, feats
5870 esac
5871 PORT=$((PORT+1))
5872 N=$((N+1))
5874 NAME=OPENSSLTCP4_SOURCEPORT
5875 case "$TESTS" in
5876 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
5877 TEST="$NAME: security of SSL-L with SOURCEPORT option"
5878 if ! eval $NUMCOND; then :;
5879 elif ! testaddrs openssl >/dev/null; then
5880 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5881 numCANT=$((numCANT+1))
5882 else
5883 gentestcert testsrv
5884 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "sp=$PORT" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
5885 fi ;; # NUMCOND, feats
5886 esac
5887 PORT=$((PORT+1))
5888 N=$((N+1))
5890 NAME=OPENSSLTCP4_LOWPORT
5891 case "$TESTS" in
5892 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%lowport%*|*%$NAME%*)
5893 TEST="$NAME: security of SSL-L with LOWPORT option"
5894 if ! eval $NUMCOND; then :;
5895 elif ! testaddrs openssl >/dev/null; then
5896 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5897 numCANT=$((numCANT+1))
5898 else
5899 gentestcert testsrv
5900 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "lowport" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
5901 fi ;; # NUMCOND, feats
5902 esac
5903 PORT=$((PORT+1))
5904 N=$((N+1))
5906 NAME=OPENSSLTCP4_TCPWRAP
5907 case "$TESTS" in
5908 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
5909 TEST="$NAME: security of SSL-L with TCPWRAP option"
5910 if ! eval $NUMCOND; then :;
5911 elif ! feat=$(testaddrs ip4 tcp libwrap openssl); then
5912 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5913 numCANT=$((numCANT+1))
5914 else
5915 gentestcert testsrv
5916 ha="$td/hosts.allow"
5917 hd="$td/hosts.deny"
5918 $ECHO "socat: $SECONDADDR" >"$ha"
5919 $ECHO "ALL: ALL" >"$hd"
5920 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "tcpwrap-etc=$td" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp $PORT -1
5921 fi ;; # NUMCOND, feats
5922 esac
5923 PORT=$((PORT+1))
5924 N=$((N+1))
5926 NAME=OPENSSLCERTSERVER
5927 case "$TESTS" in
5928 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
5929 TEST="$NAME: security of SSL-L with client certificate"
5930 if ! eval $NUMCOND; then :;
5931 elif ! testaddrs openssl >/dev/null; then
5932 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5933 numCANT=$((numCANT+1))
5934 else
5935 gentestcert testsrv
5936 gentestcert testcli
5937 testserversec "$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify,cert=testsrv.crt,key=testsrv.key" "cafile=testcli.crt" "cafile=testsrv.crt" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,cert=testcli.pem,$SOCAT_EGD" 4 tcp $PORT -1
5938 fi ;; # NUMCOND, feats
5939 esac
5940 PORT=$((PORT+1))
5941 N=$((N+1))
5943 NAME=OPENSSLCERTCLIENT
5944 case "$TESTS" in
5945 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
5946 TEST="$NAME: security of SSL with server certificate"
5947 if ! eval $NUMCOND; then :;
5948 elif ! testaddrs openssl >/dev/null; then
5949 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5950 numCANT=$((numCANT+1))
5951 else
5952 gentestcert testsrv
5953 gentestcert testcli
5954 testserversec "$N" "$TEST" "$opts -lu -d" "ssl:$LOCALHOST:$PORT,pf=ip4,fork,retry=2,verify,cert=testcli.pem,$SOCAT_EGD" "cafile=testsrv.crt" "cafile=testcli.crt" "ssl-l:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cafile=testcli.crt,cert=testsrv.crt,key=testsrv.key" 4 tcp "" -1
5955 fi ;; # NUMCOND, feats
5956 esac
5957 PORT=$((PORT+1))
5958 N=$((N+1))
5961 NAME=OPENSSLTCP6_RANGE
5962 case "$TESTS" in
5963 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%range%*|*%$NAME%*)
5964 TEST="$NAME: security of SSL-L over TCP/IPv6 with RANGE option"
5965 if ! eval $NUMCOND; then :;
5966 elif ! testaddrs openssl >/dev/null; then
5967 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5968 numCANT=$((numCANT+1))
5969 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5970 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5971 numCANT=$((numCANT+1))
5972 else
5973 gentestcert6 testsrv6
5974 testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "range=[::2]/128" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
5975 fi ;; # NUMCOND, feats
5976 esac
5977 PORT=$((PORT+1))
5978 N=$((N+1))
5980 NAME=OPENSSLTCP6_SOURCEPORT
5981 case "$TESTS" in
5982 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
5983 TEST="$NAME: security of SSL-L over TCP/IPv6 with SOURCEPORT option"
5984 if ! eval $NUMCOND; then :;
5985 elif ! testaddrs openssl >/dev/null; then
5986 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5987 numCANT=$((numCANT+1))
5988 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5989 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5990 numCANT=$((numCANT+1))
5991 else
5992 gentestcert6 testsrv6
5993 testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "sp=$PORT" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
5994 fi ;; # NUMCOND, feats
5995 esac
5996 PORT=$((PORT+1))
5997 N=$((N+1))
5999 NAME=OPENSSLTCP6_LOWPORT
6000 case "$TESTS" in
6001 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%lowport%*|*%$NAME%*)
6002 TEST="$NAME: security of SSL-L over TCP/IPv6 with LOWPORT option"
6003 if ! eval $NUMCOND; then :;
6004 elif ! testaddrs openssl >/dev/null; then
6005 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6006 numCANT=$((numCANT+1))
6007 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
6008 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6009 numCANT=$((numCANT+1))
6010 else
6011 gentestcert6 testsrv6
6012 testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "lowport" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
6013 fi ;; # NUMCOND, feats
6014 esac
6015 PORT=$((PORT+1))
6016 N=$((N+1))
6018 NAME=OPENSSLTCP6_TCPWRAP
6019 case "$TESTS" in
6020 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
6021 TEST="$NAME: security of SSL-L over TCP/IPv6 with TCPWRAP option"
6022 if ! eval $NUMCOND; then :;
6023 elif ! feat=$(testaddrs ip6 tcp libwrap openssl) || ! runsip6 >/dev/null; then
6024 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6025 numCANT=$((numCANT+1))
6026 else
6027 gentestcert6 testsrv6
6028 ha="$td/hosts.allow"
6029 hd="$td/hosts.deny"
6030 $ECHO "socat: [::2]" >"$ha"
6031 $ECHO "ALL: ALL" >"$hd"
6032 testserversec "$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "tcpwrap-etc=$td" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp $PORT -1
6033 fi ;; # NUMCOND, feats
6034 esac
6035 PORT=$((PORT+1))
6036 N=$((N+1))
6039 # test security with the openssl-commonname option on client side
6040 NAME=OPENSSL_CN_CLIENT_SECURITY
6041 case "$TESTS" in
6042 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6043 TEST="$NAME: security of client openssl-commonname option"
6044 # connect using non matching server name/address with commonname
6045 # options, this should succeed. Then without this option, should fail
6046 if ! eval $NUMCOND; then :;
6047 elif ! testaddrs openssl >/dev/null; then
6048 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6049 numCANT=$((numCANT+1))
6050 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6051 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6052 numCANT=$((numCANT+1))
6053 else
6054 gentestcert testsrv
6055 gentestcert testcli
6056 testserversec "$N" "$TEST" "$opts -4" "SSL:127.0.0.1:$PORT,fork,retry=2,verify,cafile=testsrv.crt" "commonname=$LOCALHOST" "" "SSL-L:$PORT,pf=ip4,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0" 4 tcp "" 0
6057 fi ;; # testaddrs, NUMCOND
6058 esac
6059 PORT=$((PORT+1))
6060 N=$((N+1))
6062 # test security with the openssl-commonname option on server side
6063 NAME=OPENSSL_CN_SERVER_SECURITY
6064 case "$TESTS" in
6065 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6066 TEST="$NAME: security of server openssl-commonname option"
6067 # connect using with client certificate to server, this should succeed.
6068 # Then use the server with a non matching openssl-commonname option,
6069 # this must fail
6070 if ! eval $NUMCOND; then :;
6071 elif ! testaddrs openssl >/dev/null; then
6072 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6073 numCANT=$((numCANT+1))
6074 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6075 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6076 numCANT=$((numCANT+1))
6077 else
6078 gentestcert testsrv
6079 gentestcert testcli
6080 testserversec "$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt" "" "commonname=onlyyou" "SSL:$LOCALHOST:$PORT,$REUSEADDR,verify=0,cafile=testsrv.crt,cert=testcli.crt,key=testcli.key" 4 tcp "" 0
6081 fi ;; # testaddrs, NUMCOND
6082 esac
6083 PORT=$((PORT+1))
6084 N=$((N+1))
6087 NAME=OPENSSL_FIPS_SECURITY
6088 case "$TESTS" in
6089 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
6090 TEST="$NAME: OpenSSL restrictions by FIPS"
6091 if ! eval $NUMCOND; then :;
6092 elif ! testaddrs openssl >/dev/null; then
6093 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6094 numCANT=$((numCANT+1))
6095 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
6096 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6097 numCANT=$((numCANT+1))
6098 elif ! testoptions fips >/dev/null; then
6099 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
6100 numCANT=$((numCANT+1))
6101 else
6102 gentestcert testsrv
6103 gentestcert testcli
6104 # openssl client accepts a "normal" certificate only when not in fips mode
6105 testserversec "$N" "$TEST" "$opts" "ssl:$LOCALHOST:$PORT,fork,retry=2,verify,cafile=testsrv.crt" "" "fips" "SSL-L:$PORT,pf=ip4,$REUSEADDR,cert=testsrv.crt,key=testsrv.key" 4 tcp "" -1
6106 fi ;; # testaddrs, NUMCOND
6107 esac
6108 PORT=$((PORT+1))
6109 N=$((N+1))
6112 NAME=UNIEXECEOF
6113 case "$TESTS" in
6114 *%$N%*|*%functions%*|*%$NAME%*)
6115 TEST="$NAME: give exec'd write-only process a chance to flush (-u)"
6116 testod "$N" "$TEST" "" exec:"$OD_C" "$opts -u"
6117 esac
6118 N=$((N+1))
6121 NAME=REVEXECEOF
6122 case "$TESTS" in
6123 *%$N%*|*%functions%*|*%$NAME%*)
6124 TEST="$NAME: give exec'd write-only process a chance to flush (-U)"
6125 testod "$N" "$TEST" exec:"$OD_C" "-" "$opts -U"
6126 esac
6127 N=$((N+1))
6130 NAME=FILANDIR
6131 case "$TESTS" in
6132 *%$N%*|*%filan%*|*%$NAME%*)
6133 TEST="$NAME: check type printed for directories"
6134 if ! eval $NUMCOND; then :; else
6135 te="$td/test$N.stderr"
6136 printf "test $F_n $TEST... " $N
6137 type=$($FILAN -f . 2>$te |tail -n 1 |awk '{print($2);}')
6138 if [ "$type" = "dir" ]; then
6139 $PRINTF "$OK\n"
6140 numOK=$((numOK+1))
6141 else
6142 $PRINTF "$FAILED\n"
6143 cat "$te"
6144 numFAIL=$((numFAIL+1))
6145 listFAIL="$listFAIL $N"
6147 fi ;; # NUMCOND
6148 esac
6149 N=$((N+1))
6152 NAME=FILANSOCKET
6153 case "$TESTS" in
6154 *%$N%*|*%filan%*|*%$NAME%*)
6155 TEST="$NAME: capability to analyze named unix socket"
6156 if ! eval $NUMCOND; then :; else
6157 ts="$td/test$N.socket"
6158 te1="$td/test$N.stderr1" # socat
6159 te2="$td/test$N.stderr2" # filan
6160 printf "test $F_n $TEST... " $N
6161 $TRACE $SOCAT $opts UNIX-LISTEN:"$ts" /dev/null </dev/null 2>"$te1" &
6162 spid=$!
6163 waitfile "$ts" 1
6164 type=$($FILAN -f "$ts" 2>$te2 |tail -n 1 |awk '{print($2);}')
6165 if [ "$type" = "socket" ]; then
6166 $PRINTF "$OK\n"
6167 numOK=$((numOK+1))
6168 else
6169 $PRINTF "$FAILED\n"
6170 cat "$te1"
6171 cat "$te2"
6172 numFAIL=$((numFAIL+1))
6173 listFAIL="$listFAIL $N"
6175 kill $spid 2>/dev/null
6176 wait
6177 fi ;; # NUMCOND
6178 esac
6179 N=$((N+1))
6182 testptywaitslave () {
6183 local N="$1"
6184 local TEST="$2"
6185 local PTYTYPE="$3" # ptmx or openpty
6186 local opts="$4"
6188 local tp="$td/test$N.pty"
6189 local ts="$td/test$N.socket"
6190 local tf="$td/test$N.file"
6191 local tdiff="$td/test$N.diff"
6192 local te1="$td/test$N.stderr1"
6193 local te2="$td/test$N.stderr2"
6194 local te3="$td/test$N.stderr3"
6195 local te4="$td/test$N.stderr4"
6196 local da="test$N $(date) $RANDOM"
6197 printf "test $F_n $TEST... " $N
6198 # first generate a pty, then a socket
6199 ($TRACE $SOCAT $opts -lpsocat1 pty,$PTYTYPE,pty-wait-slave,link="$tp" unix-listen:"$ts" 2>"$te1"; rm -f "$tp") 2>/dev/null &
6200 pid=$!
6201 waitfile "$tp"
6202 # if pty was non-blocking, the socket is active, and socat1 will term
6203 $TRACE $SOCAT $opts -T 10 -lpsocat2 file:/dev/null unix-connect:"$ts" 2>"$te2"
6204 # if pty is blocking, first socat is still active and we get a connection now
6205 #((echo "$da"; sleep 2) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6206 ( (waitfile "$ts"; echo "$da"; sleep 1) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6207 waitfile "$ts"
6208 # but we need an echoer on the socket
6209 $TRACE $SOCAT $opts -lpsocat4 unix:"$ts" echo 2>"$te4"
6210 # now $tf file should contain $da
6211 #kill $pid 2>/dev/null
6212 wait
6214 if echo "$da" |diff - "$tf"> "$tdiff"; then
6215 $PRINTF "$OK\n"
6216 numOK=$((numOK+1))
6217 else
6218 $PRINTF "${YELLOW}FAILED${NORMAL}\n"
6219 cat "$te1"
6220 #cat "$te2" # not of interest
6221 cat "$te3"
6222 cat "$te4"
6223 cat "$tdiff"
6224 numCANT=$((numCANT+1))
6228 NAME=PTMXWAITSLAVE
6229 PTYTYPE=ptmx
6230 case "$TESTS" in
6231 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6232 TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6233 if ! eval $NUMCOND; then :; else
6234 if ! feat=$(testaddrs pty); then
6235 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6236 numCANT=$((numCANT+1))
6237 elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
6238 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6239 numCANT=$((numCANT+1))
6240 else
6241 testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
6243 fi ;; # NUMCOND
6244 esac
6245 N=$((N+1))
6247 NAME=OPENPTYWAITSLAVE
6248 PTYTYPE=openpty
6249 case "$TESTS" in
6250 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6251 TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6252 if ! eval $NUMCOND; then :;
6253 elif ! feat=$(testaddrs pty); then
6254 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6255 numCANT=$((numCANT+1))
6256 elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
6257 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6258 numCANT=$((numCANT+1))
6259 else
6260 testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
6261 fi ;; # NUMCOND, feats
6262 esac
6263 N=$((N+1))
6266 NAME=CONNECTTIMEOUT
6267 case "$TESTS" in
6268 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
6269 TEST="$NAME: test the connect-timeout option"
6270 if ! eval $NUMCOND; then :;
6271 elif ! feat=$(testaddrs tcp); then
6272 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6273 numCANT=$((numCANT+1))
6274 elif ! feat=$(testoptions connect-timeout); then
6275 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6276 numCANT=$((numCANT+1))
6277 else
6278 # we need a hanging connection attempt, guess an address for this
6279 case "$UNAME" in
6280 Linux) HANGIP=1.0.0.1 ;;
6281 *) HANGIP=255.255.255.254 ;;
6282 esac
6283 te1="$td/test$N.stderr1"
6284 tk1="$td/test$N.kill1"
6285 te2="$td/test$N.stderr2"
6286 tk2="$td/test$N.kill2"
6287 $PRINTF "test $F_n $TEST... " $N
6288 # first, try to make socat hang and see if it can be killed
6289 #$TRACE $SOCAT $opts - tcp:$HANGIP:1 >"$te1" 2>&1 </dev/null &
6290 CMD="$TRACE $SOCAT $opts - tcp:$HANGIP:1"
6291 $CMD >"$te1" 2>&1 </dev/null &
6292 pid1=$!
6293 sleep 2
6294 if ! kill $pid1 2>"$tk1"; then
6295 $PRINTF "${YELLOW}does not hang${NORMAL}\n"
6296 numCANT=$((numCANT+1))
6297 else
6298 # second, set connect-timeout and see if socat exits before kill
6299 $TRACE $SOCAT $opts - tcp:$HANGIP:1,connect-timeout=1.0 >"$te2" 2>&1 </dev/null &
6300 pid2=$!
6301 sleep 2
6302 if kill $pid2 2>"$tk2"; then
6303 $PRINTF "$FAILED\n"
6304 echo "$CMD"
6305 cat "$te1"
6306 cat "$te2"
6307 numFAIL=$((numFAIL+1))
6308 listFAIL="$listFAIL $N"
6309 else
6310 $PRINTF "$OK\n"
6311 numOK=$((numOK+1))
6314 wait
6315 fi ;; # testaddrs, NUMCOND
6316 esac
6317 N=$((N+1))
6320 # version 1.7.0.0 had a bug with the connect-timeout option: while it correctly
6321 # terminated a hanging connect attempt, it prevented a successful connection
6322 # establishment from being recognized by socat, instead the timeout occurred
6323 NAME=CONNECTTIMEOUT_CONN
6324 if ! eval $NUMCOND; then :; else
6325 case "$TESTS" in
6326 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
6327 TEST="$NAME: TCP4 connect-timeout option when server replies"
6328 # just try a connection that is expected to succeed with the usual data
6329 # transfer; with the bug it will fail
6330 tf="$td/test$N.stdout"
6331 te="$td/test$N.stderr"
6332 tdiff="$td/test$N.diff"
6333 tsl=$PORT
6334 ts="127.0.0.1:$tsl"
6335 da="test$N $(date) $RANDOM"
6336 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
6337 CMD2="$TRACE $SOCAT $opts STDIO TCP4:$ts,connect-timeout=1"
6338 printf "test $F_n $TEST... " $N
6339 $CMD1 >"$tf" 2>"${te}1" &
6340 pid1=$!
6341 waittcp4port $tsl 1
6342 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6343 if [ $? -ne 0 ]; then
6344 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6345 echo "$CMD1 &"
6346 cat "${te}1"
6347 echo "$CMD2"
6348 cat "${te}2"
6349 numFAIL=$((numFAIL+1))
6350 listFAIL="$listFAIL $N"
6351 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6352 $PRINTF "$FAILED\n"
6353 cat "$tdiff"
6354 numFAIL=$((numFAIL+1))
6355 listFAIL="$listFAIL $N"
6356 else
6357 $PRINTF "$OK\n"
6358 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
6359 numOK=$((numOK+1))
6361 kill $pid1 2>/dev/null
6362 wait ;;
6363 esac
6364 PORT=$((PORT+1))
6365 fi # NUMCOND
6366 N=$((N+1))
6369 NAME=OPENSSLLISTENDSA
6370 case "$TESTS" in
6371 *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
6372 TEST="$NAME: openssl listen with DSA certificate"
6373 if ! eval $NUMCOND; then :;
6374 elif ! testaddrs openssl >/dev/null; then
6375 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6376 numCANT=$((numCANT+1))
6377 else
6378 SRVCERT=testsrvdsa
6379 gentestdsacert $SRVCERT
6380 tf="$td/test$N.stdout"
6381 te="$td/test$N.stderr"
6382 tdiff="$td/test$N.diff"
6383 da="test$N $(date) $RANDOM"
6384 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=$SRVCERT.pem,key=$SRVCERT.key,verify=0 pipe"
6385 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
6386 $PRINTF "test $F_n $TEST... " $N
6387 eval "$CMD2 2>\"${te}1\" &"
6388 pid=$! # background process id
6389 waittcp4port $PORT
6390 echo "$da" |$CMD >$tf 2>"${te}2"
6391 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
6392 $PRINTF "$FAILED\n"
6393 echo "$CMD2 &"
6394 echo "$CMD"
6395 cat "${te}1"
6396 cat "${te}2"
6397 cat "$tdiff"
6398 numFAIL=$((numFAIL+1))
6399 listFAIL="$listFAIL $N"
6400 else
6401 $PRINTF "$OK\n"
6402 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
6403 numOK=$((numOK+1))
6405 kill $pid 2>/dev/null
6406 wait
6407 fi ;; # testaddrs, NUMCOND
6408 esac
6409 PORT=$((PORT+1))
6410 N=$((N+1))
6413 # derive signal number from signal name
6414 # kill -l should provide the info
6415 signum () {
6416 if [ ! "$BASH_VERSION" -o -o posix ]; then
6417 # we expect:
6418 for i in $(POSIXLY_CORRECT=1 kill -l); do echo "$i"; done |grep -n -i "^$1$" |cut -d: -f1
6419 else
6420 # expect:
6421 # " 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL"
6422 signam="$1"
6423 kill -l </dev/null |
6424 while read l; do printf "%s %s\n%s %s\n%s %s\n%s %s\n" $l; done |
6425 grep -e "SIG$signam\$" |
6426 cut -d ')' -f 1
6430 # problems with QUIT, INT (are blocked in system() )
6431 for signam in TERM ILL; do
6432 NAME=EXITCODESIG$signam
6433 case "$TESTS" in
6434 *%$N%*|*%functions%*|*%pty%*|*%signal%*|*%$NAME%*)
6435 TEST="$NAME: exit status when dying on SIG$signam"
6436 if ! eval $NUMCOND; then :;
6437 elif ! feat=$(testaddrs pty); then
6438 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
6439 numCANT=$((numCANT+1))
6440 else
6441 SIG="$(signum $signam)"
6442 te="$td/test$N.stderr"
6443 tpp="$td/test$N.ppid"
6444 tp="$td/test$N.pid"
6445 $PRINTF "test $F_n $TEST... " $N
6446 (sleep 1; kill -"$SIG" "$(cat "$tpp")") &
6447 # a simple "system:echo $PPID..." does not work on NetBSD, OpenBSD
6448 #$TRACE $SOCAT $opts echo SYSTEM:'exec /usr/bin/env bash -c "echo \$PPID '">$tpp"'; echo \$$ '">$tp; read x\"",nofork 2>"$te"; stat=$?
6449 tsh="$td/test$N.sh"
6450 cat <<EOF >"$tsh"
6451 #! /usr/bin/env bash
6452 echo \$PPID >"$tpp"
6453 echo \$\$ >"$tp"
6454 read x
6456 chmod a+x "$tsh"
6457 #$TRACE $SOCAT $opts echo SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"; stat=$?
6458 CMD="$TRACE $SOCAT $opts ECHO SYSTEM:\"exec\\\ \\\"$tsh\\\"\",pty,setsid,nofork"
6459 $TRACE $SOCAT $opts ECHO SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"
6460 stat=$?
6461 sleep 1; kill -INT $(cat $tp)
6462 wait
6463 if [ "$stat" -eq $((128+$SIG)) ]; then
6464 $PRINTF "$OK\n"
6465 numOK=$((numOK+1))
6466 else
6467 $PRINTF "$FAILED\n"
6468 echo "$CMD"
6469 cat "$te"
6470 numFAIL=$((numFAIL+1))
6471 listFAIL="$listFAIL $N"
6473 wait
6474 fi ;; # NUMCOND, feats
6475 esac
6476 N=$((N+1))
6477 done
6480 NAME=READBYTES
6481 #set -vx
6482 case "$TESTS" in
6483 *%$N%*|*%functions%*|*%$NAME%*)
6484 TEST="$NAME: restrict reading from file with bytes option"
6485 if ! eval $NUMCOND; then :;
6486 elif false; then
6487 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6488 numCANT=$((numCANT+1))
6489 else
6490 tr="$td/test$N.ref"
6491 ti="$td/test$N.in"
6492 to="$td/test$N.out"
6493 te="$td/test$N.err"
6494 tdiff="$td/test$N.diff"
6495 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
6496 # the feature that we really want to test is in the readline.sh script:
6497 CMD="$TRACE $SOCAT $opts -u open:$ti,readbytes=100 -"
6498 printf "test $F_n $TEST... " $N
6499 rm -f "$tf" "$ti" "$to"
6501 echo "AAAAAAAAAAAAAAAAAAAAAAAA
6502 AAAAAAAAAAAAAAAAAAAAAAAA
6503 AAAAAAAAAAAAAAAAAAAAAAAA
6504 AAAAAAAAAAAAAAAAAAAAAAAA" >"$tr" # 100 bytes
6505 cat "$tr" "$tr" >"$ti" # 200 bytes
6506 $CMD >"$to" 2>"$te"
6507 if ! diff "$tr" "$to" >"$tdiff" 2>&1; then
6508 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6509 echo "$CMD"
6510 cat "$te"
6511 cat "$tdiff"
6512 numFAIL=$((numFAIL+1))
6513 listFAIL="$listFAIL $N"
6514 else
6515 $PRINTF "$OK\n"
6516 if [ -n "$debug" ]; then cat $te; fi
6517 numOK=$((numOK+1))
6519 fi ;; # NUMCOND, feats
6520 esac
6521 N=$((N+1))
6524 NAME=UDPLISTENFORK
6525 case "$TESTS" in
6526 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%listen%*|*%fork%*|*%$NAME%*)
6527 TEST="$NAME: UDP socket rebinds after first connection"
6528 if ! eval $NUMCOND; then :; else
6529 tf="$td/test$N.stdout"
6530 te="$td/test$N.stderr"
6531 tdiff="$td/test$N.diff"
6532 da1="test$N $(date) $RANDOM"
6533 da2="test$N $(date) $RANDOM"
6534 #establish a listening and forking udp socket in background
6535 #processes hang forever without -T
6536 SRV="$TRACE $SOCAT -T 5 $opts -lpserver UDP4-LISTEN:$PORT,bind=$LOCALHOST,$REUSEADDR,fork PIPE"
6537 #make a first and a second connection
6538 CLI="$TRACE $SOCAT $opts -lpclient - UDP4-CONNECT:$LOCALHOST:$PORT"
6539 $PRINTF "test $F_n $TEST... " $N
6540 eval "$SRV 2>${te}s &"
6541 pids=$!
6542 waitudp4port "$PORT"
6543 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6544 if [ $? -ne 0 ]; then
6545 kill "$pids" 2>/dev/null
6546 $PRINTF "$NO_RESULT (first conn failed):\n"
6547 echo "$SRV &"
6548 echo "$CLI"
6549 cat "${te}s" "${te}1"
6550 numCANT=$((numCANT+1))
6551 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6552 kill "$pids" 2>/dev/null
6553 $PRINTF "$NO_RESULT (first conn failed); diff:\n"
6554 cat "$tdiff"
6555 numCANT=$((numCANT+1))
6556 else
6557 sleep 2 # UDP-LISTEN sleeps 1s
6558 echo "$da2" |eval "$CLI" >"${tf}2" 2>"${te}2"
6559 rc="$?"; kill "$pids" 2>/dev/null
6560 if [ $rc -ne 0 ]; then
6561 $PRINTF "$FAILED:\n"
6562 echo "$SRV &"
6563 echo "$CLI"
6564 cat "${te}s" "${te}2"
6565 numFAIL=$((numFAIL+1))
6566 listFAIL="$listFAIL $N"
6567 elif ! echo "$da2" |diff - "${tf}2" >"$tdiff"; then
6568 $PRINTF "$FAILED: diff\n"
6569 cat "$tdiff"
6570 numFAIL=$((numFAIL+1))
6571 listFAIL="$listFAIL $N"
6572 else
6573 $PRINTF "$OK\n"
6574 numOK=$((numOK+1))
6575 fi # !( $? -ne 0)
6576 fi # !(rc -ne 0)
6577 wait
6578 fi ;; # NUMCOND, feats
6579 esac
6580 PORT=$((PORT+1))
6581 N=$((N+1))
6584 # is a listen address capable of forking to child processes and have both
6585 # active?
6586 while read PROTOV MAJADDR MINADDR; do
6587 if [ -z "$PROTOV" ] || [[ "$PROTOV" == \#* ]]; then continue; fi
6588 protov="$(echo "$PROTOV" |tr A-Z a-z)"
6589 proto="${protov%%[0-9]}"
6590 NAME=${PROTOV}LISTENFORK
6591 case "$TESTS" in
6592 *%$N%*|*%functions%*|*%$protov%*|*%$proto%*|*%listen%*|*%fork%*|*%$NAME%*)
6593 TEST="$NAME: $PROTOV listen handles 2 concurrent connections"
6594 # have a listening address with fork option. connect with client1, send a piece
6595 # of data, wait 1s, connect with client2, send another piece of data, wait 1s,
6596 # and send another piece of data with client1. The server processes append all
6597 # data to the same file. Check all data are written to the file in correct
6598 # order.
6599 if ! eval $NUMCOND; then :;
6600 #elif ! feat=$(testaddrs $PROTOV); then
6601 # $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$PROTOV" |tr a-z A-Z) not available${NORMAL}\n" $N
6602 # numCANT=$((numCANT+1))
6603 elif ! runs$protov; then
6604 $PRINTF "test $F_n $TEST... ${YELLOW}$PROTOV not available${NORMAL}\n" $N
6605 numCANT=$((numCANT+1))
6606 else
6607 ts="$td/test$N.sock"
6608 tref="$td/test$N.ref"
6609 tf="$td/test$N.stdout"
6610 te="$td/test$N.stderr"
6611 tdiff="$td/test$N.diff"
6612 da1a="test$N $(date) 1a $RANDOM"
6613 da1b="test$N $(date) 1b $RANDOM"
6614 da2="test$N $(date) 2 $RANDOM"
6615 case "$MAJADDR" in
6616 "FILE")
6617 tla="$ts"
6618 tca="$ts"
6619 waitproto="file"
6620 waitfor="$ts" ;;
6621 esac
6622 case "$MINADDR" in
6623 "PORT")
6624 tla="$PORT,bind=$MAJADDR"
6625 tca="$MAJADDR:$PORT"
6626 waitproto="${protov}port"
6627 waitfor="$PORT" ;;
6628 esac
6629 #set -xv
6630 echo -e "$da1a\n$da2\n$da1b" >"$tref"
6631 # establish a listening and forking listen socket in background
6632 # UDP processes hang forever without -T
6633 CMD0="$TRACE $SOCAT -T 5 $opts -lpserver $PROTOV-LISTEN:$tla,$REUSEADDR,fork PIPE"
6634 # make a first and a second connection
6635 CMD1="$TRACE $SOCAT $opts -lpclient - $PROTOV-CONNECT:$tca"
6636 $PRINTF "test $F_n $TEST... " $N
6637 eval "$CMD0 2>${te}0 &"
6638 pid0=$!
6639 wait$waitproto "$waitfor" 1 2
6640 (echo "$da1a"; sleep 2; echo "$da1b") |eval "$CMD1" >>"${tf}" 2>"${te}1" &
6641 sleep 1
6642 # trailing sleep req for sctp because no half close
6643 (echo "$da2"; sleep 1) |eval "$CMD1" >>"${tf}" 2>"${te}2" &
6644 sleep 2
6645 kill $pid0 2>/dev/null
6646 wait
6647 if ! diff "$tref" "$tf" >"$tdiff"; then
6648 $PRINTF "$FAILED\n"
6649 cat "${te}0" "${te}1" "${te}2"
6650 cat "$tdiff"
6651 numFAIL=$((numFAIL+1))
6652 listFAIL="$listFAIL $N"
6653 else
6654 $PRINTF "$OK\n"
6655 numOK=$((numOK+1))
6656 fi # !(rc -ne 0)
6657 wait
6658 fi ;; # NUMCOND, feats
6659 esac
6660 PORT=$((PORT+1))
6661 N=$((N+1))
6662 done <<<"
6663 TCP4 $LOCALHOST PORT
6664 TCP6 $LOCALHOST6 PORT
6665 UDP4 $LOCALHOST PORT
6666 UDP6 $LOCALHOST6 PORT
6667 SCTP4 $LOCALHOST PORT
6668 SCTP6 $LOCALHOST6 PORT
6669 UNIX FILE ,
6673 NAME=UNIXTOSTREAM
6674 case "$TESTS" in
6675 *%$N%*|*%functions%*|*%unix%*|*%listen%*|*%$NAME%*)
6676 TEST="$NAME: generic UNIX client connects to stream socket"
6677 if ! eval $NUMCOND; then :; else
6678 ts="$td/test$N.socket"
6679 tf="$td/test$N.stdout"
6680 te="$td/test$N.stderr"
6681 tdiff="$td/test$N.diff"
6682 da1="test$N $(date) $RANDOM"
6683 #establish a listening unix socket in background
6684 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
6685 #make a connection
6686 CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts\""
6687 $PRINTF "test $F_n $TEST... " $N
6688 eval "$SRV 2>${te}s &"
6689 pids=$!
6690 waitfile "$ts"
6691 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6692 if [ $? -ne 0 ]; then
6693 kill "$pids" 2>/dev/null
6694 $PRINTF "$FAILED:\n"
6695 echo "$SRV &"
6696 echo "$CLI"
6697 cat "${te}s" "${te}1"
6698 numFAIL=$((numFAIL+1))
6699 listFAIL="$listFAIL $N"
6700 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6701 kill "$pids" 2>/dev/null
6702 $PRINTF "$FAILED; diff:\n"
6703 cat "$tdiff"
6704 numFAIL=$((numFAIL+1))
6705 listFAIL="$listFAIL $N"
6706 else
6707 $PRINTF "$OK\n"
6708 numOK=$((numOK+1))
6709 fi # !(rc -ne 0)
6710 wait
6711 fi ;; # NUMCOND
6712 esac
6713 N=$((N+1))
6716 NAME=UNIXTODGRAM
6717 case "$TESTS" in
6718 *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%recv%*|*%$NAME%*)
6719 TEST="$NAME: generic UNIX client connects to datagram socket"
6720 if ! eval $NUMCOND; then :; else
6721 ts1="$td/test$N.socket1"
6722 ts2="$td/test$N.socket2"
6723 tf="$td/test$N.stdout"
6724 te="$td/test$N.stderr"
6725 tdiff="$td/test$N.diff"
6726 da1="test$N $(date) $RANDOM"
6727 #establish a receiving unix datagram socket in background
6728 SRV="$TRACE $SOCAT $opts -lpserver UNIX-RECVFROM:\"$ts1\" PIPE"
6729 #make a connection
6730 CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\",bind=\"$ts2\""
6731 #CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\""
6732 $PRINTF "test $F_n $TEST... " $N
6733 eval "$SRV 2>${te}s &"
6734 pids=$!
6735 waitfile "$ts1"
6736 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6737 rc=$?
6738 wait
6739 if [ $rc -ne 0 ]; then
6740 kill "$pids" 2>/dev/null
6741 $PRINTF "$FAILED:\n"
6742 echo "$SRV &"
6743 cat "${te}s"
6744 echo "$CLI"
6745 cat "${te}1" "${te}1"
6746 numFAIL=$((numFAIL+1))
6747 listFAIL="$listFAIL $N"
6748 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6749 kill "$pids" 2>/dev/null
6750 $PRINTF "$FAILED:\n"
6751 echo "$SRV &"
6752 cat "${te}s"
6753 echo "$CLI"
6754 cat "${te}1"
6755 cat "$tdiff"
6756 numFAIL=$((numFAIL+1))
6757 listFAIL="$listFAIL $N"
6758 else
6759 $PRINTF "$OK\n"
6760 numOK=$((numOK+1))
6761 fi # !(rc -ne 0)
6762 fi ;; # NUMCOND
6763 esac
6764 N=$((N+1))
6767 # there was an error in address EXEC with options pipes,stderr
6768 NAME=EXECPIPESSTDERR
6769 case "$TESTS" in
6770 *%$N%*|*%functions%*|*%$NAME%*)
6771 TEST="$NAME: simple echo via exec of cat with pipes,stderr"
6772 # this test is known to fail when logging is enabled with OPTS/opts env var.
6773 SAVE_opts="$opts"
6774 opts="$(echo "$opts" |sed 's/-d//g')"
6775 testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
6776 opts="$SAVE_opts"
6777 esac
6778 N=$((N+1))
6780 # EXEC and SYSTEM with stderr injected socat messages into the data stream.
6781 NAME=EXECSTDERRLOG
6782 case "$TESTS" in
6783 *%$N%*|*%functions%*|*%$NAME%*)
6784 TEST="$NAME: simple echo via exec of cat with pipes,stderr"
6785 SAVE_opts="$opts"
6786 # make sure at least two -d are there
6787 case "$opts" in
6788 *-d*-d*) ;;
6789 *-d*) opts="$opts -d" ;;
6790 *) opts="-d -d" ;;
6791 esac
6792 testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
6793 opts="$SAVE_opts"
6794 esac
6795 N=$((N+1))
6798 NAME=SIMPLEPARSE
6799 case "$TESTS" in
6800 *%$N%*|*%functions%*|*%PARSE%*|*%$NAME%*)
6801 TEST="$NAME: invoke socat from socat"
6802 testecho "$N" "$TEST" "" exec:"$SOCAT - exec\:$CAT,pipes" "$opts"
6803 esac
6804 N=$((N+1))
6807 NAME=FULLPARSE
6808 case "$TESTS" in
6809 *%$N%*|*%functions%*|*%parse%*|*%$NAME%*)
6810 TEST="$NAME: correctly parse special chars"
6811 if ! eval $NUMCOND; then :; else
6812 $PRINTF "test $F_n $TEST... " $N
6813 tf="$td/test$N.stdout"
6814 te="$td/test$N.stderr"
6815 tdiff="$td/test$N.diff"
6816 # a string where commas are hidden in nesting lexical constructs
6817 # if they are scanned incorrectly, socat will see an "unknown option"
6818 dain='(,)[,]{,}","([),])hugo'
6819 daout='(,)[,]{,},([),])hugo'
6820 $TRACE "$SOCAT" $opts -u "exec:echo $dain" - >"$tf" 2>"$te"
6821 rc=$?
6822 echo "$daout" |diff "$tf" - >"$tdiff"
6823 if [ "$rc" -ne 0 ]; then
6824 $PRINTF "$FAILED:\n"
6825 echo "$TRACE $SOCAT" -u "exec:echo $da" -
6826 cat "$te"
6827 numFAIL=$((numFAIL+1))
6828 listFAIL="$listFAIL $N"
6829 elif [ -s "$tdiff" ]; then
6830 $PRINTF "$FAILED:\n"
6831 echo diff:
6832 cat "$tdiff"
6833 if [ -n "$debug" ]; then cat $te; fi
6834 numFAIL=$((numFAIL+1))
6835 listFAIL="$listFAIL $N"
6836 else
6837 $PRINTF "$OK\n"
6838 if [ -n "$debug" ]; then cat $te; fi
6839 numOK=$((numOK+1))
6841 fi ;; # NUMCOND
6842 esac
6843 N=$((N+1))
6845 NAME=NESTEDSOCATEXEC
6846 case "$TESTS" in
6847 *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
6848 TEST="$NAME: does lexical analysis work sensibly (exec)"
6849 testecho "$N" "$TEST" "" "exec:'$SOCAT - exec:$CAT,pipes'" "$opts" 1
6850 esac
6851 N=$((N+1))
6853 NAME=NESTEDSOCATSYSTEM
6854 case "$TESTS" in
6855 *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
6856 TEST="$NAME: does lexical analysis work sensibly (system)"
6857 testecho "$N" "$TEST" "" "system:\"$SOCAT - exec:$CAT,pipes\"" "$opts" 1
6858 esac
6859 N=$((N+1))
6862 NAME=TCP6BYTCP4
6863 case "$TESTS" in
6864 *%$N%*|*%functions%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
6865 TEST="$NAME: TCP4 mapped into TCP6 address space"
6866 if ! eval $NUMCOND; then :;
6867 elif true; then
6868 $PRINTF "test $F_n $TEST... ${YELLOW}Feature reoved${NORMAL}\n" $N
6869 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
6870 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6871 numCANT=$((numCANT+1))
6872 else
6873 tf="$td/test$N.stdout"
6874 te="$td/test$N.stderr"
6875 tdiff="$td/test$N.diff"
6876 tsl=$PORT
6877 ts="127.0.0.1:$tsl"
6878 da="test$N $(date) $RANDOM"
6879 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,$REUSEADDR PIPE"
6880 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
6881 printf "test $F_n $TEST... " $N
6882 $CMD1 >"$tf" 2>"${te}1" &
6883 pid=$! # background process id
6884 waittcp6port $tsl 1
6885 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6886 if [ $? -ne 0 ]; then
6887 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6888 echo "$CMD1 &"
6889 echo "$CMD2"
6890 cat "${te}1"
6891 cat "${te}2"
6892 numFAIL=$((numFAIL+1))
6893 listFAIL="$listFAIL $N"
6894 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6895 $PRINTF "$FAILED: diff:\n"
6896 cat "$tdiff"
6897 numFAIL=$((numFAIL+1))
6898 listFAIL="$listFAIL $N"
6899 else
6900 $PRINTF "$OK\n"
6901 if [ -n "$debug" ]; then cat $te; fi
6902 numOK=$((numOK+1))
6904 kill $pid 2>/dev/null; wait
6905 fi ;; # NUMCOND, feats
6906 esac
6907 PORT=$((PORT+1))
6908 N=$((N+1))
6911 # test the UDP4-SENDTO and UDP4-RECVFROM addresses together
6912 NAME=UDP4DGRAM
6913 case "$TESTS" in
6914 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%$NAME%*)
6915 TEST="$NAME: UDP/IPv4 sendto and recvfrom"
6916 # start a UDP4-RECVFROM process that echoes data, and send test data using
6917 # UDP4-SENDTO. The sent data should be returned.
6918 if ! eval $NUMCOND; then :; else
6919 tf="$td/test$N.stdout"
6920 te="$td/test$N.stderr"
6921 tdiff="$td/test$N.diff"
6922 ts1p=$PORT; PORT=$((PORT+1))
6923 ts1a="127.0.0.1"
6924 ts1="$ts1a:$ts1p"
6925 ts2p=$PORT; PORT=$((PORT+1))
6926 ts2="127.0.0.1:$ts2p"
6927 da="test$N $(date) $RANDOM"
6928 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
6929 CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=$ts2"
6930 printf "test $F_n $TEST... " $N
6931 $CMD1 2>"${te}1" &
6932 pid1="$!"
6933 waitudp4port $ts1p 1
6934 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6935 rc2="$?"
6936 kill "$pid1" 2>/dev/null; wait;
6937 if [ "$rc2" -ne 0 ]; then
6938 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6939 echo "$CMD1 &"
6940 cat "${te}1"
6941 echo "$CMD2"
6942 cat "${te}2"
6943 numFAIL=$((numFAIL+1))
6944 listFAIL="$listFAIL $N"
6945 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6946 $PRINTF "$FAILED\n"
6947 cat "$tdiff"
6948 echo "$CMD1 &"
6949 cat "${te}1"
6950 echo "$CMD2"
6951 cat "${te}2"
6952 numFAIL=$((numFAIL+1))
6953 listFAIL="$listFAIL $N"
6954 else
6955 $PRINTF "$OK\n"
6956 if [ -n "$debug" ]; then cat $te; fi
6957 numOK=$((numOK+1))
6959 fi # NUMCOND
6961 esac
6962 PORT=$((PORT+1))
6963 N=$((N+1))
6966 NAME=UDP6DGRAM
6967 case "$TESTS" in
6968 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%$NAME%*)
6969 TEST="$NAME: UDP/IPv6 datagram"
6970 if ! eval $NUMCOND; then :;
6971 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
6972 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6973 numCANT=$((numCANT+1))
6974 else
6975 tf="$td/test$N.stdout"
6976 te="$td/test$N.stderr"
6977 tdiff="$td/test$N.diff"
6978 ts1p=$PORT; PORT=$((PORT+1))
6979 tsa="[::1]"
6980 ts1="$tsa:$ts1p"
6981 ts2p=$PORT; PORT=$((PORT+1))
6982 ts2="$tsa:$ts2p"
6983 da="test$N $(date) $RANDOM"
6984 CMD1="$TRACE $SOCAT $opts UDP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
6985 CMD2="$TRACE $SOCAT $opts - UDP6-SENDTO:$ts1,bind=$ts2"
6986 printf "test $F_n $TEST... " $N
6987 $CMD1 2>"${te}1" &
6988 waitudp6port $ts1p 1
6989 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6990 if [ $? -ne 0 ]; then
6991 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6992 echo "$CMD1 &"
6993 echo "$CMD2"
6994 cat "${te}1"
6995 cat "${te}2"
6996 numFAIL=$((numFAIL+1))
6997 listFAIL="$listFAIL $N"
6998 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6999 $PRINTF "$FAILED\n"
7000 cat "$tdiff"
7001 numFAIL=$((numFAIL+1))
7002 listFAIL="$listFAIL $N"
7003 else
7004 $PRINTF "$OK\n"
7005 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
7006 numOK=$((numOK+1))
7008 fi ;; # NUMCOND, feats
7009 esac
7010 PORT=$((PORT+1))
7011 N=$((N+1))
7014 NAME=RAWIP4RECVFROM
7015 case "$TESTS" in
7016 *%$N%*|*%functions%*|*%ip%*|*%ip4%*|*%rawip%*|*%rawip4%*|*%dgram%*|*%root%*|*%$NAME%*)
7017 TEST="$NAME: raw IPv4 datagram"
7018 if ! eval $NUMCOND; then :;
7019 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7020 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7021 numCANT=$((numCANT+1))
7022 else
7023 tf="$td/test$N.stdout"
7024 te="$td/test$N.stderr"
7025 tdiff="$td/test$N.diff"
7026 ts1p=$PROTO; PROTO=$((PROTO+1))
7027 ts1a="127.0.0.1"
7028 ts1="$ts1a:$ts1p"
7029 ts2a="$SECONDADDR"
7030 ts2="$ts2a:$ts2p"
7031 da="test$N $(date) $RANDOM"
7032 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
7033 CMD2="$TRACE $SOCAT $opts - IP4-SENDTO:$ts1,bind=$ts2a"
7034 printf "test $F_n $TEST... " $N
7035 $CMD1 2>"${te}1" &
7036 pid1=$!
7037 waitip4proto $ts1p 1
7038 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7039 rc2=$?
7040 kill $pid1 2>/dev/null; wait
7041 if [ $rc2 -ne 0 ]; then
7042 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7043 echo "$CMD1 &"
7044 echo "$CMD2"
7045 cat "${te}1"
7046 cat "${te}2"
7047 numFAIL=$((numFAIL+1))
7048 listFAIL="$listFAIL $N"
7049 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7050 $PRINTF "$FAILED\n"
7051 cat "$tdiff"
7052 numFAIL=$((numFAIL+1))
7053 listFAIL="$listFAIL $N"
7054 else
7055 $PRINTF "$OK\n"
7056 if [ -n "$debug" ]; then cat $te; fi
7057 numOK=$((numOK+1))
7059 fi ;; # root, NUMCOND
7060 esac
7061 N=$((N+1))
7064 if false; then
7065 NAME=RAWIP6RECVFROM
7066 case "$TESTS" in
7067 *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%dgram%*|*%root%*|*%$NAME%*)
7068 TEST="$NAME: raw IPv6 datagram by self addressing"
7069 if ! eval $NUMCOND; then :;
7070 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7071 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7072 numCANT=$((numCANT+1))
7073 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7074 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7075 numCANT=$((numCANT+1))
7076 else
7077 tf="$td/test$N.stdout"
7078 te="$td/test$N.stderr"
7079 tdiff="$td/test$N.diff"
7080 ts1p=$PROTO; PROTO=$((PROTO+1))
7081 tsa="[::1]"
7082 ts1="$tsa:$ts1p"
7083 ts2="$tsa"
7084 da="test$N $(date) $RANDOM"
7085 #CMD1="$TRACE $SOCAT $opts IP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
7086 CMD2="$TRACE $SOCAT $opts - IP6-SENDTO:$ts1,bind=$ts2"
7087 printf "test $F_n $TEST... " $N
7088 #$CMD1 2>"${te}1" &
7089 waitip6proto $ts1p 1
7090 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7091 if [ $? -ne 0 ]; then
7092 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7093 # echo "$CMD1 &"
7094 # cat "${te}1"
7095 echo "$CMD2"
7096 cat "${te}2"
7097 numFAIL=$((numFAIL+1))
7098 listFAIL="$listFAIL $N"
7099 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7100 $PRINTF "$FAILED\n"
7101 cat "$tdiff"
7102 numFAIL=$((numFAIL+1))
7103 listFAIL="$listFAIL $N"
7104 else
7105 $PRINTF "$OK\n"
7106 if [ -n "$debug" ]; then cat "$te"; fi
7107 numOK=$((numOK+1))
7109 fi ;; # root, NUMCOND
7110 esac
7111 N=$((N+1))
7112 fi #false
7115 NAME=UNIXDGRAM
7116 case "$TESTS" in
7117 *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%dgram%*|*%$NAME%*)
7118 TEST="$NAME: UNIX datagram"
7119 if ! eval $NUMCOND; then :; else
7120 tf="$td/test$N.stdout"
7121 te="$td/test$N.stderr"
7122 tdiff="$td/test$N.diff"
7123 ts1="$td/test$N.socket1"
7124 ts2="$td/test$N.socket2"
7125 da="test$N $(date) $RANDOM"
7126 CMD1="$TRACE $SOCAT $opts UNIX-RECVFROM:$ts1,reuseaddr PIPE"
7127 CMD2="$TRACE $SOCAT $opts - UNIX-SENDTO:$ts1,bind=$ts2"
7128 printf "test $F_n $TEST... " $N
7129 $CMD1 2>"${te}1" &
7130 pid1="$!"
7131 waitfile $ts1 1
7132 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7133 rc2=$?
7134 kill "$pid1" 2>/dev/null; wait
7135 if [ $rc2 -ne 0 ]; then
7136 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7137 echo "$CMD1 &"
7138 cat "${te}1"
7139 echo "$CMD2"
7140 cat "${te}2"
7141 numFAIL=$((numFAIL+1))
7142 listFAIL="$listFAIL $N"
7143 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7144 $PRINTF "$FAILED\n"
7145 cat "$tdiff"
7146 numFAIL=$((numFAIL+1))
7147 listFAIL="$listFAIL $N"
7148 else
7149 $PRINTF "$OK\n"
7150 if [ -n "$debug" ]; then cat $te; fi
7151 numOK=$((numOK+1))
7153 fi # NUMCOND
7155 esac
7156 N=$((N+1))
7159 NAME=UDP4RECV
7160 case "$TESTS" in
7161 *%$N%*|*%functions%*|*%engine%*|*%ip4%*|*%dgram%*|*%udp%*|*%udp4%*|*%recv%*|*%$NAME%*)
7162 TEST="$NAME: UDP/IPv4 receive"
7163 if ! eval $NUMCOND; then :; else
7164 tf="$td/test$N.stdout"
7165 te="$td/test$N.stderr"
7166 tdiff="$td/test$N.diff"
7167 ts1p=$PORT; PORT=$((PORT+1))
7168 ts1a="127.0.0.1"
7169 ts1="$ts1a:$ts1p"
7170 da="test$N $(date) $RANDOM"
7171 CMD1="$TRACE $SOCAT $opts -u UDP4-RECV:$ts1p,reuseaddr -"
7172 CMD2="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1"
7173 printf "test $F_n $TEST... " $N
7174 $CMD1 >"$tf" 2>"${te}1" &
7175 pid1="$!"
7176 waitudp4port $ts1p 1
7177 echo "$da" |$CMD2 2>>"${te}2"
7178 rc2="$?"
7179 #ls -l $tf
7180 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7181 kill "$pid1" 2>/dev/null; wait
7182 if [ "$rc2" -ne 0 ]; then
7183 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7184 echo "$CMD1 &"
7185 echo "$CMD2"
7186 cat "${te}1"
7187 cat "${te}2"
7188 numFAIL=$((numFAIL+1))
7189 listFAIL="$listFAIL $N"
7190 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7191 $PRINTF "$FAILED\n"
7192 cat "$tdiff"
7193 echo "$CMD1 &"
7194 echo "$CMD2"
7195 cat "${te}1"
7196 cat "${te}2"
7197 numFAIL=$((numFAIL+1))
7198 listFAIL="$listFAIL $N"
7199 else
7200 $PRINTF "$OK\n"
7201 if [ -n "$debug" ]; then cat $te; fi
7202 numOK=$((numOK+1))
7204 fi # NUMCOND
7206 esac
7207 N=$((N+1))
7210 NAME=UDP6RECV
7211 case "$TESTS" in
7212 *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%udp%*|*%udp6%*|*%recv%*|*%$NAME%*)
7213 TEST="$NAME: UDP/IPv6 receive"
7214 if ! eval $NUMCOND; then :;
7215 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
7216 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7217 numCANT=$((numCANT+1))
7218 else
7219 tf="$td/test$N.stdout"
7220 te="$td/test$N.stderr"
7221 tdiff="$td/test$N.diff"
7222 ts1p=$PORT; PORT=$((PORT+1))
7223 ts1a="[::1]"
7224 ts1="$ts1a:$ts1p"
7225 da="test$N $(date) $RANDOM"
7226 CMD1="$TRACE $SOCAT $opts -u UDP6-RECV:$ts1p,reuseaddr -"
7227 CMD2="$TRACE $SOCAT $opts -u - UDP6-SENDTO:$ts1"
7228 printf "test $F_n $TEST... " $N
7229 $CMD1 >"$tf" 2>"${te}1" &
7230 pid1="$!"
7231 waitudp6port $ts1p 1
7232 echo "$da" |$CMD2 2>>"${te}2"
7233 rc2="$?"
7234 #ls -l $tf
7235 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7236 kill "$pid1" 2>/dev/null; wait
7237 if [ "$rc2" -ne 0 ]; then
7238 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7239 echo "$CMD1 &"
7240 echo "$CMD2"
7241 cat "${te}1"
7242 cat "${te}2"
7243 numFAIL=$((numFAIL+1))
7244 listFAIL="$listFAIL $N"
7245 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7246 $PRINTF "$FAILED\n"
7247 cat "$tdiff"
7248 numFAIL=$((numFAIL+1))
7249 listFAIL="$listFAIL $N"
7250 else
7251 $PRINTF "$OK\n"
7252 if [ -n "$debug" ]; then cat $te; fi
7253 numOK=$((numOK+1))
7255 fi ;; # NUMCOND, feats
7256 esac
7257 N=$((N+1))
7260 NAME=RAWIP4RECV
7261 case "$TESTS" in
7262 *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
7263 TEST="$NAME: raw IPv4 receive"
7264 if ! eval $NUMCOND; then :;
7265 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7266 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7267 numCANT=$((numCANT+1))
7268 else
7269 tf="$td/test$N.stdout"
7270 te="$td/test$N.stderr"
7271 tdiff="$td/test$N.diff"
7272 ts1p=$PROTO; PROTO=$((PROTO+1))
7273 ts1a="127.0.0.1"
7274 ts1="$ts1a:$ts1p"
7275 da="test$N $(date) $RANDOM"
7276 CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,reuseaddr -"
7277 CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
7278 printf "test $F_n $TEST... " $N
7279 $CMD1 >"$tf" 2>"${te}1" &
7280 pid1="$!"
7281 waitip4proto $ts1p 1
7282 echo "$da" |$CMD2 2>>"${te}2"
7283 rc2="$?"
7284 #ls -l $tf
7285 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7286 kill "$pid1" 2>/dev/null; wait
7287 if [ "$rc2" -ne 0 ]; then
7288 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7289 echo "$CMD1 &"
7290 echo "$CMD2"
7291 cat "${te}1"
7292 cat "${te}2"
7293 numFAIL=$((numFAIL+1))
7294 listFAIL="$listFAIL $N"
7295 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7296 $PRINTF "$FAILED\n"
7297 cat "$tdiff"
7298 numFAIL=$((numFAIL+1))
7299 listFAIL="$listFAIL $N"
7300 else
7301 $PRINTF "$OK\n"
7302 if [ -n "$debug" ]; then cat $te; fi
7303 numOK=$((numOK+1))
7305 fi ;; # NUMCOND, root
7306 esac
7307 N=$((N+1))
7310 NAME=RAWIP6RECV
7311 case "$TESTS" in
7312 *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%rawip%*|*%rawip6%*|*%recv%*|*%root%*|*%$NAME%*)
7313 TEST="$NAME: raw IPv6 receive"
7314 if ! eval $NUMCOND; then :;
7315 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7316 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7317 numCANT=$((numCANT+1))
7318 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7319 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7320 numCANT=$((numCANT+1))
7321 else
7322 tf="$td/test$N.stdout"
7323 te="$td/test$N.stderr"
7324 tdiff="$td/test$N.diff"
7325 ts1p=$PROTO; PROTO=$((PROTO+1))
7326 ts1a="[::1]"
7327 ts1="$ts1a:$ts1p"
7328 da="test$N $(date) $RANDOM"
7329 CMD1="$TRACE $SOCAT $opts -u IP6-RECV:$ts1p,reuseaddr -"
7330 CMD2="$TRACE $SOCAT $opts -u - IP6-SENDTO:$ts1"
7331 printf "test $F_n $TEST... " $N
7332 $CMD1 >"$tf" 2>"${te}1" &
7333 pid1="$!"
7334 waitip6proto $ts1p 1
7335 echo "$da" |$CMD2 2>>"${te}2"
7336 rc2="$?"
7337 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7338 kill "$pid1" 2>/dev/null; wait
7339 if [ "$rc2" -ne 0 ]; then
7340 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7341 echo "$CMD1 &"
7342 echo "$CMD2"
7343 cat "${te}1"
7344 cat "${te}2"
7345 numFAIL=$((numFAIL+1))
7346 listFAIL="$listFAIL $N"
7347 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7348 $PRINTF "$FAILED\n"
7349 cat "$tdiff"
7350 numFAIL=$((numFAIL+1))
7351 listFAIL="$listFAIL $N"
7352 else
7353 $PRINTF "$OK\n"
7354 if [ -n "$debug" ]; then cat $te; fi
7355 numOK=$((numOK+1))
7357 fi ;; # NUMCOND, root
7358 esac
7359 N=$((N+1))
7362 NAME=UNIXRECV
7363 case "$TESTS" in
7364 *%$N%*|*%functions%*|*%unix%*|*%dgram%*|*%recv%*|*%$NAME%*)
7365 TEST="$NAME: UNIX receive"
7366 if ! eval $NUMCOND; then :; else
7367 ts="$td/test$N.socket"
7368 tf="$td/test$N.stdout"
7369 te="$td/test$N.stderr"
7370 tdiff="$td/test$N.diff"
7371 ts1="$ts"
7372 da="test$N $(date) $RANDOM"
7373 CMD1="$TRACE $SOCAT $opts -u UNIX-RECV:$ts1,reuseaddr -"
7374 CMD2="$TRACE $SOCAT $opts -u - UNIX-SENDTO:$ts1"
7375 printf "test $F_n $TEST... " $N
7376 $CMD1 >"$tf" 2>"${te}1" &
7377 pid1="$!"
7378 waitfile $ts1 1
7379 echo "$da" |$CMD2 2>>"${te}2"
7380 rc2="$?"
7381 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7382 kill "$pid1" 2>/dev/null; wait
7383 if [ "$rc2" -ne 0 ]; then
7384 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7385 echo "$CMD1 &"
7386 echo "$CMD2"
7387 cat "${te}1"
7388 cat "${te}2"
7389 numFAIL=$((numFAIL+1))
7390 listFAIL="$listFAIL $N"
7391 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7392 $PRINTF "$FAILED\n"
7393 cat "$tdiff"
7394 numFAIL=$((numFAIL+1))
7395 listFAIL="$listFAIL $N"
7396 else
7397 $PRINTF "$OK\n"
7398 if [ -n "$debug" ]; then cat $te; fi
7399 numOK=$((numOK+1))
7401 fi # NUMCOND
7403 esac
7404 N=$((N+1))
7407 NAME=UDP4RECVFROM_SOURCEPORT
7408 case "$TESTS" in
7409 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
7410 TEST="$NAME: security of UDP4-RECVFROM with SOURCEPORT option"
7411 if ! eval $NUMCOND; then :;
7412 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7413 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7414 numCANT=$((numCANT+1))
7415 else
7416 testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7417 fi ;; # NUMCOND, feats
7418 esac
7419 PORT=$((PORT+1))
7420 N=$((N+1))
7422 NAME=UDP4RECVFROM_LOWPORT
7423 case "$TESTS" in
7424 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
7425 TEST="$NAME: security of UDP4-RECVFROM with LOWPORT option"
7426 if ! eval $NUMCOND; then :;
7427 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7428 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7429 numCANT=$((numCANT+1))
7430 else
7431 testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "lowport" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7432 fi ;; # NUMCOND, feats
7433 esac
7434 PORT=$((PORT+1))
7435 N=$((N+1))
7437 NAME=UDP4RECVFROM_RANGE
7438 case "$TESTS" in
7439 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
7440 TEST="$NAME: security of UDP4-RECVFROM with RANGE option"
7441 #testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7442 if ! eval $NUMCOND; then :; else
7443 testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7444 fi ;; # NUMCOND
7445 esac
7446 PORT=$((PORT+1))
7447 N=$((N+1))
7449 NAME=UDP4RECVFROM_TCPWRAP
7450 case "$TESTS" in
7451 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
7452 TEST="$NAME: security of UDP4-RECVFROM with TCPWRAP option"
7453 if ! eval $NUMCOND; then :;
7454 elif ! feat=$(testaddrs ip4 udp libwrap) || ! runsip4 >/dev/null; then
7455 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7456 numCANT=$((numCANT+1))
7457 else
7458 ha="$td/hosts.allow"
7459 hd="$td/hosts.deny"
7460 $ECHO "socat: $SECONDADDR" >"$ha"
7461 $ECHO "ALL: ALL" >"$hd"
7462 #testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "tcpwrap=$d" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7463 testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7464 fi ;; # NUMCOND, feats
7465 esac
7466 PORT=$((PORT+1))
7467 N=$((N+1))
7470 NAME=UDP4RECV_SOURCEPORT
7471 case "$TESTS" in
7472 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
7473 TEST="$NAME: security of UDP4-RECV with SOURCEPORT option"
7474 if ! eval $NUMCOND; then :;
7475 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7476 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7477 numCANT=$((numCANT+1))
7478 else
7479 PORT1=$PORT; PORT=$((PORT+1))
7480 PORT2=$PORT; PORT=$((PORT+1))
7481 PORT3=$PORT
7482 # we use the forward channel (PORT1) for testing, and have a backward channel
7483 # (PORT2) to get the data back, so we get the classical echo behaviour
7484 testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "sp=$PORT3" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
7485 fi ;; # NUMCOND, feats
7486 esac
7487 PORT=$((PORT+1))
7488 N=$((N+1))
7490 NAME=UDP4RECV_LOWPORT
7491 case "$TESTS" in
7492 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
7493 TEST="$NAME: security of UDP4-RECV with LOWPORT option"
7494 if ! eval $NUMCOND; then :;
7495 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7496 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7497 numCANT=$((numCANT+1))
7498 else
7499 PORT1=$PORT; PORT=$((PORT+1))
7500 PORT2=$PORT
7501 # we use the forward channel (PORT1) for testing, and have a backward channel
7502 # (PORT2) to get the data back, so we get the classical echo behaviour
7503 testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "lowport" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
7504 fi ;; # NUMCOND, feats
7505 esac
7506 PORT=$((PORT+1))
7507 N=$((N+1))
7509 NAME=UDP4RECV_RANGE
7510 case "$TESTS" in
7511 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
7512 TEST="$NAME: security of UDP4-RECV with RANGE option"
7513 if ! eval $NUMCOND; then :;
7514 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7515 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7516 numCANT=$((numCANT+1))
7517 else
7518 PORT1=$PORT; PORT=$((PORT+1))
7519 PORT2=$PORT
7520 # we use the forward channel (PORT1) for testing, and have a backward channel
7521 # (PORT2) to get the data back, so we get the classical echo behaviour
7522 testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "range=$SECONDADDR/32" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
7523 fi ;; # NUMCOND, feats
7524 esac
7525 PORT=$((PORT+1))
7526 N=$((N+1))
7528 NAME=UDP4RECV_TCPWRAP
7529 case "$TESTS" in
7530 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
7531 TEST="$NAME: security of UDP4-RECV with TCPWRAP option"
7532 if ! eval $NUMCOND; then :;
7533 elif ! feat=$(testaddrs udp ip4 libwrap) || ! runsip4 >/dev/null; then
7534 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7535 numCANT=$((numCANT+1))
7536 else
7537 PORT1=$PORT; PORT=$((PORT+1))
7538 PORT2=$PORT
7539 ha="$td/hosts.allow"
7540 hd="$td/hosts.deny"
7541 $ECHO "socat: $SECONDADDR" >"$ha"
7542 $ECHO "ALL: ALL" >"$hd"
7543 # we use the forward channel (PORT1) for testing, and have a backward channel
7544 # (PORT2) to get the data back, so we get the classical echo behaviour
7545 testserversec "$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "tcpwrap-etc=$td" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp $PORT1 0
7546 fi ;; # NUMCOND, feats
7547 esac
7548 PORT=$((PORT+1))
7549 N=$((N+1))
7552 NAME=UDP6RECVFROM_SOURCEPORT
7553 case "$TESTS" in
7554 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
7555 TEST="$NAME: security of UDP6-RECVFROM with SOURCEPORT option"
7556 if ! eval $NUMCOND; then :;
7557 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7558 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7559 numCANT=$((numCANT+1))
7560 else
7561 testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7562 fi ;; # NUMCOND, feats
7563 esac
7564 PORT=$((PORT+1))
7565 N=$((N+1))
7567 NAME=UDP6RECVFROM_LOWPORT
7568 case "$TESTS" in
7569 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
7570 TEST="$NAME: security of UDP6-RECVFROM with LOWPORT option"
7571 if ! eval $NUMCOND; then :;
7572 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7573 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7574 numCANT=$((numCANT+1))
7575 else
7576 testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "lowport" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7577 fi ;; # NUMCOND, feats
7578 esac
7579 PORT=$((PORT+1))
7580 N=$((N+1))
7582 NAME=UDP6RECVFROM_RANGE
7583 case "$TESTS" in
7584 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
7585 TEST="$NAME: security of UDP6-RECVFROM with RANGE option"
7586 if ! eval $NUMCOND; then :;
7587 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
7588 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7589 numCANT=$((numCANT+1))
7590 else
7591 #testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr,fork" "" "range=[::2]/128" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7592 testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "range=[::2]/128" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7593 fi ;; # NUMCOND, feats
7594 esac
7595 PORT=$((PORT+1))
7596 N=$((N+1))
7598 NAME=UDP6RECVFROM_TCPWRAP
7599 case "$TESTS" in
7600 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
7601 TEST="$NAME: security of UDP6-RECVFROM with TCPWRAP option"
7602 if ! eval $NUMCOND; then :;
7603 elif ! feat=$(testaddrs udp ip6 libwrap) || ! runsip6 >/dev/null; then
7604 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7605 numCANT=$((numCANT+1))
7606 else
7607 ha="$td/hosts.allow"
7608 hd="$td/hosts.deny"
7609 $ECHO "socat: [::2]" >"$ha"
7610 $ECHO "ALL: ALL" >"$hd"
7611 testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7612 fi ;; # NUMCOND, feats
7613 esac
7614 PORT=$((PORT+1))
7615 N=$((N+1))
7618 NAME=UDP6RECV_SOURCEPORT
7619 case "$TESTS" in
7620 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
7621 TEST="$NAME: security of UDP6-RECV with SOURCEPORT option"
7622 if ! eval $NUMCOND; then :;
7623 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7624 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7625 numCANT=$((numCANT+1))
7626 else
7627 PORT1=$PORT; PORT=$((PORT+1))
7628 PORT2=$PORT; PORT=$((PORT+1))
7629 PORT3=$PORT
7630 # we use the forward channel (PORT1) for testing, and have a backward channel
7631 # (PORT2) to get the data back, so we get the classical echo behaviour
7632 testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "sp=$PORT3" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
7633 fi ;; # NUMCOND, feats
7634 esac
7635 PORT=$((PORT+1))
7636 N=$((N+1))
7638 NAME=UDP6RECV_LOWPORT
7639 case "$TESTS" in
7640 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
7641 TEST="$NAME: security of UDP6-RECV with LOWPORT option"
7642 if ! eval $NUMCOND; then :;
7643 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7644 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7645 numCANT=$((numCANT+1))
7646 else
7647 PORT1=$PORT; PORT=$((PORT+1))
7648 PORT2=$PORT
7649 # we use the forward channel (PORT1) for testing, and have a backward channel
7650 # (PORT2) to get the data back, so we get the classical echo behaviour
7651 testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "lowport" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
7652 fi ;; # NUMCOND, feats
7653 esac
7654 PORT=$((PORT+1))
7655 N=$((N+1))
7657 NAME=UDP6RECV_RANGE
7658 case "$TESTS" in
7659 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
7660 TEST="$NAME: security of UDP6-RECV with RANGE option"
7661 if ! eval $NUMCOND; then :;
7662 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7663 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7664 numCANT=$((numCANT+1))
7665 else
7666 PORT1=$PORT; PORT=$((PORT+1))
7667 PORT2=$PORT
7668 # we use the forward channel (PORT1) for testing, and have a backward channel
7669 # (PORT2) to get the data back, so we get the classical echo behaviour
7670 testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "range=[::2]/128" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
7671 fi ;; # NUMCOND, feats
7672 esac
7673 PORT=$((PORT+1))
7674 N=$((N+1))
7676 NAME=UDP6RECV_TCPWRAP
7677 case "$TESTS" in
7678 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
7679 TEST="$NAME: security of UDP6-RECV with TCPWRAP option"
7680 if ! eval $NUMCOND; then :;
7681 elif ! feat=$(testaddrs udp ip6 libwrap) || ! runsip6 >/dev/null; then
7682 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7683 numCANT=$((numCANT+1))
7684 else
7685 ha="$td/hosts.allow"
7686 hd="$td/hosts.deny"
7687 $ECHO "socat: [::2]" >"$ha"
7688 $ECHO "ALL: ALL" >"$hd"
7689 PORT1=$PORT; PORT=$((PORT+1))
7690 PORT2=$PORT
7691 # we use the forward channel (PORT1) for testing, and have a backward channel
7692 # (PORT2) to get the data back, so we get the classical echo behaviour
7693 testserversec "$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "tcpwrap-etc=$td" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
7694 fi ;; # NUMCOND, feats
7695 esac
7696 PORT=$((PORT+1))
7697 N=$((N+1))
7700 NAME=IP4RECVFROM_RANGE
7701 case "$TESTS" in
7702 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
7703 TEST="$NAME: security of IP4-RECVFROM with RANGE option"
7704 if ! eval $NUMCOND; then :;
7705 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
7706 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7707 numCANT=$((numCANT+1))
7708 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7709 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7710 numCANT=$((numCANT+1))
7711 else
7712 #testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "range=$SECONDADDR/32" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7713 testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr!!udp4-sendto:127.0.0.1:$PORT" "" "range=$SECONDADDR/32" "udp4-recv:$PORT!!ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7714 fi ;; # NUMCOND, feats, root
7715 esac
7716 PROTO=$((PROTO+1))
7717 PORT=$((PORT+1))
7718 N=$((N+1))
7720 NAME=IP4RECVFROM_TCPWRAP
7721 case "$TESTS" in
7722 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7723 TEST="$NAME: security of IP4-RECVFROM with TCPWRAP option"
7724 if ! eval $NUMCOND; then :;
7725 elif ! feat=$(testaddrs ip4 rawip libwrap) || ! runsip4 >/dev/null; then
7726 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7727 numCANT=$((numCANT+1))
7728 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7729 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7730 numCANT=$((numCANT+1))
7731 else
7732 ha="$td/hosts.allow"
7733 hd="$td/hosts.deny"
7734 $ECHO "socat: $SECONDADDR" >"$ha"
7735 $ECHO "ALL: ALL" >"$hd"
7736 #testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7737 testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr!!udp4-sendto:127.0.0.1:$PORT" "" "tcpwrap-etc=$td" "udp4-recv:$PORT!!ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7738 fi # NUMCOND, feats, root
7740 esac
7741 PROTO=$((PROTO+1))
7742 PORT=$((PORT+1))
7743 N=$((N+1))
7746 NAME=IP4RECV_RANGE
7747 case "$TESTS" in
7748 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
7749 TEST="$NAME: security of IP4-RECV with RANGE option"
7750 if ! eval $NUMCOND; then :;
7751 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
7752 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
7753 numCANT=$((numCANT+1))
7754 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7755 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7756 numCANT=$((numCANT+1))
7757 else
7758 PROTO1=$PROTO; PROTO=$((PROTO+1))
7759 PROTO2=$PROTO
7760 # we use the forward channel (PROTO1) for testing, and have a backward channel
7761 # (PROTO2) to get the data back, so we get the classical echo behaviour
7762 testserversec "$N" "$TEST" "$opts" "ip4-recv:$PROTO1,reuseaddr!!ip4-sendto:127.0.0.1:$PROTO2" "" "range=$SECONDADDR/32" "ip4-recv:$PROTO2!!ip4-sendto:127.0.0.1:$PROTO1" 4 ip $PROTO1 0
7763 fi ;; # NUMCOND, feats, root
7764 esac
7765 PROTO=$((PROTO+1))
7766 N=$((N+1))
7770 NAME=IP4RECV_TCPWRAP
7771 case "$TESTS" in
7772 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7773 TEST="$NAME: security of IP4-RECV with TCPWRAP option"
7774 if ! eval $NUMCOND; then :;
7775 elif ! feat=$(testaddrs ip4 rawip libwrap) || ! runsip4 >/dev/null; then
7776 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7777 numCANT=$((numCANT+1))
7778 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7779 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7780 numCANT=$((numCANT+1))
7781 else
7782 PROTO1=$PROTO; PROTO=$((PROTO+1))
7783 PROTO2=$PROTO
7784 ha="$td/hosts.allow"
7785 hd="$td/hosts.deny"
7786 $ECHO "socat: $SECONDADDR" >"$ha"
7787 $ECHO "ALL: ALL" >"$hd"
7788 # we use the forward channel (PROTO1) for testing, and have a backward channel
7789 # (PROTO2) to get the data back, so we get the classical echo behaviour
7790 testserversec "$N" "$TEST" "$opts" "ip4-recv:$PROTO1,reuseaddr!!ip4-sendto:127.0.0.1:$PROTO2" "" "tcpwrap-etc=$td" "ip4-recv:$PROTO2!!ip4-sendto:127.0.0.1:$PROTO1" 4 ip $PROTO1 0
7791 fi ;; # NUMCOND, feats, root
7792 esac
7793 PROTO=$((PROTO+1))
7794 N=$((N+1))
7797 NAME=IP6RECVFROM_RANGE
7798 case "$TESTS" in
7799 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
7800 TEST="$NAME: security of IP6-RECVFROM with RANGE option"
7801 if ! eval $NUMCOND; then :;
7802 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7803 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7804 numCANT=$((numCANT+1))
7805 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7806 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7807 numCANT=$((numCANT+1))
7808 else
7809 #testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "range=[::2]/128" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7810 testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "range=[::2]/128" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7811 fi ;; # NUMCOND, feats
7812 esac
7813 PROTO=$((PROTO+1))
7814 PORT=$((PORT+1))
7815 N=$((N+1))
7817 NAME=IP6RECVFROM_TCPWRAP
7818 case "$TESTS" in
7819 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7820 TEST="$NAME: security of IP6-RECVFROM with TCPWRAP option"
7821 if ! eval $NUMCOND; then :;
7822 elif ! feat=$(testaddrs ip6 rawip libwrap) || ! runsip6 >/dev/null; then
7823 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7824 numCANT=$((numCANT+1))
7825 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7826 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7827 numCANT=$((numCANT+1))
7828 else
7829 ha="$td/hosts.allow"
7830 hd="$td/hosts.deny"
7831 $ECHO "socat: [::2]" >"$ha"
7832 $ECHO "ALL: ALL" >"$hd"
7833 #testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7834 testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "tcpwrap-etc=$td" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7835 fi ;; # NUMCOND, feats
7836 esac
7837 PROTO=$((PROTO+1))
7838 PORT=$((PORT+1))
7839 N=$((N+1))
7842 NAME=IP6RECV_RANGE
7843 case "$TESTS" in
7844 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
7845 TEST="$NAME: security of IP6-RECV with RANGE option"
7846 if ! eval $NUMCOND; then :;
7847 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7848 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP6 not available${NORMAL}\n" $N
7849 numCANT=$((numCANT+1))
7850 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7851 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7852 numCANT=$((numCANT+1))
7853 else
7854 PROTO1=$PROTO; PROTO=$((PROTO+1))
7855 PROTO2=$PROTO
7856 # we use the forward channel (PROTO1) for testing, and have a backward channel
7857 # (PROTO2) to get the data back, so we get the classical echo behaviour
7858 testserversec "$N" "$TEST" "$opts" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "range=[::2]/128" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip $PROTO1 0
7859 fi ;; # NUMCOND, feats
7860 esac
7861 PROTO=$((PROTO+1))
7862 N=$((N+1))
7864 NAME=IP6RECV_TCPWRAP
7865 case "$TESTS" in
7866 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7867 TEST="$NAME: security of IP6-RECV with TCPWRAP option"
7868 if ! eval $NUMCOND; then :;
7869 elif ! feat=$(testaddrs ip6 rawip libwrap) || ! runsip6 >/dev/null; then
7870 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7871 numCANT=$((numCANT+1))
7872 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7873 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7874 numCANT=$((numCANT+1))
7875 else
7876 PROTO1=$PROTO; PROTO=$((PROTO+1))
7877 PROTO2=$PROTO
7878 ha="$td/hosts.allow"
7879 hd="$td/hosts.deny"
7880 $ECHO "socat: [::2]" >"$ha"
7881 $ECHO "ALL: ALL" >"$hd"
7882 # we use the forward channel (PROTO1) for testing, and have a backward channel
7883 # (PROTO2) to get the data back, so we get the classical echo behaviour
7884 testserversec "$N" "$TEST" "$opts" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "tcpwrap-etc=$td" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip $PROTO1 0
7885 fi ;; # NUMCOND, feats
7886 esac
7887 PROTO=$((PROTO+1))
7888 N=$((N+1))
7891 NAME=O_NOATIME_FILE
7892 case "$TESTS" in
7893 *%$N%*|*%functions%*|*%open%*|*%noatime%*|*%$NAME%*)
7894 TEST="$NAME: option O_NOATIME on file"
7895 # idea: create a file with o-noatime option; one second later create a file
7896 # without this option (using touch); one second later read from the first file.
7897 # Then we check which file has the later ATIME stamp. For this check we use
7898 # "ls -ltu" because it is more portable than "test ... -nt ..."
7899 if ! eval $NUMCOND; then :;
7900 elif ! testoptions o-noatime >/dev/null; then
7901 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
7902 numCANT=$((numCANT+1))
7903 else
7904 tf="$td/test$N.file"
7905 te="$td/test$N.stderr"
7906 tdiff="$td/test$N.diff"
7907 da="test$N $(date) $RANDOM"
7908 $PRINTF "test $F_n $TEST... " $N
7909 CMD="$TRACE $SOCAT $opts -u open:\"${tf}1\",o-noatime /dev/null"
7910 # generate a file
7911 touch "${tf}1"
7912 sleep 1
7913 # generate a reference file
7914 touch "${tf}2"
7915 sleep 1
7916 # read from the first file
7917 $CMD 2>"$te"
7918 if [ $? -ne 0 ]; then # command failed
7919 $PRINTF "${FAILED}:\n"
7920 echo "$CMD"
7921 cat "$te"
7922 numFAIL=$((numFAIL+1))
7923 listFAIL="$listFAIL $N"
7924 else
7925 # check which file has a later atime stamp
7926 if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
7927 then
7928 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7929 echo "$CMD"
7930 cat "$te"
7931 numFAIL=$((numFAIL+1))
7932 listFAIL="$listFAIL $N"
7933 else
7934 $PRINTF "$OK\n"
7935 if [ -n "$debug" ]; then cat "$te"; fi
7936 numOK=$((numOK+1))
7937 fi # wrong time stamps
7938 fi # command ok
7939 fi ;; # NUMCOND, feats
7940 esac
7941 N=$((N+1))
7943 NAME=O_NOATIME_FD
7944 case "$TESTS" in
7945 *%$N%*|*%functions%*|*%noatime%*|*%$NAME%*)
7946 TEST="$NAME: option O_NOATIME on file descriptor"
7947 # idea: use a fd of a file with o-noatime option; one second later create a file
7948 # without this option (using touch); one second later read from the first file.
7949 # Then we check which file has the later ATIME stamp. For this check we use
7950 # "ls -ltu" because it is more portable than "test ... -nt ..."
7951 if ! eval $NUMCOND; then :;
7952 elif ! testoptions o-noatime >/dev/null; then
7953 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
7954 numCANT=$((numCANT+1))
7955 else
7956 tf="$td/test$N.file"
7957 te="$td/test$N.stderr"
7958 tdiff="$td/test$N.diff"
7959 da="test$N $(date) $RANDOM"
7960 $PRINTF "test $F_n $TEST... " $N
7961 touch ${tf}1
7962 CMD="$TRACE $SOCAT $opts -u -,o-noatime /dev/null <${tf}1"
7963 # generate a file, len >= 1
7964 touch "${tf}1"
7965 sleep 1
7966 # generate a reference file
7967 touch "${tf}2"
7968 sleep 1
7969 # read from the first file
7970 sh -c "$CMD" 2>"$te"
7971 if [ $? -ne 0 ]; then # command failed
7972 $PRINTF "${FAILED}:\n"
7973 echo "$CMD"
7974 cat "$te"
7975 numFAIL=$((numFAIL+1))
7976 listFAIL="$listFAIL $N"
7977 else
7978 # check which file has a later atime stamp
7979 if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
7980 then
7981 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7982 echo "$CMD"
7983 cat "$te"
7984 numFAIL=$((numFAIL+1))
7985 listFAIL="$listFAIL $N"
7986 else
7987 $PRINTF "$OK\n"
7988 if [ -n "$debug" ]; then cat "$te"; fi
7989 numOK=$((numOK+1))
7990 fi # wrong time stamps
7991 fi # command ok
7992 fi ;; # NUMCOND, feats
7993 esac
7994 N=$((N+1))
7996 NAME=EXT2_NOATIME
7997 case "$TESTS" in
7998 *%$N%*|*%functions%*|*%ext2%*|*%noatime%*|*%$NAME%*)
7999 TEST="$NAME: extended file system options using ext2fs noatime option"
8000 # idea: create a file with ext2-noatime option; one second later create a file
8001 # without this option (using touch); one second later read from the first file.
8002 # Then we check which file has the later ATIME stamp. For this check we use
8003 # "ls -ltu" because it is more portable than "test ... -nt ..."
8004 if ! eval $NUMCOND; then :;
8005 elif ! testoptions ext2-noatime >/dev/null; then
8006 $PRINTF "test $F_n $TEST... ${YELLOW}ext2-noatime not available${NORMAL}\n" $N
8007 numCANT=$((numCANT+1))
8008 else
8009 ts="$td/test$N.socket"
8010 tf="$td/test$N.file"
8011 te="$td/test$N.stderr"
8012 tdiff="$td/test$N.diff"
8013 ts1="$ts"
8014 da="test$N $(date) $RANDOM"
8015 $PRINTF "test $F_n $TEST... " $N
8016 CMD0="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\""
8017 CMD="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\",ext2-noatime"
8018 # check if this is a capable FS; lsattr does other things on AIX, thus socat
8019 $CMD0 2>"${te}0"
8020 if [ $? -ne 0 ]; then
8021 $PRINTF "${YELLOW} cannot test${NORMAL}\n"
8022 numCANT=$((numCANT+1))
8023 else
8024 # generate a file with noatime, len >= 1
8025 $CMD 2>"$te"
8026 if [ $? -ne 0 ]; then # command failed
8027 $PRINTF "${YELLOW}impotent file system?${NORMAL}\n"
8028 echo "$CMD"
8029 cat "$te"
8030 numCANT=$((numCANT+1))
8031 else
8032 sleep 1
8033 # generate a reference file
8034 touch "${tf}2"
8035 sleep 1
8036 # read from the first file
8037 cat "${tf}1" >/dev/null
8038 # check which file has a later atime stamp
8039 #if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |awk '{print($8);}') != "${tf}2" ];
8040 if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |sed "s|.*\\($td.*\\)|\1|g") != "${tf}2" ];
8041 then
8042 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8043 echo "$CMD"
8044 cat "$te"
8045 numFAIL=$((numFAIL+1))
8046 listFAIL="$listFAIL $N"
8047 else
8048 $PRINTF "$OK\n"
8049 if [ -n "$debug" ]; then cat "$te"; fi
8050 numOK=$((numOK+1))
8052 fi # not impotent
8053 fi # can test
8054 fi ;; # NUMCOND, feats
8055 esac
8056 N=$((N+1))
8059 NAME=COOLWRITE
8060 case "$TESTS" in
8061 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
8062 TEST="$NAME: option cool-write"
8063 if ! eval $NUMCOND; then :;
8064 elif ! testoptions cool-write >/dev/null; then
8065 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
8066 numCANT=$((numCANT+1))
8067 else
8068 #set -vx
8069 ti="$td/test$N.pipe"
8070 tf="$td/test$N.stdout"
8071 te="$td/test$N.stderr"
8072 tdiff="$td/test$N.diff"
8073 da="test$N $(date) $RANDOM"
8074 # a reader that will terminate after 1 byte
8075 CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8076 CMD="$TRACE $SOCAT $opts -u - file:\"$ti\",cool-write"
8077 printf "test $F_n $TEST... " $N
8078 $CMD1 2>"${te}1" &
8079 bg=$! # background process id
8080 sleep 1
8081 (echo .; sleep 1; echo) |$CMD 2>"$te"
8082 rc=$?
8083 kill $bg 2>/dev/null; wait
8084 if [ $rc -ne 0 ]; then
8085 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8086 echo "$CMD &"
8087 cat "$te"
8088 numFAIL=$((numFAIL+1))
8089 listFAIL="$listFAIL $N"
8090 else
8091 $PRINTF "$OK\n"
8092 if [ -n "$debug" ]; then cat "$te"; fi
8093 numOK=$((numOK+1))
8095 fi ;; # NUMCOND, feats
8096 esac
8097 N=$((N+1))
8100 # test if option coolwrite can be applied to bidirectional address stdio
8101 # this failed up to socat 1.6.0.0
8102 NAME=COOLSTDIO
8103 case "$TESTS" in
8104 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
8105 TEST="$NAME: option cool-write on bidirectional stdio"
8106 # this test starts a socat reader that terminates after receiving one+
8107 # bytes (option readbytes); and a test process that sends two bytes via
8108 # named pipe to the receiving process and, a second later, sends another
8109 # byte. The last write will fail with "broken pipe"; if option coolwrite
8110 # has been applied successfully, socat will terminate with 0 (OK),
8111 # otherwise with error.
8112 if ! eval $NUMCOND; then :;
8113 elif ! testoptions cool-write >/dev/null; then
8114 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
8115 numCANT=$((numCANT+1))
8116 else
8117 #set -vx
8118 ti="$td/test$N.pipe"
8119 tf="$td/test$N.stdout"
8120 te="$td/test$N.stderr"
8121 tdiff="$td/test$N.diff"
8122 da="test$N $(date) $RANDOM"
8123 # a reader that will terminate after 1 byte
8124 CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8125 CMD="$TRACE $SOCAT $opts -,cool-write pipe >\"$ti\""
8126 printf "test $F_n $TEST... " $N
8127 $CMD1 2>"${te}1" &
8128 bg=$! # background process id
8129 sleep 1
8130 (echo .; sleep 1; echo) |eval "$CMD" 2>"$te"
8131 rc=$?
8132 kill $bg 2>/dev/null; wait
8133 if [ $rc -ne 0 ]; then
8134 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8135 echo "$CMD &"
8136 cat "$te"
8137 numFAIL=$((numFAIL+1))
8138 listFAIL="$listFAIL $N"
8139 else
8140 $PRINTF "$OK\n"
8141 if [ -n "$debug" ]; then cat "$te"; fi
8142 numOK=$((numOK+1))
8144 fi ;; # NUMCOND, feats
8145 esac
8146 N=$((N+1))
8149 NAME=TCP4ENDCLOSE
8150 case "$TESTS" in
8151 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
8152 TEST="$NAME: end-close keeps TCP V4 socket open"
8153 if ! eval $NUMCOND; then :; else
8154 tf="$td/test$N.stdout"
8155 te="$td/test$N.stderr"
8156 tdiff="$td/test$N.diff"
8157 p1=$PORT; PORT=$((PORT+1))
8158 p2=$PORT
8159 da1a="$(date) $RANDOM"
8160 da1b="$(date) $RANDOM"
8161 CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$LOCALHOST:$p1"
8162 CMD="$TRACE $SOCAT $opts -U TCP4:$LOCALHOST:$p2,end-close TCP4-LISTEN:$p1,bind=$LOCALHOST,$REUSEADDR,fork"
8163 CMD3="$TRACE $SOCAT $opts -u TCP4-LISTEN:$p2,$REUSEADDR,bind=$LOCALHOST -"
8164 printf "test $F_n $TEST... " $N
8165 $CMD3 >"$tf" 2>"${te}3" &
8166 pid3=$!
8167 waittcp4port $p2 1
8168 $CMD 2>"${te}2" &
8169 pid2=$!
8170 usleep $MICROS
8171 waittcp4port $p1 1
8172 echo "$da1a" |$CMD1 2>>"${te}1a"
8173 echo "$da1b" |$CMD1 2>>"${te}1b"
8174 sleep 1
8175 kill "$pid3" "$pid2" 2>/dev/null
8176 wait
8177 if [ $? -ne 0 ]; then
8178 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8179 echo "$CMD1 &"
8180 echo "$CMD2"
8181 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8182 numFAIL=$((numFAIL+1))
8183 listFAIL="$listFAIL $N"
8184 elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
8185 $PRINTF "$FAILED\n"
8186 cat "$tdiff"
8187 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8188 numFAIL=$((numFAIL+1))
8189 listFAIL="$listFAIL $N"
8190 else
8191 $PRINTF "$OK\n"
8192 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2" "${te}3"; fi
8193 numOK=$((numOK+1))
8195 fi ;; # NUMCOND
8196 esac
8197 PORT=$((PORT+1))
8198 N=$((N+1))
8201 NAME=EXECENDCLOSE
8202 case "$TESTS" in
8203 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
8204 TEST="$NAME: end-close keeps EXEC child running"
8205 if ! eval $NUMCOND; then :; else
8206 tf="$td/test$N.stdout"
8207 te="$td/test$N.stderr"
8208 ts="$td/test$N.sock"
8209 tdiff="$td/test$N.diff"
8210 da1a="$(date) $RANDOM"
8211 da1b="$(date) $RANDOM"
8212 CMD1="$TRACE $SOCAT $opts - UNIX-CONNECT:$ts"
8213 CMD="$TRACE $SOCAT $opts EXEC:"$CAT",end-close UNIX-LISTEN:$ts,fork"
8214 printf "test $F_n $TEST... " $N
8215 $CMD 2>"${te}2" &
8216 pid2=$!
8217 waitfile $ts 1
8218 echo "$da1a" |$CMD1 2>>"${te}1a" >"$tf"
8219 usleep $MICROS
8220 echo "$da1b" |$CMD1 2>>"${te}1b" >>"$tf"
8221 #usleep $MICROS
8222 kill "$pid2" 2>/dev/null
8223 wait
8224 if [ $? -ne 0 ]; then
8225 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8226 echo "$CMD1 &"
8227 echo "$CMD2"
8228 cat "${te}1a" "${te}1b" "${te}2"
8229 numFAIL=$((numFAIL+1))
8230 listFAIL="$listFAIL $N"
8231 elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
8232 $PRINTF "$FAILED\n"
8233 cat "$tdiff"
8234 cat "${te}1a" "${te}1b" "${te}2"
8235 numFAIL=$((numFAIL+1))
8236 listFAIL="$listFAIL $N"
8237 else
8238 $PRINTF "$OK\n"
8239 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2"; fi
8240 numOK=$((numOK+1))
8242 fi ;; # NUMCOND
8243 esac
8244 N=$((N+1))
8247 # up to 1.7.0.0 option end-close led to an error with some address types due to
8248 # bad internal handling. here we check it for address PTY
8249 NAME=PTYENDCLOSE
8250 case "$TESTS" in
8251 *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
8252 TEST="$NAME: PTY handles option end-close"
8253 # with the bug, socat exits with error. we invoke socat in a no-op mode and
8254 # check its return status.
8255 if ! eval $NUMCOND; then :;
8256 else
8257 tf="$td/test$N.stout"
8258 te="$td/test$N.stderr"
8259 CMD="$TRACE $SOCAT $opts /dev/null pty,end-close"
8260 printf "test $F_n $TEST... " $N
8261 $CMD 2>"${te}"
8262 rc=$?
8263 if [ "$rc" = 0 ]; then
8264 $PRINTF "$OK\n"
8265 numOK=$((numOK+1))
8266 else
8267 $PRINTF "$FAILED\n"
8268 echo "$CMD"
8269 cat "${te}"
8270 numFAIL=$((numFAIL+1))
8271 listFAIL="$listFAIL $N"
8273 fi # NUMCOND
8275 esac
8276 N=$((N+1))
8279 # test the shut-null and null-eof options
8280 NAME=SHUTNULLEOF
8281 case "$TESTS" in
8282 *%$N%*|*%functions%*|*%socket%*|*%$NAME%*)
8283 TEST="$NAME: options shut-null and null-eof"
8284 # run a receiving background process with option null-eof.
8285 # start a sending process with option shut-null that sends a test record to the
8286 # receiving process and then terminates.
8287 # send another test record.
8288 # whe the receiving process just got the first test record the test succeeded
8289 if ! eval $NUMCOND; then :; else
8290 tf="$td/test$N.stout"
8291 te="$td/test$N.stderr"
8292 tdiff="$td/test$N.diff"
8293 da="test$N $(date) $RANDOM"
8294 CMD0="$TRACE $SOCAT $opts -u UDP-RECV:$PORT,null-eof CREAT:$tf"
8295 CMD1="$TRACE $SOCAT $opts -u - UDP-SENDTO:127.0.0.1:$PORT,shut-null"
8296 printf "test $F_n $TEST... " $N
8297 $CMD0 >/dev/null 2>"${te}0" &
8298 pid0=$!
8299 waitudp4port $PORT 1
8300 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
8301 rc1=$?
8302 echo "xyz" |$CMD1 >"${tf}2" 2>"${te}2"
8303 rc2=$?
8304 kill $pid0 2>/dev/null; wait
8305 if [ $rc1 != 0 -o $rc2 != 0 ]; then
8306 $PRINTF "$FAILED\n"
8307 echo "$CMD0 &"
8308 echo "$CMD1"
8309 cat "${te}0"
8310 cat "${te}1"
8311 cat "${te}2"
8312 numFAIL=$((numFAIL+1))
8313 listFAIL="$listFAIL $N"
8314 elif echo "$da" |diff - "${tf}" >"$tdiff"; then
8315 $PRINTF "$OK\n"
8316 numOK=$((numOK+1))
8317 else
8318 $PRINTF "$FAILED\n"
8319 echo "$CMD0 &"
8320 echo "$CMD1"
8321 cat "${te}0"
8322 cat "${te}1"
8323 cat "${tdiff}"
8324 numFAIL=$((numFAIL+1))
8325 listFAIL="$listFAIL $N"
8327 fi # NUMCOND
8329 esac
8330 N=$((N+1))
8333 NAME=UDP6LISTENBIND
8334 # this tests for a bug in (up to) 1.5.0.0:
8335 # with udp*-listen, the bind option supported only IPv4
8336 case "$TESTS" in
8337 *%$N%*|*%functions%*|*%bugs%*|*%ip6%*|*%ipapp%*|*%udp%*|*%udp6%*|*%$NAME%*)
8338 TEST="$NAME: UDP6-LISTEN with bind"
8339 if ! eval $NUMCOND; then :;
8340 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
8341 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
8342 numCANT=$((numCANT+1))
8343 else
8344 tf="$td/test$N.stdout"
8345 te="$td/test$N.stderr"
8346 tdiff="$td/test$N.diff"
8347 tsl=$PORT
8348 ts="$LOCALHOST6:$tsl"
8349 da="test$N $(date) $RANDOM"
8350 CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,$REUSEADDR,bind=$LOCALHOST6 PIPE"
8351 CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
8352 printf "test $F_n $TEST... " $N
8353 $CMD1 >"$tf" 2>"${te}1" &
8354 pid1=$!
8355 waitudp6port $tsl 1
8356 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8357 rc2=$?
8358 kill $pid1 2>/dev/null; wait
8359 if [ $rc2 -ne 0 ]; then
8360 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8361 echo "$CMD1 &"
8362 echo "$CMD2"
8363 cat "${te}1" "${te}2"
8364 numFAIL=$((numFAIL+1))
8365 listFAIL="$listFAIL $N"
8366 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8367 $PRINTF "$FAILED\n"
8368 cat "$tdiff"
8369 numFAIL=$((numFAIL+1))
8370 listFAIL="$listFAIL $N"
8371 else
8372 $PRINTF "$OK\n"
8373 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8374 numOK=$((numOK+1))
8376 fi ;; # NUMCOND, feats
8377 esac
8378 PORT=$((PORT+1))
8379 N=$((N+1))
8382 NAME=TCPWRAPPERS_MULTIOPTS
8383 # this tests for a bug in 1.5.0.0 that let socat fail when more than one
8384 # tcp-wrappers related option was specified in one address
8385 case "$TESTS" in
8386 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
8387 TEST="$NAME: use of multiple tcpwrapper enabling options"
8388 if ! eval $NUMCOND; then :;
8389 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
8390 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8391 numCANT=$((numCANT+1))
8392 else
8393 tf="$td/test$N.stdout"
8394 te="$td/test$N.stderr"
8395 tdiff="$td/test$N.diff"
8396 da="test$N $(date) $RANDOM"
8397 ha="$td/hosts.allow"
8398 $ECHO "test : ALL : allow" >"$ha"
8399 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,$REUSEADDR,hosts-allow=$ha,tcpwrap=test pipe"
8400 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT"
8401 printf "test $F_n $TEST... " $N
8402 $CMD1 2>"${te}1" &
8403 waittcp4port $PORT
8404 echo "$da" |$CMD2 >"$tf" 2>"${te}2"
8405 if [ $? -ne 0 ]; then
8406 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8407 echo "$CMD1 &"
8408 echo "$CMD2"
8409 cat "${te}1"
8410 cat "${te}2"
8411 numFAIL=$((numFAIL+1))
8412 listFAIL="$listFAIL $N"
8413 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8414 $PRINTF "$FAILED\n"
8415 cat "$tdiff"
8416 numFAIL=$((numFAIL+1))
8417 listFAIL="$listFAIL $N"
8418 else
8419 $PRINTF "$OK\n"
8420 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8421 numOK=$((numOK+1))
8423 fi ;; # NUMCOND, feats
8424 esac
8425 PORT=$((PORT+1))
8426 N=$((N+1))
8429 NAME=TCPWRAPPERS_TCP6ADDR
8430 # this tests for a bug in 1.5.0.0 that brought false results with tcp-wrappers
8431 # and IPv6 when
8432 case "$TESTS" in
8433 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
8434 TEST="$NAME: specification of TCP6 address in hosts.allow"
8435 if ! eval $NUMCOND; then :;
8436 elif ! feat=$(testaddrs tcp ip6 libwrap) || ! runsip6 >/dev/null; then
8437 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8438 numCANT=$((numCANT+1))
8439 else
8440 tf="$td/test$N.stdout"
8441 te="$td/test$N.stderr"
8442 tdiff="$td/test$N.diff"
8443 da="test$N $(date) $RANDOM"
8444 ha="$td/hosts.allow"
8445 hd="$td/hosts.deny"
8446 $ECHO "socat : [::1] : allow" >"$ha"
8447 $ECHO "ALL : ALL : deny" >"$hd"
8448 CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$PORT,$REUSEADDR,tcpwrap-etc=$td,tcpwrappers=socat pipe"
8449 CMD2="$TRACE $SOCAT $opts - TCP6:[::1]:$PORT"
8450 printf "test $F_n $TEST... " $N
8451 $CMD1 2>"${te}1" &
8452 pid1=$!
8453 waittcp6port $PORT
8454 echo "$da" |$CMD2 >"$tf" 2>"${te}2"
8455 kill $pid1 2>/dev/null; wait
8456 if [ $? -ne 0 ]; then
8457 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8458 echo "$CMD1 &"
8459 echo "$CMD2"
8460 cat "${te}1"
8461 cat "${te}2"
8462 numFAIL=$((numFAIL+1))
8463 listFAIL="$listFAIL $N"
8464 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8465 $PRINTF "$FAILED\n"
8466 cat "$tdiff"
8467 numFAIL=$((numFAIL+1))
8468 listFAIL="$listFAIL $N"
8469 else
8470 $PRINTF "$OK\n"
8471 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8472 numOK=$((numOK+1))
8474 fi ;; # NUMCOND, feats
8475 esac
8476 PORT=$((PORT+1))
8477 N=$((N+1))
8480 NAME=UDP4BROADCAST
8481 case "$TESTS" in
8482 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%$NAME%*)
8483 TEST="$NAME: UDP/IPv4 broadcast"
8484 if ! eval $NUMCOND; then :;
8485 elif [ -z "$BCADDR" ]; then
8486 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8487 numCANT=$((numCANT+1))
8488 else
8489 tf="$td/test$N.stdout"
8490 te="$td/test$N.stderr"
8491 tdiff="$td/test$N.diff"
8492 ts1p=$PORT; PORT=$((PORT+1))
8493 #ts1="$BCADDR/8:$ts1p"
8494 ts1="$BCADDR:$ts1p"
8495 ts2p=$PORT; PORT=$((PORT+1))
8496 ts2="$BCIFADDR:$ts2p"
8497 da="test$N $(date) $RANDOM"
8498 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,broadcast PIPE"
8499 #CMD2="$TRACE $SOCAT $opts - UDP4-BROADCAST:$ts1"
8500 CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:$ts1,broadcast"
8501 printf "test $F_n $TEST... " $N
8502 $CMD1 2>"${te}1" &
8503 pid1="$!"
8504 waitudp4port $ts1p 1
8505 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8506 rc2="$?"
8507 kill "$pid1" 2>/dev/null; wait;
8508 if [ "$rc2" -ne 0 ]; then
8509 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8510 echo "$CMD1 &"
8511 echo "$CMD2"
8512 cat "${te}1"
8513 cat "${te}2"
8514 numFAIL=$((numFAIL+1))
8515 listFAIL="$listFAIL $N"
8516 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8517 $PRINTF "$FAILED\n"
8518 cat "$tdiff"
8519 numFAIL=$((numFAIL+1))
8520 listFAIL="$listFAIL $N"
8521 else
8522 $PRINTF "$OK\n"
8523 if [ -n "$tut" ]; then
8524 echo "$CMD1 &"
8525 echo "$CMD2"
8527 if [ -n "$debug" ]; then cat $te; fi
8528 numOK=$((numOK+1))
8530 fi ;; # NUMCOND, feats
8531 esac
8532 N=$((N+1))
8535 NAME=IP4BROADCAST
8536 # test a local broadcast of a raw IPv4 protocol.
8537 # because we receive - in addition to the regular reply - our own broadcast,
8538 # we use a token XXXX that is changed to YYYY in the regular reply packet.
8539 case "$TESTS" in
8540 *%$N%*|*%functions%*|*%engine%*|*%rawip%*|*%rawip4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%root%*|*%$NAME%*)
8541 TEST="$NAME: raw IPv4 broadcast"
8542 if ! eval $NUMCOND; then :;
8543 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8544 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP4 not available${NORMAL}\n" $N
8545 numCANT=$((numCANT+1))
8546 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8547 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8548 numCANT=$((numCANT+1))
8549 elif [ -z "$BCADDR" ]; then
8550 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8551 else
8552 tf="$td/test$N.stdout"
8553 te="$td/test$N.stderr"
8554 tdiff="$td/test$N.diff"
8555 ts1p=$PROTO
8556 #ts1="$BCADDR/8:$ts1p"
8557 ts1="$BCADDR:$ts1p"
8558 ts2p=$ts1p
8559 ts2="$BCIFADDR"
8560 da="test$N $(date) $RANDOM XXXX"
8561 sh="$td/test$N-sed.sh"
8562 echo 'sed s/XXXX/YYYY/' >"$sh"
8563 chmod a+x "$sh"
8564 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,broadcast exec:$sh"
8565 #CMD2="$TRACE $SOCAT $opts - IP4-BROADCAST:$ts1"
8566 CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:$ts1,broadcast"
8567 printf "test $F_n $TEST... " $N
8568 $CMD1 2>"${te}1" &
8569 pid1="$!"
8570 waitip4port $ts1p 1
8571 echo "$da" |$CMD2 2>>"${te}2" |grep -v XXXX >>"$tf"
8572 rc2="$?"
8573 kill "$pid1" 2>/dev/null; wait;
8574 if [ "$rc2" -ne 0 ]; then
8575 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8576 echo "$CMD1 &"
8577 echo "$CMD2"
8578 cat "${te}1"
8579 cat "${te}2"
8580 numFAIL=$((numFAIL+1))
8581 listFAIL="$listFAIL $N"
8582 elif ! echo "$da" | sed 's/XXXX/YYYY/'|diff - "$tf" >"$tdiff"; then
8583 $PRINTF "$FAILED\n"
8584 cat "$tdiff"
8585 numFAIL=$((numFAIL+1))
8586 listFAIL="$listFAIL $N"
8587 else
8588 $PRINTF "$OK\n"
8589 if [ -n "$debug" ]; then cat $te; fi
8590 numOK=$((numOK+1))
8592 fi ;; # NUMCOND, feats
8593 esac
8594 PROTO=$((PROTO+1))
8595 N=$((N+1))
8598 #NAME=UDP4BROADCAST_RANGE
8599 #case "$TESTS" in
8600 #*%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%range%*|*%$NAME%*)
8601 #TEST="$NAME: security of UDP4-BROADCAST with RANGE option"
8602 #if ! eval $NUMCOND; then :;
8603 #elif [ -z "$BCADDR" ]; then
8604 # $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8605 #else
8606 #testserversec "$N" "$TEST" "$opts" "UDP4-BROADCAST:$BCADDR/8:$PORT" "" "range=127.1.0.0:255.255.0.0" "udp4:127.1.0.0:$PORT" 4 udp $PORT 0
8607 #fi ;; # NUMCOND, feats
8608 #esac
8609 #PORT=$((PORT+1))
8610 #N=$((N+1))
8613 NAME=UDP4MULTICAST_UNIDIR
8614 case "$TESTS" in
8615 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8616 TEST="$NAME: UDP/IPv4 multicast, send only"
8617 if ! eval $NUMCOND; then :;
8618 elif ! feat=$(testaddrs ip4 udp) || ! runsip4 >/dev/null; then
8619 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8620 numCANT=$((numCANT+1))
8621 else
8622 tf="$td/test$N.stdout"
8623 te="$td/test$N.stderr"
8624 tdiff="$td/test$N.diff"
8625 ts1p=$PORT; PORT=$((PORT+1))
8626 ts1a="$SECONDADDR"
8627 ts1="$ts1a:$ts1p"
8628 da="test$N $(date) $RANDOM"
8629 CMD1="$TRACE $SOCAT -u $opts UDP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
8630 CMD2="$TRACE $SOCAT -u $opts - UDP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
8631 printf "test $F_n $TEST... " $N
8632 $CMD1 2>"${te}1" >"${tf}" &
8633 pid1="$!"
8634 waitudp4port $ts1p 1
8635 echo "$da" |$CMD2 2>>"${te}2"
8636 rc2="$?"
8637 usleep $MICROS
8638 kill "$pid1" 2>/dev/null; wait;
8639 if [ "$rc2" -ne 0 ]; then
8640 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8641 echo "$CMD1 &"
8642 echo "$CMD2"
8643 cat "${te}1"
8644 cat "${te}2"
8645 numFAIL=$((numFAIL+1))
8646 listFAIL="$listFAIL $N"
8647 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8648 $PRINTF "$FAILED\n"
8649 cat "$tdiff"
8650 numFAIL=$((numFAIL+1))
8651 listFAIL="$listFAIL $N"
8652 else
8653 $PRINTF "$OK\n"
8654 if [ -n "$debug" ]; then cat $te; fi
8655 numOK=$((numOK+1))
8657 fi ;; # NUMCOND, feats
8658 esac
8659 N=$((N+1))
8661 NAME=IP4MULTICAST_UNIDIR
8662 case "$TESTS" in
8663 *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
8664 TEST="$NAME: IPv4 multicast"
8665 if ! eval $NUMCOND; then :;
8666 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8667 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8668 numCANT=$((numCANT+1))
8669 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8670 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8671 numCANT=$((numCANT+1))
8672 else
8673 tf="$td/test$N.stdout"
8674 te="$td/test$N.stderr"
8675 tdiff="$td/test$N.diff"
8676 ts1p=$PROTO
8677 ts1a="$SECONDADDR"
8678 ts1="$ts1a:$ts1p"
8679 da="test$N $(date) $RANDOM"
8680 CMD1="$TRACE $SOCAT -u $opts IP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
8681 CMD2="$TRACE $SOCAT -u $opts - IP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
8682 printf "test $F_n $TEST... " $N
8683 $CMD1 2>"${te}1" >"${tf}" &
8684 pid1="$!"
8685 waitip4proto $ts1p 1
8686 usleep $MICROS
8687 echo "$da" |$CMD2 2>>"${te}2"
8688 rc2="$?"
8689 #usleep $MICROS
8690 sleep 1
8691 kill "$pid1" 2>/dev/null; wait;
8692 if [ "$rc2" -ne 0 ]; then
8693 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8694 echo "$CMD1 &"
8695 echo "$CMD2"
8696 cat "${te}1"
8697 cat "${te}2"
8698 numFAIL=$((numFAIL+1))
8699 listFAIL="$listFAIL $N"
8700 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8701 $PRINTF "$FAILED\n"
8702 cat "$tdiff"
8703 numFAIL=$((numFAIL+1))
8704 listFAIL="$listFAIL $N"
8705 else
8706 $PRINTF "$OK\n"
8707 if [ -n "$debug" ]; then cat $te; fi
8708 numOK=$((numOK+1))
8710 fi ;; # NUMCOND, feats
8711 esac
8712 PROTO=$((PROTO+1))
8713 N=$((N+1))
8715 if true; then
8716 NAME=UDP6MULTICAST_UNIDIR
8717 case "$TESTS" in
8718 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8719 TEST="$NAME: UDP/IPv6 multicast"
8720 if ! eval $NUMCOND; then :;
8721 elif ! feat=$(testaddrs ip6 udp) || ! runsip6 >/dev/null; then
8722 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8723 numCANT=$((numCANT+1))
8724 else
8725 tf="$td/test$N.stdout"
8726 te="$td/test$N.stderr"
8727 tdiff="$td/test$N.diff"
8728 ts1p=$PORT; PORT=$((PORT+1))
8729 if1="$MCINTERFACE"
8730 ts1a="[::1]"
8731 da="test$N $(date) $RANDOM"
8732 CMD1="$TRACE $SOCAT -u $opts UDP6-RECV:$ts1p,reuseaddr,ipv6-join-group=[ff02::2]:$if1 -"
8733 CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p,bind=$ts1a"
8734 #CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p"
8735 printf "test $F_n $TEST... " $N
8736 $CMD1 2>"${te}1" >"${tf}" &
8737 pid1="$!"
8738 waitudp6port $ts1p 1
8739 echo "$da" |$CMD2 2>>"${te}2"
8740 rc2="$?"
8741 usleep $MICROS
8742 kill "$pid1" 2>/dev/null; wait;
8743 if [ "$rc2" -ne 0 ]; then
8744 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8745 echo -e "$CMD1 &\n$CMD2"
8746 cat "${te}1"
8747 cat "${te}2"
8748 numFAIL=$((numFAIL+1))
8749 listFAIL="$listFAIL $N"
8750 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8751 $PRINTF "$FAILED\n"
8752 echo "$CMD1 &"
8753 echo "$CMD2"
8754 cat "$tdiff"
8755 numFAIL=$((numFAIL+1))
8756 listFAIL="$listFAIL $N"
8757 else
8758 $PRINTF "$OK\n"
8759 if [ "$VERBOSE" ]; then echo -e "$CMD1 &\n$CMD2"; fi
8760 if [ -n "$debug" ]; then cat $te; fi
8761 numOK=$((numOK+1))
8763 fi ;; # NUMCOND, feats
8764 esac
8765 N=$((N+1))
8766 fi # false
8768 NAME=UDP4MULTICAST_BIDIR
8769 case "$TESTS" in
8770 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8771 TEST="$NAME: UDP/IPv4 multicast, with reply"
8772 if ! eval $NUMCOND; then :; else
8773 tf="$td/test$N.stdout"
8774 te="$td/test$N.stderr"
8775 tdiff="$td/test$N.diff"
8776 ts1p=$PORT; PORT=$((PORT+1))
8777 ts1a="$SECONDADDR"
8778 ts1="$ts1a:$ts1p"
8779 ts2p=$PORT; PORT=$((PORT+1))
8780 ts2="$BCIFADDR:$ts2p"
8781 da="test$N $(date) $RANDOM"
8782 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
8783 #CMD2="$TRACE $SOCAT $opts - UDP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
8784 CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
8785 printf "test $F_n $TEST... " $N
8786 $CMD1 2>"${te}1" &
8787 pid1="$!"
8788 waitudp4port $ts1p 1
8789 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8790 rc2="$?"
8791 kill "$pid1" 2>/dev/null; wait;
8792 if [ "$rc2" -ne 0 ]; then
8793 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8794 echo "$CMD1 &"
8795 echo "$CMD2"
8796 cat "${te}1"
8797 cat "${te}2"
8798 numFAIL=$((numFAIL+1))
8799 listFAIL="$listFAIL $N"
8800 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8801 $PRINTF "$FAILED\n"
8802 cat "$tdiff"
8803 numFAIL=$((numFAIL+1))
8804 listFAIL="$listFAIL $N"
8805 else
8806 $PRINTF "$OK\n"
8807 if [ -n "$VERBOSE" ]; then
8808 echo "$CMD1 &"
8809 echo "$CMD2"
8811 if [ -n "$debug" ]; then cat $te; fi
8812 numOK=$((numOK+1))
8814 fi ;; # NUMCOND
8815 esac
8816 N=$((N+1))
8818 NAME=IP4MULTICAST_BIDIR
8819 case "$TESTS" in
8820 *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
8821 TEST="$NAME: IPv4 multicast, with reply"
8822 if ! eval $NUMCOND; then :;
8823 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8824 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8825 numCANT=$((numCANT+1))
8826 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8827 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8828 numCANT=$((numCANT+1))
8829 else
8830 tf="$td/test$N.stdout"
8831 te="$td/test$N.stderr"
8832 tdiff="$td/test$N.diff"
8833 ts1p=$PROTO
8834 ts1a="$SECONDADDR"
8835 ts1="$ts1a:$ts1p"
8836 da="test$N $(date) $RANDOM"
8837 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
8838 #CMD2="$TRACE $SOCAT $opts - IP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
8839 CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
8840 printf "test $F_n $TEST... " $N
8841 $CMD1 2>"${te}1" &
8842 pid1="$!"
8843 waitip4port $ts1p 1
8844 usleep 100000 # give process a chance to add multicast membership
8845 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8846 rc2="$?"
8847 kill "$pid1" 2>/dev/null; wait;
8848 if [ "$rc2" -ne 0 ]; then
8849 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8850 echo "$CMD1 &"
8851 echo "$CMD2"
8852 cat "${te}1"
8853 cat "${te}2"
8854 numFAIL=$((numFAIL+1))
8855 listFAIL="$listFAIL $N"
8856 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8857 $PRINTF "$FAILED\n"
8858 cat "$tdiff"
8859 numFAIL=$((numFAIL+1))
8860 listFAIL="$listFAIL $N"
8861 else
8862 $PRINTF "$OK\n"
8863 if [ -n "$tut" ]; then
8864 echo "$CMD1 &"
8865 echo "$CMD2"
8867 if [ -n "$debug" ]; then cat $te; fi
8868 numOK=$((numOK+1))
8870 fi ;; # NUMCOND, feats
8871 esac
8872 PROTO=$((PROTO+1))
8873 N=$((N+1))
8876 NAME=TUNREAD
8877 case "$TESTS" in
8878 *%$N%*|*%functions%*|*%tun%*|*%root%*|*%$NAME%*)
8879 TEST="$NAME: reading data sent through tun interface"
8880 #idea: create a TUN interface and send a datagram to one of the addresses of
8881 # its virtual network. On the tunnel side, read the packet and compare its last
8882 # bytes with the datagram payload
8883 if ! eval $NUMCOND; then :;
8884 elif ! feat=$(testaddrs ip4 tun) || ! runsip4 >/dev/null; then
8885 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8886 numCANT=$((numCANT+1))
8887 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8888 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8889 numCANT=$((numCANT+1))
8890 else
8891 tf="$td/test$N.stdout"
8892 te="$td/test$N.stderr"
8893 tdiff="$td/test$N.diff"
8894 tl="$td/test$N.lock"
8895 da="test$N $(date) $RANDOM"
8896 dalen=$((${#da}+1))
8897 TUNNET=10.255.255
8898 CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$TUNNET.2:$PORT"
8899 #CMD="$TRACE $SOCAT $opts -u -L $tl TUN,ifaddr=$TUNNET.1,netmask=255.255.255.0,iff-up=1 -"
8900 CMD="$TRACE $SOCAT $opts -u -L $tl TUN:$TUNNET.1/24,iff-up=1 -"
8901 printf "test $F_n $TEST... " $N
8902 $CMD 2>"${te}" |tail -c $dalen >"${tf}" &
8903 sleep 1
8904 echo "$da" |$CMD1 2>"${te}1"
8905 sleep 1
8906 kill "$(cat $tl 2>/dev/null)" 2>/dev/null
8907 wait
8908 if [ $? -ne 0 ]; then
8909 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8910 echo "$CMD &"
8911 echo "$CMD1"
8912 cat "${te}" "${te}1"
8913 numFAIL=$((numFAIL+1))
8914 listFAIL="$listFAIL $N"
8915 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8916 $PRINTF "$FAILED\n"
8917 echo "$CMD &"
8918 echo "$CMD1"
8919 cat "$tdiff"
8920 cat "${te}" "${te}1"
8921 numFAIL=$((numFAIL+1))
8922 listFAIL="$listFAIL $N"
8923 else
8924 $PRINTF "$OK\n"
8925 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
8926 numOK=$((numOK+1))
8928 fi ;; # NUMCOND, feats
8929 esac
8930 PORT=$((PORT+1))
8931 N=$((N+1))
8934 # use the INTERFACE address on a tun/tap device and transfer data fully
8935 # transparent
8936 NAME=TUNINTERFACE
8937 case "$TESTS" in
8938 *%$N%*|*%functions%*|*%tun%*|*%interface%*|*%root%*|*%$NAME%*)
8939 TEST="$NAME: pass data through tun interface using INTERFACE"
8940 #idea: create a TUN interface and send a raw packet on the interface side.
8941 # It should arrive unmodified on the tunnel side.
8942 if ! eval $NUMCOND; then :;
8943 elif ! feat=$(testaddrs ip4 tun interface) || ! runsip4 >/dev/null; then
8944 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8945 numCANT=$((numCANT+1))
8946 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8947 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8948 numCANT=$((numCANT+1))
8949 else
8950 tf="$td/test$N.stdout"
8951 te="$td/test$N.stderr"
8952 tdiff="$td/test$N.diff"
8953 tl="$td/test$N.lock"
8954 da="$(date) $RANDOM"
8955 dalen=$((${#da}+1))
8956 TUNNET=10.255.255
8957 TUNNAME=tun9
8958 CMD1="$TRACE $SOCAT $opts -L $tl TUN:$TUNNET.1/24,iff-up=1,tun-type=tun,tun-name=$TUNNAME echo"
8959 CMD="$TRACE $SOCAT $opts - INTERFACE:$TUNNAME"
8960 printf "test $F_n $TEST... " $N
8961 $CMD1 2>"${te}1" &
8962 pid1="$!"
8963 #waitinterface "$TUNNAME"
8964 sleep 1
8965 echo "$da" |$CMD 2>"${te}1" >"$tf" 2>"${te}"
8966 kill $pid1 2>/dev/null
8967 wait
8968 if [ $? -ne 0 ]; then
8969 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8970 echo "$CMD &"
8971 echo "$CMD1"
8972 cat "${te}" "${te}1"
8973 numFAIL=$((numFAIL+1))
8974 listFAIL="$listFAIL $N"
8975 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8976 $PRINTF "$FAILED\n"
8977 echo "$CMD &"
8978 echo "$CMD1"
8979 cat "$tdiff"
8980 cat "${te}" "${te}1"
8981 numFAIL=$((numFAIL+1))
8982 listFAIL="$listFAIL $N"
8983 else
8984 $PRINTF "$OK\n"
8985 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
8986 numOK=$((numOK+1))
8988 fi ;; # NUMCOND, feats
8989 esac
8990 PORT=$((PORT+1))
8991 N=$((N+1))
8994 NAME=ABSTRACTSTREAM
8995 case "$TESTS" in
8996 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%connect%*|*%listen%*|*%$NAME%*)
8997 TEST="$NAME: abstract UNIX stream socket, listen and connect"
8998 if ! eval $NUMCOND; then :;
8999 elif ! feat=$(testaddrs abstract-unixsocket); then
9000 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9001 numCANT=$((numCANT+1))
9002 else
9003 ts="$td/test$N.socket"
9004 tf="$td/test$N.stdout"
9005 te="$td/test$N.stderr"
9006 tdiff="$td/test$N.diff"
9007 da1="test$N $(date) $RANDOM"
9008 #establish a listening abstract unix socket
9009 SRV="$TRACE $SOCAT $opts -lpserver ABSTRACT-LISTEN:\"$ts\",$REUSEADDR PIPE"
9010 #make a connection
9011 CMD="$TRACE $SOCAT $opts - ABSTRACT-CONNECT:$ts"
9012 $PRINTF "test $F_n $TEST... " $N
9013 touch "$ts" # make a file with same name, so non-abstract fails
9014 eval "$SRV 2>${te}s &"
9015 pids=$!
9016 #waitfile "$ts"
9017 sleep 1
9018 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
9019 if [ $? -ne 0 ]; then
9020 kill "$pids" 2>/dev/null
9021 $PRINTF "$FAILED:\n"
9022 echo "$SRV &"
9023 cat "${te}s"
9024 echo "$CMD"
9025 cat "${te}1"
9026 numFAIL=$((numFAIL+1))
9027 listFAIL="$listFAIL $N"
9028 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
9029 kill "$pids" 2>/dev/null
9030 $PRINTF "$FAILED:\n"
9031 echo "$SRV &"
9032 cat "${te}s"
9033 echo "$CMD"
9034 cat "${te}1"
9035 cat "$tdiff"
9036 numFAIL=$((numFAIL+1))
9037 listFAIL="$listFAIL $N"
9038 else
9039 $PRINTF "$OK\n"
9040 if [ -n "$debug" ]; then cat $te; fi
9041 numOK=$((numOK+1))
9042 fi # !(rc -ne 0)
9043 wait
9044 fi ;; # NUMCOND, feats
9045 esac
9046 N=$((N+1))
9049 NAME=ABSTRACTDGRAM
9050 case "$TESTS" in
9051 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%$NAME%*)
9052 TEST="$NAME: abstract UNIX datagram"
9053 if ! eval $NUMCOND; then :;
9054 elif ! feat=$(testaddrs abstract-unixsocket); then
9055 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9056 numCANT=$((numCANT+1))
9057 else
9058 tf="$td/test$N.stdout"
9059 te="$td/test$N.stderr"
9060 tdiff="$td/test$N.diff"
9061 ts1="$td/test$N.socket1"
9062 ts2="$td/test$N.socket2"
9063 da="test$N $(date) $RANDOM"
9064 CMD1="$TRACE $SOCAT $opts ABSTRACT-RECVFROM:$ts1,reuseaddr PIPE"
9065 #CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
9066 CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
9067 printf "test $F_n $TEST... " $N
9068 touch "$ts1" # make a file with same name, so non-abstract fails
9069 $CMD1 2>"${te}1" &
9070 pid1="$!"
9071 sleep 1
9072 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9073 rc2=$?
9074 kill "$pid1" 2>/dev/null; wait
9075 if [ $rc2 -ne 0 ]; then
9076 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9077 echo "$CMD1 &"
9078 cat "${te}1"
9079 echo "$CMD2"
9080 cat "${te}2"
9081 numFAIL=$((numFAIL+1))
9082 listFAIL="$listFAIL $N"
9083 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9084 $PRINTF "$FAILED\n"
9085 cat "$tdiff"
9086 numFAIL=$((numFAIL+1))
9087 listFAIL="$listFAIL $N"
9088 else
9089 $PRINTF "$OK\n"
9090 if [ -n "$debug" ]; then cat $te; fi
9091 numOK=$((numOK+1))
9093 fi ;; # NUMCOND, feats
9094 esac
9095 N=$((N+1))
9098 NAME=ABSTRACTRECV
9099 case "$TESTS" in
9100 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%recv%*|*%$NAME%*)
9101 TEST="$NAME: abstract UNIX datagram receive"
9102 if ! eval $NUMCOND; then :;
9103 elif ! feat=$(testaddrs abstract-unixsocket); then
9104 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9105 numCANT=$((numCANT+1))
9106 else
9107 ts="$td/test$N.socket"
9108 tf="$td/test$N.stdout"
9109 te="$td/test$N.stderr"
9110 tdiff="$td/test$N.diff"
9111 ts1="$ts"
9112 da="test$N $(date) $RANDOM"
9113 CMD1="$TRACE $SOCAT $opts -u ABSTRACT-RECV:$ts1,reuseaddr -"
9114 CMD2="$TRACE $SOCAT $opts -u - ABSTRACT-SENDTO:$ts1"
9115 printf "test $F_n $TEST... " $N
9116 touch "$ts1" # make a file with same name, so non-abstract fails
9117 $CMD1 >"$tf" 2>"${te}1" &
9118 pid1="$!"
9119 #waitfile $ts1 1
9120 sleep 1
9121 echo "$da" |$CMD2 2>>"${te}2"
9122 rc2="$?"
9123 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9124 kill "$pid1" 2>/dev/null; wait
9125 if [ "$rc2" -ne 0 ]; then
9126 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9127 echo "$CMD1 &"
9128 echo "$CMD2"
9129 cat "${te}1"
9130 cat "${te}2"
9131 numFAIL=$((numFAIL+1))
9132 listFAIL="$listFAIL $N"
9133 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9134 $PRINTF "$FAILED\n"
9135 cat "$tdiff"
9136 numFAIL=$((numFAIL+1))
9137 listFAIL="$listFAIL $N"
9138 else
9139 $PRINTF "$OK\n"
9140 if [ -n "$debug" ]; then cat $te; fi
9141 numOK=$((numOK+1))
9143 fi ;; # NUMCOND, feats
9144 esac
9145 N=$((N+1))
9148 # bind with Linux abstract UNIX domain addresses bound to filesystem socket
9149 # instead of abstract namespace
9150 NAME=ABSTRACT_BIND
9151 case "$TESTS" in
9152 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%abstract%*|*%$NAME%*)
9153 TEST="$NAME: abstract bind"
9154 # open an abstract client address with bind option, bind to the target socket.
9155 # send a datagram.
9156 # when socat outputs the datagram it got the test succeeded
9157 if ! eval $NUMCOND; then :;
9158 elif [ "$UNAME" != Linux ]; then
9159 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
9160 numCANT=$((numCANT+1))
9161 else
9162 tf="$td/test$N.stdout"
9163 te="$td/test$N.stderr"
9164 tdiff="$td/test$N.diff"
9165 ts1="$td/test$N.sock1"
9166 da="test$N $(date) $RANDOM"
9167 CMD1="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts1"
9168 printf "test $F_n $TEST... " $N
9169 echo "$da" |$CMD1 >$tf 2>"${te}1"
9170 rc1=$?
9171 if [ $rc1 -ne 0 ]; then
9172 $PRINTF "$FAILED\n"
9173 echo "$CMD1" >&2
9174 echo "rc=$rc1" >&2
9175 cat "${te}1" >&2
9176 numFAIL=$((numFAIL+1))
9177 listFAIL="$listFAIL $N"
9178 elif echo "$da" |diff -q - $tf; then
9179 $PRINTF "$OK\n"
9180 numOK=$((numOK+1))
9181 else
9182 $PRINTF "$FAILED\n"
9183 echo "$CMD1" >&2
9184 cat "${te}1" >&2
9185 echo "$da" |diff - "$tf" >&2
9186 numFAIL=$((numFAIL+1))
9187 listFAIL="$listFAIL $N"
9189 fi # NUMCOND
9191 esac
9192 PORT=$((PORT+1))
9193 N=$((N+1))
9196 NAME=OPENSSLREAD
9197 # socat determined availability of data using select(). With openssl, the
9198 # following situation might occur:
9199 # a SSL data block with more than 8192 bytes (socats default blocksize)
9200 # arrives; socat calls SSL_read, and the SSL routine reads the complete block.
9201 # socat then reads 8192 bytes from the SSL layer, the rest remains buffered.
9202 # If the TCP connection stays idle for some time, the data in the SSL layer
9203 # keeps there and is not transferred by socat until the socket indicates more
9204 # data or EOF.
9205 case "$TESTS" in
9206 *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
9207 TEST="$NAME: socat handles data buffered by openssl"
9208 #idea: have a socat process (server) that gets an SSL block that is larger than
9209 # socat transfer block size; keep the socket connection open and kill the
9210 # server process after a short time; if not the whole data block has been
9211 # transferred, the test has failed.
9212 if ! eval $NUMCOND; then :;
9213 elif ! feat=$(testaddrs openssl) >/dev/null; then
9214 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9215 numCANT=$((numCANT+1))
9216 else
9217 tf="$td/test$N.out"
9218 te="$td/test$N.err"
9219 tdiff="$td/test$N.diff"
9220 da="test$N $(date) $RANDOM"
9221 SRVCERT=testsrv
9222 gentestcert "$SRVCERT"
9223 CMD1="$TRACE $SOCAT $opts -u -T 1 -b $($ECHO "$da\c" |wc -c) OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=$SRVCERT.pem,verify=0 -"
9224 CMD2="$TRACE $SOCAT $opts -u - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
9225 printf "test $F_n $TEST... " $N
9227 $CMD1 2>"${te}1" >"$tf" &
9228 pid=$! # background process id
9229 waittcp4port $PORT
9230 (echo "$da"; sleep 2) |$CMD2 2>"${te}2"
9231 kill "$pid" 2>/dev/null; wait
9232 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
9233 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9234 echo "$CMD1"
9235 cat "${te}1"
9236 echo "$CMD2"
9237 cat "${te}2"
9238 cat "$tdiff"
9239 numFAIL=$((numFAIL+1))
9240 listFAIL="$listFAIL $N"
9241 else
9242 $PRINTF "$OK\n"
9243 if [ -n "$debug" ]; then cat $te; fi
9244 numOK=$((numOK+1))
9246 wait
9247 fi # NUMCOND, featsesac
9249 esac
9250 N=$((N+1))
9253 # test: there is a bug with the readbytes option: when the socket delivered
9254 # exacly that many bytes as specified with readbytes and the stays idle (no
9255 # more data, no EOF), socat waits for more data instead of generating EOF on
9256 # this in put stream.
9257 NAME=READBYTES_EOF
9258 #set -vx
9259 case "$TESTS" in
9260 *%$N%*|*%functions%*|*%$NAME%*)
9261 TEST="$NAME: trigger EOF after that many bytes, even when socket idle"
9262 #idea: we deliver that many bytes to socat; the process should terminate then.
9263 # we try to transfer data in the other direction then; if transfer succeeds,
9264 # the process did not terminate and the bug is still there.
9265 if ! eval $NUMCOND; then :;
9266 elif false; then
9267 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9268 numCANT=$((numCANT+1))
9269 else
9270 tr="$td/test$N.ref"
9271 ti="$td/test$N.in"
9272 to="$td/test$N.out"
9273 te="$td/test$N.err"
9274 tdiff="$td/test$N.diff"
9275 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
9276 CMD="$TRACE $SOCAT $opts SYSTEM:\"echo A; sleep $((2*SECONDs))\",readbytes=2!!- -!!/dev/null"
9277 printf "test $F_n $TEST... " $N
9278 (usleep $((2*MICROS)); echo) |eval "$CMD" >"$to" 2>"$te"
9279 if test -s "$to"; then
9280 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9281 echo "$CMD"
9282 numFAIL=$((numFAIL+1))
9283 listFAIL="$listFAIL $N"
9284 else
9285 $PRINTF "$OK\n"
9286 if [ -n "$debug" ]; then cat $te; fi
9287 numOK=$((numOK+1))
9289 fi ;; # NUMCOND, feats
9290 esac
9291 N=$((N+1))
9294 # test: there was a bug with exec:...,pty that did not kill the exec'd sub
9295 # process under some circumstances.
9296 NAME=EXECPTYKILL
9297 case "$TESTS" in
9298 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
9299 TEST="$NAME: exec:...,pty explicitely kills sub process"
9300 # we want to check if the exec'd sub process is killed in time
9301 # for this we have a shell script that generates a file after two seconds;
9302 # it should be killed after one second, so if the file was generated the test
9303 # has failed
9304 if ! eval $NUMCOND; then :; else
9305 tf="$td/test$N.stdout"
9306 te="$td/test$N.stderr"
9307 ts="$td/test$N.sock"
9308 tda="$td/test$N.data"
9309 tsh="$td/test$N.sh"
9310 tdiff="$td/test$N.diff"
9311 cat >"$tsh" <<EOF
9312 sleep $SECONDs; echo; sleep $SECONDs; touch "$tda"; echo
9314 chmod a+x "$tsh"
9315 CMD1="$TRACE $SOCAT $opts -t $SECONDs -U UNIX-LISTEN:$ts,fork EXEC:$tsh,pty"
9316 CMD="$TRACE $SOCAT $opts -t $SECONDs /dev/null UNIX-CONNECT:$ts"
9317 printf "test $F_n $TEST... " $N
9318 $CMD1 2>"${te}2" &
9319 pid1=$!
9320 sleep $SECONDs
9321 waitfile $ts $SECONDs
9322 $CMD 2>>"${te}1" >>"$tf"
9323 sleep $((2*SECONDs))
9324 kill "$pid1" 2>/dev/null
9325 wait
9326 if [ $? -ne 0 ]; then
9327 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9328 echo "$CMD1 &"
9329 echo "$CMD2"
9330 cat "${te}1" "${te}2"
9331 numFAIL=$((numFAIL+1))
9332 listFAIL="$listFAIL $N"
9333 elif [ -f "$tda" ]; then
9334 $PRINTF "$FAILED\n"
9335 cat "${te}1" "${te}2"
9336 numFAIL=$((numFAIL+1))
9337 listFAIL="$listFAIL $N"
9338 else
9339 $PRINTF "$OK\n"
9340 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9341 numOK=$((numOK+1))
9343 fi ;; # NUMCOND
9344 esac
9345 PORT=$((PORT+1))
9346 N=$((N+1))
9349 # test if service name resolution works; this was buggy in 1.5 and 1.6.0.0
9350 NAME=TCP4SERVICE
9351 case "$TESTS" in
9352 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
9353 TEST="$NAME: echo via connection to TCP V4 socket"
9354 # select a tcp entry from /etc/services, have a server listen on the port
9355 # number and connect using the service name; with the bug, connection will to a
9356 # wrong port
9357 if ! eval $NUMCOND; then :; else
9358 tf="$td/test$N.stdout"
9359 te="$td/test$N.stderr"
9360 tdiff="$td/test$N.diff"
9361 # find a service entry we do not need root for (>=1024; here >=1100 for ease)
9362 SERVENT="$(grep '^[a-z][a-z]*[^!-~][^!-~]*[1-9][1-9][0-9][0-9]/tcp' /etc/services |head -n 1)"
9363 SERVICE="$(echo $SERVENT |cut -d' ' -f1)"
9364 _PORT="$PORT"
9365 PORT="$(echo $SERVENT |sed 's/.* \([1-9][0-9]*\).*/\1/')"
9366 tsl="$PORT"
9367 ts="127.0.0.1:$SERVICE"
9368 da="test$N $(date) $RANDOM"
9369 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
9370 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
9371 printf "test $F_n $TEST... " $N
9372 $CMD1 >"$tf" 2>"${te}1" &
9373 pid1=$!
9374 waittcp4port $tsl 1
9375 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9376 if [ $? -ne 0 ]; then
9377 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9378 echo "$CMD1 &"
9379 cat "${te}1"
9380 echo "$CMD2"
9381 cat "${te}2"
9382 numFAIL=$((numFAIL+1))
9383 listFAIL="$listFAIL $N"
9384 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9385 $PRINTF "$FAILED\n"
9386 cat "$tdiff"
9387 numFAIL=$((numFAIL+1))
9388 listFAIL="$listFAIL $N"
9389 else
9390 $PRINTF "$OK\n"
9391 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9392 numOK=$((numOK+1))
9394 kill $pid1 2>/dev/null
9395 wait
9396 PORT="$_PORT"
9397 fi ;; # NUMCOND
9398 esac
9399 N=$((N+1))
9402 # test: up to socat 1.6.0.0, the highest file descriptor supported in socats
9403 # transfer engine was FOPEN_MAX-1; this usually worked fine but would fail when
9404 # socat was invoked with many file descriptors already opened. socat would
9405 # just hang in the select() call. Thanks to Daniel Lucq for reporting this
9406 # problem.
9407 # FOPEN_MAX on different OS's:
9408 # OS FOPEN_ ulimit ulimit FD_
9409 # MAX -H -n -S -n SETSIZE
9410 # Linux 2.6: 16 1024 1024 1024
9411 # HP-UX 11.11: 60 2048 2048 2048
9412 # FreeBSD: 20 11095 11095 1024
9413 # Cygwin: 20 unlimit 256 64
9414 # AIX: 32767 65534 65534
9415 # SunOS 8: 20 1024
9416 NAME=EXCEED_FOPEN_MAX
9417 case "$TESTS" in
9418 *%$N%*|*%functions%*|*%maxfds%*|*%$NAME%*)
9419 TEST="$NAME: more than FOPEN_MAX FDs in use"
9420 # this test opens a number of FDs before socat is invoked. socat will have to
9421 # allocate higher FD numbers and thus hang if it cannot handle them.
9422 if ! eval $NUMCOND; then :; else
9423 REDIR=
9424 #set -vx
9425 FOPEN_MAX=$($PROCAN -c 2>/dev/null |grep '^#define[ ][ ]*FOPEN_MAX' |awk '{print($3);}')
9426 if [ -z "$FOPEN_MAX" ]; then
9427 $PRINTF "test $F_n $TEST... ${YELLOW}could not determine FOPEN_MAX${NORMAL}\n" "$N"
9428 numCANT=$((numCANT+1))
9429 else
9430 OPEN_FILES=$FOPEN_MAX # more than the highest FOPEN_MAX
9431 i=3; while [ "$i" -lt "$OPEN_FILES" ]; do
9432 REDIR="$REDIR $i>&2"
9433 i=$((i+1))
9434 done
9435 #echo "$REDIR"
9436 #testecho "$N" "$TEST" "" "pipe" "$opts -T 3" "" 1
9437 #set -vx
9438 eval testecho "\"$N\"" "\"$TEST\"" "\"\"" "pipe" "\"$opts -T $((2*SECONDs))\"" 1 $REDIR
9439 #set +vx
9440 fi # could determine FOPEN_MAX
9441 fi ;; # NUMCOND
9442 esac
9443 N=$((N+1))
9446 # there was a bug with udp-listen and fork: terminating sub processes became
9447 # zombies because the master process did not catch SIGCHLD
9448 NAME=UDP4LISTEN_SIGCHLD
9449 case "$TESTS" in
9450 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%zombie%*|*%signal%*|*%$NAME%*)
9451 TEST="$NAME: test if UDP4-LISTEN child becomes zombie"
9452 # idea: run a udp-listen process with fork and -T. Connect once, so a sub
9453 # process is forked off. Make some transfer and wait until the -T timeout is
9454 # over. Now check for the child process: if it is zombie the test failed.
9455 # Correct is that child process terminated
9456 if ! eval $NUMCOND; then :; else
9457 tf="$td/test$N.stdout"
9458 te="$td/test$N.stderr"
9459 tdiff="$td/test$N.diff"
9460 tsl=$PORT
9461 ts="$LOCALHOST:$tsl"
9462 da="test$N $(date) $RANDOM"
9463 CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-LISTEN:$tsl,$REUSEADDR,fork PIPE"
9464 CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
9465 printf "test $F_n $TEST... " $N
9466 $CMD1 >"$tf" 2>"${te}1" &
9467 pid1=$!
9468 waitudp4port $tsl 1
9469 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9470 rc2=$?
9471 sleep 1
9472 #read -p ">"
9473 l="$(childprocess $pid1)"
9474 kill $pid1 2>/dev/null; wait
9475 if [ $rc2 -ne 0 ]; then
9476 $PRINTF "$NO_RESULT (client failed)\n" # already handled in test UDP4STREAM
9477 numCANT=$((numCANT+1))
9478 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9479 $PRINTF "$NO_RESULT (diff failed)\n" # already handled in test UDP4STREAM
9480 numCANT=$((numCANT+1))
9481 elif $(isdefunct "$l"); then
9482 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9483 echo "$CMD1 &"
9484 echo "$CMD2"
9485 cat "${te}1" "${te}2"
9486 numFAIL=$((numFAIL+1))
9487 listFAIL="$listFAIL $N"
9488 else
9489 $PRINTF "$OK\n"
9490 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9491 numOK=$((numOK+1))
9493 fi ;; # NUMCOND
9494 esac
9495 PORT=$((PORT+1))
9496 N=$((N+1))
9497 #set +vx
9499 # there was a bug with udp-recvfrom and fork: terminating sub processes became
9500 # zombies because the master process caught SIGCHLD but did not wait()
9501 NAME=UDP4RECVFROM_SIGCHLD
9502 case "$TESTS" in
9503 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%zombie%*|*%signal%*|*%$NAME%*)
9504 TEST="$NAME: test if UDP4-RECVFROM child becomes zombie"
9505 # idea: run a udp-recvfrom process with fork and -T. Send it one packet, so a
9506 # sub process is forked off. Make some transfer and wait until the -T timeout
9507 # is over. Now check for the child process: if it is zombie the test failed.
9508 # Correct is that child process terminated
9509 if ! eval $NUMCOND; then :; else
9510 tf="$td/test$N.stdout"
9511 te="$td/test$N.stderr"
9512 tdiff="$td/test$N.diff"
9513 tsl=$PORT
9514 ts="$LOCALHOST:$tsl"
9515 da="test$N $(date) $RANDOM"
9516 CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-RECVFROM:$tsl,reuseaddr,fork PIPE"
9517 CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts"
9518 printf "test $F_n $TEST... " $N
9519 $CMD1 >"$tf" 2>"${te}1" &
9520 pid1=$!
9521 waitudp4port $tsl 1
9522 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9523 rc2=$?
9524 sleep 1
9525 #read -p ">"
9526 l="$(childprocess $pid1)"
9527 kill $pid1 2>/dev/null; wait
9528 if [ $rc2 -ne 0 ]; then
9529 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9530 numCANT=$((numCANT+1))
9531 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9532 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9533 numCANT=$((numCANT+1))
9534 elif $(isdefunct "$l"); then
9535 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9536 echo "$CMD1 &"
9537 echo "$CMD2"
9538 cat "${te}1" "${te}2"
9539 numFAIL=$((numFAIL+1))
9540 listFAIL="$listFAIL $N"
9541 else
9542 $PRINTF "$OK\n"
9543 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9544 numOK=$((numOK+1))
9546 fi ;; # NUMCOND
9547 esac
9548 PORT=$((PORT+1))
9549 N=$((N+1))
9552 # test: there was a bug with ip*-recv and bind option: it would not bind, and
9553 # with the first received packet an error:
9554 # socket_init(): unknown address family 0
9555 # occurred
9556 NAME=RAWIP4RECVBIND
9557 case "$TESTS" in
9558 *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
9559 TEST="$NAME: raw IPv4 receive with bind"
9560 # idea: start a socat process with ip4-recv:...,bind=... and send it a packet
9561 # if the packet passes the test succeeded
9562 if ! eval $NUMCOND; then :;
9563 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9564 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9565 numCANT=$((numCANT+1))
9566 else
9567 tf="$td/test$N.stdout"
9568 te="$td/test$N.stderr"
9569 tdiff="$td/test$N.diff"
9570 ts1p=$PROTO; PROTO=$((PROTO+1))
9571 ts1a="127.0.0.1"
9572 ts1="$ts1a:$ts1p"
9573 da="test$N $(date) $RANDOM"
9574 CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,bind=$ts1a,reuseaddr -"
9575 CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
9576 printf "test $F_n $TEST... " $N
9577 $CMD1 >"$tf" 2>"${te}1" &
9578 pid1="$!"
9579 waitip4proto $ts1p 1
9580 echo "$da" |$CMD2 2>>"${te}2"
9581 rc2="$?"
9582 #ls -l $tf
9583 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9584 kill "$pid1" 2>/dev/null; wait
9585 if [ "$rc2" -ne 0 ]; then
9586 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9587 echo "$CMD1 &"
9588 echo "$CMD2"
9589 cat "${te}1"
9590 cat "${te}2"
9591 numFAIL=$((numFAIL+1))
9592 listFAIL="$listFAIL $N"
9593 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9594 $PRINTF "$FAILED\n"
9595 cat "$tdiff"
9596 numFAIL=$((numFAIL+1))
9597 listFAIL="$listFAIL $N"
9598 else
9599 $PRINTF "$OK\n"
9600 if [ -n "$debug" ]; then cat $te; fi
9601 numOK=$((numOK+1))
9603 fi ;; # NUMCOND, root
9604 esac
9605 PROTO=$((PROTO+1))
9606 N=$((N+1))
9609 # there was a bug in *-recvfrom with fork: due to an error in the appropriate
9610 # signal handler the master process would hang after forking off the first
9611 # child process.
9612 NAME=UDP4RECVFROM_FORK
9613 case "$TESTS" in
9614 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
9615 TEST="$NAME: test if UDP4-RECVFROM handles more than one packet"
9616 # idea: run a UDP4-RECVFROM process with fork and -T. Send it one packet;
9617 # send it a second packet and check if this is processed properly. If yes, the
9618 # test succeeded.
9619 if ! eval $NUMCOND; then :; else
9620 tf="$td/test$N.stdout"
9621 te="$td/test$N.stderr"
9622 tdiff="$td/test$N.diff"
9623 tsp=$PORT
9624 ts="$LOCALHOST:$tsp"
9625 da="test$N $(date) $RANDOM"
9626 CMD1="$TRACE $SOCAT $opts -T 2 UDP4-RECVFROM:$tsp,reuseaddr,fork PIPE"
9627 CMD2="$TRACE $SOCAT $opts -T 1 - UDP4-SENDTO:$ts"
9628 printf "test $F_n $TEST... " $N
9629 $CMD1 >/dev/null 2>"${te}1" &
9630 pid1=$!
9631 waitudp4port $tsp 1
9632 echo "$da" |$CMD2 >/dev/null 2>>"${te}2" # this should always work
9633 rc2a=$?
9634 sleep 1
9635 echo "$da" |$CMD2 >"$tf" 2>>"${te}3" # this would fail when bug
9636 rc2b=$?
9637 kill $pid1 2>/dev/null; wait
9638 if [ $rc2b -ne 0 ]; then
9639 $PRINTF "$NO_RESULT\n"
9640 numCANT=$((numCANT+1))
9641 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9642 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9643 echo "$CMD1 &"
9644 echo "$CMD2"
9645 cat "${te}1" "${te}2" "${te}3"
9646 cat "$tdiff"
9647 numFAIL=$((numFAIL+1))
9648 listFAIL="$listFAIL $N"
9649 else
9650 $PRINTF "$OK\n"
9651 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3"; fi
9652 numOK=$((numOK+1))
9654 fi ;; # NUMCOND
9655 esac
9656 PORT=$((PORT+1))
9657 N=$((N+1))
9660 # there was a bug in parsing the arguments of exec: consecutive spaces resulted
9661 # in additional empty arguments
9662 NAME=EXECSPACES
9663 case "$TESTS" in
9664 *%$N%*|*%functions%*|*%exec%*|*%parse%*|*%$NAME%*)
9665 TEST="$NAME: correctly parse exec with consecutive spaces"
9666 if ! eval $NUMCOND; then :; else
9667 $PRINTF "test $F_n $TEST... " $N
9668 tf="$td/test$N.stdout"
9669 te="$td/test$N.stderr"
9670 da="test$N $(date) $RANDOM" # with a double space
9671 tdiff="$td/test$N.diff"
9672 # put the test data as first argument after two spaces. expect the data in the
9673 # first argument of the exec'd command.
9674 $TRACE $SOCAT $opts -u "exec:\"bash -c \\\"echo \\\\\\\"\$1\\\\\\\"\\\" \\\"\\\" \\\"$da\\\"\"" - >"$tf" 2>"$te"
9675 rc=$?
9676 echo "$da" |diff - "$tf" >"$tdiff"
9677 if [ "$rc" -ne 0 ]; then
9678 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9679 cat "$te"
9680 numFAIL=$((numFAIL+1))
9681 listFAIL="$listFAIL $N"
9682 elif [ -s "$tdiff" ]; then
9683 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9684 echo diff:
9685 cat "$tdiff"
9686 if [ -n "$debug" ]; then cat $te; fi
9687 numFAIL=$((numFAIL+1))
9688 listFAIL="$listFAIL $N"
9689 else
9690 $PRINTF "$OK\n"
9691 if [ -n "$debug" ]; then cat $te; fi
9692 numOK=$((numOK+1))
9694 fi ;; # NUMCOND
9695 esac
9696 N=$((N+1))
9699 # a bug was found in the way UDP-LISTEN handles the listening socket:
9700 # when UDP-LISTEN continued to listen after a packet had been dropped by, e.g.,
9701 # range option, the old listen socket would not be closed but a new one created.
9702 NAME=UDP4LISTENCONT
9703 case "$TESTS" in
9704 *%$N%*|*%functions%*|*%bugs%*|*%ip4%*|*%udp%*|*%$NAME%*)
9705 TEST="$NAME: let range drop a packet and see if old socket is closed"
9706 # idea: run a UDP4-LISTEN process with range option. Send it one packet from an
9707 # address outside range and check if two listening sockets are open then
9708 if ! eval $NUMCOND; then :; else
9709 tf="$td/test$N.stdout"
9710 te="$td/test$N.stderr"
9711 tdiff="$td/test$N.diff"
9712 if [ "$SS" ]; then
9713 while [ "$($SS -anu |grep "127\.0\.0\.1:$PORT\>" |wc -l)" -ne 0 ]; do
9714 PORT=$((PORT+1))
9715 done
9716 else
9717 while [ "$(netstat -an |grep "^udp.*127\.0\.0\.1:$PORT\>" |wc -l)" -ne 0 ]; do
9718 PORT=$((PORT+1))
9719 done
9721 tp=$PORT
9722 da1="test$N $(date) $RANDOM"
9723 a1="$LOCALHOST"
9724 a2="$SECONDADDR"
9725 #CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,bind=$a1,range=$a2/32 PIPE"
9726 CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,$REUSEADDR,range=$a2/32 PIPE"
9727 CMD1="$TRACE $SOCAT $opts - UDP-CONNECT:$a1:$tp"
9728 printf "test $F_n $TEST... " $N
9729 $CMD0 >/dev/null 2>"${te}0" &
9730 pid1=$!
9731 waitudp4port $tp 1
9732 echo "$da1" |$CMD1 >"${tf}1" 2>"${te}1" # this should fail
9733 rc1=$?
9734 waitudp4port $tp 1
9735 if [ "$SS" ]; then
9736 nsocks="$($SS -anu |grep ":$PORT\>" |wc -l)"
9737 else
9738 nsocks="$(netstat -an |grep "^udp.*[:.]$PORT\>" |wc -l)"
9740 kill $pid1 2>/dev/null; wait
9741 if [ $rc1 -ne 0 ]; then
9742 $PRINTF "$NO_RESULT\n"
9743 numCANT=$((numCANT+1))
9744 elif [ $nsocks -eq 0 ]; then
9745 $PRINTF "$NO_RESULT\n"
9746 numCANT=$((numCANT+1))
9747 elif [ $nsocks -ne 1 ]; then
9748 $PRINTF "$FAILED ($nsocks listening sockets)\n"
9749 echo "$CMD0 &"
9750 echo "$CMD1"
9751 cat "${te}0" "${te}1"
9752 numFAIL=$((numFAIL+1))
9753 listFAIL="$listFAIL $N"
9754 else
9755 $PRINTF "$OK\n"
9756 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
9757 numOK=$((numOK+1))
9759 fi ;; # NUMCOND
9760 esac
9761 PORT=$((PORT+1))
9762 N=$((N+1))
9765 # during wait for next poll time option ignoreeof blocked the data transfer in
9766 # the reverse direction
9767 NAME=IGNOREEOFNOBLOCK
9768 case "$TESTS" in
9769 *%$N%*|*%functions%*|*%engine%*|*%socket%*|*%ignoreeof%*|*%$NAME%*)
9770 TEST="$NAME: ignoreeof does not block other direction"
9771 # have socat poll in ignoreeof mode. while it waits one second for next check,
9772 # we send data in the reverse direction and then the total timeout fires.
9773 # it the data has passed, the test succeeded.
9774 if ! eval $NUMCOND; then :; else
9775 tf="$td/test$N.stout"
9776 te="$td/test$N.stderr"
9777 tdiff="$td/test$N.diff"
9778 da="test$N $(date) $RANDOM"
9779 CMD0="$TRACE $SOCAT $opts /dev/null,ignoreeof!!- -!!/dev/null"
9780 printf "test $F_n $TEST... " $N
9781 (usleep 333333; echo "$da") |$CMD0 >"$tf" 2>"${te}0"
9782 rc0=$?
9783 if [ $rc0 != 0 ]; then
9784 $PRINTF "$FAILED\n"
9785 echo "$CMD0 &"
9786 echo "$CMD1"
9787 cat "${te}0"
9788 cat "${te}1"
9789 numFAIL=$((numFAIL+1))
9790 listFAIL="$listFAIL $N"
9791 elif echo "$da" |diff - "$tf" >/dev/null; then
9792 $PRINTF "$OK\n"
9793 numOK=$((numOK+1))
9794 else
9795 $PRINTF "$FAILED\n"
9796 echo "$CMD0 &"
9797 echo "$CMD1"
9798 cat "${te}0"
9799 numFAIL=$((numFAIL+1))
9800 listFAIL="$listFAIL $N"
9802 fi ;; # NUMCOND
9803 esac
9804 N=$((N+1))
9807 # test the escape option
9808 NAME=ESCAPE
9809 case "$TESTS" in
9810 *%$N%*|*%functions%*|*%engine%*|*%escape%*|*%$NAME%*)
9811 TEST="$NAME: escape character triggers EOF"
9812 # idea: start socat just echoing input, but apply escape option. send a string
9813 # containing the escape character and check if the output is truncated
9814 if ! eval $NUMCOND; then :; else
9815 tf="$td/test$N.stdout"
9816 te="$td/test$N.stderr"
9817 tdiff="$td/test$N.diff"
9818 da="test$N $(date) $RANDOM"
9819 CMD="$TRACE $SOCAT $opts -,escape=27 pipe"
9820 printf "test $F_n $TEST... " $N
9821 $ECHO "$da\n\x1bXYZ" |$CMD >"$tf" 2>"$te"
9822 if [ $? -ne 0 ]; then
9823 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9824 echo "$CMD"
9825 cat "$te"
9826 numFAIL=$((numFAIL+1))
9827 listFAIL="$listFAIL $N"
9828 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9829 $PRINTF "$FAILED: diff:\n"
9830 cat "$tdiff"
9831 numFAIL=$((numFAIL+1))
9832 listFAIL="$listFAIL $N"
9833 else
9834 $PRINTF "$OK\n"
9835 if [ -n "$debug" ]; then cat $te; fi
9836 numOK=$((numOK+1))
9838 fi ;; # NUMCOND
9839 esac
9840 N=$((N+1))
9842 # test the escape option combined with ignoreeof
9843 NAME=ESCAPE_IGNOREEOF
9844 case "$TESTS" in
9845 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%escape%*|*%$NAME%*)
9846 TEST="$NAME: escape character triggers EOF"
9847 # idea: start socat just echoing input, but apply escape option. send a string
9848 # containing the escape character and check if the output is truncated
9849 if ! eval $NUMCOND; then :; else
9850 ti="$td/test$N.file"
9851 tf="$td/test$N.stdout"
9852 te="$td/test$N.stderr"
9853 tdiff="$td/test$N.diff"
9854 da="test$N $(date) $RANDOM"
9855 CMD="$TRACE $SOCAT -T 5 $opts file:$ti,ignoreeof,escape=27!!- pipe"
9856 printf "test $F_n $TEST... " $N
9857 >"$ti"
9858 $CMD >"$tf" 2>"$te" &
9859 $ECHO "$da\n\x1bXYZ" >>"$ti"
9860 sleep 1
9861 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
9862 $PRINTF "$FAILED: diff:\n"
9863 cat "$tdiff"
9864 cat "$te"
9865 numFAIL=$((numFAIL+1))
9866 listFAIL="$listFAIL $N"
9867 else
9868 $PRINTF "$OK\n"
9869 if [ -n "$debug" ]; then cat $te; fi
9870 numOK=$((numOK+1))
9872 fi ;; # NUMCOND
9873 esac
9874 N=$((N+1))
9877 # test: logging of ancillary message
9878 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_TYPE SCM_NAME ROOT SCM_VALUE
9880 if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
9882 pf="$(echo "$PF" |tr A-Z a-z)"
9883 proto="$(echo "$KEYW" |tr A-Z a-z)"
9884 NAME=${KEYW}SCM_$SCM_TYPE
9885 case "$TESTS" in
9886 *%$N%*|*%functions%*|*%socket%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%$ROOT%*|*%$NAME%*)
9887 TEST="$NAME: $KEYW log ancillary message $SCM_TYPE $SCM_NAME"
9888 # idea: start a socat process with *-RECV:..,... , ev. with ancillary message
9889 # enabling option and send it a packet, ev. with some option. check the info log
9890 # for the appropriate output.
9891 if ! eval $NUMCOND; then :;
9892 #elif [[ "$PF" == "#*" ]]; then :
9893 elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9894 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9895 numCANT=$((numCANT+1))
9896 elif [ "$PF" = "IP6" ] && ( ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null ); then
9897 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
9898 numCANT=$((numCANT+1))
9899 elif ! testoptions $SCM_RECV >/dev/null; then
9900 $PRINTF "test $F_n $TEST... ${YELLOW}option $SCM_RECV not available${NORMAL}\n" $N
9901 numCANT=$((numCANT+1))
9902 else
9903 tf="$td/test$N.stdout"
9904 te="$td/test$N.stderr"
9905 case "X$IPPORT" in
9906 "XPORT")
9907 tra="$PORT" # test recv address
9908 tsa="$ADDR:$PORT" # test sendto address
9909 PORT=$((PORT+1)) ;;
9910 "XPROTO")
9911 tra="$PROTO" # test recv address
9912 tsa="$ADDR:$PROTO" # test sendto address
9913 PROTO=$((PROTO+1)) ;;
9915 tra="$(eval echo "$ADDR")" # resolve $N
9916 tsa="$tra"
9917 esac
9918 CMD0="$TRACE $SOCAT $opts -d -d -d -u $KEYW-RECV:$tra,reuseaddr,$SCM_RECV -"
9919 CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
9920 printf "test $F_n $TEST... " $N
9921 # is this option supported?
9922 if $TRACE $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
9923 $CMD0 >"$tf" 2>"${te}0" &
9924 pid0="$!"
9925 wait${proto}port $tra 1
9926 echo "XYZ" |$CMD1 2>"${te}1"
9927 rc1="$?"
9928 sleep 1
9929 i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9930 kill "$pid0" 2>/dev/null; wait
9931 # do not show more messages than requested
9932 case "$opts" in
9933 *-d*-d*-d*-d*) LEVELS="[EWNID]" ;;
9934 *-d*-d*-d*) LEVELS="[EWNI]" ;;
9935 *-d*-d*) LEVELS="[EWN]" ;;
9936 *-d*) LEVELS="[EW]" ;;
9937 *) LEVELS="[E]" ;;
9938 esac
9939 if [ "$SCM_VALUE" = "timestamp" ]; then
9940 SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
9942 if [ "$rc1" -ne 0 ]; then
9943 $PRINTF "$NO_RESULT: $TRACE $SOCAT:\n"
9944 echo "$CMD0 &"
9945 echo "$CMD1"
9946 grep " $LEVELS " "${te}0"
9947 grep " $LEVELS " "${te}1"
9948 numCANT=$((numCANT+1))
9949 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=" ${te}0 >/dev/null; then
9950 $PRINTF "$FAILED\n"
9951 echo "variable $SCM_TYPE: $SCM_NAME not set"
9952 echo "$CMD0 &"
9953 echo "$CMD1"
9954 grep " $LEVELS " "${te}0"
9955 grep " $LEVELS " "${te}1"
9956 numFAIL=$((numFAIL+1))
9957 listFAIL="$listFAIL $N"
9958 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=$SCM_VALUE\$" ${te}0 >/dev/null; then
9959 $PRINTF "$FAILED\n"
9960 badval="$(grep "ancillary message: $SCM_TYPE: $SCM_NAME" ${te}0 |sed 's/.*=//g')"
9961 echo "variable $SCM_TYPE: $SCM_NAME has value \"$badval\" instead of pattern \"$SCM_VALUE\"" >&2
9962 echo "$CMD0 &"
9963 echo "$CMD1"
9964 grep " $LEVELS " "${te}0"
9965 grep " $LEVELS " "${te}1"
9966 numFAIL=$((numFAIL+1))
9967 listFAIL="$listFAIL $N"
9968 else
9969 $PRINTF "$OK\n"
9970 if [ -n "$debug" ]; then
9971 grep " $LEVELS " "${te}0"; echo; grep " $LEVELS " "${te}1";
9973 numOK=$((numOK+1))
9975 else # option is not supported
9976 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
9977 numCANT=$((numCANT+1))
9978 fi # option is not supported
9979 fi # NUMCOND, root, feats
9981 esac
9982 N=$((N+1))
9984 done <<<"
9985 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS options user x01000000
9986 IP4 UDP4 127.0.0.1 PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
9987 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL ttl user 53
9988 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS tos user 7
9989 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO locaddr user 127.0.0.1
9990 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO dstaddr user 127.0.0.1
9991 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO if user lo
9992 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_RECVIF if user lo0
9993 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_RECVDSTADDR dstaddr user 127.0.0.1
9994 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS options root x01000000
9995 IP4 IP4 127.0.0.1 PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
9996 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL ttl root 53
9997 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS tos root 7
9998 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO locaddr root 127.0.0.1
9999 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO dstaddr root 127.0.0.1
10000 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO if root lo
10001 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_RECVIF if root lo0
10002 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_RECVDSTADDR dstaddr root 127.0.0.1
10003 IP6 UDP6 [::1] PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10004 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_PKTINFO dstaddr user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10005 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit user 35
10006 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass user x000000aa
10007 IP6 IP6 [::1] PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
10008 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_PKTINFO dstaddr root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10009 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit root 35
10010 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass root x000000aa
10011 #UNIX UNIX $td/test\$N.server - , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10013 # this one fails, appearently due to a Linux weakness:
10014 # UNIX so-timestamp
10017 # test: setting of environment variables that describe a stream socket
10018 # connection: SOCAT_SOCKADDR, SOCAT_PEERADDR; and SOCAT_SOCKPORT,
10019 # SOCAT_PEERPORT when applicable
10020 while read KEYW FEAT TEST_SOCKADDR TEST_PEERADDR TEST_SOCKPORT TEST_PEERPORT; do
10021 if [ -z "$KEYW" ] || [[ "$KEYW" == \#* ]]; then continue; fi
10023 test_proto="$(echo "$KEYW" |tr A-Z a-z)"
10024 NAME=${KEYW}LISTENENV
10025 case "$TESTS" in
10026 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$test_proto%*|*%envvar%*|*%$NAME%*)
10027 TEST="$NAME: $KEYW-LISTEN sets environment variables with socket addresses"
10028 # have a server accepting a connection and invoking some shell code. The shell
10029 # code extracts and prints the SOCAT related environment vars.
10030 # outside code then checks if the environment contains the variables correctly
10031 # describing the peer and local sockets.
10032 if ! eval $NUMCOND; then :;
10033 elif ! feat=$(testaddrs $FEAT); then
10034 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
10035 numCANT=$((numCANT+1))
10036 elif [ "$KEYW" = "TCP6" -o "$KEYW" = "UDP6" -o "$KEYW" = "SCTP6" ] && \
10037 ! runsip6 >/dev/null; then
10038 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10039 numCANT=$((numCANT+1))
10040 elif [ "$KEYW" = "SCTP4" ] && ! runssctp4 "$((PORT))"; then
10041 $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
10042 elif [ "$KEYW" = "SCTP6" ] && ! runssctp6 "$((PORT))"; then
10043 #!!! branch not reached - caught above!
10044 $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
10045 else
10046 tf="$td/test$N.stdout"
10047 te="$td/test$N.stderr"
10048 TEST_SOCKADDR="$(echo "$TEST_SOCKADDR" |sed "s/\$N/$N/g")" # actual vars
10049 tsa="$TEST_SOCKADDR" # test server address
10050 tsp="$TEST_SOCKPORT" # test server port
10051 if [ "$tsp" != ',' ]; then
10052 tsa1="$tsp"; tsa2="$tsa"; tsa="$tsa:$tsp" # tsa2 used for server bind=
10053 else
10054 tsa1="$tsa"; tsa2= # tsa1 used for addr parameter
10056 TEST_PEERADDR="$(echo "$TEST_PEERADDR" |sed "s/\$N/$N/g")" # actual vars
10057 tca="$TEST_PEERADDR" # test client address
10058 tcp="$TEST_PEERPORT" # test client port
10059 if [ "$tcp" != ',' ]; then
10060 tca="$tca:$tcp"
10062 #CMD0="$TRACE $SOCAT $opts -u $KEYW-LISTEN:$tsa1 SYSTEM:\"export -p\""
10063 CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-LISTEN:$tsa1,$REUSEADDR SYSTEM:\"echo SOCAT_SOCKADDR=\\\$SOCAT_SOCKADDR; echo SOCAT_PEERADDR=\\\$SOCAT_PEERADDR; echo SOCAT_SOCKPORT=\\\$SOCAT_SOCKPORT; echo SOCAT_PEERPORT=\\\$SOCAT_PEERPORT; sleep 1\""
10064 CMD1="$TRACE $SOCAT $opts -u - $KEYW-CONNECT:$tsa,bind=$tca"
10065 printf "test $F_n $TEST... " $N
10066 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
10067 pid0=$!
10068 wait${test_proto}port $tsa1 1
10069 echo |$CMD1 2>"${te}1"
10070 rc1=$?
10071 waitfile "$tf" 2
10072 kill $pid0 2>/dev/null; wait
10073 #set -vx
10074 if [ $rc1 != 0 ]; then
10075 $PRINTF "$NO_RESULT (client failed):\n"
10076 echo "$CMD0 &"
10077 cat "${te}0"
10078 echo "$CMD1"
10079 cat "${te}1"
10080 numCANT=$((numCANT+1))
10081 elif [ "$(grep SOCAT_SOCKADDR "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")" = "$TEST_SOCKADDR" -a \
10082 "$(grep SOCAT_PEERADDR "${tf}" |sed -e 's/^[^=]*=//' -e "s/[\"']//g")" = "$TEST_PEERADDR" -a \
10083 \( "$TEST_SOCKPORT" = ',' -o "$(grep SOCAT_SOCKPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tsp" \) -a \
10084 \( "$TEST_PEERPORT" = ',' -o "$(grep SOCAT_PEERPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tcp" \) \
10085 ]; then
10086 $PRINTF "$OK\n"
10087 if [ "$debug" ]; then
10088 echo "$CMD0 &"
10089 cat "${te}0"
10090 echo "$CMD1"
10091 cat "${te}1"
10093 numOK=$((numOK+1))
10094 else
10095 $PRINTF "$FAILED\n"
10096 echo "$CMD0 &"
10097 cat "${te}0"
10098 echo "$CMD1"
10099 cat "${te}1"
10100 echo -e "SOCAT_SOCKADDR=$TEST_SOCKADDR\nSOCAT_PEERADDR=$TEST_PEERADDR\nSOCAT_SOCKPORT=$TEST_SOCKPORT\nSOCAT_PEERPORT=$TEST_PEERPORT" |
10101 diff - "${tf}"
10102 numFAIL=$((numFAIL+1))
10103 listFAIL="$listFAIL $N"
10105 fi # NUMCOND, feats
10107 esac
10108 N=$((N+1))
10109 #set +xv
10111 done <<<"
10112 TCP4 TCP 127.0.0.1 $SECONDADDR $PORT $((PORT+1))
10113 TCP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+2)) $((PORT+3))
10114 UDP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+6)) $((PORT+7))
10115 SCTP4 SCTP 127.0.0.1 $SECONDADDR $((PORT+8)) $((PORT+9))
10116 SCTP6 SCTP [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+10)) $((PORT+11))
10117 UNIX UNIX $td/test\$N.server $td/test\$N.client , ,
10119 # this one fails due to weakness in socats UDP4-LISTEN implementation:
10120 #UDP4 $LOCALHOST $SECONDADDR $((PORT+4)) $((PORT+5))
10123 # test: environment variables from ancillary message
10124 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_ENVNAME ROOT SCM_VALUE
10126 if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
10128 pf="$(echo "$PF" |tr A-Z a-z)"
10129 proto="$(echo "$KEYW" |tr A-Z a-z)"
10130 NAME=${KEYW}ENV_$SCM_ENVNAME
10131 case "$TESTS" in
10132 *%$N%*|*%functions%*|*%socket%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%envvar%*|*%$ROOT%*|*%$NAME%*)
10133 #set -vx
10134 TEST="$NAME: $KEYW ancillary message sets env SOCAT_$SCM_ENVNAME"
10135 # idea: start a socat process with *-RECVFROM:..,... , ev. with ancillary
10136 # message enabling option and send it a packet, ev. with some option. write
10137 # the resulting environment to a file and check its contents for the
10138 # appropriate variable.
10139 if ! eval $NUMCOND; then :;
10140 elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
10141 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
10142 numCANT=$((numCANT+1))
10143 elif [ "$PF" = "IP6" ] && ( ! feat=$(testaddrs ip6) || ! runsip6 ) >/dev/null; then
10144 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10145 numCANT=$((numCANT+1))
10146 else
10147 tf="$td/test$N.stdout"
10148 te="$td/test$N.stderr"
10149 case "X$IPPORT" in
10150 "XPORT")
10151 tra="$PORT" # test recv address
10152 tsa="$ADDR:$PORT" # test sendto address
10153 PORT=$((PORT+1)) ;;
10154 "XPROTO")
10155 tra="$PROTO" # test recv address
10156 tsa="$ADDR:$PROTO" # test sendto address
10157 PROTO=$((PROTO+1)) ;;
10159 tra="$(eval echo "$ADDR")" # resolve $N
10160 tsa="$tra"
10161 esac
10162 #CMD0="$TRACE $SOCAT $opts -u $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"export -p\""
10163 CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"echo \\\$SOCAT_$SCM_ENVNAME\""
10164 CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
10165 printf "test $F_n $TEST... " $N
10166 # is this option supported?
10167 if $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
10168 eval "$CMD0 >\"$tf\" 2>\"${te}0\" &"
10169 pid0="$!"
10170 wait${proto}port $tra 1
10171 echo "XYZ" |$CMD1 2>"${te}1"
10172 rc1="$?"
10173 waitfile "$tf" 2
10174 #i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
10175 kill "$pid0" 2>/dev/null; wait
10176 # do not show more messages than requested
10177 if [ "$SCM_VALUE" = "timestamp" ]; then
10178 SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
10180 if [ "$rc1" -ne 0 ]; then
10181 $PRINTF "$NO_RESULT: $SOCAT:\n"
10182 echo "$CMD0 &"
10183 echo "$CMD1"
10184 cat "${te}0"
10185 cat "${te}1"
10186 numCANT=$((numCANT+1))
10187 #elif ! egrep "^export SOCAT_$SCM_ENVNAME=[\"']?$SCM_VALUE[\"']?\$" ${tf} >/dev/null; then
10188 #elif ! eval echo "$TRACE $SOCAT_\$SCM_VALUE" |diff - "${tf}" >/dev/null; then
10189 elif ! expr "$(cat "$tf")" : "$(eval echo "\$SCM_VALUE")\$" >/dev/null; then
10190 $PRINTF "$FAILED\n"
10191 echo "logged value \"$(cat "$tf")\" instead of \"$(eval echo "\$SCM_VALUE")\""
10192 echo "$CMD0 &"
10193 echo "$CMD1"
10194 cat "${te}0"
10195 cat "${te}1"
10196 numFAIL=$((numFAIL+1))
10197 listFAIL="$listFAIL $N"
10198 else
10199 $PRINTF "$OK\n"
10200 if [ -n "$debug" ]; then
10201 cat "${te}0"; echo; cat "${te}1";
10203 numOK=$((numOK+1))
10205 else # option is not supported
10206 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
10207 numCANT=$((numCANT+1))
10208 fi # option is not supported
10209 fi ;; # NUMCOND, feats
10210 esac
10211 N=$((N+1))
10213 done <<<"
10214 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS user x01000000
10215 IP4 UDP4 127.0.0.1 PORT , so-timestamp TIMESTAMP user timestamp
10216 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL user 53
10217 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS user 7
10218 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_LOCADDR user 127.0.0.1
10219 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_DSTADDR user 127.0.0.1
10220 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_IF user lo
10221 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_IF user lo0
10222 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_DSTADDR user 127.0.0.1
10223 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS root x01000000
10224 IP4 IP4 127.0.0.1 PROTO , so-timestamp TIMESTAMP root timestamp
10225 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL root 53
10226 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS root 7
10227 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_LOCADDR root 127.0.0.1
10228 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_DSTADDR root 127.0.0.1
10229 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_IF root lo
10230 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_IF root lo0
10231 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_DSTADDR root 127.0.0.1
10232 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_DSTADDR user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10233 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT user 35
10234 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS user x000000aa
10235 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_DSTADDR root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10236 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT root 35
10237 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS root x000000aa
10238 #UNIX UNIX $td/test\$N.server - , so-timestamp TIMESTAMP user timestamp
10242 # test the SOCKET-CONNECT address (against TCP4-LISTEN)
10243 NAME=SOCKET_CONNECT_TCP4
10244 case "$TESTS" in
10245 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
10246 TEST="$NAME: socket connect with TCP/IPv4"
10247 # start a TCP4-LISTEN process that echoes data, and send test data using
10248 # SOCKET-CONNECT, selecting TCP/IPv4. The sent data should be returned.
10249 if ! eval $NUMCOND; then :; else
10250 tf="$td/test$N.stdout"
10251 te="$td/test$N.stderr"
10252 tdiff="$td/test$N.diff"
10253 ts0p=$PORT; PORT=$((PORT+1))
10254 ts0a="127.0.0.1"
10255 ts1p=$(printf "%04x" $ts0p);
10256 ts1a="7f000001" # "127.0.0.1"
10257 ts1="x${ts1p}${ts1a}x0000000000000000"
10258 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10259 da="test$N $(date) $RANDOM"
10260 CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$ts0p,$REUSEADDR,bind=$ts0a PIPE"
10261 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:2:6:$ts1,bind=x${ts1b}00000000x0000000000000000"
10262 printf "test $F_n $TEST... " $N
10263 $CMD0 2>"${te}0" &
10264 pid0="$!"
10265 waittcp4port $ts0p 1
10266 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10267 rc1="$?"
10268 kill "$pid0" 2>/dev/null; wait;
10269 if [ "$rc1" -ne 0 ]; then
10270 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10271 echo "$CMD0 &"
10272 cat "${te}0"
10273 echo "$CMD1"
10274 cat "${te}1"
10275 numFAIL=$((numFAIL+1))
10276 listFAIL="$listFAIL $N"
10277 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10278 $PRINTF "$FAILED\n"
10279 cat "$tdiff"
10280 echo "$CMD0 &"
10281 cat "${te}0"
10282 echo "$CMD1"
10283 cat "${te}1"
10284 numFAIL=$((numFAIL+1))
10285 listFAIL="$listFAIL $N"
10286 else
10287 $PRINTF "$OK\n"
10288 if [ -n "$debug" ]; then cat $te; fi
10289 numOK=$((numOK+1))
10291 fi # NUMCOND
10293 esac
10294 PORT=$((PORT+1))
10295 N=$((N+1))
10297 PF_INET6="$($PROCAN -c |grep "^#define[[:space:]]*PF_INET6[[:space:]]" |cut -d' ' -f3)"
10299 # test the SOCKET-CONNECT address (against TCP6-LISTEN)
10300 NAME=SOCKET_CONNECT_TCP6
10301 case "$TESTS" in
10302 *%$N%*|*%functions%*|*%generic%*|*%tcp6%*|*%socket%*|*%$NAME%*)
10303 TEST="$NAME: socket connect with TCP/IPv6"
10304 if ! eval $NUMCOND; then :;
10305 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
10306 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
10307 numCANT=$((numCANT+1))
10308 else
10309 # start a TCP6-LISTEN process that echoes data, and send test data using
10310 # SOCKET-CONNECT, selecting TCP/IPv6. The sent data should be returned.
10311 tf="$td/test$N.stdout"
10312 te="$td/test$N.stderr"
10313 tdiff="$td/test$N.diff"
10314 ts0p=$PORT; PORT=$((PORT+1))
10315 ts0a="[::1]"
10316 ts1p=$(printf "%04x" $ts0p);
10317 ts1a="00000000000000000000000000000001" # "[::1]"
10318 ts1="x${ts1p}x00000000x${ts1a}x00000000"
10319 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10320 da="test$N $(date) $RANDOM"
10321 CMD0="$TRACE $SOCAT $opts TCP6-LISTEN:$ts0p,$REUSEADDR,bind=$ts0a PIPE"
10322 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:$PF_INET6:6:$ts1,bind=x${ts1b}x00000000x00000000000000000000000000000000x00000000"
10323 printf "test $F_n $TEST... " $N
10324 $CMD0 2>"${te}0" &
10325 pid0="$!"
10326 waittcp6port $ts0p 1
10327 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10328 rc1="$?"
10329 kill "$pid0" 2>/dev/null; wait;
10330 if [ "$rc1" -ne 0 ]; then
10331 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10332 echo "$CMD0 &"
10333 cat "${te}0"
10334 echo "$CMD1"
10335 cat "${te}1"
10336 numFAIL=$((numFAIL+1))
10337 listFAIL="$listFAIL $N"
10338 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10339 $PRINTF "$FAILED\n"
10340 cat "$tdiff"
10341 echo "$CMD0 &"
10342 cat "${te}0"
10343 echo "$CMD1"
10344 cat "${te}1"
10345 numFAIL=$((numFAIL+1))
10346 listFAIL="$listFAIL $N"
10347 else
10348 $PRINTF "$OK\n"
10349 if [ -n "$debug" ]; then cat $te; fi
10350 numOK=$((numOK+1))
10352 fi ;; # NUMCOND
10353 esac
10354 PORT=$((PORT+1))
10355 N=$((N+1))
10357 # test the SOCKET-CONNECT address (against UNIX-LISTEN)
10358 NAME=SOCKET_CONNECT_UNIX
10359 case "$TESTS" in
10360 *%$N%*|*%functions%*|*%generic%*|*%unix%*|*%socket%*|*%$NAME%*)
10361 TEST="$NAME: socket connect with UNIX domain"
10362 # start a UNIX-LISTEN process that echoes data, and send test data using
10363 # SOCKET-CONNECT, selecting UNIX socket. The sent data should be returned.
10364 if ! eval $NUMCOND; then :; else
10365 tf="$td/test$N.stdout"
10366 te="$td/test$N.stderr"
10367 tdiff="$td/test$N.diff"
10368 ts0="$td/test$N.server"
10369 ts1="$td/test$N.client"
10370 da="test$N $(date) $RANDOM"
10371 CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts0,$REUSEADDR PIPE"
10372 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:1:0:\\\"$ts0\\\0\\\",bind=\\\"$ts1\\\0\\\""
10373 printf "test $F_n $TEST... " $N
10374 $CMD0 2>"${te}0" &
10375 pid0="$!"
10376 waitfile $ts0 1
10377 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10378 rc1="$?"
10379 kill "$pid0" 2>/dev/null; wait;
10380 if [ "$rc1" -ne 0 ]; then
10381 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10382 echo "$CMD0 &"
10383 cat "${te}0"
10384 echo "$CMD1"
10385 cat "${te}1"
10386 numFAIL=$((numFAIL+1))
10387 listFAIL="$listFAIL $N"
10388 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10389 $PRINTF "$FAILED\n"
10390 cat "$tdiff"
10391 echo "$CMD0 &"
10392 cat "${te}0"
10393 echo "$CMD1"
10394 cat "${te}1"
10395 numFAIL=$((numFAIL+1))
10396 listFAIL="$listFAIL $N"
10397 else
10398 $PRINTF "$OK\n"
10399 if [ -n "$debug" ]; then cat $te; fi
10400 numOK=$((numOK+1))
10402 fi ;; # NUMCOND
10403 esac
10404 N=$((N+1))
10406 # test the SOCKET-LISTEN address (with TCP4-CONNECT)
10407 NAME=SOCKET_LISTEN
10408 case "$TESTS" in
10409 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
10410 TEST="$NAME: socket recvfrom with TCP/IPv4"
10411 # start a SOCKET-LISTEN process that uses TCP/IPv4 and echoes data, and
10412 # send test data using TCP4-CONNECT. The sent data should be returned.
10413 if ! eval $NUMCOND; then :; else
10414 tf="$td/test$N.stdout"
10415 te="$td/test$N.stderr"
10416 tdiff="$td/test$N.diff"
10417 ts1p=$PORT; PORT=$((PORT+1))
10418 ts1a="127.0.0.1"
10419 ts0p=$(printf "%04x" $ts1p);
10420 ts0a="7f000001" # "127.0.0.1"
10421 ts0="x${ts0p}${ts0a}x0000000000000000"
10422 ts1b=$PORT; PORT=$((PORT+1))
10423 ts1="$ts1a:$ts1p"
10424 da="test$N $(date) $RANDOM"
10425 CMD0="$TRACE $SOCAT $opts SOCKET-LISTEN:2:6:$ts0,$REUSEADDR PIPE"
10426 CMD1="$TRACE $SOCAT $opts - TCP4-CONNECT:$ts1,bind=:$ts1b"
10427 printf "test $F_n $TEST... " $N
10428 $CMD0 2>"${te}0" &
10429 pid0="$!"
10430 #sleep 1
10431 waittcp4port $ts1p 1
10432 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10433 rc1="$?"
10434 kill "$pid0" 2>/dev/null; wait;
10435 if [ "$rc1" -ne 0 ]; then
10436 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10437 echo "$CMD0 &"
10438 cat "${te}0"
10439 echo "$CMD1"
10440 cat "${te}1"
10441 numFAIL=$((numFAIL+1))
10442 listFAIL="$listFAIL $N"
10443 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10444 $PRINTF "$FAILED\n"
10445 cat "$tdiff"
10446 echo "$CMD0 &"
10447 cat "${te}0"
10448 echo "$CMD1"
10449 cat "${te}1"
10450 numFAIL=$((numFAIL+1))
10451 listFAIL="$listFAIL $N"
10452 else
10453 $PRINTF "$OK\n"
10454 if [ -n "$debug" ]; then cat $te; fi
10455 numOK=$((numOK+1))
10457 fi ;; # NUMCOND
10458 esac
10459 PORT=$((PORT+1))
10460 N=$((N+1))
10462 SOCK_DGRAM="$($PROCAN -c |grep "^#define[[:space:]]*SOCK_DGRAM[[:space:]]" |cut -d' ' -f3)"
10464 # test the SOCKET-SENDTO address (against UDP4-RECVFROM)
10465 NAME=SOCKET_SENDTO
10466 case "$TESTS" in
10467 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10468 TEST="$NAME: socket sendto with UDP/IPv4"
10469 # start a UDP4-RECVFROM process that echoes data, and send test data using
10470 # SOCKET-SENDTO, selecting UDP/IPv4. The sent data should be returned.
10471 if ! eval $NUMCOND; then :; else
10472 tf="$td/test$N.stdout"
10473 te="$td/test$N.stderr"
10474 tdiff="$td/test$N.diff"
10475 ts0p=$PORT; PORT=$((PORT+1))
10476 ts0a="127.0.0.1"
10477 ts1p=$(printf "%04x" $ts0p);
10478 ts1a="7f000001" # "127.0.0.1"
10479 ts1="x${ts1p}${ts1a}x0000000000000000"
10480 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10481 da="test$N $(date) $RANDOM"
10482 CMD0="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts0p,reuseaddr,bind=$ts0a PIPE"
10483 CMD1="$TRACE $SOCAT $opts - SOCKET-SENDTO:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10484 printf "test $F_n $TEST... " $N
10485 $CMD0 2>"${te}0" &
10486 pid0="$!"
10487 waitudp4port $ts0p 1
10488 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10489 rc1="$?"
10490 kill "$pid0" 2>/dev/null; wait;
10491 if [ "$rc1" -ne 0 ]; then
10492 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10493 echo "$CMD0 &"
10494 cat "${te}0"
10495 echo "$CMD1"
10496 cat "${te}1"
10497 numFAIL=$((numFAIL+1))
10498 listFAIL="$listFAIL $N"
10499 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10500 $PRINTF "$FAILED\n"
10501 cat "$tdiff"
10502 echo "$CMD0 &"
10503 cat "${te}0"
10504 echo "$CMD1"
10505 cat "${te}1"
10506 numFAIL=$((numFAIL+1))
10507 listFAIL="$listFAIL $N"
10508 else
10509 $PRINTF "$OK\n"
10510 if [ -n "$debug" ]; then cat $te; fi
10511 numOK=$((numOK+1))
10513 fi ;; # NUMCOND
10514 esac
10515 PORT=$((PORT+1))
10516 N=$((N+1))
10518 # test the SOCKET-RECVFROM address (with UDP4-SENDTO)
10519 NAME=SOCKET_RECVFROM
10520 case "$TESTS" in
10521 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10522 TEST="$NAME: socket recvfrom with UDP/IPv4"
10523 # start a SOCKET-RECVFROM process that uses UDP/IPv4 and echoes data, and
10524 # send test data using UDP4-SENDTO. The sent data should be returned.
10525 if ! eval $NUMCOND; then :; else
10526 tf="$td/test$N.stdout"
10527 te="$td/test$N.stderr"
10528 tdiff="$td/test$N.diff"
10529 ts1p=$PORT; PORT=$((PORT+1))
10530 ts1a="127.0.0.1"
10531 ts0p=$(printf "%04x" $ts1p);
10532 ts0a="7f000001" # "127.0.0.1"
10533 ts0="x${ts0p}${ts0a}x0000000000000000"
10534 ts1b=$PORT; PORT=$((PORT+1))
10535 ts1="$ts1a:$ts1p"
10536 da="test$N $(date) $RANDOM"
10537 CMD0="$TRACE $SOCAT $opts SOCKET-RECVFROM:2:$SOCK_DGRAM:17:$ts0,reuseaddr PIPE"
10538 CMD1="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=:$ts1b"
10539 printf "test $F_n $TEST... " $N
10540 $CMD0 2>"${te}0" &
10541 pid0="$!"
10542 sleep 1 # waitudp4port $ts1p 1
10543 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10544 rc1="$?"
10545 kill "$pid0" 2>/dev/null; wait;
10546 if [ "$rc1" -ne 0 ]; then
10547 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10548 echo "$CMD0 &"
10549 cat "${te}0"
10550 echo "$CMD1"
10551 cat "${te}1"
10552 numFAIL=$((numFAIL+1))
10553 listFAIL="$listFAIL $N"
10554 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10555 $PRINTF "$FAILED\n"
10556 cat "$tdiff"
10557 echo "$CMD0 &"
10558 cat "${te}0"
10559 echo "$CMD1"
10560 cat "${te}1"
10561 numFAIL=$((numFAIL+1))
10562 listFAIL="$listFAIL $N"
10563 else
10564 $PRINTF "$OK\n"
10565 if [ -n "$debug" ]; then cat $te; fi
10566 numOK=$((numOK+1))
10568 fi ;; # NUMCOND
10569 esac
10570 PORT=$((PORT+1))
10571 N=$((N+1))
10574 # test the SOCKET-RECV address (with UDP4-SENDTO)
10575 NAME=SOCKET_RECV
10576 case "$TESTS" in
10577 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10578 TEST="$NAME: socket recv with UDP/IPv4"
10579 # start a SOCKET-RECV process that uses UPD/IPv4 and writes received data to file, and
10580 # send test data using UDP4-SENDTO.
10581 if ! eval $NUMCOND; then :; else
10582 tf="$td/test$N.stdout"
10583 te="$td/test$N.stderr"
10584 tdiff="$td/test$N.diff"
10585 ts1p=$PORT; PORT=$((PORT+1))
10586 ts1a="127.0.0.1"
10587 ts0p=$(printf "%04x" $ts1p);
10588 ts0a="7f000001" # "127.0.0.1"
10589 ts0="x${ts0p}${ts0a}x0000000000000000"
10590 ts1b=$PORT; PORT=$((PORT+1))
10591 ts1="$ts1a:$ts1p"
10592 da="test$N $(date) $RANDOM"
10593 CMD0="$TRACE $SOCAT $opts -u SOCKET-RECV:2:$SOCK_DGRAM:17:$ts0,reuseaddr -"
10594 CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1,bind=:$ts1b"
10595 printf "test $F_n $TEST... " $N
10596 $CMD0 2>"${te}0" >"$tf" &
10597 pid0="$!"
10598 sleep 1 # waitudp4port $ts1p 1
10599 echo "$da" |$CMD1 2>>"${te}1"
10600 rc1="$?"
10601 sleep 1
10602 kill "$pid0" 2>/dev/null; wait;
10603 if [ "$rc1" -ne 0 ]; then
10604 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10605 echo "$CMD0 &"
10606 cat "${te}0"
10607 echo "$CMD1"
10608 cat "${te}1"
10609 numFAIL=$((numFAIL+1))
10610 listFAIL="$listFAIL $N"
10611 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10612 $PRINTF "$FAILED\n"
10613 cat "$tdiff"
10614 echo "$CMD0 &"
10615 cat "${te}0"
10616 echo "$CMD1"
10617 cat "${te}1"
10618 numFAIL=$((numFAIL+1))
10619 listFAIL="$listFAIL $N"
10620 else
10621 $PRINTF "$OK\n"
10622 if [ -n "$debug" ]; then cat $te; fi
10623 numOK=$((numOK+1))
10625 fi ;; # NUMCOND
10626 esac
10627 PORT=$((PORT+1))
10628 N=$((N+1))
10630 # test SOCKET-DATAGRAM (with UDP4-DATAGRAM)
10631 NAME=SOCKET_DATAGRAM
10632 case "$TESTS" in
10633 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10634 TEST="$NAME: socket datagram via UDP/IPv4"
10635 # start a UDP4-DATAGRAM process that echoes data, and send test data using
10636 # SOCKET-DATAGRAM, selecting UDP/IPv4. The sent data should be returned.
10637 if ! eval $NUMCOND; then :; else
10638 tf="$td/test$N.stdout"
10639 te="$td/test$N.stderr"
10640 tdiff="$td/test$N.diff"
10641 ts0p=$PORT; PORT=$((PORT+1))
10642 ts1p=$PORT; PORT=$((PORT+1))
10643 ts0a="127.0.0.1"
10644 ts1b=$(printf "%04x" $ts0p);
10645 ts1a="7f000001" # "127.0.0.1"
10646 ts0b=$(printf "%04x" $ts0p)
10647 ts1b=$(printf "%04x" $ts1p)
10648 ts1="x${ts0b}${ts1a}x0000000000000000"
10649 da="test$N $(date) $RANDOM"
10650 CMD0="$TRACE $SOCAT $opts UDP4-DATAGRAM:$ts0a:$ts1p,bind=:$ts0p,reuseaddr PIPE"
10651 CMD1="$TRACE $SOCAT $opts - SOCKET-DATAGRAM:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10652 printf "test $F_n $TEST... " $N
10653 $CMD0 2>"${te}0" &
10654 pid0="$!"
10655 waitudp4port $ts0p 1
10656 echo "$da" |$CMD1 2>>"${te}1" >"$tf"
10657 rc1="$?"
10658 kill "$pid0" 2>/dev/null; wait;
10659 if [ "$rc1" -ne 0 ]; then
10660 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10661 echo "$CMD0 &"
10662 cat "${te}0"
10663 echo "$CMD1"
10664 cat "${te}1"
10665 numFAIL=$((numFAIL+1))
10666 listFAIL="$listFAIL $N"
10667 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10668 $PRINTF "$FAILED\n"
10669 cat "$tdiff"
10670 echo "$CMD0 &"
10671 cat "${te}0"
10672 echo "$CMD1"
10673 cat "${te}1"
10674 numFAIL=$((numFAIL+1))
10675 listFAIL="$listFAIL $N"
10676 else
10677 $PRINTF "$OK\n"
10678 if [ -n "$debug" ]; then cat $te; fi
10679 numOK=$((numOK+1))
10681 fi ;; # NUMCOND
10682 esac
10683 PORT=$((PORT+1))
10684 N=$((N+1))
10686 NAME=SOCKETRANGEMASK
10687 case "$TESTS" in
10688 *%$N%*|*%functions%*|*%security%*|*%generic%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%socket%*|*%range%*|*%$NAME%*)
10689 TEST="$NAME: security of generic socket-listen with RANGE option"
10690 if ! eval $NUMCOND; then :;
10691 elif [ -z "$SECONDADDR" ]; then
10692 # we need access to more loopback addresses
10693 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
10694 numCANT=$((numCANT+1))
10695 else
10696 ts1p=$(printf "%04x" $PORT);
10697 testserversec "$N" "$TEST" "$opts" "SOCKET-LISTEN:2:6:x${ts1p}x00000000x0000000000000000,$REUSEADDR,fork,retry=1" "" "range=x0000x7f000000:x0000xffffffff" "SOCKET-CONNECT:2:6:x${ts1p}x${SECONDADDRHEX}x0000000000000000" 4 tcp $PORT 0
10698 fi ;; # NUMCOND, $SECONDADDR
10699 esac
10700 PORT=$((PORT+1))
10701 N=$((N+1))
10704 TIOCEXCL="$($PROCAN -c |grep "^#define[[:space:]]*TIOCEXCL[[:space:]]" |cut -d' ' -f3)"
10706 # test the generic ioctl-void option
10707 NAME=IOCTL_VOID
10708 case "$TESTS" in
10709 *%$N%*|*%functions%*|*%pty%*|*%generic%*|*%$NAME%*)
10710 TEST="$NAME: test the ioctl-void option"
10711 # there are not many ioctls that apply to non global resources and do not
10712 # require root. TIOCEXCL seems to fit:
10713 # process 0 provides a pty;
10714 # process 1 opens it with the TIOCEXCL ioctl;
10715 # process 2 opens it too and fails with "device or resource busy" only when the
10716 # previous ioctl was successful
10717 if ! eval $NUMCOND; then :;
10718 elif [ -z "$TIOCEXCL" ]; then
10719 # we use the numeric value of TIOCEXL which is system dependent
10720 $PRINTF "test $F_n $TEST... ${YELLOW}no value of TIOCEXCL${NORMAL}\n" $N
10721 numCANT=$((numCANT+1))
10722 else
10723 tp="$td/test$N.pty"
10724 tf="$td/test$N.stdout"
10725 te="$td/test$N.stderr"
10726 tdiff="$td/test$N.diff"
10727 da="test$N $(date) $RANDOM"
10728 CMD0="$TRACE $SOCAT $opts PTY,LINK=$tp pipe"
10729 CMD1="$TRACE $SOCAT $opts - file:$tp,ioctl-void=$TIOCEXCL,raw,echo=0"
10730 CMD2="$TRACE $SOCAT $opts - file:$tp,raw,echo=0"
10731 printf "test $F_n $TEST... " $N
10732 $CMD0 >/dev/null 2>"${te}0" &
10733 pid0=$!
10734 waitfile $tp 1
10735 (echo "$da"; sleep 2) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
10736 pid1=$!
10737 usleep 1000000
10738 $CMD2 >/dev/null 2>"${te}2" </dev/null
10739 rc2=$?
10740 kill $pid0 $pid1 2>/dev/null; wait
10741 if ! echo "$da" |diff - "$tf" >/dev/null; then
10742 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
10743 echo "$CMD0 &"
10744 echo "$CMD1"
10745 echo "$da" |diff - "$tf"
10746 numCANT=$((numCANT+1))
10747 elif [ $rc2 -eq 0 ]; then
10748 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10749 echo "$CMD0 &"
10750 echo "$CMD1"
10751 echo "$CMD2"
10752 cat "${te}0" "${te}1" "${te}2"
10753 numFAIL=$((numFAIL+1))
10754 listFAIL="$listFAIL $N"
10755 else
10756 $PRINTF "$OK\n"
10757 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
10758 numOK=$((numOK+1))
10760 fi # NUMCOND, TIOCEXCL
10762 esac
10763 N=$((N+1))
10766 SOL_SOCKET="$($PROCAN -c |grep "^#define[[:space:]]*SOL_SOCKET[[:space:]]" |cut -d' ' -f3)"
10767 SO_REUSEADDR="$($PROCAN -c |grep "^#define[[:space:]]*SO_REUSEADDR[[:space:]]" |cut -d' ' -f3)"
10769 # test the generic setsockopt-int option
10770 if false; then
10771 # this test no longer works due to fix for options on listening sockets
10772 NAME=SETSOCKOPT_INT
10773 case "$TESTS" in
10774 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%generic%*|*%$NAME%*)
10775 TEST="$NAME: test the setsockopt-int option"
10776 # there are not many socket options that apply to non global resources, do not
10777 # require root, do not require a network connection, and can easily be
10778 # tested. SO_REUSEADDR seems to fit:
10779 # process 0 provides a tcp listening socket with reuseaddr;
10780 # process 1 connects to this port; thus the port is connected but no longer
10781 # listening
10782 # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
10783 # (generically specified) SO_REUSEADDR socket options did not work
10784 # process 3 connects to this port; only if it is successful the test is ok
10785 if ! eval $NUMCOND; then :;
10786 elif [ -z "$SO_REUSEADDR" ]; then
10787 # we use the numeric value of SO_REUSEADDR which might be system dependent
10788 $PRINTF "test $F_n $TEST... ${YELLOW}value of SO_REUSEADDR not known${NORMAL}\n" $N
10789 numCANT=$((numCANT+1))
10790 else
10791 tp="$PORT"
10792 tf="$td/test$N.stdout"
10793 te="$td/test$N.stderr"
10794 tdiff="$td/test$N.diff"
10795 da="test$N $(date) $RANDOM"
10796 CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,setsockopt-int=$SOL_SOCKET:$SO_REUSEADDR:1 PIPE"
10797 CMD1="$TRACE $SOCAT $opts - TCP:localhost:$tp"
10798 CMD2="$CMD0"
10799 CMD3="$CMD1"
10800 printf "test $F_n $TEST... " $N
10801 $CMD0 >/dev/null 2>"${te}0" &
10802 pid0=$!
10803 waittcp4port $tp 1
10804 (echo "$da"; sleep 3) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
10805 pid1=$!
10806 usleep 1000000
10807 $CMD2 >/dev/null 2>"${te}2" &
10808 pid2=$!
10809 waittcp4port $tp 1
10810 (echo "$da") |$CMD3 >"${tf}3" 2>"${te}3"
10811 rc3=$?
10812 kill $pid0 $pid1 $pid2 2>/dev/null; wait
10813 if ! echo "$da" |diff - "$tf"; then
10814 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
10815 echo "$CMD0 &"
10816 echo "$CMD1"
10817 numCANT=$((numCANT+1))
10818 elif [ $rc3 -ne 0 ]; then
10819 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10820 echo "$CMD0 &"
10821 echo "$CMD1"
10822 echo "$CMD2 &"
10823 echo "$CMD3"
10824 cat "${te}2" "${te}3"
10825 numFAIL=$((numFAIL+1))
10826 listFAIL="$listFAIL $N"
10827 elif ! echo "$da" |diff - "${tf}3"; then
10828 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10829 echo "$CMD0 &"
10830 echo "$CMD1"
10831 echo "$CMD2 &"
10832 echo "$CMD3"
10833 echo "$da" |diff - "${tf}3"
10834 numCANT=$((numCANT+1))
10835 else
10836 $PRINTF "$OK\n"
10837 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
10838 numOK=$((numOK+1))
10840 fi # NUMCOND, SO_REUSEADDR
10842 esac
10843 PORT=$((PORT+1))
10844 N=$((N+1))
10849 NAME=SCTP4STREAM
10850 case "$TESTS" in
10851 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
10852 TEST="$NAME: echo via connection to SCTP V4 socket"
10853 PORT="$((PORT+1))"
10854 if ! eval $NUMCOND; then :;
10855 elif ! testaddrs sctp ip4 >/dev/null || ! runsip4 >/dev/null || ! runssctp4 "$((PORT-1))" >/dev/null; then
10856 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP4 not available${NORMAL}\n" $N
10857 numCANT=$((numCANT+1))
10858 elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
10859 # RHEL5 based systems became unusable when an sctp socket was created but
10860 # module sctp not loaded
10861 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
10862 numCANT=$((numCANT+1))
10863 else
10864 tf="$td/test$N.stdout"
10865 te="$td/test$N.stderr"
10866 tdiff="$td/test$N.diff"
10867 tsl=$PORT
10868 ts="127.0.0.1:$tsl"
10869 da=$(date)
10870 CMD1="$TRACE $SOCAT $opts SCTP4-LISTEN:$tsl,$REUSEADDR PIPE"
10871 CMD2="$TRACE $SOCAT $opts stdin!!stdout SCTP4:$ts"
10872 printf "test $F_n $TEST... " $N
10873 $CMD1 >"$tf" 2>"${te}1" &
10874 pid1=$!
10875 waitsctp4port $tsl 1
10876 # SCTP does not seem to support half close, so we give it 1s to finish
10877 (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
10878 if [ $? -ne 0 ]; then
10879 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10880 echo "$CMD1 &"
10881 cat "${te}1"
10882 echo "$CMD2"
10883 cat "${te}2"
10884 numFAIL=$((numFAIL+1))
10885 listFAIL="$listFAIL $N"
10886 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10887 $PRINTF "$FAILED\n"
10888 cat "$tdiff"
10889 numFAIL=$((numFAIL+1))
10890 listFAIL="$listFAIL $N"
10891 else
10892 $PRINTF "$OK\n"
10893 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
10894 numOK=$((numOK+1))
10896 kill $pid1 2>/dev/null
10897 wait
10898 fi # NUMCOND, feats
10900 esac
10901 PORT=$((PORT+1))
10902 N=$((N+1))
10904 NAME=SCTP6STREAM
10905 case "$TESTS" in
10906 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
10907 TEST="$NAME: echo via connection to SCTP V6 socket"
10908 PORT="$((PORT+1))"
10909 if ! eval $NUMCOND; then :;
10910 elif ! testaddrs sctp ip6 >/dev/null || ! runsip6 >/dev/null || ! runssctp6 "$((PORT-1))" >/dev/null; then
10911 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP6 not available${NORMAL}\n" $N
10912 numCANT=$((numCANT+1))
10913 elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
10914 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
10915 numCANT=$((numCANT+1))
10916 else
10917 tf="$td/test$N.stdout"
10918 te="$td/test$N.stderr"
10919 tdiff="$td/test$N.diff"
10920 tsl=$PORT
10921 ts="[::1]:$tsl"
10922 da=$(date)
10923 CMD1="$TRACE $SOCAT $opts SCTP6-listen:$tsl,$REUSEADDR PIPE"
10924 CMD2="$TRACE $SOCAT $opts stdin!!stdout SCTP6:$ts"
10925 printf "test $F_n $TEST... " $N
10926 $CMD1 >"$tf" 2>"${te}1" &
10927 pid=$! # background process id
10928 waitsctp6port $tsl 1
10929 # SCTP does not seem to support half close, so we let it 1s to finish
10930 (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
10931 if [ $? -ne 0 ]; then
10932 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10933 echo "$CMD1 &"
10934 cat "${te}1"
10935 echo "$CMD2"
10936 cat "${te}2"
10937 numFAIL=$((numFAIL+1))
10938 listFAIL="$listFAIL $N"
10939 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10940 $PRINTF "$FAILED: diff:\n"
10941 cat "$tdiff"
10942 numFAIL=$((numFAIL+1))
10943 listFAIL="$listFAIL $N"
10944 else
10945 $PRINTF "$OK\n"
10946 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
10947 numOK=$((numOK+1))
10949 kill $pid 2>/dev/null
10950 fi # NUMCOND, feats
10952 esac
10953 PORT=$((PORT+1))
10954 N=$((N+1))
10957 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
10958 # performed a renegotiation. Test if this is fixed.
10959 NAME=OPENSSLRENEG1
10960 case "$TESTS" in
10961 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
10962 TEST="$NAME: OpenSSL connections survive renogotiation"
10963 # connect with s_client to socat ssl-l; force a renog, then transfer data. When
10964 # data is passed the test succeeded
10965 if ! eval $NUMCOND; then :;
10966 elif ! testaddrs openssl >/dev/null; then
10967 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
10968 numCANT=$((numCANT+1))
10969 elif ! type openssl >/dev/null 2>&1; then
10970 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
10971 numCANT=$((numCANT+1))
10972 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
10973 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
10974 numCANT=$((numCANT+1))
10975 else
10976 gentestcert testsrv
10977 tf="$td/test$N.stdout"
10978 te="$td/test$N.stderr"
10979 tdiff="$td/test$N.diff"
10980 da="test$N $(date) $RANDOM"
10981 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
10982 #CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
10983 CMD1="openssl s_client -port $PORT"
10984 printf "test $F_n $TEST... " $N
10985 $CMD0 >/dev/null 2>"${te}0" &
10986 pid0=$!
10987 waittcp4port $PORT 1
10988 (echo "R"; sleep 1; echo "$da"; sleep 1) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
10989 rc1=$?
10990 kill $pid0 2>/dev/null; wait
10991 if echo "$da" |diff - ${tf}1 >"$tdiff"; then
10992 $PRINTF "$OK\n"
10993 numOK=$((numOK+1))
10994 else
10995 $PRINTF "$FAILED\n"
10996 echo "$CMD0 &"
10997 echo "$CMD1"
10998 cat "${te}0"
10999 # cat "${te}1"
11000 cat "$tdiff"
11001 numFAIL=$((numFAIL+1))
11002 listFAIL="$listFAIL $N"
11004 fi # NUMCOND
11006 esac
11007 PORT=$((PORT+1))
11008 N=$((N+1))
11011 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
11012 # performed a renegotiation. The first temporary fix to this problem might
11013 # leave socat in a blocking ssl-read state. Test if this has been fixed.
11014 NAME=OPENSSLRENEG2
11015 case "$TESTS" in
11016 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
11017 TEST="$NAME: OpenSSL connections do not block after renogotiation"
11018 # connect with s_client to socat ssl-l; force a renog, then transfer data from
11019 # socat to the peer. When data is passed this means that the former ssl read no
11020 # longer blocks and the test succeeds
11021 if ! eval $NUMCOND; then :;
11022 elif ! testaddrs openssl >/dev/null; then
11023 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11024 numCANT=$((numCANT+1))
11025 elif ! type openssl >/dev/null 2>&1; then
11026 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
11027 numCANT=$((numCANT+1))
11028 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
11029 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11030 numCANT=$((numCANT+1))
11031 else
11032 gentestcert testsrv
11033 tf="$td/test$N.stdout"
11034 te="$td/test$N.stderr"
11035 tdiff="$td/test$N.diff"
11036 da="test$N $(date) $RANDOM"
11037 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 SYSTEM:\"sleep 1; echo \\\\\\\"\\\"$da\\\"\\\\\\\"; sleep 1\"!!STDIO"
11038 #CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
11039 CMD1="openssl s_client -port $PORT"
11040 printf "test $F_n $TEST... " $N
11041 eval "$CMD0 >/dev/null 2>\"${te}0\" &"
11042 pid0=$!
11043 waittcp4port $PORT 1
11044 (echo "R"; sleep 2) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
11045 rc1=$?
11046 kill $pid0 2>/dev/null; wait
11047 if echo "$da" |diff - ${tf}1 >"$tdiff"; then
11048 $PRINTF "$OK\n"
11049 numOK=$((numOK+1))
11050 else
11051 $PRINTF "$FAILED\n"
11052 echo "$CMD0 &"
11053 echo "$CMD1"
11054 cat "${te}0"
11055 # cat "${te}1"
11056 cat "$tdiff"
11057 numFAIL=$((numFAIL+1))
11058 listFAIL="$listFAIL $N"
11060 fi # NUMCOND
11062 esac
11063 PORT=$((PORT+1))
11064 N=$((N+1))
11067 # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
11068 # command line arguments (whole addresses, host names, file names) were longer
11069 # than 512 bytes.
11070 NAME=HOSTNAMEOVFL
11071 case "$TESTS" in
11072 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11073 TEST="$NAME: stack overflow on overly long host name"
11074 # provide a long host name to TCP-CONNECT and check socats exit code
11075 if ! eval $NUMCOND; then :; else
11076 tf="$td/test$N.stdout"
11077 te="$td/test$N.stderr"
11078 tdiff="$td/test$N.diff"
11079 da="test$N $(date) $RANDOM"
11080 # prepare long data - perl might not be installed
11081 rm -f "$td/test$N.dat"
11082 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
11083 CMD0="$TRACE $SOCAT $opts TCP-CONNECT:$(cat "$td/test$N.dat"):$PORT STDIO"
11084 printf "test $F_n $TEST... " $N
11085 $CMD0 </dev/null 1>&0 2>"${te}0"
11086 rc0=$?
11087 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
11088 $PRINTF "$OK\n"
11089 numOK=$((numOK+1))
11090 else
11091 $PRINTF "$FAILED\n"
11092 echo "$CMD0"
11093 cat "${te}0"
11094 numFAIL=$((numFAIL+1))
11095 listFAIL="$listFAIL $N"
11097 fi # NUMCOND
11099 esac
11100 PORT=$((PORT+1))
11101 N=$((N+1))
11103 # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
11104 # command line arguments (whole addresses, host names, file names) were longer
11105 # than 512 bytes.
11106 NAME=FILENAMEOVFL
11107 case "$TESTS" in
11108 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%openssl%*|*%$NAME%*)
11109 TEST="$NAME: stack overflow on overly long file name"
11110 # provide a 600 bytes long key file option to OPENSSL-CONNECT and check socats exit code
11111 if ! eval $NUMCOND; then :; else
11112 tf="$td/test$N.stdout"
11113 te="$td/test$N.stderr"
11114 tdiff="$td/test$N.diff"
11115 da="test$N $(date) $RANDOM"
11116 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
11117 CMD0="$TRACE $SOCAT $opts OPENSSL:localhost:$PORT,key=$(cat "$td/test$N.dat") STDIO"
11118 printf "test $F_n $TEST... " $N
11119 $CMD0 </dev/null 1>&0 2>"${te}0"
11120 rc0=$?
11121 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
11122 $PRINTF "$OK\n"
11123 numOK=$((numOK+1))
11124 else
11125 $PRINTF "$FAILED\n"
11126 echo "$CMD0"
11127 cat "${te}0"
11128 numFAIL=$((numFAIL+1))
11129 listFAIL="$listFAIL $N"
11131 fi # NUMCOND
11133 esac
11134 PORT=$((PORT+1))
11135 N=$((N+1))
11137 # socat up to 1.7.3.0 had a stack overflow vulnerability that occurred when
11138 # command line arguments (whole addresses, host names, file names) were longer
11139 # than 512 bytes and specially crafted.
11140 NAME=NESTEDOVFL
11141 case "$TESTS" in
11142 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%exec%*|*%$NAME%*)
11143 TEST="$NAME: stack overflow on overly long nested arg"
11144 # provide a long host name to TCP-CONNECT and check socats exit code
11145 if ! eval $NUMCOND; then :; else
11146 tf="$td/test$N.stdout"
11147 te="$td/test$N.stderr"
11148 tdiff="$td/test$N.diff"
11149 da="test$N $(date) $RANDOM"
11150 # prepare long data - perl might not be installed
11151 rm -f "$td/test$N.dat"
11152 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
11153 CMD0="$TRACE $SOCAT $opts EXEC:[$(cat "$td/test$N.dat")] STDIO"
11154 printf "test $F_n $TEST... " $N
11155 $CMD0 </dev/null 1>&0 2>"${te}0"
11156 rc0=$?
11157 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
11158 $PRINTF "$OK\n"
11159 numOK=$((numOK+1))
11160 else
11161 $PRINTF "$FAILED\n"
11162 echo "$CMD0"
11163 cat "${te}0"
11164 numFAIL=$((numFAIL+1))
11165 listFAIL="$listFAIL $N"
11167 fi # NUMCOND
11169 esac
11170 PORT=$((PORT+1))
11171 N=$((N+1))
11174 # test for a bug in gopen that lead to crash or warning when opening a unix
11175 # domain socket with GOPEN
11176 NAME=GOPEN_UNIX_CRASH
11177 case "$TESTS" in
11178 *%$N%*|*%functions%*|*%bugs%*|*%gopen%*|*%unix%*|*%socket%*|*%$NAME%*)
11179 TEST="$NAME: check crash when connecting to a unix domain socket using address GOPEN"
11180 # a unix domain server is started in background. the check process connects to
11181 # its socket. when this process crashes or issues a warning the bug is present.
11182 # please note that a clean behaviour does not proof anything; behaviour of bug
11183 # depends on the value of an uninitialized var
11184 #set -vx
11185 if ! eval $NUMCOND; then :; else
11186 tf="$td/test$N.stdout"
11187 te="$td/test$N.stderr"
11188 ts="$td/test$N.sock"
11189 tdiff="$td/test$N.diff"
11190 da="test$N $(date) $RANDOM"
11191 CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
11192 CMD1="$TRACE $SOCAT $opts -d - GOPEN:$ts"
11193 printf "test $F_n $TEST... " $N
11194 $CMD0 >/dev/null 2>"${te}0" </dev/null &
11195 pid0=$!
11196 waitunixport "$ts" 1
11197 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
11198 rc1=$?
11199 kill $pid0 2>/dev/null; wait
11200 if [ $rc1 -ne 0 ]; then
11201 $PRINTF "$FAILED\n"
11202 echo "$CMD0 &"
11203 echo "$CMD1"
11204 cat "${te}0"
11205 cat "${te}1"
11206 numFAIL=$((numFAIL+1))
11207 listFAIL="$listFAIL $N"
11208 elif grep -q ' W ' "${te}1"; then
11209 $PRINTF "$FAILED\n"
11210 echo "$CMD0 &"
11211 echo "$CMD1"
11212 cat "${te}0"
11213 cat "${te}1"
11214 numFAIL=$((numFAIL+1))
11215 listFAIL="$listFAIL $N"
11216 elif ! echo "$da" |diff - ${tf}1 >"$tdiff"; then
11217 $PRINTF "$FAILED\n"
11218 echo "$CMD0 &"
11219 echo "$CMD1"
11220 cat "${te}0"
11221 cat "${te}1"
11222 cat "$tdiff"
11223 numFAIL=$((numFAIL+1))
11224 listFAIL="$listFAIL $N"
11225 else
11226 $PRINTF "$OK\n"
11227 numOK=$((numOK+1))
11229 fi # NUMCOND
11231 esac
11232 N=$((N+1))
11235 # test if socat keeps an existing file where it wanted to create a UNIX socket
11236 NAME=UNIXLISTEN_KEEPFILE
11237 case "$TESTS" in
11238 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
11239 TEST="$NAME: socat keeps an existing file where it wanted to create a UNIX socket"
11240 # we create a file and start socat with UNIX-LISTEN on this file. expected
11241 # behaviour: socat exits immediately with error, but keeps the file
11242 # up to 1.7.1.3, it removed the file
11243 if ! eval $NUMCOND; then :; else
11244 tf="$td/test$N.file"
11245 te="$td/test$N.stderr"
11246 CMD0="$TRACE $SOCAT $opts -u UNIX-LISTEN:$tf /dev/null"
11247 printf "test $F_n $TEST... " $N
11248 rm -f "$tf"; touch "$tf"
11249 $CMD0 >/dev/null 2>"${te}0"
11250 rc0=$?
11251 if [ $rc0 -ne 0 -a -f "$tf" ]; then
11252 $PRINTF "$OK\n"
11253 numOK=$((numOK+1))
11254 else
11255 $PRINTF "$FAILED\n"
11256 echo "$CMD0"
11257 cat "${te}0"
11258 numFAIL=$((numFAIL+1))
11259 listFAIL="$listFAIL $N"
11261 fi # NUMCOND
11263 esac
11264 N=$((N+1))
11267 # PTY address allowed to sepcify address parameters but ignored them
11268 NAME=PTY_VOIDARG
11269 case "$TESTS" in
11270 *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
11271 TEST="$NAME: check if address params of PTY produce error"
11272 # invoke socat with address PTY and some param; expect an error
11273 if ! eval $NUMCOND; then :; else
11274 tf="$td/test$N.stdout"
11275 te="$td/test$N.stderr"
11276 tdiff="$td/test$N.diff"
11277 da="test$N $(date) $RANDOM"
11278 CMD0="$TRACE $SOCAT $opts /dev/null PTY:/tmp/xyz"
11279 printf "test $F_n $TEST... " $N
11280 $CMD0 >/dev/null 2>"${te}0"
11281 rc0=$?
11282 if [ $rc0 -ne 0 ]; then
11283 $PRINTF "$OK\n"
11284 numOK=$((numOK+1))
11285 else
11286 $PRINTF "$FAILED\n"
11287 echo "$CMD0"
11288 cat "${te}0"
11289 numFAIL=$((numFAIL+1))
11290 listFAIL="$listFAIL $N"
11292 fi # NUMCOND
11294 esac
11295 N=$((N+1))
11298 # incomplete writes were reported but led to data loss
11299 NAME=INCOMPLETE_WRITE
11300 case "$TESTS" in
11301 *%$N%*|*%functions%*|*%bugs%*|*%$NAME%*)
11302 TEST="$NAME: check if incomplete writes are handled properly"
11303 # write to a nonblocking fd a block that is too large for atomic write
11304 # and check if all data arrives
11305 if ! eval $NUMCOND; then :; else
11306 tf="$td/test$N.stdout"
11307 te="$td/test$N.stderr"
11308 tp="$td/test$N.pipe"
11309 tw="$td/test$N.wc-c"
11310 # this is the size we write() in one call; data is never stored on disk, so
11311 # make it large enough to exceed any atomic write size; but higher number might
11312 # take much time
11313 bytes=100000 # for Linux 2.6.? this must be >65536
11314 CMD0="$TRACE $SOCAT $opts -u PIPE:$tp STDOUT"
11315 CMD1="$TRACE $SOCAT $opts -u -b $bytes OPEN:/dev/zero,readbytes=$bytes FILE:$tp,o-nonblock"
11316 printf "test $F_n $TEST... " $N
11317 $CMD0 2>"${te}0" |wc -c >"$tw" &
11318 pid=$!
11319 waitfile "$tp"
11320 $CMD1 2>"${te}1" >"${tf}1"
11321 rc1=$?
11322 wait
11323 if [ $rc1 -ne 0 ]; then
11324 $PRINTF "$NO_RESULT\n"
11325 numCANT=$((numCANT+1))
11326 elif [ ! -e "$tw" ]; then
11327 $PRINTF "$NO_RESULT\n"
11328 numCANT=$((numCANT+1))
11329 elif [ "$bytes" -eq $(cat "$tw") ]; then
11330 $PRINTF "$OK\n"
11331 numOK=$((numOK+1))
11332 else
11333 $PRINTF "$FAILED\n"
11334 echo "transferred only $(cat $tw) of $bytes bytes" >&2
11335 numFAIL=$((numFAIL+1))
11336 listFAIL="$listFAIL $N"
11338 fi # NUMCOND
11340 esac
11341 N=$((N+1))
11344 NAME=OPENSSL_ANULL
11345 case "$TESTS" in
11346 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
11347 TEST="$NAME: OpenSSL server with cipher aNULL "
11348 if ! eval $NUMCOND; then :;
11349 elif ! testaddrs openssl >/dev/null; then
11350 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11351 numCANT=$((numCANT+1))
11352 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
11353 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11354 numCANT=$((numCANT+1))
11355 else
11356 tf="$td/test$N.stdout"
11357 te="$td/test$N.stderr"
11358 tdiff="$td/test$N.diff"
11359 da="test$N $(date) $RANDOM"
11360 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,ciphers=aNULL,verify=0 pipe"
11361 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,ciphers=aNULL,verify=0,$SOCAT_EGD"
11362 printf "test $F_n $TEST... " $N
11363 eval "$CMD2 2>\"${te}1\" &"
11364 pid=$! # background process id
11365 waittcp4port $PORT
11366 echo "$da" |$CMD >$tf 2>"${te}2"
11367 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
11368 $PRINTF "${YELLOW}FAILED${NORMAL}\n"
11369 #echo "$CMD2 &"
11370 #echo "$CMD"
11371 #cat "${te}1"
11372 #cat "${te}2"
11373 #cat "$tdiff"
11374 numOK=$((numOK+1))
11375 else
11376 $PRINTF "$OK\n"
11377 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
11378 numOK=$((numOK+1))
11380 kill $pid 2>/dev/null
11381 wait
11382 fi ;; # NUMCOND, feats
11383 esac
11384 PORT=$((PORT+1))
11385 N=$((N+1))
11388 while read KEYW FEAT ADDR IPPORT; do
11389 if [ -z "$KEYW" ]|| [[ "$KEYW" == \#* ]]; then continue; fi
11390 PROTO=$KEYW
11391 proto="$(echo "$PROTO" |tr A-Z a-z)"
11392 # test the max-children option on really connection oriented sockets
11393 NAME=${KEYW}MAXCHILDREN
11394 case "$TESTS" in
11395 *%$N%*|*%functions%*|*%maxchildren%*|*%socket%*|*%$NAME%*)
11396 TEST="$NAME: max-children option"
11397 # start a listen process with max-children=1; connect with a client, let it
11398 # sleep some time before sending data; connect with second client that sends
11399 # data immediately. If max-children is working correctly the first data should
11400 # arrive first because the second process has to wait.
11401 if ! eval $NUMCOND; then :; else
11402 case "X$IPPORT" in
11403 "XPORT")
11404 tsl=$PORT # test socket listen address
11405 tsc="$ADDR:$PORT" # test socket connect address
11406 PORT=$((PORT+1)) ;;
11408 tsl="$(eval echo "$ADDR")" # resolve $N
11409 tsc=$tsl
11410 esac
11411 #ts="$td/test$N.sock"
11412 tf="$td/test$N.stdout"
11413 te="$td/test$N.stderr"
11414 tdiff="$td/test$N.diff"
11415 da="test$N $(date) $RANDOM"
11416 CMD0="$TRACE $SOCAT $opts -U FILE:$tf,o-trunc,o-creat,o-append $PROTO-LISTEN:$tsl,$REUSEADDR,fork,max-children=1"
11417 CMD1="$TRACE $SOCAT $opts -u - $PROTO-CONNECT:$tsc,shut-null"
11418 printf "test $F_n $TEST... " $N
11419 $CMD0 >/dev/null 2>"${te}0" &
11420 pid0=$!
11421 wait${proto}port $tsl 1
11422 (echo "$da 1"; sleep 2) |$CMD1 >"${tf}1" 2>"${te}1" &
11423 pid1=$!
11424 sleep 1
11425 echo "$da 2" |$CMD1 >"${tf}2" 2>"${te}2" &
11426 pid2=$!
11427 sleep 2
11428 kill $pid1 $pid2 $pid0 2>/dev/null; wait
11429 if echo -e "$da 1\n$da 2" |diff - $tf >$tdiff; then
11430 $PRINTF "$OK\n"
11431 numOK=$((numOK+1))
11432 else
11433 $PRINTF "$FAILED\n"
11434 echo "$CMD0 &"
11435 echo "(echo \"$da 1\"; sleep 2) |$CMD1"
11436 echo "echo \"$da 2\" |$CMD1"
11437 cat "${te}0"
11438 cat "${te}1"
11439 cat "${te}2"
11440 cat "$tdiff"
11441 numFAIL=$((numFAIL+1))
11442 listFAIL="$listFAIL $N"
11444 fi # NUMCOND
11446 esac
11447 N=$((N+1))
11448 done <<<"
11449 TCP4 TCP 127.0.0.1 PORT
11450 TCP6 TCP [::1] PORT
11451 SCTP4 TCP 127.0.0.1 PORT
11452 SCTP6 TCP [::1] PORT
11453 UNIX UNIX $td/test\$N.server -
11455 # debugging this hanging test was difficult - following lessons learned:
11456 # kill <parent> had no effect when child process existed
11457 # strace -f (on Fedora-23) sometimes writes/pads? blocks with \0, overwriting client traces
11458 # using the TRACE feature lets above kill command kill strace, not socat
11459 # care for timing, understand what you want :-)
11462 while read KEYW FEAT ADDR IPPORT SHUT; do
11463 if [ -z "$KEYW" ]|| [[ "$KEYW" == \#* ]]; then continue; fi
11464 PROTO=$KEYW
11465 proto="$(echo "$PROTO" |tr A-Z a-z)"
11466 # test the max-children option on pseudo connected sockets
11467 NAME=${KEYW}MAXCHILDREN
11468 case "$TESTS" in
11469 *%$N%*|*%functions%*|*%maxchildren%*|*%socket%*|*%$NAME%*)
11470 TEST="$NAME: max-children option"
11471 # start a listen process with max-children=1; connect with a client, let it
11472 # send data and then sleep; connect with second client that wants to send
11473 # data immediately, but keep first client active until server terminates.
11474 #If max-children is working correctly only the first data should
11475 # arrive.
11476 if ! eval $NUMCOND; then :; else
11477 case "X$IPPORT" in
11478 "XPORT")
11479 tsl=$PORT # test socket listen address
11480 tsc="$ADDR:$PORT" # test socket connect address
11481 PORT=$((PORT+1)) ;;
11483 tsl="$(eval echo "$ADDR")" # resolve $N
11484 tsc=$tsl
11485 esac
11486 #ts="$td/test$N.sock"
11487 tf="$td/test$N.stdout"
11488 te="$td/test$N.stderr"
11489 tdiff="$td/test$N.diff"
11490 da="test$N $(date) $RANDOM"
11491 # on some Linux distributions it hangs, thus -T option here
11492 CMD0="$TRACE $SOCAT $opts -U -T 4 FILE:$tf,o-trunc,o-creat,o-append $PROTO-LISTEN:$tsl,$REUSEADDR,fork,max-children=1"
11493 CMD1="$TRACE $SOCAT $opts -u - $PROTO-CONNECT:$tsc,$SHUT"
11494 printf "test $F_n $TEST... " $N
11495 $CMD0 >/dev/null 2>"${te}0" &
11496 pid0=$!
11497 wait${proto}port $tsl 1
11498 (echo "$da 1"; sleep 3) |$CMD1 >"${tf}1" 2>"${te}1" &
11499 pid1=$!
11500 sleep 1
11501 echo "$da 2" |$CMD1 >"${tf}2" 2>"${te}2" &
11502 pid2=$!
11503 sleep 1
11504 cpids="$(childpids $pid0)"
11505 kill $pid1 $pid2 $pid0 $cpids 2>/dev/null; wait
11506 if echo -e "$da 1" |diff - $tf >$tdiff; then
11507 $PRINTF "$OK\n"
11508 numOK=$((numOK+1))
11509 else
11510 $PRINTF "$FAILED\n"
11511 echo "$CMD0 &"
11512 echo "(echo \"$da 1\"; sleep 2) |$CMD1"
11513 echo "echo \"$da 2\" |$CMD1"
11514 cat "${te}0"
11515 cat "${te}1"
11516 cat "${te}2"
11517 cat "$tdiff"
11518 numFAIL=$((numFAIL+1))
11519 listFAIL="$listFAIL $N"
11521 fi # NUMCOND
11523 esac
11524 N=$((N+1))
11525 done <<<"
11526 UDP4 UDP 127.0.0.1 PORT shut-null
11527 UDP6 UDP [::1] PORT shut-null
11529 # debugging this hanging test was difficult - following lessons learned:
11530 # kill <parent> had no effect when child process existed
11531 # strace -f (on Fedora-23) sometimes writes/pads? blocks with \0, overwriting client traces
11532 # using the TRACE feature lets above kill command kill strace, not socat
11533 # care for timing, understand what you want :-)
11536 # socat up to 1.7.2.0 had a bug in xioscan_readline() that could be exploited
11537 # to overflow a heap based buffer (socat security advisory 3)
11538 # problem reported by Johan Thillemann
11539 NAME=READLINE_OVFL
11540 case "$TESTS" in
11541 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%readline%*|*%$NAME%*)
11542 TEST="$NAME: test for buffer overflow in readline prompt handling"
11543 # address 1 is the readline where write data was handled erroneous
11544 # address 2 provides data to trigger the buffer overflow
11545 # when no SIGSEGV or so occurs the test succeeded (bug fixed)
11546 if ! eval $NUMCOND; then :;
11547 elif ! feat=$(testaddrs readline pty); then
11548 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
11549 numCANT=$((numCANT+1))
11550 else
11551 tf="$td/test$N.stdout"
11552 te="$td/test$N.stderr"
11553 ti="$td/test$N.data"
11554 CMD0="$SOCAT $opts READLINE $ti"
11555 printf "test $F_n $TEST... " $N
11556 # prepare long data - perl might not be installed
11557 #perl -e 'print "\r","Z"x513' >"$ti"
11558 echo $E -n "\rA" >"$ti"
11559 i=0; while [ $i -lt 32 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$ti"; let i=i+1; done
11560 $TRACE $SOCAT - SYSTEM:"$CMD0; echo rc=\$? >&2",pty >/dev/null 2>"${te}0"
11561 rc=$?
11562 rc0="$(grep ^rc= "${te}0" |sed 's/.*=//')"
11563 if [ $rc -ne 0 ]; then
11564 $PRINTF "${YELLOW}framework failed${NORMAL}\n"
11565 elif [ $rc0 -eq 0 ]; then
11566 $PRINTF "$OK\n"
11567 numOK=$((numOK+1))
11568 else
11569 $PRINTF "$FAILED\n"
11570 echo "$CMD0"
11571 grep -v ^rc= "${te}0"
11572 numFAIL=$((numFAIL+1))
11573 listFAIL="$listFAIL $N"
11575 fi # NUMCOND
11577 esac
11578 PORT=$((PORT+1))
11579 N=$((N+1))
11582 # socat up to 1.7.2.1 did only shutdown() but not close() an accept() socket
11583 # that was rejected due to range, tcpwrap, lowport, or sourceport option.
11584 # This file descriptor leak could be used for a denial of service attack.
11585 NAME=FDLEAK
11586 case "$TESTS" in
11587 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11588 TEST="$NAME: file descriptor leak with range option"
11589 # have a TCP-LISTEN with range option; connect with wrong source address until
11590 # "open files" limit would exceed. When server continues operation the bug is
11591 # not present.
11592 if ! eval $NUMCOND; then :; else
11593 tf="$td/test$N.stdout"
11594 te="$td/test$N.stderr"
11595 tdiff="$td/test$N.diff"
11596 da="test$N $(date) $RANDOM"
11597 RLIMIT_NOFILE="$(ulimit -n)"
11598 if ! [[ "$RLIMIT_NOFILE" =~ ^[0-9][0-9]*$ ]]; then
11599 $PRINTF "${YELLOW}cannot determine ulimit -n"
11600 else
11601 CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,$REUSEADDR,range=$LOCALHOST:255.255.255.255 PIPE"
11602 CMD1="$TRACE $SOCAT $opts -t 0 /dev/null TCP:$SECONDADDR:$PORT,bind=$SECONDADDR"
11603 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT,bind=$LOCALHOST"
11604 printf "test $F_n $TEST... " $N
11605 $CMD0 >/dev/null 2>"${te}0" &
11606 pid0=$!
11607 waittcp4port $PORT 1
11608 while [ $RLIMIT_NOFILE -gt 0 ]; do
11609 $CMD1 >/dev/null 2>>"${te}1"
11610 let RLIMIT_NOFILE=RLIMIT_NOFILE-1
11611 done
11612 echo "$da" |$CMD2 >"${tf}2" 2>"${te}2"
11613 rc2=$?
11614 kill $pid0 2>/dev/null; wait
11615 echo -e "$da" |diff "${tf}2" - >$tdiff
11616 if [ $rc2 -ne 0 ]; then
11617 $PRINTF "$FAILED\n"
11618 echo "$CMD2 &"
11619 cat "${te}2"
11620 numFAIL=$((numFAIL+1))
11621 listFAIL="$listFAIL $N"
11622 elif [ -f "$tdiff" -a ! -s "$tdiff" ]; then
11623 $PRINTF "$OK\n"
11624 numOK=$((numOK+1))
11625 else
11626 $PRINTF "$FAILED\n"
11627 echo "$CMD0 &"
11628 echo "$CMD1"
11629 echo "$CMD2"
11630 cat "${te}0"
11631 cat "${te}1"
11632 cat "${te}2"
11633 numFAIL=$((numFAIL+1))
11634 listFAIL="$listFAIL $N"
11636 fi # ulimit -n
11637 fi # NUMCOND
11639 esac
11640 PORT=$((PORT+1))
11641 N=$((N+1))
11644 if false; then # this overflow is not reliably reproducable
11645 # socat up to 2.0.0-b6 did not check the length of the PROXY-CONNECT command line paramters when copying them into the HTTP request buffer. This could lead to a buffer overflow.
11646 NAME=PROXY_ADDR_OVFL
11647 case "$TESTS" in
11648 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11649 TEST="$NAME: proxy address parameters overflow"
11650 # invoke socat PROXY-CONNECT with long proxy server and target server names. If it terminates with exit code >= 128 it is vulnerable
11651 # However, even if vulnerable it often does not crash. Therefore we try to use a boundary check program like ElectricFence; only with its help we can tell that clean run proofs absence of vulnerability
11652 if ! eval $NUMCOND; then :; else
11653 tf="$td/test$N.stdout"
11654 te="$td/test$N.stderr"
11655 tdiff="$td/test$N.diff"
11656 da="test$N $(date) $RANDOM"
11657 EF=; for p in ef; do
11658 if type ef >/dev/null 2>&1; then
11659 EF="ef "; break
11661 done
11662 CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,$REUSEADDR FILE:/dev/null"
11663 #CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:$(perl -e "print 'A' x 256"):$(perl -e "print 'A' x 256"):80"
11664 CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:localhost:$(perl -e "print 'A' x 384"):80,proxyport=$PORT"
11665 printf "test $F_n $TEST... " $N
11666 $CMD0 >/dev/null 2>"${te}0" &
11667 pid0=$!
11668 waittcp4port $PORT 1
11669 $CMD1 >/dev/null 2>"${te}1"
11670 rc1=$?
11671 if [ $rc1 -lt 128 ]; then
11672 if [ "$EF" ]; then
11673 $PRINTF "$OK\n"
11674 numOK=$((numOK+1))
11675 else
11676 $PRINTF "$UNKNOWN $RED(install ElectricFEnce!)$NORMAL\n"
11677 numCANT=$((num+1))
11679 else
11680 $PRINTF "$FAILED\n"
11681 echo "$CMD1"
11682 cat "${te}"
11683 numFAIL=$((numFAIL+1))
11684 listFAIL="$listFAIL $N"
11686 fi # NUMCOND
11688 esac
11689 PORT=$((PORT+1))
11690 N=$((N+1))
11691 fi # false
11694 # LISTEN addresses in socat up to 1.7.2.1 applied many file descriptor, socket,
11695 # and TCP options only to the listening socket instead of the connection socket.
11696 NAME=LISTEN_KEEPALIVE
11697 case "$TESTS" in
11698 *%$N%*|*%functions%*|*%bugs%*|*%listen%*|*%keepalive%*|*%socket%*|*%$NAME%*)
11699 TEST="$NAME: keepalive option is applied to connection socket"
11700 # instance 0 has TCP-LISTEN with option so-keepalive and invokes filan after
11701 # accept(). filan writes its output to the socket. instance 1 connects to
11702 # instance 0. The value of the sockets so-keepalive option is checked, it must
11703 # be 1
11704 if ! eval $NUMCOND; then :; else
11705 tf="$td/test$N.stdout"
11706 te="$td/test$N.stderr"
11707 #tdiff="$td/test$N.diff"
11708 #da="test$N $(date) $RANDOM"
11709 CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,$REUSEADDR,so-keepalive EXEC:\"$FILAN -i 1\",nofork"
11710 CMD1="$TRACE $SOCAT $opts - TCP4:$LOCALHOST:$PORT"
11711 printf "test $F_n $TEST... " $N
11712 eval $CMD0 >/dev/null 2>"${te}0" &
11713 pid0=$!
11714 waittcp4port $PORT 1
11715 $CMD1 >"${tf}1" 2>"${te}1"
11716 KEEPALIVE="$(cat "${tf}1" |tail -n +2 |sed -e "s/.*KEEPALIVE=//" -e "s/[[:space:]].*//")"
11717 rc1=$?
11718 kill $pid0 2>/dev/null; wait
11719 if [ -z "$KEEPALIVE" ]; then
11720 $PRINTF "$NO_RESULT\n"
11721 echo "$CMD0 &"
11722 echo "$CMD1"
11723 cat "${te}0"
11724 cat "${te}1"
11725 numCANT=$((numCANT+1))
11726 elif [ "$KEEPALIVE" = "1" ]; then
11727 $PRINTF "$OK\n";
11728 numOK=$((numOK+1))
11729 else
11730 $PRINTF "$FAILED\n"
11731 echo "$CMD0 &"
11732 echo "$CMD1"
11733 cat "${te}0"
11734 cat "${te}1"
11735 numFAIL=$((numFAIL+1))
11736 listFAIL="$listFAIL $N"
11738 fi # NUMCOND
11740 esac
11741 PORT=$((PORT+1))
11742 N=$((N+1))
11745 # OPENSSL-CONNECT with bind option failed on some systems (eg.FreeBSD, but not
11746 # Linux) with "Invalid argument".
11747 NAME=OPENSSL_CONNECT_BIND
11748 case "$TESTS" in
11749 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
11750 TEST="$NAME: test OPENSSL-CONNECT with bind option"
11751 # have a simple SSL server that just echoes data.
11752 # connect with socat using OPENSSL-CONNECT with bind, send data and check if the
11753 # reply is identical.
11754 if ! eval $NUMCOND; then :;
11755 elif ! testaddrs openssl >/dev/null; then
11756 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11757 numCANT=$((numCANT+1))
11758 else
11759 gentestcert testsrv
11760 tf0="$td/test$N.0.stdout"
11761 te0="$td/test$N.0.stderr"
11762 tf1="$td/test$N.1.stdout"
11763 te1="$td/test$N.1.stderr"
11764 tdiff="$td/test$N.diff"
11765 da="test$N $(date) $RANDOM"
11766 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 PIPE"
11767 CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,bind=$LOCALHOST,verify=0"
11768 printf "test $F_n $TEST... " $N
11769 $CMD0 >/dev/null 2>"$te0" &
11770 pid0=$!
11771 waittcp4port $PORT 1
11772 echo "$da" |$CMD1 >"$tf1" 2>"$te1"
11773 rc1=$?
11774 kill $pid0 2>/dev/null; wait
11775 if [ "$rc1" -ne 0 ]; then
11776 $PRINTF "$FAILED\n"
11777 echo "$CMD0 &"
11778 echo "$CMD1"
11779 cat "$te0"
11780 cat "$te1"
11781 numFAIL=$((numFAIL+1))
11782 listFAIL="$listFAIL $N"
11783 elif ! echo "$da" |diff - $tf1 >"$tdiff"; then
11784 $PRINTF "$FAILED\n"
11785 echo "$CMD0 &"
11786 echo "$CMD1"
11787 cat "${te}0"
11788 cat "${te}1"
11789 cat "$tdiff"
11790 numFAIL=$((numFAIL+1))
11791 listFAIL="$listFAIL $N"
11792 else
11793 $PRINTF "$OK\n"
11794 numOK=$((numOK+1))
11796 fi # NUMCOND
11798 esac
11799 PORT=$((PORT+1))
11800 N=$((N+1))
11803 # socat up to version 1.7.2.3
11804 # had a bug that converted a bit mask of 0 internally to 0xffffffff
11805 NAME=TCP4RANGE_0BITS
11806 case "$TESTS" in
11807 *%$N%*|*%functions%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
11808 TEST="$NAME: correct evaluation of range mask 0"
11809 if ! eval $NUMCOND; then :;
11810 elif [ -z "$SECONDADDR" ]; then
11811 # we need access to a second addresses
11812 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
11813 numCANT=$((numCANT+1))
11814 else
11815 tf="$td/test$N.stdout"
11816 te="$td/test$N.stderr"
11817 tdiff="$td/test$N.diff"
11818 da="test$N $(date) $RANDOM"
11819 #testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
11820 CMD0="$TRACE $SOCAT $opts -u TCP4-LISTEN:$PORT,$REUSEADDR,range=127.0.0.1/0 CREATE:$tf"
11821 CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$SECONDADDR:$PORT,bind=$SECONDADDR"
11822 printf "test $F_n $TEST... " $N
11823 $CMD0 2>"${te}0" &
11824 pid0=$!
11825 waittcp4port $PORT 1
11826 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
11827 rc1=$?
11828 kill $pid0 2>/dev/null; wait
11829 if [ $rc1 != 0 ]; then
11830 $PRINTF "${YELLOW}invocation failed${NORMAL}\n"
11831 numCANT=$((numCANT+1))
11832 elif ! [ -f "$tf" ]; then
11833 $PRINTF "$FAILED\n"
11834 echo "$CMD0 &"
11835 echo "$CMD1"
11836 cat "${te}0"
11837 cat "${te}1"
11838 numFAIL=$((numFAIL+1))
11839 listFAIL="$listFAIL $N"
11840 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
11841 $PRINTF "${YELLOW}diff failed${NORMAL}\n"
11842 numCANT=$((numCANT+1))
11843 else
11844 $PRINTF "$OK\n"
11845 numOK=$((numOK+1))
11848 fi ;; # $SECONDADDR, NUMCOND
11849 esac
11850 PORT=$((PORT+1))
11851 N=$((N+1))
11854 # test: OPENSSL sets of environment variables with important values of peer certificate
11855 while read ssldist MODE MODULE FIELD TESTADDRESS PEERADDRESS VALUE; do
11856 if [ -z "$ssldist" ] || [[ "$ssldist" == \#* ]]; then continue; fi
11858 SSLDIST=${ssldist^^*}
11859 NAME="ENV_${SSLDIST}_${MODE}_${MODULE}_${FIELD}"
11860 case "$TESTS" in
11861 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$ssldist%*|*%envvar%*|*%$NAME%*)
11862 TEST="$NAME: $SSLDIST sets env SOCAT_${SSLDIST}_${MODULE}_${FIELD}"
11863 # have a server accepting a connection and invoking some shell code. The shell
11864 # code extracts and prints the SOCAT related environment vars.
11865 # outside code then checks if the environment contains the variables correctly
11866 # describing the desired field.
11867 FEAT=$(echo "$ssldist" |tr a-z A-Z)
11868 if ! eval $NUMCOND; then :;
11869 elif ! testaddrs $FEAT >/dev/null; then
11870 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
11871 numCANT=$((numCANT+1))
11872 else
11873 tf="$td/test$N.stdout"
11874 te="$td/test$N.stderr"
11875 gentestcert testsrv
11876 gentestcert testcli
11877 test_proto=tcp4
11878 case "$MODE" in
11879 SERVER)
11880 CMD0="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
11881 CMD1="$SOCAT $opts -u /dev/null $PEERADDRESS"
11882 printf "test $F_n $TEST... " $N
11883 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
11884 pid0=$!
11885 wait${test_proto}port $PORT 1
11886 $CMD1 2>"${te}1"
11887 rc1=$?
11888 waitfile "$tf" 2
11889 kill $pid0 2>/dev/null; wait
11891 CLIENT)
11892 CMD0="$SOCAT $opts -u /dev/null $PEERADDRESS"
11893 CMD1="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
11894 printf "test $F_n $TEST... " $N
11895 $CMD0 2>"${te}0" &
11896 pid0=$!
11897 wait${test_proto}port $PORT 1
11898 eval "$CMD1 2>\"${te}1\" >\"$tf\""
11899 rc1=$?
11900 waitfile "$tf" 2
11901 kill $pid0 2>/dev/null; wait
11903 esac
11904 if [ $rc1 != 0 ]; then
11905 $PRINTF "$NO_RESULT (client failed):\n"
11906 echo "$CMD0 &"
11907 cat "${te}0"
11908 echo "$CMD1"
11909 cat "${te}1"
11910 numCANT=$((numCANT+1))
11911 elif effval="$(grep SOCAT_${SSLDIST}_${MODULE}_${FIELD} "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")";
11912 [ "$effval" = "$VALUE" ]; then
11913 $PRINTF "$OK\n"
11914 if [ "$debug" ]; then
11915 echo "$CMD0 &"
11916 cat "${te}0"
11917 echo "$CMD1"
11918 cat "${te}1"
11920 numOK=$((numOK+1))
11921 else
11922 $PRINTF "$FAILED\n"
11923 echo "expected \"$VALUE\", got \"$effval\"" >&2
11924 echo "$CMD0 &"
11925 cat "${te}0"
11926 echo "$CMD1"
11927 cat "${te}1"
11928 numFAIL=$((numFAIL+1))
11929 listFAIL="$listFAIL $N"
11931 fi # NUMCOND, feats
11933 esac
11934 N=$((N+1))
11936 done <<<"
11937 openssl SERVER X509 ISSUER OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ISSUER
11938 openssl SERVER X509 SUBJECT OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_SUBJECT
11939 openssl SERVER X509 COMMONNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_COMMONNAME
11940 openssl SERVER X509 COUNTRYNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_COUNTRYNAME
11941 openssl SERVER X509 LOCALITYNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_LOCALITYNAME
11942 openssl SERVER X509 ORGANIZATIONALUNITNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ORGANIZATIONALUNITNAME
11943 openssl SERVER X509 ORGANIZATIONNAME OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 $TESTCERT_ORGANIZATIONNAME
11944 openssl CLIENT X509 SUBJECT OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_SUBJECT
11945 openssl CLIENT X509 ISSUER OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,$REUSEADDR,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_ISSUER
11949 ###############################################################################
11950 # tests: option umask with "passive" NAMED group addresses
11951 while read addr fileopt addropts proto diropt ADDR2; do
11952 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
11953 # some passive (listening...) filesystem based addresses did not implement the
11954 # umask option
11955 ADDR=${addr^^*}
11956 ADDR_=${ADDR/-/_}
11957 PROTO=${proto^^*}
11958 if [ "$diropt" = "." ]; then diropt=; fi
11959 if [ "$fileopt" = "." ]; then fileopt=; fi
11960 if [ "$addropts" = "." ]; then addropts=; fi
11961 NAME=${ADDR_}_UMASK
11962 case "$TESTS" in
11963 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%$NAME%*)
11964 TEST="$NAME: $ADDR applies option umask"
11965 # start a socat process with passive/listening file system entry. Check the
11966 # permissions of the FS entry, then terminate the process.
11967 # Test succeeds when FS entry exists and has expected permissions.
11968 if ! eval $NUMCOND; then :; else
11969 if [ $ADDR = PTY ]; then set -xv; fi
11970 tlog="$td/test$N.log"
11971 te0="$td/test$N.0.stderr"
11972 tsock="$td/test$N.sock"
11973 if [ -z "$fileopt" ]; then
11974 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
11975 else
11976 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
11978 printf "test $F_n $TEST... " $N
11979 $CMD0 >/dev/null 2>"$te0" &
11980 pid0=$!
11981 wait${proto} $tsock 1 2>"$tlog"
11982 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
11983 perms=$(fileperms "$tsock")
11984 kill $pid0 2>>"$tlog"
11985 wait
11986 if [ "$ERRNOENT" ]; then
11987 $PRINTF "${RED}no entry${NORMAL}\n"
11988 echo "$CMD0 &"
11989 cat "$te0"
11990 cat "$tlog"
11991 let numFAIL=numFAIL+1
11992 listFAIL="$listFAIL $N"
11993 elif [ "$perms" != "600" ]; then
11994 $PRINTF "${RED}perms \"$perms\", expected \"600\" ${NORMAL}\n"
11995 echo "$CMD0 &"
11996 cat "$te0"
11997 let numFAIL=numFAIL+1
11998 listFAIL="$listFAIL $N"
11999 else
12000 $PRINTF "$OK\n"
12001 let numOK=numOK+1
12003 set +xv
12004 fi # NUMCOND
12006 esac
12007 PORT=$((PORT+1))
12008 N=$((N+1))
12010 done <<<"
12011 # address fileopt addropts waitfor direction ADDR2
12012 create . . file -U FILE:/dev/null
12013 open . creat file . FILE:/dev/null
12014 gopen . creat file . FILE:/dev/null
12015 unix-listen . . unixport . FILE:/dev/null
12016 unix-recvfrom . . unixport . FILE:/dev/null
12017 unix-recv . . unixport -u FILE:/dev/null
12018 pipe . . file -u FILE:/dev/null
12019 # pty does not seem to honor umask:
12020 #pty link . file . PIPE
12024 # tests: option perm with "passive" NAMED group addresses
12025 while read addr fileopt addropts proto diropt; do
12026 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12027 # test if passive (listening...) filesystem based addresses implement option perm
12028 ADDR=${addr^^*}
12029 ADDR_=${ADDR/-/_}
12030 PROTO=${proto^^*}
12031 if [ "$diropt" = "." ]; then diropt=; fi
12032 if [ "$fileopt" = "." ]; then fileopt=; fi
12033 if [ "$addropts" = "." ]; then addropts=; fi
12034 NAME=${ADDR_}_PERM
12035 case "$TESTS" in
12036 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%ignoreeof%*|*%$NAME%*)
12037 TEST="$NAME: $ADDR applies option perm"
12038 # start a socat process with passive/listening file system entry. Check the
12039 # permissions of the FS entry, then terminate the process.
12040 # Test succeeds when FS entry exists and has expected permissions.
12041 if ! eval $NUMCOND; then :; else
12042 tlog="$td/test$N.log"
12043 te0="$td/test$N.0.stderr"
12044 tsock="$td/test$N.sock"
12045 # set -vx
12046 if [ -z "$fileopt" ]; then
12047 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
12048 else
12049 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
12051 printf "test $F_n $TEST... " $N
12052 $CMD0 >/dev/null 2>"$te0" &
12053 pid0=$!
12054 wait${proto} $tsock 1 2>"$tlog"
12055 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12056 perms=$(fileperms "$tsock")
12057 kill $pid0 2>>"$tlog"
12058 wait
12059 if [ "$ERRNOENT" ]; then
12060 $PRINTF "${RED}no entry${NORMAL}\n"
12061 echo "$CMD0 &"
12062 cat "$te0"
12063 cat "$tlog"
12064 let numFAIL=numFAIL+1
12065 listFAIL="$listFAIL $N"
12066 elif [ "$perms" != "511" ]; then
12067 $PRINTF "${RED}perms \"$perms\", expected \"511\" ${NORMAL}\n"
12068 echo "$CMD0 &"
12069 cat "$te0"
12070 let numFAIL=numFAIL+1
12071 listFAIL="$listFAIL $N"
12072 else
12073 $PRINTF "$OK\n"
12074 let numOK=numOK+1
12076 set +vx
12077 fi # NUMCOND
12079 esac
12080 PORT=$((PORT+1))
12081 N=$((N+1))
12083 done <<<"
12084 # address fileopt addropts waitfor direction
12085 create . . file -U
12086 open . creat file .
12087 gopen . creat file .
12088 unix-listen . . unixport .
12089 unix-recvfrom . . unixport .
12090 unix-recv . . unixport -u
12091 pipe . . file -u
12092 pty link . file .
12096 # tests: option user with "passive" NAMED group addresses
12097 while read addr fileopt addropts proto diropt; do
12098 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12099 # test if passive (listening...) filesystem based addresses implement option user
12100 ADDR=${addr^^*}
12101 ADDR_=${ADDR/-/_}
12102 PROTO=${proto^^*}
12103 if [ "$diropt" = "." ]; then diropt=; fi
12104 if [ "$fileopt" = "." ]; then fileopt=; fi
12105 if [ "$addropts" = "." ]; then addropts=; fi
12106 NAME=${ADDR_}_USER
12107 case "$TESTS" in
12108 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%root%*|*%ignoreeof%*|*%$NAME%*)
12109 TEST="$NAME: $ADDR applies option user"
12110 # start a socat process with passive/listening file system entry with user option.
12111 # Check the owner of the FS entry, then terminate the process.
12112 # Test succeeds when FS entry exists and has expected owner.
12113 if ! eval $NUMCOND; then :;
12114 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
12115 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
12116 numCANT=$((numCANT+1))
12117 else
12118 tlog="$td/test$N.log"
12119 te0="$td/test$N.0.stderr"
12120 tsock="$td/test$N.sock"
12121 # set -vx
12122 if [ -z "$fileopt" ]; then
12123 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
12124 else
12125 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
12127 printf "test $F_n $TEST... " $N
12128 $CMD0 >/dev/null 2>"$te0" &
12129 pid0=$!
12130 wait${proto} $tsock 1 2>"$tlog"
12131 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12132 user=$(fileuser "$tsock")
12133 kill $pid0 2>>"$tlog"
12134 wait
12135 if [ "$ERRNOENT" ]; then
12136 $PRINTF "${RED}no entry${NORMAL}\n"
12137 echo "$CMD0 &"
12138 cat "$te0"
12139 cat "$tlog"
12140 let numFAIL=numFAIL+1
12141 listFAIL="$listFAIL $N"
12142 elif [ "$user" != "$SUBSTUSER" ]; then
12143 $PRINTF "${RED}user \"$user\", expected \"$SUBSTUSER\" ${NORMAL}\n"
12144 echo "$CMD0 &"
12145 cat "$te0"
12146 let numFAIL=numFAIL+1
12147 listFAIL="$listFAIL $N"
12148 else
12149 $PRINTF "$OK\n"
12150 let numOK=numOK+1
12152 set +vx
12153 fi # NUMCOND
12155 esac
12156 PORT=$((PORT+1))
12157 N=$((N+1))
12159 done <<<"
12160 # address fileopt addropts waitfor direction
12161 create . . file -U
12162 open . creat file .
12163 gopen . creat file .
12164 unix-listen . . unixport .
12165 unix-recvfrom . . unixport .
12166 unix-recv . . unixport -u
12167 pipe . . file -u
12168 pty link . file .
12172 # tests: is "passive" filesystem entry removed at the end? (without fork)
12173 while read addr fileopt addropts proto diropt crit ADDR2; do
12174 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12175 # some passive (listening...) filesystem based addresses did not remove the file
12176 # system entry at the end
12177 ADDR=${addr^^*}
12178 ADDR_=${ADDR/-/_}
12179 PROTO=${proto^^*}
12180 if [ "$diropt" = "." ]; then diropt=; fi
12181 if [ "$fileopt" = "." ]; then fileopt=; fi
12182 if [ "$addropts" = "." ]; then addropts=; fi
12183 # $ADDR removes the file system entry when the process is terminated
12184 NAME=${ADDR_}_REMOVE
12185 case "$TESTS" in
12186 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
12187 TEST="$NAME: $ADDR removes socket entry when terminated during accept"
12188 # start a socat process with listening unix domain socket etc. Terminate the
12189 # process and check if the file system socket entry still exists.
12190 # Test succeeds when entry does not exist.
12191 if ! eval $NUMCOND; then :; else
12192 tlog="$td/test$N.log"
12193 te0="$td/test$N.0.stderr"
12194 tsock="$td/test$N.sock"
12195 if [ -z "$fileopt" ]; then
12196 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts $ADDR2"
12197 else
12198 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts $ADDR2"
12200 printf "test $F_n $TEST... " $N
12201 $CMD0 >/dev/null 2>"$te0" &
12202 pid0=$!
12203 wait${proto} "$crit" $tsock 1 2>"$tlog"
12204 kill $pid0 2>>"$tlog"
12205 rc1=$?
12206 wait >>"$tlog"
12207 if [ $rc1 != 0 ]; then
12208 $PRINTF "${YELLOW}setup failed${NORMAL}\n"
12209 echo "$CMD0 &"
12210 cat "$te0"
12211 cat "$tlog"
12212 let numCANT=numCANT+1
12213 elif ! [ $crit $tsock ]; then
12214 $PRINTF "$OK\n"
12215 let numOK=numOK+1
12216 else
12217 $PRINTF "$FAILED\n"
12218 echo "$CMD0 &"
12219 cat "$te0"
12220 cat "$tlog"
12221 let numFAIL=numFAIL+1
12222 listFAIL="$listFAIL $N"
12224 fi # NUMCOND
12226 esac
12227 PORT=$((PORT+1))
12228 N=$((N+1))
12230 done <<<"
12231 # address fileopt addropts waitfor direction crit ADDR2
12232 unix-listen . . unixport . -e FILE:/dev/null
12233 unix-recvfrom . . unixport . -e FILE:/dev/null
12234 unix-recv . . unixport -u -e FILE:/dev/null
12235 pipe . . file -u -e FILE:/dev/null
12236 pty link . file . -L PIPE
12240 # tests: is "passive" filesystem entry removed at the end? (with fork)
12241 while read addr fileopt addropts proto diropt crit ADDR2; do
12242 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12243 # some passive (listening...) filesystem based addresses with fork did not remove
12244 # the file system entry at the end
12245 ADDR=${addr^^*}
12246 ADDR_=${ADDR/-/_}
12247 PROTO=${proto^^*}
12248 if [ "$diropt" = "." ]; then diropt=; fi
12249 if [ "$fileopt" = "." ]; then fileopt=; fi
12250 if [ "$addropts" = "." ]; then addropts=; fi
12251 # $ADDR with fork removes the file system entry when the process is terminated
12252 NAME=${ADDR_}_REMOVE_FORK
12253 case "$TESTS" in
12254 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
12255 TEST="$NAME: $ADDR with fork removes socket entry when terminated during accept"
12256 # start a socat process with listening unix domain socket etc and option fork.
12257 # Terminate the process and check if the file system socket entry still exists.
12258 # Test succeeds when entry does not exist.
12259 if ! eval $NUMCOND; then :; else
12260 tlog="$td/test$N.log"
12261 te0="$td/test$N.0.stderr"
12262 tsock="$td/test$N.sock"
12263 if [ -z "$fileopt" ]; then
12264 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,fork,$addropts $ADDR2"
12265 else
12266 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,fork,$fileopt=$tsock,$addropts $ADDR2"
12268 printf "test $F_n $TEST... " $N
12269 $CMD0 >/dev/null 2>"$te0" &
12270 pid0=$!
12271 wait${proto} "$crit" $tsock 1 2>"$tlog"
12272 kill $pid0 2>>"$tlog"
12273 rc1=$?
12274 wait
12275 if [ $rc1 != 0 ]; then
12276 $PRINTF "${YELLOW}setup failed${NORMAL}\n"
12277 echo "$CMD0 &"
12278 cat "$te0"
12279 cat "$tlog"
12280 let numCANT=numCANT+1
12281 elif ! [ $crit $tsock ]; then
12282 $PRINTF "$OK\n"
12283 let numOK=numOK+1
12284 else
12285 $PRINTF "$FAILED\n"
12286 echo "$CMD0 &"
12287 cat "$te0"
12288 cat "$tlog"
12289 let numFAIL=numFAIL+1
12290 listFAIL="$listFAIL $N"
12292 fi # NUMCOND
12294 esac
12295 PORT=$((PORT+1))
12296 N=$((N+1))
12298 done <<<"
12299 # address fileopt addropts waitfor direction crit ADDR2
12300 unix-listen . . unixport . -e FILE:/dev/null
12301 unix-recvfrom . . unixport . -e FILE:/dev/null
12305 # bug fix: SYSTEM address child process shut down parents sockets including
12306 # SSL connection under some circumstances.
12307 NAME=SYSTEM_SHUTDOWN
12308 case "$TESTS" in
12309 *%$N%*|*%functions%*|*%bugs%*|*%system%*|*%openssl%*|*%socket%*|*%$NAME%*)
12310 TEST="$NAME: SYSTEM address does not shutdown its parents addresses"
12311 # start an OpenSSL echo server using SYSTEM:cat
12312 # start an OpenSSL client that sends data
12313 # when the client recieves its data and terminates without error the test succeeded
12314 # in case of the bug the client issues an error like:
12315 # SSL_connect(): error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac
12316 if ! eval $NUMCOND; then :;
12317 elif ! testaddrs openssl >/dev/null; then
12318 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
12319 numCANT=$((numCANT+1))
12320 else
12321 gentestcert testsrv
12322 tf="$td/test$N.stdout"
12323 te="$td/test$N.stderr"
12324 tdiff="$td/test$N.diff"
12325 da="test$N $(date) $RANDOM"
12326 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 SYSTEM:cat"
12327 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
12328 printf "test $F_n $TEST... " $N
12329 $CMD0 >/dev/null 2>"${te}0" &
12330 pid0=$!
12331 waittcp4port $PORT 1
12332 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12333 rc1=$?
12334 kill $pid0 2>/dev/null; wait
12335 if [ $rc1 -ne 0 ]; then
12336 $PRINTF "$FAILED\n"
12337 echo "rc1=$rc1"
12338 echo "$CMD0 &"
12339 echo "$CMD1"
12340 cat "${te}0"
12341 cat "${te}1"
12342 numFAIL=$((numFAIL+1))
12343 listFAIL="$listFAIL $N"
12344 elif ! echo "$da" |diff - "${tf}1" >"$tdiff" 2>&1; then
12345 $PRINTF "$FAILED\n"
12346 echo "diff:"
12347 cat "$tdiff"
12348 echo "$CMD0 &"
12349 echo "$CMD1"
12350 cat "${te}0"
12351 cat "${te}1"
12352 numFAIL=$((numFAIL+1))
12353 listFAIL="$listFAIL $N"
12354 else
12355 $PRINTF "$OK\n"
12356 numOK=$((numOK+1))
12358 fi # NUMCOND
12360 esac
12361 PORT=$((PORT+1))
12362 N=$((N+1))
12365 # test if TCP4-LISTEN with empty port arg terminates with error
12366 NAME=TCP4_NOPORT
12367 case "$TESTS" in
12368 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%tcp%*|*%tcp4%*|*%$NAME%*)
12369 TEST="$NAME: test if TCP4-LISTEN with empty port arg bails out"
12370 # run socat with TCP4-LISTEN with empty port arg. Check if it terminates
12371 # immediately with return code 1
12372 if ! eval $NUMCOND; then :; else
12373 tf="$td/test$N.stdout"
12374 te="$td/test$N.stderr"
12375 t0rc="$td/test$N.rc"
12376 tdiff="$td/test$N.diff"
12377 da="test$N $(date) $RANDOM"
12378 CMD0="$SOCAT $opts TCP4-LISTEN: /dev/null"
12379 printf "test $F_n $TEST... " $N
12380 { $CMD0 >/dev/null 2>"${te}0"; echo $? >"$t0rc"; } & 2>/dev/null
12381 pid0=$!
12382 sleep 1
12383 kill $pid0 2>/dev/null; wait
12384 if [ ! -f "$t0rc" ]; then
12385 $PRINTF "$FAILED\n"
12386 echo "no return code of CMD0 stored" >&2
12387 echo "$CMD0 &"
12388 cat "${te}0"
12389 numFAIL=$((numFAIL+1))
12390 listFAIL="$listFAIL $N"
12391 elif ! echo 1 |diff - "$t0rc" >"$tdiff"; then
12392 $PRINTF "$FAILED\n"
12393 echo "CMD0 exited with $(cat $t0rc), expected 1"
12394 echo "$CMD0 &"
12395 cat "${te}0"
12396 numFAIL=$((numFAIL+1))
12397 listFAIL="$listFAIL $N"
12398 else
12399 $PRINTF "$OK\n"
12400 numOK=$((numOK+1))
12402 fi # NUMCOND
12404 esac
12405 PORT=$((PORT+1))
12406 N=$((N+1))
12409 # tests of various SSL methods:
12410 OPENSSL_METHODS_OBSOLETE="SSL3 SSL23"
12411 OPENSSL_METHODS_EXPECTED="TLS1 TLS1.1 TLS1.2 DTLS1"
12413 # the OPENSSL_METHOD_DTLS1 test hangs sometimes, probably depending on the openssl version.
12414 OPENSSL_VERSION="$(openssl version)"
12415 OPENSSL_VERSION="${OPENSSL_VERSION#* }"
12416 OPENSSL_VERSION="${OPENSSL_VERSION%%-*}"
12417 OPENSSL_VERSION_GOOD=1.0.2 # this is just a guess.
12418 # known bad: 1.0.1e
12419 # known good: 1.0.2j
12422 # test if the obsolete SSL methods can be used with OpenSSL
12423 for method in $OPENSSL_METHODS_OBSOLETE; do
12425 NAME=OPENSSL_METHOD_$method
12426 case "$TESTS" in
12427 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
12428 TEST="$NAME: test OpenSSL method $method"
12429 # Start a socat process with obsoelete OpenSSL method, it should fail
12430 if ! eval $NUMCOND; then :;
12431 elif ! testaddrs openssl >/dev/null; then
12432 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
12433 numCANT=$((numCANT+1))
12434 elif ! socat -hhh |grep -q "^[[:space:]]*openssl-method[[:space:]]"; then
12435 $PRINTF "test $F_n $TEST... ${YELLOW}Option openssl-method not available${NORMAL}\n" $N
12436 numCANT=$((numCANT+1))
12437 else
12438 gentestcert testsrv
12439 tf="$td/test$N.stdout"
12440 te="$td/test$N.stderr"
12441 tdiff="$td/test$N.diff"
12442 da="test$N $(date) $RANDOM"
12443 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,openssl-method=$method,cert=testsrv.pem,verify=0 PIPE"
12444 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,opensslmethod=$method,verify=0"
12445 printf "test $F_n $TEST... " $N
12446 if [ "$method" = DTLS1 -a "$(echo -e "$OPENSSL_VERSION\n1.0.2" |sort -V |tail -n 1)" = "$OPENSSL_VERSION_GOOD" ]; then
12447 $PRINTF "${YELLOW}might hang, skipping${NORMAL}\n"
12448 numCANT=$((numCANT+1))
12449 else
12450 $CMD0 >/dev/null 2>"${te}0" &
12451 pid0=$!
12452 waittcp4port $PORT 1 1 2>/dev/null; w0=$? # result of waiting for process 0
12453 if [ $w0 -eq 0 ]; then
12454 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12455 rc1=$?
12456 kill $pid0 2>/dev/null; wait
12458 if [ $w0 -eq 0 ] && echo "$da" |diff - "${tf}1"; then
12459 $PRINTF "${YELLOW}WARN${NORMAL} (obsolete method succeeds)\n"
12460 numOK=$((numOK+1))
12461 else
12462 $PRINTF "$OK (obsolete method fails)\n"
12463 numOK=$((numOK+1))
12465 if [ "$VERBOSE" ]; then
12466 echo " $CMD0"
12467 echo " echo \"$da\" |$CMD1"
12469 fi # !DTLS1 hang
12470 fi # NUMCOND
12472 esac
12473 PORT=$((PORT+1))
12474 N=$((N+1))
12476 done
12478 # test if the various SSL methods can be used with OpenSSL
12479 for method in $OPENSSL_METHODS_EXPECTED; do
12481 NAME=OPENSSL_METHOD_$method
12482 case "$TESTS" in
12483 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
12484 TEST="$NAME: test OpenSSL method $method"
12485 # Start a socat process listening with OpenSSL and echoing data,
12486 # using the selected method
12487 # Start a second socat process connecting to the listener using
12488 # the same method, send some data and catch the reply.
12489 # If the reply is identical to the sent data the test succeeded.
12490 if ! eval $NUMCOND; then :;
12491 elif ! testaddrs openssl >/dev/null; then
12492 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
12493 numCANT=$((numCANT+1))
12494 elif ! socat -hhh |grep -q "^[[:space:]]*openssl-method[[:space:]]"; then
12495 $PRINTF "test $F_n $TEST... ${YELLOW}Option openssl-method not available${NORMAL}\n" $N
12496 numCANT=$((numCANT+1))
12497 else
12498 gentestcert testsrv
12499 tf="$td/test$N.stdout"
12500 te="$td/test$N.stderr"
12501 tdiff="$td/test$N.diff"
12502 da="test$N $(date) $RANDOM"
12503 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,openssl-method=$method,cert=testsrv.pem,verify=0 PIPE"
12504 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,openssl-method=$method,verify=0"
12505 printf "test $F_n $TEST... " $N
12506 if [ "$method" = DTLS1 -a "$(echo -e "$OPENSSL_VERSION\n1.0.2" |sort -V |tail -n 1)" = "$OPENSSL_VERSION_GOOD" ]; then
12507 $PRINTF "${YELLOW}might hang, skipping${NORMAL}\n"
12508 numCANT=$((numCANT+1))
12509 else
12510 $CMD0 >/dev/null 2>"${te}0" &
12511 pid0=$!
12512 waittcp4port $PORT 1
12513 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12514 rc1=$?
12515 kill $pid0 2>/dev/null; wait
12516 if echo "$da" |diff - "${tf}1"; then
12517 $PRINTF "$OK\n"
12518 numOK=$((numOK+1))
12519 if [ "$VERBOSE" ]; then
12520 echo " $CMD0"
12521 echo " echo \"$da\" |$CMD1"
12523 else
12524 $PRINTF "$FAILED\n"
12525 echo "$CMD0 &"
12526 echo "$CMD1"
12527 cat "${te}0"
12528 cat "${te}1"
12529 numFAIL=$((numFAIL+1))
12530 listFAIL="$listFAIL $N"
12531 #esac
12533 fi # !DTLS1 hang
12534 fi # NUMCOND
12536 esac
12537 PORT=$((PORT+1))
12538 N=$((N+1))
12540 done
12543 # Address options fdin and fdout were silently ignored when not applicable
12544 # due to -u or -U option. Now these combinations are caught as errors.
12545 NAME=FDOUT_ERROR
12546 case "$TESTS" in
12547 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
12548 TEST="$NAME: fdout bails out in write-only context"
12549 # use EXEC in write-only context with option fdout. Expected behaviour: error
12550 if ! eval $NUMCOND; then :; else
12551 tf="$td/test$N.stdout"
12552 te="$td/test$N.stderr"
12553 tdiff="$td/test$N.diff"
12554 da="test$N $(date) $RANDOM"
12555 CMD="$SOCAT $opts -u /dev/null EXEC:cat,fdout=1"
12556 printf "test $F_n $TEST... " $N
12557 $CMD >/dev/null 2>"${te}"
12558 rc=$?
12559 if [ $rc -eq 1 ]; then
12560 $PRINTF "$OK\n"
12561 numOK=$((numOK+1))
12562 else
12563 $PRINTF "$FAILED\n"
12564 echo "$CMD"
12565 cat "${te}"
12566 echo "command did not terminate with error!"
12567 numFAIL=$((numFAIL+1))
12568 listFAIL="$listFAIL $N"
12570 fi # NUMCOND
12572 esac
12573 PORT=$((PORT+1))
12574 N=$((N+1))
12577 # test if failure exit code of SYSTEM invocation causes socat to also exit
12578 # with !=0
12579 NAME=SYSTEM_RC
12580 case "$TESTS" in
12581 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
12582 TEST="$NAME: promote failure of SYSTEM"
12583 # run socat with SYSTEM:false and check if socat exits with !=0
12584 if ! eval $NUMCOND; then :; else
12585 tf="$td/test$N.stdout"
12586 te="$td/test$N.stderr"
12587 tdiff="$td/test$N.diff"
12588 da="test$N $(date) $RANDOM"
12589 # shut-none makes sure that the child is not killed by parent
12590 CMD0="$TRACE $SOCAT $opts - SYSTEM:false,shut-none"
12591 printf "test $F_n $TEST... " $N
12592 sleep 1 |$CMD0 >/dev/null 2>"${te}0"
12593 rc0=$?
12594 if [ $rc0 -eq 0 ]; then
12595 $PRINTF "$FAILED\n"
12596 echo "$CMD0"
12597 cat "${te}0"
12598 numFAIL=$((numFAIL+1))
12599 listFAIL="$listFAIL $N"
12600 else
12601 $PRINTF "$OK\n"
12602 numOK=$((numOK+1))
12604 fi # NUMCOND
12606 esac
12607 PORT=$((PORT+1))
12608 N=$((N+1))
12611 # test if failure exit code of EXEC invocation causes socat to also exit
12612 # with !=0
12613 NAME=EXEC_RC
12614 case "$TESTS" in
12615 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
12616 TEST="$NAME: promote failure of EXEC"
12617 # run socat with EXEC:false and check if socat exits with !=0
12618 if ! eval $NUMCOND; then :; else
12619 tf="$td/test$N.stdout"
12620 te="$td/test$N.stderr"
12621 tdiff="$td/test$N.diff"
12622 da="test$N $(date) $RANDOM"
12623 # shut-none makes sure that the child is not killed by parent
12624 CMD0="$TRACE $SOCAT $opts - EXEC:false,shut-none"
12625 printf "test $F_n $TEST... " $N
12626 sleep 1 |$CMD0 >/dev/null 2>"${te}0"
12627 rc0=$?
12628 if [ $rc0 -eq 0 ]; then
12629 $PRINTF "$FAILED\n"
12630 echo "$CMD0"
12631 cat "${te}0"
12632 numFAIL=$((numFAIL+1))
12633 listFAIL="$listFAIL $N"
12634 else
12635 $PRINTF "$OK\n"
12636 numOK=$((numOK+1))
12638 fi # NUMCOND
12640 esac
12641 PORT=$((PORT+1))
12642 N=$((N+1))
12645 # test the so-reuseaddr option
12646 NAME=SO_REUSEADDR
12647 case "$TESTS" in
12648 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%socket%*|*%$NAME%*)
12649 TEST="$NAME: test the so-reuseaddr option"
12650 # process 0 provides a tcp listening socket with so-reuseaddr;
12651 # process 1 connects to this port; thus the port is connected but no longer
12652 # listening
12653 # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
12654 # SO_REUSEADDR socket options did not work
12655 # process 3 connects to this port; only if it is successful the test is ok
12656 if ! eval $NUMCOND; then :;
12657 elif ! feat=$(testoptions so-reuseaddr); then
12658 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
12659 numCANT=$((numCANT+1))
12660 else
12661 tp="$PORT"
12662 tf="$td/test$N.stdout"
12663 te="$td/test$N.stderr"
12664 tdiff="$td/test$N.diff"
12665 da="test$N $(date) $RANDOM"
12666 CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,$REUSEADDR PIPE"
12667 CMD1="$TRACE $SOCAT $opts - TCP:localhost:$tp"
12668 CMD2="$CMD0"
12669 CMD3="$CMD1"
12670 printf "test $F_n $TEST... " $N
12671 $CMD0 >/dev/null 2>"${te}0" &
12672 pid0=$!
12673 waittcp4port $tp 1
12674 (echo "$da"; sleep 3) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
12675 pid1=$!
12676 usleep 1000000
12677 $CMD2 >/dev/null 2>"${te}2" &
12678 pid2=$!
12679 waittcp4port $tp 1
12680 (echo "$da") |$CMD3 >"${tf}3" 2>"${te}3"
12681 rc3=$?
12682 kill $pid0 $pid1 $pid2 2>/dev/null; wait
12683 if ! echo "$da" |diff - "$tf"; then
12684 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
12685 echo "$CMD0 &"
12686 echo "$CMD1"
12687 numCANT=$((numCANT+1))
12688 elif [ $rc3 -ne 0 ]; then
12689 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
12690 echo "$CMD0 &"
12691 echo "$CMD1"
12692 echo "$CMD2 &"
12693 echo "$CMD3"
12694 cat "${te}2" "${te}3"
12695 numFAIL=$((numFAIL+1))
12696 listFAIL="$listFAIL $N"
12697 elif ! echo "$da" |diff - "${tf}3"; then
12698 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
12699 echo "$CMD0 &"
12700 echo "$CMD1"
12701 echo "$CMD2 &"
12702 echo "$CMD3"
12703 echo "$da" |diff - "${tf}3"
12704 numCANT=$((numCANT+1))
12705 else
12706 $PRINTF "$OK\n"
12707 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
12708 numOK=$((numOK+1))
12710 fi # NUMCOND, SO_REUSEADDR
12712 esac
12713 PORT=$((PORT+1))
12714 N=$((N+1))
12717 # test the so-reuseport option
12718 NAME=SO_REUSEPORT
12719 case "$TESTS" in
12720 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%socket%*|*%$NAME%*)
12721 TEST="$NAME: test the so-reuseport option"
12722 # process 0 provides a tcp listening socket with so-reuseport;
12723 # process 1 provides an equivalent tcp listening socket with so-reuseport;
12724 # process 2 connects to this port and transfers data
12725 # process 3 connects to this port and transfers data
12726 # test succeeds when both data transfers work
12727 if ! eval $NUMCOND; then :;
12728 elif ! feat=$(testoptions so-reuseport); then
12729 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
12730 numCANT=$((numCANT+1))
12731 else
12732 tp="$PORT"
12733 tf="$td/test$N.stdout"
12734 te="$td/test$N.stderr"
12735 tdiff="$td/test$N.diff"
12736 da2="test$N $(date) $RANDOM"
12737 da3="test$N $(date) $RANDOM"
12738 CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,$REUSEADDR,so-reuseport PIPE"
12739 CMD1="$CMD0"
12740 CMD2="$TRACE $SOCAT $opts - TCP:localhost:$tp"
12741 CMD3="$CMD2"
12742 printf "test $F_n $TEST... " $N
12743 $CMD0 >/dev/null 2>"${te}0" &
12744 pid0=$!
12745 $CMD1 >/dev/null 2>"${te}1" &
12746 pid1=$!
12747 waittcp4port $tp 1
12748 (echo "$da2") |$CMD2 >"${tf}2" 2>"${te}2" # this should always work
12749 rc2=$?
12750 (echo "$da3") |$CMD3 >"${tf}3" 2>"${te}3"
12751 rc3=$?
12752 kill $pid0 $pid1 $pid2 2>/dev/null; wait
12753 if ! echo "$da2" |diff - "${tf}2"; then
12754 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
12755 echo "$CMD0 &"
12756 echo "$CMD1 &"
12757 echo "$CMD2"
12758 cat "${te}0" "${te}1" "${te}2"
12759 numCANT=$((numCANT+1))
12760 elif [ $rc3 -ne 0 ]; then
12761 $PRINTF "$FAILED:\n"
12762 echo "$CMD0 &"
12763 echo "$CMD1 &"
12764 echo "$CMD2"
12765 echo "$CMD3"
12766 cat "${te}0" "${te}1" "${te}2" "${te}3"
12767 numFAIL=$((numFAIL+1))
12768 listFAIL="$listFAIL $N"
12769 elif ! echo "$da2" |diff - "${tf}2"; then
12770 $PRINTF "$FAILED:\n"
12771 echo "$CMD0 &"
12772 echo "$CMD1"
12773 echo "$CMD2"
12774 echo "$CMD3"
12775 cat "${te}0" "${te}1" "${te}2" "${te}3"
12776 echo "$da2" |diff - "${tf}2"
12777 numFAIL=$((numFAIL+1))
12778 listFAIL="$listFAIL $N"
12779 elif ! echo "$da3" |diff - "${tf}3"; then
12780 $PRINTF "$FAILED:\n"
12781 echo "$CMD0 &"
12782 echo "$CMD1"
12783 echo "$CMD2"
12784 echo "$CMD3"
12785 cat "${te}0" "${te}1" "${te}2" "${te}3"
12786 echo "$da3" |diff - "${tf}3"
12787 numFAIL=$((numFAIL+1))
12788 listFAIL="$listFAIL $N"
12789 else
12790 $PRINTF "$OK\n"
12791 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
12792 numOK=$((numOK+1))
12794 fi # NUMCOND, SO_REUSEPORT
12796 esac
12797 PORT=$((PORT+1))
12798 N=$((N+1))
12801 # Programs invoked with EXEC, nofork, and -u or -U had stdin and stdout assignment swapped.
12802 NAME=EXEC_NOFORK_UNIDIR
12803 case "$TESTS" in
12804 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
12805 TEST="$NAME: Programs invoked with EXEC, nofork, and -u or -U had stdin and stdout assignment swapped"
12806 # invoke a simple echo command with EXEC, nofork, and -u
12807 # expected behaviour: output appears on stdout
12808 if ! eval $NUMCOND; then :; else
12809 tf="$td/test$N.stdout"
12810 te="$td/test$N.stderr"
12811 tdiff="$td/test$N.diff"
12812 da="test$N $(date) $RANDOM"
12813 CMD0="$TRACE $SOCAT $opts -u /dev/null EXEC:\"echo \\\\\\\"\\\"$da\\\"\\\\\\\"\",nofork"
12814 printf "test $F_n $TEST... " $N
12815 eval "$CMD0" >"${tf}0" 2>"${te}0"
12816 rc1=$?
12817 if echo "$da" |diff - "${tf}0" >"$tdiff"; then
12818 $PRINTF "$OK\n"
12819 numOK=$((numOK+1))
12820 else
12821 $PRINTF "$FAILED\n"
12822 echo "$CMD0"
12823 cat "${te}0"
12824 cat "$tdiff"
12825 numFAIL=$((numFAIL+1))
12826 listFAIL="$listFAIL $N"
12828 fi # NUMCOND
12830 esac
12831 #PORT=$((PORT+1))
12832 N=$((N+1))
12835 # OpenSSL ECDHE ciphers were introduced in socat 1.7.3.0 but in the same release
12836 # they were broken by a porting effort. This test checks if OpenSSL ECDHE works
12837 # 2019-02: this does no longer work (Ubuntu-18.04)
12838 NAME=OPENSSL_ECDHE
12839 case "$TESTS" in
12840 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
12841 TEST="$NAME: test OpenSSL ECDHE"
12842 # generate a ECDHE key, start an OpenSSL server, connect with a client and try to
12843 # pass data
12844 if ! eval $NUMCOND; then :;
12845 elif ! testaddrs openssl >/dev/null; then
12846 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
12847 numCANT=$((numCANT+1))
12848 else
12849 tf="$td/test$N.stdout"
12850 te="$td/test$N.stderr"
12851 tdiff="$td/test$N.diff"
12852 da="test$N $(date) $RANDOM"
12853 #TESTSRV=./testsrvec; gentesteccert $TESTSRV
12854 TESTSRV=./testsrv; gentestcert $TESTSRV
12855 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=$TESTSRV.crt,key=$TESTSRV.pem,verify=0 PIPE"
12856 CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,cipher=ECDHE-ECDSA-AES256-GCM-SHA384,cafile=$TESTSRV.crt,verify=0"
12857 printf "test $F_n $TEST... " $N
12858 $CMD0 >/dev/null 2>"${te}0" &
12859 pid0=$!
12860 waittcp4port $PORT 1
12861 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12862 rc1=$?
12863 kill $pid0 2>/dev/null; wait
12864 if [ $rc1 -ne 0 ]; then
12865 $PRINTF "$FAILED\n"
12866 echo "failure symptom: client error" >&2
12867 echo "server and stderr:" >&2
12868 echo "$CMD0 &"
12869 cat "${te}0"
12870 echo "client and stderr:" >&2
12871 echo "$CMD1"
12872 cat "${te}1"
12873 numFAIL=$((numFAIL+1))
12874 listFAIL="$listFAIL $N"
12875 elif echo "$da" |diff - "${tf}1" >"$tdiff"; then
12876 $PRINTF "$OK\n"
12877 numOK=$((numOK+1))
12878 else
12879 $PRINTF "$FAILED\n"
12880 echo "server and stderr:" >&2
12881 echo "$CMD1"
12882 cat "${te}1"
12883 echo "client and stderr:" >&2
12884 echo "$CMD0 &"
12885 cat "${te}0"
12886 numFAIL=$((numFAIL+1))
12887 listFAIL="$listFAIL $N"
12889 fi # NUMCOND
12891 esac
12892 PORT=$((PORT+1))
12893 N=$((N+1))
12896 # option ipv6-join-group "could not be used"
12897 # fixed in 1.7.3.2
12898 NAME=USE_IPV6_JOIN_GROUP
12899 case "$TESTS" in
12900 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%ip6%*|*%udp%*|*%udp6%*|*%dgram%*|*%$NAME%*)
12901 TEST="$NAME: is option ipv6-join-group used"
12902 # Invoke socat with option ipv6-join-group on UDP6 address.
12903 # Terminate immediately, do not transfer data.
12904 # If socat exits with 0 the test succeeds.
12905 # Up to 1.7.3.1 it failed with "1 option(s) could not be used"
12906 if ! eval $NUMCOND; then :; else
12907 tf="$td/test$N.stdout"
12908 te="$td/test$N.stderr"
12909 tdiff="$td/test$N.diff"
12910 da="test$N $(date) $RANDOM"
12911 CMD0="$TRACE $SOCAT $opts UDP6-RECV:$PORT,ipv6-join-group=[ff02::2]:$MCINTERFACE /dev/null"
12912 printf "test $F_n $TEST... " $N
12913 $CMD0 >/dev/null 2>"${te}0"
12914 rc0=$?
12915 if [ $rc0 -eq 0 ]; then
12916 $PRINTF "$OK\n"
12917 numOK=$((numOK+1))
12918 else
12919 $PRINTF "$FAILED\n"
12920 echo "$CMD0"
12921 cat "${te}0"
12922 numFAIL=$((numFAIL+1))
12923 listFAIL="$listFAIL $N"
12925 fi # NUMCOND
12927 esac
12928 PORT=$((PORT+1))
12929 N=$((N+1))
12932 # The fix to "Make code async-signal-safe" used internally FD 3 and FD 4.
12933 # Using option fdin=3 did not pass data to executed program.
12934 NAME=DIAG_FDIN
12935 case "$TESTS" in
12936 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
12937 TEST="$NAME: test use of fdin=3"
12938 # Use FD 3 explicitely with fdin and test if Socat passes data to executed
12939 # program
12940 if ! eval $NUMCOND; then :; else
12941 tf="$td/test$N.stdout"
12942 te="$td/test$N.stderr"
12943 tdiff="$td/test$N.diff"
12944 da="test$N $(date) $RANDOM"
12945 CMD0="$TRACE $SOCAT $opts - SYSTEM:\"cat >&3 <&4\",fdin=4,fdout=3"
12946 printf "test $F_n $TEST... " $N
12947 echo "$da" |$TRACE $SOCAT $opts - SYSTEM:"cat <&3 >&4",fdin=3,fdout=4 >${tf}0 2>"${te}0"
12948 rc0=$?
12949 if [ $rc0 -ne 0 ]; then
12950 $PRINTF "$FAILED\n"
12951 echo "$CMD0"
12952 cat "${te}0"
12953 numFAIL=$((numFAIL+1))
12954 listFAIL="$listFAIL $N"
12955 elif echo "$da" |diff - ${tf}0 >$tdiff; then
12956 $PRINTF "$OK\n"
12957 numOK=$((numOK+1))
12958 else
12959 $PRINTF "$FAILED\n"
12960 echo "$CMD0"
12961 cat "${te}0"
12962 cat "$tdiff"
12963 numFAIL=$((numFAIL+1))
12964 listFAIL="$listFAIL $N"
12966 fi # NUMCOND
12968 esac
12969 PORT=$((PORT+1))
12970 N=$((N+1))
12973 NAME=SOCAT_OPT_HINT
12974 case "$TESTS" in
12975 *%$N%*|*%socat%*|*%$NAME%*)
12976 TEST="$NAME: check if merging single character options is rejected"
12977 if ! eval $NUMCOND; then :; else
12978 te="$td/test$N.stderr"
12979 CMD0="$TRACE $SOCAT $opts -vx FILE:/dev/null ECHO"
12980 printf "test $F_n $TEST... " $N
12981 $CMD0 >/dev/null 2>"${te}0"
12982 rc0=$?
12983 if [ "$rc0" = "1" ]; then
12984 $PRINTF "$OK\n"
12985 numOK=$((numOK+1))
12986 else
12987 $PRINTF "$FAILED\n"
12988 echo "$CMD0" >&2
12989 numFAIL=$((numFAIL+1))
12990 listFAIL="$listFAIL $N"
12992 fi ;; # NUMCOND
12993 esac
12994 N=$((N+1))
12997 ##################################################################################
12998 #=================================================================================
12999 # here come tests that might affect your systems integrity. Put normal tests
13000 # before this paragraph.
13001 # tests must be explicitely selected by roottough or name (not number)
13003 NAME=PTYGROUPLATE
13004 case "$TESTS" in
13005 *%roottough%*|*%$NAME%*)
13006 TEST="$NAME: pty with group-late works on pty"
13007 # up to socat 1.7.1.1 address pty changed the ownership of /dev/ptmx instead of
13008 # the pty with options user-late, group-late, or perm-late.
13009 # here we check for correct behaviour.
13010 # ATTENTION: in case of failure of this test the
13011 # group of /dev/ptmx might be changed!
13012 if ! eval $NUMCOND; then :; else
13013 # save current /dev/ptmx properties
13015 for f in /dev/ptmx /dev/ptc; do
13016 if [ -e $f ]; then
13017 F=$(echo "$f" |tr / ..)
13018 ls -l $f >"$td/test$N.$F.ls-l"
13019 break
13021 done
13022 printf "test $F_n $TEST... " $N
13023 if [ -z "$F" ]; then
13024 echo -e "${YELLOW}no /dev/ptmx or /dev/ptc${NORMAL}"
13025 else
13026 GROUP=daemon
13027 tf="$td/test$N.stdout"
13028 te="$td/test$N.stderr"
13029 tl="$td/test$N.pty"
13030 tdiff="$td/test$N.diff"
13031 da="test$N $(date) $RANDOM"
13032 CMD0="$TRACE $SOCAT $opts pty,link=$tl,group-late=$GROUP,escape=0x1a PIPE"
13033 CMD1="$TRACE $SOCAT $opts - $tl,raw,echo=0"
13034 $CMD0 >/dev/null 2>"${te}0" &
13035 pid0=$!
13036 (echo "$da"; usleep $MICROS; echo -e "\x1a") |$CMD1 >"${tf}1" 2>"${te}1" >"$tf"
13037 rc1=$?
13038 kill $pid0 2>/dev/null; wait
13039 if [ $rc1 -ne 0 ]; then
13040 $PRINTF "$FAILED\n"
13041 echo "$CMD0 &"
13042 echo "$CMD1"
13043 cat "${te}0"
13044 cat "${te}1"
13045 numFAIL=$((numFAIL+1))
13046 listFAIL="$listFAIL $N"
13047 elif echo "$da" |diff - "$tf" >$tdiff; then
13048 $PRINTF "$OK\n"
13049 numOK=$((numOK+1))
13050 else
13051 $PRINTF "$FAILED\n"
13052 cat "$tdiff"
13053 numFAIL=$((numFAIL+1))
13054 listFAIL="$listFAIL $N"
13056 if ! ls -l $f |diff "$td/test$N.$F.ls-l" -; then
13057 $PRINTF "${RED}this test changed properties of $f!${NORMAL}\n"
13059 fi # no /dev/ptmx
13060 fi # NUMCOND
13062 esac
13063 N=$((N+1))
13066 echo "summary: $((N-1)) tests, $((numOK+numFAIL+numCANT)) selected; $numOK ok, $numFAIL failed, $numCANT could not be performed"
13068 if [ "$numFAIL" -gt 0 ]; then
13069 echo "FAILED: $listFAIL"
13070 exit 1
13072 exit 0
13074 #==============================================================================
13076 rm -f testsrv.* testcli.* testsrvdsa* testsrvfips* testclifips*
13078 # end
13080 # too dangerous - run as root and having a shell problem, it might purge your
13081 # file systems
13082 #rm -r "$td"
13084 # sometimes subprocesses hang; we want to see this
13085 wait
13087 exit
13089 # test template
13091 # give a description of what is tested (a bugfix, a new feature...)
13092 NAME=SHORT_UNIQUE_TESTNAME
13093 case "$TESTS" in
13094 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
13095 TEST="$NAME: give a one line description of test"
13096 # describe how the test is performed, and what's the success criteria
13097 if ! eval $NUMCOND; then :; else
13098 tf="$td/test$N.stdout"
13099 te="$td/test$N.stderr"
13100 tdiff="$td/test$N.diff"
13101 da="test$N $(date) $RANDOM"
13102 CMD0="$TRACE $SOCAT $opts server-address PIPE"
13103 CMD1="$TRACE $SOCAT $opts - client-address"
13104 printf "test $F_n $TEST... " $N
13105 $CMD0 >/dev/null 2>"${te}0" &
13106 pid0=$!
13107 wait<something>port $PORT 1
13108 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
13109 rc1=$?
13110 kill $pid0 2>/dev/null; wait
13111 if [ !!! ]; then
13112 $PRINTF "$OK\n"
13113 numOK=$((numOK+1))
13114 else
13115 $PRINTF "$FAILED\n"
13116 echo "$CMD0 &"
13117 echo "$CMD1"
13118 cat "${te}0"
13119 cat "${te}1"
13120 numFAIL=$((numFAIL+1))
13121 listFAIL="$listFAIL $N"
13123 fi # NUMCOND
13125 esac
13126 PORT=$((PORT+1))
13127 N=$((N+1))