version 1.7.3.0
[socat.git] / test.sh
blob65d93ecdc872a3dbe8ea06dc51b05bdc10ceda84
1 #! /bin/bash
2 # source: test.sh
3 # Copyright Gerhard Rieger
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 while [ "$1" ]; do
18 case "X$1" in
19 X-t?*) val_t="${1#-t}" ;;
20 X-t) shift; val_t="$1" ;;
21 X-n?*) NUMCOND="test \$N -eq ${1#-n}" ;;
22 X-n) shift; NUMCOND="test \$N -eq $1" ;;
23 X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;;
24 X-N) shift; NUMCOND="test \$N -ge $1" ;;
25 *) break;
26 esac
27 shift
28 done
30 opt_t="-t $val_t"
33 #MICROS=100000
34 case "X$val_t" in
35 X*.???????*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS:0:6}" ;;
36 X*.*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS}000000"; uS="${uS:0:6}" ;;
37 X*) S="${val_t}"; uS="000000" ;;
38 esac
39 MICROS=${S}${uS}
40 MICROS=${MICROS##0000}; MICROS=${MICROS##00}; MICROS=${MICROS##0}
42 _MICROS=$((MICROS+999999)); SECONDs="${_MICROS%??????}"
43 [ -z "$SECONDs" ] && SECONDs=0
45 withroot=0 # perform privileged tests even if not run by root
46 #PATH=$PATH:/opt/freeware/bin
47 #PATH=$PATH:/usr/local/ssl/bin
48 case "$0" in
49 */*) PATH="${0%/*}:$PATH"
50 esac
51 #OPENSSL_RAND="-rand /dev/egd-pool"
52 #SOCAT_EGD="egd=/dev/egd-pool"
53 MISCDELAY=1
54 [ -z "$SOCAT" ] && SOCAT="./socat"
55 if ! [ -x "$SOCAT" ] && ! type $SOCAT >/dev/null 2>&1; then
56 echo "$SOCAT does not exist" >&2; exit 1;
58 [ -z "$PROCAN" ] && PROCAN="./procan"
59 [ -z "$FILAN" ] && FILAN="./filan"
60 opts="$opt_t $OPTS"
61 export SOCAT_OPTS="$opts"
62 #debug="1"
63 debug=
64 TESTS="$@"; export TESTS
65 # for some tests we need a network interface
66 if type ip >/dev/null 2>&1; then
67 INTERFACE=$(ip r get 8.8.8.8 |grep ' dev ' |head -n 1 |sed "s/.*dev[[:space:]][[:space:]]*\([^[:space:]][^[:space:]]*\).*/\1/")
68 else
69 INTERFACE=eth0
71 MCINTERFACE=lo # !!! Linux only
72 #LOCALHOST=192.168.58.1
73 LOCALHOST=localhost
74 #LOCALHOST=127.0.0.1
75 LOCALHOST6=[::1]
76 #PROTO=$(awk '{print($2);}' /etc/protocols |sort -n |tail -n 1)
77 #PROTO=$(($PROTO+1))
78 PROTO=$((144+RANDOM/2048))
79 PORT=12002
80 SOURCEPORT=2002
82 # SSL certificate contents
83 TESTCERT_CONF=testcert.conf
84 TESTCERT6_CONF=testcert6.conf
86 TESTCERT_COMMONNAME="$LOCALHOST"
87 TESTCERT_COMMONNAME6="$LOCALHOST6"
88 TESTCERT_COUNTRYNAME="XY"
89 TESTCERT_LOCALITYNAME="Lunar Base"
90 TESTCERT_ORGANIZATIONALUNITNAME="socat"
91 TESTCERT_ORGANIZATIONNAME="dest-unreach"
92 TESTCERT_SUBJECT="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
93 TESTCERT_ISSUER="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
94 cat >$TESTCERT_CONF <<EOF
95 prompt=no
97 [ req ]
98 default_bits = 768
99 distinguished_name=Test
101 [ Test ]
102 countryName=$TESTCERT_COUNTRYNAME
103 commonName=$TESTCERT_COMMONNAME
104 O=$TESTCERT_ORGANIZATIONNAME
105 OU=$TESTCERT_ORGANIZATIONALUNITNAME
106 L=$TESTCERT_LOCALITYNAME
109 cat >$TESTCERT6_CONF <<EOF
110 prompt=no
112 [ req ]
113 default_bits = 768
114 distinguished_name=Test
116 [ Test ]
117 countryName=$TESTCERT_COUNTRYNAME
118 commonName=$TESTCERT_COMMONNAME6
119 O=$TESTCERT_ORGANIZATIONNAME
120 OU=$TESTCERT_ORGANIZATIONALUNITNAME
121 L=$TESTCERT_LOCALITYNAME
124 # clean up from previous runs
125 rm -f testcli.{crt,key,pem}
126 rm -f testsrv.{crt,key,pem}
127 rm -f testcli6.{crt,key,pem}
128 rm -f testsrv6.{crt,key,pem}
131 CAT=cat
132 OD_C="od -c"
134 # precision sleep; takes seconds with fractional part
135 psleep () {
136 local T="$1"
137 [ "$T" = 0 ] && T=0.000002
138 $SOCAT -T "$T" pipe pipe
140 # time in microseconds to wait in some situations
141 if ! type usleep >/dev/null 2>&1; then
142 usleep () {
143 local n="$1"
144 case "$n" in
145 *???????) S="${n%??????}"; uS="${n:${#n}-6}" ;;
146 *) S=0; uS="00000$n"; uS="${uS:${#uS}-6}" ;;
147 esac
148 $SOCAT -T $S.$uS pipe pipe
151 #USLEEP=usleep
152 F_n="%3d" # format string for test numbers
153 LC_ALL=C # for timestamps format...
154 LANG=C
155 LANGUAGE=C # knoppix
156 UNAME=`uname`
157 case "$UNAME" in
158 HP-UX|OSF1)
159 echo "$SOCAT -u stdin stdout" >cat.sh
160 chmod a+x cat.sh
161 CAT=./cat.sh
163 SunOS)
164 # /usr/bin/tr doesn't handle the a-z range syntax (needs [a-z]), use
165 # /usr/xpg4/bin/tr instead
166 alias tr=/usr/xpg4/bin/tr
169 CAT=cat
171 esac
173 case "$UNAME" in
174 #HP-UX)
175 # # on HP-UX, the default options (below) hang some tests (former 14, 15)
176 # PTYOPTS=
177 # PTYOPTS2=
178 # ;;
180 PTYOPTS="echo=0,opost=0"
181 #PTYOPTS2="raw,echo=0"
182 PTYOPTS2="cfmakeraw"
183 #PTYOPTS2="rawer"
185 esac
187 # for some tests we need an unprivileged user id to su to
188 if [ "$SUDO_USER" ]; then
189 SUBSTUSER="$SUDO_USER"
190 else
191 SUBSTUSER="$(grep -v '^[^:]*:^[^:]*:0:' /etc/passwd |tail -n 1 |cut -d: -f1)"
194 # non-root users might miss ifconfig in their path
195 case "$UNAME" in
196 AIX) IFCONFIG=/usr/sbin/ifconfig ;;
197 FreeBSD) IFCONFIG=/sbin/ifconfig ;;
198 HP-UX) IFCONFIG=/usr/sbin/ifconfig ;;
199 Linux) IFCONFIG=/sbin/ifconfig ;;
200 NetBSD)IFCONFIG=/sbin/ifconfig ;;
201 OpenBSD)IFCONFIG=/sbin/ifconfig ;;
202 OSF1) IFCONFIG=/sbin/ifconfig ;;
203 SunOS) IFCONFIG=/sbin/ifconfig ;;
204 Darwin)IFCONFIG=/sbin/ifconfig ;;
205 DragonFly) IFCONFIG=/sbin/ifconfig ;;
206 *) IFCONFIG=/sbin/ifconfig ;;
207 esac
209 # need output like "644"
210 case "$UNAME" in
211 Linux) fileperms() { stat -L --print "%a\n" "$1" 2>/dev/null; } ;;
212 FreeBSD) fileperms() { stat -L -x "$1" |grep ' Mode:' |sed 's/.* Mode:[[:space:]]*([0-9]\([0-7][0-7][0-7]\).*/\1/'; } ;;
213 *) fileperms() {
214 local p s=0 c
215 p="$(ls -l -L "$1" |awk '{print($1);}')"
216 p="${p:1:9}"
217 while [ "$p" ]; do c=${p:0:1}; p=${p:1}; [ "x$c" == x- ]; let "s=2*s+$?"; done
218 printf "%03o\n" $s;
219 } ;;
220 esac
222 # need user (owner) of filesystem entry
223 case "$UNAME" in
224 Linux) fileuser() { stat -L --print "%U\n" "$tsock" 2>/dev/null; } ;;
225 FreeBSD) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
226 *) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
227 esac
230 # for some tests we need a second local IPv4 address
231 case "$UNAME" in
232 Linux)
233 BROADCASTIF=$(ip r get 8.8.8.8 |grep ' dev ' |sed 's/.*\<dev[[:space:]][[:space:]]*\([a-z0-9][a-z0-9]*\).*/\1/')
234 [ -z "$BROADCASTIF" ] && BROADCASTIF=eth0
235 SECONDADDR=127.1.0.1
236 SECONDMASK=255.255.0.0
237 BCADDR=127.255.255.255
238 BCIFADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}' |cut -d: -f2) ;;
239 FreeBSD|NetBSD|OpenBSD)
240 MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
241 BROADCASTIF="$MAINIF"
242 SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
243 BCIFADDR="$SECONDADDR"
244 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
245 HP-UX)
246 MAINIF=lan0 # might use "netstat -ni" for this
247 BROADCASTIF="$MAINIF"
248 SECONDADDR=$($IFCONFIG $MAINIF |tail -n 1 |awk '{print($2);}')
249 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
250 SunOS)
251 MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
252 BROADCASTIF="$MAINIF"
253 #BROADCASTIF=hme0
254 #BROADCASTIF=eri0
255 #SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
256 SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
257 #BCIFADDR="$SECONDADDR"
258 #BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}')
260 DragonFly)
261 MAINIF=$($IFCONFIG -a |grep -v ^lp |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
262 BROADCASTIF="$MAINIF"
263 SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
264 BCIFADDR="$SECONDADDR"
265 BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
266 #AIX|FreeBSD|Solaris)
268 SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 ' |head -n 1)" : '.*inet \([0-9.]*\) .*')
270 esac
271 # for generic sockets we need this address in hex form
272 if [ "$SECONDADDR" ]; then
273 SECONDADDRHEX="$(printf "%02x%02x%02x%02x\n" $(echo "$SECONDADDR" |tr '.' '
274 '))"
277 # for some tests we need a second local IPv6 address
278 case "$UNAME" in
280 SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
282 esac
283 if [ -z "$SECONDIP6ADDR" ]; then
284 # case "$TESTS" in
285 # *%root2%*) $IFCONFIG eth0 ::2/128
286 # esac
287 SECONDIP6ADDR="$LOCALHOST6"
288 else
289 SECONDIP6ADDR="[$SECONDIP6ADDR]"
292 TRUE=$(which true)
293 #E=-e # Linux
294 if [ $(echo "x\c") = "x" ]; then E=""
295 elif [ $(echo -e "x\c") = "x" ]; then E="-e"
296 else
297 echo "cannot suppress trailing newline on echo" >&2
298 exit 1
300 ECHO="echo $E"
301 PRINTF="printf"
303 case "$TERM" in
304 vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color)
305 # there are different behaviours of printf (and echo)
306 # on some systems, echo behaves different than printf...
307 if [ $($PRINTF "\0101") = "A" ]; then
308 RED="\0033[31m"
309 GREEN="\0033[32m"
310 YELLOW="\0033[33m"
311 # if [ "$UNAME" = SunOS ]; then
312 # NORMAL="\0033[30m"
313 # else
314 NORMAL="\0033[39m"
315 # fi
316 else
317 RED="\033[31m"
318 GREEN="\033[32m"
319 YELLOW="\033[33m"
320 # if [ "$UNAME" = SunOS ]; then
321 # NORMAL="\033[30m"
322 # else
323 NORMAL="\033[39m"
324 # fi
326 OK="${GREEN}OK${NORMAL}"
327 FAILED="${RED}FAILED${NORMAL}"
328 NO_RESULT="${YELLOW}NO RESULT${NORMAL}"
330 *) OK="OK"
331 FAILED="FAILED"
332 NO_RESULT="NO RESULT"
334 esac
337 if [ -x /usr/xpg4/bin/id ]; then
338 # SunOS has rather useless tools in its default path
339 PATH="/usr/xpg4/bin:$PATH"
342 [ -z "$TESTS" ] && TESTS="consistency functions filan"
343 # use '%' as separation char
344 TESTS="%$(echo "$TESTS" |tr ' ' '%')%"
346 [ -z "$USER" ] && USER="$LOGNAME" # HP-UX
347 if [ -z "$TMPDIR" ]; then
348 if [ -z "$TMP" ]; then
349 TMP=/tmp
351 TMPDIR="$TMP"
353 TD="$TMPDIR/$USER/$$"; td="$TD"
354 rm -rf "$TD" || (echo "cannot rm $TD" >&2; exit 1)
355 mkdir -p "$TD"
356 #trap "rm -r $TD" 0 3
358 echo "using temp directory $TD"
360 case "$TESTS" in
361 *%consistency%*)
362 # test if addresses are sorted alphabetically:
363 $ECHO "testing if address array is sorted...\c"
364 TF="$TD/socat-q"
365 IFS="$($ECHO ' \n\t')"
366 $SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done >"$TF"
367 $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"
368 if [ -s "$TF-diff" ]; then
369 $ECHO "\n*** address array is not sorted. Wrong entries:" >&2
370 cat "$TD/socat-q-diff" >&2
371 exit 1
372 else
373 echo " ok"
375 #/bin/rm "$TF"
376 #/bin/rm "$TF-diff"
377 esac
379 case "$TESTS" in
380 *%consistency%*)
381 # test if address options array ("optionnames") is sorted alphabetically:
382 $ECHO "testing if address options are sorted...\c"
383 TF="$TD/socat-qq"
384 $SOCAT -??? |sed '1,/opt:/ d' |awk '{print($1);}' >"$TF"
385 LC_ALL=C sort "$TF" |diff "$TF" - >"$TF-diff"
386 if [ -s "$TF-diff" ]; then
387 $ECHO "\n*** option array is not sorted. Wrong entries:" >&2
388 cat "$TD/socat-qq-diff" >&2
389 exit 1
390 else
391 echo " ok"
393 /bin/rm "$TF"
394 /bin/rm "$TF-diff"
395 esac
397 #==============================================================================
398 case "$TESTS" in
399 *%options%*)
401 # inquire which options are available
402 OPTS_ANY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*ANY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
403 OPTS_BLK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*BLK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
404 OPTS_CHILD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHILD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
405 OPTS_CHR=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHR' |awk '{print($1);}' |xargs echo |tr ' ' ',')
406 OPTS_DEVICE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*DEVICE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
407 OPTS_EXEC=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*EXEC' |awk '{print($1);}' |xargs echo |tr ' ' ',')
408 OPTS_FD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
409 OPTS_FIFO=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FIFO' |awk '{print($1);}' |xargs echo |tr ' ' ',')
410 OPTS_FORK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FORK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
411 OPTS_LISTEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*LISTEN' |awk '{print($1);}' |xargs echo |tr ' ' ',')
412 OPTS_NAMED=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*NAMED' |awk '{print($1);}' |xargs echo |tr ' ' ',')
413 OPTS_OPEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPEN[^S]' |awk '{print($1);}' |xargs echo |tr ' ' ',')
414 OPTS_PARENT=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PARENT' |awk '{print($1);}' |xargs echo |tr ' ' ',')
415 OPTS_READLINE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*READLINE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
416 OPTS_RETRY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RETRY' |awk '{print($1);}' |grep -v forever|xargs echo |tr ' ' ',')
417 OPTS_RANGE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RANGE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
418 OPTS_FILE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*REG' |awk '{print($1);}' |xargs echo |tr ' ' ',')
419 OPTS_UNIX=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UNIX' |awk '{print($1);}' |xargs echo |tr ' ' ',')
420 OPTS_SOCKET=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKET' |awk '{print($1);}' |xargs echo |tr ' ' ',')
421 OPTS_TERMIOS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TERMIOS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
422 OPTS_IP4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
423 OPTS_IP6=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP6' |awk '{print($1);}' |xargs echo |tr ' ' ',')
424 OPTS_TCP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TCP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
425 OPTS_UDP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UDP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
426 OPTS_SOCKS4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKS4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
427 OPTS_PROCESS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PROCESS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
428 OPTS_OPENSSL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPENSSL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
429 OPTS_PTY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PTY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
430 OPTS_HTTP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*HTTP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
431 OPTS_APPL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*APPL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
433 # find user ids to setown to; non-root only can setown to itself
434 if [ $(id -u) = 0 ]; then
435 # up to now, it is not a big problem when these do not exist
436 _UID=nobody
437 _GID=staff
438 else
439 _UID=$(id -u)
440 _GID=$(id -g)
443 # some options require values; here we try to replace these bare options with
444 # valid forms.
445 filloptionvalues() {
446 local OPTS=",$1,"
448 case "$OPTS" in
449 *,umask,*) OPTS=$(echo "$OPTS" |sed "s/,umask,/,umask=0026,/g");;
450 esac
451 case "$OPTS" in
452 *,user,*) OPTS=$(echo "$OPTS" |sed "s/,user,/,user=$_UID,/g");;
453 esac
454 case "$OPTS" in
455 *,user-early,*) OPTS=$(echo "$OPTS" |sed "s/,user-early,/,user-early=$_UID,/g");;
456 esac
457 case "$OPTS" in
458 *,user-late,*) OPTS=$(echo "$OPTS" |sed "s/,user-late,/,user-late=$_UID,/g");;
459 esac
460 case "$OPTS" in
461 *,owner,*) OPTS=$(echo "$OPTS" |sed "s/,owner,/,owner=$_UID,/g");;
462 esac
463 case "$OPTS" in
464 *,uid,*) OPTS=$(echo "$OPTS" |sed "s/,uid,/,uid=$_UID,/g");;
465 esac
466 case "$OPTS" in
467 *,uid-l,*) OPTS=$(echo "$OPTS" |sed "s/,uid-l,/,uid-l=$_UID,/g");;
468 esac
469 case "$OPTS" in
470 *,setuid,*) OPTS=$(echo "$OPTS" |sed "s/,setuid,/,setuid=$_UID,/g");;
471 esac
472 case "$OPTS" in
473 *,group,*) OPTS=$(echo "$OPTS" |sed "s/,group,/,group=$_GID,/g");;
474 esac
475 case "$OPTS" in
476 *,group-early,*) OPTS=$(echo "$OPTS" |sed "s/,group-early,/,group-early=$_GID,/g");;
477 esac
478 case "$OPTS" in
479 *,group-late,*) OPTS=$(echo "$OPTS" |sed "s/,group-late,/,group-late=$_GID,/g");;
480 esac
481 case "$OPTS" in
482 *,gid,*) OPTS=$(echo "$OPTS" |sed "s/,gid,/,gid=$_GID,/g");;
483 esac
484 case "$OPTS" in
485 *,gid-l,*) OPTS=$(echo "$OPTS" |sed "s/,gid-l,/,gid-l=$_GID,/g");;
486 esac
487 case "$OPTS" in
488 *,setgid,*) OPTS=$(echo "$OPTS" |sed "s/,setgid,/,setgid=$_GID,/g");;
489 esac
490 case "$OPTS" in
491 *,mode,*) OPTS=$(echo "$OPTS" |sed "s/,mode,/,mode=0700,/g");;
492 esac
493 case "$OPTS" in
494 *,perm,*) OPTS=$(echo "$OPTS" |sed "s/,perm,/,perm=0700,/g");;
495 esac
496 case "$OPTS" in
497 *,perm-early,*) OPTS=$(echo "$OPTS" |sed "s/,perm-early,/,perm-early=0700,/g");;
498 esac
499 case "$OPTS" in
500 *,perm-late,*) OPTS=$(echo "$OPTS" |sed "s/,perm-late,/,perm-late=0700,/g");;
501 esac
502 case "$OPTS" in
503 *,path,*) OPTS=$(echo "$OPTS" |sed "s/,path,/,path=.,/g");;
504 esac
505 # SOCKET
506 case "$OPTS" in
507 *,bind,*) OPTS=$(echo "$OPTS" |sed "s/,bind,/,bind=:,/g");;
508 esac
509 case "$OPTS" in
510 *,linger,*) OPTS=$(echo "$OPTS" |sed "s/,linger,/,linger=2,/g");;
511 esac
512 case "$OPTS" in
513 *,rcvtimeo,*) OPTS=$(echo "$OPTS" |sed "s/,rcvtimeo,/,rcvtimeo=1,/g");;
514 esac
515 case "$OPTS" in
516 *,sndtimeo,*) OPTS=$(echo "$OPTS" |sed "s/,sndtimeo,/,sndtimeo=1,/g");;
517 esac
518 case "$OPTS" in
519 *,connect-timeout,*) OPTS=$(echo "$OPTS" |sed "s/,connect-timeout,/,connect-timeout=1,/g");;
520 esac
521 # IP
522 case "$OPTS" in
523 *,ipoptions,*) OPTS=$(echo "$OPTS" |sed "s|,ipoptions,|,ipoptions=x01,|g");;
524 esac
525 case "$OPTS" in
526 *,pf,*) OPTS=$(echo "$OPTS" |sed "s|,pf,|,pf=ip4,|g");;
527 esac
528 case "$OPTS" in
529 *,range,*) OPTS=$(echo "$OPTS" |sed "s|,range,|,range=127.0.0.1/32,|g");;
530 esac
531 case "$OPTS" in
532 *,if,*) OPTS=$(echo "$OPTS" |sed "s/,if,/,if=$INTERFACE,/g");;
533 esac
534 # PTY
535 case "$OPTS" in
536 *,pty-interval,*) OPTS=$(echo "$OPTS" |sed "s/,pty-interval,/,pty-interval=$INTERFACE,/g");;
537 esac
538 # RETRY
539 case "$OPTS" in
540 *,interval,*) OPTS=$(echo "$OPTS" |sed "s/,interval,/,interval=1,/g");;
541 esac
542 # READLINE
543 case "$OPTS" in
544 *,history,*) OPTS=$(echo "$OPTS" |sed "s/,history,/,history=.history,/g");;
545 esac
546 case "$OPTS" in
547 *,noecho,*) OPTS=$(echo "$OPTS" |sed "s/,noecho,/,noecho=password,/g");;
548 esac
549 case "$OPTS" in
550 *,prompt,*) OPTS=$(echo "$OPTS" |sed "s/,prompt,/,prompt=CMD,/g");;
551 esac
552 # IPAPP
553 case "$OPTS" in
554 *,sp,*) OPTS=$(echo "$OPTS" |sed "s/,sp,/,sp=$SOURCEPORT,/g");;
555 esac
556 # OPENSSL
557 case "$OPTS" in
558 *,ciphers,*) OPTS=$(echo "$OPTS" |sed "s/,ciphers,/,ciphers=NULL,/g");;
559 esac
560 case "$OPTS" in
561 *,method,*) OPTS=$(echo "$OPTS" |sed "s/,method,/,method=SSLv3,/g");;
562 esac
563 case "$OPTS" in
564 *,cafile,*) OPTS=$(echo "$OPTS" |sed "s/,cafile,/,cafile=/tmp/hugo,/g");;
565 esac
566 case "$OPTS" in
567 *,capath,*) OPTS=$(echo "$OPTS" |sed "s/,capath,/,capath=/tmp/hugo,/g");;
568 esac
569 case "$OPTS" in
570 *,cert,*) OPTS=$(echo "$OPTS" |sed "s/,cert,/,cert=/tmp/hugo,/g");;
571 esac
572 case "$OPTS" in
573 *,key,*) OPTS=$(echo "$OPTS" |sed "s/,key,/,key=/tmp/hugo,/g");;
574 esac
575 case "$OPTS" in
576 *,dh,*) OPTS=$(echo "$OPTS" |sed "s/,dh,/,dh=/tmp/hugo,/g");;
577 esac
578 case "$OPTS" in
579 *,egd,*) OPTS=$(echo "$OPTS" |sed "s/,egd,/,egd=/tmp/hugo,/g");;
580 esac
581 case "$OPTS" in
582 *,compress,*) OPTS=$(echo "$OPTS" |sed "s/,compress,/,compress=none,/g");;
583 esac
584 # PROXY
585 case "$OPTS" in
586 *,proxyauth,*) OPTS=$(echo "$OPTS" |sed "s/,proxyauth,/,proxyauth=user:pass,/g");;
587 esac
588 case "$OPTS" in
589 *,proxyport,*) OPTS=$(echo "$OPTS" |sed "s/,proxyport,/,proxyport=3128,/g");;
590 esac
591 case "$OPTS" in
592 *,link,*) OPTS=$(echo "$OPTS" |sed "s/,link,/,link=testlink,/g");;
593 esac
594 # TCP-WRAPPERS
595 case "$OPTS" in
596 *,allow-table,*) OPTS=$(echo "$OPTS" |sed "s|,allow-table,|,allow-table=/tmp/hugo,|g");;
597 esac
598 case "$OPTS" in
599 *,deny-table,*) OPTS=$(echo "$OPTS" |sed "s|,deny-table,|,deny-table=/tmp/hugo,|g");;
600 esac
601 case "$OPTS" in
602 *,tcpwrap-dir,*) OPTS=$(echo "$OPTS" |sed "s|,tcpwrap-dir,|,tcpwrap-dir=/tmp,|g");;
603 esac
604 echo $OPTS >&2
605 expr "$OPTS" : ',\(.*\),'
607 # OPTS_FIFO: nothing yet
609 # OPTS_CHR: nothing yet
611 # OPTS_BLK: nothing yet
613 # OPTS_REG: nothing yet
615 OPTS_SOCKET=",$OPTS_SOCKET,"
616 OPTS_SOCKET=$(expr "$OPTS_SOCKET" : ',\(.*\),')
619 #------------------------------------------------------------------------------
621 #method=open
622 #METHOD=$(echo "$method" |tr a-z A-Z)
623 #TEST="$METHOD on file accepts all its options"
624 # echo "### $TEST"
625 #TF=$TD/file$N
626 #DA="test$N $(date) $RANDOM"
627 #OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//')
628 #for g in $(echo $OPTGROUPS |tr ',' ' '); do
629 # eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)";
630 # OPTS="$OPTS,$OPTG";
631 #done
632 ##echo $OPTS
634 #for o in $(filloptionvalues $OPTS|tr ',' ' '); do
635 # echo testing if $METHOD accepts option $o
636 # touch $TF
637 # $SOCAT $opts -!!$method:$TF,$o /dev/null,ignoreof </dev/null
638 # rm -f $TF
639 #done
641 #------------------------------------------------------------------------------
643 # test openssl connect
645 #set -vx
646 if true; then
647 #if false; then
648 #opts="-s -d -d -d -d"
649 pid=$!
650 for addr in openssl; do
651 ADDR=$(echo "$addr" |tr a-z A-Z)
652 TEST="$ADDR accepts all its options"
653 echo "### $TEST"
654 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
655 # echo OPTGROUPS=$OPTGROUPS
656 OPTS=
657 for g in $(echo $OPTGROUPS |tr ',' ' '); do
658 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
659 OPTS="$OPTS,$OPTG";
660 done
661 echo $OPTS
662 openssl s_server -www -accept $PORT || echo "cannot start s_server" >&2 &
663 pid=$!
664 sleep 1
665 #waittcp4port $PORT
666 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
667 echo "testing if $ADDR accepts option $o"
668 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
669 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
670 done
671 kill $pid
672 done
673 kill $pid 2>/dev/null
674 opts=
675 PORT=$((PORT+1))
678 #------------------------------------------------------------------------------
680 # test proxy connect
682 #set -vx
683 if true; then
684 #if false; then
685 #opts="-s -d -d -d -d"
686 pid=$!
687 for addr in proxy; do
688 ADDR=$(echo "$addr" |tr a-z A-Z)
689 TEST="$ADDR accepts all its options"
690 echo "### $TEST"
691 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
692 # echo OPTGROUPS=$OPTGROUPS
693 OPTS=
694 for g in $(echo $OPTGROUPS |tr ',' ' '); do
695 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
696 OPTS="$OPTS,$OPTG";
697 done
698 echo $OPTS
699 # prepare dummy server
700 $SOCAT tcp-l:$PORT,reuseaddr,crlf exec:"/bin/bash proxyecho.sh" || echo "cannot start proxyecho.sh" >&2 &
701 pid=$!
702 sleep 1
703 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
704 echo "testing if $ADDR accepts option $o"
705 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$PORT,$o
706 $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$((PORT+1)),proxyport=$PORT,$o
707 done
708 kill $pid 2>/dev/null
709 done
710 kill $pid 2>/dev/null
711 opts=
712 PORT=$((PORT+2))
715 #------------------------------------------------------------------------------
717 # test tcp4
719 #set -vx
720 if true; then
721 #if false; then
722 #opts="-s -d -d -d -d"
723 $SOCAT $opts tcp4-listen:$PORT,reuseaddr,fork,$o echo </dev/null &
724 pid=$!
725 for addr in tcp4; do
726 ADDR=$(echo "$addr" |tr a-z A-Z)
727 TEST="$ADDR accepts all its options"
728 echo "### $TEST"
729 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
730 # echo OPTGROUPS=$OPTGROUPS
731 OPTS=
732 for g in $(echo $OPTGROUPS |tr ',' ' '); do
733 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
734 OPTS="$OPTS,$OPTG";
735 done
736 echo $OPTS
737 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
738 echo "testing if $ADDR accepts option $o"
739 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
740 done
741 done
742 kill $pid 2>/dev/null
743 opts=
744 PORT=$((PORT+1))
747 #------------------------------------------------------------------------------
749 # test udp4-connect
751 #set -vx
752 if true; then
753 #if false; then
754 #opts="-s -d -d -d -d"
755 $SOCAT $opts udp4-listen:$PORT,fork,$o echo </dev/null &
756 pid=$!
757 for addr in udp4-connect; do
758 ADDR=$(echo "$addr" |tr a-z A-Z)
759 TEST="$ADDR accepts all its options"
760 echo "### $TEST"
761 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
762 # echo OPTGROUPS=$OPTGROUPS
763 OPTS=
764 for g in $(echo $OPTGROUPS |tr ',' ' '); do
765 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
766 OPTS="$OPTS,$OPTG";
767 done
768 echo $OPTS
769 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
770 echo "testing if $ADDR accepts option $o"
771 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
772 done
773 done
774 kill $pid 2>/dev/null
775 opts=
776 PORT=$((PORT+1))
779 #------------------------------------------------------------------------------
781 # test tcp4-listen
783 #set -vx
784 if true; then
785 #if false; then
786 #opts="-s -d -d -d -d"
787 for addr in tcp4-listen; 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 OPTS=
793 for g in $(echo $OPTGROUPS |tr ',' ' '); do
794 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
795 OPTS="$OPTS,$OPTG";
796 done
797 echo $OPTS
798 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
799 echo "testing if $ADDR accepts option $o"
800 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
801 pid=$!
802 $SOCAT /dev/null tcp4:$LOCALHOST:$PORT 2>/dev/null
803 kill $pid 2>/dev/null
804 done
805 done
806 opts=
807 PORT=$((PORT+1))
810 #------------------------------------------------------------------------------
812 # test udp4-listen
814 #set -vx
815 if true; then
816 #if false; then
817 #opts="-s -d -d -d -d"
818 for addr in udp4-listen; do
819 ADDR=$(echo "$addr" |tr a-z A-Z)
820 TEST="$ADDR accepts all its options"
821 echo "### $TEST"
822 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
823 OPTS=
824 for g in $(echo $OPTGROUPS |tr ',' ' '); do
825 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
826 OPTS="$OPTS,$OPTG";
827 done
828 echo $OPTS
829 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
830 echo "testing if $ADDR accepts option $o"
831 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
832 pid=$!
833 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
834 kill $pid 2>/dev/null
835 done
836 done
837 opts=
838 PORT=$((PORT+1))
841 #------------------------------------------------------------------------------
843 # test udp4-sendto
845 #set -vx
846 if true; then
847 #if false; then
848 #opts="-s -d -d -d -d"
849 $SOCAT $opts udp4-recv:$PORT,fork,$o echo </dev/null &
850 pid=$!
851 for addr in udp4-sendto; do
852 ADDR=$(echo "$addr" |tr a-z A-Z)
853 TEST="$ADDR accepts all its options"
854 echo "### $TEST"
855 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
856 # echo OPTGROUPS=$OPTGROUPS
857 OPTS=
858 for g in $(echo $OPTGROUPS |tr ',' ' '); do
859 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
860 OPTS="$OPTS,$OPTG";
861 done
862 echo $OPTS
863 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
864 echo "testing if $ADDR accepts option $o"
865 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
866 done
867 done
868 kill $pid 2>/dev/null
869 opts=
870 PORT=$((PORT+1))
873 #------------------------------------------------------------------------------
875 # test udp4-datagram
877 #set -vx
878 if true; then
879 #if false; then
880 #opts="-s -d -d -d -d"
881 #$SOCAT $opts udp4-recvfrom:$PORT,fork,$o echo </dev/null &
882 #pid=$!
883 for addr in udp4-datagram; do
884 ADDR=$(echo "$addr" |tr a-z A-Z)
885 TEST="$ADDR accepts all its options"
886 echo "### $TEST"
887 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
888 # echo OPTGROUPS=$OPTGROUPS
889 OPTS=
890 for g in $(echo $OPTGROUPS |tr ',' ' '); do
891 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
892 OPTS="$OPTS,$OPTG";
893 done
894 echo $OPTS
895 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
896 echo "testing if $ADDR accepts option $o"
897 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
898 done
899 done
900 #kill $pid 2>/dev/null
901 opts=
902 PORT=$((PORT+1))
905 #------------------------------------------------------------------------------
907 # test udp4-recv
909 #set -vx
910 if true; then
911 #if false; then
912 #opts="-s -d -d -d -d"
913 for addr in udp4-recv; 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 OPTS=
919 for g in $(echo $OPTGROUPS |tr ',' ' '); do
920 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
921 OPTS="$OPTS,$OPTG";
922 done
923 echo $OPTS
924 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
925 echo "testing if $ADDR accepts option $o"
926 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
927 pid=$!
928 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
929 kill $pid 2>/dev/null
930 done
931 done
932 opts=
933 PORT=$((PORT+1))
936 #------------------------------------------------------------------------------
938 # test udp4-recvfrom
940 #set -vx
941 if true; then
942 #if false; then
943 #opts="-s -d -d -d -d"
944 for addr in udp4-recvfrom; do
945 ADDR=$(echo "$addr" |tr a-z A-Z)
946 TEST="$ADDR accepts all its options"
947 echo "### $TEST"
948 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
949 OPTS=
950 for g in $(echo $OPTGROUPS |tr ',' ' '); do
951 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
952 OPTS="$OPTS,$OPTG";
953 done
954 echo $OPTS
955 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
956 echo "testing if $ADDR accepts option $o"
957 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
958 pid=$!
959 $SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
960 kill $pid 2>/dev/null
961 done
962 done
963 opts=
964 PORT=$((PORT+1))
967 #------------------------------------------------------------------------------
969 # test ip4-sendto
971 #set -vx
972 if true; then
973 #if false; then
974 #opts="-s -d -d -d -d"
975 $SOCAT $opts ip4-recv:$PORT,fork,$o echo </dev/null &
976 pid=$!
977 for addr in ip4-sendto; do
978 ADDR=$(echo "$addr" |tr a-z A-Z)
979 TEST="$ADDR accepts all its options"
980 echo "### $TEST"
981 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
982 # echo OPTGROUPS=$OPTGROUPS
983 OPTS=
984 for g in $(echo $OPTGROUPS |tr ',' ' '); do
985 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
986 OPTS="$OPTS,$OPTG";
987 done
988 echo $OPTS
989 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
990 echo "testing if $ADDR accepts option $o"
991 $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
992 done
993 done
994 kill $pid 2>/dev/null
995 opts=
996 PORT=$((PORT+1))
999 #------------------------------------------------------------------------------
1001 # test ip4-recv
1003 #set -vx
1004 if true; then
1005 #if false; then
1006 #opts="-s -d -d -d -d"
1007 for addr in ip4-recv; do
1008 ADDR=$(echo "$addr" |tr a-z A-Z)
1009 TEST="$ADDR accepts all its options"
1010 echo "### $TEST"
1011 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1012 OPTS=
1013 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1014 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1015 OPTS="$OPTS,$OPTG";
1016 done
1017 echo $OPTS
1018 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1019 echo "testing if $ADDR accepts option $o"
1020 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1021 pid=$!
1022 $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
1023 kill $pid 2>/dev/null
1024 done
1025 done
1026 opts=
1027 PORT=$((PORT+1))
1030 #------------------------------------------------------------------------------
1032 # test ip4-recvfrom
1034 #set -vx
1035 if true; then
1036 #if false; then
1037 #opts="-s -d -d -d -d"
1038 for addr in ip4-recvfrom; do
1039 ADDR=$(echo "$addr" |tr a-z A-Z)
1040 TEST="$ADDR accepts all its options"
1041 echo "### $TEST"
1042 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1043 OPTS=
1044 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1045 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1046 OPTS="$OPTS,$OPTG";
1047 done
1048 echo $OPTS
1049 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1050 echo "testing if $ADDR accepts option $o"
1051 $SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
1052 pid=$!
1053 $SOCAT /dev/null ip4-sendto:$LOCALHOST:$PORT 2>/dev/null
1054 kill $pid 2>/dev/null
1055 done
1056 done
1057 opts=
1058 PORT=$((PORT+1))
1061 #------------------------------------------------------------------------------
1063 # test READLINE
1065 if true; then
1066 #if false; then
1067 #opts="-s -d -d -d -d"
1068 for addr in readline; do
1069 ADDR=$(echo "$addr" |tr a-z A-Z)
1070 TEST="$ADDR accepts all its options"
1071 echo "### $TEST"
1072 TS=$TD/script$N
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 # for o in bs0; do
1082 echo "testing if $ADDR accepts option $o"
1083 echo "$SOCAT $opts readline,$o /dev/null" >$TS
1084 chmod u+x $TS
1085 $SOCAT /dev/null,ignoreeof exec:$TS,pty
1086 #stty sane
1087 done
1088 #reset 1>&0 2>&0
1089 done
1090 opts=
1093 #------------------------------------------------------------------------------
1095 # unnamed pipe
1096 #if false; then
1097 if true; then
1098 for addr in pipe; do
1099 ADDR=$(echo "$addr" |tr a-z A-Z)
1100 TEST="unnamed $ADDR accepts all its options"
1101 echo "### $TEST"
1102 OPTGROUPS=$($SOCAT -? |egrep " $addr[^:]" |sed 's/.*=//')
1103 OPTS=
1104 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1105 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1106 OPTS="$OPTS,$OPTG";
1107 done
1108 #echo $OPTS
1110 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1111 echo testing if unnamed $ADDR accepts option $o
1112 $SOCAT $opts $addr,$o /dev/null </dev/null
1113 done
1114 done
1117 #------------------------------------------------------------------------------
1119 # test addresses on files
1122 #if false; then
1123 if true; then
1124 for addr in create; do
1125 ADDR=$(echo "$addr" |tr a-z A-Z)
1126 TEST="$ADDR on new file accepts all its options"
1127 echo "### $TEST"
1128 TF=$TD/file$N
1129 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1130 OPTS=
1131 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1132 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1133 OPTS="$OPTS,$OPTG";
1134 done
1135 #echo $OPTS
1137 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1138 echo testing if $ADDR accepts option $o
1139 rm -f $TF
1140 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1141 rm -f $TF
1142 done
1143 done
1145 #------------------------------------------------------------------------------
1147 #if false; then
1148 if true; then
1149 for addr in exec system; do
1150 ADDR=$(echo "$addr" |tr a-z A-Z)
1152 TEST="$ADDR with socketpair accepts all its options"
1153 echo "### $TEST"
1154 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1155 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g')
1156 OPTS=
1157 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1158 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1159 OPTS="$OPTS,$OPTG";
1160 done
1161 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1162 #echo $OPTS
1163 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1164 echo testing if $ADDR with socketpair accepts option $o
1165 $SOCAT $opts $addr:$TRUE,$o /dev/null,ignoreof </dev/null
1166 done
1168 TEST="$ADDR with pipes accepts all its options"
1169 echo "### $TEST"
1170 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1171 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1172 OPTS=
1173 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1174 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1175 OPTS="$OPTS,$OPTG";
1176 done
1177 # flock tends to hang, so dont test it
1178 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')
1179 #echo $OPTS
1180 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1181 echo testing if $ADDR with pipes accepts option $o
1182 $SOCAT $opts $addr:$TRUE,pipes,$o /dev/null,ignoreof </dev/null
1183 done
1185 TEST="$ADDR with pty accepts all its options"
1186 echo "### $TEST"
1187 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1188 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1189 OPTS=
1190 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1191 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1192 OPTS="$OPTS,$OPTG";
1193 done
1194 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1195 #echo $OPTS
1196 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1197 echo testing if $ADDR with pty accepts option $o
1198 $SOCAT $opts $addr:$TRUE,pty,$o /dev/null,ignoreof </dev/null
1199 done
1201 TEST="$ADDR with nofork accepts all its options"
1202 echo "### $TEST"
1203 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1204 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,FIFO,/,/g' -e 's/,PTY,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1205 OPTS=
1206 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1207 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1208 OPTS="$OPTS,$OPTG";
1209 done
1210 OPTS=$(echo $OPTS|sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1211 #echo $OPTS
1212 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1213 echo testing if $ADDR with nofork accepts option $o
1214 $SOCAT /dev/null $opts $addr:$TRUE,nofork,$o </dev/null
1215 done
1217 done
1220 #------------------------------------------------------------------------------
1222 #if false; then
1223 if true; then
1224 for addr in fd; do
1225 ADDR=$(echo "$addr" |tr a-z A-Z)
1226 TEST="$ADDR accepts all its options"
1227 echo "### $TEST"
1228 TF=$TD/file$N
1229 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1230 OPTS=
1231 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1232 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1233 OPTS="$OPTS,$OPTG";
1234 done
1235 #echo $OPTS
1236 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1237 echo "testing if $ADDR (to file) accepts option $o"
1238 rm -f $TF
1239 $SOCAT $opts -u /dev/null $addr:3,$o 3>$TF
1240 done
1241 done
1244 #------------------------------------------------------------------------------
1246 # test OPEN address
1248 #! test it on pipe, device, new file
1251 #if false; then
1252 if true; then
1253 for addr in open; do
1254 ADDR=$(echo "$addr" |tr a-z A-Z)
1255 TEST="$ADDR on file accepts all its options"
1256 echo "### $TEST"
1257 TF=$TD/file$N
1258 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1259 OPTS=
1260 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1261 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1262 OPTS="$OPTS,$OPTG";
1263 done
1264 #echo $OPTS
1265 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1266 echo testing if $ADDR on file accepts option $o
1267 touch $TF
1268 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1269 rm -f $TF
1270 done
1271 done
1274 #------------------------------------------------------------------------------
1276 # test GOPEN address on files, sockets, pipes, devices
1279 #if false; then
1280 if true; then
1281 for addr in gopen; do
1282 ADDR=$(echo "$addr" |tr a-z A-Z)
1284 TEST="$ADDR on new file accepts all its options"
1285 echo "### $TEST"
1286 TF=$TD/file$N
1287 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1288 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1289 OPTS=
1290 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1291 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1292 OPTS="$OPTS,$OPTG";
1293 done
1294 #echo $OPTS
1295 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1296 echo testing if $ADDR on new file accepts option $o
1297 rm -f $TF
1298 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1299 rm -f $TF
1300 done
1302 TEST="$ADDR on existing file accepts all its options"
1303 echo "### $TEST"
1304 TF=$TD/file$N
1305 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1306 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1307 OPTS=
1308 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1309 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1310 OPTS="$OPTS,$OPTG";
1311 done
1312 #echo $OPTS
1313 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1314 echo testing if $ADDR on existing file accepts option $o
1315 rm -f $TF; touch $TF
1316 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1317 rm -f $TF
1318 done
1320 TEST="$ADDR on existing pipe accepts all its options"
1321 echo "### $TEST"
1322 TF=$TD/pipe$N
1323 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1324 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1325 OPTS=
1326 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1327 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1328 OPTS="$OPTS,$OPTG";
1329 done
1330 #echo $OPTS
1331 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1332 echo testing if $ADDR on named pipe accepts option $o
1333 rm -f $TF; mkfifo $TF
1334 $SOCAT $opts $addr:$TF,$o,nonblock /dev/null </dev/null
1335 rm -f $TF
1336 done
1338 TEST="$ADDR on existing socket accepts all its options"
1339 echo "### $TEST"
1340 TF=$TD/sock$N
1341 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1342 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1343 OPTS=
1344 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1345 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1346 OPTS="$OPTS,$OPTG";
1347 done
1348 #echo $OPTS
1349 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1350 echo testing if $ADDR on socket accepts option $o
1351 rm -f $TF; $SOCAT - UNIX-L:$TF & pid=$!
1352 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1353 kill $pid 2>/dev/null
1354 rm -f $TF
1355 done
1357 if [ $(id -u) -eq 0 ]; then
1358 TEST="$ADDR on existing device accepts all its options"
1359 echo "### $TEST"
1360 TF=$TD/null
1361 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1362 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1363 OPTS=
1364 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1365 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1366 OPTS="$OPTS,$OPTG";
1367 done
1368 #echo $OPTS
1369 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1370 echo testing if $ADDR on existing device accepts option $o
1371 rm -f $TF; mknod $TF c 1 3
1372 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1373 done
1374 else
1375 TEST="$ADDR on existing device accepts all its options"
1376 echo "### $TEST"
1377 TF=/dev/null
1378 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1379 OPTGROUPS=$(echo $OPTGROUPS |sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1380 OPTS=
1381 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1382 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1383 OPTS="$OPTS,$OPTG";
1384 done
1385 #echo $OPTS
1386 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1387 echo testing if $ADDR on existing device accepts option $o
1388 $SOCAT $opts -!!$addr:$TF,$o /dev/null,ignoreof </dev/null
1389 done
1392 done
1395 #------------------------------------------------------------------------------
1397 # test named pipe
1400 #if false; then
1401 if true; then
1402 for addr in pipe; do
1403 ADDR=$(echo "$addr" |tr a-z A-Z)
1404 TEST="$ADDR on file accepts all its options"
1405 echo "### $TEST"
1406 TF=$TD/pipe$N
1407 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1408 OPTS=
1409 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1410 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1411 OPTS="$OPTS,$OPTG";
1412 done
1413 #echo $OPTS
1415 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1416 echo testing if named $ADDR accepts option $o
1417 rm -f $TF
1418 # blocks with rdonly, wronly
1419 case "$o" in rdonly|wronly) o="$o,nonblock" ;; esac
1420 $SOCAT $opts $addr:$TF,$o /dev/null </dev/null
1421 rm -f $TF
1422 done
1423 done
1425 #------------------------------------------------------------------------------
1427 # test STDIO
1429 #! test different stream types
1431 #if false; then
1432 if true; then
1433 for addr in stdio; do
1434 ADDR=$(echo "$addr" |tr a-z A-Z)
1435 TEST="$ADDR accepts all its options"
1436 echo "### $TEST"
1437 OPTGROUPS=$($SOCAT -? |fgrep " $addr" |sed 's/.*=//')
1438 OPTS=
1439 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1440 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1441 OPTS="$OPTS,$OPTG";
1442 done
1443 #echo $OPTS
1445 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1446 echo "testing if $ADDR (/dev/null, stdout) accepts option $o"
1447 $SOCAT $opts $addr,$o /dev/null,ignoreof </dev/null
1448 done
1449 done
1452 #------------------------------------------------------------------------------
1454 # test STDIN
1456 #if false; then
1457 if true; then
1458 for addr in stdin; do
1459 ADDR=$(echo "$addr" |tr a-z A-Z)
1460 TEST="$ADDR accepts all its options"
1461 echo "### $TEST"
1462 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1463 OPTS=
1464 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1465 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1466 OPTS="$OPTS,$OPTG";
1467 done
1468 #echo $OPTS
1470 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1471 echo "testing if $ADDR (/dev/null) accepts option $o"
1472 $SOCAT $opts -u $addr,$o /dev/null </dev/null
1473 done
1474 done
1477 #------------------------------------------------------------------------------
1479 # test STDOUT, STDERR
1481 if true; then
1482 #if false; then
1483 for addr in stdout stderr; do
1484 ADDR=$(echo "$addr" |tr a-z A-Z)
1485 TEST="$ADDR accepts all its options"
1486 echo "### $TEST"
1487 OPTGROUPS=$($SOCAT -? |fgrep " $addr " |sed 's/.*=//')
1488 OPTS=
1489 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1490 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1491 OPTS="$OPTS,$OPTG";
1492 done
1493 #echo $OPTS
1494 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1495 echo "testing if $ADDR accepts option $o"
1496 $SOCAT $opts -u /dev/null $addr,$o
1497 done
1498 done
1501 #------------------------------------------------------------------------------
1502 # REQUIRES ROOT
1504 if [ "$withroot" ]; then
1505 for addr in ip4; do
1506 ADDR=$(echo "$addr" |tr a-z A-Z)
1507 TEST="$ADDR accepts all its options"
1508 echo "### $TEST"
1509 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1510 OPTS=
1511 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1512 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1513 OPTS="$OPTS,$OPTG";
1514 done
1515 #echo $OPTS
1516 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1517 echo "testing if $ADDR accepts option $o"
1518 $SOCAT $opts $addr:127.0.0.1:200 /dev/null,ignoreof </dev/null
1519 done
1520 done
1523 #------------------------------------------------------------------------------
1524 # REQUIRES ROOT
1526 if [ "$withroot" ]; then
1527 for addr in ip6; do
1528 ADDR=$(echo "$addr" |tr a-z A-Z)
1529 TEST="$ADDR accepts all its options"
1530 echo "### $TEST"
1531 OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
1532 OPTS=
1533 for g in $(echo $OPTGROUPS |tr ',' ' '); do
1534 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1535 OPTS="$OPTS,$OPTG";
1536 done
1537 #echo $OPTS
1538 for o in $(filloptionvalues $OPTS|tr ',' ' '); do
1539 echo "testing if $ADDR accepts option $o"
1540 $SOCAT $opts $addr:[::1]:200 /dev/null,ignoreof </dev/null
1541 done
1542 done
1545 #==============================================================================
1547 #TEST="stdio accepts all options of GROUP_ANY"
1548 #echo "### $TEST"
1549 #CMD="$SOCAT $opts -,$OPTS_ANY /dev/null"
1550 #$CMD
1551 #if [ $? = 0 ]; then
1552 # echo "... test $N ($TEST) succeeded"
1553 ## echo "CMD=$CMD"
1554 #else
1555 # echo "*** test $N ($TEST) FAILED"
1556 # echo "CMD=$CMD"
1559 #N=$((N+1))
1560 ##------------------------------------------------------------------------------
1562 #TEST="exec accepts all options of GROUP_ANY and GROUP_SOCKET"
1563 #echo "### $TEST"
1564 #CMD="$SOCAT $opts exec:$TRUE,$OPTS_ANY,$OPTS_SOCKET /dev/null"
1565 #$CMD
1566 #if [ $? = 0 ]; then
1567 # echo "... test $N ($TEST) succeeded"
1568 ## echo "CMD=$CMD"
1569 #else
1570 # echo "*** test $N ($TEST) FAILED"
1571 # echo "CMD=$CMD"
1574 #------------------------------------------------------------------------------
1576 esac
1578 #==============================================================================
1581 numOK=0
1582 numFAIL=0
1583 numCANT=0
1584 listFAIL=
1586 #==============================================================================
1587 # test if selected socat features work ("FUNCTIONS")
1589 testecho () {
1590 local N="$1"
1591 local title="$2"
1592 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1593 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1594 local opts="$5"
1595 local T="$6"; [ -z "$T" ] && T=0
1596 local tf="$td/test$N.stdout"
1597 local te="$td/test$N.stderr"
1598 local tdiff="$td/test$N.diff"
1599 local da="test$N $(date) $RANDOM"
1600 if ! eval $NUMCOND; then :; else
1601 #local cmd="$TRACE $SOCAT $opts $arg1 $arg2"
1602 #$ECHO "testing $title (test $N)... \c"
1603 $PRINTF "test $F_n %s... " $N "$title"
1604 #echo "$da" |$cmd >"$tf" 2>"$te"
1605 (psleep $T; echo "$da"; psleep $T) |($TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"; echo $? >"$td/test$N.rc") &
1606 export rc1=$!
1607 #sleep 5 && kill $rc1 2>/dev/null &
1608 # rc2=$!
1609 wait $rc1
1610 # kill $rc2 2>/dev/null
1611 if [ "$(cat "$td/test$N.rc")" != 0 ]; then
1612 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1613 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1614 cat "$te"
1615 numFAIL=$((numFAIL+1))
1616 listFAIL="$listFAIL $N"
1617 elif echo "$da" |diff - "$tf" >"$tdiff" 2>&1; then
1618 $PRINTF "$OK\n"
1619 if [ -n "$debug" ]; then cat $te; fi
1620 numOK=$((numOK+1))
1621 else
1622 $PRINTF "$FAILED:\n"
1623 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1624 cat "$te"
1625 echo diff:
1626 cat "$tdiff"
1627 numFAIL=$((numFAIL+1))
1628 listFAIL="$listFAIL $N"
1630 fi # NUMCOND
1633 # test if call to od and throughput of data works - with graceful shutdown and
1634 # flush of od buffers
1635 testod () {
1636 local num="$1"
1637 local title="$2"
1638 local arg1="$3"; [ -z "$arg1" ] && arg1="-"
1639 local arg2="$4"; [ -z "$arg2" ] && arg2="echo"
1640 local opts="$5"
1641 local T="$6"; [ -z "$T" ] && T=0
1642 local tf="$td/test$N.stdout"
1643 local te="$td/test$N.stderr"
1644 local tr="$td/test$N.ref"
1645 local tdiff="$td/test$N.diff"
1646 local dain="$(date) $RANDOM"
1647 if ! eval $NUMCOND; then :; else
1648 echo "$dain" |$OD_C >"$tr"
1649 # local daout="$(echo "$dain" |$OD_C)"
1650 $PRINTF "test $F_n %s... " $num "$title"
1651 (psleep $T; echo "$dain"; psleep $T) |$TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"
1652 if [ "$?" != 0 ]; then
1653 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1654 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1655 cat "$te"
1656 numFAIL=$((numFAIL+1))
1657 listFAIL="$listFAIL $num"
1658 # elif echo "$daout" |diff - "$tf" >"$tdiff" 2>&1; then
1659 elif diff "$tr" "$tf" >"$tdiff" 2>&1; then
1660 $PRINTF "$OK\n"
1661 if [ -n "$debug" ]; then cat $te; fi
1662 numOK=$((numOK+1))
1663 else
1664 $PRINTF "$FAILED: diff:\n"
1665 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1666 cat "$te"
1667 cat "$tdiff"
1668 numFAIL=$((numFAIL+1))
1669 listFAIL="$listFAIL $num"
1671 fi # NUMCOND
1674 # test if the socat executable has these address types compiled in
1675 # print the first missing address type
1676 testaddrs () {
1677 local a A;
1678 for a in $@; do
1679 A=$(echo "$a" |tr 'a-z-' 'A-Z_')
1680 if $TRACE $SOCAT -V |grep "#define WITH_$A 1\$" >/dev/null; then
1681 shift
1682 continue
1684 echo "$a"
1685 return 1
1686 done
1687 return 0
1690 # test if the socat executable has these options compiled in
1691 # print the first missing option
1692 testoptions () {
1693 local a A;
1694 for a in $@; do
1695 A=$(echo "$a" |tr 'a-z' 'A-Z')
1696 if $TRACE $SOCAT -??? |grep "[^a-z0-9-]$a[^a-z0-9-]" >/dev/null; then
1697 shift
1698 continue
1700 echo "$a"
1701 return 1
1702 done
1703 return 0
1706 # check if the given pid exists and has child processes
1707 # if yes: prints child process lines to stdout, returns 0
1708 # if not: prints ev.message to stderr, returns 1
1709 childprocess () {
1710 local l
1711 case "$UNAME" in
1712 AIX) l="$(ps -fade |grep "^........ ...... $(printf %6u $1)")" ;;
1713 FreeBSD) l="$(ps -faje |grep "^........ ..... $(printf %5u $1)")" ;;
1714 HP-UX) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1715 Linux) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1716 # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)")" ;;
1717 NetBSD) l="$(ps -aj |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
1718 OpenBSD) l="$(ps -aj |grep "^........ ..... $(printf %5u $1)")" ;;
1719 SunOS) l="$(ps -fade |grep "^........ ..... $(printf %5u $1)")" ;;
1720 DragonFly)l="$(ps -faje |grep "^[^ ][^ ]*[ ][ ]*..... $(printf %5u $1)")" ;;
1721 CYGWIN*) l="$(ps -pafe |grep "^[^ ]*[ ][ ]*[^ ][^ ]*[ ][ ]*$1[ ]")" ;;
1722 *) l="$(ps -fade |grep "^[^ ][^ ]*[ ][ ]*[0-9][0-9]**[ ][ ]*$(printf %5u $1) ")" ;; esac
1723 if [ -z "$l" ]; then
1724 return 1;
1726 echo "$l"
1727 return 0
1730 # check if the given process line refers to a defunct (zombie) process
1731 # yes: returns 0
1732 # no: returns 1
1733 isdefunct () {
1734 local l
1735 case "$UNAME" in
1736 AIX) l="$(echo "$1" |grep ' <defunct>$')" ;;
1737 FreeBSD) l="$(echo "$1" |grep ' <defunct>$')" ;;
1738 HP-UX) l="$(echo "$1" |grep ' <defunct>$')" ;;
1739 Linux) l="$(echo "$1" |grep ' <defunct>$')" ;;
1740 SunOS) l="$(echo "$1" |grep ' <defunct>$')" ;;
1741 DragonFly)l="$(echo "$1" |grep ' <defunct>$')" ;;
1742 *) l="$(echo "$1" |grep ' <defunct>$')" ;;
1743 esac
1744 [ -n "$l" ];
1747 # check if UNIX socket protocol is available on host
1748 runsunix () {
1749 return 0;
1750 $TRACE $SOCAT /dev/null UNIX-LISTEN:"$td/unix.socket" 2>"$td/unix.stderr" &
1751 pid=$!
1752 usleep $MICROS
1753 kill "$pid" 2>/dev/null
1754 test ! -s "$td/unix.stderr"
1757 unset HAVENOT_IP4
1758 # check if an IP4 loopback interface exists
1759 runsip4 () {
1760 [ -n "$HAVENOT_IP4" ] && return $HAVENOT_IP4
1761 local l
1762 case "$UNAME" in
1763 AIX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1764 FreeBSD) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1765 HP-UX) l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1766 Linux) l=$($IFCONFIG |egrep 'inet (addr:)?127\.0\.0\.1 ') ;;
1767 NetBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1768 OpenBSD)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1769 OSF1) l=$($IFCONFIG -a |grep ' inet ') ;;
1770 SunOS) l=$($IFCONFIG -a |grep 'inet ') ;;
1771 Darwin)l=$($IFCONFIG lo0 |fgrep 'inet 127.0.0.1 ') ;;
1772 DragonFly)l=$($IFCONFIG -a |fgrep 'inet 127.0.0.1 ');;
1773 CYGWIN*) l=$(ipconfig |grep IPv4);;
1774 *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
1775 esac
1776 [ -z "$l" ] && return 1
1777 # existence of interface might not suffice, check for routeability:
1778 case "$UNAME" in
1779 Darwin) ping -c 1 127.0.0.1; l="$?" ;;
1780 Linux) ping -c 1 127.0.0.1; l="$?" ;;
1781 *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
1782 esac
1783 HAVENOT_IP4=$l
1784 return $l;
1787 unset HAVENOT_IP6
1788 # check if an IP6 loopback interface exists
1789 runsip6 () {
1790 [ -n "$HAVENOT_IP6" ] && return $HAVENOT_IP6
1791 local l
1792 case "$UNAME" in
1793 AIX) l=$($IFCONFIG lo0 |grep 'inet6 ::1/0') ;;
1794 HP-UX) l=$($IFCONFIG lo0 |grep ' inet6 ') ;;
1795 Linux) l=$($IFCONFIG |egrep 'inet6 (addr: )?::1/?') ;;
1796 NetBSD)l=$($IFCONFIG -a |grep 'inet6 ::1 ');;
1797 OSF1) l=$($IFCONFIG -a |grep ' inet6 ') ;;
1798 SunOS) l=$($IFCONFIG -a |grep 'inet6 ') ;;
1799 Darwin)l=$($IFCONFIG lo0 |grep 'inet6 ::1 ') ;;
1800 CYGWIN*) l=$(ipconfig |grep IPv6);;
1801 *) l=$($IFCONFIG -a |grep ' ::1[^:0-9A-Fa-f]') ;;
1802 esac
1803 [ -z "$l" ] && return 1
1804 # existence of interface might not suffice, check for routeability:
1805 case "$UNAME" in
1806 Darwin) ping6 -c 1 ::1; l="$?" ;;
1807 Linux) ping6 -c 1 ::1; l="$?" ;;
1808 *) if [ -n "$l" ]; then l=0; else l=1; fi ;;
1809 esac
1810 HAVENOT_IP6=$l
1811 return $l;
1814 # check if TCP on IPv4 is available on host
1815 runstcp4 () {
1816 return 0;
1817 # PORT="$1"
1818 $TRACE $SOCAT $opts /dev/null TCP4-LISTEN:$PORT 2>"$td/tcp4.stderr" &
1819 pid=$!
1820 usleep $MICROS
1821 kill "$pid" 2>/dev/null
1822 wait
1823 usleep $MICROS
1824 test ! -s "$td/tcp4.stderr"
1827 # check if TCP on IPv6 is available on host
1828 runstcp6 () {
1829 return 0;
1830 # PORT="$1"
1831 $TRACE $SOCAT $opts /dev/null TCP6-LISTEN:$PORT 2>"$td/tcp6.stderr" &
1832 pid=$!
1833 kill "$pid" 2>/dev/null
1834 wait
1835 usleep $MICROS
1836 test ! -s "$td/tcp6.stderr"
1839 # check if UDP on IPv4 is available on host
1840 runsudp4 () {
1841 return 0;
1842 # PORT="$1"
1843 $TRACE $SOCAT $opts /dev/null UDP4-LISTEN:$PORT 2>"$td/udp4.stderr" &
1844 pid=$!
1845 usleep $MICROS
1846 kill "$pid" 2>/dev/null
1847 wait
1848 usleep $MICROS
1849 test ! -s "$td/udp4.stderr"
1852 # check if UDP on IPv6 is available on host
1853 runsudp6 () {
1854 return 0;
1855 # PORT="$1"
1856 $TRACE $SOCAT $opts /dev/null UDP6-LISTEN:$PORT 2>"$td/udp6.stderr" &
1857 pid=$!
1858 usleep $MICROS
1859 kill "$pid" 2>/dev/null
1860 wait
1861 usleep $MICROS
1862 test ! -s "$td/udp6.stderr"
1865 # check if SCTP on IPv4 is available on host
1866 runssctp4 () {
1867 # PORT="$1"
1868 $TRACE $SOCAT $opts /dev/null SCTP4-LISTEN:$PORT 2>"$td/sctp4.stderr" &
1869 pid=$!
1870 usleep $MICROS
1871 kill "$pid" 2>/dev/null
1872 wait
1873 usleep $MICROS
1874 test ! -s "$td/sctp4.stderr"
1877 # check if SCTP on IPv6 is available on host
1878 runssctp6 () {
1879 #PORT="$1"
1880 $TRACE $SOCAT $opts /dev/null SCTP6-LISTEN:$PORT 2>"$td/sctp6.stderr" &
1881 pid=$!
1882 usleep $MICROS
1883 kill "$pid" 2>/dev/null
1884 wait
1885 usleep $MICROS
1886 test ! -s "$td/sctp6.stderr"
1889 # wait until an IP4 protocol is ready
1890 waitip4proto () {
1891 local proto="$1"
1892 local logic="$2" # 0..wait until free; 1..wait until listening
1893 local timeout="$3"
1894 local l
1895 [ "$logic" ] || logic=1
1896 [ "$timeout" ] || timeout=5
1897 while [ $timeout -gt 0 ]; do
1898 case "$UNAME" in
1899 Linux) l=$(netstat -n -w -l |grep '^raw .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*') ;;
1900 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
1901 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1902 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1903 # Darwin) case "$(uname -r)" in
1904 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
1905 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
1906 # esac ;;
1907 AIX) # does not seem to show raw sockets in netstat
1908 sleep 1; return 0 ;;
1909 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
1910 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
1911 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
1912 *) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;;
1913 sleep 1; return 0 ;;
1914 esac
1915 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
1916 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
1917 sleep 1
1918 timeout=$((timeout-1))
1919 done
1921 $ECHO "!protocol $proto timed out! \c" >&2
1922 return 1
1925 # we need this misleading function name for canonical reasons
1926 waitip4port () {
1927 waitip4proto "$1" "$2" "$3"
1930 # wait until an IP6 protocol is ready
1931 waitip6proto () {
1932 local proto="$1"
1933 local logic="$2" # 0..wait until free; 1..wait until listening
1934 local timeout="$3"
1935 local l
1936 [ "$logic" ] || logic=1
1937 [ "$timeout" ] || timeout=5
1938 while [ $timeout -gt 0 ]; do
1939 case "$UNAME" in
1940 Linux) l=$(netstat -n -w -l |grep '^raw[6 ] .* .*:[0-9*]*:'$proto' [ ]*:::\*') ;;
1941 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
1942 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1943 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1944 # Darwin) case "$(uname -r)" in
1945 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
1946 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
1947 # esac ;;
1948 AIX) # does not seem to show raw sockets in netstat
1949 sleep 1; return 0 ;;
1950 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
1951 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
1952 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
1953 *) #l=$(netstat -an |egrep -i 'raw6? .*[0-9*][:.]'$proto' ') ;;
1954 sleep 1; return 0 ;;
1955 esac
1956 [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
1957 \( \( $logic -eq 0 \) -a -z "$l" \) ] && return 0
1958 sleep 1
1959 timeout=$((timeout-1))
1960 done
1962 $ECHO "!protocol $proto timed out! \c" >&2
1963 return 1
1966 # we need this misleading function name for canonical reasons
1967 waitip6port () {
1968 waitip6proto "$1" "$2" "$3"
1971 # check if a TCP4 port is in use
1972 # exits with 0 when it is not used
1973 checktcp4port () {
1974 local port="$1"
1975 local l
1976 case "$UNAME" in
1977 Linux) l=$(netstat -a -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN') ;;
1978 FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
1979 NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
1980 Darwin) case "$(uname -r)" in
1981 [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
1982 *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
1983 esac ;;
1984 AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
1985 SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
1986 HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
1987 OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
1988 CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
1989 DragonFly)l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
1990 *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
1991 esac
1992 [ -z "$l" ] && return 0
1993 return 1
1996 # wait until a TCP4 listen port is ready
1997 waittcp4port () {
1998 local port="$1"
1999 local logic="$2" # 0..wait until free; 1..wait until listening
2000 local timeout="$3"
2001 local l
2002 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2003 [ "$logic" ] || logic=1
2004 [ "$timeout" ] || timeout=5
2005 while [ $timeout -gt 0 ]; do
2006 case "$UNAME" in
2007 Linux) l=$(netstat -a -n -t -l |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN') ;;
2008 FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2009 NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2010 Darwin) case "$(uname -r)" in
2011 [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2012 *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2013 esac ;;
2014 AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2015 SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2016 HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2017 OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2018 CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2019 DragonFly) l=$(netstat -ant |grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2020 *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2021 esac
2022 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2023 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2024 set ${vx}vx
2025 return 0
2027 sleep 1
2028 timeout=$((timeout-1))
2029 done
2031 $ECHO "!port $port timed out! \c" >&2
2032 set ${vx}vx
2033 return 1
2036 # wait until a UDP4 port is ready
2037 waitudp4port () {
2038 local port="$1"
2039 local logic="$2" # 0..wait until free; 1..wait until listening
2040 local timeout="$3"
2041 local l
2042 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2043 [ "$logic" ] || logic=1
2044 [ "$timeout" ] || timeout=5
2045 while [ $timeout -gt 0 ]; do
2046 case "$UNAME" in
2047 Linux) l=$(netstat -a -n -u -l |grep '^udp .* .*[0-9*]:'$port' [ ]*0\.0\.0\.0:\*') ;;
2048 FreeBSD) l=$(netstat -an |egrep '^udp46? .*[0-9*]\.'$port' .* \*\.\*') ;;
2049 NetBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2050 OpenBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2051 Darwin) case "$(uname -r)" in
2052 [1-5]*) l=$(netstat -an |grep '^udp.* .*[0-9*]\.'$port' .* \*\.\*') ;;
2053 *) l=$(netstat -an |grep '^udp4.* .*[0-9*]\.'$port' .* \*\.\* .*') ;;
2054 esac ;;
2055 AIX) l=$(netstat -an |grep '^udp[4 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2056 SunOS) l=$(netstat -an -f inet -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2057 HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' .* \*\.\* ') ;;
2058 OSF1) l=$(/usr/sbin/netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2059 DragonFly) l=$(netstat -an |grep '^udp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2060 *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2061 esac
2062 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2063 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2064 set ${vx}vx
2065 return 0
2067 sleep 1
2068 timeout=$((timeout-1))
2069 done
2071 $ECHO "!port $port timed out! \c" >&2
2072 set ${vx}vx
2073 return 1
2076 # wait until an SCTP4 listen port is ready
2077 waitsctp4port () {
2078 local port="$1"
2079 local logic="$2" # 0..wait until free; 1..wait until listening
2080 local timeout="$3"
2081 local l
2082 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2083 [ "$logic" ] || logic=1
2084 [ "$timeout" ] || timeout=5
2085 while [ $timeout -gt 0 ]; do
2086 case "$UNAME" in
2087 Linux) l=$(netstat -n -a |grep '^sctp .* .*[0-9*]:'$port' .* LISTEN') ;;
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 sctp |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 *) l=$(netstat -an |grep -i 'sctp .*[0-9*][:.]'$port' .* listen') ;;
2100 esac
2101 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2102 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2103 set ${vx}vx
2104 return 0
2106 sleep 1
2107 timeout=$((timeout-1))
2108 done
2110 $ECHO "!port $port timed out! \c" >&2
2111 set ${vx}vx
2112 return 1
2115 # wait until a tcp6 listen port is ready
2116 waittcp6port () {
2117 local port="$1"
2118 local logic="$2" # 0..wait until free; 1..wait until listening
2119 local timeout="$3"
2120 local l
2121 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2122 [ "$logic" ] || logic=1
2123 [ "$timeout" ] || timeout=5
2124 while [ $timeout -gt 0 ]; do
2125 case "$UNAME" in
2126 Linux) l=$(netstat -an |grep -E '^tcp6? .* [0-9a-f:%]*:'$port' .* LISTEN') ;;
2127 FreeBSD) l=$(netstat -an |egrep -i 'tcp(6|46) .*[0-9*][:.]'$port' .* listen') ;;
2128 NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2129 OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2130 Darwin) l=$(netstat -an |egrep '^tcp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+ +LISTEN') ;;
2131 AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2132 SunOS) l=$(netstat -an -f inet6 -P tcp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2133 #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2134 DragonFly) l=$(netstat -ant |grep '^tcp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2135 *) l=$(netstat -an |grep -i 'tcp6 .*:'$port' .* listen') ;;
2136 esac
2137 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2138 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2139 set ${vx}vx
2140 return 0
2142 sleep 1
2143 timeout=$((timeout-1))
2144 done
2146 $ECHO "!port $port timed out! \c" >&2
2147 #echo set ${vx}vx >&2
2148 set ${vx}vx
2149 return 1
2152 # wait until a UDP6 port is ready
2153 waitudp6port () {
2154 local port="$1"
2155 local logic="$2" # 0..wait until free; 1..wait until listening
2156 local timeout="$3"
2157 local l
2158 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2159 [ "$logic" ] || logic=1
2160 [ "$timeout" ] || timeout=5
2161 while [ $timeout -gt 0 ]; do
2162 case "$UNAME" in
2163 Linux) l=$(netstat -an |grep -E '^udp6? .* .*[0-9*:%]:'$port' [ ]*:::\*') ;;
2164 FreeBSD) l=$(netstat -an |egrep '^udp(6|46) .*[0-9*]\.'$port' .* \*\.\*') ;;
2165 NetBSD) l=$(netstat -an |grep '^udp6 .* \*\.'$port' [ ]* \*\.\*') ;;
2166 OpenBSD) l=$(netstat -an |grep '^udp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2167 Darwin) l=$(netstat -an |egrep '^udp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+') ;;
2168 AIX) l=$(netstat -an |grep '^udp[6 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2169 SunOS) l=$(netstat -an -f inet6 -P udp |grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2170 #HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' ') ;;
2171 #OSF1) l=$(/usr/sbin/netstat -an |grep '^udp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2172 DragonFly) l=$(netstat -ant |grep '^udp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2173 *) l=$(netstat -an |grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2174 esac
2175 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2176 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2177 set ${vx}vx
2178 return 0
2180 sleep 1
2181 timeout=$((timeout-1))
2182 done
2184 $ECHO "!port $port timed out! \c" >&2
2185 set ${vx}vx
2186 return 1
2189 # wait until a sctp6 listen port is ready
2190 # not all (Linux) variants show this in netstat
2191 waitsctp6port () {
2192 local port="$1"
2193 local logic="$2" # 0..wait until free; 1..wait until listening
2194 local timeout="$3"
2195 local l
2196 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2197 [ "$logic" ] || logic=1
2198 [ "$timeout" ] || timeout=5
2199 while [ $timeout -gt 0 ]; do
2200 case "$UNAME" in
2201 Linux) l=$(netstat -an |grep '^sctp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN') ;;
2202 # FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;;
2203 # NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2204 # OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2205 # AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2206 SunOS) l=$(netstat -an -f inet6 -P sctp |grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2207 # #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2208 *) l=$(netstat -an |grep -i 'stcp6 .*:'$port' .* listen') ;;
2209 esac
2210 if [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \
2211 \( \( $logic -eq 0 \) -a -z "$l" \) ]; then
2212 set ${vx}vx
2213 return 0
2215 sleep 1
2216 timeout=$((timeout-1))
2217 done
2219 $ECHO "!port $port timed out! \c" >&2
2220 set ${vx}vx
2221 return 1
2224 # we need this misleading function name for canonical reasons
2225 waitunixport () {
2226 waitfile "$1" "$2" "$3"
2229 # wait until a filesystem entry exists
2230 waitfile () {
2231 local crit=-e
2232 case "X$1" in X-*) crit="$1"; shift ;; esac
2233 local file="$1"
2234 local logic="$2" # 0..wait until gone; 1..wait until exists (default);
2235 # 2..wait until not empty
2236 local timeout="$3"
2237 local vx=+; case $- in *vx*) set +vx; vx=-; esac # no tracing here
2238 [ "$logic" ] || logic=1
2239 [ "$logic" -eq 2 ] && crit=-s
2240 [ "$timeout" ] || timeout=5
2241 while [ $timeout -gt 0 ]; do
2242 if [ \( \( $logic -ne 0 \) -a $crit "$file" \) -o \
2243 \( \( $logic -eq 0 \) -a ! $crit "$file" \) ]; then
2244 set ${vx}vx
2245 return 0
2247 sleep 1
2248 timeout=$((timeout-1))
2249 done
2251 echo "file $file timed out" >&2
2252 set ${vx}vx
2253 return 1
2256 # generate a test certificate and key
2257 gentestcert () {
2258 local name="$1"
2259 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2260 openssl genrsa $OPENSSL_RAND -out $name.key 768 >/dev/null 2>&1
2261 openssl req -new -config $TESTCERT_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
2262 cat $name.key $name.crt >$name.pem
2265 # generate a test DSA key and certificate
2266 gentestdsacert () {
2267 local name="$1"
2268 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2269 openssl dsaparam -out $name-dsa.pem 512 >/dev/null 2>&1
2270 openssl dhparam -dsaparam -out $name-dh.pem 512 >/dev/null 2>&1
2271 openssl req -newkey dsa:$name-dsa.pem -keyout $name.key -nodes -x509 -config $TESTCERT_CONF -out $name.crt -days 3653 >/dev/null 2>&1
2272 cat $name-dsa.pem $name-dh.pem $name.key $name.crt >$name.pem
2275 gentestcert6 () {
2276 local name="$1"
2277 if [ -s $name.key -a -s $name.crt -a -s $name.pem ]; then return; fi
2278 cat $TESTCERT_CONF |
2279 { echo "# automatically generated by $0"; cat; } |
2280 sed 's/\(commonName\s*=\s*\).*/\1[::1]/' >$TESTCERT6_CONF
2281 openssl genrsa $OPENSSL_RAND -out $name.key 768 >/dev/null 2>&1
2282 openssl req -new -config $TESTCERT6_CONF -key $name.key -x509 -out $name.crt -days 3653 >/dev/null 2>&1
2283 cat $name.key $name.crt >$name.pem
2287 NAME=UNISTDIO
2288 case "$TESTS " in
2289 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2290 TEST="$NAME: unidirectional throughput from stdin to stdout"
2291 testecho "$N" "$TEST" "stdin" "stdout" "$opts -u"
2292 esac
2293 N=$((N+1))
2296 NAME=UNPIPESTDIO
2297 case "$TESTS" in
2298 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2299 TEST="$NAME: stdio with simple echo via internal pipe"
2300 testecho "$N" "$TEST" "stdio" "pipe" "$opts"
2301 esac
2302 N=$((N+1))
2305 NAME=UNPIPESHORT
2306 case "$TESTS" in
2307 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2308 TEST="$NAME: short form of stdio ('-') with simple echo via internal pipe"
2309 testecho "$N" "$TEST" "-" "pipe" "$opts"
2310 esac
2311 N=$((N+1))
2314 NAME=DUALSTDIO
2315 case "$TESTS" in
2316 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2317 TEST="$NAME: splitted form of stdio ('stdin!!stdout') with simple echo via internal pipe"
2318 testecho "$N" "$TEST" "stdin!!stdout" "pipe" "$opts"
2319 esac
2320 N=$((N+1))
2323 NAME=DUALSHORTSTDIO
2324 case "$TESTS" in
2325 *%$N%*|*%functions%*|*%stdio%*|*%$NAME%*)
2326 TEST="$NAME: short splitted form of stdio ('-!!-') with simple echo via internal pipe"
2327 testecho "$N" "$TEST" "-!!-" "pipe" "$opts"
2328 esac
2329 N=$((N+1))
2332 NAME=DUALFDS
2333 case "$TESTS" in
2334 *%$N%*|*%functions%*|*%fd%*|*%$NAME%*)
2335 TEST="$NAME: file descriptors with simple echo via internal pipe"
2336 testecho "$N" "$TEST" "0!!1" "pipe" "$opts"
2337 esac
2338 N=$((N+1))
2341 NAME=NAMEDPIPE
2342 case "$TESTS" in
2343 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2344 TEST="$NAME: simple echo via named pipe"
2345 # with MacOS, this test hangs if nonblock is not used. Is an OS bug.
2346 tp="$td/pipe$N"
2347 # note: the nonblock is required by MacOS 10.1(?), otherwise it hangs (OS bug?)
2348 testecho "$N" "$TEST" "" "pipe:$tp,nonblock" "$opts"
2349 esac
2350 N=$((N+1))
2353 NAME=DUALPIPE
2354 case "$TESTS" in
2355 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2356 TEST="$NAME: simple echo via named pipe, specified twice"
2357 tp="$td/pipe$N"
2358 testecho "$N" "$TEST" "" "pipe:$tp,nonblock!!pipe:$tp" "$opts"
2359 esac
2360 N=$((N+1))
2363 NAME=FILE
2364 case "$TESTS" in
2365 *%$N%*|*%functions%*|*%engine%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
2366 TEST="$NAME: simple echo via file"
2367 tf="$td/file$N"
2368 testecho "$N" "$TEST" "" "$tf,ignoreeof!!$tf" "$opts"
2369 esac
2370 N=$((N+1))
2373 NAME=EXECSOCKET
2374 case "$TESTS" in
2375 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2376 TEST="$NAME: simple echo via exec of cat with socketpair"
2377 testecho "$N" "$TEST" "" "exec:$CAT" "$opts"
2378 esac
2379 N=$((N+1))
2382 NAME=SYSTEMSOCKET
2383 case "$TESTS" in
2384 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2385 TEST="$NAME: simple echo via system() of cat with socketpair"
2386 testecho "$N" "$TEST" "" "system:$CAT" "$opts" "$val_t"
2387 esac
2388 N=$((N+1))
2391 NAME=EXECPIPES
2392 case "$TESTS" in
2393 *%$N%*|*%functions%*|*%pipe%*|*%$NAME%*)
2394 TEST="$NAME: simple echo via exec of cat with pipes"
2395 testecho "$N" "$TEST" "" "exec:$CAT,pipes" "$opts"
2396 esac
2397 N=$((N+1))
2400 NAME=SYSTEMPIPES
2401 case "$TESTS" in
2402 *%$N%*|*%functions%*|*%pipes%*|*%$NAME%*)
2403 TEST="$NAME: simple echo via system() of cat with pipes"
2404 testecho "$N" "$TEST" "" "system:$CAT,pipes" "$opts"
2405 esac
2406 N=$((N+1))
2409 NAME=EXECPTY
2410 case "$TESTS" in
2411 *%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
2412 TEST="$NAME: simple echo via exec of cat with pseudo terminal"
2413 if ! eval $NUMCOND; then :;
2414 elif ! testaddrs pty >/dev/null; then
2415 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2416 numCANT=$((numCANT+1))
2417 else
2418 testecho "$N" "$TEST" "" "exec:$CAT,pty,$PTYOPTS" "$opts"
2420 esac
2421 N=$((N+1))
2424 NAME=SYSTEMPTY
2425 case "$TESTS" in
2426 *%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
2427 TEST="$NAME: simple echo via system() of cat with pseudo terminal"
2428 if ! eval $NUMCOND; then :;
2429 elif ! testaddrs pty >/dev/null; then
2430 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2431 numCANT=$((numCANT+1))
2432 else
2433 testecho "$N" "$TEST" "" "system:$CAT,pty,$PTYOPTS" "$opts"
2435 esac
2436 N=$((N+1))
2439 NAME=SYSTEMPIPESFDS
2440 case "$TESTS" in
2441 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2442 TEST="$NAME: simple echo via system() of cat with pipes, non stdio"
2443 testecho "$N" "$TEST" "" "system:$CAT>&9 <&8,pipes,fdin=8,fdout=9" "$opts"
2444 esac
2445 N=$((N+1))
2448 NAME=DUALSYSTEMFDS
2449 case "$TESTS" in
2450 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2451 TEST="$NAME: echo via dual system() of cat"
2452 testecho "$N" "$TEST" "system:$CAT>&6,fdout=6!!system:$CAT<&7,fdin=7" "" "$opts" "$val_t"
2453 esac
2454 N=$((N+1))
2457 # test: send EOF to exec'ed sub process, let it finish its operation, and
2458 # check if the sub process returns its data before terminating.
2459 NAME=EXECSOCKETFLUSH
2460 # idea: have socat exec'ing od; send data and EOF, and check if the od'ed data
2461 # arrives.
2462 case "$TESTS" in
2463 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2464 TEST="$NAME: call to od via exec with socketpair"
2465 testod "$N" "$TEST" "" "exec:$OD_C" "$opts"
2466 esac
2467 N=$((N+1))
2470 NAME=SYSTEMSOCKETFLUSH
2471 case "$TESTS" in
2472 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2473 TEST="$NAME: call to od via system() with socketpair"
2474 testod "$N" "$TEST" "" "system:$OD_C" "$opts" $val_t
2475 esac
2476 N=$((N+1))
2479 NAME=EXECPIPESFLUSH
2480 case "$TESTS" in
2481 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
2482 TEST="$NAME: call to od via exec with pipes"
2483 testod "$N" "$TEST" "" "exec:$OD_C,pipes" "$opts"
2484 esac
2485 N=$((N+1))
2488 NAME=SYSTEMPIPESFLUSH
2489 case "$TESTS" in
2490 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2491 TEST="$NAME: call to od via system() with pipes"
2492 testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" "$val_t"
2493 esac
2494 N=$((N+1))
2497 ## LATER:
2498 #NAME=EXECPTYFLUSH
2499 #case "$TESTS" in
2500 #*%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
2501 #TEST="$NAME: call to od via exec with pseudo terminal"
2502 #if ! testaddrs pty >/dev/null; then
2503 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2504 # numCANT=$((numCANT+1))
2505 #else
2506 #testod "$N" "$TEST" "" "exec:$OD_C,pty,$PTYOPTS" "$opts"
2508 #esac
2509 #N=$((N+1))
2512 ## LATER:
2513 #NAME=SYSTEMPTYFLUSH
2514 #case "$TESTS" in
2515 #*%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
2516 #TEST="$NAME: call to od via system() with pseudo terminal"
2517 #if ! testaddrs pty >/dev/null; then
2518 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2519 # numCANT=$((numCANT+1))
2520 #else
2521 #testod "$N" "$TEST" "" "system:$OD_C,pty,$PTYOPTS" "$opts"
2523 #esac
2524 #N=$((N+1))
2527 NAME=SYSTEMPIPESFDSFLUSH
2528 case "$TESTS" in
2529 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2530 TEST="$NAME: call to od via system() with pipes, non stdio"
2531 testod "$N" "$TEST" "" "system:$OD_C>&9 <&8,pipes,fdin=8,fdout=9" "$opts" "$val_t"
2532 esac
2533 N=$((N+1))
2536 NAME=DUALSYSTEMFDSFLUSH
2537 case "$TESTS" in
2538 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
2539 TEST="$NAME: call to od via dual system()"
2540 testod "$N" "$TEST" "system:$OD_C>&6,fdout=6!!system:$CAT<&7,fdin=7" "pipe" "$opts" "$val_t"
2541 esac
2542 N=$((N+1))
2545 case "$UNAME" in
2546 Linux) IPPROTO=254 ;;
2547 Darwin) IPPROTO=255 ;;
2548 *) IPPROTO=254 ;; # just a guess
2549 esac
2551 NAME=RAWIP4SELF
2552 case "$TESTS" in
2553 *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
2554 TEST="$NAME: simple echo via self receiving raw IPv4 protocol"
2555 if ! eval $NUMCOND; then :;
2556 elif ! feat=$(testaddrs ip4) || ! runsip4 >/dev/null; then
2557 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2558 numCANT=$((numCANT+1))
2559 elif ! feat=$(testaddrs rawip) >/dev/null; then
2560 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2561 numCANT=$((numCANT+1))
2562 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2563 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2564 numCANT=$((numCANT+1))
2565 else
2566 testecho "$N" "$TEST" "" "ip4:127.0.0.1:$IPPROTO" "$opts"
2568 esac
2569 N=$((N+1))
2571 NAME=RAWIPX4SELF
2572 case "$TESTS" in
2573 *%$N%*|*%functions%*|*%ip4%*|*%rawip%*|*%root%*|*%$NAME%*)
2574 TEST="$NAME: simple echo via self receiving raw IP protocol, v4 by target"
2575 if ! eval $NUMCOND; then :;
2576 elif ! feat=$(testaddrs ip4) || ! runsip4 >/dev/null; then
2577 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2578 numCANT=$((numCANT+1))
2579 elif ! feat=$(testaddrs rawip) >/dev/null; then
2580 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2581 numCANT=$((numCANT+1))
2582 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2583 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2584 numCANT=$((numCANT+1))
2585 else
2586 testecho "$N" "$TEST" "" "ip:127.0.0.1:$IPPROTO" "$opts"
2587 fi ;; # NUMCOND, feats
2588 esac
2589 N=$((N+1))
2591 NAME=RAWIP6SELF
2592 case "$TESTS" in
2593 *%$N%*|*%functions%*|*%ip6%*|*%rawip%*|*%root%*|*%$NAME%*)
2594 TEST="$NAME: simple echo via self receiving raw IPv6 protocol"
2595 if ! eval $NUMCOND; then :;
2596 elif ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null; then
2597 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2598 numCANT=$((numCANT+1))
2599 elif ! feat=$(testaddrs rawip) || ! runsip6 >/dev/null; then
2600 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2601 numCANT=$((numCANT+1))
2602 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2603 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2604 numCANT=$((numCANT+1))
2605 else
2606 testecho "$N" "$TEST" "" "ip6:[::1]:$IPPROTO" "$opts"
2607 fi ;; # NUMCOND, feats
2608 esac
2609 N=$((N+1))
2611 NAME=RAWIPX6SELF
2612 case "$TESTS" in
2613 *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%root%*|*%$NAME%*)
2614 TEST="$NAME: simple echo via self receiving raw IP protocol, v6 by target"
2615 if ! eval $NUMCOND; then :;
2616 elif ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null; then
2617 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2618 numCANT=$((numCANT+1))
2619 elif ! feat=$(testaddrs rawip) || ! runsip6 >/dev/null; then
2620 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2621 numCANT=$((numCANT+1))
2622 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
2623 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2624 numCANT=$((numCANT+1))
2625 else
2626 testecho "$N" "$TEST" "" "ip:[::1]:$IPPROTO" "$opts"
2628 esac
2629 N=$((N+1))
2632 NAME=TCPSELF
2633 case "$TESTS" in
2634 *%$N%*|*%functions%*|*%$NAME%*)
2635 TEST="$NAME: echo via self connection of TCP IPv4 socket"
2636 if ! eval $NUMCOND; then :;
2637 elif [ "$UNAME" != Linux ]; then
2638 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2639 numCANT=$((numCANT+1))
2640 else
2641 #ts="127.0.0.1:$tsl"
2642 testecho "$N" "$TEST" "" "tcp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR,reuseaddr" "$opts"
2644 esac
2645 PORT=$((PORT+1))
2646 N=$((N+1))
2649 NAME=UDPSELF
2650 if ! eval $NUMCOND; then :; else
2651 case "$TESTS" in
2652 *%$N%*|*%functions%*|*%$NAME%*)
2653 TEST="$NAME: echo via self connection of UDP IPv4 socket"
2654 if [ "$UNAME" != Linux ]; then
2655 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2656 numCANT=$((numCANT+1))
2657 else
2658 testecho "$N" "$TEST" "" "udp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR" "$opts"
2660 esac
2661 fi # NUMCOND
2662 PORT=$((PORT+1))
2663 N=$((N+1))
2666 NAME=UDP6SELF
2667 case "$TESTS" in
2668 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%$NAME%*)
2669 TEST="$NAME: echo via self connection of UDP IPv6 socket"
2670 if ! eval $NUMCOND; then :;
2671 elif [ "$UNAME" != Linux ]; then
2672 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
2673 numCANT=$((numCANT+1))
2674 elif ! testaddrs udp ip6 >/dev/null || ! runsip6 >/dev/null; then
2675 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
2676 numCANT=$((numCANT+1))
2677 else
2678 tf="$td/file$N"
2679 testecho "$N" "$TEST" "" "udp6:[::1]:$PORT,sp=$PORT,bind=[::1]" "$opts"
2681 esac
2682 PORT=$((PORT+1))
2683 N=$((N+1))
2686 NAME=DUALUDPSELF
2687 if ! eval $NUMCOND; then :; else
2688 case "$TESTS" in
2689 *%$N%*|*%functions%*|*%$NAME%*)
2690 TEST="$NAME: echo via two unidirectional UDP IPv4 sockets"
2691 tf="$td/file$N"
2692 p1=$PORT
2693 p2=$((PORT+1))
2694 testecho "$N" "$TEST" "" "udp:127.0.0.1:$p2,sp=$p1!!udp:127.0.0.1:$p1,sp=$p2" "$opts"
2695 esac
2696 fi # NUMCOND
2697 PORT=$((PORT+2))
2698 N=$((N+1))
2701 #function testdual {
2702 # local
2706 NAME=UNIXSTREAM
2707 if ! eval $NUMCOND; then :; else
2708 case "$TESTS" in
2709 *%$N%*|*%functions%*|*%unix%*|*%$NAME%*)
2710 TEST="$NAME: echo via connection to UNIX domain socket"
2711 tf="$td/test$N.stdout"
2712 te="$td/test$N.stderr"
2713 ts="$td/test$N.socket"
2714 tdiff="$td/test$N.diff"
2715 da="test$N $(date) $RANDOM"
2716 CMD1="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
2717 CMD2="$TRACE $SOCAT $opts -!!- UNIX-CONNECT:$ts"
2718 printf "test $F_n $TEST... " $N
2719 $CMD1 </dev/null >$tf 2>"${te}1" &
2720 bg=$! # background process id
2721 waitfile "$ts"
2722 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2723 if [ $? -ne 0 ]; then
2724 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2725 echo "$CMD1 &"
2726 echo "$CMD2"
2727 cat "$te"
2728 numFAIL=$((numFAIL+1))
2729 listFAIL="$listFAIL $N"
2730 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2731 $PRINTF "$FAILED: diff:\n"
2732 cat "$tdiff"
2733 numFAIL=$((numFAIL+1))
2734 listFAIL="$listFAIL $N"
2735 else
2736 $PRINTF "$OK\n"
2737 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2738 numOK=$((numOK+1))
2740 kill $bg 2>/dev/null
2741 esac
2742 fi # NUMCOND
2743 N=$((N+1))
2746 NAME=TCP4
2747 if ! eval $NUMCOND; then :; else
2748 case "$TESTS" in
2749 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2750 TEST="$NAME: echo via connection to TCP V4 socket"
2751 tf="$td/test$N.stdout"
2752 te="$td/test$N.stderr"
2753 tdiff="$td/test$N.diff"
2754 tsl=$PORT
2755 ts="127.0.0.1:$tsl"
2756 da="test$N $(date) $RANDOM"
2757 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr PIPE"
2758 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
2759 printf "test $F_n $TEST... " $N
2760 $CMD1 >"$tf" 2>"${te}1" &
2761 pid1=$!
2762 waittcp4port $tsl 1
2763 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2764 if [ $? -ne 0 ]; then
2765 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2766 echo "$CMD1 &"
2767 cat "${te}1"
2768 echo "$CMD2"
2769 cat "${te}2"
2770 numFAIL=$((numFAIL+1))
2771 listFAIL="$listFAIL $N"
2772 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2773 $PRINTF "$FAILED\n"
2774 cat "$tdiff"
2775 numFAIL=$((numFAIL+1))
2776 listFAIL="$listFAIL $N"
2777 else
2778 $PRINTF "$OK\n"
2779 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2780 numOK=$((numOK+1))
2782 kill $pid1 2>/dev/null
2783 wait ;;
2784 esac
2785 PORT=$((PORT+1))
2786 fi # NUMCOND
2787 N=$((N+1))
2790 #et -xv
2791 NAME=TCP6
2792 case "$TESTS" in
2793 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2794 TEST="$NAME: echo via connection to TCP V6 socket"
2795 if ! eval $NUMCOND; then :;
2796 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
2797 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
2798 numCANT=$((numCANT+1))
2799 else
2800 tf="$td/test$N.stdout"
2801 te="$td/test$N.stderr"
2802 tdiff="$td/test$N.diff"
2803 tsl=$PORT
2804 ts="[::1]:$tsl"
2805 da="test$N $(date) $RANDOM"
2806 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,reuseaddr PIPE"
2807 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
2808 printf "test $F_n $TEST... " $N
2809 $CMD1 >"$tf" 2>"${te}1" &
2810 pid=$! # background process id
2811 waittcp6port $tsl 1
2812 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2813 if [ $? -ne 0 ]; then
2814 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2815 echo "$CMD1 &"
2816 echo "$CMD2"
2817 cat "$te"
2818 numFAIL=$((numFAIL+1))
2819 listFAIL="$listFAIL $N"
2820 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2821 $PRINTF "$FAILED: diff:\n"
2822 cat "$tdiff"
2823 numFAIL=$((numFAIL+1))
2824 listFAIL="$listFAIL $N"
2825 else
2826 $PRINTF "$OK\n"
2827 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2828 numOK=$((numOK+1))
2830 kill $pid 2>/dev/null
2832 esac
2833 PORT=$((PORT+1))
2834 N=$((N+1))
2835 #set +vx
2838 NAME=TCPX4
2839 case "$TESTS" in
2840 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2841 TEST="$NAME: echo via connection to TCP socket, v4 by target"
2842 if ! eval $NUMCOND; then :;
2843 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2844 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2845 numCANT=$((numCANT+1))
2846 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
2847 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2848 numCANT=$((numCANT+1))
2849 else
2850 tf="$td/test$N.stdout"
2851 te="$td/test$N.stderr"
2852 tdiff="$td/test$N.diff"
2853 tsl=$PORT
2854 ts="127.0.0.1:$tsl"
2855 da="test$N $(date) $RANDOM"
2856 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip4,reuseaddr PIPE"
2857 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
2858 printf "test $F_n $TEST... " $N
2859 $CMD1 >"$tf" 2>"${te}1" &
2860 pid=$! # background process id
2861 waittcp4port $tsl 1
2862 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2863 if [ $? -ne 0 ]; then
2864 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2865 echo "$CMD1 &"
2866 echo "$CMD2"
2867 cat "$te"
2868 numFAIL=$((numFAIL+1))
2869 listFAIL="$listFAIL $N"
2870 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2871 $PRINTF "$FAILED: diff:\n"
2872 cat "$tdiff"
2873 numFAIL=$((numFAIL+1))
2874 listFAIL="$listFAIL $N"
2875 else
2876 $PRINTF "$OK\n"
2877 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2878 numOK=$((numOK+1))
2880 kill $pid 2>/dev/null
2882 esac
2883 PORT=$((PORT+1))
2884 N=$((N+1))
2887 NAME=TCPX6
2888 case "$TESTS" in
2889 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2890 TEST="$NAME: echo via connection to TCP socket, v6 by target"
2891 if ! eval $NUMCOND; then :;
2892 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2893 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2894 numCANT=$((numCANT+1))
2895 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
2896 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2897 numCANT=$((numCANT+1))
2898 else
2899 tf="$td/test$N.stdout"
2900 te="$td/test$N.stderr"
2901 tdiff="$td/test$N.diff"
2902 tsl=$PORT
2903 ts="[::1]:$tsl"
2904 da="test$N $(date) $RANDOM"
2905 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip6,reuseaddr PIPE"
2906 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
2907 printf "test $F_n $TEST... " $N
2908 $CMD1 >"$tf" 2>"${te}1" &
2909 pid=$! # background process id
2910 waittcp6port $tsl 1
2911 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2912 if [ $? -ne 0 ]; then
2913 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2914 echo "$CMD1 &"
2915 echo "$CMD2"
2916 cat "$te"
2917 numFAIL=$((numFAIL+1))
2918 listFAIL="$listFAIL $N"
2919 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2920 $PRINTF "$FAILED: diff:\n"
2921 cat "$tdiff"
2922 numFAIL=$((numFAIL+1))
2923 listFAIL="$listFAIL $N"
2924 else
2925 $PRINTF "$OK\n"
2926 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2927 numOK=$((numOK+1))
2929 kill $pid 2>/dev/null
2931 esac
2932 PORT=$((PORT+1))
2933 N=$((N+1))
2935 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
2936 # ipv6-v6only=0 shows this behaviour.
2937 NAME=IPV6ONLY0
2938 case "$TESTS" in
2939 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2940 TEST="$NAME: option ipv6-v6only=0 listens on IPv4"
2941 # create a listening TCP6 socket and try to connect to the port using TCP4
2942 if ! eval $NUMCOND; then :;
2943 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2944 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2945 numCANT=$((numCANT+1))
2946 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
2947 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2948 numCANT=$((numCANT+1))
2949 elif ! feat=$(testoptions ipv6-v6only); then
2950 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
2951 numCANT=$((numCANT+1))
2952 else
2953 tf="$td/test$N.stdout"
2954 te="$td/test$N.stderr"
2955 tdiff="$td/test$N.diff"
2956 tsl=$PORT
2957 ts="127.0.0.1:$tsl"
2958 da="test$N $(date) $RANDOM"
2959 CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$tsl,ipv6-v6only=0,reuseaddr PIPE"
2960 CMD2="$TRACE $SOCAT $opts STDIN!!STDOUT TCP4:$ts"
2961 printf "test $F_n $TEST... " $N
2962 $CMD1 >"$tf" 2>"${te}1" &
2963 pid=$! # background process id
2964 waittcp6port $tsl 1
2965 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
2966 if [ $? -ne 0 ]; then
2967 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2968 echo "$CMD1 &"
2969 echo "$CMD2"
2970 cat "${te}1" "${te}2"
2971 numFAIL=$((numFAIL+1))
2972 listFAIL="$listFAIL $N"
2973 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
2974 $PRINTF "$FAILED: diff:\n"
2975 cat "$tdiff"
2976 numFAIL=$((numFAIL+1))
2977 listFAIL="$listFAIL $N"
2978 else
2979 $PRINTF "$OK\n"
2980 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2981 numOK=$((numOK+1))
2983 kill $pid 2>/dev/null
2985 esac
2986 PORT=$((PORT+1))
2987 N=$((N+1))
2989 #set -vx
2990 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
2991 # ipv6-v6only=1 turns off this behaviour.
2992 NAME=IPV6ONLY1
2993 case "$TESTS" in
2994 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
2995 TEST="$NAME: option ipv6-v6only=1 does not listen on IPv4"
2996 if ! eval $NUMCOND; then :;
2997 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
2998 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2999 numCANT=$((numCANT+1))
3000 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3001 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3002 numCANT=$((numCANT+1))
3003 elif ! feat=$(testoptions ipv6-v6only); then
3004 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3005 numCANT=$((numCANT+1))
3006 else
3007 tf="$td/test$N.stdout"
3008 te="$td/test$N.stderr"
3009 tdiff="$td/test$N.diff"
3010 tsl=$PORT
3011 ts="127.0.0.1:$tsl"
3012 da="test$N $(date) $RANDOM"
3013 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,ipv6-v6only=1,reuseaddr PIPE"
3014 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3015 printf "test $F_n $TEST... " $N
3016 $CMD1 >"$tf" 2>"${te}1" &
3017 pid=$! # background process id
3018 waittcp6port $tsl 1
3019 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3020 if [ $? -eq 0 ]; then
3021 $PRINTF "$FAILED:\n"
3022 cat "${te}1" "${te}2"
3023 numFAIL=$((numFAIL+1))
3024 listFAIL="$listFAIL $N"
3025 elif echo "$da" |diff - "$tf" >"$tdiff"; then
3026 $PRINTF "$FAILED:\n"
3027 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3028 numFAIL=$((numFAIL+1))
3029 listFAIL="$listFAIL $N"
3030 else
3031 $PRINTF "$OK\n"
3032 numOK=$((numOK+1))
3034 kill $pid; wait
3035 wait
3037 esac
3038 PORT=$((PORT+1))
3039 N=$((N+1))
3040 #set +vx
3042 NAME=ENV_LISTEN_4
3043 case "$TESTS" in
3044 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3045 TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv4 preference on listen"
3046 if ! eval $NUMCOND; then :;
3047 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3048 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3049 numCANT=$((numCANT+1))
3050 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3051 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3052 numCANT=$((numCANT+1))
3053 elif ! feat=$(testoptions ipv6-v6only); then
3054 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3055 numCANT=$((numCANT+1))
3056 else
3057 tf="$td/test$N.stdout"
3058 te="$td/test$N.stderr"
3059 tdiff="$td/test$N.diff"
3060 tsl=$PORT
3061 ts="127.0.0.1:$tsl"
3062 da="test$N $(date) $RANDOM"
3063 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,reuseaddr PIPE"
3064 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3065 printf "test $F_n $TEST... " $N
3066 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3067 pid=$! # background process id
3068 waittcp4port $tsl 1
3069 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3070 if [ $? -ne 0 ]; then
3071 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3072 echo "$CMD1 &"
3073 echo "$CMD2"
3074 cat "${te}1" "${te}2"
3075 numFAIL=$((numFAIL+1))
3076 listFAIL="$listFAIL $N"
3077 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3078 $PRINTF "$FAILED: diff:\n"
3079 cat "$tdiff"
3080 numFAIL=$((numFAIL+1))
3081 listFAIL="$listFAIL $N"
3082 else
3083 $PRINTF "$OK\n"
3084 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3085 numOK=$((numOK+1))
3087 kill $pid 2>/dev/null; wait
3089 esac
3090 PORT=$((PORT+1))
3091 N=$((N+1))
3093 NAME=ENV_LISTEN_6
3094 case "$TESTS" in
3095 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3096 TEST="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv6 preference on listen"
3097 if ! eval $NUMCOND; then :;
3098 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3099 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3100 numCANT=$((numCANT+1))
3101 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3102 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3103 numCANT=$((numCANT+1))
3104 else
3105 tf="$td/test$N.stdout"
3106 te="$td/test$N.stderr"
3107 tdiff="$td/test$N.diff"
3108 tsl=$PORT
3109 ts="[::1]:$tsl"
3110 da="test$N $(date) $RANDOM"
3111 CMD1="$TRACE $SOCAT $opts TCP-listen:$tsl,reuseaddr PIPE"
3112 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3113 printf "test $F_n $TEST... " $N
3114 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3115 pid=$! # background process id
3116 waittcp6port $tsl 1
3117 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3118 if [ $? -ne 0 ]; then
3119 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3120 echo "$CMD1 &"
3121 echo "$CMD2"
3122 cat "${te}1" "${te}2"
3123 numFAIL=$((numFAIL+1))
3124 listFAIL="$listFAIL $N"
3125 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3126 $PRINTF "$FAILED: diff:\n"
3127 cat "$tdiff"
3128 numFAIL=$((numFAIL+1))
3129 listFAIL="$listFAIL $N"
3130 else
3131 $PRINTF "$OK\n"
3132 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3133 numOK=$((numOK+1))
3135 kill $pid 2>/dev/null; wait
3137 esac
3138 PORT=$((PORT+1))
3139 N=$((N+1))
3141 NAME=LISTEN_OPTION_4
3142 case "$TESTS" in
3143 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3144 TEST="$NAME: option -4 for IPv4 preference on listen"
3145 if ! eval $NUMCOND; then :;
3146 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3147 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3148 numCANT=$((numCANT+1))
3149 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3150 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3151 numCANT=$((numCANT+1))
3152 elif ! feat=$(testoptions ipv6-v6only); then
3153 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3154 numCANT=$((numCANT+1))
3155 else
3156 tf="$td/test$N.stdout"
3157 te="$td/test$N.stderr"
3158 tdiff="$td/test$N.diff"
3159 tsl=$PORT
3160 ts="127.0.0.1:$tsl"
3161 da="test$N $(date) $RANDOM"
3162 CMD1="$TRACE $SOCAT $opts -4 TCP-listen:$tsl,reuseaddr PIPE"
3163 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3164 printf "test $F_n $TEST... " $N
3165 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3166 pid=$! # background process id
3167 waittcp4port $tsl 1
3168 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3169 if [ $? -ne 0 ]; then
3170 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3171 echo "$CMD1 &"
3172 echo "$CMD2"
3173 cat "${te}1" "${te}2"
3174 numFAIL=$((numFAIL+1))
3175 listFAIL="$listFAIL $N"
3176 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3177 $PRINTF "$FAILED: diff:\n"
3178 cat "$tdiff"
3179 numFAIL=$((numFAIL+1))
3180 listFAIL="$listFAIL $N"
3181 else
3182 $PRINTF "$OK\n"
3183 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3184 numOK=$((numOK+1))
3186 kill $pid 2>/dev/null; wait
3188 esac
3189 PORT=$((PORT+1))
3190 N=$((N+1))
3192 NAME=LISTEN_OPTION_6
3193 case "$TESTS" in
3194 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3195 TEST="$NAME: option -6 for IPv6 preference on listen"
3196 if ! eval $NUMCOND; then :;
3197 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3198 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3199 numCANT=$((numCANT+1))
3200 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3201 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3202 numCANT=$((numCANT+1))
3203 else
3204 tf="$td/test$N.stdout"
3205 te="$td/test$N.stderr"
3206 tdiff="$td/test$N.diff"
3207 tsl=$PORT
3208 ts="[::1]:$tsl"
3209 da="test$N $(date) $RANDOM"
3210 CMD1="$TRACE $SOCAT $opts -6 TCP-listen:$tsl,reuseaddr PIPE"
3211 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3212 printf "test $F_n $TEST... " $N
3213 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3214 pid=$! # background process id
3215 waittcp6port $tsl 1
3216 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3217 if [ $? -ne 0 ]; then
3218 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3219 echo "$CMD1 &"
3220 echo "$CMD2"
3221 cat "${te}1" "${te}2"
3222 numFAIL=$((numFAIL+1))
3223 listFAIL="$listFAIL $N"
3224 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3225 $PRINTF "$FAILED: diff:\n"
3226 cat "$tdiff"
3227 numFAIL=$((numFAIL+1))
3228 listFAIL="$listFAIL $N"
3229 else
3230 $PRINTF "$OK\n"
3231 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3232 numOK=$((numOK+1))
3234 kill $pid 2>/dev/null; wait
3235 wait
3236 fi # feats
3237 esac
3238 PORT=$((PORT+1))
3239 N=$((N+1))
3241 NAME=LISTEN_PF_IP4
3242 case "$TESTS" in
3243 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3244 TEST="$NAME: pf=4 overrides option -6 on listen"
3245 if ! eval $NUMCOND; then :;
3246 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3247 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3248 numCANT=$((numCANT+1))
3249 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3250 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3251 numCANT=$((numCANT+1))
3252 elif ! feat=$(testoptions ipv6-v6only); then
3253 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3254 numCANT=$((numCANT+1))
3255 else
3256 tf="$td/test$N.stdout"
3257 te="$td/test$N.stderr"
3258 tdiff="$td/test$N.diff"
3259 tsl=$PORT
3260 ts="127.0.0.1:$tsl"
3261 da="test$N $(date) $RANDOM"
3262 CMD1="$TRACE $SOCAT $opts -6 TCP-listen:$tsl,pf=ip4,reuseaddr PIPE"
3263 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3264 printf "test $F_n $TEST... " $N
3265 SOCAT_DEFAULT_LISTEN_IP=6 $CMD1 >"$tf" 2>"${te}1" &
3266 pid=$! # background process id
3267 waittcp4port $tsl 1
3268 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3269 if [ $? -ne 0 ]; then
3270 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3271 echo "$CMD1 &"
3272 echo "$CMD2"
3273 cat "${te}1" "${te}2"
3274 numFAIL=$((numFAIL+1))
3275 listFAIL="$listFAIL $N"
3276 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3277 $PRINTF "$FAILED: diff:\n"
3278 cat "$tdiff"
3279 numFAIL=$((numFAIL+1))
3280 listFAIL="$listFAIL $N"
3281 else
3282 $PRINTF "$OK\n"
3283 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3284 numOK=$((numOK+1))
3286 kill $pid 2>/dev/null; wait
3288 esac
3289 PORT=$((PORT+1))
3290 N=$((N+1))
3292 NAME=LISTEN_PF_IP6
3293 case "$TESTS" in
3294 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
3295 TEST="$NAME: pf=6 overrides option -4 on listen"
3296 if ! eval $NUMCOND; then :;
3297 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3298 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3299 numCANT=$((numCANT+1))
3300 elif ! testaddrs ip6 >/dev/null || ! runsip6 >/dev/null; then
3301 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3302 numCANT=$((numCANT+1))
3303 else
3304 tf="$td/test$N.stdout"
3305 te="$td/test$N.stderr"
3306 tdiff="$td/test$N.diff"
3307 tsl=$PORT
3308 ts="[::1]:$tsl"
3309 da="test$N $(date) $RANDOM"
3310 CMD1="$TRACE $SOCAT $opts -4 TCP-listen:$tsl,pf=ip6,reuseaddr PIPE"
3311 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3312 printf "test $F_n $TEST... " $N
3313 SOCAT_DEFAULT_LISTEN_IP=4 $CMD1 >"$tf" 2>"${te}1" &
3314 pid=$! # background process id
3315 waittcp6port $tsl 1
3316 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3317 if [ $? -ne 0 ]; then
3318 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3319 echo "$CMD1 &"
3320 echo "$CMD2"
3321 cat "${te}1" "${te}2"
3322 numFAIL=$((numFAIL+1))
3323 listFAIL="$listFAIL $N"
3324 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3325 $PRINTF "$FAILED: diff:\n"
3326 cat "$tdiff"
3327 numFAIL=$((numFAIL+1))
3328 listFAIL="$listFAIL $N"
3329 else
3330 $PRINTF "$OK\n"
3331 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3332 numOK=$((numOK+1))
3334 kill $pid 2>/dev/null; wait
3335 fi ;; # NUMCOND, feats
3336 esac
3337 PORT=$((PORT+1))
3338 N=$((N+1))
3341 NAME=UDP4STREAM
3342 case "$TESTS" in
3343 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%$NAME%*)
3344 TEST="$NAME: echo via connection to UDP V4 socket"
3345 if ! eval $NUMCOND; then :; else
3346 tf="$td/test$N.stdout"
3347 te="$td/test$N.stderr"
3348 tdiff="$td/test$N.diff"
3349 tsl=$PORT
3350 ts="$LOCALHOST:$tsl"
3351 da="test$N $(date) $RANDOM"
3352 CMD1="$TRACE $SOCAT $opts UDP4-LISTEN:$tsl,reuseaddr PIPE"
3353 CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
3354 printf "test $F_n $TEST... " $N
3355 $CMD1 >"$tf" 2>"${te}1" &
3356 pid1=$!
3357 waitudp4port $tsl 1
3358 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3359 rc2=$?
3360 kill $pid1 2>/dev/null; wait
3361 if [ $rc2 -ne 0 ]; then
3362 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3363 echo "$CMD1 &"
3364 echo "$CMD2"
3365 cat "${te}1" "${te}2"
3366 numFAIL=$((numFAIL+1))
3367 listFAIL="$listFAIL $N"
3368 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3369 $PRINTF "$FAILED\n"
3370 echo "$CMD1 &"
3371 cat "${te}1"
3372 echo "$CMD2"
3373 cat "${te}2"
3374 cat "$tdiff"
3375 numFAIL=$((numFAIL+1))
3376 listFAIL="$listFAIL $N"
3377 else
3378 $PRINTF "$OK\n"
3379 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3380 numOK=$((numOK+1))
3382 fi ;; # NUMCOND
3383 esac
3384 PORT=$((PORT+1))
3385 N=$((N+1))
3388 NAME=UDP6STREAM
3389 case "$TESTS" in
3390 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%udp%*|*%$NAME%*)
3391 TEST="$NAME: echo via connection to UDP V6 socket"
3392 if ! eval $NUMCOND; then :;
3393 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
3394 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
3395 numCANT=$((numCANT+1))
3396 else
3397 tf="$td/test$N.stdout"
3398 te="$td/test$N.stderr"
3399 tdiff="$td/test$N.diff"
3400 tsl=$PORT
3401 ts="$LOCALHOST6:$tsl"
3402 da="test$N $(date) $RANDOM"
3403 CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,reuseaddr PIPE"
3404 CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
3405 printf "test $F_n $TEST... " $N
3406 $CMD1 >"$tf" 2>"${te}1" &
3407 pid1=$!
3408 waitudp6port $tsl 1
3409 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
3410 rc2=$?
3411 kill $pid1 2>/dev/null; wait
3412 if [ $rc2 -ne 0 ]; then
3413 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3414 echo "$CMD1 &"
3415 echo "$CMD2"
3416 cat "${te}1" "${te}2"
3417 numFAIL=$((numFAIL+1))
3418 listFAIL="$listFAIL $N"
3419 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
3420 $PRINTF "$FAILED\n"
3421 cat "$tdiff"
3422 numFAIL=$((numFAIL+1))
3423 listFAIL="$listFAIL $N"
3424 else
3425 $PRINTF "$OK\n"
3426 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3427 numOK=$((numOK+1))
3429 fi ;; # ! testaddrs
3430 esac
3431 PORT=$((PORT+1))
3432 N=$((N+1))
3435 NAME=GOPENFILE
3436 case "$TESTS" in
3437 *%$N%*|*%functions%*|*%engine%*|*%gopen%*|*%file%*|*%ignoreeof%*|*%$NAME%*)
3438 TEST="$NAME: file opening with gopen"
3439 if ! eval $NUMCOND; then :; else
3440 tf1="$td/test$N.1.stdout"
3441 tf2="$td/test$N.2.stdout"
3442 te="$td/test$N.stderr"
3443 tdiff="$td/test$N.diff"
3444 da="test$N $(date) $RANDOM"
3445 echo "$da" >$tf1
3446 CMD="$TRACE $SOCAT $opts $tf1!!/dev/null /dev/null,ignoreeof!!-"
3447 printf "test $F_n $TEST... " $N
3448 $CMD >"$tf2" 2>"$te"
3449 if [ $? -ne 0 ]; then
3450 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3451 echo "$CMD"
3452 cat "$te"
3453 numFAIL=$((numFAIL+1))
3454 listFAIL="$listFAIL $N"
3455 elif ! diff "$tf1" "$tf2" >"$tdiff"; then
3456 $PRINTF "$FAILED: diff:\n"
3457 cat "$tdiff"
3458 numFAIL=$((numFAIL+1))
3459 listFAIL="$listFAIL $N"
3460 else
3461 $PRINTF "$OK\n"
3462 if [ -n "$debug" ]; then cat $te; fi
3463 numOK=$((numOK+1))
3465 fi # NUMCOND
3466 esac
3467 N=$((N+1))
3470 NAME=GOPENPIPE
3471 case "$TESTS" in
3472 *%$N%*|*%functions%*|*%gopen%*|*%pipe%*|*%ignoreeof%*|*%$NAME%*)
3473 TEST="$NAME: pipe opening with gopen for reading"
3474 if ! eval $NUMCOND; then :; else
3475 tp="$td/pipe$N"
3476 tf="$td/test$N.stdout"
3477 te="$td/test$N.stderr"
3478 tdiff="$td/test$N.diff"
3479 da="test$N $(date) $RANDOM"
3480 CMD="$TRACE $SOCAT $opts $tp!!/dev/null /dev/null,ignoreeof!!$tf"
3481 printf "test $F_n $TEST... " $N
3482 #mknod $tp p # no mknod p on FreeBSD
3483 mkfifo $tp
3484 $CMD >$tf 2>"$te" &
3485 #($CMD >$tf 2>"$te" || rm -f "$tp") 2>/dev/null &
3486 bg=$! # background process id
3487 usleep $MICROS
3488 if [ ! -p "$tp" ]; then
3489 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3490 echo "$CMD"
3491 cat "$te"
3492 numFAIL=$((numFAIL+1))
3493 listFAIL="$listFAIL $N"
3494 else
3495 #echo "$da" >"$tp" # might hang forever
3496 echo "$da" >"$tp" & export pid=$!; (sleep 1; kill $pid 2>/dev/null) &
3497 # Solaris needs more time:
3498 sleep 1
3499 kill "$bg" 2>/dev/null; wait
3500 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3501 if [ -s "$te" ]; then
3502 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3503 echo "$CMD"
3504 cat "$te"
3505 else
3506 $PRINTF "$FAILED: diff:\n"
3507 cat "$tdiff"
3509 numFAIL=$((numFAIL+1))
3510 listFAIL="$listFAIL $N"
3511 else
3512 $PRINTF "$OK\n"
3513 if [ -n "$debug" ]; then cat $te; fi
3514 numOK=$((numOK+1))
3517 wait
3518 fi # NUMCOND
3519 esac
3520 N=$((N+1))
3523 NAME=GOPENUNIXSTREAM
3524 case "$TESTS" in
3525 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%listen%*|*%$NAME%*)
3526 TEST="$NAME: GOPEN on UNIX stream socket"
3527 if ! eval $NUMCOND; then :; else
3528 ts="$td/test$N.socket"
3529 tf="$td/test$N.stdout"
3530 te="$td/test$N.stderr"
3531 tdiff="$td/test$N.diff"
3532 da1="test$N $(date) $RANDOM"
3533 #establish a listening unix socket in background
3534 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
3535 #make a connection
3536 CMD="$TRACE $SOCAT $opts - $ts"
3537 $PRINTF "test $F_n $TEST... " $N
3538 eval "$SRV 2>${te}s &"
3539 pids=$!
3540 waitfile "$ts"
3541 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
3542 if [ $? -ne 0 ]; then
3543 kill "$pids" 2>/dev/null
3544 $PRINTF "$FAILED:\n"
3545 echo "$SRV &"
3546 cat "${te}s"
3547 echo "$CMD"
3548 cat "${te}1"
3549 numFAIL=$((numFAIL+1))
3550 listFAIL="$listFAIL $N"
3551 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
3552 kill "$pids" 2>/dev/null
3553 $PRINTF "$FAILED:\n"
3554 echo "$SRV &"
3555 cat "${te}s"
3556 echo "$CMD"
3557 cat "${te}1"
3558 cat "$tdiff"
3559 numFAIL=$((numFAIL+1))
3560 listFAIL="$listFAIL $N"
3561 else
3562 $PRINTF "$OK\n"
3563 if [ -n "$debug" ]; then cat $te; fi
3564 numOK=$((numOK+1))
3565 fi # !(rc -ne 0)
3566 wait
3567 fi # NUMCOND
3568 esac
3569 N=$((N+1))
3572 NAME=GOPENUNIXDGRAM
3573 case "$TESTS" in
3574 *%$N%*|*%functions%*|*%gopen%*|*%unix%*|*%dgram%*|*%$NAME%*)
3575 TEST="$NAME: GOPEN on UNIX datagram socket"
3576 if ! eval $NUMCOND; then :; else
3577 ts="$td/test$N.socket"
3578 tf="$td/test$N.stdout"
3579 te="$td/test$N.stderr"
3580 tdiff="$td/test$N.diff"
3581 da1="test$N $(date) $RANDOM"
3582 #establish a receiving unix socket in background
3583 SRV="$TRACE $SOCAT $opts -u -lpserver UNIX-RECV:\"$ts\" file:\"$tf\",create"
3584 #make a connection
3585 CMD="$TRACE $SOCAT $opts -u - $ts"
3586 $PRINTF "test $F_n $TEST... " $N
3587 eval "$SRV 2>${te}s &"
3588 pids=$!
3589 waitfile "$ts"
3590 echo "$da1" |eval "$CMD" 2>"${te}1"
3591 waitfile -s "$tf"
3592 if [ $? -ne 0 ]; then
3593 $PRINTF "$FAILED:\n"
3594 echo "$SRV &"
3595 cat "${te}s"
3596 echo "$CMD"
3597 cat "${te}1"
3598 numFAIL=$((numFAIL+1))
3599 listFAIL="$listFAIL $N"
3600 elif ! echo "$da1" |diff - "${tf}" >"$tdiff"; then
3601 $PRINTF "$FAILED:\n"
3602 echo "$SRV &"
3603 cat "${te}s"
3604 echo "$CMD"
3605 cat "${te}1"
3606 cat "$tdiff"
3607 numFAIL=$((numFAIL+1))
3608 listFAIL="$listFAIL $N"
3609 else
3610 $PRINTF "$OK\n"
3611 if [ -n "$debug" ]; then cat $te; fi
3612 numOK=$((numOK+1))
3613 fi # !(rc -ne 0)
3614 kill "$pids" 2>/dev/null; wait
3615 fi ;; # NUMCOND
3616 esac
3617 N=$((N+1))
3620 NAME=IGNOREEOF
3621 case "$TESTS" in
3622 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3623 TEST="$NAME: ignoreeof on file"
3624 if ! eval $NUMCOND; then :; else
3625 ti="$td/test$N.file"
3626 tf="$td/test$N.stdout"
3627 te="$td/test$N.stderr"
3628 tdiff="$td/test$N.diff"
3629 da="test$N $(date) $RANDOM"
3630 CMD="$TRACE $SOCAT $opts -u file:\"$ti\",ignoreeof -"
3631 printf "test $F_n $TEST... " $N
3632 touch "$ti"
3633 $CMD >"$tf" 2>"$te" &
3634 bg=$!
3635 usleep 500000
3636 echo "$da" >>"$ti"
3637 sleep 1
3638 kill $bg 2>/dev/null; wait
3639 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3640 $PRINTF "$FAILED: diff:\n"
3641 cat "$tdiff"
3642 listFAIL="$listFAIL $N"
3643 numFAIL=$((numFAIL+1))
3644 else
3645 $PRINTF "$OK\n"
3646 if [ -n "$debug" ]; then cat $te; fi
3647 numOK=$((numOK+1))
3649 fi ;; # NUMCOND
3650 esac
3651 N=$((N+1))
3653 NAME=IGNOREEOF_REV
3654 case "$TESTS" in
3655 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3656 TEST="$NAME: ignoreeof on file right-to-left"
3657 if ! eval $NUMCOND; then :; else
3658 ti="$td/test$N.file"
3659 tf="$td/test$N.stdout"
3660 te="$td/test$N.stderr"
3661 tdiff="$td/test$N.diff"
3662 da="test$N $(date) $RANDOM"
3663 CMD="$SOCAT $opts -U - file:\"$ti\",ignoreeof"
3664 printf "test $F_n $TEST... " $N
3665 touch "$ti"
3666 $CMD >"$tf" 2>"$te" &
3667 bg=$!
3668 usleep 500000
3669 echo "$da" >>"$ti"
3670 sleep 1
3671 kill $bg 2>/dev/null
3672 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3673 $PRINTF "$FAILED: diff:\n"
3674 cat "$tdiff"
3675 listFAIL="$listFAIL $N"
3676 numFAIL=$((numFAIL+1))
3677 else
3678 $PRINTF "$OK\n"
3679 if [ -n "$debug" ]; then cat $te; fi
3680 numOK=$((numOK+1))
3682 wait
3683 fi ;; # NUMCOND
3684 esac
3685 N=$((N+1))
3688 NAME=EXECIGNOREEOF
3689 case "$TESTS" in
3690 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
3691 TEST="$NAME: exec against address with ignoreeof"
3692 if ! eval $NUMCOND; then :; else
3693 tf="$td/test$N.stdout"
3694 te="$td/test$N.stderr"
3695 CMD="$TRACE $SOCAT $opts -lf /dev/null EXEC:$TRUE /dev/null,ignoreeof"
3696 printf "test $F_n $TEST... " $N
3697 $CMD >"$tf" 2>"$te"
3698 if [ -s "$te" ]; then
3699 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3700 echo "$CMD"
3701 cat "$te"
3702 numFAIL=$((numFAIL+1))
3703 listFAIL="$listFAIL $N"
3704 else
3705 $PRINTF "$OK\n"
3706 if [ -n "$debug" ]; then cat $te; fi
3707 numOK=$((numOK+1))
3709 fi ;; # NUMCOND
3710 esac
3711 N=$((N+1))
3714 NAME=FAKEPTY
3715 case "$TESTS" in
3716 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
3717 TEST="$NAME: generation of pty for other processes"
3718 if ! eval $NUMCOND; then :;
3719 elif ! testaddrs pty >/dev/null; then
3720 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
3721 numCANT=$((numCANT+1))
3722 else
3723 tt="$td/pty$N"
3724 tf="$td/test$N.stdout"
3725 te="$td/test$N.stderr"
3726 tdiff="$td/test$N.diff"
3727 da="test$N $(date) $RANDOM"
3728 CMD1="$TRACE $SOCAT $opts pty,link=$tt pipe"
3729 CMD2="$TRACE $SOCAT $opts - $tt,$PTYOPTS2"
3730 printf "test $F_n $TEST... " $N
3731 $CMD1 2>"${te}1" &
3732 pid=$! # background process id
3733 waitfile "$tt"
3734 # this hangs on HP-UX, so we use a timeout
3735 (echo "$da"; sleep 1) |$CMD2 >$tf 2>"${te}2" &
3736 rc2=$!
3737 #sleep 5 && kill $rc2 2>/dev/null &
3738 wait $rc2
3739 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3740 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3741 echo "$CMD1 &"
3742 sleep 1
3743 echo "$CMD2"
3744 cat "${te}1"
3745 cat "${te}2"
3746 cat "$tdiff"
3747 numFAIL=$((numFAIL+1))
3748 listFAIL="$listFAIL $N"
3749 else
3750 $PRINTF "$OK\n"
3751 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3752 numOK=$((numOK+1))
3754 kill $pid 2>/dev/null; wait
3755 fi ;; # NUMCOND, feats
3756 esac
3757 N=$((N+1))
3760 NAME=O_TRUNC
3761 case "$TESTS" in
3762 *%$N%*|*%functions%*|*%$NAME%*)
3763 TEST="$NAME: option o-trunc"
3764 if ! eval $NUMCOND; then :; else
3765 ff="$td/test$N.file"
3766 tf="$td/test$N.stdout"
3767 te="$td/test$N.stderr"
3768 tdiff="$td/test$N.diff"
3769 da="test$N $(date) $RANDOM"
3770 CMD="$TRACE $SOCAT -u $opts - open:$ff,append,o-trunc"
3771 printf "test $F_n $TEST... " $N
3772 rm -f $ff; $ECHO "prefix-\c" >$ff
3773 echo "$da" |$CMD >$tf 2>"$te"
3774 rc0=$?
3775 if ! [ $rc0 = 0 ] ||
3776 ! echo "$da" |diff - $ff >"$tdiff"; then
3777 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3778 echo "$CMD"
3779 cat "$te"
3780 cat "$tdiff"
3781 numFAIL=$((numFAIL+1))
3782 listFAIL="$listFAIL $N"
3783 else
3784 $PRINTF "$OK\n"
3785 if [ -n "$debug" ]; then cat $te; fi
3786 numOK=$((numOK+1))
3788 fi ;; # NUMCOND
3789 esac
3790 N=$((N+1))
3793 NAME=FTRUNCATE
3794 case "$TESTS" in
3795 *%$N%*|*%functions%*|*%$NAME%*)
3796 TEST="$NAME: option ftruncate"
3797 if ! eval $NUMCOND; then :; else
3798 ff="$td/test$N.file"
3799 tf="$td/test$N.stdout"
3800 te="$td/test$N.stderr"
3801 tdiff="$td/test$N.diff"
3802 da="test$N $(date) $RANDOM"
3803 CMD="$TRACE $SOCAT -u $opts - open:$ff,append,ftruncate=0"
3804 printf "test $F_n $TEST... " $N
3805 rm -f $ff; $ECHO "prefix-\c" >$ff
3806 if ! echo "$da" |$CMD >$tf 2>"$te" ||
3807 ! echo "$da" |diff - $ff >"$tdiff"; then
3808 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3809 echo "$CMD"
3810 cat "$te"
3811 cat "$tdiff"
3812 numFAIL=$((numFAIL+1))
3813 listFAIL="$listFAIL $N"
3814 else
3815 $PRINTF "$OK\n"
3816 if [ -n "$debug" ]; then cat $te; fi
3817 numOK=$((numOK+1))
3819 fi ;; # NUMCOND
3820 esac
3821 N=$((N+1))
3824 NAME=RIGHTTOLEFT
3825 case "$TESTS" in
3826 *%$N%*|*%functions%*|*%$NAME%*)
3827 TEST="$NAME: unidirectional throughput from stdin to stdout, right to left"
3828 testecho "$N" "$TEST" "stdout" "stdin" "$opts -U"
3829 esac
3830 N=$((N+1))
3833 NAME=CHILDDEFAULT
3834 case "$TESTS" in
3835 *%$N%*|*%functions%*|*%$NAME%*)
3836 if ! eval $NUMCOND; then :; else
3837 TEST="$NAME: child process default properties"
3838 tf="$td/test$N.stdout"
3839 te="$td/test$N.stderr"
3840 CMD="$TRACE $SOCAT $opts -u exec:$PROCAN -"
3841 printf "test $F_n $TEST... " $N
3842 $CMD >$tf 2>$te
3843 MYPID=`expr "\`grep "process id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3844 MYPPID=`expr "\`grep "process parent id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3845 MYPGID=`expr "\`grep "process group id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3846 MYSID=`expr "\`grep "process session id =" $tf\`" : '[^0-9]*\([0-9]*\).*'`
3847 #echo "PID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3848 if [ "$MYPID" = "$MYPPID" -o "$MYPID" = "$MYPGID" -o "$MYPID" = "$MYSID" -o \
3849 "$MYPPID" = "$MYPGID" -o "$MYPPID" = "$MYSID" -o "$MYPGID" = "$MYSID" ];
3850 then
3851 $PRINTF "$FAILED:\n"
3852 echo "$CMD"
3853 cat "$te"
3854 numFAIL=$((numFAIL+1))
3855 listFAIL="$listFAIL $N"
3856 else
3857 $PRINTF "$OK\n"
3858 numOK=$((numOK+1))
3860 fi ;; # NUMCOND
3861 esac
3862 N=$((N+1))
3865 NAME=CHILDSETSID
3866 case "$TESTS" in
3867 *%$N%*|*%functions%*|*%$NAME%*)
3868 TEST="$NAME: child process with setsid"
3869 if ! eval $NUMCOND; then :; else
3870 tf="$td/test$N.stdout"
3871 te="$td/test$N.stderr"
3872 CMD="$TRACE $SOCAT $opts -u exec:$PROCAN,setsid -"
3873 printf "test $F_n $TEST... " $N
3874 $CMD >$tf 2>$te
3875 MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3876 MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3877 MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3878 MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3879 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3880 # PID, PGID, and SID must be the same
3881 if [ "$MYPID" = "$MYPPID" -o \
3882 "$MYPID" != "$MYPGID" -o "$MYPID" != "$MYSID" ];
3883 then
3884 $PRINTF "$FAILED\n"
3885 echo "$CMD"
3886 cat "$te"
3887 numFAIL=$((numFAIL+1))
3888 listFAIL="$listFAIL $N"
3889 else
3890 $PRINTF "$OK\n"
3891 numOK=$((numOK+1))
3893 fi ;; # NUMCOND
3894 esac
3895 N=$((N+1))
3898 NAME=MAINSETSID
3899 case "$TESTS" in
3900 *%$N%*|*%functions%*|*%$NAME%*)
3901 TEST="$NAME: main process with setsid"
3902 if ! eval $NUMCOND; then :; else
3903 tf="$td/test$N.stdout"
3904 te="$td/test$N.stderr"
3905 CMD="$TRACE $SOCAT $opts -U -,setsid exec:$PROCAN"
3906 printf "test $F_n $TEST... " $N
3907 $CMD >$tf 2>$te
3908 MYPID=`grep "process id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3909 MYPPID=`grep "process parent id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3910 MYPGID=`grep "process group id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3911 MYSID=`grep "process session id =" $tf |(expr "\`cat\`" : '[^0-9]*\([0-9]*\).*')`
3912 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3913 # PPID, PGID, and SID must be the same
3914 if [ "$MYPID" = "$MYPPID" -o \
3915 "$MYPPID" != "$MYPGID" -o "$MYPPID" != "$MYSID" ];
3916 then
3917 $PRINTF "$FAILED\n"
3918 echo "$CMD"
3919 cat "$te"
3920 numFAIL=$((numFAIL+1))
3921 listFAIL="$listFAIL $N"
3922 else
3923 $PRINTF "$OK\n"
3924 numOK=$((numOK+1))
3926 fi ;; # NUMCOND
3927 esac
3928 N=$((N+1))
3931 NAME=OPENSSL_TCP4
3932 case "$TESTS" in
3933 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
3934 TEST="$NAME: openssl connect"
3935 if ! eval $NUMCOND; then :;
3936 elif ! testaddrs openssl >/dev/null; then
3937 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
3938 numCANT=$((numCANT+1))
3939 elif ! type openssl >/dev/null 2>&1; then
3940 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
3941 numCANT=$((numCANT+1))
3942 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3943 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
3944 numCANT=$((numCANT+1))
3945 else
3946 gentestcert testsrv
3947 tf="$td/test$N.stdout"
3948 te="$td/test$N.stderr"
3949 tdiff="$td/test$N.diff"
3950 da="test$N $(date) $RANDOM"
3951 CMD2="$TRACE $SOCAT $opts exec:'openssl s_server -accept "$PORT" -quiet -cert testsrv.pem' pipe"
3952 #! CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT"
3953 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
3954 printf "test $F_n $TEST... " $N
3955 eval "$CMD2 2>\"${te}1\" &"
3956 pid=$! # background process id
3957 # this might timeout when openssl opens tcp46 port like " :::$PORT"
3958 waittcp4port $PORT
3959 echo "$da" |$CMD >$tf 2>"${te}2"
3960 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
3961 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3962 echo "$CMD2 &"
3963 echo "$CMD"
3964 cat "${te}1"
3965 cat "${te}2"
3966 cat "$tdiff"
3967 numFAIL=$((numFAIL+1))
3968 listFAIL="$listFAIL $N"
3969 else
3970 $PRINTF "$OK\n"
3971 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3972 numOK=$((numOK+1))
3974 kill $pid 2>/dev/null; wait
3975 fi ;; # NUMCOND, feats
3976 esac
3977 PORT=$((PORT+1))
3978 N=$((N+1))
3981 NAME=OPENSSLLISTEN_TCP4
3982 case "$TESTS" in
3983 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
3984 TEST="$NAME: openssl listen"
3985 if ! eval $NUMCOND; then :;
3986 elif ! testaddrs openssl >/dev/null; then
3987 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
3988 numCANT=$((numCANT+1))
3989 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
3990 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
3991 numCANT=$((numCANT+1))
3992 else
3993 gentestcert testsrv
3994 tf="$td/test$N.stdout"
3995 te="$td/test$N.stderr"
3996 tdiff="$td/test$N.diff"
3997 da="test$N $(date) $RANDOM"
3998 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
3999 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
4000 printf "test $F_n $TEST... " $N
4001 eval "$CMD2 2>\"${te}1\" &"
4002 pid=$! # background process id
4003 waittcp4port $PORT
4004 echo "$da" |$CMD >$tf 2>"${te}2"
4005 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4006 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4007 echo "$CMD2 &"
4008 echo "$CMD"
4009 cat "${te}1"
4010 cat "${te}2"
4011 cat "$tdiff"
4012 numFAIL=$((numFAIL+1))
4013 listFAIL="$listFAIL $N"
4014 else
4015 $PRINTF "$OK\n"
4016 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4017 numOK=$((numOK+1))
4019 kill $pid 2>/dev/null
4020 wait
4021 fi ;; # NUMCOND, feats
4022 esac
4023 PORT=$((PORT+1))
4024 N=$((N+1))
4026 NAME=OPENSSLLISTEN_TCP6
4027 case "$TESTS" in
4028 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4029 TEST="$NAME: openssl listen"
4030 if ! eval $NUMCOND; then :;
4031 elif ! testaddrs openssl >/dev/null; then
4032 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4033 numCANT=$((numCANT+1))
4034 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4035 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4036 numCANT=$((numCANT+1))
4037 else
4038 gentestcert testsrv
4039 tf="$td/test$N.stdout"
4040 te="$td/test$N.stderr"
4041 tdiff="$td/test$N.diff"
4042 da="test$N $(date) $RANDOM"
4043 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip6,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4044 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST6:$PORT,verify=0,$SOCAT_EGD"
4045 printf "test $F_n $TEST... " $N
4046 eval "$CMD2 2>\"${te}1\" &"
4047 pid=$! # background process id
4048 waittcp6port $PORT
4049 echo "$da" |$CMD >$tf 2>"${te}2"
4050 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4051 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4052 echo "$CMD2 &"
4053 echo "$CMD"
4054 cat "${te}1"
4055 cat "${te}2"
4056 cat "$tdiff"
4057 numFAIL=$((numFAIL+1))
4058 listFAIL="$listFAIL $N"
4059 else
4060 $PRINTF "$OK\n"
4061 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4062 numOK=$((numOK+1))
4064 kill $pid 2>/dev/null
4065 wait
4066 fi ;; # NUMCOND, feats
4067 esac
4068 PORT=$((PORT+1))
4069 N=$((N+1))
4072 while read NAMEKEYW FEAT RUNS TESTTMPL PEERTMPL WAITTMPL; do
4073 if [ -z "$NAMEKEYW" ] || [[ "$NAMEKEYW" == \#* ]]; then continue; fi
4075 export ts="$td/test$N.socket"
4076 WAITTMPL="$(echo "$WAITTMPL" |sed -e 's/\040/ /g')"
4077 TESTADDR=$(eval echo $TESTTMPL)
4078 PEERADDR=$(eval echo $PEERTMPL)
4079 WAITCMD=$(eval echo $WAITTMPL)
4080 TESTKEYW=${TESTADDR%%:*}
4082 # does our address implementation support halfclose?
4083 NAME=${NAMEKEYW}_HALFCLOSE
4084 case "$TESTS" in
4085 *%$N%*|*%functions%*|*%$FEAT%*|*%socket%*|*%halfclose%*|*%$NAME%*)
4086 TEST="$NAME: $TESTKEYW half close"
4087 # have a "peer" socat "peer" that executes "$OD_C" and see if EOF on the
4088 # connecting socat brings the result of od
4089 if ! eval $NUMCOND; then :;
4090 elif [ "$FEAT" != ',' ] && ! testaddrs "$FEAT" >/dev/null; then
4091 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
4092 numCANT=$((numCANT+1))
4093 elif ! runs$RUNS; then
4094 $PRINTF "test $F_n $TEST... ${YELLOW}$RUNS not available${NORMAL}\n" $N
4095 numCANT=$((numCANT+1))
4096 else
4097 tf="$td/test$N.stdout"
4098 te="$td/test$N.stderr"
4099 tdiff="$td/test$N.diff"
4100 da="test$N $(date) $RANDOM"
4101 CMD2="$TRACE $SOCAT $opts \"$PEERADDR\" EXEC:'$OD_C'"
4102 CMD="$TRACE $SOCAT -T1 $opts - $TESTADDR"
4103 printf "test $F_n $TEST... " $N
4104 eval "$CMD2 2>\"${te}1\" &"
4105 pid=$! # background process id
4106 $WAITCMD
4107 echo "$da" |$CMD >$tf 2>"${te}2"
4108 if ! echo "$da" |$OD_C |diff - "$tf" >"$tdiff"; then
4109 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4110 echo "$CMD2 &"
4111 echo "$CMD"
4112 cat "${te}1"
4113 cat "${te}2"
4114 cat "$tdiff"
4115 numFAIL=$((numFAIL+1))
4116 listFAIL="$listFAIL $N"
4117 else
4118 $PRINTF "$OK\n"
4119 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4120 numOK=$((numOK+1))
4122 kill $pid 2>/dev/null
4123 wait
4124 fi ;; # NUMCOND, feats
4125 esac
4126 PORT=$((PORT+1))
4127 N=$((N+1))
4129 done <<<"
4130 UNIXCONNECT , unix UNIX-CONNECT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4131 UNIXCLIENT , unix UNIX-CLIENT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4132 GOPEN_UNIXSTREAM , unix GOPEN:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4133 UNIXLISTEN , unix UNIX-LISTEN:\$ts UNIX-CONNECT:\$ts,retry=3 sleep\040\1
4134 TCP4CONNECT , tcp4 TCP4-CONNECT:\$LOCALHOST:\$PORT TCP4-LISTEN:\$PORT waittcp4port\040\$PORT
4135 TCP4LISTEN , tcp4 TCP4-LISTEN:\$PORT TCP4-CONNECT:\$LOCALHOST:\$PORT,retry=3
4136 TCP6CONNECT , tcp6 TCP6-CONNECT:\$LOCALHOST6:\$PORT TCP6-LISTEN:\$PORT waittcp6port\040\$PORT
4137 TCP6LISTEN , tcp6 TCP6-LISTEN:\$PORT TCP6-CONNECT:\$LOCALHOST6:\$PORT,retry=3
4138 OPENSSL4CLIENT OPENSSL tcp4 OPENSSL:\$LOCALHOST:\$PORT,verify=0 OPENSSL-LISTEN:\$PORT,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp4port\040\$PORT
4139 OPENSSL4SERVER OPENSSL tcp4 OPENSSL-LISTEN:\$PORT,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST:\$PORT,verify=0,retry=3
4140 OPENSSL6CLIENT OPENSSL tcp6 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,verify=0 OPENSSL-LISTEN:\$PORT,pf=ip6,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp6port\040\$PORT
4141 OPENSSL6SERVER OPENSSL tcp6 OPENSSL-LISTEN:\$PORT,pf=ip6,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,verify=0,retry=3
4145 NAME=OPENSSL_SERVERAUTH
4146 case "$TESTS" in
4147 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4148 TEST="$NAME: openssl server authentication"
4149 if ! eval $NUMCOND; then :;
4150 elif ! testaddrs openssl >/dev/null; then
4151 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4152 numCANT=$((numCANT+1))
4153 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4154 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4155 numCANT=$((numCANT+1))
4156 else
4157 gentestcert testsrv
4158 gentestcert testcli
4159 tf="$td/test$N.stdout"
4160 te="$td/test$N.stderr"
4161 tdiff="$td/test$N.diff"
4162 da="test$N $(date) $RANDOM"
4163 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4164 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=1,cafile=testsrv.crt,$SOCAT_EGD"
4165 printf "test $F_n $TEST... " $N
4166 eval "$CMD2 2>\"${te}1\" &"
4167 pid=$! # background process id
4168 waittcp4port $PORT
4169 echo "$da" |$CMD >$tf 2>"${te}2"
4170 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4171 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4172 echo "$CMD2 &"
4173 echo "$CMD"
4174 cat "${te}1"
4175 cat "${te}2"
4176 cat "$tdiff"
4177 numFAIL=$((numFAIL+1))
4178 listFAIL="$listFAIL $N"
4179 else
4180 $PRINTF "$OK\n"
4181 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4182 numOK=$((numOK+1))
4184 kill $pid 2>/dev/null
4185 wait
4186 fi ;; # NUMCOND, feats
4187 esac
4188 PORT=$((PORT+1))
4189 N=$((N+1))
4191 NAME=OPENSSL_CLIENTAUTH
4192 case "$TESTS" in
4193 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4194 TEST="$NAME: openssl client authentication"
4195 if ! eval $NUMCOND; then :;
4196 elif ! testaddrs openssl >/dev/null; then
4197 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4198 numCANT=$((numCANT+1))
4199 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4200 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4201 numCANT=$((numCANT+1))
4202 else
4203 gentestcert testsrv
4204 gentestcert testcli
4205 tf="$td/test$N.stdout"
4206 te="$td/test$N.stderr"
4207 tdiff="$td/test$N.diff"
4208 da="test$N $(date) $RANDOM"
4209 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,verify=1,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt,$SOCAT_EGD pipe"
4210 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=0,cert=testcli.crt,key=testcli.key,$SOCAT_EGD"
4211 printf "test $F_n $TEST... " $N
4212 eval "$CMD2 2>\"${te}1\" &"
4213 pid=$! # background process id
4214 waittcp4port $PORT
4215 echo "$da" |$CMD >$tf 2>"${te}2"
4216 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4217 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4218 echo "$CMD2 &"
4219 echo "$CMD"
4220 cat "${te}1"
4221 cat "${te}2"
4222 cat "$tdiff"
4223 numFAIL=$((numFAIL+1))
4224 listFAIL="$listFAIL $N"
4225 else
4226 $PRINTF "$OK\n"
4227 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4228 numOK=$((numOK+1))
4230 kill $pid 2>/dev/null
4231 wait
4232 fi ;; # NUMCOND, feats
4233 esac
4234 PORT=$((PORT+1))
4235 N=$((N+1))
4237 NAME=OPENSSL_FIPS_BOTHAUTH
4238 case "$TESTS" in
4239 *%$N%*|*%functions%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4240 TEST="$NAME: OpenSSL+FIPS client and server authentication"
4241 if ! eval $NUMCOND; then :;
4242 elif ! testaddrs openssl >/dev/null; then
4243 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4244 numCANT=$((numCANT+1))
4245 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4246 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4247 numCANT=$((numCANT+1))
4248 elif ! testoptions fips >/dev/null; then
4249 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
4250 numCANT=$((numCANT+1))
4251 else
4252 OPENSSL_FIPS=1 gentestcert testsrvfips
4253 OPENSSL_FIPS=1 gentestcert testclifips
4254 tf="$td/test$N.stdout"
4255 te="$td/test$N.stderr"
4256 tdiff="$td/test$N.diff"
4257 da="test$N $(date) $RANDOM"
4258 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,fips,$SOCAT_EGD,cert=testsrvfips.crt,key=testsrvfips.key,cafile=testclifips.crt pipe"
4259 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,fips,verify=1,cert=testclifips.crt,key=testclifips.key,cafile=testsrvfips.crt,$SOCAT_EGD"
4260 printf "test $F_n $TEST... " $N
4261 eval "$CMD2 2>\"${te}1\" &"
4262 pid=$! # background process id
4263 waittcp4port $PORT
4264 echo "$da" |$CMD >$tf 2>"${te}2"
4265 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4266 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4267 echo "$CMD2 &"
4268 echo "$CMD"
4269 cat "${te}1"
4270 cat "${te}2"
4271 cat "$tdiff"
4272 numFAIL=$((numFAIL+1))
4273 listFAIL="$listFAIL $N"
4274 else
4275 $PRINTF "$OK\n"
4276 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4277 numOK=$((numOK+1))
4279 kill $pid 2>/dev/null
4280 wait
4281 fi ;; # NUMCOND, feats
4282 esac
4283 PORT=$((PORT+1))
4284 N=$((N+1))
4287 NAME=OPENSSL_COMPRESS
4288 case "$TESTS" in
4289 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4290 TEST="$NAME: OpenSSL compression"
4291 if ! eval $NUMCOND; then :;
4292 elif ! testaddrs openssl >/dev/null; then
4293 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4294 numCANT=$((numCANT+1))
4295 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4296 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4297 numCANT=$((numCANT+1))
4298 elif ! testoptions openssl-compress >/dev/null; then
4299 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL compression option not available${NORMAL}\n" $N
4300 numCANT=$((numCANT+1))
4301 else
4302 gentestcert testsrv
4303 printf "test $F_n $TEST... " $N
4304 tf="$td/test$N.stdout"
4305 te="$td/test$N.stderr"
4306 tdiff="$td/test$N.diff"
4307 da="test$N $(date) $RANDOM"
4308 success=yes
4309 for srccompr in '' compress=auto compress=none; do
4310 for dstcompr in '' compress=auto compress=none; do
4311 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0,$dstcompr pipe"
4312 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD,$srccompr"
4313 eval "$CMD2 2>\"${te}1\" &"
4314 pid=$! # background process id
4315 waittcp4port $PORT
4316 echo "$da" | $CMD >$tf 2>"${te}2"
4317 kill $pid 2>/dev/null
4318 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4319 success=
4320 break
4322 done
4323 done
4324 if test -z "$success"; then
4325 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4326 echo "$CMD2 &"
4327 echo "$CMD"
4328 cat "${te}1"
4329 cat "${te}2"
4330 cat "$tdiff"
4331 numFAIL=$((numFAIL+1))
4332 listFAIL="$listFAIL $N"
4333 else
4334 $PRINTF "$OK\n"
4335 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4336 numOK=$((numOK+1))
4338 fi ;; # NUMCOND, feats
4339 esac
4340 PORT=$((PORT+1))
4341 N=$((N+1))
4344 NAME=SOCKS4CONNECT_TCP4
4345 case "$TESTS" in
4346 *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4347 TEST="$NAME: socks4 connect over TCP/IPv4"
4348 if ! eval $NUMCOND; then :;
4349 elif ! testaddrs socks4 >/dev/null; then
4350 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4351 numCANT=$((numCANT+1))
4352 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4353 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4354 numCANT=$((numCANT+1))
4355 else
4356 tf="$td/test$N.stdout"
4357 te="$td/test$N.stderr"
4358 tdiff="$td/test$N.diff"
4359 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4360 # we have a normal tcp echo listening - so the socks header must appear in answer
4361 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr exec:\"./socks4echo.sh\""
4362 CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST:32.98.76.54:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
4363 printf "test $F_n $TEST... " $N
4364 eval "$CMD2 2>\"${te}1\" &"
4365 pid=$! # background process id
4366 waittcp4port $PORT 1
4367 echo "$da" |$CMD >$tf 2>"${te}2"
4368 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4369 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4370 echo "$CMD2 &"
4371 echo "$CMD"
4372 cat "${te}1"
4373 cat "${te}2"
4374 cat "$tdiff"
4375 numFAIL=$((numFAIL+1))
4376 listFAIL="$listFAIL $N"
4377 else
4378 $PRINTF "$OK\n"
4379 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4380 numOK=$((numOK+1))
4382 kill $pid 2>/dev/null
4383 wait
4384 fi ;; # NUMCOND, feats
4385 esac
4386 PORT=$((PORT+1))
4387 N=$((N+1))
4389 NAME=SOCKS4CONNECT_TCP6
4390 case "$TESTS" in
4391 *%$N%*|*%functions%*|*%socks%*|*%socks4%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4392 TEST="$NAME: socks4 connect over TCP/IPv6"
4393 if ! eval $NUMCOND; then :;
4394 elif ! testaddrs socks4 >/dev/null; then
4395 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4396 numCANT=$((numCANT+1))
4397 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4398 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4399 numCANT=$((numCANT+1))
4400 else
4401 tf="$td/test$N.stdout"
4402 te="$td/test$N.stderr"
4403 tdiff="$td/test$N.diff"
4404 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4405 # we have a normal tcp echo listening - so the socks header must appear in answer
4406 CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,reuseaddr exec:\"./socks4echo.sh\""
4407 CMD="$TRACE $SOCAT $opts - socks4:$LOCALHOST6:32.98.76.54:32109,socksport=$PORT",socksuser="nobody"
4408 printf "test $F_n $TEST... " $N
4409 eval "$CMD2 2>\"${te}1\" &"
4410 pid=$! # background process id
4411 waittcp6port $PORT 1
4412 echo "$da" |$CMD >$tf 2>"${te}2"
4413 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4414 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4415 echo "$CMD2 &"
4416 echo "$CMD"
4417 cat "${te}1"
4418 cat "${te}2"
4419 cat "$tdiff"
4420 numFAIL=$((numFAIL+1))
4421 listFAIL="$listFAIL $N"
4422 else
4423 $PRINTF "$OK\n"
4424 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4425 numOK=$((numOK+1))
4427 kill $pid 2>/dev/null
4428 wait
4429 fi ;; # NUMCOND, feats
4430 esac
4431 PORT=$((PORT+1))
4432 N=$((N+1))
4435 NAME=SOCKS4ACONNECT_TCP4
4436 case "$TESTS" in
4437 *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4438 TEST="$NAME: socks4a connect over TCP/IPv4"
4439 if ! eval $NUMCOND; then :;
4440 elif ! testaddrs socks4a >/dev/null; then
4441 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4442 numCANT=$((numCANT+1))
4443 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4444 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4445 numCANT=$((numCANT+1))
4446 else
4447 tf="$td/test$N.stdout"
4448 te="$td/test$N.stderr"
4449 tdiff="$td/test$N.diff"
4450 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4451 # we have a normal tcp echo listening - so the socks header must appear in answer
4452 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr exec:\"./socks4a-echo.sh\""
4453 CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST:localhost:32109,pf=ip4,socksport=$PORT",socksuser="nobody"
4454 printf "test $F_n $TEST... " $N
4455 eval "$CMD2 2>\"${te}1\" &"
4456 pid=$! # background process id
4457 waittcp4port $PORT 1
4458 echo "$da" |$CMD >$tf 2>"${te}2"
4459 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4460 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4461 echo "$CMD2 &"
4462 echo "$CMD"
4463 cat "${te}1"
4464 cat "${te}2"
4465 cat "$tdiff"
4466 numFAIL=$((numFAIL+1))
4467 listFAIL="$listFAIL $N"
4468 else
4469 $PRINTF "$OK\n"
4470 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4471 numOK=$((numOK+1))
4473 kill $pid 2>/dev/null
4474 wait
4475 fi ;; # NUMCOND, feats
4476 esac
4477 PORT=$((PORT+1))
4478 N=$((N+1))
4480 NAME=SOCKS4ACONNECT_TCP6
4481 case "$TESTS" in
4482 *%$N%*|*%functions%*|*%socks%*|*%socks4a%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4483 TEST="$NAME: socks4a connect over TCP/IPv6"
4484 if ! eval $NUMCOND; then :;
4485 elif ! testaddrs socks4a >/dev/null; then
4486 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4487 numCANT=$((numCANT+1))
4488 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4489 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4490 numCANT=$((numCANT+1))
4491 else
4492 tf="$td/test$N.stdout"
4493 te="$td/test$N.stderr"
4494 tdiff="$td/test$N.diff"
4495 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4496 # we have a normal tcp echo listening - so the socks header must appear in answer
4497 CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,reuseaddr exec:\"./socks4a-echo.sh\""
4498 CMD="$TRACE $SOCAT $opts - socks4a:$LOCALHOST6:localhost:32109,socksport=$PORT",socksuser="nobody"
4499 printf "test $F_n $TEST... " $N
4500 eval "$CMD2 2>\"${te}1\" &"
4501 pid=$! # background process id
4502 waittcp6port $PORT 1
4503 echo "$da" |$CMD >$tf 2>"${te}2"
4504 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4505 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4506 echo "$CMD2 &"
4507 echo "$CMD"
4508 cat "${te}1"
4509 cat "${te}2"
4510 cat "$tdiff"
4511 numFAIL=$((numFAIL+1))
4512 listFAIL="$listFAIL $N"
4513 else
4514 $PRINTF "$OK\n"
4515 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4516 numOK=$((numOK+1))
4518 kill $pid 2>/dev/null
4519 wait
4520 fi ;; # NUMCOND, feats
4521 esac
4522 PORT=$((PORT+1))
4523 N=$((N+1))
4526 NAME=PROXYCONNECT_TCP4
4527 case "$TESTS" in
4528 *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
4529 TEST="$NAME: proxy connect over TCP/IPv4"
4530 if ! eval $NUMCOND; then :;
4531 elif ! testaddrs proxy >/dev/null; then
4532 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4533 numCANT=$((numCANT+1))
4534 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
4535 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4536 numCANT=$((numCANT+1))
4537 else
4538 ts="$td/test$N.sh"
4539 tf="$td/test$N.stdout"
4540 te="$td/test$N.stderr"
4541 tdiff="$td/test$N.diff"
4542 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4543 #CMD2="$TRACE $SOCAT tcp4-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4544 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh\""
4545 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4546 printf "test $F_n $TEST... " $N
4547 eval "$CMD2 2>\"${te}2\" &"
4548 pid=$! # background process id
4549 waittcp4port $PORT 1
4550 echo "$da" |$CMD >"$tf" 2>"${te}1"
4551 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4552 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4553 echo "$CMD2 &"
4554 echo "$CMD"
4555 cat "${te}1"
4556 cat "${te}2"
4557 cat "$tdiff"
4558 numFAIL=$((numFAIL+1))
4559 listFAIL="$listFAIL $N"
4560 else
4561 $PRINTF "$OK\n"
4562 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4563 numOK=$((numOK+1))
4565 kill $pid 2>/dev/null
4566 wait
4567 fi ;; # NUMCOND, feats
4568 esac
4569 PORT=$((PORT+1))
4570 N=$((N+1))
4572 NAME=PROXYCONNECT_TCP6
4573 case "$TESTS" in
4574 *%$N%*|*%functions%*|*%proxyconnect%*|*%proxy%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
4575 TEST="$NAME: proxy connect over TCP/IPv6"
4576 if ! eval $NUMCOND; then :;
4577 elif ! testaddrs proxy >/dev/null; then
4578 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4579 numCANT=$((numCANT+1))
4580 elif ! testaddrs listen tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
4581 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4582 numCANT=$((numCANT+1))
4583 else
4584 ts="$td/test$N.sh"
4585 tf="$td/test$N.stdout"
4586 te="$td/test$N.stderr"
4587 tdiff="$td/test$N.diff"
4588 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4589 #CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4590 CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh\""
4591 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST6:127.0.0.1:1000,proxyport=$PORT"
4592 printf "test $F_n $TEST... " $N
4593 eval "$CMD2 2>\"${te}2\" &"
4594 pid=$! # background process id
4595 waittcp6port $PORT 1
4596 echo "$da" |$CMD >"$tf" 2>"${te}1"
4597 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4598 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4599 echo "$CMD2 &"
4600 echo "$CMD"
4601 cat "${te}1"
4602 cat "${te}2"
4603 cat "$tdiff"
4604 numFAIL=$((numFAIL+1))
4605 listFAIL="$listFAIL $N"
4606 else
4607 $PRINTF "$OK\n"
4608 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4609 numOK=$((numOK+1))
4611 kill $pid 2>/dev/null
4612 wait
4613 fi ;; # NUMCOND, feats
4614 esac
4615 PORT=$((PORT+1))
4616 N=$((N+1))
4619 NAME=TCP4NOFORK
4620 case "$TESTS" in
4621 *%$N%*|*%functions%*|*%$NAME%*)
4622 TEST="$NAME: echo via connection to TCP V4 socket with nofork'ed exec"
4623 if ! eval $NUMCOND; then :; else
4624 tf="$td/test$N.stdout"
4625 te="$td/test$N.stderr"
4626 tdiff="$td/test$N.diff"
4627 tsl=$PORT
4628 ts="127.0.0.1:$tsl"
4629 da="test$N $(date) $RANDOM"
4630 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr exec:$CAT,nofork"
4631 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
4632 printf "test $F_n $TEST... " $N
4633 #$CMD1 >"$tf" 2>"${te}1" &
4634 $CMD1 >/dev/null 2>"${te}1" &
4635 waittcp4port $tsl
4636 #usleep $MICROS
4637 echo "$da" |$CMD2 >"$tf" 2>>"${te}2"
4638 if [ $? -ne 0 ]; then
4639 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4640 echo "$CMD1 &"
4641 echo "$CMD2"
4642 cat "${te}1"
4643 cat "${te}2"
4644 numFAIL=$((numFAIL+1))
4645 listFAIL="$listFAIL $N"
4646 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
4647 $PRINTF "$FAILED\n"
4648 cat "$tdiff"
4649 numFAIL=$((numFAIL+1))
4650 listFAIL="$listFAIL $N"
4651 else
4652 $PRINTF "$OK\n"
4653 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4654 numOK=$((numOK+1))
4656 fi ;; # NUMCOND
4657 esac
4658 PORT=$((PORT+1))
4659 N=$((N+1))
4662 NAME=EXECCATNOFORK
4663 case "$TESTS" in
4664 *%$N%*|*%functions%*|*%$NAME%*)
4665 TEST="$NAME: simple echo via exec of cat with nofork"
4666 testecho "$N" "$TEST" "" "exec:$CAT,nofork" "$opts"
4667 esac
4668 N=$((N+1))
4671 NAME=SYSTEMCATNOFORK
4672 case "$TESTS" in
4673 *%$N%*|*%functions%*|*%$NAME%*)
4674 TEST="$NAME: simple echo via system() of cat with nofork"
4675 testecho "$N" "$TEST" "" "system:$CAT,nofork" "$opts"
4676 esac
4677 N=$((N+1))
4680 NAME=NOFORKSETSID
4681 case "$TESTS" in
4682 *%$N%*|*%functions%*|*%$NAME%*)
4683 TEST="$NAME: simple echo via exec() of cat with nofork and setsid"
4684 testecho "$N" "$TEST" "" "system:$CAT,nofork,setsid" "$opts"
4685 esac
4686 N=$((N+1))
4688 #==============================================================================
4689 #TEST="$NAME: echo via 'connection' to UDP V4 socket"
4690 #if ! eval $NUMCOND; then :; else
4691 #tf="$td/file$N"
4692 #tsl=65534
4693 #ts="127.0.0.1:$tsl"
4694 #da="test$N $(date) $RANDOM"
4695 #$TRACE $SOCAT UDP-listen:$tsl PIPE &
4696 #sleep 2
4697 #echo "$da" |$TRACE $SOCAT stdin!!stdout UDP:$ts >"$tf"
4698 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
4699 # $ECHO "... test $N succeeded"
4700 # numOK=$((numOK+1))
4701 #else
4702 # $ECHO "*** test $N $FAILED"
4703 # numFAIL=$((numFAIL+1))
4704 # listFAIL="$listFAIL $N"
4706 #fi ;; # NUMCOND
4707 #N=$((N+1))
4708 #==============================================================================
4709 # TEST 4 - simple echo via new file
4710 #if ! eval $NUMCOND; then :; else
4711 #N=4
4712 #tf="$td/file$N"
4713 #tp="$td/pipe$N"
4714 #da="test$N $(date) $RANDOM"
4715 #rm -f "$tf.tmp"
4716 #echo "$da" |$TRACE $SOCAT - FILE:$tf.tmp,ignoreeof >"$tf"
4717 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
4718 # $ECHO "... test $N succeeded"
4719 # numOK=$((numOK+1))
4720 #else
4721 # $ECHO "*** test $N $FAILED"
4722 # numFAIL=$((numFAIL+1))
4723 # listFAIL="$listFAIL $N"
4725 #fi ;; # NUMCOND
4727 #==============================================================================
4729 NAME=TOTALTIMEOUT
4730 case "$TESTS" in
4731 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%$NAME%*)
4732 TEST="$NAME: socat inactivity timeout"
4733 if ! eval $NUMCOND; then :; else
4734 #set -vx
4735 tf="$td/test$N.stdout"
4736 te="$td/test$N.stderr"
4737 tdiff="$td/test$N.diff"
4738 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4739 CMD2="$TRACE $SOCAT $opts -T 1 tcp4-listen:$PORT,reuseaddr pipe"
4740 CMD="$TRACE $SOCAT $opts - tcp4-connect:$LOCALHOST:$PORT"
4741 printf "test $F_n $TEST... " $N
4742 eval "$CMD2 2>${te}1 &"
4743 pid=$! # background process id
4744 waittcp4port $PORT 1
4745 (echo "$da"; sleep 2; echo X) |$CMD >"$tf" 2>"${te}2"
4746 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4747 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4748 echo "$CMD2 &"
4749 echo "$CMD"
4750 cat "${te}1"
4751 cat "${te}2"
4752 cat "$tdiff"
4753 numFAIL=$((numFAIL+1))
4754 listFAIL="$listFAIL $N"
4755 else
4756 $PRINTF "$OK\n"
4757 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4758 numOK=$((numOK+1))
4760 kill $pid 2>/dev/null
4761 wait
4762 #set +vx
4763 fi ;; # NUMCOND
4764 esac
4765 PORT=$((PORT+1))
4766 N=$((N+1))
4769 NAME=IGNOREEOF+TOTALTIMEOUT
4770 case "$TESTS" in
4771 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%ignoreeof%*|*%$NAME%*)
4772 TEST="$NAME: ignoreeof and inactivity timeout"
4773 if ! eval $NUMCOND; then :; else
4774 #set -vx
4775 ti="$td/test$N.file"
4776 tf="$td/test$N.stdout"
4777 te="$td/test$N.stderr"
4778 tdiff="$td/test$N.diff"
4779 da="test$N $(date) $RANDOM"
4780 CMD="$TRACE $SOCAT $opts -T 2 -u file:\"$ti\",ignoreeof -"
4781 printf "test $F_n $TEST... " $N
4782 touch "$ti"
4783 $CMD >"$tf" 2>"$te" &
4784 bg=$! # background process id
4785 psleep 0.5
4786 echo "$da" >>"$ti"
4787 sleep 4
4788 echo X >>"$ti"
4789 sleep 1
4790 kill $bg 2>/dev/null
4791 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4792 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4793 echo "$CMD &"
4794 cat "$te"
4795 cat "$tdiff"
4796 numFAIL=$((numFAIL+1))
4797 listFAIL="$listFAIL $N"
4798 else
4799 $PRINTF "$OK\n"
4800 if [ -n "$debug" ]; then cat "$te"; fi
4801 numOK=$((numOK+1))
4803 wait
4804 fi ;; # NUMCOND, feats
4805 esac
4806 N=$((N+1))
4809 NAME=PROXY2SPACES
4810 case "$TESTS" in
4811 *%$N%*|*%functions%*|*%proxy%*|*%$NAME%*)
4812 TEST="$NAME: proxy connect accepts status with multiple spaces"
4813 if ! eval $NUMCOND; then :;
4814 elif ! testaddrs proxy >/dev/null; then
4815 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4816 numCANT=$((numCANT+1))
4817 else
4818 ts="$td/test$N.sh"
4819 tf="$td/test$N.stdout"
4820 te="$td/test$N.stderr"
4821 tdiff="$td/test$N.diff"
4822 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4823 #CMD2="$TRACE $SOCAT $opts tcp-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4824 CMD2="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh -w 2\""
4825 CMD="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4826 printf "test $F_n $TEST... " $N
4827 eval "$CMD2 2>\"${te}1\" &"
4828 pid=$! # background process id
4829 waittcp4port $PORT 1
4830 echo "$da" |$CMD >"$tf" 2>"${te}2"
4831 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
4832 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4833 echo "$CMD2 &"
4834 echo "$CMD"
4835 cat "${te}1"
4836 cat "${te}2"
4837 cat "$tdiff"
4838 numFAIL=$((numFAIL+1))
4839 listFAIL="$listFAIL $N"
4840 else
4841 $PRINTF "$OK\n"
4842 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4843 numOK=$((numOK+1))
4845 kill $pid 2>/dev/null
4846 wait
4847 fi ;; # NUMCOND, feats
4848 esac
4849 PORT=$((PORT+1))
4850 N=$((N+1))
4853 NAME=BUG-UNISTDIO
4854 case "$TESTS" in
4855 *%$N%*|*%functions%*|*%$NAME%*)
4856 TEST="$NAME: for bug with address options on both stdin/out in unidirectional mode"
4857 if ! eval $NUMCOND; then :; else
4858 tf="$td/test$N.stdout"
4859 te="$td/test$N.stderr"
4860 ff="$td/file$N"
4861 printf "test $F_n $TEST... " $N
4862 >"$ff"
4863 #$TRACE $SOCAT $opts -u /dev/null -,setlk <"$ff" 2>"$te"
4864 CMD="$TRACE $SOCAT $opts -u /dev/null -,setlk"
4865 $CMD <"$ff" 2>"$te"
4866 if [ "$?" -eq 0 ]; then
4867 $PRINTF "$OK\n"
4868 numOK=$((numOK+1))
4869 else
4870 if [ "$UNAME" = "Linux" ]; then
4871 $PRINTF "$FAILED\n"
4872 echo "$CMD"
4873 cat "$te"
4874 numFAIL=$((numFAIL+1))
4875 listFAIL="$listFAIL $N"
4876 else
4877 $PRINTF "${YELLOW}failed (don't care)${NORMAL}\n"
4878 numCANT=$((numCANT+1))
4881 fi ;; # NUMCOND
4882 esac
4883 N=$((N+1))
4886 NAME=SINGLEEXECOUTSOCKETPAIR
4887 case "$TESTS" in
4888 *%$N%*|*%functions%*|*%$NAME%*)
4889 TEST="$NAME: inheritance of stdout to single exec with socketpair"
4890 testecho "$N" "$TEST" "-!!exec:cat" "" "$opts" 1
4891 esac
4892 N=$((N+1))
4894 NAME=SINGLEEXECOUTPIPE
4895 case "$TESTS" in
4896 *%$N%*|*%functions%*|*%$NAME%*)
4897 TEST="$NAME: inheritance of stdout to single exec with pipe"
4898 testecho "$N" "$TEST" "-!!exec:cat,pipes" "" "$opts" 1
4899 esac
4900 N=$((N+1))
4902 NAME=SINGLEEXECOUTPTY
4903 case "$TESTS" in
4904 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
4905 TEST="$NAME: inheritance of stdout to single exec with pty"
4906 if ! eval $NUMCOND; then :;
4907 elif ! testaddrs pty >/dev/null; then
4908 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
4909 numCANT=$((numCANT+1))
4910 else
4911 testecho "$N" "$TEST" "-!!exec:cat,pty,raw" "" "$opts" 1
4912 fi ;; # NUMCOND, feats
4913 esac
4914 N=$((N+1))
4916 NAME=SINGLEEXECINSOCKETPAIR
4917 case "$TESTS" in
4918 *%$N%*|*%functions%*|*%$NAME%*)
4919 TEST="$NAME: inheritance of stdin to single exec with socketpair"
4920 testecho "$N" "$TEST" "exec:cat!!-" "" "$opts"
4921 esac
4922 N=$((N+1))
4924 NAME=SINGLEEXECINPIPE
4925 case "$TESTS" in
4926 *%$N%*|*%functions%*|*%$NAME%*)
4927 TEST="$NAME: inheritance of stdin to single exec with pipe"
4928 testecho "$N" "$TEST" "exec:cat,pipes!!-" "" "$opts"
4929 esac
4930 N=$((N+1))
4932 NAME=SINGLEEXECINPTYDELAY
4933 case "$TESTS" in
4934 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
4935 TEST="$NAME: inheritance of stdin to single exec with pty, with delay"
4936 if ! eval $NUMCOND; then :;
4937 elif ! testaddrs pty >/dev/null; then
4938 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
4939 numCANT=$((numCANT+1))
4940 else
4941 testecho "$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts" $MISCDELAY
4942 fi ;; # NUMCOND, feats
4943 esac
4944 N=$((N+1))
4946 NAME=SINGLEEXECINPTY
4947 case "$TESTS" in
4948 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
4949 TEST="$NAME: inheritance of stdin to single exec with pty"
4950 if ! eval $NUMCOND; then :;
4951 elif ! testaddrs pty >/dev/null; then
4952 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
4953 numCANT=$((numCANT+1))
4954 else
4955 testecho "$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts"
4956 fi ;; # NUMCOND, feats
4957 esac
4958 N=$((N+1))
4961 NAME=READLINE
4962 #set -vx
4963 case "$TESTS" in
4964 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
4965 TEST="$NAME: readline with password and sigint"
4966 if ! eval $NUMCOND; then :;
4967 elif ! feat=$(testaddrs readline pty); then
4968 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
4969 numCANT=$((numCANT+1))
4970 else
4971 SAVETERM="$TERM"; TERM= # 'cause konsole might print controls even in raw
4972 SAVEMICS=$MICROS
4973 #MICROS=2000000
4974 ts="$td/test$N.sh"
4975 to="$td/test$N.stdout"
4976 tpi="$td/test$N.inpipe"
4977 tpo="$td/test$N.outpipe"
4978 te="$td/test$N.stderr"
4979 tr="$td/test$N.ref"
4980 tdiff="$td/test$N.diff"
4981 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
4982 # the feature that we really want to test is in the readline.sh script:
4983 CMD="$TRACE $SOCAT $opts -t1 open:$tpi,nonblock!!open:$tpo exec:\"./readline.sh -nh ./readline-test.sh\",pty,ctty,setsid,raw,echo=0,isig"
4984 #echo "$CMD" >"$ts"
4985 #chmod a+x "$ts"
4986 printf "test $F_n $TEST... " $N
4987 rm -f "$tpi" "$tpo"
4988 mkfifo "$tpi"
4989 touch "$tpo"
4991 # during development of this test, the following command line succeeded:
4992 # (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
4994 PATH=${SOCAT%socat}:$PATH eval "$CMD 2>$te &"
4995 pid=$! # background process id
4996 usleep $MICROS
4999 usleep $((3*MICROS))
5000 $ECHO "user\n\c"
5001 usleep $MICROS
5002 $ECHO "password\c"
5003 usleep $MICROS
5004 $ECHO "\n\c"
5005 usleep $MICROS
5006 $ECHO "test 1\n\c"
5007 usleep $MICROS
5008 $ECHO "\003\c"
5009 usleep $MICROS
5010 $ECHO "test 2\n\c"
5011 usleep $MICROS
5012 $ECHO "exit\n\c"
5013 usleep $MICROS
5014 ) >"$tpi"
5016 cat >$tr <<EOF
5017 readline feature test program
5018 Authentication required
5019 Username: user
5020 Password:
5021 prog> test 1
5022 executing test 1
5023 prog> ./readline-test.sh got SIGINT
5024 test 2
5025 executing test 2
5026 prog> exit
5029 #0 if ! sed 's/.*\r//g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5030 #0 if ! sed 's/.*'"$($ECHO '\r\c')"'/</g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5031 wait
5032 if ! tr "$($ECHO '\r \c')" "% " <$tpo |sed 's/%$//g' |sed 's/.*%//g' |diff "$tr" - >"$tdiff" 2>&1; then
5033 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5034 echo "$CMD"
5035 cat "$te"
5036 cat "$tdiff"
5037 numFAIL=$((numFAIL+1))
5038 listFAIL="$listFAIL $N"
5039 else
5040 $PRINTF "$OK\n"
5041 if [ -n "$debug" ]; then cat $te; fi
5042 numOK=$((numOK+1))
5044 kill $pid 2>/dev/null # necc on OpenBSD
5045 wait
5046 MICROS=$SAVEMICS
5047 TERM="$SAVETERM"
5048 fi ;; # NUMCOND, feats
5049 esac
5050 PORT=$((PORT+1))
5051 N=$((N+1))
5054 NAME=GENDERCHANGER
5055 case "$TESTS" in
5056 *%$N%*|*%functions%*|*%$NAME%*)
5057 TEST="$NAME: TCP4 \"gender changer\""
5058 if ! eval $NUMCOND; then :; else
5059 tf="$td/test$N.stdout"
5060 te="$td/test$N.stderr"
5061 tdiff="$td/test$N.diff"
5062 da="test$N $(date) $RANDOM"
5063 # this is the server in the protected network that we want to reach
5064 CMD1="$TRACE $SOCAT -lpserver $opts tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5065 # this is the double client in the protected network
5066 CMD2="$TRACE $SOCAT -lp2client $opts tcp4:$LOCALHOST:$((PORT+1)),retry=10,interval=1 tcp4:$LOCALHOST:$PORT"
5067 # this is the double server in the outside network
5068 CMD3="$TRACE $SOCAT -lp2server $opts tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST"
5069 # this is the outside client that wants to use the protected server
5070 CMD4="$TRACE $SOCAT -lpclient $opts -t1 - tcp4:$LOCALHOST:$((PORT+2))"
5071 printf "test $F_n $TEST... " $N
5072 eval "$CMD1 2>${te}1 &"
5073 pid1=$!
5074 eval "$CMD2 2>${te}2 &"
5075 pid2=$!
5076 eval "$CMD3 2>${te}3 &"
5077 pid3=$!
5078 waittcp4port $PORT 1 &&
5079 waittcp4port $((PORT+2)) 1
5080 sleep 1
5081 echo "$da" |$CMD4 >$tf 2>"${te}4"
5082 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
5083 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5084 echo "$CMD1 &"
5085 echo "$CMD2 &"
5086 echo "$CMD3 &"
5087 echo "$CMD4"
5088 cat "${te}1" "${te}2" "${te}3" "${te}4"
5089 cat "$tdiff"
5090 numFAIL=$((numFAIL+1))
5091 listFAIL="$listFAIL $N"
5092 else
5093 $PRINTF "$OK\n"
5094 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4"; fi
5095 numOK=$((numOK+1))
5097 kill $pid1 $pid2 $pid3 $pid4 2>/dev/null
5098 wait
5099 fi ;; # NUMCOND
5100 esac
5101 PORT=$((PORT+3))
5102 N=$((N+1))
5106 #PORT=10000
5108 NAME=OUTBOUNDIN
5109 case "$TESTS" in
5110 *%$N%*|*%functions%*|*%openssl%*|*%proxy%*|*%$NAME%*)
5111 TEST="$NAME: gender changer via SSL through HTTP proxy, oneshot"
5112 if ! eval $NUMCOND; then :;
5113 elif ! feat=$(testaddrs openssl proxy); then
5114 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5115 numCANT=$((numCANT+1))
5116 else
5117 gentestcert testsrv
5118 gentestcert testcli
5119 tf="$td/test$N.stdout"
5120 te="$td/test$N.stderr"
5121 tdiff="$td/test$N.diff"
5122 da="test$N $(date) $RANDOM"
5123 # this is the server in the protected network that we want to reach
5124 CMD1="$TRACE $SOCAT $opts -lpserver tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5125 # this is the proxy in the protected network that provides a way out
5126 CMD2="$TRACE $SOCAT $opts -lpproxy tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5127 # this is our proxy connect wrapper in the protected network
5128 CMD3="$TRACE $SOCAT $opts -lpwrapper tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
5129 # this is our double client in the protected network using SSL
5130 #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"
5131 CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5132 # this is the double server in the outside network
5133 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"
5134 # this is the outside client that wants to use the protected server
5135 CMD6="$TRACE $SOCAT $opts -lpclient -t5 - tcp4:$LOCALHOST:$((PORT+4))"
5136 printf "test $F_n $TEST... " $N
5137 eval "$CMD1 2>${te}1 &"
5138 pid1=$!
5139 eval "$CMD2 2>${te}2 &"
5140 pid2=$!
5141 eval "$CMD3 2>${te}3 &"
5142 pid3=$!
5143 waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
5144 waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
5145 waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
5146 eval "$CMD5 2>${te}5 &"
5147 pid5=$!
5148 waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
5149 echo "$da" |$CMD6 >$tf 2>"${te}6" &
5150 pid6=$!
5151 waittcp4port $((PORT+3)) 1 || $PRINTF "$FAILED: port $((PORT+3))\n" >&2 </dev/null
5152 eval "$CMD4 2>${te}4 &"
5153 pid4=$!
5154 wait $pid6
5155 if ! (echo "$da"; sleep 2) |diff - "$tf" >"$tdiff"; then
5156 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5157 echo "$CMD1 &"
5158 cat "${te}1"
5159 echo "$CMD2 &"
5160 cat "${te}2"
5161 echo "$CMD3 &"
5162 cat "${te}3"
5163 echo "$CMD5 &"
5164 cat "${te}5"
5165 echo "$CMD6"
5166 cat "${te}6"
5167 echo "$CMD4 &"
5168 cat "${te}4"
5169 cat "$tdiff"
5170 numFAIL=$((numFAIL+1))
5171 listFAIL="$listFAIL $N"
5172 else
5173 $PRINTF "$OK\n"
5174 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" "${te}6"; fi
5175 numOK=$((numOK+1))
5177 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
5178 wait
5179 fi ;; # NUMCOND, feats
5180 esac
5181 PORT=$((PORT+5))
5182 N=$((N+1))
5185 # test the TCP gender changer with almost production requirements: a double
5186 # client repeatedly tries to connect to a double server via SSL through an HTTP
5187 # proxy. the double servers SSL port becomes active for one connection only
5188 # after a (real) client has connected to its TCP port. when the double client
5189 # succeeded to establish an SSL connection, it connects with its second client
5190 # side to the specified (protected) server. all three consecutive connections
5191 # must function for full success of this test.
5192 PORT=$((RANDOM+16184))
5194 NAME=INTRANETRIPPER
5195 case "$TESTS" in
5196 *%$N%*|*%functions%*|*%openssl%*|*%proxy%*|*%$NAME%*)
5197 TEST="$NAME: gender changer via SSL through HTTP proxy, daemons"
5198 if ! eval $NUMCOND; then :;
5199 elif ! feat=$(testaddrs openssl proxy); then
5200 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5201 numCANT=$((numCANT+1))
5202 else
5203 gentestcert testsrv
5204 gentestcert testcli
5205 tf="$td/test$N.stdout"
5206 te="$td/test$N.stderr"
5207 tdiff="$td/test$N.diff"
5208 da1="test$N.1 $(date) $RANDOM"
5209 da2="test$N.2 $(date) $RANDOM"
5210 da3="test$N.3 $(date) $RANDOM"
5211 # this is the server in the protected network that we want to reach
5212 CMD1="$TRACE $SOCAT $opts -lpserver -t1 tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST,fork echo"
5213 # this is the proxy in the protected network that provides a way out
5214 # note: the proxy.sh script starts one or two more socat processes without
5215 # setting the program name
5216 CMD2="$TRACE $SOCAT $opts -lpproxy -t1 tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5217 # this is our proxy connect wrapper in the protected network
5218 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"
5219 # this is our double client in the protected network using SSL
5220 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"
5221 # this is the double server in the outside network
5222 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"
5223 # this is the outside client that wants to use the protected server
5224 CMD6="$TRACE $SOCAT $opts -lpclient -t6 - tcp4:$LOCALHOST:$((PORT+4)),retry=3"
5225 printf "test $F_n $TEST... " $N
5226 # start the intranet infrastructure
5227 eval "$CMD1 2>\"${te}1\" &"
5228 pid1=$!
5229 eval "$CMD2 2>\"${te}2\" &"
5230 pid2=$!
5231 waittcp4port $PORT 1 || $PRINTF "$FAILED: port $PORT\n" >&2 </dev/null
5232 waittcp4port $((PORT+1)) 1 || $PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev/null
5233 # initiate our internal measures
5234 eval "$CMD3 2>\"${te}3\" &"
5235 pid3=$!
5236 eval "$CMD4 2>\"${te}4\" &"
5237 pid4=$!
5238 waittcp4port $((PORT+2)) 1 || $PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev/null
5239 # now we start the external daemon
5240 eval "$CMD5 2>\"${te}5\" &"
5241 pid5=$!
5242 waittcp4port $((PORT+4)) 1 || $PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev/null
5243 # and this is the outside client:
5244 echo "$da1" |$CMD6 >${tf}_1 2>"${te}6_1" &
5245 pid6_1=$!
5246 echo "$da2" |$CMD6 >${tf}_2 2>"${te}6_2" &
5247 pid6_2=$!
5248 echo "$da3" |$CMD6 >${tf}_3 2>"${te}6_3" &
5249 pid6_3=$!
5250 wait $pid6_1 $pid6_2 $pid6_3
5252 (echo "$da1"; sleep 2) |diff - "${tf}_1" >"${tdiff}1"
5253 (echo "$da2"; sleep 2) |diff - "${tf}_2" >"${tdiff}2"
5254 (echo "$da3"; sleep 2) |diff - "${tf}_3" >"${tdiff}3"
5255 if test -s "${tdiff}1" -o -s "${tdiff}2" -o -s "${tdiff}3"; then
5256 # FAILED only when none of the three transfers succeeded
5257 if test -s "${tdiff}1" -a -s "${tdiff}2" -a -s "${tdiff}3"; then
5258 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5259 echo "$CMD1 &"
5260 cat "${te}1"
5261 echo "$CMD2 &"
5262 cat "${te}2"
5263 echo "$CMD3 &"
5264 cat "${te}3"
5265 echo "$CMD4 &"
5266 cat "${te}4"
5267 echo "$CMD5 &"
5268 cat "${te}5"
5269 echo "$CMD6 &"
5270 cat "${te}6_1"
5271 cat "${tdiff}1"
5272 echo "$CMD6 &"
5273 cat "${te}6_2"
5274 cat "${tdiff}2"
5275 echo "$CMD6 &"
5276 cat "${te}6_3"
5277 cat "${tdiff}3"
5278 numFAIL=$((numFAIL+1))
5279 listFAIL="$listFAIL $N"
5280 else
5281 $PRINTF "$OK ${YELLOW}(partial failure)${NORMAL}\n"
5282 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5283 numOK=$((numOK+1))
5285 else
5286 $PRINTF "$OK\n"
5287 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5288 numOK=$((numOK+1))
5290 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev/null
5291 wait
5292 fi ;; # NUMCOND, feats
5293 esac
5294 PORT=$((PORT+5))
5295 N=$((N+1))
5298 # let us test the security features with -s, retry, and fork
5299 # method: first test without security feature if it works
5300 # then try with security feature, must fail
5302 # test the security features of a server address
5303 testserversec () {
5304 local N="$1"
5305 local title="$2"
5306 local opts="$3"
5307 local arg1="$4" # the server address
5308 local secopt0="$5" # option without security for server, mostly empty
5309 local secopt1="$6" # the security option for server, to be tested
5310 local arg2="$7" # the client address
5311 local ipvers="$8" # IP version, for check of listen port
5312 local proto="$9" # protocol, for check of listen port
5313 local port="${10}" # start client when this port is listening
5314 local expect="${11}" # expected behaviour of client: 0..empty output; -1..error
5315 local T="${12}"; [ -z "$T" ] && T=0
5316 local tf="$td/test$N.stdout"
5317 local te="$td/test$N.stderr"
5318 local tdiff1="$td/test$N.diff1"
5319 local tdiff2="$td/test$N.diff2"
5320 local da="test$N.1 $(date) $RANDOM"
5321 local stat result
5323 $PRINTF "test $F_n %s... " $N "$title"
5324 # first: without security
5325 # start server
5326 $TRACE $SOCAT $opts "$arg1,$secopt0" echo 2>"${te}1" &
5327 spid=$!
5328 if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
5329 kill $spid 2>/dev/null
5330 $PRINTF "$NO_RESULT (ph.1 server not working):\n"
5331 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5332 cat "${te}1"
5333 numCANT=$((numCANT+1))
5334 wait; return
5336 # now use client
5337 (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}2"
5338 stat="$?"
5339 kill $spid 2>/dev/null
5340 #killall $TRACE $SOCAT 2>/dev/null
5341 if [ "$stat" != 0 ]; then
5342 $PRINTF "$NO_RESULT (ph.1 function fails): $TRACE $SOCAT:\n"
5343 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5344 cat "${te}1"
5345 echo "$TRACE $SOCAT $opts - \"$arg2\""
5346 cat "${te}2"
5347 numCANT=$((numCANT+1))
5348 wait; return
5349 elif echo "$da" |diff - "$tf" >"$tdiff1" 2>&1; then
5350 : # function without security is ok, go on
5351 else
5352 $PRINTF "$NO_RESULT (ph.1 function fails): diff:\n"
5353 echo "$TRACE $SOCAT $opts $arg1,$secopt0 echo &"
5354 cat "${te}1"
5355 echo "$TRACE $SOCAT $opts - $arg2"
5356 cat "${te}2"
5357 cat "$tdiff1"
5358 numCANT=$((numCANT+1))
5359 wait; return
5362 # then: with security
5363 if [ "$port" ] && ! wait${proto}${ipvers}port $port 0; then
5364 $PRINTF "$NO_RESULT (ph.1 port remains in use)\n"
5365 numCANT=$((numCANT+1))
5366 wait; return
5368 wait
5370 #set -vx
5371 # assemble address w/ security option; on dual, take read part:
5372 case "$arg1" in
5373 *!!*) arg="${arg1%!!*},$secopt1!!${arg1#*!!}" ;;
5374 *) arg="$arg1,$secopt1" ;;
5375 esac
5376 # start server
5377 CMD3="$TRACE $SOCAT $opts $arg echo"
5378 $CMD3 2>"${te}3" &
5379 spid=$!
5380 if [ "$port" ] && ! wait${proto}${ipvers}port $port 1; then
5381 kill $spid 2>/dev/null
5382 $PRINTF "$NO_RESULT (ph.2 server not working)\n"
5383 wait
5384 echo "$CMD3"
5385 cat "${te}3"
5386 numCANT=$((numCANT+1))
5387 return
5389 # now use client
5390 da="test$N.2 $(date) $RANDOM"
5391 (echo "$da"; sleep $T) |$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}4"
5392 stat=$?
5393 kill $spid 2>/dev/null
5394 #set +vx
5395 #killall $TRACE $SOCAT 2>/dev/null
5396 if [ "$stat" != 0 ]; then
5397 result=-1; # socat had error
5398 elif [ ! -s "$tf" ]; then
5399 result=0; # empty output
5400 elif echo "$da" |diff - "$tf" >"$tdiff2" 2>&1; then
5401 result=1; # output is copy of input
5402 else
5403 result=2; # output differs from input
5405 if [ X$result != X$expect ]; then
5406 case X$result in
5407 X-1) $PRINTF "$NO_RESULT (ph.2 client error): $TRACE $SOCAT:\n"
5408 echo "$TRACE $SOCAT $opts $arg echo"
5409 cat "${te}3"
5410 echo "$TRACE $SOCAT $opts - $arg2"
5411 cat "${te}4"
5412 numCANT=$((numCANT+1)) ;;
5413 X0) $PRINTF "$NO_RESULT (ph.2 diff failed): diff:\n"
5414 echo "$TRACE $SOCAT $opts $arg echo"
5415 cat "${te}3"
5416 echo "$TRACE $SOCAT $opts - $arg2"
5417 cat "${te}4"
5418 cat "$tdiff2"
5419 numCANT=$((numCANT+1)) ;;
5420 X1) $PRINTF "$FAILED: SECURITY BROKEN\n"
5421 echo "$TRACE $SOCAT $opts $arg echo"
5422 cat "${te}3"
5423 echo "$TRACE $SOCAT $opts - $arg2"
5424 cat "${te}4"
5425 cat "$tdiff2"
5426 numFAIL=$((numFAIL+1))
5427 listFAIL="$listFAIL $N" ;;
5428 X2) $PRINTF "$FAILED: diff:\n"
5429 echo "$TRACE $SOCAT $opts $arg echo"
5430 cat "${te}3"
5431 echo "$TRACE $SOCAT $opts - $arg2"
5432 cat "${te}4"
5433 cat "$tdiff2"
5434 numFAIL=$((numFAIL+1))
5435 listFAIL="$listFAIL $N" ;;
5436 esac
5437 else
5438 $PRINTF "$OK\n"
5439 if [ -n "$debug" ]; then cat $te; fi
5440 numOK=$((numOK+1))
5442 wait
5443 #set +vx
5447 NAME=TCP4RANGEBITS
5448 case "$TESTS" in
5449 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5450 TEST="$NAME: security of TCP4-L with RANGE option"
5451 if ! eval $NUMCOND; then :;
5452 elif [ -z "$SECONDADDR" ]; then
5453 # we need access to a second addresses
5454 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5455 numCANT=$((numCANT+1))
5456 else
5457 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5458 fi ;; # $SECONDADDR, NUMCOND
5459 esac
5460 PORT=$((PORT+1))
5461 N=$((N+1))
5463 NAME=TCP4RANGEMASK
5464 case "$TESTS" in
5465 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5466 TEST="$NAME: security of TCP4-L with RANGE option"
5467 if ! eval $NUMCOND; then :;
5468 elif [ -z "$SECONDADDR" ]; then
5469 # we need access to a second addresses
5470 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5471 numCANT=$((numCANT+1))
5472 else
5473 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR:255.255.255.255" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5474 fi ;; # $SECONDADDR, NUMCOND
5475 esac
5476 PORT=$((PORT+1))
5477 N=$((N+1))
5479 # like TCP4RANGEMASK, but the "bad" address is within the same class A network
5480 NAME=TCP4RANGEMASKHAIRY
5481 case "$TESTS" in
5482 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5483 TEST="$NAME: security of TCP4-L with RANGE option"
5484 if ! eval $NUMCOND; then :; else
5485 testserversec "$N" "$TEST" "$opts -s" "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
5486 fi ;; # Linux, NUMCOND
5487 esac
5488 PORT=$((PORT+1))
5489 N=$((N+1))
5492 NAME=TCP4SOURCEPORT
5493 case "$TESTS" in
5494 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
5495 TEST="$NAME: security of TCP4-L with SOURCEPORT option"
5496 if ! eval $NUMCOND; then :; else
5497 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5498 fi ;; # NUMCOND
5499 esac
5500 PORT=$((PORT+1))
5501 N=$((N+1))
5503 NAME=TCP4LOWPORT
5504 case "$TESTS" in
5505 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
5506 TEST="$NAME: security of TCP4-L with LOWPORT option"
5507 if ! eval $NUMCOND; then :; else
5508 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5509 fi ;; # NUMCOND
5510 esac
5511 PORT=$((PORT+1))
5512 N=$((N+1))
5514 NAME=TCP4WRAPPERS_ADDR
5515 case "$TESTS" in
5516 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5517 TEST="$NAME: security of TCP4-L with TCPWRAP option"
5518 if ! eval $NUMCOND; then :;
5519 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
5520 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5521 numCANT=$((numCANT+1))
5522 else
5523 ha="$td/hosts.allow"
5524 hd="$td/hosts.deny"
5525 $ECHO "socat: $SECONDADDR" >"$ha"
5526 $ECHO "ALL: ALL" >"$hd"
5527 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
5528 fi ;; # NUMCOND, feats
5529 esac
5530 PORT=$((PORT+1))
5531 N=$((N+1))
5533 NAME=TCP4WRAPPERS_NAME
5534 case "$TESTS" in
5535 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5536 TEST="$NAME: security of TCP4-L with TCPWRAP option"
5537 if ! eval $NUMCOND; then :;
5538 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
5539 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5540 numCANT=$((numCANT+1))
5541 else
5542 ha="$td/hosts.allow"
5543 hd="$td/hosts.deny"
5544 $ECHO "socat: $LOCALHOST" >"$ha"
5545 $ECHO "ALL: ALL" >"$hd"
5546 testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp $PORT 0
5547 fi ;; # NUMCOND, feats
5548 esac
5549 PORT=$((PORT+1))
5550 N=$((N+1))
5553 NAME=TCP6RANGE
5554 case "$TESTS" in
5555 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%range%*|*%$NAME%*)
5556 TEST="$NAME: security of TCP6-L with RANGE option"
5557 if ! eval $NUMCOND; then :;
5558 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5559 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5560 numCANT=$((numCANT+1))
5561 else
5562 testserversec "$N" "$TEST" "$opts -s" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "range=[::2/128]" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5563 fi ;; # NUMCOND, feats
5564 esac
5565 PORT=$((PORT+1))
5566 N=$((N+1))
5568 NAME=TCP6SOURCEPORT
5569 case "$TESTS" in
5570 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
5571 TEST="$NAME: security of TCP6-L with SOURCEPORT option"
5572 if ! eval $NUMCOND; then :;
5573 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5574 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5575 numCANT=$((numCANT+1))
5576 else
5577 testserversec "$N" "$TEST" "$opts -s" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5578 fi ;; # NUMCOND, feats
5579 esac
5580 PORT=$((PORT+1))
5581 N=$((N+1))
5583 NAME=TCP6LOWPORT
5584 case "$TESTS" in
5585 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
5586 TEST="$NAME: security of TCP6-L with LOWPORT option"
5587 if ! eval $NUMCOND; then :;
5588 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5589 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5590 numCANT=$((numCANT+1))
5591 else
5592 testserversec "$N" "$TEST" "$opts -s" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5593 fi ;; # NUMCOND, feats
5594 esac
5595 PORT=$((PORT+1))
5596 N=$((N+1))
5598 NAME=TCP6TCPWRAP
5599 case "$TESTS" in
5600 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
5601 TEST="$NAME: security of TCP6-L with TCPWRAP option"
5602 if ! eval $NUMCOND; then :;
5603 elif ! feat=$(testaddrs tcp ip6 libwrap) || ! runsip6 >/dev/null; then
5604 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5605 numCANT=$((numCANT+1))
5606 else
5607 ha="$td/hosts.allow"
5608 hd="$td/hosts.deny"
5609 $ECHO "socat: [::2]" >"$ha"
5610 $ECHO "ALL: ALL" >"$hd"
5611 testserversec "$N" "$TEST" "$opts -s" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp6:[::1]:$PORT" 6 tcp $PORT 0
5612 fi ;; # NUMCOND, feats
5613 esac
5614 PORT=$((PORT+1))
5615 N=$((N+1))
5618 NAME=UDP4RANGE
5619 case "$TESTS" in
5620 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
5621 TEST="$NAME: security of UDP4-L with RANGE option"
5622 if ! eval $NUMCOND; then :; else
5623 #testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5624 testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5625 fi ;; # NUMCOND
5626 esac
5627 PORT=$((PORT+1))
5628 N=$((N+1))
5630 NAME=UDP4SOURCEPORT
5631 case "$TESTS" in
5632 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
5633 TEST="$NAME: security of UDP4-L with SOURCEPORT option"
5634 if ! eval $NUMCOND; then :; else
5635 testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr" "" "sp=$PORT" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5636 fi ;; # NUMCOND
5637 esac
5638 PORT=$((PORT+1))
5639 N=$((N+1))
5641 NAME=UDP4LOWPORT
5642 case "$TESTS" in
5643 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
5644 TEST="$NAME: security of UDP4-L with LOWPORT option"
5645 if ! eval $NUMCOND; then :; else
5646 testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr" "" "lowport" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5647 fi ;; # NUMCOND
5648 esac
5649 PORT=$((PORT+1))
5650 N=$((N+1))
5652 NAME=UDP4TCPWRAP
5653 case "$TESTS" in
5654 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
5655 TEST="$NAME: security of UDP4-L with TCPWRAP option"
5656 if ! eval $NUMCOND; then :;
5657 elif ! feat=$(testaddrs udp ip4 libwrap) || ! runsip4 >/dev/null; then
5658 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5659 numCANT=$((numCANT+1))
5660 else
5661 ha="$td/hosts.allow"
5662 hd="$td/hosts.deny"
5663 $ECHO "socat: $SECONDADDR" >"$ha"
5664 $ECHO "ALL: ALL" >"$hd"
5665 testserversec "$N" "$TEST" "$opts -s" "udp4-l:$PORT,reuseaddr,retry=1" "" "tcpwrap-etc=$td" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5666 fi ;; # NUMCOND, feats
5667 esac
5668 PORT=$((PORT+1))
5669 N=$((N+1))
5672 NAME=UDP6RANGE
5673 case "$TESTS" in
5674 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
5675 TEST="$NAME: security of UDP6-L with RANGE option"
5676 if ! eval $NUMCOND; then :;
5677 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5678 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5679 numCANT=$((numCANT+1))
5680 else
5681 #testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr,fork" "" "range=[::2/128]" "udp6:[::1]:$PORT" 6 udp $PORT 0
5682 testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr" "" "range=[::2/128]" "udp6:[::1]:$PORT" 6 udp $PORT 0
5683 fi ;; # NUMCOND, feats
5684 esac
5685 PORT=$((PORT+1))
5686 N=$((N+1))
5688 NAME=UDP6SOURCEPORT
5689 case "$TESTS" in
5690 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
5691 TEST="$NAME: security of UDP6-L with SOURCEPORT option"
5692 if ! eval $NUMCOND; then :;
5693 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
5694 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
5695 numCANT=$((numCANT+1))
5696 else
5697 testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr" "" "sp=$PORT" "udp6:[::1]:$PORT" 6 udp $PORT 0
5698 fi ;; # NUMCOND, feats
5699 esac
5700 PORT=$((PORT+1))
5701 N=$((N+1))
5703 NAME=UDP6LOWPORT
5704 case "$TESTS" in
5705 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
5706 TEST="$NAME: security of UDP6-L with LOWPORT option"
5707 if ! eval $NUMCOND; then :;
5708 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
5709 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
5710 numCANT=$((numCANT+1))
5711 else
5712 testserversec "$N" "$TEST" "$opts -s" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
5713 fi ;; # NUMCOND, feats
5714 esac
5715 PORT=$((PORT+1))
5716 N=$((N+1))
5718 NAME=UDP6TCPWRAP
5719 case "$TESTS" in
5720 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
5721 TEST="$NAME: security of UDP6-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 -s" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp $PORT 0
5732 fi ;; # NUMCOND, feats
5733 esac
5734 PORT=$((PORT+1))
5735 N=$((N+1))
5738 NAME=OPENSSLTCP4_RANGE
5739 case "$TESTS" in
5740 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%range%*|*%$NAME%*)
5741 TEST="$NAME: security of SSL-L over TCP/IPv4 with RANGE option"
5742 if ! eval $NUMCOND; then :;
5743 elif ! testaddrs openssl >/dev/null; then
5744 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5745 numCANT=$((numCANT+1))
5746 else
5747 gentestcert testsrv
5748 testserversec "$N" "$TEST" "$opts -s" "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
5749 fi ;; # NUMCOND, feats
5750 esac
5751 PORT=$((PORT+1))
5752 N=$((N+1))
5754 NAME=OPENSSLTCP4_SOURCEPORT
5755 case "$TESTS" in
5756 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
5757 TEST="$NAME: security of SSL-L with SOURCEPORT option"
5758 if ! eval $NUMCOND; then :;
5759 elif ! testaddrs openssl >/dev/null; then
5760 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5761 numCANT=$((numCANT+1))
5762 else
5763 gentestcert testsrv
5764 testserversec "$N" "$TEST" "$opts -s" "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
5765 fi ;; # NUMCOND, feats
5766 esac
5767 PORT=$((PORT+1))
5768 N=$((N+1))
5770 NAME=OPENSSLTCP4_LOWPORT
5771 case "$TESTS" in
5772 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%lowport%*|*%$NAME%*)
5773 TEST="$NAME: security of SSL-L with LOWPORT option"
5774 if ! eval $NUMCOND; then :;
5775 elif ! testaddrs openssl >/dev/null; then
5776 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5777 numCANT=$((numCANT+1))
5778 else
5779 gentestcert testsrv
5780 testserversec "$N" "$TEST" "$opts -s" "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
5781 fi ;; # NUMCOND, feats
5782 esac
5783 PORT=$((PORT+1))
5784 N=$((N+1))
5786 NAME=OPENSSLTCP4_TCPWRAP
5787 case "$TESTS" in
5788 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
5789 TEST="$NAME: security of SSL-L with TCPWRAP option"
5790 if ! eval $NUMCOND; then :;
5791 elif ! feat=$(testaddrs ip4 tcp libwrap openssl); then
5792 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5793 numCANT=$((numCANT+1))
5794 else
5795 gentestcert testsrv
5796 ha="$td/hosts.allow"
5797 hd="$td/hosts.deny"
5798 $ECHO "socat: $SECONDADDR" >"$ha"
5799 $ECHO "ALL: ALL" >"$hd"
5800 testserversec "$N" "$TEST" "$opts -s" "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
5801 fi ;; # NUMCOND, feats
5802 esac
5803 PORT=$((PORT+1))
5804 N=$((N+1))
5806 NAME=OPENSSLCERTSERVER
5807 case "$TESTS" in
5808 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
5809 TEST="$NAME: security of SSL-L with client certificate"
5810 if ! eval $NUMCOND; then :;
5811 elif ! testaddrs openssl >/dev/null; then
5812 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5813 numCANT=$((numCANT+1))
5814 else
5815 gentestcert testsrv
5816 gentestcert testcli
5817 testserversec "$N" "$TEST" "$opts -s" "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
5818 fi ;; # NUMCOND, feats
5819 esac
5820 PORT=$((PORT+1))
5821 N=$((N+1))
5823 NAME=OPENSSLCERTCLIENT
5824 case "$TESTS" in
5825 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%openssl%*|*%$NAME%*)
5826 TEST="$NAME: security of SSL with server certificate"
5827 if ! eval $NUMCOND; then :;
5828 elif ! testaddrs openssl >/dev/null; then
5829 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5830 numCANT=$((numCANT+1))
5831 else
5832 gentestcert testsrv
5833 gentestcert testcli
5834 testserversec "$N" "$TEST" "$opts -s -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
5835 fi ;; # NUMCOND, feats
5836 esac
5837 PORT=$((PORT+1))
5838 N=$((N+1))
5841 NAME=OPENSSLTCP6_RANGE
5842 case "$TESTS" in
5843 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%range%*|*%$NAME%*)
5844 TEST="$NAME: security of SSL-L over TCP/IPv6 with RANGE option"
5845 if ! eval $NUMCOND; then :;
5846 elif ! testaddrs openssl >/dev/null; then
5847 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5848 numCANT=$((numCANT+1))
5849 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5850 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5851 numCANT=$((numCANT+1))
5852 else
5853 gentestcert6 testsrv6
5854 testserversec "$N" "$TEST" "$opts -s" "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
5855 fi ;; # NUMCOND, feats
5856 esac
5857 PORT=$((PORT+1))
5858 N=$((N+1))
5860 NAME=OPENSSLTCP6_SOURCEPORT
5861 case "$TESTS" in
5862 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%sourceport%*|*%$NAME%*)
5863 TEST="$NAME: security of SSL-L over TCP/IPv6 with SOURCEPORT option"
5864 if ! eval $NUMCOND; then :;
5865 elif ! testaddrs openssl >/dev/null; then
5866 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5867 numCANT=$((numCANT+1))
5868 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5869 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5870 numCANT=$((numCANT+1))
5871 else
5872 gentestcert6 testsrv6
5873 testserversec "$N" "$TEST" "$opts -s" "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
5874 fi ;; # NUMCOND, feats
5875 esac
5876 PORT=$((PORT+1))
5877 N=$((N+1))
5879 NAME=OPENSSLTCP6_LOWPORT
5880 case "$TESTS" in
5881 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%lowport%*|*%$NAME%*)
5882 TEST="$NAME: security of SSL-L over TCP/IPv6 with LOWPORT option"
5883 if ! eval $NUMCOND; then :;
5884 elif ! testaddrs openssl >/dev/null; then
5885 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5886 numCANT=$((numCANT+1))
5887 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
5888 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5889 numCANT=$((numCANT+1))
5890 else
5891 gentestcert6 testsrv6
5892 testserversec "$N" "$TEST" "$opts -s" "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
5893 fi ;; # NUMCOND, feats
5894 esac
5895 PORT=$((PORT+1))
5896 N=$((N+1))
5898 NAME=OPENSSLTCP6_TCPWRAP
5899 case "$TESTS" in
5900 *%$N%*|*%functions%*|*%security%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%openssl%*|*%tcpwrap%*|*%$NAME%*)
5901 TEST="$NAME: security of SSL-L over TCP/IPv6 with TCPWRAP option"
5902 if ! eval $NUMCOND; then :;
5903 elif ! feat=$(testaddrs ip6 tcp libwrap openssl) || ! runsip6 >/dev/null; then
5904 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5905 numCANT=$((numCANT+1))
5906 else
5907 gentestcert6 testsrv6
5908 ha="$td/hosts.allow"
5909 hd="$td/hosts.deny"
5910 $ECHO "socat: [::2]" >"$ha"
5911 $ECHO "ALL: ALL" >"$hd"
5912 testserversec "$N" "$TEST" "$opts -s" "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
5913 fi ;; # NUMCOND, feats
5914 esac
5915 PORT=$((PORT+1))
5916 N=$((N+1))
5919 # test security with the openssl-commonname option on client side
5920 NAME=OPENSSL_CN_CLIENT_SECURITY
5921 case "$TESTS" in
5922 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
5923 TEST="$NAME: security of client openssl-commonname option"
5924 # connect using non matching server name/address with commonname
5925 # options, this should succeed. Then without this option, should fail
5926 if ! eval $NUMCOND; then :;
5927 elif ! testaddrs openssl >/dev/null; then
5928 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5929 numCANT=$((numCANT+1))
5930 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
5931 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
5932 numCANT=$((numCANT+1))
5933 else
5934 gentestcert testsrv
5935 gentestcert testcli
5936 testserversec "$N" "$TEST" "$opts" "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
5937 fi ;; # testaddrs, NUMCOND
5938 esac
5939 PORT=$((PORT+1))
5940 N=$((N+1))
5942 # test security with the openssl-commonname option on server side
5943 NAME=OPENSSL_CN_SERVER_SECURITY
5944 case "$TESTS" in
5945 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
5946 TEST="$NAME: security of server openssl-commonname option"
5947 # connect using with client certificate to server, this should succeed.
5948 # Then use the server with a non matching openssl-commonname option,
5949 # this must fail
5950 if ! eval $NUMCOND; then :;
5951 elif ! testaddrs openssl >/dev/null; then
5952 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5953 numCANT=$((numCANT+1))
5954 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
5955 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
5956 numCANT=$((numCANT+1))
5957 else
5958 gentestcert testsrv
5959 gentestcert testcli
5960 testserversec "$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt" "" "commonname=onlyyou" "SSL:$LOCALHOST:$PORT,verify=0,cafile=testsrv.crt,cert=testcli.crt,key=testcli.key" 4 tcp "" 0
5961 fi ;; # testaddrs, NUMCOND
5962 esac
5963 PORT=$((PORT+1))
5964 N=$((N+1))
5967 NAME=OPENSSL_FIPS_SECURITY
5968 case "$TESTS" in
5969 *%$N%*|*%functions%*|*%security%*|*%openssl%*|*%fips%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
5970 TEST="$NAME: OpenSSL restrictions by FIPS"
5971 if ! eval $NUMCOND; then :;
5972 elif ! testaddrs openssl >/dev/null; then
5973 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5974 numCANT=$((numCANT+1))
5975 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
5976 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
5977 numCANT=$((numCANT+1))
5978 elif ! testoptions fips >/dev/null; then
5979 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
5980 numCANT=$((numCANT+1))
5981 else
5982 gentestcert testsrv
5983 gentestcert testcli
5984 # openssl client accepts a "normal" certificate only when not in fips mode
5985 testserversec "$N" "$TEST" "$opts -s" "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
5986 fi ;; # testaddrs, NUMCOND
5987 esac
5988 PORT=$((PORT+1))
5989 N=$((N+1))
5992 NAME=UNIEXECEOF
5993 case "$TESTS" in
5994 *%$N%*|*%functions%*|*%$NAME%*)
5995 TEST="$NAME: give exec'd write-only process a chance to flush (-u)"
5996 testod "$N" "$TEST" "" exec:"$OD_C" "$opts -u"
5997 esac
5998 N=$((N+1))
6001 NAME=REVEXECEOF
6002 case "$TESTS" in
6003 *%$N%*|*%functions%*|*%$NAME%*)
6004 TEST="$NAME: give exec'd write-only process a chance to flush (-U)"
6005 testod "$N" "$TEST" exec:"$OD_C" "-" "$opts -U"
6006 esac
6007 N=$((N+1))
6010 NAME=FILANDIR
6011 case "$TESTS" in
6012 *%$N%*|*%filan%*|*%$NAME%*)
6013 TEST="$NAME: check type printed for directories"
6014 if ! eval $NUMCOND; then :; else
6015 te="$td/test$N.stderr"
6016 printf "test $F_n $TEST... " $N
6017 type=$($FILAN -f . 2>$te |tail -n 1 |awk '{print($2);}')
6018 if [ "$type" = "dir" ]; then
6019 $PRINTF "$OK\n"
6020 numOK=$((numOK+1))
6021 else
6022 $PRINTF "$FAILED\n"
6023 cat "$te"
6024 numFAIL=$((numFAIL+1))
6025 listFAIL="$listFAIL $N"
6027 fi ;; # NUMCOND
6028 esac
6029 N=$((N+1))
6032 NAME=FILANSOCKET
6033 case "$TESTS" in
6034 *%$N%*|*%filan%*|*%$NAME%*)
6035 TEST="$NAME: capability to analyze named unix socket"
6036 if ! eval $NUMCOND; then :; else
6037 ts="$td/test$N.socket"
6038 te1="$td/test$N.stderr1" # socat
6039 te2="$td/test$N.stderr2" # filan
6040 printf "test $F_n $TEST... " $N
6041 $TRACE $SOCAT $opts UNIX-LISTEN:"$ts" /dev/null </dev/null 2>"$te1" &
6042 spid=$!
6043 waitfile "$ts" 1
6044 type=$($FILAN -f "$ts" 2>$te2 |tail -n 1 |awk '{print($2);}')
6045 if [ "$type" = "socket" ]; then
6046 $PRINTF "$OK\n"
6047 numOK=$((numOK+1))
6048 else
6049 $PRINTF "$FAILED\n"
6050 cat "$te1"
6051 cat "$te2"
6052 numFAIL=$((numFAIL+1))
6053 listFAIL="$listFAIL $N"
6055 kill $spid 2>/dev/null
6056 wait
6057 fi ;; # NUMCOND
6058 esac
6059 N=$((N+1))
6062 testptywaitslave () {
6063 local N="$1"
6064 local TEST="$2"
6065 local PTYTYPE="$3" # ptmx or openpty
6066 local opts="$4"
6068 local tp="$td/test$N.pty"
6069 local ts="$td/test$N.socket"
6070 local tf="$td/test$N.file"
6071 local tdiff="$td/test$N.diff"
6072 local te1="$td/test$N.stderr1"
6073 local te2="$td/test$N.stderr2"
6074 local te3="$td/test$N.stderr3"
6075 local te4="$td/test$N.stderr4"
6076 local da="test$N $(date) $RANDOM"
6077 printf "test $F_n $TEST... " $N
6078 # first generate a pty, then a socket
6079 ($TRACE $SOCAT $opts -lpsocat1 pty,$PTYTYPE,pty-wait-slave,link="$tp" unix-listen:"$ts" 2>"$te1"; rm -f "$tp") 2>/dev/null &
6080 pid=$!
6081 waitfile "$tp"
6082 # if pty was non-blocking, the socket is active, and socat1 will term
6083 $TRACE $SOCAT $opts -T 10 -lpsocat2 file:/dev/null unix-connect:"$ts" 2>"$te2"
6084 # if pty is blocking, first socat is still active and we get a connection now
6085 #((echo "$da"; sleep 2) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6086 ( (waitfile "$ts"; echo "$da"; sleep 1) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6087 waitfile "$ts"
6088 # but we need an echoer on the socket
6089 $TRACE $SOCAT $opts -lpsocat4 unix:"$ts" echo 2>"$te4"
6090 # now $tf file should contain $da
6091 #kill $pid 2>/dev/null
6092 wait
6094 if echo "$da" |diff - "$tf"> "$tdiff"; then
6095 $PRINTF "$OK\n"
6096 numOK=$((numOK+1))
6097 else
6098 $PRINTF "${YELLOW}FAILED${NORMAL}\n"
6099 cat "$te1"
6100 #cat "$te2" # not of interest
6101 cat "$te3"
6102 cat "$te4"
6103 cat "$tdiff"
6104 numCANT=$((numCANT+1))
6108 NAME=PTMXWAITSLAVE
6109 PTYTYPE=ptmx
6110 case "$TESTS" in
6111 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6112 TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6113 if ! eval $NUMCOND; then :; else
6114 if ! feat=$(testaddrs pty); then
6115 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6116 numCANT=$((numCANT+1))
6117 elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
6118 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6119 numCANT=$((numCANT+1))
6120 else
6121 testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
6123 fi ;; # NUMCOND
6124 esac
6125 N=$((N+1))
6127 NAME=OPENPTYWAITSLAVE
6128 PTYTYPE=openpty
6129 case "$TESTS" in
6130 *%$N%*|*%functions%*|*%pty%*|*%$NAME%*)
6131 TEST="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6132 if ! eval $NUMCOND; then :;
6133 elif ! feat=$(testaddrs pty); then
6134 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6135 numCANT=$((numCANT+1))
6136 elif ! feat=$(testoptions "$PTYTYPE" pty-wait-slave); then
6137 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6138 numCANT=$((numCANT+1))
6139 else
6140 testptywaitslave "$N" "$TEST" "$PTYTYPE" "$opts"
6141 fi ;; # NUMCOND, feats
6142 esac
6143 N=$((N+1))
6146 NAME=CONNECTTIMEOUT
6147 case "$TESTS" in
6148 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
6149 TEST="$NAME: test the connect-timeout option"
6150 if ! eval $NUMCOND; then :;
6151 elif ! feat=$(testaddrs tcp); then
6152 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6153 numCANT=$((numCANT+1))
6154 elif ! feat=$(testoptions connect-timeout); then
6155 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6156 numCANT=$((numCANT+1))
6157 else
6158 # we need a hanging connection attempt, guess an address for this
6159 case "$UNAME" in
6160 Linux) HANGIP=1.0.0.1 ;;
6161 *) HANGIP=255.255.255.254 ;;
6162 esac
6163 te1="$td/test$N.stderr1"
6164 tk1="$td/test$N.kill1"
6165 te2="$td/test$N.stderr2"
6166 tk2="$td/test$N.kill2"
6167 $PRINTF "test $F_n $TEST... " $N
6168 # first, try to make socat hang and see if it can be killed
6169 #$TRACE $SOCAT $opts - tcp:$HANGIP:1 >"$te1" 2>&1 </dev/null &
6170 CMD="$TRACE $SOCAT $opts - tcp:$HANGIP:1"
6171 $CMD >"$te1" 2>&1 </dev/null &
6172 pid1=$!
6173 sleep 2
6174 if ! kill $pid1 2>"$tk1"; then
6175 $PRINTF "${YELLOW}does not hang${NORMAL}\n"
6176 numCANT=$((numCANT+1))
6177 else
6178 # second, set connect-timeout and see if socat exits before kill
6179 $TRACE $SOCAT $opts - tcp:$HANGIP:1,connect-timeout=1.0 >"$te2" 2>&1 </dev/null &
6180 pid2=$!
6181 sleep 2
6182 if kill $pid2 2>"$tk2"; then
6183 $PRINTF "$FAILED\n"
6184 echo "$CMD"
6185 cat "$te1"
6186 cat "$te2"
6187 numFAIL=$((numFAIL+1))
6188 listFAIL="$listFAIL $N"
6189 else
6190 $PRINTF "$OK\n"
6191 numOK=$((numOK+1))
6194 wait
6195 fi ;; # testaddrs, NUMCOND
6196 esac
6197 N=$((N+1))
6200 # version 1.7.0.0 had a bug with the connect-timeout option: while it correctly
6201 # terminated a hanging connect attempt, it prevented a successful connection
6202 # establishment from being recognized by socat, instead the timeout occurred
6203 NAME=CONNECTTIMEOUT_CONN
6204 if ! eval $NUMCOND; then :; else
6205 case "$TESTS" in
6206 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%timeout%*|*%$NAME%*)
6207 TEST="$NAME: TCP4 connect-timeout option when server replies"
6208 # just try a connection that is expected to succeed with the usual data
6209 # transfer; with the bug it will fail
6210 tf="$td/test$N.stdout"
6211 te="$td/test$N.stderr"
6212 tdiff="$td/test$N.diff"
6213 tsl=$PORT
6214 ts="127.0.0.1:$tsl"
6215 da="test$N $(date) $RANDOM"
6216 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr PIPE"
6217 CMD2="$TRACE $SOCAT $opts STDIO TCP4:$ts,connect-timeout=1"
6218 printf "test $F_n $TEST... " $N
6219 $CMD1 >"$tf" 2>"${te}1" &
6220 pid1=$!
6221 waittcp4port $tsl 1
6222 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6223 if [ $? -ne 0 ]; then
6224 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6225 echo "$CMD1 &"
6226 cat "${te}1"
6227 echo "$CMD2"
6228 cat "${te}2"
6229 numFAIL=$((numFAIL+1))
6230 listFAIL="$listFAIL $N"
6231 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6232 $PRINTF "$FAILED\n"
6233 cat "$tdiff"
6234 numFAIL=$((numFAIL+1))
6235 listFAIL="$listFAIL $N"
6236 else
6237 $PRINTF "$OK\n"
6238 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
6239 numOK=$((numOK+1))
6241 kill $pid1 2>/dev/null
6242 wait ;;
6243 esac
6244 PORT=$((PORT+1))
6245 fi # NUMCOND
6246 N=$((N+1))
6249 NAME=OPENSSLLISTENDSA
6250 case "$TESTS" in
6251 *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
6252 TEST="$NAME: openssl listen with DSA certificate"
6253 if ! eval $NUMCOND; then :;
6254 elif ! testaddrs openssl >/dev/null; then
6255 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6256 numCANT=$((numCANT+1))
6257 else
6258 SRVCERT=testsrvdsa
6259 gentestdsacert $SRVCERT
6260 tf="$td/test$N.stdout"
6261 te="$td/test$N.stderr"
6262 tdiff="$td/test$N.diff"
6263 da="test$N $(date) $RANDOM"
6264 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=$SRVCERT.pem,key=$SRVCERT.key,verify=0 pipe"
6265 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
6266 $PRINTF "test $F_n $TEST... " $N
6267 eval "$CMD2 2>\"${te}1\" &"
6268 pid=$! # background process id
6269 waittcp4port $PORT
6270 echo "$da" |$CMD >$tf 2>"${te}2"
6271 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
6272 $PRINTF "$FAILED\n"
6273 echo "$CMD2 &"
6274 echo "$CMD"
6275 cat "${te}1"
6276 cat "${te}2"
6277 cat "$tdiff"
6278 numFAIL=$((numFAIL+1))
6279 listFAIL="$listFAIL $N"
6280 else
6281 $PRINTF "$OK\n"
6282 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
6283 numOK=$((numOK+1))
6285 kill $pid 2>/dev/null
6286 wait
6287 fi ;; # testaddrs, NUMCOND
6288 esac
6289 PORT=$((PORT+1))
6290 N=$((N+1))
6293 # derive signal number from signal name
6294 # kill -l should provide the info
6295 signum () {
6296 if [ ! "$BASH_VERSION" -o -o posix ]; then
6297 # we expect:
6298 for i in $(POSIXLY_CORRECT=1 kill -l); do echo "$i"; done |grep -n -i "^$1$" |cut -d: -f1
6299 else
6300 # expect:
6301 # " 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL"
6302 signam="$1"
6303 kill -l </dev/null |
6304 while read l; do printf "%s %s\n%s %s\n%s %s\n%s %s\n" $l; done |
6305 grep -e "SIG$signam\$" |
6306 cut -d ')' -f 1
6310 # problems with QUIT, INT (are blocked in system() )
6311 for signam in TERM ILL; do
6312 NAME=EXITCODESIG$signam
6313 case "$TESTS" in
6314 *%$N%*|*%functions%*|*%pty%*|*%signal%*|*%$NAME%*)
6315 TEST="$NAME: exit status when dying on SIG$signam"
6316 if ! eval $NUMCOND; then :;
6317 elif ! feat=$(testaddrs pty); then
6318 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
6319 numCANT=$((numCANT+1))
6320 else
6321 SIG="$(signum $signam)"
6322 te="$td/test$N.stderr"
6323 tpp="$td/test$N.ppid"
6324 tp="$td/test$N.pid"
6325 $PRINTF "test $F_n $TEST... " $N
6326 (sleep 1; kill -"$SIG" "$(cat "$tpp")") &
6327 # a simple "system:echo $PPID..." does not work on NetBSD, OpenBSD
6328 #$TRACE $SOCAT $opts echo SYSTEM:'exec /bin/bash -c "echo \$PPID '">$tpp"'; echo \$$ '">$tp; read x\"",nofork 2>"$te"; stat=$?
6329 tsh="$td/test$N.sh"
6330 cat <<EOF >"$tsh"
6331 #! /bin/bash
6332 echo \$PPID >"$tpp"
6333 echo \$\$ >"$tp"
6334 read x
6336 chmod a+x "$tsh"
6337 #$TRACE $SOCAT $opts echo SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"; stat=$?
6338 CMD="$TRACE $SOCAT $opts ECHO SYSTEM:\"exec\\\ \\\"$tsh\\\"\",pty,setsid,nofork"
6339 $TRACE $SOCAT $opts ECHO SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"
6340 stat=$?
6341 sleep 1; kill -INT $(cat $tp)
6342 wait
6343 if [ "$stat" -eq $((128+$SIG)) ]; then
6344 $PRINTF "$OK\n"
6345 numOK=$((numOK+1))
6346 else
6347 $PRINTF "$FAILED\n"
6348 echo "$CMD"
6349 cat "$te"
6350 numFAIL=$((numFAIL+1))
6351 listFAIL="$listFAIL $N"
6353 wait
6354 fi ;; # NUMCOND, feats
6355 esac
6356 N=$((N+1))
6357 done
6360 NAME=READBYTES
6361 #set -vx
6362 case "$TESTS" in
6363 *%$N%*|*%functions%*|*%$NAME%*)
6364 TEST="$NAME: restrict reading from file with bytes option"
6365 if ! eval $NUMCOND; then :;
6366 elif false; then
6367 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6368 numCANT=$((numCANT+1))
6369 else
6370 tr="$td/test$N.ref"
6371 ti="$td/test$N.in"
6372 to="$td/test$N.out"
6373 te="$td/test$N.err"
6374 tdiff="$td/test$N.diff"
6375 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
6376 # the feature that we really want to test is in the readline.sh script:
6377 CMD="$TRACE $SOCAT $opts -u open:$ti,readbytes=100 -"
6378 printf "test $F_n $TEST... " $N
6379 rm -f "$tf" "$ti" "$to"
6381 echo "AAAAAAAAAAAAAAAAAAAAAAAA
6382 AAAAAAAAAAAAAAAAAAAAAAAA
6383 AAAAAAAAAAAAAAAAAAAAAAAA
6384 AAAAAAAAAAAAAAAAAAAAAAAA" >"$tr" # 100 bytes
6385 cat "$tr" "$tr" >"$ti" # 200 bytes
6386 $CMD >"$to" 2>"$te"
6387 if ! diff "$tr" "$to" >"$tdiff" 2>&1; then
6388 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6389 echo "$CMD"
6390 cat "$te"
6391 cat "$tdiff"
6392 numFAIL=$((numFAIL+1))
6393 listFAIL="$listFAIL $N"
6394 else
6395 $PRINTF "$OK\n"
6396 if [ -n "$debug" ]; then cat $te; fi
6397 numOK=$((numOK+1))
6399 fi ;; # NUMCOND, feats
6400 esac
6401 N=$((N+1))
6404 NAME=UDPLISTENFORK
6405 case "$TESTS" in
6406 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%listen%*|*%fork%*|*%$NAME%*)
6407 TEST="$NAME: UDP socket rebinds after first connection"
6408 if ! eval $NUMCOND; then :; else
6409 tf="$td/test$N.stdout"
6410 te="$td/test$N.stderr"
6411 tdiff="$td/test$N.diff"
6412 da1="test$N $(date) $RANDOM"
6413 da2="test$N $(date) $RANDOM"
6414 #establish a listening and forking udp socket in background
6415 #processes hang forever without -T
6416 SRV="$TRACE $SOCAT -T 5 $opts -lpserver UDP4-LISTEN:$PORT,bind=$LOCALHOST,fork PIPE"
6417 #make a first and a second connection
6418 CLI="$TRACE $SOCAT $opts -lpclient - UDP4-CONNECT:$LOCALHOST:$PORT"
6419 $PRINTF "test $F_n $TEST... " $N
6420 eval "$SRV 2>${te}s &"
6421 pids=$!
6422 waitudp4port "$PORT"
6423 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6424 if [ $? -ne 0 ]; then
6425 kill "$pids" 2>/dev/null
6426 $PRINTF "$NO_RESULT (first conn failed):\n"
6427 echo "$SRV &"
6428 echo "$CLI"
6429 cat "${te}s" "${te}1"
6430 numCANT=$((numCANT+1))
6431 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6432 kill "$pids" 2>/dev/null
6433 $PRINTF "$NO_RESULT (first conn failed); diff:\n"
6434 cat "$tdiff"
6435 numCANT=$((numCANT+1))
6436 else
6437 sleep 2 # UDP-LISTEN sleeps 1s
6438 echo "$da2" |eval "$CLI" >"${tf}2" 2>"${te}2"
6439 rc="$?"; kill "$pids" 2>/dev/null
6440 if [ $rc -ne 0 ]; then
6441 $PRINTF "$FAILED:\n"
6442 echo "$SRV &"
6443 echo "$CLI"
6444 cat "${te}s" "${te}2"
6445 numFAIL=$((numFAIL+1))
6446 listFAIL="$listFAIL $N"
6447 elif ! echo "$da2" |diff - "${tf}2" >"$tdiff"; then
6448 $PRINTF "$FAILED: diff\n"
6449 cat "$tdiff"
6450 numFAIL=$((numFAIL+1))
6451 listFAIL="$listFAIL $N"
6452 else
6453 $PRINTF "$OK\n"
6454 numOK=$((numOK+1))
6455 fi # !( $? -ne 0)
6456 fi # !(rc -ne 0)
6457 wait
6458 fi ;; # NUMCOND, feats
6459 esac
6460 PORT=$((PORT+1))
6461 N=$((N+1))
6464 # is a listen address capable of forking to child processes and have both
6465 # active?
6466 while read PROTOV MAJADDR MINADDR; do
6467 if [ -z "$PROTOV" ] || [[ "$PROTOV" == \#* ]]; then continue; fi
6468 protov="$(echo "$PROTOV" |tr A-Z a-z)"
6469 proto="${protov%%[0-9]}"
6470 NAME=${PROTOV}LISTENFORK
6471 case "$TESTS" in
6472 *%$N%*|*%functions%*|*%$protov%*|*%$proto%*|*%listen%*|*%fork%*|*%$NAME%*)
6473 TEST="$NAME: $PROTOV listen handles 2 concurrent connections"
6474 # have a listening address with fork option. connect with client1, send a piece
6475 # of data, wait 1s, connect with client2, send another piece of data, wait 1s,
6476 # and send another piece of data with client1. The server processes append all
6477 # data to the same file. Check all data are written to the file in correct
6478 # order.
6479 if ! eval $NUMCOND; then :;
6480 #elif ! feat=$(testaddrs $PROTOV); then
6481 # $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$PROTOV" |tr a-z A-Z) not available${NORMAL}\n" $N
6482 # numCANT=$((numCANT+1))
6483 elif ! runs$protov; then
6484 $PRINTF "test $F_n $TEST... ${YELLOW}$PROTOV not available${NORMAL}\n" $N
6485 numCANT=$((numCANT+1))
6486 else
6487 ts="$td/test$N.sock"
6488 tref="$td/test$N.ref"
6489 tf="$td/test$N.stdout"
6490 te="$td/test$N.stderr"
6491 tdiff="$td/test$N.diff"
6492 da1a="test$N $(date) 1a $RANDOM"
6493 da1b="test$N $(date) 1b $RANDOM"
6494 da2="test$N $(date) 2 $RANDOM"
6495 case "$MAJADDR" in
6496 "FILE")
6497 tla="$ts"
6498 tca="$ts"
6499 waitproto="file"
6500 waitfor="$ts" ;;
6501 esac
6502 case "$MINADDR" in
6503 "PORT")
6504 tla="$PORT,bind=$MAJADDR"
6505 tca="$MAJADDR:$PORT"
6506 waitproto="${protov}port"
6507 waitfor="$PORT" ;;
6508 esac
6509 #set -xv
6510 echo -e "$da1a\n$da2\n$da1b" >"$tref"
6511 # establish a listening and forking listen socket in background
6512 # UDP processes hang forever without -T
6513 CMD0="$TRACE $SOCAT -T 5 $opts -lpserver $PROTOV-LISTEN:$tla,fork PIPE"
6514 # make a first and a second connection
6515 CMD1="$TRACE $SOCAT $opts -lpclient - $PROTOV-CONNECT:$tca"
6516 $PRINTF "test $F_n $TEST... " $N
6517 eval "$CMD0 2>${te}0 &"
6518 pid0=$!
6519 wait$waitproto "$waitfor" 1 2
6520 (echo "$da1a"; sleep 2; echo "$da1b") |eval "$CMD1" >>"${tf}" 2>"${te}1" &
6521 sleep 1
6522 # trailing sleep req for sctp because no half close
6523 (echo "$da2"; sleep 1) |eval "$CMD1" >>"${tf}" 2>"${te}2" &
6524 sleep 2
6525 kill $pid0 2>/dev/null
6526 wait
6527 if ! diff "$tref" "$tf" >"$tdiff"; then
6528 $PRINTF "$FAILED\n"
6529 cat "${te}0" "${te}1" "${te}2"
6530 cat "$tdiff"
6531 numFAIL=$((numFAIL+1))
6532 listFAIL="$listFAIL $N"
6533 else
6534 $PRINTF "$OK\n"
6535 numOK=$((numOK+1))
6536 fi # !(rc -ne 0)
6537 wait
6538 fi ;; # NUMCOND, feats
6539 esac
6540 PORT=$((PORT+1))
6541 N=$((N+1))
6542 done <<<"
6543 TCP4 $LOCALHOST PORT
6544 TCP6 $LOCALHOST6 PORT
6545 UDP4 $LOCALHOST PORT
6546 UDP6 $LOCALHOST6 PORT
6547 SCTP4 $LOCALHOST PORT
6548 SCTP6 $LOCALHOST6 PORT
6549 UNIX FILE ,
6553 NAME=UNIXTOSTREAM
6554 case "$TESTS" in
6555 *%$N%*|*%functions%*|*%unix%*|*%listen%*|*%$NAME%*)
6556 TEST="$NAME: generic UNIX client connects to stream socket"
6557 if ! eval $NUMCOND; then :; else
6558 ts="$td/test$N.socket"
6559 tf="$td/test$N.stdout"
6560 te="$td/test$N.stderr"
6561 tdiff="$td/test$N.diff"
6562 da1="test$N $(date) $RANDOM"
6563 #establish a listening unix socket in background
6564 SRV="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
6565 #make a connection
6566 CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts\""
6567 $PRINTF "test $F_n $TEST... " $N
6568 eval "$SRV 2>${te}s &"
6569 pids=$!
6570 waitfile "$ts"
6571 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6572 if [ $? -ne 0 ]; then
6573 kill "$pids" 2>/dev/null
6574 $PRINTF "$FAILED:\n"
6575 echo "$SRV &"
6576 echo "$CLI"
6577 cat "${te}s" "${te}1"
6578 numFAIL=$((numFAIL+1))
6579 listFAIL="$listFAIL $N"
6580 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6581 kill "$pids" 2>/dev/null
6582 $PRINTF "$FAILED; diff:\n"
6583 cat "$tdiff"
6584 numFAIL=$((numFAIL+1))
6585 listFAIL="$listFAIL $N"
6586 else
6587 $PRINTF "$OK\n"
6588 numOK=$((numOK+1))
6589 fi # !(rc -ne 0)
6590 wait
6591 fi ;; # NUMCOND
6592 esac
6593 N=$((N+1))
6596 NAME=UNIXTODGRAM
6597 case "$TESTS" in
6598 *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%recv%*|*%$NAME%*)
6599 TEST="$NAME: generic UNIX client connects to datagram socket"
6600 if ! eval $NUMCOND; then :; else
6601 ts1="$td/test$N.socket1"
6602 ts2="$td/test$N.socket2"
6603 tf="$td/test$N.stdout"
6604 te="$td/test$N.stderr"
6605 tdiff="$td/test$N.diff"
6606 da1="test$N $(date) $RANDOM"
6607 #establish a receiving unix datagram socket in background
6608 SRV="$TRACE $SOCAT $opts -lpserver UNIX-RECVFROM:\"$ts1\" PIPE"
6609 #make a connection
6610 CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\",bind=\"$ts2\""
6611 #CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\""
6612 $PRINTF "test $F_n $TEST... " $N
6613 eval "$SRV 2>${te}s &"
6614 pids=$!
6615 waitfile "$ts1"
6616 echo "$da1" |eval "$CLI" >"${tf}1" 2>"${te}1"
6617 rc=$?
6618 wait
6619 if [ $rc -ne 0 ]; then
6620 kill "$pids" 2>/dev/null
6621 $PRINTF "$FAILED:\n"
6622 echo "$SRV &"
6623 cat "${te}s"
6624 echo "$CLI"
6625 cat "${te}1" "${te}1"
6626 numFAIL=$((numFAIL+1))
6627 listFAIL="$listFAIL $N"
6628 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
6629 kill "$pids" 2>/dev/null
6630 $PRINTF "$FAILED:\n"
6631 echo "$SRV &"
6632 cat "${te}s"
6633 echo "$CLI"
6634 cat "${te}1"
6635 cat "$tdiff"
6636 numFAIL=$((numFAIL+1))
6637 listFAIL="$listFAIL $N"
6638 else
6639 $PRINTF "$OK\n"
6640 numOK=$((numOK+1))
6641 fi # !(rc -ne 0)
6642 fi ;; # NUMCOND
6643 esac
6644 N=$((N+1))
6647 # there was an error in address EXEC with options pipes,stderr
6648 NAME=EXECPIPESSTDERR
6649 case "$TESTS" in
6650 *%$N%*|*%functions%*|*%$NAME%*)
6651 TEST="$NAME: simple echo via exec of cat with pipes,stderr"
6652 # this test is known to fail when logging is enabled with OPTS/opts env var.
6653 SAVE_opts="$opts"
6654 opts="$(echo "$opts" |sed 's/-d//g')"
6655 testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
6656 opts="$SAVE_opts"
6657 esac
6658 N=$((N+1))
6660 # EXEC and SYSTEM with stderr injected socat messages into the data stream.
6661 NAME=EXECSTDERRLOG
6662 case "$TESTS" in
6663 *%$N%*|*%functions%*|*%$NAME%*)
6664 TEST="$NAME: simple echo via exec of cat with pipes,stderr"
6665 SAVE_opts="$opts"
6666 # make sure at least two -d are there
6667 case "$opts" in
6668 *-d*-d*) ;;
6669 *-d*) opts="$opts -d" ;;
6670 *) opts="-d -d" ;;
6671 esac
6672 testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
6673 opts="$SAVE_opts"
6674 esac
6675 N=$((N+1))
6678 NAME=SIMPLEPARSE
6679 case "$TESTS" in
6680 *%$N%*|*%functions%*|*%PARSE%*|*%$NAME%*)
6681 TEST="$NAME: invoke socat from socat"
6682 testecho "$N" "$TEST" "" exec:"$SOCAT - exec\:$CAT,pipes" "$opts"
6683 esac
6684 N=$((N+1))
6687 NAME=FULLPARSE
6688 case "$TESTS" in
6689 *%$N%*|*%functions%*|*%parse%*|*%$NAME%*)
6690 TEST="$NAME: correctly parse special chars"
6691 if ! eval $NUMCOND; then :; else
6692 $PRINTF "test $F_n $TEST... " $N
6693 tf="$td/test$N.stdout"
6694 te="$td/test$N.stderr"
6695 tdiff="$td/test$N.diff"
6696 # a string where commas are hidden in nesting lexical constructs
6697 # if they are scanned incorrectly, socat will see an "unknown option"
6698 dain='(,)[,]{,}","([),])hugo'
6699 daout='(,)[,]{,},([),])hugo'
6700 $TRACE "$SOCAT" $opts -u "exec:echo $dain" - >"$tf" 2>"$te"
6701 rc=$?
6702 echo "$daout" |diff "$tf" - >"$tdiff"
6703 if [ "$rc" -ne 0 ]; then
6704 $PRINTF "$FAILED:\n"
6705 echo "$TRACE $SOCAT" -u "exec:echo $da" -
6706 cat "$te"
6707 numFAIL=$((numFAIL+1))
6708 listFAIL="$listFAIL $N"
6709 elif [ -s "$tdiff" ]; then
6710 $PRINTF "$FAILED:\n"
6711 echo diff:
6712 cat "$tdiff"
6713 if [ -n "$debug" ]; then cat $te; fi
6714 numFAIL=$((numFAIL+1))
6715 listFAIL="$listFAIL $N"
6716 else
6717 $PRINTF "$OK\n"
6718 if [ -n "$debug" ]; then cat $te; fi
6719 numOK=$((numOK+1))
6721 fi ;; # NUMCOND
6722 esac
6723 N=$((N+1))
6725 NAME=NESTEDSOCATEXEC
6726 case "$TESTS" in
6727 *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
6728 TEST="$NAME: does lexical analysis work sensibly (exec)"
6729 testecho "$N" "$TEST" "" "exec:'$SOCAT - exec:$CAT,pipes'" "$opts" 1
6730 esac
6731 N=$((N+1))
6733 NAME=NESTEDSOCATSYSTEM
6734 case "$TESTS" in
6735 *%parse%*|*%$N%*|*%functions%*|*%$NAME%*)
6736 TEST="$NAME: does lexical analysis work sensibly (system)"
6737 testecho "$N" "$TEST" "" "system:\"$SOCAT - exec:$CAT,pipes\"" "$opts" 1
6738 esac
6739 N=$((N+1))
6742 NAME=TCP6BYTCP4
6743 case "$TESTS" in
6744 *%$N%*|*%functions%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%$NAME%*)
6745 TEST="$NAME: TCP4 mapped into TCP6 address space"
6746 if ! eval $NUMCOND; then :;
6747 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
6748 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6749 numCANT=$((numCANT+1))
6750 else
6751 tf="$td/test$N.stdout"
6752 te="$td/test$N.stderr"
6753 tdiff="$td/test$N.diff"
6754 tsl=$PORT
6755 ts="127.0.0.1:$tsl"
6756 da="test$N $(date) $RANDOM"
6757 CMD1="$TRACE $SOCAT $opts TCP6-listen:$tsl,reuseaddr PIPE"
6758 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
6759 printf "test $F_n $TEST... " $N
6760 $CMD1 >"$tf" 2>"${te}1" &
6761 pid=$! # background process id
6762 waittcp6port $tsl 1
6763 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6764 if [ $? -ne 0 ]; then
6765 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6766 echo "$CMD1 &"
6767 echo "$CMD2"
6768 cat "${te}1"
6769 cat "${te}2"
6770 numFAIL=$((numFAIL+1))
6771 listFAIL="$listFAIL $N"
6772 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6773 $PRINTF "$FAILED: diff:\n"
6774 cat "$tdiff"
6775 numFAIL=$((numFAIL+1))
6776 listFAIL="$listFAIL $N"
6777 else
6778 $PRINTF "$OK\n"
6779 if [ -n "$debug" ]; then cat $te; fi
6780 numOK=$((numOK+1))
6782 kill $pid 2>/dev/null; wait
6783 fi ;; # NUMCOND, feats
6784 esac
6785 PORT=$((PORT+1))
6786 N=$((N+1))
6789 # test the UDP4-SENDTO and UDP4-RECVFROM addresses together
6790 NAME=UDP4DGRAM
6791 case "$TESTS" in
6792 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%$NAME%*)
6793 TEST="$NAME: UDP/IPv4 sendto and recvfrom"
6794 # start a UDP4-RECVFROM process that echoes data, and send test data using
6795 # UDP4-SENDTO. The sent data should be returned.
6796 if ! eval $NUMCOND; then :; else
6797 tf="$td/test$N.stdout"
6798 te="$td/test$N.stderr"
6799 tdiff="$td/test$N.diff"
6800 ts1p=$PORT; PORT=$((PORT+1))
6801 ts1a="127.0.0.1"
6802 ts1="$ts1a:$ts1p"
6803 ts2p=$PORT; PORT=$((PORT+1))
6804 ts2="127.0.0.1:$ts2p"
6805 da="test$N $(date) $RANDOM"
6806 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
6807 CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=$ts2"
6808 printf "test $F_n $TEST... " $N
6809 $CMD1 2>"${te}1" &
6810 pid1="$!"
6811 waitudp4port $ts1p 1
6812 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6813 rc2="$?"
6814 kill "$pid1" 2>/dev/null; wait;
6815 if [ "$rc2" -ne 0 ]; then
6816 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6817 echo "$CMD1 &"
6818 cat "${te}1"
6819 echo "$CMD2"
6820 cat "${te}2"
6821 numFAIL=$((numFAIL+1))
6822 listFAIL="$listFAIL $N"
6823 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6824 $PRINTF "$FAILED\n"
6825 cat "$tdiff"
6826 echo "$CMD1 &"
6827 cat "${te}1"
6828 echo "$CMD2"
6829 cat "${te}2"
6830 numFAIL=$((numFAIL+1))
6831 listFAIL="$listFAIL $N"
6832 else
6833 $PRINTF "$OK\n"
6834 if [ -n "$debug" ]; then cat $te; fi
6835 numOK=$((numOK+1))
6837 fi # NUMCOND
6839 esac
6840 PORT=$((PORT+1))
6841 N=$((N+1))
6844 NAME=UDP6DGRAM
6845 case "$TESTS" in
6846 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%$NAME%*)
6847 TEST="$NAME: UDP/IPv6 datagram"
6848 if ! eval $NUMCOND; then :;
6849 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
6850 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6851 numCANT=$((numCANT+1))
6852 else
6853 tf="$td/test$N.stdout"
6854 te="$td/test$N.stderr"
6855 tdiff="$td/test$N.diff"
6856 ts1p=$PORT; PORT=$((PORT+1))
6857 tsa="[::1]"
6858 ts1="$tsa:$ts1p"
6859 ts2p=$PORT; PORT=$((PORT+1))
6860 ts2="$tsa:$ts2p"
6861 da="test$N $(date) $RANDOM"
6862 CMD1="$TRACE $SOCAT $opts UDP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
6863 CMD2="$TRACE $SOCAT $opts - UDP6-SENDTO:$ts1,bind=$ts2"
6864 printf "test $F_n $TEST... " $N
6865 $CMD1 2>"${te}1" &
6866 waitudp6port $ts1p 1
6867 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6868 if [ $? -ne 0 ]; then
6869 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6870 echo "$CMD1 &"
6871 echo "$CMD2"
6872 cat "${te}1"
6873 cat "${te}2"
6874 numFAIL=$((numFAIL+1))
6875 listFAIL="$listFAIL $N"
6876 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6877 $PRINTF "$FAILED\n"
6878 cat "$tdiff"
6879 numFAIL=$((numFAIL+1))
6880 listFAIL="$listFAIL $N"
6881 else
6882 $PRINTF "$OK\n"
6883 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
6884 numOK=$((numOK+1))
6886 fi ;; # NUMCOND, feats
6887 esac
6888 PORT=$((PORT+1))
6889 N=$((N+1))
6892 NAME=RAWIP4RECVFROM
6893 case "$TESTS" in
6894 *%$N%*|*%functions%*|*%ip%*|*%ip4%*|*%rawip%*|*%rawip4%*|*%dgram%*|*%root%*|*%$NAME%*)
6895 TEST="$NAME: raw IPv4 datagram"
6896 if ! eval $NUMCOND; then :;
6897 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
6898 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
6899 numCANT=$((numCANT+1))
6900 else
6901 tf="$td/test$N.stdout"
6902 te="$td/test$N.stderr"
6903 tdiff="$td/test$N.diff"
6904 ts1p=$PROTO; PROTO=$((PROTO+1))
6905 ts1a="127.0.0.1"
6906 ts1="$ts1a:$ts1p"
6907 ts2a="$SECONDADDR"
6908 ts2="$ts2a:$ts2p"
6909 da="test$N $(date) $RANDOM"
6910 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
6911 CMD2="$TRACE $SOCAT $opts - IP4-SENDTO:$ts1,bind=$ts2a"
6912 printf "test $F_n $TEST... " $N
6913 $CMD1 2>"${te}1" &
6914 pid1=$!
6915 waitip4proto $ts1p 1
6916 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6917 rc2=$?
6918 kill $pid1 2>/dev/null; wait
6919 if [ $rc2 -ne 0 ]; then
6920 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6921 echo "$CMD1 &"
6922 echo "$CMD2"
6923 cat "${te}1"
6924 cat "${te}2"
6925 numFAIL=$((numFAIL+1))
6926 listFAIL="$listFAIL $N"
6927 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6928 $PRINTF "$FAILED\n"
6929 cat "$tdiff"
6930 numFAIL=$((numFAIL+1))
6931 listFAIL="$listFAIL $N"
6932 else
6933 $PRINTF "$OK\n"
6934 if [ -n "$debug" ]; then cat $te; fi
6935 numOK=$((numOK+1))
6937 fi ;; # root, NUMCOND
6938 esac
6939 N=$((N+1))
6942 if false; then
6943 NAME=RAWIP6RECVFROM
6944 case "$TESTS" in
6945 *%$N%*|*%functions%*|*%ip%*|*%ip6%*|*%rawip%*|*%rawip6%*|*%dgram%*|*%root%*|*%$NAME%*)
6946 TEST="$NAME: raw IPv6 datagram by self addressing"
6947 if ! eval $NUMCOND; then :;
6948 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
6949 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6950 numCANT=$((numCANT+1))
6951 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
6952 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
6953 numCANT=$((numCANT+1))
6954 else
6955 tf="$td/test$N.stdout"
6956 te="$td/test$N.stderr"
6957 tdiff="$td/test$N.diff"
6958 ts1p=$PROTO; PROTO=$((PROTO+1))
6959 tsa="[::1]"
6960 ts1="$tsa:$ts1p"
6961 ts2="$tsa"
6962 da="test$N $(date) $RANDOM"
6963 #CMD1="$TRACE $SOCAT $opts IP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
6964 CMD2="$TRACE $SOCAT $opts - IP6-SENDTO:$ts1,bind=$ts2"
6965 printf "test $F_n $TEST... " $N
6966 #$CMD1 2>"${te}1" &
6967 waitip6proto $ts1p 1
6968 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
6969 if [ $? -ne 0 ]; then
6970 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6971 # echo "$CMD1 &"
6972 # cat "${te}1"
6973 echo "$CMD2"
6974 cat "${te}2"
6975 numFAIL=$((numFAIL+1))
6976 listFAIL="$listFAIL $N"
6977 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
6978 $PRINTF "$FAILED\n"
6979 cat "$tdiff"
6980 numFAIL=$((numFAIL+1))
6981 listFAIL="$listFAIL $N"
6982 else
6983 $PRINTF "$OK\n"
6984 if [ -n "$debug" ]; then cat "$te"; fi
6985 numOK=$((numOK+1))
6987 fi ;; # root, NUMCOND
6988 esac
6989 N=$((N+1))
6990 fi #false
6993 NAME=UNIXDGRAM
6994 case "$TESTS" in
6995 *%$N%*|*%functions%*|*%engine%*|*%unix%*|*%dgram%*|*%$NAME%*)
6996 TEST="$NAME: UNIX datagram"
6997 if ! eval $NUMCOND; then :; else
6998 tf="$td/test$N.stdout"
6999 te="$td/test$N.stderr"
7000 tdiff="$td/test$N.diff"
7001 ts1="$td/test$N.socket1"
7002 ts2="$td/test$N.socket2"
7003 da="test$N $(date) $RANDOM"
7004 CMD1="$TRACE $SOCAT $opts UNIX-RECVFROM:$ts1,reuseaddr PIPE"
7005 CMD2="$TRACE $SOCAT $opts - UNIX-SENDTO:$ts1,bind=$ts2"
7006 printf "test $F_n $TEST... " $N
7007 $CMD1 2>"${te}1" &
7008 pid1="$!"
7009 waitfile $ts1 1
7010 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
7011 rc2=$?
7012 kill "$pid1" 2>/dev/null; wait
7013 if [ $rc2 -ne 0 ]; then
7014 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7015 echo "$CMD1 &"
7016 cat "${te}1"
7017 echo "$CMD2"
7018 cat "${te}2"
7019 numFAIL=$((numFAIL+1))
7020 listFAIL="$listFAIL $N"
7021 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7022 $PRINTF "$FAILED\n"
7023 cat "$tdiff"
7024 numFAIL=$((numFAIL+1))
7025 listFAIL="$listFAIL $N"
7026 else
7027 $PRINTF "$OK\n"
7028 if [ -n "$debug" ]; then cat $te; fi
7029 numOK=$((numOK+1))
7031 fi # NUMCOND
7033 esac
7034 N=$((N+1))
7037 NAME=UDP4RECV
7038 case "$TESTS" in
7039 *%$N%*|*%functions%*|*%engine%*|*%ip4%*|*%dgram%*|*%udp%*|*%udp4%*|*%recv%*|*%$NAME%*)
7040 TEST="$NAME: UDP/IPv4 receive"
7041 if ! eval $NUMCOND; then :; else
7042 tf="$td/test$N.stdout"
7043 te="$td/test$N.stderr"
7044 tdiff="$td/test$N.diff"
7045 ts1p=$PORT; PORT=$((PORT+1))
7046 ts1a="127.0.0.1"
7047 ts1="$ts1a:$ts1p"
7048 da="test$N $(date) $RANDOM"
7049 CMD1="$TRACE $SOCAT $opts -u UDP4-RECV:$ts1p,reuseaddr -"
7050 CMD2="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1"
7051 printf "test $F_n $TEST... " $N
7052 $CMD1 >"$tf" 2>"${te}1" &
7053 pid1="$!"
7054 waitudp4port $ts1p 1
7055 echo "$da" |$CMD2 2>>"${te}2"
7056 rc2="$?"
7057 #ls -l $tf
7058 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7059 kill "$pid1" 2>/dev/null; wait
7060 if [ "$rc2" -ne 0 ]; then
7061 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7062 echo "$CMD1 &"
7063 echo "$CMD2"
7064 cat "${te}1"
7065 cat "${te}2"
7066 numFAIL=$((numFAIL+1))
7067 listFAIL="$listFAIL $N"
7068 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7069 $PRINTF "$FAILED\n"
7070 cat "$tdiff"
7071 echo "$CMD1 &"
7072 echo "$CMD2"
7073 cat "${te}1"
7074 cat "${te}2"
7075 numFAIL=$((numFAIL+1))
7076 listFAIL="$listFAIL $N"
7077 else
7078 $PRINTF "$OK\n"
7079 if [ -n "$debug" ]; then cat $te; fi
7080 numOK=$((numOK+1))
7082 fi # NUMCOND
7084 esac
7085 N=$((N+1))
7088 NAME=UDP6RECV
7089 case "$TESTS" in
7090 *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%udp%*|*%udp6%*|*%recv%*|*%$NAME%*)
7091 TEST="$NAME: UDP/IPv6 receive"
7092 if ! eval $NUMCOND; then :;
7093 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
7094 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7095 numCANT=$((numCANT+1))
7096 else
7097 tf="$td/test$N.stdout"
7098 te="$td/test$N.stderr"
7099 tdiff="$td/test$N.diff"
7100 ts1p=$PORT; PORT=$((PORT+1))
7101 ts1a="[::1]"
7102 ts1="$ts1a:$ts1p"
7103 da="test$N $(date) $RANDOM"
7104 CMD1="$TRACE $SOCAT $opts -u UDP6-RECV:$ts1p,reuseaddr -"
7105 CMD2="$TRACE $SOCAT $opts -u - UDP6-SENDTO:$ts1"
7106 printf "test $F_n $TEST... " $N
7107 $CMD1 >"$tf" 2>"${te}1" &
7108 pid1="$!"
7109 waitudp6port $ts1p 1
7110 echo "$da" |$CMD2 2>>"${te}2"
7111 rc2="$?"
7112 #ls -l $tf
7113 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7114 kill "$pid1" 2>/dev/null; wait
7115 if [ "$rc2" -ne 0 ]; then
7116 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7117 echo "$CMD1 &"
7118 echo "$CMD2"
7119 cat "${te}1"
7120 cat "${te}2"
7121 numFAIL=$((numFAIL+1))
7122 listFAIL="$listFAIL $N"
7123 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7124 $PRINTF "$FAILED\n"
7125 cat "$tdiff"
7126 numFAIL=$((numFAIL+1))
7127 listFAIL="$listFAIL $N"
7128 else
7129 $PRINTF "$OK\n"
7130 if [ -n "$debug" ]; then cat $te; fi
7131 numOK=$((numOK+1))
7133 fi ;; # NUMCOND, feats
7134 esac
7135 N=$((N+1))
7138 NAME=RAWIP4RECV
7139 case "$TESTS" in
7140 *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
7141 TEST="$NAME: raw IPv4 receive"
7142 if ! eval $NUMCOND; then :;
7143 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7144 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7145 numCANT=$((numCANT+1))
7146 else
7147 tf="$td/test$N.stdout"
7148 te="$td/test$N.stderr"
7149 tdiff="$td/test$N.diff"
7150 ts1p=$PROTO; PROTO=$((PROTO+1))
7151 ts1a="127.0.0.1"
7152 ts1="$ts1a:$ts1p"
7153 da="test$N $(date) $RANDOM"
7154 CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,reuseaddr -"
7155 CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
7156 printf "test $F_n $TEST... " $N
7157 $CMD1 >"$tf" 2>"${te}1" &
7158 pid1="$!"
7159 waitip4proto $ts1p 1
7160 echo "$da" |$CMD2 2>>"${te}2"
7161 rc2="$?"
7162 #ls -l $tf
7163 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7164 kill "$pid1" 2>/dev/null; wait
7165 if [ "$rc2" -ne 0 ]; then
7166 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7167 echo "$CMD1 &"
7168 echo "$CMD2"
7169 cat "${te}1"
7170 cat "${te}2"
7171 numFAIL=$((numFAIL+1))
7172 listFAIL="$listFAIL $N"
7173 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7174 $PRINTF "$FAILED\n"
7175 cat "$tdiff"
7176 numFAIL=$((numFAIL+1))
7177 listFAIL="$listFAIL $N"
7178 else
7179 $PRINTF "$OK\n"
7180 if [ -n "$debug" ]; then cat $te; fi
7181 numOK=$((numOK+1))
7183 fi ;; # NUMCOND, root
7184 esac
7185 N=$((N+1))
7188 NAME=RAWIP6RECV
7189 case "$TESTS" in
7190 *%$N%*|*%functions%*|*%ip6%*|*%dgram%*|*%rawip%*|*%rawip6%*|*%recv%*|*%root%*|*%$NAME%*)
7191 TEST="$NAME: raw IPv6 receive"
7192 if ! eval $NUMCOND; then :;
7193 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7194 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7195 numCANT=$((numCANT+1))
7196 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7197 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7198 numCANT=$((numCANT+1))
7199 else
7200 tf="$td/test$N.stdout"
7201 te="$td/test$N.stderr"
7202 tdiff="$td/test$N.diff"
7203 ts1p=$PROTO; PROTO=$((PROTO+1))
7204 ts1a="[::1]"
7205 ts1="$ts1a:$ts1p"
7206 da="test$N $(date) $RANDOM"
7207 CMD1="$TRACE $SOCAT $opts -u IP6-RECV:$ts1p,reuseaddr -"
7208 CMD2="$TRACE $SOCAT $opts -u - IP6-SENDTO:$ts1"
7209 printf "test $F_n $TEST... " $N
7210 $CMD1 >"$tf" 2>"${te}1" &
7211 pid1="$!"
7212 waitip6proto $ts1p 1
7213 echo "$da" |$CMD2 2>>"${te}2"
7214 rc2="$?"
7215 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7216 kill "$pid1" 2>/dev/null; wait
7217 if [ "$rc2" -ne 0 ]; then
7218 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7219 echo "$CMD1 &"
7220 echo "$CMD2"
7221 cat "${te}1"
7222 cat "${te}2"
7223 numFAIL=$((numFAIL+1))
7224 listFAIL="$listFAIL $N"
7225 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7226 $PRINTF "$FAILED\n"
7227 cat "$tdiff"
7228 numFAIL=$((numFAIL+1))
7229 listFAIL="$listFAIL $N"
7230 else
7231 $PRINTF "$OK\n"
7232 if [ -n "$debug" ]; then cat $te; fi
7233 numOK=$((numOK+1))
7235 fi ;; # NUMCOND, root
7236 esac
7237 N=$((N+1))
7240 NAME=UNIXRECV
7241 case "$TESTS" in
7242 *%$N%*|*%functions%*|*%unix%*|*%dgram%*|*%recv%*|*%$NAME%*)
7243 TEST="$NAME: UNIX receive"
7244 if ! eval $NUMCOND; then :; else
7245 ts="$td/test$N.socket"
7246 tf="$td/test$N.stdout"
7247 te="$td/test$N.stderr"
7248 tdiff="$td/test$N.diff"
7249 ts1="$ts"
7250 da="test$N $(date) $RANDOM"
7251 CMD1="$TRACE $SOCAT $opts -u UNIX-RECV:$ts1,reuseaddr -"
7252 CMD2="$TRACE $SOCAT $opts -u - UNIX-SENDTO:$ts1"
7253 printf "test $F_n $TEST... " $N
7254 $CMD1 >"$tf" 2>"${te}1" &
7255 pid1="$!"
7256 waitfile $ts1 1
7257 echo "$da" |$CMD2 2>>"${te}2"
7258 rc2="$?"
7259 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
7260 kill "$pid1" 2>/dev/null; wait
7261 if [ "$rc2" -ne 0 ]; then
7262 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7263 echo "$CMD1 &"
7264 echo "$CMD2"
7265 cat "${te}1"
7266 cat "${te}2"
7267 numFAIL=$((numFAIL+1))
7268 listFAIL="$listFAIL $N"
7269 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
7270 $PRINTF "$FAILED\n"
7271 cat "$tdiff"
7272 numFAIL=$((numFAIL+1))
7273 listFAIL="$listFAIL $N"
7274 else
7275 $PRINTF "$OK\n"
7276 if [ -n "$debug" ]; then cat $te; fi
7277 numOK=$((numOK+1))
7279 fi # NUMCOND
7281 esac
7282 N=$((N+1))
7285 NAME=UDP4RECVFROM_SOURCEPORT
7286 case "$TESTS" in
7287 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
7288 TEST="$NAME: security of UDP4-RECVFROM with SOURCEPORT option"
7289 if ! eval $NUMCOND; then :;
7290 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7291 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7292 numCANT=$((numCANT+1))
7293 else
7294 testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7295 fi ;; # NUMCOND, feats
7296 esac
7297 PORT=$((PORT+1))
7298 N=$((N+1))
7300 NAME=UDP4RECVFROM_LOWPORT
7301 case "$TESTS" in
7302 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
7303 TEST="$NAME: security of UDP4-RECVFROM with LOWPORT option"
7304 if ! eval $NUMCOND; then :;
7305 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7306 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7307 numCANT=$((numCANT+1))
7308 else
7309 testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr" "" "lowport" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7310 fi ;; # NUMCOND, feats
7311 esac
7312 PORT=$((PORT+1))
7313 N=$((N+1))
7315 NAME=UDP4RECVFROM_RANGE
7316 case "$TESTS" in
7317 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
7318 TEST="$NAME: security of UDP4-RECVFROM with RANGE option"
7319 #testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7320 if ! eval $NUMCOND; then :; else
7321 testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7322 fi ;; # NUMCOND
7323 esac
7324 PORT=$((PORT+1))
7325 N=$((N+1))
7327 NAME=UDP4RECVFROM_TCPWRAP
7328 case "$TESTS" in
7329 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
7330 TEST="$NAME: security of UDP4-RECVFROM with TCPWRAP option"
7331 if ! eval $NUMCOND; then :;
7332 elif ! feat=$(testaddrs ip4 udp libwrap) || ! runsip4 >/dev/null; then
7333 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7334 numCANT=$((numCANT+1))
7335 else
7336 ha="$td/hosts.allow"
7337 hd="$td/hosts.deny"
7338 $ECHO "socat: $SECONDADDR" >"$ha"
7339 $ECHO "ALL: ALL" >"$hd"
7340 #testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "tcpwrap=$d" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7341 testserversec "$N" "$TEST" "$opts -s" "udp4-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7342 fi ;; # NUMCOND, feats
7343 esac
7344 PORT=$((PORT+1))
7345 N=$((N+1))
7348 NAME=UDP4RECV_SOURCEPORT
7349 case "$TESTS" in
7350 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%sourceport%*|*%$NAME%*)
7351 TEST="$NAME: security of UDP4-RECV with SOURCEPORT option"
7352 if ! eval $NUMCOND; then :;
7353 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7354 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7355 numCANT=$((numCANT+1))
7356 else
7357 PORT1=$PORT; PORT=$((PORT+1))
7358 PORT2=$PORT; PORT=$((PORT+1))
7359 PORT3=$PORT
7360 # we use the forward channel (PORT1) for testing, and have a backward channel
7361 # (PORT2) to get the data back, so we get the classical echo behaviour
7362 testserversec "$N" "$TEST" "$opts -s" "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
7363 fi ;; # NUMCOND, feats
7364 esac
7365 PORT=$((PORT+1))
7366 N=$((N+1))
7368 NAME=UDP4RECV_LOWPORT
7369 case "$TESTS" in
7370 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%lowport%*|*%$NAME%*)
7371 TEST="$NAME: security of UDP4-RECV with LOWPORT option"
7372 if ! eval $NUMCOND; then :;
7373 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7374 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7375 numCANT=$((numCANT+1))
7376 else
7377 PORT1=$PORT; PORT=$((PORT+1))
7378 PORT2=$PORT
7379 # we use the forward channel (PORT1) for testing, and have a backward channel
7380 # (PORT2) to get the data back, so we get the classical echo behaviour
7381 testserversec "$N" "$TEST" "$opts -s" "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
7382 fi ;; # NUMCOND, feats
7383 esac
7384 PORT=$((PORT+1))
7385 N=$((N+1))
7387 NAME=UDP4RECV_RANGE
7388 case "$TESTS" in
7389 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%range%*|*%$NAME%*)
7390 TEST="$NAME: security of UDP4-RECV with RANGE option"
7391 if ! eval $NUMCOND; then :;
7392 elif ! feat=$(testaddrs udp ip4) || ! runsip4 >/dev/null; then
7393 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7394 numCANT=$((numCANT+1))
7395 else
7396 PORT1=$PORT; PORT=$((PORT+1))
7397 PORT2=$PORT
7398 # we use the forward channel (PORT1) for testing, and have a backward channel
7399 # (PORT2) to get the data back, so we get the classical echo behaviour
7400 testserversec "$N" "$TEST" "$opts -s" "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
7401 fi ;; # NUMCOND, feats
7402 esac
7403 PORT=$((PORT+1))
7404 N=$((N+1))
7406 NAME=UDP4RECV_TCPWRAP
7407 case "$TESTS" in
7408 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
7409 TEST="$NAME: security of UDP4-RECV with TCPWRAP option"
7410 if ! eval $NUMCOND; then :;
7411 elif ! feat=$(testaddrs udp ip4 libwrap) || ! runsip4 >/dev/null; then
7412 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7413 numCANT=$((numCANT+1))
7414 else
7415 PORT1=$PORT; PORT=$((PORT+1))
7416 PORT2=$PORT
7417 ha="$td/hosts.allow"
7418 hd="$td/hosts.deny"
7419 $ECHO "socat: $SECONDADDR" >"$ha"
7420 $ECHO "ALL: ALL" >"$hd"
7421 # we use the forward channel (PORT1) for testing, and have a backward channel
7422 # (PORT2) to get the data back, so we get the classical echo behaviour
7423 testserversec "$N" "$TEST" "$opts -s" "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
7424 fi ;; # NUMCOND, feats
7425 esac
7426 PORT=$((PORT+1))
7427 N=$((N+1))
7430 NAME=UDP6RECVFROM_SOURCEPORT
7431 case "$TESTS" in
7432 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
7433 TEST="$NAME: security of UDP6-RECVFROM with SOURCEPORT option"
7434 if ! eval $NUMCOND; then :;
7435 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7436 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7437 numCANT=$((numCANT+1))
7438 else
7439 testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7440 fi ;; # NUMCOND, feats
7441 esac
7442 PORT=$((PORT+1))
7443 N=$((N+1))
7445 NAME=UDP6RECVFROM_LOWPORT
7446 case "$TESTS" in
7447 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
7448 TEST="$NAME: security of UDP6-RECVFROM with LOWPORT option"
7449 if ! eval $NUMCOND; then :;
7450 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7451 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7452 numCANT=$((numCANT+1))
7453 else
7454 testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr" "" "lowport" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7455 fi ;; # NUMCOND, feats
7456 esac
7457 PORT=$((PORT+1))
7458 N=$((N+1))
7460 NAME=UDP6RECVFROM_RANGE
7461 case "$TESTS" in
7462 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
7463 TEST="$NAME: security of UDP6-RECVFROM with RANGE option"
7464 if ! eval $NUMCOND; then :;
7465 elif ! feat=$(testaddrs tcp ip6) || ! runsip6 >/dev/null; then
7466 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7467 numCANT=$((numCANT+1))
7468 else
7469 #testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr,fork" "" "range=[::2/128]" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7470 testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr" "" "range=[::2/128]" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7471 fi ;; # NUMCOND, feats
7472 esac
7473 PORT=$((PORT+1))
7474 N=$((N+1))
7476 NAME=UDP6RECVFROM_TCPWRAP
7477 case "$TESTS" in
7478 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
7479 TEST="$NAME: security of UDP6-RECVFROM with TCPWRAP option"
7480 if ! eval $NUMCOND; then :;
7481 elif ! feat=$(testaddrs udp ip6 libwrap) || ! runsip6 >/dev/null; then
7482 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7483 numCANT=$((numCANT+1))
7484 else
7485 ha="$td/hosts.allow"
7486 hd="$td/hosts.deny"
7487 $ECHO "socat: [::2]" >"$ha"
7488 $ECHO "ALL: ALL" >"$hd"
7489 testserversec "$N" "$TEST" "$opts -s" "udp6-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7490 fi ;; # NUMCOND, feats
7491 esac
7492 PORT=$((PORT+1))
7493 N=$((N+1))
7496 NAME=UDP6RECV_SOURCEPORT
7497 case "$TESTS" in
7498 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%sourceport%*|*%$NAME%*)
7499 TEST="$NAME: security of UDP6-RECV with SOURCEPORT option"
7500 if ! eval $NUMCOND; then :;
7501 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7502 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7503 numCANT=$((numCANT+1))
7504 else
7505 PORT1=$PORT; PORT=$((PORT+1))
7506 PORT2=$PORT; PORT=$((PORT+1))
7507 PORT3=$PORT
7508 # we use the forward channel (PORT1) for testing, and have a backward channel
7509 # (PORT2) to get the data back, so we get the classical echo behaviour
7510 testserversec "$N" "$TEST" "$opts -s" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "sp=$PORT3" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
7511 fi ;; # NUMCOND, feats
7512 esac
7513 PORT=$((PORT+1))
7514 N=$((N+1))
7516 NAME=UDP6RECV_LOWPORT
7517 case "$TESTS" in
7518 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%lowport%*|*%$NAME%*)
7519 TEST="$NAME: security of UDP6-RECV with LOWPORT option"
7520 if ! eval $NUMCOND; then :;
7521 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7522 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7523 numCANT=$((numCANT+1))
7524 else
7525 PORT1=$PORT; PORT=$((PORT+1))
7526 PORT2=$PORT
7527 # we use the forward channel (PORT1) for testing, and have a backward channel
7528 # (PORT2) to get the data back, so we get the classical echo behaviour
7529 testserversec "$N" "$TEST" "$opts -s" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "lowport" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
7530 fi ;; # NUMCOND, feats
7531 esac
7532 PORT=$((PORT+1))
7533 N=$((N+1))
7535 NAME=UDP6RECV_RANGE
7536 case "$TESTS" in
7537 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%range%*|*%$NAME%*)
7538 TEST="$NAME: security of UDP6-RECV with RANGE option"
7539 if ! eval $NUMCOND; then :;
7540 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
7541 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7542 numCANT=$((numCANT+1))
7543 else
7544 PORT1=$PORT; PORT=$((PORT+1))
7545 PORT2=$PORT
7546 # we use the forward channel (PORT1) for testing, and have a backward channel
7547 # (PORT2) to get the data back, so we get the classical echo behaviour
7548 testserversec "$N" "$TEST" "$opts -s" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "range=[::2/128]" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
7549 fi ;; # NUMCOND, feats
7550 esac
7551 PORT=$((PORT+1))
7552 N=$((N+1))
7554 NAME=UDP6RECV_TCPWRAP
7555 case "$TESTS" in
7556 *%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
7557 TEST="$NAME: security of UDP6-RECV with TCPWRAP option"
7558 if ! eval $NUMCOND; then :;
7559 elif ! feat=$(testaddrs udp ip6 libwrap) || ! runsip6 >/dev/null; then
7560 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7561 numCANT=$((numCANT+1))
7562 else
7563 ha="$td/hosts.allow"
7564 hd="$td/hosts.deny"
7565 $ECHO "socat: [::2]" >"$ha"
7566 $ECHO "ALL: ALL" >"$hd"
7567 PORT1=$PORT; PORT=$((PORT+1))
7568 PORT2=$PORT
7569 # we use the forward channel (PORT1) for testing, and have a backward channel
7570 # (PORT2) to get the data back, so we get the classical echo behaviour
7571 testserversec "$N" "$TEST" "$opts -s" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "tcpwrap-etc=$td" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp $PORT1 0
7572 fi ;; # NUMCOND, feats
7573 esac
7574 PORT=$((PORT+1))
7575 N=$((N+1))
7578 NAME=IP4RECVFROM_RANGE
7579 case "$TESTS" in
7580 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
7581 TEST="$NAME: security of IP4-RECVFROM with RANGE option"
7582 if ! eval $NUMCOND; then :;
7583 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
7584 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7585 numCANT=$((numCANT+1))
7586 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7587 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7588 numCANT=$((numCANT+1))
7589 else
7590 #testserversec "$N" "$TEST" "$opts -s" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "range=$SECONDADDR/32" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7591 testserversec "$N" "$TEST" "$opts -s" "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
7592 fi ;; # NUMCOND, feats, root
7593 esac
7594 PROTO=$((PROTO+1))
7595 PORT=$((PORT+1))
7596 N=$((N+1))
7598 NAME=IP4RECVFROM_TCPWRAP
7599 case "$TESTS" in
7600 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7601 TEST="$NAME: security of IP4-RECVFROM with TCPWRAP option"
7602 if ! eval $NUMCOND; then :;
7603 elif ! feat=$(testaddrs ip4 rawip libwrap) || ! runsip4 >/dev/null; then
7604 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7605 numCANT=$((numCANT+1))
7606 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7607 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7608 numCANT=$((numCANT+1))
7609 else
7610 ha="$td/hosts.allow"
7611 hd="$td/hosts.deny"
7612 $ECHO "socat: $SECONDADDR" >"$ha"
7613 $ECHO "ALL: ALL" >"$hd"
7614 #testserversec "$N" "$TEST" "$opts -s" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7615 testserversec "$N" "$TEST" "$opts -s" "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
7616 fi # NUMCOND, feats, root
7618 esac
7619 PROTO=$((PROTO+1))
7620 PORT=$((PORT+1))
7621 N=$((N+1))
7624 NAME=IP4RECV_RANGE
7625 case "$TESTS" in
7626 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%range%*|*%root%*|*%$NAME%*)
7627 TEST="$NAME: security of IP4-RECV with RANGE option"
7628 if ! eval $NUMCOND; then :;
7629 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
7630 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
7631 numCANT=$((numCANT+1))
7632 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7633 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7634 numCANT=$((numCANT+1))
7635 else
7636 PROTO1=$PROTO; PROTO=$((PROTO+1))
7637 PROTO2=$PROTO
7638 # we use the forward channel (PROTO1) for testing, and have a backward channel
7639 # (PROTO2) to get the data back, so we get the classical echo behaviour
7640 testserversec "$N" "$TEST" "$opts -s" "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
7641 fi ;; # NUMCOND, feats, root
7642 esac
7643 PROTO=$((PROTO+1))
7644 N=$((N+1))
7648 NAME=IP4RECV_TCPWRAP
7649 case "$TESTS" in
7650 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip4%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7651 TEST="$NAME: security of IP4-RECV with TCPWRAP option"
7652 if ! eval $NUMCOND; then :;
7653 elif ! feat=$(testaddrs ip4 rawip libwrap) || ! runsip4 >/dev/null; then
7654 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7655 numCANT=$((numCANT+1))
7656 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7657 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7658 numCANT=$((numCANT+1))
7659 else
7660 PROTO1=$PROTO; PROTO=$((PROTO+1))
7661 PROTO2=$PROTO
7662 ha="$td/hosts.allow"
7663 hd="$td/hosts.deny"
7664 $ECHO "socat: $SECONDADDR" >"$ha"
7665 $ECHO "ALL: ALL" >"$hd"
7666 # we use the forward channel (PROTO1) for testing, and have a backward channel
7667 # (PROTO2) to get the data back, so we get the classical echo behaviour
7668 testserversec "$N" "$TEST" "$opts -s" "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
7669 fi ;; # NUMCOND, feats, root
7670 esac
7671 PROTO=$((PROTO+1))
7672 N=$((N+1))
7675 NAME=IP6RECVFROM_RANGE
7676 case "$TESTS" in
7677 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
7678 TEST="$NAME: security of IP6-RECVFROM with RANGE option"
7679 if ! eval $NUMCOND; then :;
7680 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7681 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7682 numCANT=$((numCANT+1))
7683 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7684 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7685 numCANT=$((numCANT+1))
7686 else
7687 #testserversec "$N" "$TEST" "$opts -s" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "range=[::2/128]" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7688 testserversec "$N" "$TEST" "$opts -s" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "range=[::2/128]" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7689 fi ;; # NUMCOND, feats
7690 esac
7691 PROTO=$((PROTO+1))
7692 PORT=$((PORT+1))
7693 N=$((N+1))
7695 NAME=IP6RECVFROM_TCPWRAP
7696 case "$TESTS" in
7697 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7698 TEST="$NAME: security of IP6-RECVFROM with TCPWRAP option"
7699 if ! eval $NUMCOND; then :;
7700 elif ! feat=$(testaddrs ip6 rawip libwrap) || ! runsip6 >/dev/null; then
7701 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7702 numCANT=$((numCANT+1))
7703 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7704 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7705 numCANT=$((numCANT+1))
7706 else
7707 ha="$td/hosts.allow"
7708 hd="$td/hosts.deny"
7709 $ECHO "socat: [::2]" >"$ha"
7710 $ECHO "ALL: ALL" >"$hd"
7711 #testserversec "$N" "$TEST" "$opts -s" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7712 testserversec "$N" "$TEST" "$opts -s" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "tcpwrap-etc=$td" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7713 fi ;; # NUMCOND, feats
7714 esac
7715 PROTO=$((PROTO+1))
7716 PORT=$((PORT+1))
7717 N=$((N+1))
7720 NAME=IP6RECV_RANGE
7721 case "$TESTS" in
7722 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%range%*|*%root%*|*%$NAME%*)
7723 TEST="$NAME: security of IP6-RECV with RANGE option"
7724 if ! eval $NUMCOND; then :;
7725 elif ! feat=$(testaddrs ip6 rawip) || ! runsip6 >/dev/null; then
7726 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP6 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 PROTO1=$PROTO; PROTO=$((PROTO+1))
7733 PROTO2=$PROTO
7734 # we use the forward channel (PROTO1) for testing, and have a backward channel
7735 # (PROTO2) to get the data back, so we get the classical echo behaviour
7736 testserversec "$N" "$TEST" "$opts -s" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "range=[::2/128]" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip $PROTO1 0
7737 fi ;; # NUMCOND, feats
7738 esac
7739 PROTO=$((PROTO+1))
7740 N=$((N+1))
7742 NAME=IP6RECV_TCPWRAP
7743 case "$TESTS" in
7744 *%$N%*|*%functions%*|*%security%*|*%ip%*|*%ip6%*|*%tcpwrap%*|*%root%*|*%$NAME%*)
7745 TEST="$NAME: security of IP6-RECV with TCPWRAP option"
7746 if ! eval $NUMCOND; then :;
7747 elif ! feat=$(testaddrs ip6 rawip libwrap) || ! runsip6 >/dev/null; then
7748 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7749 numCANT=$((numCANT+1))
7750 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
7751 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7752 numCANT=$((numCANT+1))
7753 else
7754 PROTO1=$PROTO; PROTO=$((PROTO+1))
7755 PROTO2=$PROTO
7756 ha="$td/hosts.allow"
7757 hd="$td/hosts.deny"
7758 $ECHO "socat: [::2]" >"$ha"
7759 $ECHO "ALL: ALL" >"$hd"
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 -s" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "tcpwrap-etc=$td" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip $PROTO1 0
7763 fi ;; # NUMCOND, feats
7764 esac
7765 PROTO=$((PROTO+1))
7766 N=$((N+1))
7769 NAME=O_NOATIME_FILE
7770 case "$TESTS" in
7771 *%$N%*|*%functions%*|*%open%*|*%noatime%*|*%$NAME%*)
7772 TEST="$NAME: option O_NOATIME on file"
7773 # idea: create a file with o-noatime option; one second later create a file
7774 # without this option (using touch); one second later read from the first file.
7775 # Then we check which file has the later ATIME stamp. For this check we use
7776 # "ls -ltu" because it is more portable than "test ... -nt ..."
7777 if ! eval $NUMCOND; then :;
7778 elif ! testoptions o-noatime >/dev/null; then
7779 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
7780 numCANT=$((numCANT+1))
7781 else
7782 tf="$td/test$N.file"
7783 te="$td/test$N.stderr"
7784 tdiff="$td/test$N.diff"
7785 da="test$N $(date) $RANDOM"
7786 $PRINTF "test $F_n $TEST... " $N
7787 CMD="$TRACE $SOCAT $opts -u open:\"${tf}1\",o-noatime /dev/null"
7788 # generate a file
7789 touch "${tf}1"
7790 sleep 1
7791 # generate a reference file
7792 touch "${tf}2"
7793 sleep 1
7794 # read from the first file
7795 $CMD 2>"$te"
7796 if [ $? -ne 0 ]; then # command failed
7797 $PRINTF "${FAILED}:\n"
7798 echo "$CMD"
7799 cat "$te"
7800 numFAIL=$((numFAIL+1))
7801 listFAIL="$listFAIL $N"
7802 else
7803 # check which file has a later atime stamp
7804 if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
7805 then
7806 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7807 echo "$CMD"
7808 cat "$te"
7809 numFAIL=$((numFAIL+1))
7810 listFAIL="$listFAIL $N"
7811 else
7812 $PRINTF "$OK\n"
7813 if [ -n "$debug" ]; then cat "$te"; fi
7814 numOK=$((numOK+1))
7815 fi # wrong time stamps
7816 fi # command ok
7817 fi ;; # NUMCOND, feats
7818 esac
7819 N=$((N+1))
7821 NAME=O_NOATIME_FD
7822 case "$TESTS" in
7823 *%$N%*|*%functions%*|*%noatime%*|*%$NAME%*)
7824 TEST="$NAME: option O_NOATIME on file descriptor"
7825 # idea: use a fd of a file with o-noatime option; one second later create a file
7826 # without this option (using touch); one second later read from the first file.
7827 # Then we check which file has the later ATIME stamp. For this check we use
7828 # "ls -ltu" because it is more portable than "test ... -nt ..."
7829 if ! eval $NUMCOND; then :;
7830 elif ! testoptions o-noatime >/dev/null; then
7831 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
7832 numCANT=$((numCANT+1))
7833 else
7834 tf="$td/test$N.file"
7835 te="$td/test$N.stderr"
7836 tdiff="$td/test$N.diff"
7837 da="test$N $(date) $RANDOM"
7838 $PRINTF "test $F_n $TEST... " $N
7839 touch ${tf}1
7840 CMD="$TRACE $SOCAT $opts -u -,o-noatime /dev/null <${tf}1"
7841 # generate a file, len >= 1
7842 touch "${tf}1"
7843 sleep 1
7844 # generate a reference file
7845 touch "${tf}2"
7846 sleep 1
7847 # read from the first file
7848 sh -c "$CMD" 2>"$te"
7849 if [ $? -ne 0 ]; then # command failed
7850 $PRINTF "${FAILED}:\n"
7851 echo "$CMD"
7852 cat "$te"
7853 numFAIL=$((numFAIL+1))
7854 listFAIL="$listFAIL $N"
7855 else
7856 # check which file has a later atime stamp
7857 if [ $(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
7858 then
7859 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7860 echo "$CMD"
7861 cat "$te"
7862 numFAIL=$((numFAIL+1))
7863 listFAIL="$listFAIL $N"
7864 else
7865 $PRINTF "$OK\n"
7866 if [ -n "$debug" ]; then cat "$te"; fi
7867 numOK=$((numOK+1))
7868 fi # wrong time stamps
7869 fi # command ok
7870 fi ;; # NUMCOND, feats
7871 esac
7872 N=$((N+1))
7874 NAME=EXT2_NOATIME
7875 case "$TESTS" in
7876 *%$N%*|*%functions%*|*%ext2%*|*%noatime%*|*%$NAME%*)
7877 TEST="$NAME: extended file system options using ext2fs noatime option"
7878 # idea: create a file with ext2-noatime option; one second later create a file
7879 # without this option (using touch); one second later read from the first file.
7880 # Then we check which file has the later ATIME stamp. For this check we use
7881 # "ls -ltu" because it is more portable than "test ... -nt ..."
7882 if ! eval $NUMCOND; then :;
7883 elif ! testoptions ext2-noatime >/dev/null; then
7884 $PRINTF "test $F_n $TEST... ${YELLOW}ext2-noatime not available${NORMAL}\n" $N
7885 numCANT=$((numCANT+1))
7886 else
7887 ts="$td/test$N.socket"
7888 tf="$td/test$N.file"
7889 te="$td/test$N.stderr"
7890 tdiff="$td/test$N.diff"
7891 ts1="$ts"
7892 da="test$N $(date) $RANDOM"
7893 $PRINTF "test $F_n $TEST... " $N
7894 CMD0="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\""
7895 CMD="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\",ext2-noatime"
7896 # check if this is a capable FS; lsattr does other things on AIX, thus socat
7897 $CMD0 2>"${te}0"
7898 if [ $? -ne 0 ]; then
7899 $PRINTF "${YELLOW} cannot test${NORMAL}\n"
7900 numCANT=$((numCANT+1))
7901 else
7902 # generate a file with noatime, len >= 1
7903 $CMD 2>"$te"
7904 if [ $? -ne 0 ]; then # command failed
7905 $PRINTF "${YELLOW}impotent file system?${NORMAL}\n"
7906 echo "$CMD"
7907 cat "$te"
7908 numCANT=$((numCANT+1))
7909 else
7910 sleep 1
7911 # generate a reference file
7912 touch "${tf}2"
7913 sleep 1
7914 # read from the first file
7915 cat "${tf}1" >/dev/null
7916 # check which file has a later atime stamp
7917 #if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |awk '{print($8);}') != "${tf}2" ];
7918 if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |sed "s|.*\\($td.*\\)|\1|g") != "${tf}2" ];
7919 then
7920 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7921 echo "$CMD"
7922 cat "$te"
7923 numFAIL=$((numFAIL+1))
7924 listFAIL="$listFAIL $N"
7925 else
7926 $PRINTF "$OK\n"
7927 if [ -n "$debug" ]; then cat "$te"; fi
7928 numOK=$((numOK+1))
7930 fi # not impotent
7931 fi # can test
7932 fi ;; # NUMCOND, feats
7933 esac
7934 N=$((N+1))
7937 NAME=COOLWRITE
7938 case "$TESTS" in
7939 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
7940 TEST="$NAME: option cool-write"
7941 if ! eval $NUMCOND; then :;
7942 elif ! testoptions cool-write >/dev/null; then
7943 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
7944 numCANT=$((numCANT+1))
7945 else
7946 #set -vx
7947 ti="$td/test$N.pipe"
7948 tf="$td/test$N.stdout"
7949 te="$td/test$N.stderr"
7950 tdiff="$td/test$N.diff"
7951 da="test$N $(date) $RANDOM"
7952 # a reader that will terminate after 1 byte
7953 CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
7954 CMD="$TRACE $SOCAT $opts -u - file:\"$ti\",cool-write"
7955 printf "test $F_n $TEST... " $N
7956 $CMD1 2>"${te}1" &
7957 bg=$! # background process id
7958 sleep 1
7959 (echo .; sleep 1; echo) |$CMD 2>"$te"
7960 rc=$?
7961 kill $bg 2>/dev/null; wait
7962 if [ $rc -ne 0 ]; then
7963 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7964 echo "$CMD &"
7965 cat "$te"
7966 numFAIL=$((numFAIL+1))
7967 listFAIL="$listFAIL $N"
7968 else
7969 $PRINTF "$OK\n"
7970 if [ -n "$debug" ]; then cat "$te"; fi
7971 numOK=$((numOK+1))
7973 fi ;; # NUMCOND, feats
7974 esac
7975 N=$((N+1))
7978 # test if option coolwrite can be applied to bidirectional address stdio
7979 # this failed up to socat 1.6.0.0
7980 NAME=COOLSTDIO
7981 case "$TESTS" in
7982 *%$N%*|*%functions%*|*%engine%*|*%timeout%*|*%coolwrite%*|*%$NAME%*)
7983 TEST="$NAME: option cool-write on bidirectional stdio"
7984 # this test starts a socat reader that terminates after receiving one+
7985 # bytes (option readbytes); and a test process that sends two bytes via
7986 # named pipe to the receiving process and, a second later, sends another
7987 # byte. The last write will fail with "broken pipe"; if option coolwrite
7988 # has been applied successfully, socat will terminate with 0 (OK),
7989 # otherwise with error.
7990 if ! eval $NUMCOND; then :;
7991 elif ! testoptions cool-write >/dev/null; then
7992 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
7993 numCANT=$((numCANT+1))
7994 else
7995 #set -vx
7996 ti="$td/test$N.pipe"
7997 tf="$td/test$N.stdout"
7998 te="$td/test$N.stderr"
7999 tdiff="$td/test$N.diff"
8000 da="test$N $(date) $RANDOM"
8001 # a reader that will terminate after 1 byte
8002 CMD1="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8003 CMD="$TRACE $SOCAT $opts -,cool-write pipe >\"$ti\""
8004 printf "test $F_n $TEST... " $N
8005 $CMD1 2>"${te}1" &
8006 bg=$! # background process id
8007 sleep 1
8008 (echo .; sleep 1; echo) |eval "$CMD" 2>"$te"
8009 rc=$?
8010 kill $bg 2>/dev/null; wait
8011 if [ $rc -ne 0 ]; then
8012 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8013 echo "$CMD &"
8014 cat "$te"
8015 numFAIL=$((numFAIL+1))
8016 listFAIL="$listFAIL $N"
8017 else
8018 $PRINTF "$OK\n"
8019 if [ -n "$debug" ]; then cat "$te"; fi
8020 numOK=$((numOK+1))
8022 fi ;; # NUMCOND, feats
8023 esac
8024 N=$((N+1))
8027 NAME=TCP4ENDCLOSE
8028 case "$TESTS" in
8029 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
8030 TEST="$NAME: end-close keeps TCP V4 socket open"
8031 if ! eval $NUMCOND; then :; else
8032 tf="$td/test$N.stdout"
8033 te="$td/test$N.stderr"
8034 tdiff="$td/test$N.diff"
8035 p1=$PORT; PORT=$((PORT+1))
8036 p2=$PORT
8037 da1a="$(date) $RANDOM"
8038 da1b="$(date) $RANDOM"
8039 CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$LOCALHOST:$p1"
8040 CMD="$TRACE $SOCAT $opts -U TCP4:$LOCALHOST:$p2,end-close TCP4-LISTEN:$p1,bind=$LOCALHOST,reuseaddr,fork"
8041 CMD3="$TRACE $SOCAT $opts -u TCP4-LISTEN:$p2,reuseaddr,bind=$LOCALHOST -"
8042 printf "test $F_n $TEST... " $N
8043 $CMD3 >"$tf" 2>"${te}3" &
8044 pid3=$!
8045 waittcp4port $p2 1
8046 $CMD 2>"${te}2" &
8047 pid2=$!
8048 usleep $MICROS
8049 waittcp4port $p1 1
8050 echo "$da1a" |$CMD1 2>>"${te}1a"
8051 echo "$da1b" |$CMD1 2>>"${te}1b"
8052 sleep 1
8053 kill "$pid3" "$pid2" 2>/dev/null
8054 wait
8055 if [ $? -ne 0 ]; then
8056 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8057 echo "$CMD1 &"
8058 echo "$CMD2"
8059 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8060 numFAIL=$((numFAIL+1))
8061 listFAIL="$listFAIL $N"
8062 elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
8063 $PRINTF "$FAILED\n"
8064 cat "$tdiff"
8065 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8066 numFAIL=$((numFAIL+1))
8067 listFAIL="$listFAIL $N"
8068 else
8069 $PRINTF "$OK\n"
8070 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2" "${te}3"; fi
8071 numOK=$((numOK+1))
8073 fi ;; # NUMCOND
8074 esac
8075 PORT=$((PORT+1))
8076 N=$((N+1))
8079 NAME=EXECENDCLOSE
8080 case "$TESTS" in
8081 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
8082 TEST="$NAME: end-close keeps EXEC child running"
8083 if ! eval $NUMCOND; then :; else
8084 tf="$td/test$N.stdout"
8085 te="$td/test$N.stderr"
8086 ts="$td/test$N.sock"
8087 tdiff="$td/test$N.diff"
8088 da1a="$(date) $RANDOM"
8089 da1b="$(date) $RANDOM"
8090 CMD1="$TRACE $SOCAT $opts - UNIX-CONNECT:$ts"
8091 CMD="$TRACE $SOCAT $opts EXEC:"$CAT",end-close UNIX-LISTEN:$ts,fork"
8092 printf "test $F_n $TEST... " $N
8093 $CMD 2>"${te}2" &
8094 pid2=$!
8095 waitfile $ts 1
8096 echo "$da1a" |$CMD1 2>>"${te}1a" >"$tf"
8097 usleep $MICROS
8098 echo "$da1b" |$CMD1 2>>"${te}1b" >>"$tf"
8099 #usleep $MICROS
8100 kill "$pid2" 2>/dev/null
8101 wait
8102 if [ $? -ne 0 ]; then
8103 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8104 echo "$CMD1 &"
8105 echo "$CMD2"
8106 cat "${te}1a" "${te}1b" "${te}2"
8107 numFAIL=$((numFAIL+1))
8108 listFAIL="$listFAIL $N"
8109 elif ! $ECHO "$da1a\n$da1b" |diff - "$tf" >"$tdiff"; then
8110 $PRINTF "$FAILED\n"
8111 cat "$tdiff"
8112 cat "${te}1a" "${te}1b" "${te}2"
8113 numFAIL=$((numFAIL+1))
8114 listFAIL="$listFAIL $N"
8115 else
8116 $PRINTF "$OK\n"
8117 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2"; fi
8118 numOK=$((numOK+1))
8120 fi ;; # NUMCOND
8121 esac
8122 N=$((N+1))
8125 # up to 1.7.0.0 option end-close led to an error with some address types due to
8126 # bad internal handling. here we check it for address PTY
8127 NAME=PTYENDCLOSE
8128 case "$TESTS" in
8129 *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
8130 TEST="$NAME: PTY handles option end-close"
8131 # with the bug, socat exits with error. we invoke socat in a no-op mode and
8132 # check its return status.
8133 if ! eval $NUMCOND; then :;
8134 else
8135 tf="$td/test$N.stout"
8136 te="$td/test$N.stderr"
8137 CMD="$TRACE $SOCAT $opts /dev/null pty,end-close"
8138 printf "test $F_n $TEST... " $N
8139 $CMD 2>"${te}"
8140 rc=$?
8141 if [ "$rc" = 0 ]; then
8142 $PRINTF "$OK\n"
8143 numOK=$((numOK+1))
8144 else
8145 $PRINTF "$FAILED\n"
8146 echo "$CMD"
8147 cat "${te}"
8148 numFAIL=$((numFAIL+1))
8149 listFAIL="$listFAIL $N"
8151 fi # NUMCOND
8153 esac
8154 N=$((N+1))
8157 # test the shut-null and null-eof options
8158 NAME=SHUTNULLEOF
8159 case "$TESTS" in
8160 *%$N%*|*%functions%*|*%socket%*|*%$NAME%*)
8161 TEST="$NAME: options shut-null and null-eof"
8162 # run a receiving background process with option null-eof.
8163 # start a sending process with option shut-null that sends a test record to the
8164 # receiving process and then terminates.
8165 # send another test record.
8166 # whe the receiving process just got the first test record the test succeeded
8167 if ! eval $NUMCOND; then :; else
8168 tf="$td/test$N.stout"
8169 te="$td/test$N.stderr"
8170 tdiff="$td/test$N.diff"
8171 da="test$N $(date) $RANDOM"
8172 CMD0="$TRACE $SOCAT $opts -u UDP-RECV:$PORT,null-eof CREAT:$tf"
8173 CMD1="$TRACE $SOCAT $opts -u - UDP-SENDTO:127.0.0.1:$PORT,shut-null"
8174 printf "test $F_n $TEST... " $N
8175 $CMD0 >/dev/null 2>"${te}0" &
8176 pid0=$!
8177 waitudp4port $PORT 1
8178 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
8179 rc1=$?
8180 echo "xyz" |$CMD1 >"${tf}2" 2>"${te}2"
8181 rc2=$?
8182 kill $pid0 2>/dev/null; wait
8183 if [ $rc1 != 0 -o $rc2 != 0 ]; then
8184 $PRINTF "$FAILED\n"
8185 echo "$CMD0 &"
8186 echo "$CMD1"
8187 cat "${te}0"
8188 cat "${te}1"
8189 cat "${te}2"
8190 numFAIL=$((numFAIL+1))
8191 listFAIL="$listFAIL $N"
8192 elif echo "$da" |diff - "${tf}" >"$tdiff"; then
8193 $PRINTF "$OK\n"
8194 numOK=$((numOK+1))
8195 else
8196 $PRINTF "$FAILED\n"
8197 echo "$CMD0 &"
8198 echo "$CMD1"
8199 cat "${te}0"
8200 cat "${te}1"
8201 cat "${tdiff}"
8202 numFAIL=$((numFAIL+1))
8203 listFAIL="$listFAIL $N"
8205 fi # NUMCOND
8207 esac
8208 N=$((N+1))
8211 NAME=UDP6LISTENBIND
8212 # this tests for a bug in (up to) 1.5.0.0:
8213 # with udp*-listen, the bind option supported only IPv4
8214 case "$TESTS" in
8215 *%$N%*|*%functions%*|*%bugs%*|*%ip6%*|*%ipapp%*|*%udp%*|*%$NAME%*)
8216 TEST="$NAME: UDP6-LISTEN with bind"
8217 if ! eval $NUMCOND; then :;
8218 elif ! feat=$(testaddrs udp ip6) || ! runsip6 >/dev/null; then
8219 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
8220 numCANT=$((numCANT+1))
8221 else
8222 tf="$td/test$N.stdout"
8223 te="$td/test$N.stderr"
8224 tdiff="$td/test$N.diff"
8225 tsl=$PORT
8226 ts="$LOCALHOST6:$tsl"
8227 da="test$N $(date) $RANDOM"
8228 CMD1="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,reuseaddr,bind=$LOCALHOST6 PIPE"
8229 CMD2="$TRACE $SOCAT $opts - UDP6:$ts"
8230 printf "test $F_n $TEST... " $N
8231 $CMD1 >"$tf" 2>"${te}1" &
8232 pid1=$!
8233 waitudp6port $tsl 1
8234 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8235 rc2=$?
8236 kill $pid1 2>/dev/null; wait
8237 if [ $rc2 -ne 0 ]; then
8238 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8239 echo "$CMD1 &"
8240 echo "$CMD2"
8241 cat "${te}1" "${te}2"
8242 numFAIL=$((numFAIL+1))
8243 listFAIL="$listFAIL $N"
8244 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8245 $PRINTF "$FAILED\n"
8246 cat "$tdiff"
8247 numFAIL=$((numFAIL+1))
8248 listFAIL="$listFAIL $N"
8249 else
8250 $PRINTF "$OK\n"
8251 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8252 numOK=$((numOK+1))
8254 fi ;; # NUMCOND, feats
8255 esac
8256 PORT=$((PORT+1))
8257 N=$((N+1))
8260 NAME=TCPWRAPPERS_MULTIOPTS
8261 # this tests for a bug in 1.5.0.0 that let socat fail when more than one
8262 # tcp-wrappers related option was specified in one address
8263 case "$TESTS" in
8264 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%tcpwrap%*|*%$NAME%*)
8265 TEST="$NAME: use of multiple tcpwrapper enabling options"
8266 if ! eval $NUMCOND; then :;
8267 elif ! feat=$(testaddrs tcp ip4 libwrap) || ! runsip4 >/dev/null; then
8268 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8269 numCANT=$((numCANT+1))
8270 else
8271 tf="$td/test$N.stdout"
8272 te="$td/test$N.stderr"
8273 tdiff="$td/test$N.diff"
8274 da="test$N $(date) $RANDOM"
8275 ha="$td/hosts.allow"
8276 $ECHO "test : ALL : allow" >"$ha"
8277 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,reuseaddr,hosts-allow=$ha,tcpwrap=test pipe"
8278 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT"
8279 printf "test $F_n $TEST... " $N
8280 $CMD1 2>"${te}1" &
8281 waittcp4port $PORT
8282 echo "$da" |$CMD2 >"$tf" 2>"${te}2"
8283 if [ $? -ne 0 ]; then
8284 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8285 echo "$CMD1 &"
8286 echo "$CMD2"
8287 cat "${te}1"
8288 cat "${te}2"
8289 numFAIL=$((numFAIL+1))
8290 listFAIL="$listFAIL $N"
8291 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8292 $PRINTF "$FAILED\n"
8293 cat "$tdiff"
8294 numFAIL=$((numFAIL+1))
8295 listFAIL="$listFAIL $N"
8296 else
8297 $PRINTF "$OK\n"
8298 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8299 numOK=$((numOK+1))
8301 fi ;; # NUMCOND, feats
8302 esac
8303 PORT=$((PORT+1))
8304 N=$((N+1))
8307 NAME=TCPWRAPPERS_TCP6ADDR
8308 # this tests for a bug in 1.5.0.0 that brought false results with tcp-wrappers
8309 # and IPv6 when
8310 case "$TESTS" in
8311 *%$N%*|*%functions%*|*%bugs%*|*%tcp%*|*%tcp6%*|*%ip6%*|*%tcpwrap%*|*%$NAME%*)
8312 TEST="$NAME: specification of TCP6 address in hosts.allow"
8313 if ! eval $NUMCOND; then :;
8314 elif ! feat=$(testaddrs tcp ip6 libwrap) || ! runsip6 >/dev/null; then
8315 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8316 numCANT=$((numCANT+1))
8317 else
8318 tf="$td/test$N.stdout"
8319 te="$td/test$N.stderr"
8320 tdiff="$td/test$N.diff"
8321 da="test$N $(date) $RANDOM"
8322 ha="$td/hosts.allow"
8323 hd="$td/hosts.deny"
8324 $ECHO "socat : [::1] : allow" >"$ha"
8325 $ECHO "ALL : ALL : deny" >"$hd"
8326 CMD1="$TRACE $SOCAT $opts TCP6-LISTEN:$PORT,reuseaddr,tcpwrap-etc=$td,tcpwrappers=socat pipe"
8327 CMD2="$TRACE $SOCAT $opts - TCP6:[::1]:$PORT"
8328 printf "test $F_n $TEST... " $N
8329 $CMD1 2>"${te}1" &
8330 pid1=$!
8331 waittcp6port $PORT
8332 echo "$da" |$CMD2 >"$tf" 2>"${te}2"
8333 kill $pid1 2>/dev/null; wait
8334 if [ $? -ne 0 ]; then
8335 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8336 echo "$CMD1 &"
8337 echo "$CMD2"
8338 cat "${te}1"
8339 cat "${te}2"
8340 numFAIL=$((numFAIL+1))
8341 listFAIL="$listFAIL $N"
8342 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8343 $PRINTF "$FAILED\n"
8344 cat "$tdiff"
8345 numFAIL=$((numFAIL+1))
8346 listFAIL="$listFAIL $N"
8347 else
8348 $PRINTF "$OK\n"
8349 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8350 numOK=$((numOK+1))
8352 fi ;; # NUMCOND, feats
8353 esac
8354 PORT=$((PORT+1))
8355 N=$((N+1))
8358 NAME=UDP4BROADCAST
8359 case "$TESTS" in
8360 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%$NAME%*)
8361 TEST="$NAME: UDP/IPv4 broadcast"
8362 if ! eval $NUMCOND; then :;
8363 elif [ -z "$BCADDR" ]; then
8364 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8365 numCANT=$((numCANT+1))
8366 else
8367 tf="$td/test$N.stdout"
8368 te="$td/test$N.stderr"
8369 tdiff="$td/test$N.diff"
8370 ts1p=$PORT; PORT=$((PORT+1))
8371 #ts1="$BCADDR/8:$ts1p"
8372 ts1="$BCADDR:$ts1p"
8373 ts2p=$PORT; PORT=$((PORT+1))
8374 ts2="$BCIFADDR:$ts2p"
8375 da="test$N $(date) $RANDOM"
8376 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,broadcast PIPE"
8377 #CMD2="$TRACE $SOCAT $opts - UDP4-BROADCAST:$ts1"
8378 CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:$ts1,broadcast"
8379 printf "test $F_n $TEST... " $N
8380 $CMD1 2>"${te}1" &
8381 pid1="$!"
8382 waitudp4port $ts1p 1
8383 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8384 rc2="$?"
8385 kill "$pid1" 2>/dev/null; wait;
8386 if [ "$rc2" -ne 0 ]; then
8387 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8388 echo "$CMD1 &"
8389 echo "$CMD2"
8390 cat "${te}1"
8391 cat "${te}2"
8392 numFAIL=$((numFAIL+1))
8393 listFAIL="$listFAIL $N"
8394 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8395 $PRINTF "$FAILED\n"
8396 cat "$tdiff"
8397 numFAIL=$((numFAIL+1))
8398 listFAIL="$listFAIL $N"
8399 else
8400 $PRINTF "$OK\n"
8401 if [ -n "$tut" ]; then
8402 echo "$CMD1 &"
8403 echo "$CMD2"
8405 if [ -n "$debug" ]; then cat $te; fi
8406 numOK=$((numOK+1))
8408 fi ;; # NUMCOND, feats
8409 esac
8410 N=$((N+1))
8413 NAME=IP4BROADCAST
8414 # test a local broadcast of a raw IPv4 protocol.
8415 # because we receive - in addition to the regular reply - our own broadcast,
8416 # we use a token XXXX that is changed to YYYY in the regular reply packet.
8417 case "$TESTS" in
8418 *%$N%*|*%functions%*|*%engine%*|*%rawip%*|*%rawip4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%root%*|*%$NAME%*)
8419 TEST="$NAME: raw IPv4 broadcast"
8420 if ! eval $NUMCOND; then :;
8421 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8422 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP4 not available${NORMAL}\n" $N
8423 numCANT=$((numCANT+1))
8424 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8425 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8426 numCANT=$((numCANT+1))
8427 elif [ -z "$BCADDR" ]; then
8428 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8429 else
8430 tf="$td/test$N.stdout"
8431 te="$td/test$N.stderr"
8432 tdiff="$td/test$N.diff"
8433 ts1p=$PROTO
8434 #ts1="$BCADDR/8:$ts1p"
8435 ts1="$BCADDR:$ts1p"
8436 ts2p=$ts1p
8437 ts2="$BCIFADDR"
8438 da="test$N $(date) $RANDOM XXXX"
8439 sh="$td/test$N-sed.sh"
8440 echo 'sed s/XXXX/YYYY/' >"$sh"
8441 chmod a+x "$sh"
8442 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,broadcast exec:$sh"
8443 #CMD2="$TRACE $SOCAT $opts - IP4-BROADCAST:$ts1"
8444 CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:$ts1,broadcast"
8445 printf "test $F_n $TEST... " $N
8446 $CMD1 2>"${te}1" &
8447 pid1="$!"
8448 waitip4port $ts1p 1
8449 echo "$da" |$CMD2 2>>"${te}2" |grep -v XXXX >>"$tf"
8450 rc2="$?"
8451 kill "$pid1" 2>/dev/null; wait;
8452 if [ "$rc2" -ne 0 ]; then
8453 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8454 echo "$CMD1 &"
8455 echo "$CMD2"
8456 cat "${te}1"
8457 cat "${te}2"
8458 numFAIL=$((numFAIL+1))
8459 listFAIL="$listFAIL $N"
8460 elif ! echo "$da" | sed 's/XXXX/YYYY/'|diff - "$tf" >"$tdiff"; then
8461 $PRINTF "$FAILED\n"
8462 cat "$tdiff"
8463 numFAIL=$((numFAIL+1))
8464 listFAIL="$listFAIL $N"
8465 else
8466 $PRINTF "$OK\n"
8467 if [ -n "$debug" ]; then cat $te; fi
8468 numOK=$((numOK+1))
8470 fi ;; # NUMCOND, feats
8471 esac
8472 PROTO=$((PROTO+1))
8473 N=$((N+1))
8476 #NAME=UDP4BROADCAST_RANGE
8477 #case "$TESTS" in
8478 #*%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%range%*|*%$NAME%*)
8479 #TEST="$NAME: security of UDP4-BROADCAST with RANGE option"
8480 #if ! eval $NUMCOND; then :;
8481 #elif [ -z "$BCADDR" ]; then
8482 # $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8483 #else
8484 #testserversec "$N" "$TEST" "$opts -s" "UDP4-BROADCAST:$BCADDR/8:$PORT" "" "range=127.1.0.0:255.255.0.0" "udp4:127.1.0.0:$PORT" 4 udp $PORT 0
8485 #fi ;; # NUMCOND, feats
8486 #esac
8487 #PORT=$((PORT+1))
8488 #N=$((N+1))
8491 NAME=UDP4MULTICAST_UNIDIR
8492 case "$TESTS" in
8493 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8494 TEST="$NAME: UDP/IPv4 multicast, send only"
8495 if ! eval $NUMCOND; then :;
8496 elif ! feat=$(testaddrs ip4 udp) || ! runsip4 >/dev/null; then
8497 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8498 numCANT=$((numCANT+1))
8499 else
8500 tf="$td/test$N.stdout"
8501 te="$td/test$N.stderr"
8502 tdiff="$td/test$N.diff"
8503 ts1p=$PORT; PORT=$((PORT+1))
8504 ts1a="$SECONDADDR"
8505 ts1="$ts1a:$ts1p"
8506 da="test$N $(date) $RANDOM"
8507 CMD1="$TRACE $SOCAT -u $opts UDP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
8508 CMD2="$TRACE $SOCAT -u $opts - UDP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
8509 printf "test $F_n $TEST... " $N
8510 $CMD1 2>"${te}1" >"${tf}" &
8511 pid1="$!"
8512 waitudp4port $ts1p 1
8513 echo "$da" |$CMD2 2>>"${te}2"
8514 rc2="$?"
8515 usleep $MICROS
8516 kill "$pid1" 2>/dev/null; wait;
8517 if [ "$rc2" -ne 0 ]; then
8518 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8519 echo "$CMD1 &"
8520 echo "$CMD2"
8521 cat "${te}1"
8522 cat "${te}2"
8523 numFAIL=$((numFAIL+1))
8524 listFAIL="$listFAIL $N"
8525 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8526 $PRINTF "$FAILED\n"
8527 cat "$tdiff"
8528 numFAIL=$((numFAIL+1))
8529 listFAIL="$listFAIL $N"
8530 else
8531 $PRINTF "$OK\n"
8532 if [ -n "$debug" ]; then cat $te; fi
8533 numOK=$((numOK+1))
8535 fi ;; # NUMCOND, feats
8536 esac
8537 N=$((N+1))
8539 NAME=IP4MULTICAST_UNIDIR
8540 case "$TESTS" in
8541 *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
8542 TEST="$NAME: IPv4 multicast"
8543 if ! eval $NUMCOND; then :;
8544 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8545 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8546 numCANT=$((numCANT+1))
8547 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8548 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8549 numCANT=$((numCANT+1))
8550 else
8551 tf="$td/test$N.stdout"
8552 te="$td/test$N.stderr"
8553 tdiff="$td/test$N.diff"
8554 ts1p=$PROTO
8555 ts1a="$SECONDADDR"
8556 ts1="$ts1a:$ts1p"
8557 da="test$N $(date) $RANDOM"
8558 CMD1="$TRACE $SOCAT -u $opts IP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
8559 CMD2="$TRACE $SOCAT -u $opts - IP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
8560 printf "test $F_n $TEST... " $N
8561 $CMD1 2>"${te}1" >"${tf}" &
8562 pid1="$!"
8563 waitip4proto $ts1p 1
8564 usleep $MICROS
8565 echo "$da" |$CMD2 2>>"${te}2"
8566 rc2="$?"
8567 #usleep $MICROS
8568 sleep 1
8569 kill "$pid1" 2>/dev/null; wait;
8570 if [ "$rc2" -ne 0 ]; then
8571 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8572 echo "$CMD1 &"
8573 echo "$CMD2"
8574 cat "${te}1"
8575 cat "${te}2"
8576 numFAIL=$((numFAIL+1))
8577 listFAIL="$listFAIL $N"
8578 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8579 $PRINTF "$FAILED\n"
8580 cat "$tdiff"
8581 numFAIL=$((numFAIL+1))
8582 listFAIL="$listFAIL $N"
8583 else
8584 $PRINTF "$OK\n"
8585 if [ -n "$debug" ]; then cat $te; fi
8586 numOK=$((numOK+1))
8588 fi ;; # NUMCOND, feats
8589 esac
8590 PROTO=$((PROTO+1))
8591 N=$((N+1))
8593 if false; then
8594 NAME=UDP6MULTICAST_UNIDIR
8595 case "$TESTS" in
8596 *%$N%*|*%functions%*|*%udp%*|*%udp6%*|*%ip6%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8597 TEST="$NAME: UDP/IPv6 multicast"
8598 if ! eval $NUMCOND; then :;
8599 elif ! feat=$(testaddrs ip6 udp) || ! runsip6 >/dev/null; then
8600 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8601 numCANT=$((numCANT+1))
8602 else
8603 tf="$td/test$N.stdout"
8604 te="$td/test$N.stderr"
8605 tdiff="$td/test$N.diff"
8606 ts1p=$PORT; PORT=$((PORT+1))
8607 if1="$MCINTERFACE"
8608 ts1a="[::1]"
8609 da="test$N $(date) $RANDOM"
8610 CMD1="$TRACE $SOCAT -u $opts UDP6-RECV:$ts1p,reuseaddr,ipv6-join-group=[ff02::2]:$if1 -"
8611 CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p,bind=$ts1a"
8612 printf "test $F_n $TEST... " $N
8613 $CMD1 2>"${te}1" >"${tf}" &
8614 pid1="$!"
8615 waitudp6port $ts1p 1
8616 echo "$da" |$CMD2 2>>"${te}2"
8617 rc2="$?"
8618 usleep $MICROS
8619 kill "$pid1" 2>/dev/null; wait;
8620 if [ "$rc2" -ne 0 ]; then
8621 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8622 echo "$CMD1 &"
8623 echo "$CMD2"
8624 cat "${te}1"
8625 cat "${te}2"
8626 numFAIL=$((numFAIL+1))
8627 listFAIL="$listFAIL $N"
8628 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8629 $PRINTF "$FAILED\n"
8630 cat "$tdiff"
8631 numFAIL=$((numFAIL+1))
8632 listFAIL="$listFAIL $N"
8633 else
8634 $PRINTF "$OK\n"
8635 if [ -n "$debug" ]; then cat $te; fi
8636 numOK=$((numOK+1))
8638 fi ;; # NUMCOND, feats
8639 esac
8640 N=$((N+1))
8641 fi # false
8643 NAME=UDP4MULTICAST_BIDIR
8644 case "$TESTS" in
8645 *%$N%*|*%functions%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%multicast%*|*%$NAME%*)
8646 TEST="$NAME: UDP/IPv4 multicast, with reply"
8647 if ! eval $NUMCOND; then :; else
8648 tf="$td/test$N.stdout"
8649 te="$td/test$N.stderr"
8650 tdiff="$td/test$N.diff"
8651 ts1p=$PORT; PORT=$((PORT+1))
8652 ts1a="$SECONDADDR"
8653 ts1="$ts1a:$ts1p"
8654 ts2p=$PORT; PORT=$((PORT+1))
8655 ts2="$BCIFADDR:$ts2p"
8656 da="test$N $(date) $RANDOM"
8657 CMD1="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
8658 #CMD2="$TRACE $SOCAT $opts - UDP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
8659 CMD2="$TRACE $SOCAT $opts - UDP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
8660 printf "test $F_n $TEST... " $N
8661 $CMD1 2>"${te}1" &
8662 pid1="$!"
8663 waitudp4port $ts1p 1
8664 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8665 rc2="$?"
8666 kill "$pid1" 2>/dev/null; wait;
8667 if [ "$rc2" -ne 0 ]; then
8668 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8669 echo "$CMD1 &"
8670 echo "$CMD2"
8671 cat "${te}1"
8672 cat "${te}2"
8673 numFAIL=$((numFAIL+1))
8674 listFAIL="$listFAIL $N"
8675 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8676 $PRINTF "$FAILED\n"
8677 cat "$tdiff"
8678 numFAIL=$((numFAIL+1))
8679 listFAIL="$listFAIL $N"
8680 else
8681 $PRINTF "$OK\n"
8682 if [ -n "$tut" ]; then
8683 echo "$CMD1 &"
8684 echo "$CMD2"
8686 if [ -n "$debug" ]; then cat $te; fi
8687 numOK=$((numOK+1))
8689 fi ;; # NUMCOND
8690 esac
8691 N=$((N+1))
8693 NAME=IP4MULTICAST_BIDIR
8694 case "$TESTS" in
8695 *%$N%*|*%functions%*|*%rawip%*|*%ip4%*|*%dgram%*|*%multicast%*|*%root%*|*%$NAME%*)
8696 TEST="$NAME: IPv4 multicast, with reply"
8697 if ! eval $NUMCOND; then :;
8698 elif ! feat=$(testaddrs ip4 rawip) || ! runsip4 >/dev/null; then
8699 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8700 numCANT=$((numCANT+1))
8701 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8702 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8703 numCANT=$((numCANT+1))
8704 else
8705 tf="$td/test$N.stdout"
8706 te="$td/test$N.stderr"
8707 tdiff="$td/test$N.diff"
8708 ts1p=$PROTO
8709 ts1a="$SECONDADDR"
8710 ts1="$ts1a:$ts1p"
8711 da="test$N $(date) $RANDOM"
8712 CMD1="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
8713 #CMD2="$TRACE $SOCAT $opts - IP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
8714 CMD2="$TRACE $SOCAT $opts - IP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
8715 printf "test $F_n $TEST... " $N
8716 $CMD1 2>"${te}1" &
8717 pid1="$!"
8718 waitip4port $ts1p 1
8719 usleep 100000 # give process a chance to add multicast membership
8720 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8721 rc2="$?"
8722 kill "$pid1" 2>/dev/null; wait;
8723 if [ "$rc2" -ne 0 ]; then
8724 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8725 echo "$CMD1 &"
8726 echo "$CMD2"
8727 cat "${te}1"
8728 cat "${te}2"
8729 numFAIL=$((numFAIL+1))
8730 listFAIL="$listFAIL $N"
8731 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8732 $PRINTF "$FAILED\n"
8733 cat "$tdiff"
8734 numFAIL=$((numFAIL+1))
8735 listFAIL="$listFAIL $N"
8736 else
8737 $PRINTF "$OK\n"
8738 if [ -n "$tut" ]; then
8739 echo "$CMD1 &"
8740 echo "$CMD2"
8742 if [ -n "$debug" ]; then cat $te; fi
8743 numOK=$((numOK+1))
8745 fi ;; # NUMCOND, feats
8746 esac
8747 PROTO=$((PROTO+1))
8748 N=$((N+1))
8751 NAME=TUNREAD
8752 case "$TESTS" in
8753 *%$N%*|*%functions%*|*%tun%*|*%root%*|*%$NAME%*)
8754 TEST="$NAME: reading data sent through tun interface"
8755 #idea: create a TUN interface and send a datagram to one of the addresses of
8756 # its virtual network. On the tunnel side, read the packet and compare its last
8757 # bytes with the datagram payload
8758 if ! eval $NUMCOND; then :;
8759 elif ! feat=$(testaddrs ip4 tun) || ! runsip4 >/dev/null; then
8760 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8761 numCANT=$((numCANT+1))
8762 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8763 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8764 numCANT=$((numCANT+1))
8765 else
8766 tf="$td/test$N.stdout"
8767 te="$td/test$N.stderr"
8768 tdiff="$td/test$N.diff"
8769 tl="$td/test$N.lock"
8770 da="test$N $(date) $RANDOM"
8771 dalen=$((${#da}+1))
8772 TUNNET=10.255.255
8773 CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$TUNNET.2:$PORT"
8774 #CMD="$TRACE $SOCAT $opts -u -L $tl TUN,ifaddr=$TUNNET.1,netmask=255.255.255.0,iff-up=1 -"
8775 CMD="$TRACE $SOCAT $opts -u -L $tl TUN:$TUNNET.1/24,iff-up=1 -"
8776 printf "test $F_n $TEST... " $N
8777 $CMD 2>"${te}" |tail -c $dalen >"${tf}" &
8778 sleep 1
8779 echo "$da" |$CMD1 2>"${te}1"
8780 sleep 1
8781 kill "$(cat $tl 2>/dev/null)" 2>/dev/null
8782 wait
8783 if [ $? -ne 0 ]; then
8784 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8785 echo "$CMD &"
8786 echo "$CMD1"
8787 cat "${te}" "${te}1"
8788 numFAIL=$((numFAIL+1))
8789 listFAIL="$listFAIL $N"
8790 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8791 $PRINTF "$FAILED\n"
8792 cat "$tdiff"
8793 cat "${te}" "${te}1"
8794 numFAIL=$((numFAIL+1))
8795 listFAIL="$listFAIL $N"
8796 else
8797 $PRINTF "$OK\n"
8798 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
8799 numOK=$((numOK+1))
8801 fi ;; # NUMCOND, feats
8802 esac
8803 PORT=$((PORT+1))
8804 N=$((N+1))
8807 # use the INTERFACE address on a tun/tap device and transfer data fully
8808 # transparent
8809 NAME=TUNINTERFACE
8810 case "$TESTS" in
8811 *%$N%*|*%functions%*|*%tun%*|*%interface%*|*%root%*|*%$NAME%*)
8812 TEST="$NAME: pass data through tun interface using INTERFACE"
8813 #idea: create a TUN interface and send a raw packet on the interface side.
8814 # It should arrive unmodified on the tunnel side.
8815 if ! eval $NUMCOND; then :;
8816 elif ! feat=$(testaddrs ip4 tun interface) || ! runsip4 >/dev/null; then
8817 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8818 numCANT=$((numCANT+1))
8819 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
8820 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8821 numCANT=$((numCANT+1))
8822 else
8823 tf="$td/test$N.stdout"
8824 te="$td/test$N.stderr"
8825 tdiff="$td/test$N.diff"
8826 tl="$td/test$N.lock"
8827 da="$(date) $RANDOM"
8828 dalen=$((${#da}+1))
8829 TUNNET=10.255.255
8830 TUNNAME=tun9
8831 CMD1="$TRACE $SOCAT $opts -L $tl TUN:$TUNNET.1/24,iff-up=1,tun-type=tun,tun-name=$TUNNAME echo"
8832 CMD="$TRACE $SOCAT $opts - INTERFACE:$TUNNAME"
8833 printf "test $F_n $TEST... " $N
8834 $CMD1 2>"${te}1" &
8835 pid1="$!"
8836 #waitinterface "$TUNNAME"
8837 sleep 1
8838 echo "$da" |$CMD 2>"${te}1" >"$tf" 2>"${te}"
8839 kill $pid1 2>/dev/null
8840 wait
8841 if [ $? -ne 0 ]; then
8842 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8843 echo "$CMD &"
8844 echo "$CMD1"
8845 cat "${te}" "${te}1"
8846 numFAIL=$((numFAIL+1))
8847 listFAIL="$listFAIL $N"
8848 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8849 $PRINTF "$FAILED\n"
8850 cat "$tdiff"
8851 cat "${te}" "${te}1"
8852 numFAIL=$((numFAIL+1))
8853 listFAIL="$listFAIL $N"
8854 else
8855 $PRINTF "$OK\n"
8856 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
8857 numOK=$((numOK+1))
8859 fi ;; # NUMCOND, feats
8860 esac
8861 PORT=$((PORT+1))
8862 N=$((N+1))
8865 NAME=ABSTRACTSTREAM
8866 case "$TESTS" in
8867 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%connect%*|*%listen%*|*%$NAME%*)
8868 TEST="$NAME: abstract UNIX stream socket, listen and connect"
8869 if ! eval $NUMCOND; then :;
8870 elif ! feat=$(testaddrs abstract-unixsocket); then
8871 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8872 numCANT=$((numCANT+1))
8873 else
8874 ts="$td/test$N.socket"
8875 tf="$td/test$N.stdout"
8876 te="$td/test$N.stderr"
8877 tdiff="$td/test$N.diff"
8878 da1="test$N $(date) $RANDOM"
8879 #establish a listening abstract unix socket
8880 SRV="$TRACE $SOCAT $opts -lpserver ABSTRACT-LISTEN:\"$ts\" PIPE"
8881 #make a connection
8882 CMD="$TRACE $SOCAT $opts - ABSTRACT-CONNECT:$ts"
8883 $PRINTF "test $F_n $TEST... " $N
8884 touch "$ts" # make a file with same name, so non-abstract fails
8885 eval "$SRV 2>${te}s &"
8886 pids=$!
8887 #waitfile "$ts"
8888 sleep 1
8889 echo "$da1" |eval "$CMD" >"${tf}1" 2>"${te}1"
8890 if [ $? -ne 0 ]; then
8891 kill "$pids" 2>/dev/null
8892 $PRINTF "$FAILED:\n"
8893 echo "$SRV &"
8894 cat "${te}s"
8895 echo "$CMD"
8896 cat "${te}1"
8897 numFAIL=$((numFAIL+1))
8898 listFAIL="$listFAIL $N"
8899 elif ! echo "$da1" |diff - "${tf}1" >"$tdiff"; then
8900 kill "$pids" 2>/dev/null
8901 $PRINTF "$FAILED:\n"
8902 echo "$SRV &"
8903 cat "${te}s"
8904 echo "$CMD"
8905 cat "${te}1"
8906 cat "$tdiff"
8907 numFAIL=$((numFAIL+1))
8908 listFAIL="$listFAIL $N"
8909 else
8910 $PRINTF "$OK\n"
8911 if [ -n "$debug" ]; then cat $te; fi
8912 numOK=$((numOK+1))
8913 fi # !(rc -ne 0)
8914 wait
8915 fi ;; # NUMCOND, feats
8916 esac
8917 N=$((N+1))
8920 NAME=ABSTRACTDGRAM
8921 case "$TESTS" in
8922 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%$NAME%*)
8923 TEST="$NAME: abstract UNIX datagram"
8924 if ! eval $NUMCOND; then :;
8925 elif ! feat=$(testaddrs abstract-unixsocket); then
8926 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8927 numCANT=$((numCANT+1))
8928 else
8929 tf="$td/test$N.stdout"
8930 te="$td/test$N.stderr"
8931 tdiff="$td/test$N.diff"
8932 ts1="$td/test$N.socket1"
8933 ts2="$td/test$N.socket2"
8934 da="test$N $(date) $RANDOM"
8935 CMD1="$TRACE $SOCAT $opts ABSTRACT-RECVFROM:$ts1,reuseaddr PIPE"
8936 #CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
8937 CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
8938 printf "test $F_n $TEST... " $N
8939 touch "$ts1" # make a file with same name, so non-abstract fails
8940 $CMD1 2>"${te}1" &
8941 pid1="$!"
8942 sleep 1
8943 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
8944 rc2=$?
8945 kill "$pid1" 2>/dev/null; wait
8946 if [ $rc2 -ne 0 ]; then
8947 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8948 echo "$CMD1 &"
8949 cat "${te}1"
8950 echo "$CMD2"
8951 cat "${te}2"
8952 numFAIL=$((numFAIL+1))
8953 listFAIL="$listFAIL $N"
8954 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
8955 $PRINTF "$FAILED\n"
8956 cat "$tdiff"
8957 numFAIL=$((numFAIL+1))
8958 listFAIL="$listFAIL $N"
8959 else
8960 $PRINTF "$OK\n"
8961 if [ -n "$debug" ]; then cat $te; fi
8962 numOK=$((numOK+1))
8964 fi ;; # NUMCOND, feats
8965 esac
8966 N=$((N+1))
8969 NAME=ABSTRACTRECV
8970 case "$TESTS" in
8971 *%$N%*|*%functions%*|*%unix%*|*%abstract%*|*%dgram%*|*%recv%*|*%$NAME%*)
8972 TEST="$NAME: abstract UNIX datagram receive"
8973 if ! eval $NUMCOND; then :;
8974 elif ! feat=$(testaddrs abstract-unixsocket); then
8975 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8976 numCANT=$((numCANT+1))
8977 else
8978 ts="$td/test$N.socket"
8979 tf="$td/test$N.stdout"
8980 te="$td/test$N.stderr"
8981 tdiff="$td/test$N.diff"
8982 ts1="$ts"
8983 da="test$N $(date) $RANDOM"
8984 CMD1="$TRACE $SOCAT $opts -u ABSTRACT-RECV:$ts1,reuseaddr -"
8985 CMD2="$TRACE $SOCAT $opts -u - ABSTRACT-SENDTO:$ts1"
8986 printf "test $F_n $TEST... " $N
8987 touch "$ts1" # make a file with same name, so non-abstract fails
8988 $CMD1 >"$tf" 2>"${te}1" &
8989 pid1="$!"
8990 #waitfile $ts1 1
8991 sleep 1
8992 echo "$da" |$CMD2 2>>"${te}2"
8993 rc2="$?"
8994 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
8995 kill "$pid1" 2>/dev/null; wait
8996 if [ "$rc2" -ne 0 ]; then
8997 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8998 echo "$CMD1 &"
8999 echo "$CMD2"
9000 cat "${te}1"
9001 cat "${te}2"
9002 numFAIL=$((numFAIL+1))
9003 listFAIL="$listFAIL $N"
9004 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9005 $PRINTF "$FAILED\n"
9006 cat "$tdiff"
9007 numFAIL=$((numFAIL+1))
9008 listFAIL="$listFAIL $N"
9009 else
9010 $PRINTF "$OK\n"
9011 if [ -n "$debug" ]; then cat $te; fi
9012 numOK=$((numOK+1))
9014 fi ;; # NUMCOND, feats
9015 esac
9016 N=$((N+1))
9019 # bind with Linux abstract UNIX domain addresses bound to filesystem socket
9020 # instead of abstract namespace
9021 NAME=ABSTRACT_BIND
9022 case "$TESTS" in
9023 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%abstract%*|*%$NAME%*)
9024 TEST="$NAME: abstract bind"
9025 # open an abstract client address with bind option, bind to the target socket.
9026 # send a datagram.
9027 # when socat outputs the datagram it got the test succeeded
9028 if ! eval $NUMCOND; then :;
9029 elif [ "$UNAME" != Linux ]; then
9030 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
9031 numCANT=$((numCANT+1))
9032 else
9033 tf="$td/test$N.stdout"
9034 te="$td/test$N.stderr"
9035 tdiff="$td/test$N.diff"
9036 ts1="$td/test$N.sock1"
9037 da="test$N $(date) $RANDOM"
9038 CMD1="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts1"
9039 printf "test $F_n $TEST... " $N
9040 echo "$da" |$CMD1 >$tf 2>"${te}1"
9041 rc1=$?
9042 if [ $rc1 -ne 0 ]; then
9043 $PRINTF "$FAILED\n"
9044 echo "$CMD1" >&2
9045 echo "rc=$rc1" >&2
9046 cat "${te}1" >&2
9047 numFAIL=$((numFAIL+1))
9048 listFAIL="$listFAIL $N"
9049 elif echo "$da" |diff -q - $tf; then
9050 $PRINTF "$OK\n"
9051 numOK=$((numOK+1))
9052 else
9053 $PRINTF "$FAILED\n"
9054 echo "$CMD1" >&2
9055 cat "${te}1" >&2
9056 echo "$da" |diff - "$tf" >&2
9057 numFAIL=$((numFAIL+1))
9058 listFAIL="$listFAIL $N"
9060 fi # NUMCOND
9062 esac
9063 PORT=$((PORT+1))
9064 N=$((N+1))
9067 NAME=OPENSSLREAD
9068 # socat determined availability of data using select(). With openssl, the
9069 # following situation might occur:
9070 # a SSL data block with more than 8192 bytes (socats default blocksize)
9071 # arrives; socat calls SSL_read, and the SSL routine reads the complete block.
9072 # socat then reads 8192 bytes from the SSL layer, the rest remains buffered.
9073 # If the TCP connection stays idle for some time, the data in the SSL layer
9074 # keeps there and is not transferred by socat until the socket indicates more
9075 # data or EOF.
9076 case "$TESTS" in
9077 *%$N%*|*%functions%*|*%openssl%*|*%$NAME%*)
9078 TEST="$NAME: socat handles data buffered by openssl"
9079 #idea: have a socat process (server) that gets an SSL block that is larger than
9080 # socat transfer block size; keep the socket connection open and kill the
9081 # server process after a short time; if not the whole data block has been
9082 # transferred, the test has failed.
9083 if ! eval $NUMCOND; then :;
9084 elif ! feat=$(testaddrs openssl) >/dev/null; then
9085 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9086 numCANT=$((numCANT+1))
9087 else
9088 tf="$td/test$N.out"
9089 te="$td/test$N.err"
9090 tdiff="$td/test$N.diff"
9091 da="test$N $(date) $RANDOM"
9092 SRVCERT=testsrv
9093 gentestcert "$SRVCERT"
9094 CMD1="$TRACE $SOCAT $opts -u -T 1 -b $($ECHO "$da\c" |wc -c) OPENSSL-LISTEN:$PORT,reuseaddr,cert=$SRVCERT.pem,verify=0 -"
9095 CMD2="$TRACE $SOCAT $opts -u - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
9096 printf "test $F_n $TEST... " $N
9098 $CMD1 2>"${te}1" >"$tf" &
9099 pid=$! # background process id
9100 waittcp4port $PORT
9101 (echo "$da"; sleep 2) |$CMD2 2>"${te}2"
9102 kill "$pid" 2>/dev/null; wait
9103 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
9104 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9105 echo "$CMD1"
9106 cat "${te}1"
9107 echo "$CMD2"
9108 cat "${te}2"
9109 cat "$tdiff"
9110 numFAIL=$((numFAIL+1))
9111 listFAIL="$listFAIL $N"
9112 else
9113 $PRINTF "$OK\n"
9114 if [ -n "$debug" ]; then cat $te; fi
9115 numOK=$((numOK+1))
9117 wait
9118 fi # NUMCOND, featsesac
9120 esac
9121 N=$((N+1))
9124 # test: there is a bug with the readbytes option: when the socket delivered
9125 # exacly that many bytes as specified with readbytes and the stays idle (no
9126 # more data, no EOF), socat waits for more data instead of generating EOF on
9127 # this in put stream.
9128 NAME=READBYTES_EOF
9129 #set -vx
9130 case "$TESTS" in
9131 *%$N%*|*%functions%*|*%$NAME%*)
9132 TEST="$NAME: trigger EOF after that many bytes, even when socket idle"
9133 #idea: we deliver that many bytes to socat; the process should terminate then.
9134 # we try to transfer data in the other direction then; if transfer succeeds,
9135 # the process did not terminate and the bug is still there.
9136 if ! eval $NUMCOND; then :;
9137 elif false; then
9138 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9139 numCANT=$((numCANT+1))
9140 else
9141 tr="$td/test$N.ref"
9142 ti="$td/test$N.in"
9143 to="$td/test$N.out"
9144 te="$td/test$N.err"
9145 tdiff="$td/test$N.diff"
9146 da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')"
9147 CMD="$TRACE $SOCAT $opts SYSTEM:\"echo A; sleep $((2*SECONDs))\",readbytes=2!!- -!!/dev/null"
9148 printf "test $F_n $TEST... " $N
9149 (usleep $((2*MICROS)); echo) |eval "$CMD" >"$to" 2>"$te"
9150 if test -s "$to"; then
9151 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9152 echo "$CMD"
9153 numFAIL=$((numFAIL+1))
9154 listFAIL="$listFAIL $N"
9155 else
9156 $PRINTF "$OK\n"
9157 if [ -n "$debug" ]; then cat $te; fi
9158 numOK=$((numOK+1))
9160 fi ;; # NUMCOND, feats
9161 esac
9162 N=$((N+1))
9165 # test: there was a bug with exec:...,pty that did not kill the exec'd sub
9166 # process under some circumstances.
9167 NAME=EXECPTYKILL
9168 case "$TESTS" in
9169 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
9170 TEST="$NAME: exec:...,pty explicitely kills sub process"
9171 # we want to check if the exec'd sub process is killed in time
9172 # for this we have a shell script that generates a file after two seconds;
9173 # it should be killed after one second, so if the file was generated the test
9174 # has failed
9175 if ! eval $NUMCOND; then :; else
9176 tf="$td/test$N.stdout"
9177 te="$td/test$N.stderr"
9178 ts="$td/test$N.sock"
9179 tda="$td/test$N.data"
9180 tsh="$td/test$N.sh"
9181 tdiff="$td/test$N.diff"
9182 cat >"$tsh" <<EOF
9183 sleep $SECONDs; echo; sleep $SECONDs; touch "$tda"; echo
9185 chmod a+x "$tsh"
9186 CMD1="$TRACE $SOCAT $opts -t $SECONDs -U UNIX-LISTEN:$ts,fork EXEC:$tsh,pty"
9187 CMD="$TRACE $SOCAT $opts -t $SECONDs /dev/null UNIX-CONNECT:$ts"
9188 printf "test $F_n $TEST... " $N
9189 $CMD1 2>"${te}2" &
9190 pid1=$!
9191 sleep $SECONDs
9192 waitfile $ts $SECONDs
9193 $CMD 2>>"${te}1" >>"$tf"
9194 sleep $((2*SECONDs))
9195 kill "$pid1" 2>/dev/null
9196 wait
9197 if [ $? -ne 0 ]; then
9198 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9199 echo "$CMD1 &"
9200 echo "$CMD2"
9201 cat "${te}1" "${te}2"
9202 numFAIL=$((numFAIL+1))
9203 listFAIL="$listFAIL $N"
9204 elif [ -f "$tda" ]; then
9205 $PRINTF "$FAILED\n"
9206 cat "${te}1" "${te}2"
9207 numFAIL=$((numFAIL+1))
9208 listFAIL="$listFAIL $N"
9209 else
9210 $PRINTF "$OK\n"
9211 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9212 numOK=$((numOK+1))
9214 fi ;; # NUMCOND
9215 esac
9216 PORT=$((PORT+1))
9217 N=$((N+1))
9220 # test if service name resolution works; this was buggy in 1.5 and 1.6.0.0
9221 NAME=TCP4SERVICE
9222 case "$TESTS" in
9223 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
9224 TEST="$NAME: echo via connection to TCP V4 socket"
9225 # select a tcp entry from /etc/services, have a server listen on the port
9226 # number and connect using the service name; with the bug, connection will to a
9227 # wrong port
9228 if ! eval $NUMCOND; then :; else
9229 tf="$td/test$N.stdout"
9230 te="$td/test$N.stderr"
9231 tdiff="$td/test$N.diff"
9232 # find a service entry we do not need root for (>=1024; here >=1100 for ease)
9233 SERVENT="$(grep '^[a-z][a-z]*[^!-~][^!-~]*[1-9][1-9][0-9][0-9]/tcp' /etc/services |head -n 1)"
9234 SERVICE="$(echo $SERVENT |cut -d' ' -f1)"
9235 _PORT="$PORT"
9236 PORT="$(echo $SERVENT |sed 's/.* \([1-9][0-9]*\).*/\1/')"
9237 tsl="$PORT"
9238 ts="127.0.0.1:$SERVICE"
9239 da="test$N $(date) $RANDOM"
9240 CMD1="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr PIPE"
9241 CMD2="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
9242 printf "test $F_n $TEST... " $N
9243 $CMD1 >"$tf" 2>"${te}1" &
9244 pid1=$!
9245 waittcp4port $tsl 1
9246 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9247 if [ $? -ne 0 ]; then
9248 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9249 echo "$CMD1 &"
9250 cat "${te}1"
9251 echo "$CMD2"
9252 cat "${te}2"
9253 numFAIL=$((numFAIL+1))
9254 listFAIL="$listFAIL $N"
9255 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9256 $PRINTF "$FAILED\n"
9257 cat "$tdiff"
9258 numFAIL=$((numFAIL+1))
9259 listFAIL="$listFAIL $N"
9260 else
9261 $PRINTF "$OK\n"
9262 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9263 numOK=$((numOK+1))
9265 kill $pid1 2>/dev/null
9266 wait
9267 PORT="$_PORT"
9268 fi ;; # NUMCOND
9269 esac
9270 N=$((N+1))
9273 # test: up to socat 1.6.0.0, the highest file descriptor supported in socats
9274 # transfer engine was FOPEN_MAX-1; this usually worked fine but would fail when
9275 # socat was invoked with many file descriptors already opened. socat would
9276 # just hang in the select() call. Thanks to Daniel Lucq for reporting this
9277 # problem.
9278 # FOPEN_MAX on different OS's:
9279 # OS FOPEN_ ulimit ulimit FD_
9280 # MAX -H -n -S -n SETSIZE
9281 # Linux 2.6: 16 1024 1024 1024
9282 # HP-UX 11.11: 60 2048 2048 2048
9283 # FreeBSD: 20 11095 11095 1024
9284 # Cygwin: 20 unlimit 256 64
9285 # AIX: 32767 65534 65534
9286 # SunOS 8: 20 1024
9287 NAME=EXCEED_FOPEN_MAX
9288 case "$TESTS" in
9289 *%$N%*|*%functions%*|*%maxfds%*|*%$NAME%*)
9290 TEST="$NAME: more than FOPEN_MAX FDs in use"
9291 # this test opens a number of FDs before socat is invoked. socat will have to
9292 # allocate higher FD numbers and thus hang if it cannot handle them.
9293 if ! eval $NUMCOND; then :; else
9294 REDIR=
9295 #set -vx
9296 FOPEN_MAX=$($PROCAN -c 2>/dev/null |grep '^#define[ ][ ]*FOPEN_MAX' |awk '{print($3);}')
9297 if [ -z "$FOPEN_MAX" ]; then
9298 $PRINTF "test $F_n $TEST... ${YELLOW}could not determine FOPEN_MAX${NORMAL}\n" "$N"
9299 numCANT=$((numCANT+1))
9300 else
9301 OPEN_FILES=$FOPEN_MAX # more than the highest FOPEN_MAX
9302 i=3; while [ "$i" -lt "$OPEN_FILES" ]; do
9303 REDIR="$REDIR $i>&2"
9304 i=$((i+1))
9305 done
9306 #echo "$REDIR"
9307 #testecho "$N" "$TEST" "" "pipe" "$opts -T 3" "" 1
9308 #set -vx
9309 eval testecho "\"$N\"" "\"$TEST\"" "\"\"" "pipe" "\"$opts -T $((2*SECONDs))\"" 1 $REDIR
9310 #set +vx
9311 fi # could determine FOPEN_MAX
9312 fi ;; # NUMCOND
9313 esac
9314 N=$((N+1))
9317 # there was a bug with udp-listen and fork: terminating sub processes became
9318 # zombies because the master process did not catch SIGCHLD
9319 NAME=UDP4LISTEN_SIGCHLD
9320 case "$TESTS" in
9321 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%udp%*|*%zombie%*|*%signal%*|*%$NAME%*)
9322 TEST="$NAME: test if UDP4-LISTEN child becomes zombie"
9323 # idea: run a udp-listen process with fork and -T. Connect once, so a sub
9324 # process is forked off. Make some transfer and wait until the -T timeout is
9325 # over. Now check for the child process: if it is zombie the test failed.
9326 # Correct is that child process terminated
9327 if ! eval $NUMCOND; then :; else
9328 tf="$td/test$N.stdout"
9329 te="$td/test$N.stderr"
9330 tdiff="$td/test$N.diff"
9331 tsl=$PORT
9332 ts="$LOCALHOST:$tsl"
9333 da="test$N $(date) $RANDOM"
9334 CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-LISTEN:$tsl,reuseaddr,fork PIPE"
9335 CMD2="$TRACE $SOCAT $opts - UDP4:$ts"
9336 printf "test $F_n $TEST... " $N
9337 $CMD1 >"$tf" 2>"${te}1" &
9338 pid1=$!
9339 waitudp4port $tsl 1
9340 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9341 rc2=$?
9342 sleep 1
9343 #read -p ">"
9344 l="$(childprocess $pid1)"
9345 kill $pid1 2>/dev/null; wait
9346 if [ $rc2 -ne 0 ]; then
9347 $PRINTF "$NO_RESULT (client failed)\n" # already handled in test UDP4STREAM
9348 numCANT=$((numCANT+1))
9349 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9350 $PRINTF "$NO_RESULT (diff failed)\n" # already handled in test UDP4STREAM
9351 numCANT=$((numCANT+1))
9352 elif $(isdefunct "$l"); then
9353 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9354 echo "$CMD1 &"
9355 echo "$CMD2"
9356 cat "${te}1" "${te}2"
9357 numFAIL=$((numFAIL+1))
9358 listFAIL="$listFAIL $N"
9359 else
9360 $PRINTF "$OK\n"
9361 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9362 numOK=$((numOK+1))
9364 fi ;; # NUMCOND
9365 esac
9366 PORT=$((PORT+1))
9367 N=$((N+1))
9368 #set +vx
9370 # there was a bug with udp-recvfrom and fork: terminating sub processes became
9371 # zombies because the master process caught SIGCHLD but did not wait()
9372 NAME=UDP4RECVFROM_SIGCHLD
9373 case "$TESTS" in
9374 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%zombie%*|*%signal%*|*%$NAME%*)
9375 TEST="$NAME: test if UDP4-RECVFROM child becomes zombie"
9376 # idea: run a udp-recvfrom process with fork and -T. Send it one packet, so a
9377 # sub process is forked off. Make some transfer and wait until the -T timeout
9378 # is over. Now check for the child process: if it is zombie the test failed.
9379 # Correct is that child process terminated
9380 if ! eval $NUMCOND; then :; else
9381 tf="$td/test$N.stdout"
9382 te="$td/test$N.stderr"
9383 tdiff="$td/test$N.diff"
9384 tsl=$PORT
9385 ts="$LOCALHOST:$tsl"
9386 da="test$N $(date) $RANDOM"
9387 CMD1="$TRACE $SOCAT $opts -T 0.5 UDP4-RECVFROM:$tsl,reuseaddr,fork PIPE"
9388 CMD2="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts"
9389 printf "test $F_n $TEST... " $N
9390 $CMD1 >"$tf" 2>"${te}1" &
9391 pid1=$!
9392 waitudp4port $tsl 1
9393 echo "$da" |$CMD2 >>"$tf" 2>>"${te}2"
9394 rc2=$?
9395 sleep 1
9396 #read -p ">"
9397 l="$(childprocess $pid1)"
9398 kill $pid1 2>/dev/null; wait
9399 if [ $rc2 -ne 0 ]; then
9400 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9401 numCANT=$((numCANT+1))
9402 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9403 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9404 numCANT=$((numCANT+1))
9405 elif $(isdefunct "$l"); then
9406 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9407 echo "$CMD1 &"
9408 echo "$CMD2"
9409 cat "${te}1" "${te}2"
9410 numFAIL=$((numFAIL+1))
9411 listFAIL="$listFAIL $N"
9412 else
9413 $PRINTF "$OK\n"
9414 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9415 numOK=$((numOK+1))
9417 fi ;; # NUMCOND
9418 esac
9419 PORT=$((PORT+1))
9420 N=$((N+1))
9423 # test: there was a bug with ip*-recv and bind option: it would not bind, and
9424 # with the first received packet an error:
9425 # socket_init(): unknown address family 0
9426 # occurred
9427 NAME=RAWIP4RECVBIND
9428 case "$TESTS" in
9429 *%$N%*|*%functions%*|*%ip4%*|*%dgram%*|*%rawip%*|*%rawip4%*|*%recv%*|*%root%*|*%$NAME%*)
9430 TEST="$NAME: raw IPv4 receive with bind"
9431 # idea: start a socat process with ip4-recv:...,bind=... and send it a packet
9432 # if the packet passes the test succeeded
9433 if ! eval $NUMCOND; then :;
9434 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9435 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9436 numCANT=$((numCANT+1))
9437 else
9438 tf="$td/test$N.stdout"
9439 te="$td/test$N.stderr"
9440 tdiff="$td/test$N.diff"
9441 ts1p=$PROTO; PROTO=$((PROTO+1))
9442 ts1a="127.0.0.1"
9443 ts1="$ts1a:$ts1p"
9444 da="test$N $(date) $RANDOM"
9445 CMD1="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,bind=$ts1a,reuseaddr -"
9446 CMD2="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
9447 printf "test $F_n $TEST... " $N
9448 $CMD1 >"$tf" 2>"${te}1" &
9449 pid1="$!"
9450 waitip4proto $ts1p 1
9451 echo "$da" |$CMD2 2>>"${te}2"
9452 rc2="$?"
9453 #ls -l $tf
9454 i=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9455 kill "$pid1" 2>/dev/null; wait
9456 if [ "$rc2" -ne 0 ]; then
9457 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9458 echo "$CMD1 &"
9459 echo "$CMD2"
9460 cat "${te}1"
9461 cat "${te}2"
9462 numFAIL=$((numFAIL+1))
9463 listFAIL="$listFAIL $N"
9464 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9465 $PRINTF "$FAILED\n"
9466 cat "$tdiff"
9467 numFAIL=$((numFAIL+1))
9468 listFAIL="$listFAIL $N"
9469 else
9470 $PRINTF "$OK\n"
9471 if [ -n "$debug" ]; then cat $te; fi
9472 numOK=$((numOK+1))
9474 fi ;; # NUMCOND, root
9475 esac
9476 PROTO=$((PROTO+1))
9477 N=$((N+1))
9480 # there was a bug in *-recvfrom with fork: due to an error in the appropriate
9481 # signal handler the master process would hang after forking off the first
9482 # child process.
9483 NAME=UDP4RECVFROM_FORK
9484 case "$TESTS" in
9485 *%$N%*|*%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
9486 TEST="$NAME: test if UDP4-RECVFROM handles more than one packet"
9487 # idea: run a UDP4-RECVFROM process with fork and -T. Send it one packet;
9488 # send it a second packet and check if this is processed properly. If yes, the
9489 # test succeeded.
9490 if ! eval $NUMCOND; then :; else
9491 tf="$td/test$N.stdout"
9492 te="$td/test$N.stderr"
9493 tdiff="$td/test$N.diff"
9494 tsp=$PORT
9495 ts="$LOCALHOST:$tsp"
9496 da="test$N $(date) $RANDOM"
9497 CMD1="$TRACE $SOCAT $opts -T 2 UDP4-RECVFROM:$tsp,reuseaddr,fork PIPE"
9498 CMD2="$TRACE $SOCAT $opts -T 1 - UDP4-SENDTO:$ts"
9499 printf "test $F_n $TEST... " $N
9500 $CMD1 >/dev/null 2>"${te}1" &
9501 pid1=$!
9502 waitudp4port $tsp 1
9503 echo "$da" |$CMD2 >/dev/null 2>>"${te}2" # this should always work
9504 rc2a=$?
9505 sleep 1
9506 echo "$da" |$CMD2 >"$tf" 2>>"${te}3" # this would fail when bug
9507 rc2b=$?
9508 kill $pid1 2>/dev/null; wait
9509 if [ $rc2b -ne 0 ]; then
9510 $PRINTF "$NO_RESULT\n"
9511 numCANT=$((numCANT+1))
9512 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9513 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9514 echo "$CMD1 &"
9515 echo "$CMD2"
9516 cat "${te}1" "${te}2" "${te}3"
9517 cat "$tdiff"
9518 numFAIL=$((numFAIL+1))
9519 listFAIL="$listFAIL $N"
9520 else
9521 $PRINTF "$OK\n"
9522 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3"; fi
9523 numOK=$((numOK+1))
9525 fi ;; # NUMCOND
9526 esac
9527 PORT=$((PORT+1))
9528 N=$((N+1))
9531 # there was a bug in parsing the arguments of exec: consecutive spaces resulted
9532 # in additional empty arguments
9533 NAME=EXECSPACES
9534 case "$TESTS" in
9535 *%$N%*|*%functions%*|*%exec%*|*%parse%*|*%$NAME%*)
9536 TEST="$NAME: correctly parse exec with consecutive spaces"
9537 if ! eval $NUMCOND; then :; else
9538 $PRINTF "test $F_n $TEST... " $N
9539 tf="$td/test$N.stdout"
9540 te="$td/test$N.stderr"
9541 da="test$N $(date) $RANDOM" # with a double space
9542 tdiff="$td/test$N.diff"
9543 # put the test data as first argument after two spaces. expect the data in the
9544 # first argument of the exec'd command.
9545 $TRACE $SOCAT $opts -u "exec:\"bash -c \\\"echo \\\\\\\"\$1\\\\\\\"\\\" \\\"\\\" \\\"$da\\\"\"" - >"$tf" 2>"$te"
9546 rc=$?
9547 echo "$da" |diff - "$tf" >"$tdiff"
9548 if [ "$rc" -ne 0 ]; then
9549 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9550 cat "$te"
9551 numFAIL=$((numFAIL+1))
9552 listFAIL="$listFAIL $N"
9553 elif [ -s "$tdiff" ]; then
9554 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9555 echo diff:
9556 cat "$tdiff"
9557 if [ -n "$debug" ]; then cat $te; fi
9558 numFAIL=$((numFAIL+1))
9559 listFAIL="$listFAIL $N"
9560 else
9561 $PRINTF "$OK\n"
9562 if [ -n "$debug" ]; then cat $te; fi
9563 numOK=$((numOK+1))
9565 fi ;; # NUMCOND
9566 esac
9567 N=$((N+1))
9570 # a bug was found in the way UDP-LISTEN handles the listening socket:
9571 # when UDP-LISTEN continued to listen after a packet had been dropped by, e.g.,
9572 # range option, the old listen socket would not be closed but a new one created.
9573 NAME=UDP4LISTENCONT
9574 case "$TESTS" in
9575 *%$N%*|*%functions%*|*%bugs%*|*%ip4%*|*%udp%*|*%$NAME%*)
9576 TEST="$NAME: let range drop a packet and see if old socket is closed"
9577 # idea: run a UDP4-LISTEN process with range option. Send it one packet from an
9578 # address outside range and check if two listening sockets are open then
9579 if ! eval $NUMCOND; then :; else
9580 tf="$td/test$N.stdout"
9581 te="$td/test$N.stderr"
9582 tdiff="$td/test$N.diff"
9583 while [ "$(netstat -an |grep "^udp.*127.0.0.1:$PORT" |wc -l)" -ne 0 ]; do
9584 PORT=$((PORT+1))
9585 done
9586 tp=$PORT
9587 da1="test$N $(date) $RANDOM"
9588 a1="$LOCALHOST"
9589 a2="$SECONDADDR"
9590 #CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,bind=$a1,range=$a2/32 PIPE"
9591 CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,range=$a2/32 PIPE"
9592 CMD1="$TRACE $SOCAT $opts - UDP-CONNECT:$a1:$tp"
9593 printf "test $F_n $TEST... " $N
9594 $CMD0 >/dev/null 2>"${te}0" &
9595 pid1=$!
9596 waitudp4port $tp 1
9597 echo "$da1" |$CMD1 >"${tf}1" 2>"${te}1" # this should fail
9598 rc1=$?
9599 waitudp4port $tp 1
9600 nsocks="$(netstat -an |grep "^udp.*[:.]$PORT" |wc -l)"
9601 kill $pid1 2>/dev/null; wait
9602 if [ $rc1 -ne 0 ]; then
9603 $PRINTF "$NO_RESULT\n"
9604 numCANT=$((numCANT+1))
9605 elif [ $nsocks -eq 0 ]; then
9606 $PRINTF "$NO_RESULT\n"
9607 numCANT=$((numCANT+1))
9608 elif [ $nsocks -ne 1 ]; then
9609 $PRINTF "$FAILED ($nsocks listening sockets)\n"
9610 echo "$CMD0 &"
9611 echo "$CMD1"
9612 cat "${te}0" "${te}1"
9613 numFAIL=$((numFAIL+1))
9614 listFAIL="$listFAIL $N"
9615 else
9616 $PRINTF "$OK\n"
9617 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
9618 numOK=$((numOK+1))
9620 fi ;; # NUMCOND
9621 esac
9622 PORT=$((PORT+1))
9623 N=$((N+1))
9626 # during wait for next poll time option ignoreeof blocked the data transfer in
9627 # the reverse direction
9628 NAME=IGNOREEOFNOBLOCK
9629 case "$TESTS" in
9630 *%$N%*|*%functions%*|*%engine%*|*%socket%*|*%ignoreeof%*|*%$NAME%*)
9631 TEST="$NAME: ignoreeof does not block other direction"
9632 # have socat poll in ignoreeof mode. while it waits one second for next check,
9633 # we send data in the reverse direction and then the total timeout fires.
9634 # it the data has passed, the test succeeded.
9635 if ! eval $NUMCOND; then :; else
9636 tf="$td/test$N.stout"
9637 te="$td/test$N.stderr"
9638 tdiff="$td/test$N.diff"
9639 da="test$N $(date) $RANDOM"
9640 CMD0="$TRACE $SOCAT $opts /dev/null,ignoreeof!!- -!!/dev/null"
9641 printf "test $F_n $TEST... " $N
9642 (usleep 333333; echo "$da") |$CMD0 >"$tf" 2>"${te}0"
9643 rc0=$?
9644 if [ $rc0 != 0 ]; then
9645 $PRINTF "$FAILED\n"
9646 echo "$CMD0 &"
9647 echo "$CMD1"
9648 cat "${te}0"
9649 cat "${te}1"
9650 numFAIL=$((numFAIL+1))
9651 listFAIL="$listFAIL $N"
9652 elif echo "$da" |diff - "$tf" >/dev/null; then
9653 $PRINTF "$OK\n"
9654 numOK=$((numOK+1))
9655 else
9656 $PRINTF "$FAILED\n"
9657 echo "$CMD0 &"
9658 echo "$CMD1"
9659 cat "${te}0"
9660 numFAIL=$((numFAIL+1))
9661 listFAIL="$listFAIL $N"
9663 fi ;; # NUMCOND
9664 esac
9665 N=$((N+1))
9668 # test the escape option
9669 NAME=ESCAPE
9670 case "$TESTS" in
9671 *%$N%*|*%functions%*|*%engine%*|*%escape%*|*%$NAME%*)
9672 TEST="$NAME: escape character triggers EOF"
9673 # idea: start socat just echoing input, but apply escape option. send a string
9674 # containing the escape character and check if the output is truncated
9675 if ! eval $NUMCOND; then :; else
9676 tf="$td/test$N.stdout"
9677 te="$td/test$N.stderr"
9678 tdiff="$td/test$N.diff"
9679 da="test$N $(date) $RANDOM"
9680 CMD="$TRACE $SOCAT $opts -,escape=27 pipe"
9681 printf "test $F_n $TEST... " $N
9682 $ECHO "$da\n\x1bXYZ" |$CMD >"$tf" 2>"$te"
9683 if [ $? -ne 0 ]; then
9684 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9685 echo "$CMD"
9686 cat "$te"
9687 numFAIL=$((numFAIL+1))
9688 listFAIL="$listFAIL $N"
9689 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
9690 $PRINTF "$FAILED: diff:\n"
9691 cat "$tdiff"
9692 numFAIL=$((numFAIL+1))
9693 listFAIL="$listFAIL $N"
9694 else
9695 $PRINTF "$OK\n"
9696 if [ -n "$debug" ]; then cat $te; fi
9697 numOK=$((numOK+1))
9699 fi ;; # NUMCOND
9700 esac
9701 N=$((N+1))
9703 # test the escape option combined with ignoreeof
9704 NAME=ESCAPE_IGNOREEOF
9705 case "$TESTS" in
9706 *%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%escape%*|*%$NAME%*)
9707 TEST="$NAME: escape character triggers EOF"
9708 # idea: start socat just echoing input, but apply escape option. send a string
9709 # containing the escape character and check if the output is truncated
9710 if ! eval $NUMCOND; then :; else
9711 ti="$td/test$N.file"
9712 tf="$td/test$N.stdout"
9713 te="$td/test$N.stderr"
9714 tdiff="$td/test$N.diff"
9715 da="test$N $(date) $RANDOM"
9716 CMD="$TRACE $SOCAT -T 5 $opts file:$ti,ignoreeof,escape=27!!- pipe"
9717 printf "test $F_n $TEST... " $N
9718 >"$ti"
9719 $CMD >"$tf" 2>"$te" &
9720 $ECHO "$da\n\x1bXYZ" >>"$ti"
9721 sleep 1
9722 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
9723 $PRINTF "$FAILED: diff:\n"
9724 cat "$tdiff"
9725 cat "$te"
9726 numFAIL=$((numFAIL+1))
9727 listFAIL="$listFAIL $N"
9728 else
9729 $PRINTF "$OK\n"
9730 if [ -n "$debug" ]; then cat $te; fi
9731 numOK=$((numOK+1))
9733 fi ;; # NUMCOND
9734 esac
9735 N=$((N+1))
9738 # test: logging of ancillary message
9739 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_TYPE SCM_NAME ROOT SCM_VALUE
9741 if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
9743 pf="$(echo "$PF" |tr A-Z a-z)"
9744 proto="$(echo "$KEYW" |tr A-Z a-z)"
9745 NAME=${KEYW}SCM_$SCM_TYPE
9746 case "$TESTS" in
9747 *%$N%*|*%functions%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%$ROOT%*|*%$NAME%*)
9748 TEST="$NAME: $KEYW log ancillary message $SCM_TYPE $SCM_NAME"
9749 # idea: start a socat process with *-RECV:..,... , ev. with ancillary message
9750 # enabling option and send it a packet, ev. with some option. check the info log
9751 # for the appropriate output.
9752 if ! eval $NUMCOND; then :;
9753 #elif [[ "$PF" == "#*" ]]; then :
9754 elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
9755 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9756 numCANT=$((numCANT+1))
9757 elif [ "$PF" = "IP6" ] && ( ! feat=$(testaddrs ip6) || ! runsip6 >/dev/null ); then
9758 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
9759 numCANT=$((numCANT+1))
9760 elif ! testoptions $SCM_RECV >/dev/null; then
9761 $PRINTF "test $F_n $TEST... ${YELLOW}option $SCM_RECV not available${NORMAL}\n" $N
9762 numCANT=$((numCANT+1))
9763 else
9764 tf="$td/test$N.stdout"
9765 te="$td/test$N.stderr"
9766 case "X$IPPORT" in
9767 "XPORT")
9768 tra="$PORT" # test recv address
9769 tsa="$ADDR:$PORT" # test sendto address
9770 PORT=$((PORT+1)) ;;
9771 "XPROTO")
9772 tra="$PROTO" # test recv address
9773 tsa="$ADDR:$PROTO" # test sendto address
9774 PROTO=$((PROTO+1)) ;;
9776 tra="$(eval echo "$ADDR")" # resolve $N
9777 tsa="$tra"
9778 esac
9779 CMD0="$TRACE $SOCAT $opts -d -d -d -u $KEYW-RECV:$tra,reuseaddr,$SCM_RECV -"
9780 CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
9781 printf "test $F_n $TEST... " $N
9782 # is this option supported?
9783 if $TRACE $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
9784 $CMD0 >"$tf" 2>"${te}0" &
9785 pid0="$!"
9786 wait${proto}port $tra 1
9787 echo "XYZ" |$CMD1 2>"${te}1"
9788 rc1="$?"
9789 sleep 1
9790 i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
9791 kill "$pid0" 2>/dev/null; wait
9792 # do not show more messages than requested
9793 case "$opts" in
9794 *-d*-d*-d*-d*) LEVELS="[EWNID]" ;;
9795 *-d*-d*-d*) LEVELS="[EWNI]" ;;
9796 *-d*-d*) LEVELS="[EWN]" ;;
9797 *-d*) LEVELS="[EW]" ;;
9798 *) LEVELS="[E]" ;;
9799 esac
9800 if [ "$SCM_VALUE" = "timestamp" ]; then
9801 SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y')"
9803 if [ "$rc1" -ne 0 ]; then
9804 $PRINTF "$NO_RESULT: $TRACE $SOCAT:\n"
9805 echo "$CMD0 &"
9806 echo "$CMD1"
9807 grep " $LEVELS " "${te}0"
9808 grep " $LEVELS " "${te}1"
9809 numCANT=$((numCANT+1))
9810 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=" ${te}0 >/dev/null; then
9811 $PRINTF "$FAILED\n"
9812 echo "variable $SCM_TYPE: $SCM_NAME not set"
9813 echo "$CMD0 &"
9814 echo "$CMD1"
9815 grep " $LEVELS " "${te}0"
9816 grep " $LEVELS " "${te}1"
9817 numFAIL=$((numFAIL+1))
9818 listFAIL="$listFAIL $N"
9819 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=$SCM_VALUE" ${te}0 >/dev/null; then
9820 $PRINTF "$FAILED\n"
9821 badval="$(grep "ancillary message: $SCM_TYPE: $SCM_NAME" ${te}0 |sed 's/.*=//g')"
9822 echo "variable $SCM_TYPE: $SCM_NAME has value \"$badval\" instead of pattern \"$SCM_VALUE\"" >&2
9823 echo "$CMD0 &"
9824 echo "$CMD1"
9825 grep " $LEVELS " "${te}0"
9826 grep " $LEVELS " "${te}1"
9827 numFAIL=$((numFAIL+1))
9828 listFAIL="$listFAIL $N"
9829 else
9830 $PRINTF "$OK\n"
9831 if [ -n "$debug" ]; then
9832 grep " $LEVELS " "${te}0"; echo; grep " $LEVELS " "${te}1";
9834 numOK=$((numOK+1))
9836 #set +vx
9837 else # option is not supported
9838 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
9839 numCANT=$((numCANT+1))
9840 fi # option is not supported
9841 fi # NUMCOND, root, feats
9843 esac
9844 N=$((N+1))
9846 done <<<"
9847 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS options user x01000000
9848 IP4 UDP4 127.0.0.1 PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
9849 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL ttl user 53
9850 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS tos user 7
9851 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO locaddr user 127.0.0.1
9852 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO dstaddr user 127.0.0.1
9853 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO if user lo
9854 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_RECVIF if user lo0
9855 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_RECVDSTADDR dstaddr user 127.0.0.1
9856 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS options root x01000000
9857 IP4 IP4 127.0.0.1 PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
9858 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL ttl root 53
9859 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS tos root 7
9860 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO locaddr root 127.0.0.1
9861 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO dstaddr root 127.0.0.1
9862 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO if root lo
9863 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_RECVIF if root lo0
9864 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_RECVDSTADDR dstaddr root 127.0.0.1
9865 IP6 UDP6 [::1] PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
9866 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_PKTINFO dstaddr user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
9867 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit user 35
9868 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass user xaa000000
9869 IP6 IP6 [::1] PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
9870 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_PKTINFO dstaddr root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
9871 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit root 35
9872 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass root xaa000000
9873 #UNIX UNIX $td/test\$N.server - , so-timestamp SCM_TIMESTAMP timestamp user timestamp
9875 # this one fails, appearently due to a Linux weakness:
9876 # UNIX so-timestamp
9879 # test: setting of environment variables that describe a stream socket
9880 # connection: SOCAT_SOCKADDR, SOCAT_PEERADDR; and SOCAT_SOCKPORT,
9881 # SOCAT_PEERPORT when applicable
9882 while read KEYW FEAT TEST_SOCKADDR TEST_PEERADDR TEST_SOCKPORT TEST_PEERPORT; do
9883 if [ -z "$KEYW" ] || [[ "$KEYW" == \#* ]]; then continue; fi
9885 test_proto="$(echo "$KEYW" |tr A-Z a-z)"
9886 NAME=${KEYW}LISTENENV
9887 case "$TESTS" in
9888 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$test_proto%*|*%envvar%*|*%$NAME%*)
9889 TEST="$NAME: $KEYW-LISTEN sets environment variables with socket addresses"
9890 # have a server accepting a connection and invoking some shell code. The shell
9891 # code extracts and prints the SOCAT related environment vars.
9892 # outside code then checks if the environment contains the variables correctly
9893 # describing the peer and local sockets.
9894 if ! eval $NUMCOND; then :;
9895 elif ! feat=$(testaddrs $FEAT); then
9896 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
9897 numCANT=$((numCANT+1))
9898 elif [ "$KEYW" = "TCP6" -o "$KEYW" = "UDP6" -o "$KEYW" = "SCTP6" ] && \
9899 ! runsip6 >/dev/null; then
9900 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
9901 numCANT=$((numCANT+1))
9902 elif [ "$KEYW" = "SCTP4" ] && ! runssctp4 "$((PORT))"; then
9903 $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
9904 elif [ "$KEYW" = "SCTP6" ] && ! runssctp4 "$((PORT))"; then
9905 #!!! branch not reached - caught above!
9906 $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
9907 else
9908 tf="$td/test$N.stdout"
9909 te="$td/test$N.stderr"
9910 TEST_SOCKADDR="$(echo "$TEST_SOCKADDR" |sed "s/\$N/$N/g")" # actual vars
9911 tsa="$TEST_SOCKADDR" # test server address
9912 tsp="$TEST_SOCKPORT" # test server port
9913 if [ "$tsp" != ',' ]; then
9914 tsa1="$tsp"; tsa2="$tsa"; tsa="$tsa:$tsp" # tsa2 used for server bind=
9915 else
9916 tsa1="$tsa"; tsa2= # tsa1 used for addr parameter
9918 TEST_PEERADDR="$(echo "$TEST_PEERADDR" |sed "s/\$N/$N/g")" # actual vars
9919 tca="$TEST_PEERADDR" # test client address
9920 tcp="$TEST_PEERPORT" # test client port
9921 if [ "$tcp" != ',' ]; then
9922 tca="$tca:$tcp"
9924 #CMD0="$TRACE $SOCAT $opts -u $KEYW-LISTEN:$tsa1 SYSTEM:\"export -p\""
9925 CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-LISTEN:$tsa1 SYSTEM:\"echo SOCAT_SOCKADDR=\\\$SOCAT_SOCKADDR; echo SOCAT_PEERADDR=\\\$SOCAT_PEERADDR; echo SOCAT_SOCKPORT=\\\$SOCAT_SOCKPORT; echo SOCAT_PEERPORT=\\\$SOCAT_PEERPORT; sleep 1\""
9926 CMD1="$TRACE $SOCAT $opts -u - $KEYW-CONNECT:$tsa,bind=$tca"
9927 printf "test $F_n $TEST... " $N
9928 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
9929 pid0=$!
9930 wait${test_proto}port $tsa1 1
9931 echo |$CMD1 2>"${te}1"
9932 rc1=$?
9933 waitfile "$tf" 2
9934 kill $pid0 2>/dev/null; wait
9935 #set -vx
9936 if [ $rc1 != 0 ]; then
9937 $PRINTF "$NO_RESULT (client failed):\n"
9938 echo "$CMD0 &"
9939 cat "${te}0"
9940 echo "$CMD1"
9941 cat "${te}1"
9942 numCANT=$((numCANT+1))
9943 elif [ "$(grep SOCAT_SOCKADDR "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")" = "$TEST_SOCKADDR" -a \
9944 "$(grep SOCAT_PEERADDR "${tf}" |sed -e 's/^[^=]*=//' -e "s/[\"']//g")" = "$TEST_PEERADDR" -a \
9945 \( "$TEST_SOCKPORT" = ',' -o "$(grep SOCAT_SOCKPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tsp" \) -a \
9946 \( "$TEST_PEERPORT" = ',' -o "$(grep SOCAT_PEERPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g')" = "$tcp" \) \
9947 ]; then
9948 $PRINTF "$OK\n"
9949 if [ "$debug" ]; then
9950 echo "$CMD0 &"
9951 cat "${te}0"
9952 echo "$CMD1"
9953 cat "${te}1"
9955 numOK=$((numOK+1))
9956 else
9957 $PRINTF "$FAILED\n"
9958 echo "$CMD0 &"
9959 cat "${te}0"
9960 echo "$CMD1"
9961 cat "${te}1"
9962 echo -e "SOCAT_SOCKADDR=$TEST_SOCKADDR\nSOCAT_PEERADDR=$TEST_PEERADDR\nSOCAT_SOCKPORT=$TEST_SOCKPORT\nSOCAT_PEERPORT=$TEST_PEERPORT" |
9963 diff - "${tf}"
9964 numFAIL=$((numFAIL+1))
9965 listFAIL="$listFAIL $N"
9967 fi # NUMCOND, feats
9969 esac
9970 N=$((N+1))
9971 #set +xv
9973 done <<<"
9974 TCP4 TCP 127.0.0.1 $SECONDADDR $PORT $((PORT+1))
9975 TCP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+2)) $((PORT+3))
9976 UDP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+6)) $((PORT+7))
9977 SCTP4 SCTP 127.0.0.1 $SECONDADDR $((PORT+8)) $((PORT+9))
9978 SCTP6 SCTP [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+10)) $((PORT+11))
9979 UNIX UNIX $td/test\$N.server $td/test\$N.client , ,
9981 # this one fails due to weakness in socats UDP4-LISTEN implementation:
9982 #UDP4 $LOCALHOST $SECONDADDR $((PORT+4)) $((PORT+5))
9985 # test: environment variables from ancillary message
9986 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_ENVNAME ROOT SCM_VALUE
9988 if [ -z "$PF" ] || [[ "$PF" == \#* ]]; then continue; fi
9990 pf="$(echo "$PF" |tr A-Z a-z)"
9991 proto="$(echo "$KEYW" |tr A-Z a-z)"
9992 NAME=${KEYW}ENV_$SCM_ENVNAME
9993 case "$TESTS" in
9994 *%$N%*|*%functions%*|*%$pf%*|*%dgram%*|*%udp%*|*%$proto%*|*%recv%*|*%ancillary%*|*%envvar%*|*%$ROOT%*|*%$NAME%*)
9995 #set -vx
9996 TEST="$NAME: $KEYW ancillary message sets env SOCAT_$SCM_ENVNAME"
9997 # idea: start a socat process with *-RECVFROM:..,... , ev. with ancillary
9998 # message enabling option and send it a packet, ev. with some option. write
9999 # the resulting environment to a file and check its contents for the
10000 # appropriate variable.
10001 if ! eval $NUMCOND; then :;
10002 elif [ "$ROOT" = root -a $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
10003 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
10004 numCANT=$((numCANT+1))
10005 elif [ "$PF" = "IP6" ] && ( ! feat=$(testaddrs ip6) || ! runsip6 ) >/dev/null; then
10006 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10007 numCANT=$((numCANT+1))
10008 else
10009 tf="$td/test$N.stdout"
10010 te="$td/test$N.stderr"
10011 case "X$IPPORT" in
10012 "XPORT")
10013 tra="$PORT" # test recv address
10014 tsa="$ADDR:$PORT" # test sendto address
10015 PORT=$((PORT+1)) ;;
10016 "XPROTO")
10017 tra="$PROTO" # test recv address
10018 tsa="$ADDR:$PROTO" # test sendto address
10019 PROTO=$((PROTO+1)) ;;
10021 tra="$(eval echo "$ADDR")" # resolve $N
10022 tsa="$tra"
10023 esac
10024 #CMD0="$TRACE $SOCAT $opts -u $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"export -p\""
10025 CMD0="$TRACE $SOCAT $opts -u -lpsocat $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"echo \\\$SOCAT_$SCM_ENVNAME\""
10026 CMD1="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
10027 printf "test $F_n $TEST... " $N
10028 # is this option supported?
10029 if $SOCAT -hhh |grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev/null; then
10030 eval "$CMD0 >\"$tf\" 2>\"${te}0\" &"
10031 pid0="$!"
10032 wait${proto}port $tra 1
10033 echo "XYZ" |$CMD1 2>"${te}1"
10034 rc1="$?"
10035 waitfile "$tf" 2
10036 #i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
10037 kill "$pid0" 2>/dev/null; wait
10038 # do not show more messages than requested
10039 if [ "$SCM_VALUE" = "timestamp" ]; then
10040 SCM_VALUE="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
10042 if [ "$rc1" -ne 0 ]; then
10043 $PRINTF "$NO_RESULT: $SOCAT:\n"
10044 echo "$CMD0 &"
10045 echo "$CMD1"
10046 cat "${te}0"
10047 cat "${te}1"
10048 numCANT=$((numCANT+1))
10049 #elif ! egrep "^export SOCAT_$SCM_ENVNAME=[\"']?$SCM_VALUE[\"']?\$" ${tf} >/dev/null; then
10050 #elif ! eval echo "$TRACE $SOCAT_\$SCM_VALUE" |diff - "${tf}" >/dev/null; then
10051 elif ! expr "$(cat "$tf")" : "$(eval echo "\$SCM_VALUE")" >/dev/null; then
10052 $PRINTF "$FAILED\n"
10053 echo "$CMD0 &"
10054 echo "$CMD1"
10055 cat "${te}0"
10056 cat "${te}1"
10057 numFAIL=$((numFAIL+1))
10058 listFAIL="$listFAIL $N"
10059 else
10060 $PRINTF "$OK\n"
10061 if [ -n "$debug" ]; then
10062 cat "${te}0"; echo; cat "${te}1";
10064 numOK=$((numOK+1))
10066 else # option is not supported
10067 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
10068 numCANT=$((numCANT+1))
10069 fi # option is not supported
10070 fi ;; # NUMCOND, feats
10071 esac
10072 N=$((N+1))
10074 done <<<"
10075 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS user x01000000
10076 IP4 UDP4 127.0.0.1 PORT , so-timestamp TIMESTAMP user timestamp
10077 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL user 53
10078 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS user 7
10079 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_LOCADDR user 127.0.0.1
10080 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_DSTADDR user 127.0.0.1
10081 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_IF user lo
10082 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_IF user lo0
10083 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_DSTADDR user 127.0.0.1
10084 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS root x01000000
10085 IP4 IP4 127.0.0.1 PROTO , so-timestamp TIMESTAMP root timestamp
10086 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL root 53
10087 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS root 7
10088 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_LOCADDR root 127.0.0.1
10089 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_DSTADDR root 127.0.0.1
10090 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_IF root lo
10091 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_IF root lo0
10092 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_DSTADDR root 127.0.0.1
10093 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_DSTADDR user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10094 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT user 35
10095 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS user xaa000000
10096 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_DSTADDR root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10097 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT root 35
10098 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS root xaa000000
10099 #UNIX UNIX $td/test\$N.server - , so-timestamp TIMESTAMP user timestamp
10103 # test the SOCKET-CONNECT address (against TCP4-LISTEN)
10104 NAME=SOCKET_CONNECT_TCP4
10105 case "$TESTS" in
10106 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
10107 TEST="$NAME: socket connect with TCP/IPv4"
10108 # start a TCP4-LISTEN process that echoes data, and send test data using
10109 # SOCKET-CONNECT, selecting TCP/IPv4. The sent data should be returned.
10110 if ! eval $NUMCOND; then :; else
10111 tf="$td/test$N.stdout"
10112 te="$td/test$N.stderr"
10113 tdiff="$td/test$N.diff"
10114 ts0p=$PORT; PORT=$((PORT+1))
10115 ts0a="127.0.0.1"
10116 ts1p=$(printf "%04x" $ts0p);
10117 ts1a="7f000001" # "127.0.0.1"
10118 ts1="x${ts1p}${ts1a}x0000000000000000"
10119 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10120 da="test$N $(date) $RANDOM"
10121 CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$ts0p,reuseaddr,bind=$ts0a PIPE"
10122 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:2:6:$ts1,bind=x${ts1b}00000000x0000000000000000"
10123 printf "test $F_n $TEST... " $N
10124 $CMD0 2>"${te}0" &
10125 pid0="$!"
10126 waittcp4port $ts0p 1
10127 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10128 rc1="$?"
10129 kill "$pid0" 2>/dev/null; wait;
10130 if [ "$rc1" -ne 0 ]; then
10131 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10132 echo "$CMD0 &"
10133 cat "${te}0"
10134 echo "$CMD1"
10135 cat "${te}1"
10136 numFAIL=$((numFAIL+1))
10137 listFAIL="$listFAIL $N"
10138 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10139 $PRINTF "$FAILED\n"
10140 cat "$tdiff"
10141 echo "$CMD0 &"
10142 cat "${te}0"
10143 echo "$CMD1"
10144 cat "${te}1"
10145 numFAIL=$((numFAIL+1))
10146 listFAIL="$listFAIL $N"
10147 else
10148 $PRINTF "$OK\n"
10149 if [ -n "$debug" ]; then cat $te; fi
10150 numOK=$((numOK+1))
10152 fi # NUMCOND
10154 esac
10155 PORT=$((PORT+1))
10156 N=$((N+1))
10158 PF_INET6="$($PROCAN -c |grep "^#define[[:space:]]*PF_INET6[[:space:]]" |cut -d' ' -f3)"
10160 # test the SOCKET-CONNECT address (against TCP6-LISTEN)
10161 NAME=SOCKET_CONNECT_TCP6
10162 case "$TESTS" in
10163 *%$N%*|*%functions%*|*%generic%*|*%tcp6%*|*%socket%*|*%$NAME%*)
10164 TEST="$NAME: socket connect with TCP/IPv6"
10165 if ! eval $NUMCOND; then :;
10166 elif ! testaddrs tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
10167 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
10168 numCANT=$((numCANT+1))
10169 else
10170 # start a TCP6-LISTEN process that echoes data, and send test data using
10171 # SOCKET-CONNECT, selecting TCP/IPv6. The sent data should be returned.
10172 tf="$td/test$N.stdout"
10173 te="$td/test$N.stderr"
10174 tdiff="$td/test$N.diff"
10175 ts0p=$PORT; PORT=$((PORT+1))
10176 ts0a="[::1]"
10177 ts1p=$(printf "%04x" $ts0p);
10178 ts1a="00000000000000000000000000000001" # "[::1]"
10179 ts1="x${ts1p}x00000000x${ts1a}x00000000"
10180 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10181 da="test$N $(date) $RANDOM"
10182 CMD0="$TRACE $SOCAT $opts TCP6-LISTEN:$ts0p,reuseaddr,bind=$ts0a PIPE"
10183 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:$PF_INET6:6:$ts1,bind=x${ts1b}x00000000x00000000000000000000000000000000x00000000"
10184 printf "test $F_n $TEST... " $N
10185 $CMD0 2>"${te}0" &
10186 pid0="$!"
10187 waittcp6port $ts0p 1
10188 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10189 rc1="$?"
10190 kill "$pid0" 2>/dev/null; wait;
10191 if [ "$rc1" -ne 0 ]; then
10192 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10193 echo "$CMD0 &"
10194 cat "${te}0"
10195 echo "$CMD1"
10196 cat "${te}1"
10197 numFAIL=$((numFAIL+1))
10198 listFAIL="$listFAIL $N"
10199 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10200 $PRINTF "$FAILED\n"
10201 cat "$tdiff"
10202 echo "$CMD0 &"
10203 cat "${te}0"
10204 echo "$CMD1"
10205 cat "${te}1"
10206 numFAIL=$((numFAIL+1))
10207 listFAIL="$listFAIL $N"
10208 else
10209 $PRINTF "$OK\n"
10210 if [ -n "$debug" ]; then cat $te; fi
10211 numOK=$((numOK+1))
10213 fi ;; # NUMCOND
10214 esac
10215 PORT=$((PORT+1))
10216 N=$((N+1))
10218 # test the SOCKET-CONNECT address (against UNIX-LISTEN)
10219 NAME=SOCKET_CONNECT_UNIX
10220 case "$TESTS" in
10221 *%$N%*|*%functions%*|*%generic%*|*%unix%*|*%socket%*|*%$NAME%*)
10222 TEST="$NAME: socket connect with UNIX domain"
10223 # start a UNIX-LISTEN process that echoes data, and send test data using
10224 # SOCKET-CONNECT, selecting UNIX socket. The sent data should be returned.
10225 if ! eval $NUMCOND; then :; else
10226 tf="$td/test$N.stdout"
10227 te="$td/test$N.stderr"
10228 tdiff="$td/test$N.diff"
10229 ts0="$td/test$N.server"
10230 ts1="$td/test$N.client"
10231 da="test$N $(date) $RANDOM"
10232 CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts0,reuseaddr PIPE"
10233 CMD1="$TRACE $SOCAT $opts - SOCKET-CONNECT:1:0:\\\"$ts0\\\0\\\",bind=\\\"$ts1\\\0\\\""
10234 printf "test $F_n $TEST... " $N
10235 $CMD0 2>"${te}0" &
10236 pid0="$!"
10237 waitfile $ts0 1
10238 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10239 rc1="$?"
10240 kill "$pid0" 2>/dev/null; wait;
10241 if [ "$rc1" -ne 0 ]; then
10242 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10243 echo "$CMD0 &"
10244 cat "${te}0"
10245 echo "$CMD1"
10246 cat "${te}1"
10247 numFAIL=$((numFAIL+1))
10248 listFAIL="$listFAIL $N"
10249 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10250 $PRINTF "$FAILED\n"
10251 cat "$tdiff"
10252 echo "$CMD0 &"
10253 cat "${te}0"
10254 echo "$CMD1"
10255 cat "${te}1"
10256 numFAIL=$((numFAIL+1))
10257 listFAIL="$listFAIL $N"
10258 else
10259 $PRINTF "$OK\n"
10260 if [ -n "$debug" ]; then cat $te; fi
10261 numOK=$((numOK+1))
10263 fi ;; # NUMCOND
10264 esac
10265 N=$((N+1))
10267 # test the SOCKET-LISTEN address (with TCP4-CONNECT)
10268 NAME=SOCKET_LISTEN
10269 case "$TESTS" in
10270 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%$NAME%*)
10271 TEST="$NAME: socket recvfrom with TCP/IPv4"
10272 # start a SOCKET-LISTEN process that uses TCP/IPv4 and echoes data, and
10273 # send test data using TCP4-CONNECT. The sent data should be returned.
10274 if ! eval $NUMCOND; then :; else
10275 tf="$td/test$N.stdout"
10276 te="$td/test$N.stderr"
10277 tdiff="$td/test$N.diff"
10278 ts1p=$PORT; PORT=$((PORT+1))
10279 ts1a="127.0.0.1"
10280 ts0p=$(printf "%04x" $ts1p);
10281 ts0a="7f000001" # "127.0.0.1"
10282 ts0="x${ts0p}${ts0a}x0000000000000000"
10283 ts1b=$PORT; PORT=$((PORT+1))
10284 ts1="$ts1a:$ts1p"
10285 da="test$N $(date) $RANDOM"
10286 CMD0="$TRACE $SOCAT $opts SOCKET-LISTEN:2:6:$ts0,reuseaddr PIPE"
10287 CMD1="$TRACE $SOCAT $opts - TCP4-CONNECT:$ts1,bind=:$ts1b"
10288 printf "test $F_n $TEST... " $N
10289 $CMD0 2>"${te}0" &
10290 pid0="$!"
10291 #sleep 1
10292 waittcp4port $ts1p 1
10293 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10294 rc1="$?"
10295 kill "$pid0" 2>/dev/null; wait;
10296 if [ "$rc1" -ne 0 ]; then
10297 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10298 echo "$CMD0 &"
10299 cat "${te}0"
10300 echo "$CMD1"
10301 cat "${te}1"
10302 numFAIL=$((numFAIL+1))
10303 listFAIL="$listFAIL $N"
10304 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10305 $PRINTF "$FAILED\n"
10306 cat "$tdiff"
10307 echo "$CMD0 &"
10308 cat "${te}0"
10309 echo "$CMD1"
10310 cat "${te}1"
10311 numFAIL=$((numFAIL+1))
10312 listFAIL="$listFAIL $N"
10313 else
10314 $PRINTF "$OK\n"
10315 if [ -n "$debug" ]; then cat $te; fi
10316 numOK=$((numOK+1))
10318 fi ;; # NUMCOND
10319 esac
10320 PORT=$((PORT+1))
10321 N=$((N+1))
10323 SOCK_DGRAM="$($PROCAN -c |grep "^#define[[:space:]]*SOCK_DGRAM[[:space:]]" |cut -d' ' -f3)"
10325 # test the SOCKET-SENDTO address (against UDP4-RECVFROM)
10326 NAME=SOCKET_SENDTO
10327 case "$TESTS" in
10328 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10329 TEST="$NAME: socket sendto with UDP/IPv4"
10330 # start a UDP4-RECVFROM process that echoes data, and send test data using
10331 # SOCKET-SENDTO, selecting UDP/IPv4. The sent data should be returned.
10332 if ! eval $NUMCOND; then :; else
10333 tf="$td/test$N.stdout"
10334 te="$td/test$N.stderr"
10335 tdiff="$td/test$N.diff"
10336 ts0p=$PORT; PORT=$((PORT+1))
10337 ts0a="127.0.0.1"
10338 ts1p=$(printf "%04x" $ts0p);
10339 ts1a="7f000001" # "127.0.0.1"
10340 ts1="x${ts1p}${ts1a}x0000000000000000"
10341 ts1b=$(printf "%04x" $PORT); PORT=$((PORT+1))
10342 da="test$N $(date) $RANDOM"
10343 CMD0="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts0p,reuseaddr,bind=$ts0a PIPE"
10344 CMD1="$TRACE $SOCAT $opts - SOCKET-SENDTO:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10345 printf "test $F_n $TEST... " $N
10346 $CMD0 2>"${te}0" &
10347 pid0="$!"
10348 waitudp4port $ts0p 1
10349 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10350 rc1="$?"
10351 kill "$pid0" 2>/dev/null; wait;
10352 if [ "$rc1" -ne 0 ]; then
10353 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10354 echo "$CMD0 &"
10355 cat "${te}0"
10356 echo "$CMD1"
10357 cat "${te}1"
10358 numFAIL=$((numFAIL+1))
10359 listFAIL="$listFAIL $N"
10360 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10361 $PRINTF "$FAILED\n"
10362 cat "$tdiff"
10363 echo "$CMD0 &"
10364 cat "${te}0"
10365 echo "$CMD1"
10366 cat "${te}1"
10367 numFAIL=$((numFAIL+1))
10368 listFAIL="$listFAIL $N"
10369 else
10370 $PRINTF "$OK\n"
10371 if [ -n "$debug" ]; then cat $te; fi
10372 numOK=$((numOK+1))
10374 fi ;; # NUMCOND
10375 esac
10376 PORT=$((PORT+1))
10377 N=$((N+1))
10379 # test the SOCKET-RECVFROM address (with UDP4-SENDTO)
10380 NAME=SOCKET_RECVFROM
10381 case "$TESTS" in
10382 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10383 TEST="$NAME: socket recvfrom with UDP/IPv4"
10384 # start a SOCKET-RECVFROM process that uses UDP/IPv4 and echoes data, and
10385 # send test data using UDP4-SENDTO. The sent data should be returned.
10386 if ! eval $NUMCOND; then :; else
10387 tf="$td/test$N.stdout"
10388 te="$td/test$N.stderr"
10389 tdiff="$td/test$N.diff"
10390 ts1p=$PORT; PORT=$((PORT+1))
10391 ts1a="127.0.0.1"
10392 ts0p=$(printf "%04x" $ts1p);
10393 ts0a="7f000001" # "127.0.0.1"
10394 ts0="x${ts0p}${ts0a}x0000000000000000"
10395 ts1b=$PORT; PORT=$((PORT+1))
10396 ts1="$ts1a:$ts1p"
10397 da="test$N $(date) $RANDOM"
10398 CMD0="$TRACE $SOCAT $opts SOCKET-RECVFROM:2:$SOCK_DGRAM:17:$ts0,reuseaddr PIPE"
10399 CMD1="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=:$ts1b"
10400 printf "test $F_n $TEST... " $N
10401 $CMD0 2>"${te}0" &
10402 pid0="$!"
10403 sleep 1 # waitudp4port $ts1p 1
10404 echo "$da" |$CMD1 >>"$tf" 2>>"${te}1"
10405 rc1="$?"
10406 kill "$pid0" 2>/dev/null; wait;
10407 if [ "$rc1" -ne 0 ]; then
10408 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10409 echo "$CMD0 &"
10410 cat "${te}0"
10411 echo "$CMD1"
10412 cat "${te}1"
10413 numFAIL=$((numFAIL+1))
10414 listFAIL="$listFAIL $N"
10415 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10416 $PRINTF "$FAILED\n"
10417 cat "$tdiff"
10418 echo "$CMD0 &"
10419 cat "${te}0"
10420 echo "$CMD1"
10421 cat "${te}1"
10422 numFAIL=$((numFAIL+1))
10423 listFAIL="$listFAIL $N"
10424 else
10425 $PRINTF "$OK\n"
10426 if [ -n "$debug" ]; then cat $te; fi
10427 numOK=$((numOK+1))
10429 fi ;; # NUMCOND
10430 esac
10431 PORT=$((PORT+1))
10432 N=$((N+1))
10435 # test the SOCKET-RECV address (with UDP4-SENDTO)
10436 NAME=SOCKET_RECV
10437 case "$TESTS" in
10438 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10439 TEST="$NAME: socket recv with UDP/IPv4"
10440 # start a SOCKET-RECV process that uses UPD/IPv4 and writes received data to file, and
10441 # send test data using UDP4-SENDTO.
10442 if ! eval $NUMCOND; then :; else
10443 tf="$td/test$N.stdout"
10444 te="$td/test$N.stderr"
10445 tdiff="$td/test$N.diff"
10446 ts1p=$PORT; PORT=$((PORT+1))
10447 ts1a="127.0.0.1"
10448 ts0p=$(printf "%04x" $ts1p);
10449 ts0a="7f000001" # "127.0.0.1"
10450 ts0="x${ts0p}${ts0a}x0000000000000000"
10451 ts1b=$PORT; PORT=$((PORT+1))
10452 ts1="$ts1a:$ts1p"
10453 da="test$N $(date) $RANDOM"
10454 CMD0="$TRACE $SOCAT $opts -u SOCKET-RECV:2:$SOCK_DGRAM:17:$ts0,reuseaddr -"
10455 CMD1="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1,bind=:$ts1b"
10456 printf "test $F_n $TEST... " $N
10457 $CMD0 2>"${te}0" >"$tf" &
10458 pid0="$!"
10459 sleep 1 # waitudp4port $ts1p 1
10460 echo "$da" |$CMD1 2>>"${te}1"
10461 rc1="$?"
10462 sleep 1
10463 kill "$pid0" 2>/dev/null; wait;
10464 if [ "$rc1" -ne 0 ]; then
10465 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10466 echo "$CMD0 &"
10467 cat "${te}0"
10468 echo "$CMD1"
10469 cat "${te}1"
10470 numFAIL=$((numFAIL+1))
10471 listFAIL="$listFAIL $N"
10472 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10473 $PRINTF "$FAILED\n"
10474 cat "$tdiff"
10475 echo "$CMD0 &"
10476 cat "${te}0"
10477 echo "$CMD1"
10478 cat "${te}1"
10479 numFAIL=$((numFAIL+1))
10480 listFAIL="$listFAIL $N"
10481 else
10482 $PRINTF "$OK\n"
10483 if [ -n "$debug" ]; then cat $te; fi
10484 numOK=$((numOK+1))
10486 fi ;; # NUMCOND
10487 esac
10488 PORT=$((PORT+1))
10489 N=$((N+1))
10491 # test SOCKET-DATAGRAM (with UDP4-DATAGRAM)
10492 NAME=SOCKET_DATAGRAM
10493 case "$TESTS" in
10494 *%$N%*|*%functions%*|*%generic%*|*%socket%*|*%ip4%*|*%udp%*|*%dgram%*|*%$NAME%*)
10495 TEST="$NAME: socket datagram via UDP/IPv4"
10496 # start a UDP4-DATAGRAM process that echoes data, and send test data using
10497 # SOCKET-DATAGRAM, selecting UDP/IPv4. The sent data should be returned.
10498 if ! eval $NUMCOND; then :; else
10499 tf="$td/test$N.stdout"
10500 te="$td/test$N.stderr"
10501 tdiff="$td/test$N.diff"
10502 ts0p=$PORT; PORT=$((PORT+1))
10503 ts1p=$PORT; PORT=$((PORT+1))
10504 ts0a="127.0.0.1"
10505 ts1b=$(printf "%04x" $ts0p);
10506 ts1a="7f000001" # "127.0.0.1"
10507 ts0b=$(printf "%04x" $ts0p)
10508 ts1b=$(printf "%04x" $ts1p)
10509 ts1="x${ts0b}${ts1a}x0000000000000000"
10510 da="test$N $(date) $RANDOM"
10511 CMD0="$TRACE $SOCAT $opts UDP4-DATAGRAM:$ts0a:$ts1p,bind=:$ts0p,reuseaddr PIPE"
10512 CMD1="$TRACE $SOCAT $opts - SOCKET-DATAGRAM:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10513 printf "test $F_n $TEST... " $N
10514 $CMD0 2>"${te}0" &
10515 pid0="$!"
10516 waitudp4port $ts0p 1
10517 echo "$da" |$CMD1 2>>"${te}1" >"$tf"
10518 rc1="$?"
10519 kill "$pid0" 2>/dev/null; wait;
10520 if [ "$rc1" -ne 0 ]; then
10521 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10522 echo "$CMD0 &"
10523 cat "${te}0"
10524 echo "$CMD1"
10525 cat "${te}1"
10526 numFAIL=$((numFAIL+1))
10527 listFAIL="$listFAIL $N"
10528 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10529 $PRINTF "$FAILED\n"
10530 cat "$tdiff"
10531 echo "$CMD0 &"
10532 cat "${te}0"
10533 echo "$CMD1"
10534 cat "${te}1"
10535 numFAIL=$((numFAIL+1))
10536 listFAIL="$listFAIL $N"
10537 else
10538 $PRINTF "$OK\n"
10539 if [ -n "$debug" ]; then cat $te; fi
10540 numOK=$((numOK+1))
10542 fi ;; # NUMCOND
10543 esac
10544 PORT=$((PORT+1))
10545 N=$((N+1))
10547 NAME=SOCKETRANGEMASK
10548 case "$TESTS" in
10549 *%$N%*|*%functions%*|*%security%*|*%generic%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%socket%*|*%range%*|*%$NAME%*)
10550 TEST="$NAME: security of generic socket-listen with RANGE option"
10551 if ! eval $NUMCOND; then :;
10552 elif [ -z "$SECONDADDR" ]; then
10553 # we need access to more loopback addresses
10554 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
10555 numCANT=$((numCANT+1))
10556 else
10557 ts1p=$(printf "%04x" $PORT);
10558 testserversec "$N" "$TEST" "$opts -s" "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
10559 fi ;; # NUMCOND, $SECONDADDR
10560 esac
10561 PORT=$((PORT+1))
10562 N=$((N+1))
10565 TIOCEXCL="$($PROCAN -c |grep "^#define[[:space:]]*TIOCEXCL[[:space:]]" |cut -d' ' -f3)"
10567 # test the generic ioctl-void option
10568 NAME=IOCTL_VOID
10569 case "$TESTS" in
10570 *%$N%*|*%functions%*|*%pty%*|*%generic%*|*%$NAME%*)
10571 TEST="$NAME: test the ioctl-void option"
10572 # there are not many ioctls that apply to non global resources and do not
10573 # require root. TIOCEXCL seems to fit:
10574 # process 0 provides a pty;
10575 # process 1 opens it with the TIOCEXCL ioctl;
10576 # process 2 opens it too and fails with "device or resource busy" only when the
10577 # previous ioctl was successful
10578 if ! eval $NUMCOND; then :;
10579 elif [ -z "$TIOCEXCL" ]; then
10580 # we use the numeric value of TIOCEXL which is system dependent
10581 $PRINTF "test $F_n $TEST... ${YELLOW}no value of TIOCEXCL${NORMAL}\n" $N
10582 numCANT=$((numCANT+1))
10583 else
10584 tp="$td/test$N.pty"
10585 tf="$td/test$N.stdout"
10586 te="$td/test$N.stderr"
10587 tdiff="$td/test$N.diff"
10588 da="test$N $(date) $RANDOM"
10589 CMD0="$TRACE $SOCAT $opts PTY,LINK=$tp pipe"
10590 CMD1="$TRACE $SOCAT $opts - file:$tp,ioctl-void=$TIOCEXCL,raw,echo=0"
10591 CMD2="$TRACE $SOCAT $opts - file:$tp,raw,echo=0"
10592 printf "test $F_n $TEST... " $N
10593 $CMD0 >/dev/null 2>"${te}0" &
10594 pid0=$!
10595 waitfile $tp 1
10596 (echo "$da"; sleep 2) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
10597 pid1=$!
10598 usleep 1000000
10599 $CMD2 >/dev/null 2>"${te}2" </dev/null
10600 rc2=$?
10601 kill $pid0 $pid1 2>/dev/null; wait
10602 if ! echo "$da" |diff - "$tf" >/dev/null; then
10603 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
10604 echo "$CMD0 &"
10605 echo "$CMD1"
10606 echo "$da" |diff - "$tf"
10607 numCANT=$((numCANT+1))
10608 elif [ $rc2 -eq 0 ]; then
10609 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10610 echo "$CMD0 &"
10611 echo "$CMD1"
10612 echo "$CMD2"
10613 cat "${te}0" "${te}1" "${te}2"
10614 numFAIL=$((numFAIL+1))
10615 listFAIL="$listFAIL $N"
10616 else
10617 $PRINTF "$OK\n"
10618 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
10619 numOK=$((numOK+1))
10621 fi # NUMCOND, TIOCEXCL
10623 esac
10624 N=$((N+1))
10627 SOL_SOCKET="$($PROCAN -c |grep "^#define[[:space:]]*SOL_SOCKET[[:space:]]" |cut -d' ' -f3)"
10628 SO_REUSEADDR="$($PROCAN -c |grep "^#define[[:space:]]*SO_REUSEADDR[[:space:]]" |cut -d' ' -f3)"
10630 # test the generic setsockopt-int option
10631 if false; then
10632 # this test no longer works due to fix for options on listening sockets
10633 NAME=SETSOCKOPT_INT
10634 case "$TESTS" in
10635 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%generic%*|*%$NAME%*)
10636 TEST="$NAME: test the setsockopt-int option"
10637 # there are not many socket options that apply to non global resources, do not
10638 # require root, do not require a network connection, and can easily be
10639 # tested. SO_REUSEADDR seems to fit:
10640 # process 0 provides a tcp listening socket with reuseaddr;
10641 # process 1 connects to this port; thus the port is connected but no longer
10642 # listening
10643 # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
10644 # (generically specified) SO_REUSEADDR socket options did not work
10645 # process 3 connects to this port; only if it is successful the test is ok
10646 if ! eval $NUMCOND; then :;
10647 elif [ -z "SO_REUSEADDR" ]; then
10648 # we use the numeric value of SO_REUSEADDR which might be system dependent
10649 $PRINTF "test $F_n $TEST... ${YELLOW}value of SO_REUSEADDR not known${NORMAL}\n" $N
10650 numCANT=$((numCANT+1))
10651 else
10652 tp="$PORT"
10653 tf="$td/test$N.stdout"
10654 te="$td/test$N.stderr"
10655 tdiff="$td/test$N.diff"
10656 da="test$N $(date) $RANDOM"
10657 CMD0="$TRACE $SOCAT $opts TCP4-L:$tp,setsockopt-int=$SOL_SOCKET:$SO_REUSEADDR:1 PIPE"
10658 CMD1="$TRACE $SOCAT $opts - TCP:localhost:$tp"
10659 CMD2="$CMD0"
10660 CMD3="$CMD1"
10661 printf "test $F_n $TEST... " $N
10662 $CMD0 >/dev/null 2>"${te}0" &
10663 pid0=$!
10664 waittcp4port $tp 1
10665 (echo "$da"; sleep 3) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
10666 pid1=$!
10667 usleep 1000000
10668 $CMD2 >/dev/null 2>"${te}2" &
10669 pid2=$!
10670 waittcp4port $tp 1
10671 (echo "$da") |$CMD3 >"${tf}3" 2>"${te}3"
10672 rc3=$?
10673 kill $pid0 $pid1 $pid2 2>/dev/null; wait
10674 if ! echo "$da" |diff - "$tf"; then
10675 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
10676 echo "$CMD0 &"
10677 echo "$CMD1"
10678 numCANT=$((numCANT+1))
10679 elif [ $rc3 -ne 0 ]; then
10680 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10681 echo "$CMD2 &"
10682 echo "$CMD3"
10683 cat "${te}2" "${te}3"
10684 numFAIL=$((numFAIL+1))
10685 listFAIL="$listFAIL $N"
10686 elif ! echo "$da" |diff - "${tf}3"; then
10687 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10688 echo "$CMD2 &"
10689 echo "$CMD3"
10690 echo "$da" |diff - "${tf}3"
10691 numCANT=$((numCANT+1))
10692 else
10693 $PRINTF "$OK\n"
10694 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
10695 numOK=$((numOK+1))
10697 fi # NUMCOND, SO_REUSEADDR
10699 esac
10700 PORT=$((PORT+1))
10701 N=$((N+1))
10706 NAME=SCTP4STREAM
10707 case "$TESTS" in
10708 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
10709 TEST="$NAME: echo via connection to SCTP V4 socket"
10710 PORT="$((PORT+1))"
10711 if ! eval $NUMCOND; then :;
10712 elif ! testaddrs sctp ip4 >/dev/null || ! runsip4 >/dev/null || ! runssctp4 "$((PORT-1))" >/dev/null; then
10713 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP4 not available${NORMAL}\n" $N
10714 numCANT=$((numCANT+1))
10715 elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
10716 # RHEL5 based systems became unusable when an sctp socket was created but
10717 # module sctp not loaded
10718 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
10719 numCANT=$((numCANT+1))
10720 else
10721 tf="$td/test$N.stdout"
10722 te="$td/test$N.stderr"
10723 tdiff="$td/test$N.diff"
10724 tsl=$PORT
10725 ts="127.0.0.1:$tsl"
10726 da=$(date)
10727 CMD1="$TRACE $SOCAT $opts SCTP4-LISTEN:$tsl,reuseaddr PIPE"
10728 CMD2="$TRACE $SOCAT $opts stdin!!stdout SCTP4:$ts"
10729 printf "test $F_n $TEST... " $N
10730 $CMD1 >"$tf" 2>"${te}1" &
10731 pid1=$!
10732 waitsctp4port $tsl 1
10733 # SCTP does not seem to support half close, so we give it 1s to finish
10734 (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
10735 if [ $? -ne 0 ]; then
10736 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10737 echo "$CMD1 &"
10738 cat "${te}1"
10739 echo "$CMD2"
10740 cat "${te}2"
10741 numFAIL=$((numFAIL+1))
10742 listFAIL="$listFAIL $N"
10743 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10744 $PRINTF "$FAILED\n"
10745 cat "$tdiff"
10746 numFAIL=$((numFAIL+1))
10747 listFAIL="$listFAIL $N"
10748 else
10749 $PRINTF "$OK\n"
10750 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
10751 numOK=$((numOK+1))
10753 kill $pid1 2>/dev/null
10754 wait
10755 fi # NUMCOND, feats
10757 esac
10758 PORT=$((PORT+1))
10759 N=$((N+1))
10761 NAME=SCTP6STREAM
10762 case "$TESTS" in
10763 *%$N%*|*%functions%*|*%ip6%*|*%ipapp%*|*%sctp%*|*%$NAME%*)
10764 TEST="$NAME: echo via connection to SCTP V6 socket"
10765 PORT="$((PORT+1))"
10766 if ! eval $NUMCOND; then :;
10767 elif ! testaddrs sctp ip6 >/dev/null || ! runsip6 >/dev/null || ! runssctp6 "$((PORT-1))" >/dev/null; then
10768 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP6 not available${NORMAL}\n" $N
10769 numCANT=$((numCANT+1))
10770 elif [ "$UNAME" = Linux ] && ! grep ^sctp /proc/modules >/dev/null; then
10771 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
10772 numCANT=$((numCANT+1))
10773 else
10774 tf="$td/test$N.stdout"
10775 te="$td/test$N.stderr"
10776 tdiff="$td/test$N.diff"
10777 tsl=$PORT
10778 ts="[::1]:$tsl"
10779 da=$(date)
10780 CMD1="$TRACE $SOCAT $opts SCTP6-listen:$tsl,reuseaddr PIPE"
10781 CMD2="$TRACE $SOCAT $opts stdin!!stdout SCTP6:$ts"
10782 printf "test $F_n $TEST... " $N
10783 $CMD1 >"$tf" 2>"${te}1" &
10784 pid=$! # background process id
10785 waitsctp6port $tsl 1
10786 # SCTP does not seem to support half close, so we let it 1s to finish
10787 (echo "$da"; sleep 1) |$CMD2 >>"$tf" 2>>"${te}2"
10788 if [ $? -ne 0 ]; then
10789 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10790 echo "$CMD1 &"
10791 cat "${te}1"
10792 echo "$CMD2"
10793 cat "${te}2"
10794 numFAIL=$((numFAIL+1))
10795 listFAIL="$listFAIL $N"
10796 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
10797 $PRINTF "$FAILED: diff:\n"
10798 cat "$tdiff"
10799 numFAIL=$((numFAIL+1))
10800 listFAIL="$listFAIL $N"
10801 else
10802 $PRINTF "$OK\n"
10803 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
10804 numOK=$((numOK+1))
10806 kill $pid 2>/dev/null
10807 fi # NUMCOND, feats
10809 esac
10810 PORT=$((PORT+1))
10811 N=$((N+1))
10814 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
10815 # performed a renegotiation. Test if this is fixed.
10816 NAME=OPENSSLRENEG1
10817 case "$TESTS" in
10818 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
10819 TEST="$NAME: OpenSSL connections survive renogotiation"
10820 # connect with s_client to socat ssl-l; force a renog, then transfer data. When
10821 # data is passed the test succeeded
10822 if ! eval $NUMCOND; then :;
10823 elif ! testaddrs openssl >/dev/null; then
10824 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
10825 numCANT=$((numCANT+1))
10826 elif ! type openssl >/dev/null 2>&1; then
10827 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
10828 numCANT=$((numCANT+1))
10829 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
10830 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
10831 numCANT=$((numCANT+1))
10832 else
10833 gentestcert testsrv
10834 tf="$td/test$N.stdout"
10835 te="$td/test$N.stderr"
10836 tdiff="$td/test$N.diff"
10837 da="test$N $(date) $RANDOM"
10838 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
10839 CMD1="openssl s_client -port $PORT -verify 0"
10840 printf "test $F_n $TEST... " $N
10841 $CMD0 >/dev/null 2>"${te}0" &
10842 pid0=$!
10843 waittcp4port $PORT 1
10844 (echo "R"; sleep 1; echo "$da"; sleep 1) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
10845 rc1=$?
10846 kill $pid0 2>/dev/null; wait
10847 if echo "$da" |diff - ${tf}1 >"$tdiff"; then
10848 $PRINTF "$OK\n"
10849 numOK=$((numOK+1))
10850 else
10851 $PRINTF "$FAILED\n"
10852 echo "$CMD0 &"
10853 echo "$CMD1"
10854 cat "${te}0"
10855 # cat "${te}1"
10856 cat "$tdiff"
10857 numFAIL=$((numFAIL+1))
10858 listFAIL="$listFAIL $N"
10860 fi # NUMCOND
10862 esac
10863 PORT=$((PORT+1))
10864 N=$((N+1))
10867 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
10868 # performed a renegotiation. The first temporary fix to this problem might
10869 # leave socat in a blocking ssl-read state. Test if this has been fixed.
10870 NAME=OPENSSLRENEG2
10871 case "$TESTS" in
10872 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
10873 TEST="$NAME: OpenSSL connections do not block after renogotiation"
10874 # connect with s_client to socat ssl-l; force a renog, then transfer data from
10875 # socat to the peer. When data is passed this means that the former ssl read no
10876 # longer blocks and the test succeeds
10877 if ! eval $NUMCOND; then :;
10878 elif ! testaddrs openssl >/dev/null; then
10879 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
10880 numCANT=$((numCANT+1))
10881 elif ! type openssl >/dev/null 2>&1; then
10882 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
10883 numCANT=$((numCANT+1))
10884 elif ! testaddrs tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
10885 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
10886 numCANT=$((numCANT+1))
10887 else
10888 gentestcert testsrv
10889 tf="$td/test$N.stdout"
10890 te="$td/test$N.stderr"
10891 tdiff="$td/test$N.diff"
10892 da="test$N $(date) $RANDOM"
10893 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,cert=testsrv.crt,key=testsrv.key,verify=0 SYSTEM:\"sleep 1; echo \\\\\\\"\\\"$da\\\"\\\\\\\"; sleep 1\"!!STDIO"
10894 CMD1="openssl s_client -port $PORT -verify 0"
10895 printf "test $F_n $TEST... " $N
10896 eval "$CMD0 >/dev/null 2>\"${te}0\" &"
10897 pid0=$!
10898 waittcp4port $PORT 1
10899 (echo "R"; sleep 2) |$CMD1 2>"${te}1" |fgrep "$da" >"${tf}1"
10900 rc1=$?
10901 kill $pid0 2>/dev/null; wait
10902 if echo "$da" |diff - ${tf}1 >"$tdiff"; then
10903 $PRINTF "$OK\n"
10904 numOK=$((numOK+1))
10905 else
10906 $PRINTF "$FAILED\n"
10907 echo "$CMD0 &"
10908 echo "$CMD1"
10909 cat "${te}0"
10910 # cat "${te}1"
10911 cat "$tdiff"
10912 numFAIL=$((numFAIL+1))
10913 listFAIL="$listFAIL $N"
10915 fi # NUMCOND
10917 esac
10918 PORT=$((PORT+1))
10919 N=$((N+1))
10922 # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
10923 # command line arguments (whole addresses, host names, file names) were longer
10924 # than 512 bytes.
10925 NAME=HOSTNAMEOVFL
10926 case "$TESTS" in
10927 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
10928 TEST="$NAME: stack overflow on overly long host name"
10929 # provide a long host name to TCP-CONNECT and check socats exit code
10930 if ! eval $NUMCOND; then :; else
10931 tf="$td/test$N.stdout"
10932 te="$td/test$N.stderr"
10933 tdiff="$td/test$N.diff"
10934 da="test$N $(date) $RANDOM"
10935 # prepare long data - perl might not be installed
10936 rm -f "$td/test$N.dat"
10937 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
10938 CMD0="$TRACE $SOCAT $opts TCP-CONNECT:$(cat "$td/test$N.dat"):$PORT STDIO"
10939 printf "test $F_n $TEST... " $N
10940 $CMD0 </dev/null 1>&0 2>"${te}0"
10941 rc0=$?
10942 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
10943 $PRINTF "$OK\n"
10944 numOK=$((numOK+1))
10945 else
10946 $PRINTF "$FAILED\n"
10947 echo "$CMD0"
10948 cat "${te}0"
10949 numFAIL=$((numFAIL+1))
10950 listFAIL="$listFAIL $N"
10952 fi # NUMCOND
10954 esac
10955 PORT=$((PORT+1))
10956 N=$((N+1))
10958 # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
10959 # command line arguments (whole addresses, host names, file names) were longer
10960 # than 512 bytes.
10961 NAME=FILENAMEOVFL
10962 case "$TESTS" in
10963 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%openssl%*|*%$NAME%*)
10964 TEST="$NAME: stack overflow on overly long file name"
10965 # provide a 600 bytes long key file option to SSL-CONNECT and check socats exit code
10966 if ! eval $NUMCOND; then :; else
10967 tf="$td/test$N.stdout"
10968 te="$td/test$N.stderr"
10969 tdiff="$td/test$N.diff"
10970 da="test$N $(date) $RANDOM"
10971 i=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i=$((i+1)); done
10972 CMD0="$TRACE $SOCAT $opts OPENSSL:localhost:$PORT,key=$(cat "$td/test$N.dat") STDIO"
10973 printf "test $F_n $TEST... " $N
10974 $CMD0 </dev/null 1>&0 2>"${te}0"
10975 rc0=$?
10976 if [ $rc0 -lt 128 ] || [ $rc0 -eq 255 ]; then
10977 $PRINTF "$OK\n"
10978 numOK=$((numOK+1))
10979 else
10980 $PRINTF "$FAILED\n"
10981 echo "$CMD0"
10982 cat "${te}0"
10983 numFAIL=$((numFAIL+1))
10984 listFAIL="$listFAIL $N"
10986 fi # NUMCOND
10988 esac
10989 PORT=$((PORT+1))
10990 N=$((N+1))
10993 # test for a bug in gopen that lead to crash or warning when opening a unix
10994 # domain socket with GOPEN
10995 NAME=GOPEN_UNIX_CRASH
10996 case "$TESTS" in
10997 *%$N%*|*%functions%*|*%bugs%*|*%gopen%*|*%unix%*|*%socket%*|*%$NAME%*)
10998 TEST="$NAME: check crash when connecting to a unix domain socket using address GOPEN"
10999 # a unix domain server is started in background. the check process connects to
11000 # its socket. when this process crashes or issues a warning the bug is present.
11001 # please note that a clean behaviour does not proof anything; behaviour of bug
11002 # depends on the value of an uninitialized var
11003 #set -vx
11004 if ! eval $NUMCOND; then :; else
11005 tf="$td/test$N.stdout"
11006 te="$td/test$N.stderr"
11007 ts="$td/test$N.sock"
11008 tdiff="$td/test$N.diff"
11009 da="test$N $(date) $RANDOM"
11010 CMD0="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
11011 CMD1="$TRACE $SOCAT $opts -d - GOPEN:$ts"
11012 printf "test $F_n $TEST... " $N
11013 $CMD0 >/dev/null 2>"${te}0" </dev/null &
11014 pid0=$!
11015 waitunixport "$ts" 1
11016 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
11017 rc1=$?
11018 kill $pid0 2>/dev/null; wait
11019 if [ $rc1 -ne 0 ]; then
11020 $PRINTF "$FAILED\n"
11021 echo "$CMD0 &"
11022 echo "$CMD1"
11023 cat "${te}0"
11024 cat "${te}1"
11025 numFAIL=$((numFAIL+1))
11026 listFAIL="$listFAIL $N"
11027 elif grep -q ' W ' "${te}1"; then
11028 $PRINTF "$FAILED\n"
11029 echo "$CMD0 &"
11030 echo "$CMD1"
11031 cat "${te}0"
11032 cat "${te}1"
11033 numFAIL=$((numFAIL+1))
11034 listFAIL="$listFAIL $N"
11035 elif ! echo "$da" |diff - ${tf}1 >"$tdiff"; then
11036 $PRINTF "$FAILED\n"
11037 echo "$CMD0 &"
11038 echo "$CMD1"
11039 cat "${te}0"
11040 cat "${te}1"
11041 cat "$tdiff"
11042 numFAIL=$((numFAIL+1))
11043 listFAIL="$listFAIL $N"
11044 else
11045 $PRINTF "$OK\n"
11046 numOK=$((numOK+1))
11048 fi # NUMCOND
11050 esac
11051 N=$((N+1))
11054 # test if socat keeps an existing file where it wanted to create a UNIX socket
11055 NAME=UNIXLISTEN_KEEPFILE
11056 case "$TESTS" in
11057 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
11058 TEST="$NAME: socat keeps an existing file where it wanted to create a UNIX socket"
11059 # we create a file and start socat with UNIX-LISTEN on this file. expected
11060 # behaviour: socat exits immediately with error, but keeps the file
11061 # up to 1.7.1.3, it removed the file
11062 if ! eval $NUMCOND; then :; else
11063 tf="$td/test$N.file"
11064 te="$td/test$N.stderr"
11065 CMD0="$TRACE $SOCAT $opts -u UNIX-LISTEN:$tf /dev/null"
11066 printf "test $F_n $TEST... " $N
11067 rm -f "$tf"; touch "$tf"
11068 $CMD0 >/dev/null 2>"${te}0"
11069 rc0=$?
11070 if [ $rc0 -ne 0 -a -f "$tf" ]; then
11071 $PRINTF "$OK\n"
11072 numOK=$((numOK+1))
11073 else
11074 $PRINTF "$FAILED\n"
11075 echo "$CMD0"
11076 cat "${te}0"
11077 numFAIL=$((numFAIL+1))
11078 listFAIL="$listFAIL $N"
11080 fi # NUMCOND
11082 esac
11083 N=$((N+1))
11086 # PTY address allowed to sepcify address parameters but ignored them
11087 NAME=PTY_VOIDARG
11088 case "$TESTS" in
11089 *%$N%*|*%functions%*|*%bugs%*|*%pty%*|*%$NAME%*)
11090 TEST="$NAME: check if address params of PTY produce error"
11091 # invoke socat with address PTY and some param; expect an error
11092 if ! eval $NUMCOND; then :; else
11093 tf="$td/test$N.stdout"
11094 te="$td/test$N.stderr"
11095 tdiff="$td/test$N.diff"
11096 da="test$N $(date) $RANDOM"
11097 CMD0="$TRACE $SOCAT $opts /dev/null PTY:/tmp/xyz"
11098 printf "test $F_n $TEST... " $N
11099 $CMD0 >/dev/null 2>"${te}0"
11100 rc0=$?
11101 if [ $rc0 -ne 0 ]; then
11102 $PRINTF "$OK\n"
11103 numOK=$((numOK+1))
11104 else
11105 $PRINTF "$FAILED\n"
11106 echo "$CMD0"
11107 cat "${te}0"
11108 numFAIL=$((numFAIL+1))
11109 listFAIL="$listFAIL $N"
11111 fi # NUMCOND
11113 esac
11114 N=$((N+1))
11117 # incomplete writes were reported but led to data loss
11118 NAME=INCOMPLETE_WRITE
11119 case "$TESTS" in
11120 *%$N%*|*%functions%*|*%bugs%*|*%$NAME%*)
11121 TEST="$NAME: check if incomplete writes are handled properly"
11122 # write to a nonblocking fd a block that is too large for atomic write
11123 # and check if all data arrives
11124 if ! eval $NUMCOND; then :; else
11125 tf="$td/test$N.stdout"
11126 te="$td/test$N.stderr"
11127 tp="$td/test$N.pipe"
11128 tw="$td/test$N.wc-c"
11129 # this is the size we write() in one call; data is never stored on disk, so
11130 # make it large enough to exceed any atomic write size; but higher number might
11131 # take much time
11132 bytes=100000 # for Linux 2.6.? this must be >65536
11133 CMD0="$TRACE $SOCAT $opts -u PIPE:$tp STDOUT"
11134 CMD1="$TRACE $SOCAT $opts -u -b $bytes OPEN:/dev/zero,readbytes=$bytes FILE:$tp,o-nonblock"
11135 printf "test $F_n $TEST... " $N
11136 $CMD0 2>"${te}0" |wc -c >"$tw" &
11137 pid=$!
11138 waitfile "$tp"
11139 $CMD1 2>"${te}1" >"${tf}1"
11140 rc1=$?
11141 wait
11142 if [ $rc1 -ne 0 ]; then
11143 $PRINTF "$NO_RESULT\n"
11144 numCANT=$((numCANT+1))
11145 elif [ ! -e "$tw" ]; then
11146 $PRINTF "$NO_RESULT\n"
11147 numCANT=$((numCANT+1))
11148 elif [ "$bytes" -eq $(cat "$tw") ]; then
11149 $PRINTF "$OK\n"
11150 numOK=$((numOK+1))
11151 else
11152 $PRINTF "$FAILED\n"
11153 echo "transferred only $(cat $tw) of $bytes bytes" >&2
11154 numFAIL=$((numFAIL+1))
11155 listFAIL="$listFAIL $N"
11157 fi # NUMCOND
11159 esac
11160 N=$((N+1))
11163 NAME=OPENSSL_ANULL
11164 case "$TESTS" in
11165 *%$N%*|*%functions%*|*%openssl%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%$NAME%*)
11166 TEST="$NAME: OpenSSL server with cipher aNULL "
11167 if ! eval $NUMCOND; then :;
11168 elif ! testaddrs openssl >/dev/null; then
11169 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11170 numCANT=$((numCANT+1))
11171 elif ! testaddrs listen tcp ip4 >/dev/null || ! runsip4 >/dev/null; then
11172 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11173 numCANT=$((numCANT+1))
11174 else
11175 tf="$td/test$N.stdout"
11176 te="$td/test$N.stderr"
11177 tdiff="$td/test$N.diff"
11178 da="test$N $(date) $RANDOM"
11179 CMD2="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,$SOCAT_EGD,ciphers=aNULL,verify=0 pipe"
11180 CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,ciphers=aNULL,verify=0,$SOCAT_EGD"
11181 printf "test $F_n $TEST... " $N
11182 eval "$CMD2 2>\"${te}1\" &"
11183 pid=$! # background process id
11184 waittcp4port $PORT
11185 echo "$da" |$CMD >$tf 2>"${te}2"
11186 if ! echo "$da" |diff - "$tf" >"$tdiff"; then
11187 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
11188 echo "$CMD2 &"
11189 echo "$CMD"
11190 cat "${te}1"
11191 cat "${te}2"
11192 cat "$tdiff"
11193 numFAIL=$((numFAIL+1))
11194 listFAIL="$listFAIL $N"
11195 else
11196 $PRINTF "$OK\n"
11197 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
11198 numOK=$((numOK+1))
11200 kill $pid 2>/dev/null
11201 wait
11202 fi ;; # NUMCOND, feats
11203 esac
11204 PORT=$((PORT+1))
11205 N=$((N+1))
11208 # test the max-children option
11209 NAME=MAXCHILDREN
11210 case "$TESTS" in
11211 *%$N%*|*%functions%*|*%socket%*|*%$NAME%*)
11212 TEST="$NAME: max-children option"
11213 # start a listen process with max-children=1; connect with a client, let it
11214 # sleep some time before sending data; connect with second client that sends
11215 # data immediately. If max-children is working correctly the first data should
11216 # arrive first because the second process has to wait.
11217 if ! eval $NUMCOND; then :; else
11218 ts="$td/test$N.sock"
11219 tf="$td/test$N.stdout"
11220 te="$td/test$N.stderr"
11221 tdiff="$td/test$N.diff"
11222 da="test$N $(date) $RANDOM"
11223 CMD0="$TRACE $SOCAT $opts -U FILE:$tf,o-trunc,o-creat,o-append UNIX-L:$ts,fork,max-children=1"
11224 CMD1="$TRACE $SOCAT $opts -u - UNIX-CONNECT:$ts"
11225 printf "test $F_n $TEST... " $N
11226 $CMD0 >/dev/null 2>"${te}0" &
11227 pid0=$!
11228 waitunixport $ts 1
11229 (sleep 2; echo "$da 1") |$CMD1 >"${tf}1" 2>"${te}1" &
11230 pid1=$!
11231 sleep 1
11232 echo "$da 2" |$CMD1 >"${tf}2" 2>"${te}2"
11233 rc2=$?
11234 sleep 2
11235 kill $pid0 $pid1 2>/dev/null; wait
11236 if echo -e "$da 1\n$da 2" |diff $tf - >$tdiff; then
11237 $PRINTF "$OK\n"
11238 numOK=$((numOK+1))
11239 else
11240 $PRINTF "$FAILED\n"
11241 echo "$CMD0 &"
11242 echo "(sleep 2; echo \"$da 1\") |$CMD1"
11243 echo "echo \"$da 2\" |$CMD1"
11244 cat "${te}0"
11245 cat "${te}1"
11246 cat "${te}2"
11247 cat "$tdiff"
11248 numFAIL=$((numFAIL+1))
11249 listFAIL="$listFAIL $N"
11251 fi # NUMCOND
11253 esac
11254 N=$((N+1))
11257 # socat up to 1.7.2.0 had a bug in xioscan_readline() that could be exploited
11258 # to overflow a heap based buffer (socat security advisory 3)
11259 # problem reported by Johan Thillemann
11260 NAME=READLINE_OVFL
11261 case "$TESTS" in
11262 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%$NAME%*)
11263 TEST="$NAME: test for buffer overflow in readline prompt handling"
11264 # address 1 is the readline where write data was handled erroneous
11265 # address 2 provides data to trigger the buffer overflow
11266 # when no SIGSEGV or so occurs the test succeeded (bug fixed)
11267 if ! eval $NUMCOND; then :; else
11268 tf="$td/test$N.stdout"
11269 te="$td/test$N.stderr"
11270 ti="$td/test$N.data"
11271 CMD0="$SOCAT $opts READLINE $ti"
11272 printf "test $F_n $TEST... " $N
11273 # prepare long data - perl might not be installed
11274 #perl -e 'print "\r","Z"x513' >"$ti"
11275 echo $E -n "\rA" >"$ti"
11276 i=0; while [ $i -lt 32 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$ti"; let i=i+1; done
11277 $TRACE $SOCAT - SYSTEM:"$CMD0; echo rc=\$? >&2",pty >/dev/null 2>"${te}0"
11278 rc=$?
11279 rc0="$(grep ^rc= "${te}0" |sed 's/.*=//')"
11280 if [ $rc -ne 0 ]; then
11281 $PRINTF "${YELLOW}framework failed${NORMAL}\n"
11282 elif [ $rc0 -eq 0 ]; then
11283 $PRINTF "$OK\n"
11284 numOK=$((numOK+1))
11285 else
11286 $PRINTF "$FAILED\n"
11287 echo "$CMD0"
11288 grep -v ^rc= "${te}0"
11289 numFAIL=$((numFAIL+1))
11290 listFAIL="$listFAIL $N"
11292 fi # NUMCOND
11294 esac
11295 PORT=$((PORT+1))
11296 N=$((N+1))
11299 # socat up to 1.7.2.1 did only shutdown() but not close() an accept() socket
11300 # that was rejected due to range, tcpwrap, lowport, or sourceport option.
11301 # This file descriptor leak could be used for a denial of service attack.
11302 NAME=FDLEAK
11303 case "$TESTS" in
11304 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11305 TEST="$NAME: file descriptor leak with range option"
11306 # have a TCP-LISTEN with range option; connect with wrong source address until
11307 # "open files" limit would exceed. When server continues operation the bug is
11308 # not present.
11309 if ! eval $NUMCOND; then :; else
11310 tf="$td/test$N.stdout"
11311 te="$td/test$N.stderr"
11312 tdiff="$td/test$N.diff"
11313 da="test$N $(date) $RANDOM"
11314 RLIMIT_NOFILE="$(ulimit -n)"
11315 if ! [[ "$RLIMIT_NOFILE" =~ ^[0-9][0-9]*$ ]]; then
11316 $PRINTF "${YELLOW}cannot determine ulimit -n"
11317 else
11318 CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,reuseaddr,range=$LOCALHOST:255.255.255.255 PIPE"
11319 CMD1="$TRACE $SOCAT $opts -t 0 /dev/null TCP:$SECONDADDR:$PORT,bind=$SECONDADDR"
11320 CMD2="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT,bind=$LOCALHOST"
11321 printf "test $F_n $TEST... " $N
11322 $CMD0 >/dev/null 2>"${te}0" &
11323 pid0=$!
11324 waittcp4port $PORT 1
11325 while [ $RLIMIT_NOFILE -gt 0 ]; do
11326 $CMD1 >/dev/null 2>>"${te}1"
11327 let RLIMIT_NOFILE=RLIMIT_NOFILE-1
11328 done
11329 echo "$da" |$CMD2 >"${tf}2" 2>"${te}2"
11330 rc2=$?
11331 kill $pid0 2>/dev/null; wait
11332 echo -e "$da" |diff "${tf}2" - >$tdiff
11333 if [ $rc2 -ne 0 ]; then
11334 $PRINTF "$FAILED\n"
11335 echo "$CMD2 &"
11336 cat "${te}2"
11337 numFAIL=$((numFAIL+1))
11338 listFAIL="$listFAIL $N"
11339 elif [ -f "$tdiff" -a ! -s "$tdiff" ]; then
11340 $PRINTF "$OK\n"
11341 numOK=$((numOK+1))
11342 else
11343 $PRINTF "$FAILED\n"
11344 echo "$CMD0 &"
11345 echo "$CMD1"
11346 echo "$CMD2"
11347 cat "${te}0"
11348 cat "${te}1"
11349 cat "${te}2"
11350 numFAIL=$((numFAIL+1))
11351 listFAIL="$listFAIL $N"
11353 fi # ulimit -n
11354 fi # NUMCOND
11356 esac
11357 PORT=$((PORT+1))
11358 N=$((N+1))
11361 if false; then # this overflow is not reliably reproducable
11362 # 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.
11363 NAME=PROXY_ADDR_OVFL
11364 case "$TESTS" in
11365 *%$N%*|*%functions%*|*%bugs%*|*%security%*|*%socket%*|*%$NAME%*)
11366 TEST="$NAME: proxy address parameters overflow"
11367 # invoke socat PROXY-CONNECT with long proxy server and target server names. If it terminates with exit code >= 128 it is vulnerable
11368 # 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
11369 if ! eval $NUMCOND; then :; else
11370 tf="$td/test$N.stdout"
11371 te="$td/test$N.stderr"
11372 tdiff="$td/test$N.diff"
11373 da="test$N $(date) $RANDOM"
11374 EF=; for p in ef; do
11375 if type ef >/dev/null 2>&1; then
11376 EF="ef "; break
11378 done
11379 CMD0="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,reuseaddr FILE:/dev/null"
11380 #CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:$(perl -e "print 'A' x 256"):$(perl -e "print 'A' x 256"):80"
11381 CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:localhost:$(perl -e "print 'A' x 384"):80,proxyport=$PORT"
11382 printf "test $F_n $TEST... " $N
11383 $CMD0 >/dev/null 2>"${te}0" &
11384 pid0=$!
11385 waittcp4port $PORT 1
11386 $CMD1 >/dev/null 2>"${te}1"
11387 rc1=$?
11388 if [ $rc1 -lt 128 ]; then
11389 if [ "$EF" ]; then
11390 $PRINTF "$OK\n"
11391 numOK=$((numOK+1))
11392 else
11393 $PRINTF "$UNKNOWN $RED(install ElectricFEnce!)$NORMAL\n"
11394 numCANT=$((num+1))
11396 else
11397 $PRINTF "$FAILED\n"
11398 echo "$CMD1"
11399 cat "${te}"
11400 numFAIL=$((numFAIL+1))
11401 listFAIL="$listFAIL $N"
11403 fi # NUMCOND
11405 esac
11406 PORT=$((PORT+1))
11407 N=$((N+1))
11408 fi # false
11411 # LISTEN addresses in socat up to 1.7.2.1 applied many file descriptor, socket,
11412 # and TCP options only to the listening socket instead of the connection socket.
11413 NAME=LISTEN_KEEPALIVE
11414 case "$TESTS" in
11415 *%$N%*|*%functions%*|*%bugs%*|*%listen%*|*%keepalive%*|*%socket%*|*%$NAME%*)
11416 TEST="$NAME: keepalive option is applied to connection socket"
11417 # instance 0 has TCP-LISTEN with option so-keepalive and invokes filan after
11418 # accept(). filan writes its output to the socket. instance 1 connects to
11419 # instance 0. The value of the sockets so-keepalive option is checked, it must
11420 # be 1
11421 if ! eval $NUMCOND; then :; else
11422 tf="$td/test$N.stdout"
11423 te="$td/test$N.stderr"
11424 #tdiff="$td/test$N.diff"
11425 #da="test$N $(date) $RANDOM"
11426 CMD0="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,reuseaddr,so-keepalive EXEC:\"$FILAN -i 1\",nofork"
11427 CMD1="$TRACE $SOCAT $opts - TCP4:$LOCALHOST:$PORT"
11428 printf "test $F_n $TEST... " $N
11429 eval $CMD0 >/dev/null 2>"${te}0" &
11430 pid0=$!
11431 waittcp4port $PORT 1
11432 $CMD1 >"${tf}1" 2>"${te}1"
11433 KEEPALIVE="$(cat "${tf}1" |tail -n +2 |sed -e "s/.*KEEPALIVE=//" -e "s/[[:space:]].*//")"
11434 rc1=$?
11435 kill $pid0 2>/dev/null; wait
11436 if [ -z "$KEEPALIVE" ]; then
11437 $PRINTF "$NO_RESULT\n"
11438 echo "$CMD0 &"
11439 echo "$CMD1"
11440 cat "${te}0"
11441 cat "${te}1"
11442 numWARN=$((numWARN+1))
11443 elif [ "$KEEPALIVE" = "1" ]; then
11444 $PRINTF "$OK\n";
11445 numOK=$((numOK+1))
11446 else
11447 $PRINTF "$FAILED\n"
11448 echo "$CMD0 &"
11449 echo "$CMD1"
11450 cat "${te}0"
11451 cat "${te}1"
11452 numFAIL=$((numFAIL+1))
11453 listFAIL="$listFAIL $N"
11455 fi # NUMCOND
11457 esac
11458 PORT=$((PORT+1))
11459 N=$((N+1))
11462 # OPENSSL-CONNECT with bind option failed on some systems (eg.FreeBSD, but not
11463 # Linux) with "Invalid argument".
11464 NAME=OPENSSL_CONNECT_BIND
11465 case "$TESTS" in
11466 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
11467 TEST="$NAME: test OPENSSL-CONNECT with bind option"
11468 # have a simple SSL server that just echoes data.
11469 # connect with socat using OPENSSL-CONNECT with bind, send data and check if the
11470 # reply is identical.
11471 if ! eval $NUMCOND; then :; else
11472 tf0="$td/test$N.0.stdout"
11473 te0="$td/test$N.0.stderr"
11474 tf1="$td/test$N.1.stdout"
11475 te1="$td/test$N.1.stderr"
11476 tdiff="$td/test$N.diff"
11477 da="test$N $(date) $RANDOM"
11478 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,ciphers=aNULL,verify=0, PIPE"
11479 CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,bind=$LOCALHOST,ciphers=aNULL,verify=0"
11480 printf "test $F_n $TEST... " $N
11481 $CMD0 >/dev/null 2>"$te0" &
11482 pid0=$!
11483 waittcp4port $PORT 1
11484 echo "$da" |$CMD1 >"$tf1" 2>"$te1"
11485 rc1=$?
11486 kill $pid0 2>/dev/null; wait
11487 if [ "$rc1" -ne 0 ]; then
11488 $PRINTF "$FAILED\n"
11489 echo "$CMD0 &"
11490 echo "$CMD1"
11491 cat "$te0"
11492 cat "$te1"
11493 numFAIL=$((numFAIL+1))
11494 listFAIL="$listFAIL $N"
11495 elif ! echo "$da" |diff - $tf1 >"$tdiff"; then
11496 $PRINTF "$FAILED\n"
11497 echo "$CMD0 &"
11498 echo "$CMD1"
11499 cat "${te}0"
11500 cat "${te}1"
11501 cat "$tdiff"
11502 numFAIL=$((numFAIL+1))
11503 listFAIL="$listFAIL $N"
11504 else
11505 $PRINTF "$OK\n"
11506 numOK=$((numOK+1))
11508 fi # NUMCOND
11510 esac
11511 PORT=$((PORT+1))
11512 N=$((N+1))
11515 # socat up to version 1.7.2.3
11516 # had a bug that converted a bit mask of 0 internally to 0xffffffff
11517 NAME=TCP4RANGE_0BITS
11518 case "$TESTS" in
11519 *%$N%*|*%functions%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*)
11520 TEST="$NAME: correct evaluation of range mask 0"
11521 if ! eval $NUMCOND; then :;
11522 elif [ -z "$SECONDADDR" ]; then
11523 # we need access to a second addresses
11524 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
11525 numCANT=$((numCANT+1))
11526 else
11527 tf="$td/test$N.stdout"
11528 te="$td/test$N.stderr"
11529 tdiff="$td/test$N.diff"
11530 da="test$N $(date) $RANDOM"
11531 #testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
11532 CMD0="$TRACE $SOCAT $opts -u TCP4-LISTEN:$PORT,reuseaddr,range=127.0.0.1/0 CREATE:$tf"
11533 CMD1="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$SECONDADDR:$PORT,bind=$SECONDADDR"
11534 printf "test $F_n $TEST... " $N
11535 $CMD0 2>"${te}0" &
11536 pid0=$!
11537 waittcp4port $PORT 1
11538 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
11539 rc1=$?
11540 kill $pid0 2>/dev/null; wait
11541 if [ $rc1 != 0 ]; then
11542 $PRINTF "${YELLOW}invocation failed${NORMAL}\n"
11543 numCANT=$((numCANT+1))
11544 elif ! [ -f "$tf" ]; then
11545 $PRINTF "$FAILED\n"
11546 echo "$CMD0 &"
11547 echo "$CMD1"
11548 cat "${te}0"
11549 cat "${te}1"
11550 numFAIL=$((numFAIL+1))
11551 listFAIL="$listFAIL $N"
11552 elif ! echo "$da" |diff - "$tf" >"$tdiff"; then
11553 $PRINTF "${YELLOW}diff failed${NORMAL}\n"
11554 numCANT=$((numCANT+1))
11555 else
11556 $PRINTF "$OK\n"
11557 numOK=$((numOK+1))
11560 fi ;; # $SECONDADDR, NUMCOND
11561 esac
11562 PORT=$((PORT+1))
11563 N=$((N+1))
11566 # test: OPENSSL sets of environment variables with important values of peer certificate
11567 while read ssldist MODE MODULE FIELD TESTADDRESS PEERADDRESS VALUE; do
11568 if [ -z "$ssldist" ] || [[ "$ssldist" == \#* ]]; then continue; fi
11570 SSLDIST=${ssldist^^*}
11571 NAME="ENV_${SSLDIST}_${MODE}_${MODULE}_${FIELD}"
11572 case "$TESTS" in
11573 *%$N%*|*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$ssldist%*|*%envvar%*|*%$NAME%*)
11574 TEST="$NAME: $SSLDIST sets env SOCAT_${SSLDIST}_${MODULE}_${FIELD}"
11575 # have a server accepting a connection and invoking some shell code. The shell
11576 # code extracts and prints the SOCAT related environment vars.
11577 # outside code then checks if the environment contains the variables correctly
11578 # describing the desired field.
11579 if ! eval $NUMCOND; then :;
11580 elif ! feat=$(testaddrs $FEAT); then
11581 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
11582 numCANT=$((numCANT+1))
11583 else
11584 tf="$td/test$N.stdout"
11585 te="$td/test$N.stderr"
11586 gentestcert testsrv
11587 gentestcert testcli
11588 test_proto=tcp4
11589 case "$MODE" in
11590 SERVER)
11591 CMD0="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
11592 CMD1="$SOCAT $opts -u /dev/null $PEERADDRESS"
11593 printf "test $F_n $TEST... " $N
11594 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
11595 pid0=$!
11596 wait${test_proto}port $PORT 1
11597 $CMD1 2>"${te}1"
11598 rc1=$?
11599 waitfile "$tf" 2
11600 kill $pid0 2>/dev/null; wait
11602 CLIENT)
11603 CMD0="$SOCAT $opts -u /dev/null $PEERADDRESS"
11604 CMD1="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
11605 printf "test $F_n $TEST... " $N
11606 $CMD0 2>"${te}0" &
11607 pid0=$!
11608 wait${test_proto}port $PORT 1
11609 eval "$CMD1 2>\"${te}1\" >\"$tf\""
11610 rc1=$?
11611 waitfile "$tf" 2
11612 kill $pid0 2>/dev/null; wait
11614 esac
11615 if [ $rc1 != 0 ]; then
11616 $PRINTF "$NO_RESULT (client failed):\n"
11617 echo "$CMD0 &"
11618 cat "${te}0"
11619 echo "$CMD1"
11620 cat "${te}1"
11621 numCANT=$((numCANT+1))
11622 elif effval="$(grep SOCAT_${SSLDIST}_${MODULE}_${FIELD} "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s/[\"']//g")";
11623 [ "$effval" = "$VALUE" ]; then
11624 $PRINTF "$OK\n"
11625 if [ "$debug" ]; then
11626 echo "$CMD0 &"
11627 cat "${te}0"
11628 echo "$CMD1"
11629 cat "${te}1"
11631 numOK=$((numOK+1))
11632 else
11633 $PRINTF "$FAILED\n"
11634 echo "expected \"$VALUE\", got \"$effval\"" >&2
11635 echo "$CMD0 &"
11636 cat "${te}0"
11637 echo "$CMD1"
11638 cat "${te}1"
11639 numFAIL=$((numFAIL+1))
11640 listFAIL="$listFAIL $N"
11642 fi # NUMCOND, feats
11644 esac
11645 N=$((N+1))
11647 done <<<"
11648 openssl SERVER X509 ISSUER OPENSSL-LISTEN:$PORT,so-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
11649 openssl SERVER X509 SUBJECT OPENSSL-LISTEN:$PORT,so-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
11650 openssl SERVER X509 COMMONNAME OPENSSL-LISTEN:$PORT,so-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
11651 openssl SERVER X509 COUNTRYNAME OPENSSL-LISTEN:$PORT,so-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
11652 openssl SERVER X509 LOCALITYNAME OPENSSL-LISTEN:$PORT,so-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
11653 openssl SERVER X509 ORGANIZATIONALUNITNAME OPENSSL-LISTEN:$PORT,so-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
11654 openssl SERVER X509 ORGANIZATIONNAME OPENSSL-LISTEN:$PORT,so-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
11655 openssl CLIENT X509 SUBJECT OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,so-reuseaddr,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_SUBJECT
11656 openssl CLIENT X509 ISSUER OPENSSL-CONNECT:$LOCALHOST:$PORT,cert=testcli.pem,cafile=testsrv.crt,verify=1 OPENSSL-LISTEN:$PORT,so-reuseaddr,bind=$LOCALHOST,cert=testsrv.pem,cafile=testcli.crt,verify=1 $TESTCERT_ISSUER
11660 ###############################################################################
11661 # tests: option umask with "passive" NAMED group addresses
11662 while read addr fileopt addropts proto diropt ADDR2; do
11663 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
11664 # some passive (listening...) filesystem based addresses did not implement the
11665 # umask option
11666 ADDR=${addr^^*}
11667 ADDR_=${ADDR/-/_}
11668 PROTO=${proto^^*}
11669 if [ "$diropt" = "." ]; then diropt=; fi
11670 if [ "$fileopt" = "." ]; then fileopt=; fi
11671 if [ "$addropts" = "." ]; then addropts=; fi
11672 NAME=${ADDR_}_UMASK
11673 case "$TESTS" in
11674 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%$NAME%*)
11675 TEST="$NAME: $ADDR applies option umask"
11676 # start a socat process with passive/listening file system entry. Check the
11677 # permissions of the FS entry, then terminate the process.
11678 # Test succeeds when FS entry exists and has expected permissions.
11679 if ! eval $NUMCOND; then :; else
11680 if [ $ADDR = PTY ]; then set -xv; fi
11681 tlog="$td/test$N.log"
11682 te0="$td/test$N.0.stderr"
11683 tsock="$td/test$N.sock"
11684 if [ -z "$fileopt" ]; then
11685 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
11686 else
11687 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,unlink-close=0,umask=177 $ADDR2"
11689 printf "test $F_n $TEST... " $N
11690 $CMD0 >/dev/null 2>"$te0" &
11691 pid0=$!
11692 wait${proto} $tsock 1 2>"$tlog"
11693 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
11694 perms=$(fileperms "$tsock")
11695 kill $pid0 2>>"$tlog"
11696 wait
11697 if [ "$ERRNOENT" ]; then
11698 $PRINTF "${RED}no entry${NORMAL}\n"
11699 echo "$CMD0 &"
11700 cat "$te0"
11701 cat "$tlog"
11702 let numFAIL=numFAIL+1
11703 listFAIL="$listFAIL $N"
11704 elif [ "$perms" != "600" ]; then
11705 $PRINTF "${RED}perms \"$perms\", expected \"600\" ${NORMAL}\n"
11706 echo "$CMD0 &"
11707 cat "$te0"
11708 let numFAIL=numFAIL+1
11709 listFAIL="$listFAIL $N"
11710 else
11711 $PRINTF "$OK\n"
11712 let numOK=numOK+1
11714 set +xv
11715 fi # NUMCOND
11717 esac
11718 PORT=$((PORT+1))
11719 N=$((N+1))
11721 done <<<"
11722 # address fileopt addropts waitfor direction ADDR2
11723 create . . file -U FILE:/dev/null
11724 open . creat file . FILE:/dev/null
11725 gopen . creat file . FILE:/dev/null
11726 unix-listen . . unixport . FILE:/dev/null
11727 unix-recvfrom . . unixport . FILE:/dev/null
11728 unix-recv . . unixport -u FILE:/dev/null
11729 pipe . . file -u FILE:/dev/null
11730 # pty does not seem to honor umask:
11731 #pty link . file . PIPE
11735 # tests: option perm with "passive" NAMED group addresses
11736 while read addr fileopt addropts proto diropt; do
11737 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
11738 # test if passive (listening...) filesystem based addresses implement option perm
11739 ADDR=${addr^^*}
11740 ADDR_=${ADDR/-/_}
11741 PROTO=${proto^^*}
11742 if [ "$diropt" = "." ]; then diropt=; fi
11743 if [ "$fileopt" = "." ]; then fileopt=; fi
11744 if [ "$addropts" = "." ]; then addropts=; fi
11745 NAME=${ADDR_}_PERM
11746 case "$TESTS" in
11747 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%ignoreeof%*|*%$NAME%*)
11748 TEST="$NAME: $ADDR applies option perm"
11749 # start a socat process with passive/listening file system entry. Check the
11750 # permissions of the FS entry, then terminate the process.
11751 # Test succeeds when FS entry exists and has expected permissions.
11752 if ! eval $NUMCOND; then :; else
11753 tlog="$td/test$N.log"
11754 te0="$td/test$N.0.stderr"
11755 tsock="$td/test$N.sock"
11756 # set -vx
11757 if [ -z "$fileopt" ]; then
11758 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
11759 else
11760 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,perm=511 FILE:/dev/null,ignoreeof"
11762 printf "test $F_n $TEST... " $N
11763 $CMD0 >/dev/null 2>"$te0" &
11764 pid0=$!
11765 wait${proto} $tsock 1 2>"$tlog"
11766 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
11767 perms=$(fileperms "$tsock")
11768 kill $pid0 2>>"$tlog"
11769 wait
11770 if [ "$ERRNOENT" ]; then
11771 $PRINTF "${RED}no entry${NORMAL}\n"
11772 echo "$CMD0 &"
11773 cat "$te0"
11774 cat "$tlog"
11775 let numFAIL=numFAIL+1
11776 listFAIL="$listFAIL $N"
11777 elif [ "$perms" != "511" ]; then
11778 $PRINTF "${RED}perms \"$perms\", expected \"511\" ${NORMAL}\n"
11779 echo "$CMD0 &"
11780 cat "$te0"
11781 let numFAIL=numFAIL+1
11782 listFAIL="$listFAIL $N"
11783 else
11784 $PRINTF "$OK\n"
11785 let numOK=numOK+1
11787 set +vx
11788 fi # NUMCOND
11790 esac
11791 PORT=$((PORT+1))
11792 N=$((N+1))
11794 done <<<"
11795 # address fileopt addropts waitfor direction
11796 create . . file -U
11797 open . creat file .
11798 gopen . creat file .
11799 unix-listen . . unixport .
11800 unix-recvfrom . . unixport .
11801 unix-recv . . unixport -u
11802 pipe . . file -u
11803 pty link . file .
11807 # tests: option user with "passive" NAMED group addresses
11808 while read addr fileopt addropts proto diropt; do
11809 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
11810 # test if passive (listening...) filesystem based addresses implement option user
11811 ADDR=${addr^^*}
11812 ADDR_=${ADDR/-/_}
11813 PROTO=${proto^^*}
11814 if [ "$diropt" = "." ]; then diropt=; fi
11815 if [ "$fileopt" = "." ]; then fileopt=; fi
11816 if [ "$addropts" = "." ]; then addropts=; fi
11817 NAME=${ADDR_}_USER
11818 case "$TESTS" in
11819 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%root%*|*%ignoreeof%*|*%$NAME%*)
11820 TEST="$NAME: $ADDR applies option user"
11821 # start a socat process with passive/listening file system entry with user option.
11822 # Check the owner of the FS entry, then terminate the process.
11823 # Test succeeds when FS entry exists and has expected owner.
11824 if ! eval $NUMCOND; then :;
11825 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
11826 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
11827 numCANT=$((numCANT+1))
11828 else
11829 tlog="$td/test$N.log"
11830 te0="$td/test$N.0.stderr"
11831 tsock="$td/test$N.sock"
11832 # set -vx
11833 if [ -z "$fileopt" ]; then
11834 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
11835 else
11836 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,user=$SUBSTUSER FILE:/dev/null,ignoreeof"
11838 printf "test $F_n $TEST... " $N
11839 $CMD0 >/dev/null 2>"$te0" &
11840 pid0=$!
11841 wait${proto} $tsock 1 2>"$tlog"
11842 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
11843 user=$(fileuser "$tsock")
11844 kill $pid0 2>>"$tlog"
11845 wait
11846 if [ "$ERRNOENT" ]; then
11847 $PRINTF "${RED}no entry${NORMAL}\n"
11848 echo "$CMD0 &"
11849 cat "$te0"
11850 cat "$tlog"
11851 let numFAIL=numFAIL+1
11852 listFAIL="$listFAIL $N"
11853 elif [ "$user" != "$SUBSTUSER" ]; then
11854 $PRINTF "${RED}user \"$user\", expected \"$SUBSTUSER\" ${NORMAL}\n"
11855 echo "$CMD0 &"
11856 cat "$te0"
11857 let numFAIL=numFAIL+1
11858 listFAIL="$listFAIL $N"
11859 else
11860 $PRINTF "$OK\n"
11861 let numOK=numOK+1
11863 set +vx
11864 fi # NUMCOND
11866 esac
11867 PORT=$((PORT+1))
11868 N=$((N+1))
11870 done <<<"
11871 # address fileopt addropts waitfor direction
11872 create . . file -U
11873 open . creat file .
11874 gopen . creat file .
11875 unix-listen . . unixport .
11876 unix-recvfrom . . unixport .
11877 unix-recv . . unixport -u
11878 pipe . . file -u
11879 pty link . file .
11883 # tests: is "passive" filesystem entry removed at the end? (without fork)
11884 while read addr fileopt addropts proto diropt crit ADDR2; do
11885 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
11886 # some passive (listening...) filesystem based addresses did not remove the file
11887 # system entry at the end
11888 ADDR=${addr^^*}
11889 ADDR_=${ADDR/-/_}
11890 PROTO=${proto^^*}
11891 if [ "$diropt" = "." ]; then diropt=; fi
11892 if [ "$fileopt" = "." ]; then fileopt=; fi
11893 if [ "$addropts" = "." ]; then addropts=; fi
11894 # $ADDR removes the file system entry when the process is terminated
11895 NAME=${ADDR_}_REMOVE
11896 case "$TESTS" in
11897 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
11898 TEST="$NAME: $ADDR removes socket entry when terminated during accept"
11899 # start a socat process with listening unix domain socket etc. Terminate the
11900 # process and check if the file system socket entry still exists.
11901 # Test succeeds when entry does not exist.
11902 if ! eval $NUMCOND; then :; else
11903 tlog="$td/test$N.log"
11904 te0="$td/test$N.0.stderr"
11905 tsock="$td/test$N.sock"
11906 if [ -z "$fileopt" ]; then
11907 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts $ADDR2"
11908 else
11909 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts $ADDR2"
11911 printf "test $F_n $TEST... " $N
11912 $CMD0 >/dev/null 2>"$te0" &
11913 pid0=$!
11914 wait${proto} "$crit" $tsock 1 2>"$tlog"
11915 kill $pid0 2>>"$tlog"
11916 rc1=$?
11917 wait >>"$tlog"
11918 if [ $rc1 != 0 ]; then
11919 $PRINTF "${YELLOW}setup failed${NORMAL}\n"
11920 echo "$CMD0 &"
11921 cat "$te0"
11922 cat "$tlog"
11923 let numCANT=numCANT+1
11924 elif ! [ $crit $tsock ]; then
11925 $PRINTF "$OK\n"
11926 let numOK=numOK+1
11927 else
11928 $PRINTF "$FAILED\n"
11929 echo "$CMD0 &"
11930 cat "$te0"
11931 cat "$tlog"
11932 let numFAIL=numFAIL+1
11933 listFAIL="$listFAIL $N"
11935 fi # NUMCOND
11937 esac
11938 PORT=$((PORT+1))
11939 N=$((N+1))
11941 done <<<"
11942 # address fileopt addropts waitfor direction crit ADDR2
11943 unix-listen . . unixport . -e FILE:/dev/null
11944 unix-recvfrom . . unixport . -e FILE:/dev/null
11945 unix-recv . . unixport -u -e FILE:/dev/null
11946 pipe . . file -u -e FILE:/dev/null
11947 pty link . file . -L PIPE
11951 # tests: is "passive" filesystem entry removed at the end? (with fork)
11952 while read addr fileopt addropts proto diropt crit ADDR2; do
11953 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
11954 # some passive (listening...) filesystem based addresses with fork did not remove
11955 # the file system entry at the end
11956 ADDR=${addr^^*}
11957 ADDR_=${ADDR/-/_}
11958 PROTO=${proto^^*}
11959 if [ "$diropt" = "." ]; then diropt=; fi
11960 if [ "$fileopt" = "." ]; then fileopt=; fi
11961 if [ "$addropts" = "." ]; then addropts=; fi
11962 # $ADDR with fork removes the file system entry when the process is terminated
11963 NAME=${ADDR_}_REMOVE_FORK
11964 case "$TESTS" in
11965 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
11966 TEST="$NAME: $ADDR with fork removes socket entry when terminated during accept"
11967 # start a socat process with listening unix domain socket etc and option fork.
11968 # Terminate the process and check if the file system socket entry still exists.
11969 # Test succeeds when entry does not exist.
11970 if ! eval $NUMCOND; then :; else
11971 tlog="$td/test$N.log"
11972 te0="$td/test$N.0.stderr"
11973 tsock="$td/test$N.sock"
11974 if [ -z "$fileopt" ]; then
11975 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,fork,$addropts $ADDR2"
11976 else
11977 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,fork,$fileopt=$tsock,$addropts $ADDR2"
11979 printf "test $F_n $TEST... " $N
11980 $CMD0 >/dev/null 2>"$te0" &
11981 pid0=$!
11982 wait${proto} "$crit" $tsock 1 2>"$tlog"
11983 kill $pid0 2>>"$tlog"
11984 rc1=$?
11985 wait
11986 if [ $rc1 != 0 ]; then
11987 $PRINTF "${YELLOW}setup failed${NORMAL}\n"
11988 echo "$CMD0 &"
11989 cat "$te0"
11990 cat "$tlog"
11991 let numCANT=numCANT+1
11992 elif ! [ $crit $tsock ]; then
11993 $PRINTF "$OK\n"
11994 let numOK=numOK+1
11995 else
11996 $PRINTF "$FAILED\n"
11997 echo "$CMD0 &"
11998 cat "$te0"
11999 cat "$tlog"
12000 let numFAIL=numFAIL+1
12001 listFAIL="$listFAIL $N"
12003 fi # NUMCOND
12005 esac
12006 PORT=$((PORT+1))
12007 N=$((N+1))
12009 done <<<"
12010 # address fileopt addropts waitfor direction crit ADDR2
12011 unix-listen . . unixport . -e FILE:/dev/null
12012 unix-recvfrom . . unixport . -e FILE:/dev/null
12016 # bug fix: SYSTEM address child process shut down parents sockets including
12017 # SSL connection under some circumstances.
12018 NAME=SYSTEM_SHUTDOWN
12019 case "$TESTS" in
12020 *%$N%*|*%functions%*|*%bugs%*|*%system%*|*%openssl%*|*%socket%*|*%$NAME%*)
12021 TEST="$NAME: SYSTEM address does not shutdown its parents addresses"
12022 # start an OpenSSL echo server using SYSTEM:cat
12023 # start an OpenSSL client that sends data
12024 # when the client recieves its data and terminates without error the test succeeded
12025 # in case of the bug the client issues an error like:
12026 # SSL_connect(): error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac
12027 if ! eval $NUMCOND; then :; else
12028 tf="$td/test$N.stdout"
12029 te="$td/test$N.stderr"
12030 tdiff="$td/test$N.diff"
12031 da="test$N $(date) $RANDOM"
12032 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,cipher=aNULL,verify=0 SYSTEM:cat"
12033 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,cipher=aNULL,verify=0"
12034 printf "test $F_n $TEST... " $N
12035 $CMD0 >/dev/null 2>"${te}0" &
12036 pid0=$!
12037 waittcp4port $PORT 1
12038 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12039 rc1=$?
12040 kill $pid0 2>/dev/null; wait
12041 if [ $rc1 -ne 0 ]; then
12042 $PRINTF "$FAILED\n"
12043 echo "rc1=$rc1"
12044 echo "$CMD0 &"
12045 echo "$CMD1"
12046 cat "${te}0"
12047 cat "${te}1"
12048 numFAIL=$((numFAIL+1))
12049 listFAIL="$listFAIL $N"
12050 elif ! echo "$da" |diff - "${tf}1" >"$tdiff" 2>&1; then
12051 $PRINTF "$FAILED\n"
12052 echo "diff:"
12053 cat "$tdiff"
12054 echo "$CMD0 &"
12055 echo "$CMD1"
12056 cat "${te}0"
12057 cat "${te}1"
12058 numFAIL=$((numFAIL+1))
12059 listFAIL="$listFAIL $N"
12060 else
12061 $PRINTF "$OK\n"
12062 numOK=$((numOK+1))
12064 fi # NUMCOND
12066 esac
12067 PORT=$((PORT+1))
12068 N=$((N+1))
12071 # test if TCP4-LISTEN with empty port arg terminates with error
12072 NAME=TCP4_NOPORT
12073 case "$TESTS" in
12074 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%tcp%*|*%tcp4%*|*%$NAME%*)
12075 TEST="$NAME: test if TCP4-LISTEN with empty port arg bails out"
12076 # run socat with TCP4-LISTEN with empty port arg. Check if it terminates
12077 # immediately with return code 1
12078 if ! eval $NUMCOND; then :; else
12079 tf="$td/test$N.stdout"
12080 te="$td/test$N.stderr"
12081 t0rc="$td/test$N.rc"
12082 tdiff="$td/test$N.diff"
12083 da="test$N $(date) $RANDOM"
12084 CMD0="$SOCAT $opts TCP4-LISTEN: /dev/null"
12085 printf "test $F_n $TEST... " $N
12086 { $CMD0 >/dev/null 2>"${te}0"; echo $? >"$t0rc"; } & 2>/dev/null
12087 pid0=$!
12088 sleep 1
12089 kill $pid0 2>/dev/null; wait
12090 if [ ! -f "$t0rc" ]; then
12091 $PRINTF "$FAILED\n"
12092 echo "no return code of CMD0 stored" >&2
12093 echo "$CMD0 &"
12094 cat "${te}0"
12095 numFAIL=$((numFAIL+1))
12096 listFAIL="$listFAIL $N"
12097 elif ! echo 1 |diff - "$t0rc" >"$tdiff"; then
12098 $PRINTF "$FAILED\n"
12099 echo "CMD0 exited with $(cat $t0rc), expected 1"
12100 echo "$CMD0 &"
12101 cat "${te}0"
12102 numFAIL=$((numFAIL+1))
12103 listFAIL="$listFAIL $N"
12104 else
12105 $PRINTF "$OK\n"
12106 numOK=$((numOK+1))
12108 fi # NUMCOND
12110 esac
12111 PORT=$((PORT+1))
12112 N=$((N+1))
12114 # test if the various SSL methods can be used with OpenSSL
12115 for method in SSL3 SSL23 TLS1 TLS1.1 TLS1.2 DTLS1; do
12117 NAME=OPENSSL_METHOD_$method
12118 case "$TESTS" in
12119 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
12120 TEST="$NAME: test OpenSSL method $method"
12121 # Start a socat process listening with OpenSSL and echoing data,
12122 # using the selected method
12123 # Start a second socat process connecting to the listener using
12124 # the same method, send some data and catch the reply.
12125 # If the reply is identical to the sent data the test succeeded.
12126 if ! eval $NUMCOND; then :; else
12127 tf="$td/test$N.stdout"
12128 te="$td/test$N.stderr"
12129 tdiff="$td/test$N.diff"
12130 da="test$N $(date) $RANDOM"
12131 CMD0="$SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,method=$method,cipher=aNULL,verify=0 PIPE"
12132 CMD1="$SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,method=$method,cipher=aNULL,verify=0"
12133 printf "test $F_n $TEST... " $N
12134 $CMD0 >/dev/null 2>"${te}0" &
12135 pid0=$!
12136 waittcp4port $PORT 1
12137 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12138 rc1=$?
12139 kill $pid0 2>/dev/null; wait
12140 if echo "$da" |diff - "${tf}1"; then
12141 $PRINTF "$OK\n"
12142 numOK=$((numOK+1))
12143 else
12144 $PRINTF "$FAILED\n"
12145 echo "$CMD0 &"
12146 echo "$CMD1"
12147 cat "${te}0"
12148 cat "${te}1"
12149 numFAIL=$((numFAIL+1))
12150 listFAIL="$listFAIL $N"
12152 fi # NUMCOND
12154 esac
12155 PORT=$((PORT+1))
12156 N=$((N+1))
12158 done
12161 # give a description of what is tested (a bugfix, a new feature...)
12162 NAME=FDOUT_ERROR
12163 case "$TESTS" in
12164 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
12165 TEST="$NAME: fdout bails out in write-only context"
12166 # use EXEC in write-only context with option fdout. Expected behaviour: error
12167 if ! eval $NUMCOND; then :; else
12168 tf="$td/test$N.stdout"
12169 te="$td/test$N.stderr"
12170 tdiff="$td/test$N.diff"
12171 da="test$N $(date) $RANDOM"
12172 CMD="$SOCAT $opts -u /dev/null EXEC:cat,fdout=1"
12173 printf "test $F_n $TEST... " $N
12174 $CMD >/dev/null 2>"${te}"
12175 rc=$?
12176 if [ $rc -eq 1 ]; then
12177 $PRINTF "$OK\n"
12178 numOK=$((numOK+1))
12179 else
12180 $PRINTF "$FAILED\n"
12181 echo "$CMD"
12182 cat "${te}"
12183 echo "command did not terminate with error!"
12184 numFAIL=$((numFAIL+1))
12185 listFAIL="$listFAIL $N"
12187 fi # NUMCOND
12189 esac
12190 PORT=$((PORT+1))
12191 N=$((N+1))
12194 ##################################################################################
12195 #=================================================================================
12196 # here come tests that might affect your systems integrity. Put normal tests
12197 # before this paragraph.
12198 # tests must be explicitely selected by roottough or name (not number)
12200 NAME=PTYGROUPLATE
12201 case "$TESTS" in
12202 *%roottough%*|*%$NAME%*)
12203 TEST="$NAME: pty with group-late works on pty"
12204 # up to socat 1.7.1.1 address pty changed the ownership of /dev/ptmx instead of
12205 # the pty with options user-late, group-late, or perm-late.
12206 # here we check for correct behaviour.
12207 # ATTENTION: in case of failure of this test the
12208 # group of /dev/ptmx might be changed!
12209 if ! eval $NUMCOND; then :; else
12210 # save current /dev/ptmx properties
12212 for f in /dev/ptmx /dev/ptc; do
12213 if [ -e $f ]; then
12214 F=$(echo "$f" |tr / ..)
12215 ls -l $f >"$td/test$N.$F.ls-l"
12216 break
12218 done
12219 printf "test $F_n $TEST... " $N
12220 if [ -z "$F" ]; then
12221 echo -e "${YELLOW}no /dev/ptmx or /dev/ptc${NORMAL}"
12222 else
12223 GROUP=daemon
12224 tf="$td/test$N.stdout"
12225 te="$td/test$N.stderr"
12226 tl="$td/test$N.pty"
12227 tdiff="$td/test$N.diff"
12228 da="test$N $(date) $RANDOM"
12229 CMD0="$TRACE $SOCAT $opts pty,link=$tl,group-late=$GROUP,escape=0x1a PIPE"
12230 CMD1="$TRACE $SOCAT $opts - $tl,raw,echo=0"
12231 $CMD0 >/dev/null 2>"${te}0" &
12232 pid0=$!
12233 (echo "$da"; usleep $MICROS; echo -e "\x1a") |$CMD1 >"${tf}1" 2>"${te}1" >"$tf"
12234 rc1=$?
12235 kill $pid0 2>/dev/null; wait
12236 if [ $rc1 -ne 0 ]; then
12237 $PRINTF "$FAILED\n"
12238 echo "$CMD0 &"
12239 echo "$CMD1"
12240 cat "${te}0"
12241 cat "${te}1"
12242 numFAIL=$((numFAIL+1))
12243 listFAIL="$listFAIL $N"
12244 elif echo "$da" |diff - "$tf" >$tdiff; then
12245 $PRINTF "$OK\n"
12246 numOK=$((numOK+1))
12247 else
12248 $PRINTF "$FAILED\n"
12249 cat "$tdiff"
12250 numFAIL=$((numFAIL+1))
12251 listFAIL="$listFAIL $N"
12253 if ! ls -l $f |diff "$td/test$N.$F.ls-l" -; then
12254 $PRINTF "${RED}this test changed properties of $f!${NORMAL}\n"
12256 fi # no /dev/ptmx
12257 fi # NUMCOND
12259 esac
12260 N=$((N+1))
12263 echo "summary: $((N-1)) tests, $((numOK+numFAIL+numCANT)) selected; $numOK ok, $numFAIL failed, $numCANT could not be performed"
12265 if [ "$numFAIL" -gt 0 ]; then
12266 echo "FAILED: $listFAIL"
12267 exit 1
12269 exit 0
12271 #==============================================================================
12273 rm -f testsrv.* testcli.* testsrvdsa* testsrvfips* testclifips*
12275 # end
12277 # too dangerous - run as root and having a shell problem, it might purge your
12278 # file systems
12279 #rm -r "$td"
12281 # sometimes subprocesses hang; we want to see this
12282 wait
12284 exit
12286 # test template
12288 # give a description of what is tested (a bugfix, a new feature...)
12289 NAME=SHORT_UNIQUE_TESTNAME
12290 case "$TESTS" in
12291 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
12292 TEST="$NAME: give a one line description of test"
12293 # describe how the test is performed, and what's the success criteria
12294 if ! eval $NUMCOND; then :; else
12295 tf="$td/test$N.stdout"
12296 te="$td/test$N.stderr"
12297 tdiff="$td/test$N.diff"
12298 da="test$N $(date) $RANDOM"
12299 CMD0="$TRACE $SOCAT $opts server-address PIPE"
12300 CMD1="$TRACE $SOCAT $opts - client-address"
12301 printf "test $F_n $TEST... " $N
12302 $CMD0 >/dev/null 2>"${te}0" &
12303 pid0=$!
12304 wait<something>port $PORT 1
12305 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12306 rc1=$?
12307 kill $pid0 2>/dev/null; wait
12308 if [ !!! ]; then
12309 $PRINTF "$OK\n"
12310 numOK=$((numOK+1))
12311 else
12312 $PRINTF "$FAILED\n"
12313 echo "$CMD0 &"
12314 echo "$CMD1"
12315 cat "${te}0"
12316 cat "${te}1"
12317 numFAIL=$((numFAIL+1))
12318 listFAIL="$listFAIL $N"
12320 fi # NUMCOND
12322 esac
12323 PORT=$((PORT+1))
12324 N=$((N+1))