3 # Copyright Gerhard Rieger and contributors (see file CHANGES)
4 # Published under the GNU General Public License V.2, see file COPYING
6 # perform lots of tests on socat
8 # this script uses functions; you need a shell that supports them
10 # you can pass general options to socat: export OPTS="-d -d -d -d -lu"
11 # you can eg strace socat with: export TRACE="strace -v -tt -ff -D -x -s 1024 -o /tmp/$USER/socat.strace"
16 #NUMCOND="test \$N -gt 70"
20 X-t?
*) val_t
="${1#-t}" ;;
21 X-t
) shift; val_t
="$1" ;;
22 X-v
) VERBOSE
=1 ;; # show commands
23 X-n?
*) NUMCOND
="test \$N -eq ${1#-n}" ;;
24 X-n
) shift; NUMCOND
="test \$N -eq $1" ;;
25 X-N?
*) NUMCOND
="test \$N -gt ${1#-N}" ;;
26 X-N
) shift; NUMCOND
="test \$N -ge $1" ;;
27 X-C
) rm -f testcert
*.conf testcert.dh testcli
*.
* testsrv
*.
* ;;
39 X
*.???????
*) S
="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS:0:6}" ;;
40 X
*.
*) S
="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS}000000"; uS="${uS:0:6}" ;;
41 X
*) S
="${val_t}"; uS
="000000" ;;
44 MICROS
=${MICROS##0000}; MICROS=${MICROS##00}; MICROS=${MICROS##0}
46 _MICROS
=$
((MICROS
+999999)); SECONDs
="${_MICROS%??????}"
47 [ -z "$SECONDs" ] && SECONDs
=0
49 withroot
=0 # perform privileged tests even if not run by root
50 #PATH=$PATH:/opt/freeware/bin
51 #PATH=$PATH:/usr/local/ssl/bin
52 PATH
=$PATH:/sbin
# RHEL6:ip
54 */*) PATH
="${0%/*}:$PATH"
56 #OPENSSL_RAND="-rand /dev/egd-pool"
57 #SOCAT_EGD="egd=/dev/egd-pool"
59 [ -z "$SOCAT" ] && SOCAT
="./socat"
60 if ! [ -x "$SOCAT" ] && ! type $SOCAT >/dev
/null
2>&1; then
61 echo "$SOCAT does not exist" >&2; exit 1;
63 [ -z "$PROCAN" ] && PROCAN
="./procan"
64 [ -z "$FILAN" ] && FILAN
="./filan"
66 export SOCAT_OPTS
="$opts"
69 TESTS
="$@"; export TESTS
70 # for some tests we need a network interface
71 if type ip
>/dev
/null
2>&1; then
72 INTERFACE
=$
(ip r get
8.8.8.8 |
grep ' dev ' |
head -n 1 |
sed "s/.*dev[[:space:]][[:space:]]*\([^[:space:]][^[:space:]]*\).*/\1/")
77 INTERFACE
="$($IP route get 8.8.8.8 |grep ' dev ' |sed -e 's/.* dev //' -e 's/ .*//')"
79 INTERFACE
="$(netstat -rn |grep -e "^default
" -e "^
0\
.0\
.0\
.0" |awk '{print($8);}')"
81 FreeBSD
) INTERFACE
="$(netstat -rn |grep -e "^default
" -e "^
0\
.0\
.0\
.0" |awk '{print($4);}')" ;;
82 *) INTERFACE
="$(netstat -rn |grep -e "^default
" -e "^
0\
.0\
.0\
.0" |awk '{print($4);}')" ;;
85 MCINTERFACE
=$INTERFACE
86 [ -z "$MCINTERFACE" ] && MCINTERFACE
=lo
# !!! Linux only - and not always
87 #LOCALHOST=192.168.58.1
91 #PROTO=$(awk '{print($2);}' /etc/protocols |sort -n |tail -n 1)
93 PROTO
=$
((144+RANDOM
/2048))
96 REUSEADDR
=reuseaddr
# use this with LISTEN addresses and bind options
98 # SSL certificate contents
99 TESTCERT_CONF
=testcert.conf
100 TESTCERT6_CONF
=testcert6.conf
102 TESTCERT_COMMONNAME
="$LOCALHOST"
103 TESTCERT_COMMONNAME6
="$LOCALHOST6"
104 TESTCERT_COUNTRYNAME
="XY"
105 TESTCERT_LOCALITYNAME
="Lunar Base"
106 TESTCERT_ORGANIZATIONALUNITNAME
="socat"
107 TESTCERT_ORGANIZATIONNAME
="dest-unreach"
108 TESTCERT_SUBJECT
="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
109 TESTCERT_ISSUER
="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
111 cat >$TESTCERT_CONF <<EOF
115 default_bits = $RSABITS
116 distinguished_name=Test
119 countryName=$TESTCERT_COUNTRYNAME
120 commonName=$TESTCERT_COMMONNAME
121 O=$TESTCERT_ORGANIZATIONNAME
122 OU=$TESTCERT_ORGANIZATIONALUNITNAME
123 L=$TESTCERT_LOCALITYNAME
126 cat >$TESTCERT6_CONF <<EOF
130 default_bits = $RESBITS
131 distinguished_name=Test
134 countryName=$TESTCERT_COUNTRYNAME
135 commonName=$TESTCERT_COMMONNAME6
136 O=$TESTCERT_ORGANIZATIONNAME
137 OU=$TESTCERT_ORGANIZATIONALUNITNAME
138 L=$TESTCERT_LOCALITYNAME
141 # clean up from previous runs
142 rm -f testcli.
{crt
,key
,pem
}
143 rm -f testsrv.
{crt
,key
,pem
}
144 rm -f testcli6.
{crt
,key
,pem
}
145 rm -f testsrv6.
{crt
,key
,pem
}
151 # precision sleep; takes seconds with fractional part
154 [ "$T" = 0 ] && T
=0.000002
155 $SOCAT -T "$T" pipe pipe
157 # time in microseconds to wait in some situations
158 if ! type usleep >/dev
/null
2>&1 ||
159 usleep 0 2>&1 |
grep -q deprecated
; then
163 *???????
) S
="${n%??????}"; uS="${n:${#n}-6}" ;;
164 *) S
=0; uS
="00000$n"; uS
="${uS:${#uS}-6}" ;;
166 $SOCAT -T $S.
$uS pipe pipe
177 F_n
="%3d" # format string for test numbers
178 export LC_ALL
=C
# for timestamps format...
180 export LANGUAGE
=C
# knoppix
183 echo "$SOCAT -u stdin stdout" >cat.sh
188 # /usr/bin/tr doesn't handle the a-z range syntax (needs [a-z]), use
189 # /usr/xpg4/bin/tr instead
190 alias tr=/usr
/xpg
4/bin
/tr
199 # # on HP-UX, the default options (below) hang some tests (former 14, 15)
204 PTYOPTS
="echo=0,opost=0"
205 #PTYOPTS2="raw,echo=0"
211 # for some tests we need an unprivileged user id to su to
212 if [ "$SUDO_USER" ]; then
213 SUBSTUSER
="$SUDO_USER"
215 SUBSTUSER
="$(grep -v '^[^:]*:^[^:]*:0:' /etc/passwd |tail -n 1 |cut -d: -f1)"
219 if ip
-V |
grep -q "^ip utility, iproute2-ss"; then
227 if ss
-V |
grep -q "^ss utility, iproute2-ss"; then
234 if [ -z "$SS" ]; then
235 # non-root users might miss ifconfig in their path
237 AIX
) IFCONFIG
=/usr
/sbin
/ifconfig
;;
238 FreeBSD
) IFCONFIG
=/sbin
/ifconfig
;;
239 HP-UX
) IFCONFIG
=/usr
/sbin
/ifconfig
;;
240 Linux
) IFCONFIG
=/sbin
/ifconfig
;;
241 NetBSD
)IFCONFIG
=/sbin
/ifconfig
;;
242 OpenBSD
)IFCONFIG
=/sbin
/ifconfig
;;
243 OSF1
) IFCONFIG
=/sbin
/ifconfig
;;
244 SunOS
) IFCONFIG
=/sbin
/ifconfig
;;
245 Darwin
)IFCONFIG
=/sbin
/ifconfig
;;
246 DragonFly
) IFCONFIG
=/sbin
/ifconfig
;;
247 *) IFCONFIG
=/sbin
/ifconfig
;;
251 # need output like "644"
253 Linux
) fileperms
() { stat
-L --print "%a\n" "$1" 2>/dev
/null
; } ;;
254 FreeBSD
) fileperms
() { stat
-L -x "$1" |
grep ' Mode:' |
sed 's/.* Mode:[[:space:]]*([0-9]\([0-7][0-7][0-7]\).*/\1/'; } ;;
257 p
="$(ls -l -L "$1" |awk '{print($1);}')"
259 while [ "$p" ]; do c
=${p:0:1}; p
=${p:1}; [ "x$c" == x-
]; let "s=2*s+$?"; done
264 # need user (owner) of filesystem entry
266 Linux
) fileuser
() { stat
-L --print "%U\n" "$tsock" 2>/dev
/null
; } ;;
267 FreeBSD
) fileuser
() { ls -l test.sh |
awk '{print($3);}'; } ;;
268 *) fileuser
() { ls -l test.sh |
awk '{print($3);}'; } ;;
274 $IP address show dev
$IF |
grep "inet " |
sed -e "s/.*inet //" -e "s/ .*//"
276 $IFCONFIG $BROADCASTIF |
grep 'inet ' |
awk '{print($2);}' |cut
-d: -f2
283 $IP address show dev
$IF |
grep ' inet .* brd ' |
awk '{print($4);}'
285 $IFCONFIG $IF |
grep 'broadcast ' |
sed 's/.*broadcast/broadcast/' |
awk '{print($2);}'
289 # for some tests we need a second local IPv4 address
293 BROADCASTIF
=$
($IP r get
8.8.8.8 |
grep ' dev ' |
sed 's/.*\<dev[[:space:]][[:space:]]*\([a-z0-9][a-z0-9]*\).*/\1/')
295 BROADCASTIF
=$
(route
-n |
grep '^0.0.0.0 ' |
awk '{print($8);}')
297 [ -z "$BROADCASTIF" ] && BROADCASTIF
=eth0
299 SECONDMASK
=255.255.0.0
300 BCADDR
=127.255.255.255
301 BCIFADDR
=$
(if2addr4
$BROADCASTIF) ;;
302 FreeBSD|NetBSD|OpenBSD
)
303 MAINIF
=$
($IFCONFIG -a |
grep '^[a-z]' |
grep -v '^lo0: ' |
head -1 |cut
-d: -f1)
304 BROADCASTIF
="$MAINIF"
305 SECONDADDR
=$
($IFCONFIG $BROADCASTIF |
grep 'inet ' |
awk '{print($2);}')
306 BCIFADDR
="$SECONDADDR"
307 BCADDR
=$
($IFCONFIG $BROADCASTIF |
grep 'broadcast ' |
sed 's/.*broadcast/broadcast/' |
awk '{print($2);}') ;;
309 MAINIF
=lan0
# might use "netstat -ni" for this
310 BROADCASTIF
="$MAINIF"
311 SECONDADDR
=$
($IFCONFIG $MAINIF |
tail -n 1 |
awk '{print($2);}')
312 BCADDR
=$
($IFCONFIG $BROADCASTIF |
grep 'broadcast ' |
sed 's/.*broadcast/broadcast/' |
awk '{print($2);}') ;;
314 MAINIF
=$
($IFCONFIG -a |
grep '^[a-z]' |
grep -v '^lo0: ' |
head -1 |cut
-d: -f1)
315 BROADCASTIF
="$MAINIF"
318 #SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
319 SECONDADDR
=$
(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
320 #BCIFADDR="$SECONDADDR"
321 #BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}')
324 MAINIF
=$
($IFCONFIG -a |
grep -v ^
lp |
grep '^[a-z]' |
grep -v '^lo0: ' |
head -1 |cut
-d: -f1)
325 BROADCASTIF
="$MAINIF"
326 SECONDADDR
=$
($IFCONFIG $BROADCASTIF |
grep 'inet ' |
awk '{print($2);}')
327 BCIFADDR
="$SECONDADDR"
328 BCADDR
=$
($IFCONFIG $BROADCASTIF |
grep 'broadcast ' |
sed 's/.*broadcast/broadcast/' |
awk '{print($2);}') ;;
329 #AIX|FreeBSD|Solaris)
331 SECONDADDR
=$
(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 ' |head -n 1)" : '.*inet \([0-9.]*\) .*')
334 # for generic sockets we need this address in hex form
335 if [ "$SECONDADDR" ]; then
336 SECONDADDRHEX
="$(printf "%02x
%02x
%02x
%02x
\n" $(echo "$SECONDADDR" |tr '.' '
340 # for some tests we need a second local IPv6 address
342 Linux
) if [ "$IP" ]; then
343 SECONDIP6ADDR
=$
(expr "$($IP address |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet6 \([0-9a-f:][0-9a-f:]*\)/.*')
345 SECONDIP6ADDR
=$
(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
348 SECONDIP6ADDR
=$
(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
351 if [ -z "$SECONDIP6ADDR" ]; then
353 # *%root2%*) $IFCONFIG eth0 ::2/128
355 SECONDIP6ADDR
="$LOCALHOST6"
357 SECONDIP6ADDR
="[$SECONDIP6ADDR]"
362 if [ $
(echo "x\c") = "x" ]; then E
=""
363 elif [ $
(echo -e "x\c") = "x" ]; then E
="-e"
365 echo "cannot suppress trailing newline on echo" >&2
372 vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color
)
373 # there are different behaviours of printf (and echo)
374 # on some systems, echo behaves different than printf...
375 if [ $
($PRINTF "\0101") = "A" ]; then
379 # if [ "$UNAME" = SunOS ]; then
388 # if [ "$UNAME" = SunOS ]; then
394 OK
="${GREEN}OK${NORMAL}"
395 FAILED
="${RED}FAILED${NORMAL}"
396 NO_RESULT
="${YELLOW}NO RESULT${NORMAL}"
400 NO_RESULT
="NO RESULT"
405 if [ -x /usr
/xpg
4/bin
/id
]; then
406 # SunOS has rather useless tools in its default path
407 PATH
="/usr/xpg4/bin:$PATH"
410 [ -z "$TESTS" ] && TESTS
="consistency functions filan"
411 # use '%' as separation char
412 TESTS
="%$(echo "$TESTS" |tr ' ' '%')%"
414 [ -z "$USER" ] && USER
="$LOGNAME" # HP-UX
415 if [ -z "$TMPDIR" ]; then
416 if [ -z "$TMP" ]; then
421 TD
="$TMPDIR/$USER/$$"; td
="$TD"
422 rm -rf "$TD" ||
(echo "cannot rm $TD" >&2; exit 1)
424 #trap "rm -r $TD" 0 3
426 echo "using temp directory $TD"
430 # test if addresses are sorted alphabetically:
431 $ECHO "testing if address array is sorted...\c"
433 IFS
="$($ECHO ' \n\t')"
434 $SOCAT -? |
sed '1,/address-head:/ d' |
egrep 'groups=' |
while IFS
="$IFS:" read x y
; do echo "$x"; done >"$TF"
435 $SOCAT -? |
sed '1,/address-head:/ d' |
egrep 'groups=' |
while IFS
="$IFS:" read x y
; do echo "$x"; done |LC_ALL
=C
sort |
diff "$TF" - >"$TF-diff"
436 if [ -s "$TF-diff" ]; then
437 $ECHO "\n*** address array is not sorted. Wrong entries:" >&2
438 cat "$TD/socat-q-diff" >&2
449 # test if address options array ("optionnames") is sorted alphabetically:
450 $ECHO "testing if address options are sorted...\c"
452 $SOCAT -??? |
sed '1,/opt:/ d' |
awk '{print($1);}' >"$TF"
453 LC_ALL
=C
sort "$TF" |
diff "$TF" - >"$TF-diff"
454 if [ -s "$TF-diff" ]; then
455 $ECHO "\n*** option array is not sorted. Wrong entries:" >&2
456 cat "$TD/socat-qq-diff" >&2
465 #==============================================================================
469 # inquire which options are available
470 OPTS_ANY
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*ANY' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
471 OPTS_BLK
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*BLK' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
472 OPTS_CHILD
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*CHILD' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
473 OPTS_CHR
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*CHR' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
474 OPTS_DEVICE
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*DEVICE' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
475 OPTS_EXEC
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*EXEC' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
476 OPTS_FD
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*FD' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
477 OPTS_FIFO
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*FIFO' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
478 OPTS_FORK
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*FORK' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
479 OPTS_LISTEN
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*LISTEN' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
480 OPTS_NAMED
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*NAMED' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
481 OPTS_OPEN
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*OPEN[^S]' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
482 OPTS_PARENT
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*PARENT' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
483 OPTS_READLINE
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*READLINE' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
484 OPTS_RETRY
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*RETRY' |
awk '{print($1);}' |
grep -v forever|
xargs echo |
tr ' ' ',')
485 OPTS_RANGE
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*RANGE' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
486 OPTS_FILE
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*REG' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
487 OPTS_UNIX
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*UNIX' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
488 OPTS_SOCKET
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*SOCKET' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
489 OPTS_TERMIOS
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*TERMIOS' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
490 OPTS_IP4
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*IP4' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
491 OPTS_IP6
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*IP6' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
492 OPTS_TCP
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*TCP' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
493 OPTS_UDP
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*UDP' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
494 OPTS_SOCKS4
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*SOCKS4' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
495 OPTS_PROCESS
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*PROCESS' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
496 OPTS_OPENSSL
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*OPENSSL' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
497 OPTS_PTY
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*PTY' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
498 OPTS_HTTP
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*HTTP' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
499 OPTS_APPL
=$
($SOCAT -?? |
sed '1,/opt:/ d' |
egrep 'groups=([A-Z]+,)*APPL' |
awk '{print($1);}' |
xargs echo |
tr ' ' ',')
501 # find user ids to setown to; non-root only can setown to itself
502 if [ $
(id
-u) = 0 ]; then
503 # up to now, it is not a big problem when these do not exist
511 # some options require values; here we try to replace these bare options with
517 *,umask,*) OPTS
=$
(echo "$OPTS" |
sed "s/,umask,/,umask=0026,/g");;
520 *,user
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,user,/,user=$_UID,/g");;
523 *,user-early
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,user-early,/,user-early=$_UID,/g");;
526 *,user-late
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,user-late,/,user-late=$_UID,/g");;
529 *,owner
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,owner,/,owner=$_UID,/g");;
532 *,uid
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,uid,/,uid=$_UID,/g");;
535 *,uid-l
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,uid-l,/,uid-l=$_UID,/g");;
538 *,setuid
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,setuid,/,setuid=$_UID,/g");;
541 *,group
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,group,/,group=$_GID,/g");;
544 *,group-early
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,group-early,/,group-early=$_GID,/g");;
547 *,group-late
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,group-late,/,group-late=$_GID,/g");;
550 *,gid
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,gid,/,gid=$_GID,/g");;
553 *,gid-l
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,gid-l,/,gid-l=$_GID,/g");;
556 *,setgid
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,setgid,/,setgid=$_GID,/g");;
559 *,mode
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,mode,/,mode=0700,/g");;
562 *,perm
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,perm,/,perm=0700,/g");;
565 *,perm-early
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,perm-early,/,perm-early=0700,/g");;
568 *,perm-late
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,perm-late,/,perm-late=0700,/g");;
571 *,path
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,path,/,path=.,/g");;
575 *,bind,*) OPTS
=$
(echo "$OPTS" |
sed "s/,bind,/,bind=:,/g");;
578 *,linger
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,linger,/,linger=2,/g");;
581 *,connect-timeout
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,connect-timeout,/,connect-timeout=1,/g");;
585 *,ipoptions
,*) OPTS
=$
(echo "$OPTS" |
sed "s|,ipoptions,|,ipoptions=x01,|g");;
588 *,pf
,*) OPTS
=$
(echo "$OPTS" |
sed "s|,pf,|,pf=ip4,|g");;
591 *,range
,*) OPTS
=$
(echo "$OPTS" |
sed "s|,range,|,range=127.0.0.1/32,|g");;
594 *,if,*) OPTS
=$
(echo "$OPTS" |
sed "s/,if,/,if=$INTERFACE,/g");;
598 *,pty-interval
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,pty-interval,/,pty-interval=$INTERFACE,/g");;
602 *,interval
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,interval,/,interval=1,/g");;
606 *,history,*) OPTS
=$
(echo "$OPTS" |
sed "s/,history,/,history=.history,/g");;
609 *,noecho
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,noecho,/,noecho=password,/g");;
612 *,prompt
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,prompt,/,prompt=CMD,/g");;
616 *,sp
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,sp,/,sp=$SOURCEPORT,/g");;
620 *,ciphers
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,ciphers,/,ciphers=NULL,/g");;
623 *,method
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,method,/,method=SSLv3,/g");;
626 *,cafile
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,cafile,/,cafile=/tmp/hugo,/g");;
629 *,capath
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,capath,/,capath=/tmp/hugo,/g");;
632 *,cert
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,cert,/,cert=/tmp/hugo,/g");;
635 *,key
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,key,/,key=/tmp/hugo,/g");;
638 *,dh
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,dh,/,dh=/tmp/hugo,/g");;
641 *,egd
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,egd,/,egd=/tmp/hugo,/g");;
644 *,compress,*) OPTS
=$
(echo "$OPTS" |
sed "s/,compress,/,compress=none,/g");;
648 *,proxyauth
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,proxyauth,/,proxyauth=user:pass,/g");;
651 *,proxyport
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,proxyport,/,proxyport=3128,/g");;
654 *,link
,*) OPTS
=$
(echo "$OPTS" |
sed "s/,link,/,link=testlink,/g");;
658 *,allow-table
,*) OPTS
=$
(echo "$OPTS" |
sed "s|,allow-table,|,allow-table=/tmp/hugo,|g");;
661 *,deny-table
,*) OPTS
=$
(echo "$OPTS" |
sed "s|,deny-table,|,deny-table=/tmp/hugo,|g");;
664 *,tcpwrap-dir
,*) OPTS
=$
(echo "$OPTS" |
sed "s|,tcpwrap-dir,|,tcpwrap-dir=/tmp,|g");;
667 expr "$OPTS" : ',\(.*\),'
669 # OPTS_FIFO: nothing yet
671 # OPTS_CHR: nothing yet
673 # OPTS_BLK: nothing yet
675 # OPTS_REG: nothing yet
677 OPTS_SOCKET
=",$OPTS_SOCKET,"
678 OPTS_SOCKET
=$
(expr "$OPTS_SOCKET" : ',\(.*\),')
681 #------------------------------------------------------------------------------
684 #METHOD=$(echo "$method" |tr a-z A-Z)
685 #TEST="$METHOD on file accepts all its options"
688 #DA="test$N $(date) $RANDOM"
689 #OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//')
690 #for g in $(echo $OPTGROUPS |tr ',' ' '); do
691 # eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)";
692 # OPTS="$OPTS,$OPTG";
696 #for o in $(filloptionvalues $OPTS|tr ',' ' '); do
697 # echo testing if $METHOD accepts option $o
699 # $SOCAT $opts -!!$method:$TF,$o /dev/null,ignoreof </dev/null
703 #------------------------------------------------------------------------------
705 # test openssl connect
710 #opts="-s -d -d -d -d"
712 for addr
in openssl
; do
713 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
714 TEST
="$ADDR accepts all its options"
716 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
717 # echo OPTGROUPS=$OPTGROUPS
719 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
720 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
724 openssl s_server
-www -accept $PORT ||
echo "cannot start s_server" >&2 &
728 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
729 echo "testing if $ADDR accepts option $o"
730 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
731 $SOCAT $opts /dev
/null
$addr:$LOCALHOST:$PORT,$o
735 kill $pid 2>/dev
/null
740 #------------------------------------------------------------------------------
747 #opts="-s -d -d -d -d"
749 for addr
in proxy
; do
750 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
751 TEST
="$ADDR accepts all its options"
753 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
754 # echo OPTGROUPS=$OPTGROUPS
756 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
757 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
761 # prepare dummy server
762 $SOCAT tcp-l
:$PORT,reuseaddr
,crlf
exec:"/usr/bin/env bash proxyecho.sh" ||
echo "cannot start proxyecho.sh" >&2 &
765 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
766 echo "testing if $ADDR accepts option $o"
767 # echo $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$PORT,$o
768 $SOCAT $opts /dev
/null
$addr:$LOCALHOST:127.0.0.1:$
((PORT
+1)),proxyport
=$PORT,$o
770 kill $pid 2>/dev
/null
772 kill $pid 2>/dev
/null
777 #------------------------------------------------------------------------------
784 #opts="-s -d -d -d -d"
785 $SOCAT $opts tcp4-listen
:$PORT,reuseaddr
,fork
,$o echo </dev
/null
&
788 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
789 TEST
="$ADDR accepts all its options"
791 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
792 # echo OPTGROUPS=$OPTGROUPS
794 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
795 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
799 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
800 echo "testing if $ADDR accepts option $o"
801 $SOCAT $opts /dev
/null
$addr:$LOCALHOST:$PORT,$o
804 kill $pid 2>/dev
/null
809 #------------------------------------------------------------------------------
816 #opts="-s -d -d -d -d"
817 $SOCAT $opts udp4-listen
:$PORT,fork
,$o echo </dev
/null
&
819 for addr
in udp4-connect
; do
820 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
821 TEST
="$ADDR accepts all its options"
823 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
824 # echo OPTGROUPS=$OPTGROUPS
826 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
827 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
831 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
832 echo "testing if $ADDR accepts option $o"
833 $SOCAT $opts /dev
/null
$addr:$LOCALHOST:$PORT,$o
836 kill $pid 2>/dev
/null
841 #------------------------------------------------------------------------------
848 #opts="-s -d -d -d -d"
849 for addr
in tcp4-listen
; do
850 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
851 TEST
="$ADDR accepts all its options"
853 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
855 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
856 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
860 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
861 echo "testing if $ADDR accepts option $o"
862 $SOCAT $opts $ADDR:$PORT,reuseaddr
,$o echo </dev
/null
&
864 $SOCAT /dev
/null tcp4
:$LOCALHOST:$PORT 2>/dev
/null
865 kill $pid 2>/dev
/null
872 #------------------------------------------------------------------------------
879 #opts="-s -d -d -d -d"
880 for addr
in udp4-listen
; do
881 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
882 TEST
="$ADDR accepts all its options"
884 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
886 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
887 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
891 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
892 echo "testing if $ADDR accepts option $o"
893 $SOCAT $opts $ADDR:$PORT,reuseaddr
,$o echo </dev
/null
&
895 $SOCAT /dev
/null udp4
:$LOCALHOST:$PORT 2>/dev
/null
896 kill $pid 2>/dev
/null
903 #------------------------------------------------------------------------------
910 #opts="-s -d -d -d -d"
911 $SOCAT $opts udp4-recv
:$PORT,fork
,$o echo </dev
/null
&
913 for addr
in udp4-sendto
; do
914 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
915 TEST
="$ADDR accepts all its options"
917 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
918 # echo OPTGROUPS=$OPTGROUPS
920 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
921 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
925 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
926 echo "testing if $ADDR accepts option $o"
927 $SOCAT $opts /dev
/null
$addr:$LOCALHOST:$PORT,$o
930 kill $pid 2>/dev
/null
935 #------------------------------------------------------------------------------
942 #opts="-s -d -d -d -d"
943 #$SOCAT $opts udp4-recvfrom:$PORT,fork,$o echo </dev/null &
945 for addr
in udp4-datagram
; do
946 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
947 TEST
="$ADDR accepts all its options"
949 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
950 # echo OPTGROUPS=$OPTGROUPS
952 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
953 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
957 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
958 echo "testing if $ADDR accepts option $o"
959 $SOCAT $opts /dev
/null
$addr:$LOCALHOST:$PORT,$o
962 #kill $pid 2>/dev/null
967 #------------------------------------------------------------------------------
974 #opts="-s -d -d -d -d"
975 for addr
in udp4-recv
; do
976 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
977 TEST
="$ADDR accepts all its options"
979 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
981 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
982 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
986 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
987 echo "testing if $ADDR accepts option $o"
988 $SOCAT $opts $ADDR:$PORT,reuseaddr
,$o echo </dev
/null
&
990 $SOCAT /dev
/null udp4
:$LOCALHOST:$PORT 2>/dev
/null
991 kill $pid 2>/dev
/null
998 #------------------------------------------------------------------------------
1000 # test udp4-recvfrom
1005 #opts="-s -d -d -d -d"
1006 for addr
in udp4-recvfrom
; do
1007 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1008 TEST
="$ADDR accepts all its options"
1010 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1012 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1013 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1017 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1018 echo "testing if $ADDR accepts option $o"
1019 $SOCAT $opts $ADDR:$PORT,reuseaddr
,$o echo </dev
/null
&
1021 $SOCAT /dev
/null udp4
:$LOCALHOST:$PORT 2>/dev
/null
1022 kill $pid 2>/dev
/null
1029 #------------------------------------------------------------------------------
1036 #opts="-s -d -d -d -d"
1037 $SOCAT $opts ip4-recv
:$PORT,fork
,$o echo </dev
/null
&
1039 for addr
in ip4-sendto
; do
1040 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1041 TEST
="$ADDR accepts all its options"
1043 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1044 # echo OPTGROUPS=$OPTGROUPS
1046 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1047 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1051 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1052 echo "testing if $ADDR accepts option $o"
1053 $SOCAT $opts /dev
/null
$addr:$LOCALHOST:$PORT,$o
1056 kill $pid 2>/dev
/null
1061 #------------------------------------------------------------------------------
1068 #opts="-s -d -d -d -d"
1069 for addr
in ip4-recv
; do
1070 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1071 TEST
="$ADDR accepts all its options"
1073 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1075 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1076 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1080 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1081 echo "testing if $ADDR accepts option $o"
1082 $SOCAT $opts $ADDR:$PORT,reuseaddr
,$o echo </dev
/null
&
1084 $SOCAT /dev
/null ip4-sendto
:$LOCALHOST:$PORT 2>/dev
/null
1085 kill $pid 2>/dev
/null
1092 #------------------------------------------------------------------------------
1099 #opts="-s -d -d -d -d"
1100 for addr
in ip4-recvfrom
; do
1101 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1102 TEST
="$ADDR accepts all its options"
1104 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1106 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1107 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1111 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1112 echo "testing if $ADDR accepts option $o"
1113 $SOCAT $opts $ADDR:$PORT,reuseaddr
,$o echo </dev
/null
&
1115 $SOCAT /dev
/null ip4-sendto
:$LOCALHOST:$PORT 2>/dev
/null
1116 kill $pid 2>/dev
/null
1123 #------------------------------------------------------------------------------
1129 #opts="-s -d -d -d -d"
1130 for addr
in readline
; do
1131 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1132 TEST
="$ADDR accepts all its options"
1135 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr " |
sed 's/.*=//')
1137 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1138 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1142 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1144 echo "testing if $ADDR accepts option $o"
1145 echo "$SOCAT $opts readline,$o /dev/null" >$TS
1147 $SOCAT /dev
/null
,ignoreeof
exec:$TS,pty
1155 #------------------------------------------------------------------------------
1160 for addr
in pipe
; do
1161 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1162 TEST
="unnamed $ADDR accepts all its options"
1164 OPTGROUPS
=$
($SOCAT -? |
egrep " $addr[^:]" |
sed 's/.*=//')
1166 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1167 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1172 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1173 echo testing
if unnamed
$ADDR accepts option
$o
1174 $SOCAT $opts $addr,$o /dev
/null
</dev
/null
1179 #------------------------------------------------------------------------------
1181 # test addresses on files
1186 for addr
in create
; do
1187 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1188 TEST
="$ADDR on new file accepts all its options"
1191 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1193 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1194 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1199 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1200 echo testing
if $ADDR accepts option
$o
1202 $SOCAT $opts -!!$addr:$TF,$o /dev
/null
,ignoreof
</dev
/null
1207 #------------------------------------------------------------------------------
1211 for addr
in exec system
; do
1212 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1214 TEST
="$ADDR with socketpair accepts all its options"
1216 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1217 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,FIFO,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g')
1219 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1220 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1223 OPTS
=$
(echo $OPTS|
sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1225 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1226 echo testing
if $ADDR with socketpair accepts option
$o
1227 $SOCAT $opts $addr:$TRUE,$o /dev
/null
,ignoreof
</dev
/null
1230 TEST
="$ADDR with pipes accepts all its options"
1232 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1233 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,TERMIOS,/,/g' -e 's/,PTY,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1235 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1236 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1239 # flock tends to hang, so dont test it
1240 OPTS
=$
(echo $OPTS|
sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g' -e 's/,flock,/,/g')
1242 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1243 echo testing
if $ADDR with pipes accepts option
$o
1244 $SOCAT $opts $addr:$TRUE,pipes
,$o /dev
/null
,ignoreof
</dev
/null
1247 TEST
="$ADDR with pty accepts all its options"
1249 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1250 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,FIFO,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1252 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1253 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1256 OPTS
=$
(echo $OPTS|
sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1258 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1259 echo testing
if $ADDR with pty accepts option
$o
1260 $SOCAT $opts $addr:$TRUE,pty
,$o /dev
/null
,ignoreof
</dev
/null
1263 TEST
="$ADDR with nofork accepts all its options"
1265 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1266 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,FIFO,/,/g' -e 's/,PTY,/,/g' -e 's/,TERMIOS,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1268 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1269 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1272 OPTS
=$
(echo $OPTS|
sed -e 's/,pipes,/,/g' -e 's/,pty,/,/g' -e 's/,openpty,/,/g' -e 's/,ptmx,/,/g' -e 's/,nofork,/,/g')
1274 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1275 echo testing
if $ADDR with nofork accepts option
$o
1276 $SOCAT /dev
/null
$opts $addr:$TRUE,nofork
,$o </dev
/null
1282 #------------------------------------------------------------------------------
1287 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1288 TEST
="$ADDR accepts all its options"
1291 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1293 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1294 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1298 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1299 echo "testing if $ADDR (to file) accepts option $o"
1301 $SOCAT $opts -u /dev
/null
$addr:3,$o 3>$TF
1306 #------------------------------------------------------------------------------
1310 #! test it on pipe, device, new file
1315 for addr
in open
; do
1316 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1317 TEST
="$ADDR on file accepts all its options"
1320 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1322 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1323 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1327 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1328 echo testing
if $ADDR on
file accepts option
$o
1330 $SOCAT $opts -!!$addr:$TF,$o /dev
/null
,ignoreof
</dev
/null
1336 #------------------------------------------------------------------------------
1338 # test GOPEN address on files, sockets, pipes, devices
1343 for addr
in gopen
; do
1344 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1346 TEST
="$ADDR on new file accepts all its options"
1349 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1350 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1352 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1353 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1357 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1358 echo testing
if $ADDR on new
file accepts option
$o
1360 $SOCAT $opts -!!$addr:$TF,$o /dev
/null
,ignoreof
</dev
/null
1364 TEST
="$ADDR on existing file accepts all its options"
1367 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1368 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1370 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1371 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1375 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1376 echo testing
if $ADDR on existing
file accepts option
$o
1377 rm -f $TF; touch $TF
1378 $SOCAT $opts -!!$addr:$TF,$o /dev
/null
,ignoreof
</dev
/null
1382 TEST
="$ADDR on existing pipe accepts all its options"
1385 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1386 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,REG,/,/g' -e 's/,SOCKET,/,/g' -e 's/,UNIX//g')
1388 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1389 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1393 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1394 echo testing
if $ADDR on named pipe accepts option
$o
1395 rm -f $TF; mkfifo $TF
1396 $SOCAT $opts $addr:$TF,$o,nonblock
/dev
/null
</dev
/null
1400 TEST
="$ADDR on existing socket accepts all its options"
1403 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1404 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1406 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1407 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1411 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1412 echo testing
if $ADDR on socket accepts option
$o
1413 rm -f $TF; $SOCAT - UNIX-L
:$TF & pid
=$
!
1414 $SOCAT $opts -!!$addr:$TF,$o /dev
/null
,ignoreof
</dev
/null
1415 kill $pid 2>/dev
/null
1419 if [ $
(id
-u) -eq 0 ]; then
1420 TEST
="$ADDR on existing device accepts all its options"
1423 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1424 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1426 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1427 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1431 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1432 echo testing
if $ADDR on existing device accepts option
$o
1433 rm -f $TF; mknod
$TF c
1 3
1434 $SOCAT $opts -!!$addr:$TF,$o /dev
/null
,ignoreof
</dev
/null
1437 TEST
="$ADDR on existing device accepts all its options"
1440 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1441 OPTGROUPS
=$
(echo $OPTGROUPS |
sed -e 's/,REG,/,/g' -e 's/,OPEN,/,/g')
1443 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1444 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1448 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1449 echo testing
if $ADDR on existing device accepts option
$o
1450 $SOCAT $opts -!!$addr:$TF,$o /dev
/null
,ignoreof
</dev
/null
1457 #------------------------------------------------------------------------------
1464 for addr
in pipe
; do
1465 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1466 TEST
="$ADDR on file accepts all its options"
1469 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1471 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1472 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1477 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1478 echo testing
if named
$ADDR accepts option
$o
1480 # blocks with rdonly, wronly
1481 case "$o" in rdonly|wronly
) o
="$o,nonblock" ;; esac
1482 $SOCAT $opts $addr:$TF,$o /dev
/null
</dev
/null
1487 #------------------------------------------------------------------------------
1491 #! test different stream types
1495 for addr
in stdio
; do
1496 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1497 TEST
="$ADDR accepts all its options"
1499 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr" |
sed 's/.*=//')
1501 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1502 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1507 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1508 echo "testing if $ADDR (/dev/null, stdout) accepts option $o"
1509 $SOCAT $opts $addr,$o /dev
/null
,ignoreof
</dev
/null
1514 #------------------------------------------------------------------------------
1520 for addr
in stdin
; do
1521 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1522 TEST
="$ADDR accepts all its options"
1524 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr " |
sed 's/.*=//')
1526 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1527 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1532 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1533 echo "testing if $ADDR (/dev/null) accepts option $o"
1534 $SOCAT $opts -u $addr,$o /dev
/null
</dev
/null
1539 #------------------------------------------------------------------------------
1541 # test STDOUT, STDERR
1545 for addr
in stdout stderr
; do
1546 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1547 TEST
="$ADDR accepts all its options"
1549 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr " |
sed 's/.*=//')
1551 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1552 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1556 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1557 echo "testing if $ADDR accepts option $o"
1558 $SOCAT $opts -u /dev
/null
$addr,$o
1563 #------------------------------------------------------------------------------
1566 if [ "$withroot" ]; then
1568 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1569 TEST
="$ADDR accepts all its options"
1571 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1573 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1574 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1578 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1579 echo "testing if $ADDR accepts option $o"
1580 $SOCAT $opts $addr:127.0.0.1:200 /dev
/null
,ignoreof
</dev
/null
1585 #------------------------------------------------------------------------------
1588 if [ "$withroot" ]; then
1590 ADDR
=$
(echo "$addr" |
tr a-z A-Z
)
1591 TEST
="$ADDR accepts all its options"
1593 OPTGROUPS
=$
($SOCAT -? |fgrep
" $addr:" |
sed 's/.*=//')
1595 for g
in $
(echo $OPTGROUPS |
tr ',' ' '); do
1596 eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
1600 for o
in $
(filloptionvalues
$OPTS|
tr ',' ' '); do
1601 echo "testing if $ADDR accepts option $o"
1602 $SOCAT $opts $addr:[::1]:200 /dev
/null
,ignoreof
</dev
/null
1607 #==============================================================================
1609 #TEST="stdio accepts all options of GROUP_ANY"
1611 #CMD="$SOCAT $opts -,$OPTS_ANY /dev/null"
1613 #if [ $? = 0 ]; then
1614 # echo "... test $N ($TEST) succeeded"
1617 # echo "*** test $N ($TEST) FAILED"
1622 ##------------------------------------------------------------------------------
1624 #TEST="exec accepts all options of GROUP_ANY and GROUP_SOCKET"
1626 #CMD="$SOCAT $opts exec:$TRUE,$OPTS_ANY,$OPTS_SOCKET /dev/null"
1628 #if [ $? = 0 ]; then
1629 # echo "... test $N ($TEST) succeeded"
1632 # echo "*** test $N ($TEST) FAILED"
1636 #------------------------------------------------------------------------------
1640 #==============================================================================
1648 #==============================================================================
1649 # test if selected socat features work ("FUNCTIONS")
1654 local arg1
="$3"; [ -z "$arg1" ] && arg1
="-"
1655 local arg2
="$4"; [ -z "$arg2" ] && arg2
="echo"
1657 local T
="$6"; [ -z "$T" ] && T
=0
1658 local tf
="$td/test$N.stdout"
1659 local te
="$td/test$N.stderr"
1660 local tdiff
="$td/test$N.diff"
1661 local da
="test$N $(date) $RANDOM"
1662 if ! eval $NUMCOND; then :; else
1663 #local cmd="$TRACE $SOCAT $opts $arg1 $arg2"
1664 #$ECHO "testing $title (test $N)... \c"
1665 $PRINTF "test $F_n %s... " $N "$title"
1666 #echo "$da" |$cmd >"$tf" 2>"$te"
1667 (psleep
$T; echo "$da"; psleep
$T) |
($TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"; echo $?
>"$td/test$N.rc") &
1669 #sleep 5 && kill $rc1 2>/dev/null &
1672 # kill $rc2 2>/dev/null
1673 if [ "$(cat "$td/test$N.rc
")" != 0 ]; then
1674 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1675 echo "$TRACE $SOCAT $opts $arg1 $arg2" >&2
1677 numFAIL
=$
((numFAIL
+1))
1678 listFAIL
="$listFAIL $N"
1679 elif echo "$da" |
diff - "$tf" >"$tdiff" 2>&1; then
1681 if [ "$verbose" ]; then echo "$SOCAT $opts $arg1 $arg2" >&2; fi
1682 if [ -n "$debug" ]; then cat $te >&2; fi
1685 $PRINTF "$FAILED:\n"
1686 echo "$TRACE $SOCAT $opts $arg1 $arg2" >&2
1690 numFAIL
=$
((numFAIL
+1))
1691 listFAIL
="$listFAIL $N"
1696 # test if call to od and throughput of data works - with graceful shutdown and
1697 # flush of od buffers
1701 local arg1
="$3"; [ -z "$arg1" ] && arg1
="-"
1702 local arg2
="$4"; [ -z "$arg2" ] && arg2
="echo"
1704 local T
="$6"; [ -z "$T" ] && T
=0
1705 local tf
="$td/test$N.stdout"
1706 local te
="$td/test$N.stderr"
1707 local tr="$td/test$N.ref"
1708 local tdiff
="$td/test$N.diff"
1709 local dain
="$(date) $RANDOM"
1710 if ! eval $NUMCOND; then :; else
1711 echo "$dain" |
$OD_C >"$tr"
1712 # local daout="$(echo "$dain" |$OD_C)"
1713 $PRINTF "test $F_n %s... " $num "$title"
1714 (psleep
$T; echo "$dain"; psleep
$T) |
$TRACE $SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"
1715 if [ "$?" != 0 ]; then
1716 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
1717 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1719 numFAIL
=$
((numFAIL
+1))
1720 listFAIL
="$listFAIL $num"
1721 # elif echo "$daout" |diff - "$tf" >"$tdiff" 2>&1; then
1722 elif diff "$tr" "$tf" >"$tdiff" 2>&1; then
1724 if [ -n "$debug" ]; then cat $te; fi
1727 $PRINTF "$FAILED: diff:\n"
1728 echo "$TRACE $SOCAT $opts $arg1 $arg2"
1731 numFAIL
=$
((numFAIL
+1))
1732 listFAIL
="$listFAIL $num"
1737 # test if the socat executable has these address types compiled in
1738 # print the first missing address type
1742 A
=$
(echo "$a" |
tr 'a-z-' 'A-Z_')
1743 if $TRACE $SOCAT -V |
grep "#define WITH_$A 1\$" >/dev
/null
; then
1744 if [[ "$A" =~ OPENSSL.
* ]]; then
1757 # test if the socat executable has these options compiled in
1758 # print the first missing option
1762 A
=$
(echo "$a" |
tr 'a-z' 'A-Z')
1763 if $SOCAT -??? |
grep "[^a-z0-9-]$a[^a-z0-9-]" >/dev
/null
; then
1773 # check if the given pid exists and has child processes
1774 # if yes: prints child process lines to stdout, returns 0
1775 # if not: prints ev.message to stderr, returns 1
1779 AIX
) l
="$(ps -fade |grep "^........ ...... $
(printf %6u $1)")" ;;
1780 FreeBSD
) l
="$(ps -faje |grep "^........ ..... $
(printf %5u $1)")" ;;
1781 HP-UX
) l
="$(ps -fade |grep "^........ ..... $
(printf %5u $1)")" ;;
1782 Linux
) l
="$(ps -fade |grep "^........ ..... $
(printf %5u $1)")" ;;
1783 # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)")" ;;
1784 NetBSD
) l
="$(ps -aj |grep "^
[^
][^
]*[ ][ ]*..... $
(printf %5u $1)")" ;;
1785 OpenBSD
) l
="$(ps -aj |grep "^........ ..... $
(printf %5u $1)")" ;;
1786 SunOS
) l
="$(ps -fade |grep "^........ ..... $
(printf %5u $1)")" ;;
1787 DragonFly
)l
="$(ps -faje |grep "^
[^
][^
]*[ ][ ]*..... $
(printf %5u $1)")" ;;
1788 CYGWIN
*) l
="$(ps -pafe |grep "^
[^
]*[ ][ ]*[^
][^
]*[ ][ ]*$1[ ]")" ;;
1789 *) l
="$(ps -fade |grep "^
[^
][^
]*[ ][ ]*[0-9][0-9]**[ ][ ]*$
(printf %5u $1) ")" ;; esac
1790 if [ -z "$l" ]; then
1797 # return a list of child process pids
1800 AIX
) l
="$(ps -fade |grep "^........ ...... $
(printf %6u $1)" |awk '{print($2);}')" ;;
1801 FreeBSD
) l
="$(ps -fl |grep "^
[^
][^
]*[ ][ ]*[0-9][0-9]*[ ][ ]*$
(printf %5u $1)" |awk '{print($2);}')" ;;
1802 HP-UX
) l
="$(ps -fade |grep "^........ ..... $
(printf %5u $1)" |awk '{print($2);}')" ;;
1803 Linux
) l
="$(ps -fade |grep "^........ ..... $
(printf %5u $1)" |awk '{print($2);}')" ;;
1804 # NetBSD) l="$(ps -aj |grep "^........ ..... $(printf %4u $1)" |awk '{print($2);}')" ;;
1805 NetBSD
) l
="$(ps -aj |grep "^
[^
][^
]*[ ][ ]*..... $
(printf %5u $1)" |awk '{print($2);}')" ;;
1806 OpenBSD
) l
="$(ps -aj |grep "^........ ..... $
(printf %5u $1)" |awk '{print($2);}')" ;;
1807 SunOS
) l
="$(ps -fade |grep "^........ ..... $
(printf %5u $1)" |awk '{print($2);}')" ;;
1808 DragonFly
)l
="$(ps -faje |grep "^
[^
][^
]*[ ][ ]*..... $
(printf %5u $1)" |awk '{print($2);}')" ;;
1809 CYGWIN
*) l
="$(ps -pafe |grep "^
[^
]*[ ][ ]*[^
][^
]*[ ][ ]*$1[ ]" |awk '{print($2)';})" ;;
1810 *) l
="$(ps -fade |grep "^
[^
][^
]*[ ][ ]*[0-9][0-9]*[ ][ ]*$
(printf %5u $1) " |awk '{print($2)';})" ;; esac
1811 if [ -z "$l" ]; then
1818 # check if the given process line refers to a defunct (zombie) process
1824 AIX
) l
="$(echo "$1" |grep ' <defunct>$')" ;;
1825 FreeBSD
) l
="$(echo "$1" |grep ' <defunct>$')" ;;
1826 HP-UX
) l
="$(echo "$1" |grep ' <defunct>$')" ;;
1827 Linux
) l
="$(echo "$1" |grep ' <defunct>$')" ;;
1828 SunOS
) l
="$(echo "$1" |grep ' <defunct>$')" ;;
1829 DragonFly
)l
="$(echo "$1" |grep ' <defunct>$')" ;;
1830 *) l
="$(echo "$1" |grep ' <defunct>$')" ;;
1835 # check if UNIX socket protocol is available on host
1838 $TRACE $SOCAT /dev
/null UNIX-LISTEN
:"$td/unix.socket" 2>"$td/unix.stderr" &
1841 kill "$pid" 2>/dev
/null
1842 test ! -s "$td/unix.stderr"
1846 # check if an IP4 loopback interface exists
1848 [ -n "$HAVENOT_IP4" ] && return $HAVENOT_IP4
1851 AIX
) l
=$
($IFCONFIG lo0 |fgrep
'inet 127.0.0.1 ') ;;
1852 FreeBSD
) l
=$
($IFCONFIG lo0 |fgrep
'inet 127.0.0.1 ') ;;
1853 HP-UX
) l
=$
($IFCONFIG lo0 |fgrep
'inet 127.0.0.1 ') ;;
1854 Linux
) if [ "$IP" ]; then
1855 l
=$
($IP address |
egrep ' inet 127.0.0.1/')
1857 l
=$
($IFCONFIG |
egrep 'inet (addr:)?127\.0\.0\.1 ')
1859 NetBSD
)l
=$
($IFCONFIG -a |fgrep
'inet 127.0.0.1 ');;
1860 OpenBSD
)l
=$
($IFCONFIG -a |fgrep
'inet 127.0.0.1 ');;
1861 OSF1
) l
=$
($IFCONFIG -a |
grep ' inet ') ;;
1862 SunOS
) l
=$
($IFCONFIG -a |
grep 'inet ') ;;
1863 Darwin
)l
=$
($IFCONFIG lo0 |fgrep
'inet 127.0.0.1 ') ;;
1864 DragonFly
)l
=$
($IFCONFIG -a |fgrep
'inet 127.0.0.1 ');;
1865 CYGWIN
*) l
=$
(ipconfig |
grep IPv4
);;
1866 *) l
=$
($IFCONFIG -a |
grep ' ::1[^:0-9A-Fa-f]') ;;
1868 [ -z "$l" ] && return 1
1869 # existence of interface might not suffice, check for routeability:
1871 Darwin
) ping -c 1 127.0.0.1 >/dev
/null
2>&1; l
="$?" ;;
1872 Linux
) ping -c 1 127.0.0.1 >/dev
/null
2>&1; l
="$?" ;;
1873 *) if [ -n "$l" ]; then l
=0; else l
=1; fi ;;
1880 # check if an IP6 loopback interface exists
1882 [ -n "$HAVENOT_IP6" ] && return $HAVENOT_IP6
1885 AIX
) l
=$
($IFCONFIG lo0 |
grep 'inet6 ::1/0') ;;
1886 HP-UX
) l
=$
($IFCONFIG lo0 |
grep ' inet6 ') ;;
1887 Linux
) if [ "$IP" ]; then
1888 l
=$
($IP address |
egrep 'inet6 ::1/128')
1890 l
=$
($IFCONFIG |
egrep 'inet6 (addr: )?::1/?')
1892 NetBSD
)l
=$
($IFCONFIG -a |
grep 'inet6 ::1 ');;
1893 OSF1
) l
=$
($IFCONFIG -a |
grep ' inet6 ') ;;
1894 SunOS
) l
=$
($IFCONFIG -a |
grep 'inet6 ') ;;
1895 Darwin
)l
=$
($IFCONFIG lo0 |
grep 'inet6 ::1 ') ;;
1896 CYGWIN
*) l
=$
(ipconfig |
grep IPv6
);;
1897 *) l
=$
($IFCONFIG -a |
grep ' ::1[^:0-9A-Fa-f]') ;;
1899 [ -z "$l" ] && return 1
1900 # existence of interface might not suffice, check for routeability:
1902 Darwin
) $PING6 -c 1 ::1 >/dev
/null
2>&1; l
="$?" ;;
1903 Linux
) $PING6 -c 1 ::1 >/dev
/null
2>&1; l
="$?" ;;
1904 *) if [ -n "$l" ]; then l
=0; else l
=1; fi ;;
1910 # check if TCP on IPv4 is available on host
1913 $SOCAT -h |
grep '\<tcp4-' >/dev
/null ||
return 1
1917 # check if TCP on IPv6 is available on host
1920 $SOCAT -h |
grep '\<tcp6-' >/dev
/null ||
return 1
1924 # check if UDP on IPv4 is available on host
1927 $SOCAT -h |
grep '\<udp4-' >/dev
/null ||
return 1
1931 # check if UDP on IPv6 is available on host
1934 $SOCAT -h |
grep '\<udp6-' >/dev
/null ||
return 1
1938 # check if SCTP on IPv4 is available on host
1941 $SOCAT -h |
grep '\<sctp4-' >/dev
/null ||
return 1
1945 # check if SCTP on IPv6 is available on host
1948 $SOCAT -h |
grep '\<sctp6-' >/dev
/null ||
return 1
1952 # wait until an IP4 protocol is ready
1955 local logic
="$2" # 0..wait until free; 1..wait until listening
1958 [ "$logic" ] || logic
=1
1959 [ "$timeout" ] || timeout
=5
1960 while [ $timeout -gt 0 ]; do
1962 Linux
) if [ "$SS" ]; then
1963 l
=$
($SS -n -w -l |
grep '^\(raw\|UNCONN\) .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*')
1965 l
=$
(netstat
-n -w -l |
grep '^raw .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*')
1967 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
1968 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1969 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
1970 # Darwin) case "$(uname -r)" in
1971 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
1972 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
1974 AIX
) # does not seem to show raw sockets in netstat
1975 sleep 1; return 0 ;;
1976 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
1977 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
1978 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
1979 *) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;;
1980 sleep 1; return 0 ;;
1982 [ \
( \
( $logic -ne 0 \
) -a -n "$l" \
) -o \
1983 \
( \
( $logic -eq 0 \
) -a -z "$l" \
) ] && return 0
1985 timeout
=$
((timeout-1
))
1988 $ECHO "!protocol $proto timed out! \c" >&2
1992 # we need this misleading function name for canonical reasons
1994 waitip4proto
"$1" "$2" "$3"
1997 # wait until an IP6 protocol is ready
2000 local logic
="$2" # 0..wait until free; 1..wait until listening
2003 [ "$logic" ] || logic
=1
2004 [ "$timeout" ] || timeout
=5
2005 while [ $timeout -gt 0 ]; do
2009 l
=$
($SS -n -w -l |
grep '^\(raw\|UNCONN\) .* \*:'$proto' [ ]*\*:\*')
2011 l
=$
(netstat
-n -w -l |
grep '^raw[6 ] .* .*:[0-9*]*:'$proto' [ ]*:::\*')
2013 # FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;;
2014 # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2015 # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;;
2016 # Darwin) case "$(uname -r)" in
2017 # [1-5]*) l=$(netstat -an |grep '^raw.* .*[0-9*]\.'$proto' .* \*\.\*') ;;
2018 # *) l=$(netstat -an |grep '^raw4.* .*[0-9*]\.'$proto' .* \*\.\* .*') ;;
2020 AIX
) # does not seem to show raw sockets in netstat
2021 sleep 1; return 0 ;;
2022 # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;;
2023 # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;;
2024 # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;;
2025 *) #l=$(netstat -an |egrep -i 'raw6? .*[0-9*][:.]'$proto' ') ;;
2026 sleep 1; return 0 ;;
2028 [ \
( \
( $logic -ne 0 \
) -a -n "$l" \
) -o \
2029 \
( \
( $logic -eq 0 \
) -a -z "$l" \
) ] && return 0
2031 timeout
=$
((timeout-1
))
2034 $ECHO "!protocol $proto timed out! \c" >&2
2038 # we need this misleading function name for canonical reasons
2040 waitip6proto
"$1" "$2" "$3"
2043 # check if a TCP4 port is in use
2044 # exits with 0 when it is not used
2049 Linux
) if [ "$SS" ]; then
2050 l
=$
($SS -4 -l -n -t |
grep "^LISTEN .*:$port\>")
2052 l
=$
(netstat
-a -n -t |
grep '^tcp .* .*[0-9*]:'$port' .* LISTEN')
2054 FreeBSD
) l
=$
(netstat
-an |
grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2055 NetBSD
) l
=$
(netstat
-an |
grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2056 Darwin
) case "$(uname -r)" in
2057 [1-5]*) l
=$
(netstat
-an |
grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2058 *) l
=$
(netstat
-an |
grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2060 AIX
) l
=$
(netstat
-an |
grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2061 SunOS
) l
=$
(netstat
-an -f inet
-P tcp |
grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2062 HP-UX
) l
=$
(netstat
-an |
grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2063 OSF1
) l
=$
(/usr
/sbin
/netstat
-an |
grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2064 CYGWIN
*) l
=$
(netstat
-an -p TCP |
grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2065 DragonFly
)l
=$
(netstat
-ant |
grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2066 *) l
=$
(netstat
-an |
grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2068 [ -z "$l" ] && return 0
2072 # wait until a TCP4 listen port is ready
2075 local logic
="$2" # 0..wait until free; 1..wait until listening (default)
2078 local vx
=+; case $
- in *vx
*) set +vx
; vx
=-; esac # no tracing here
2079 [ "$logic" ] || logic
=1
2080 [ "$timeout" ] || timeout
=5
2081 while [ $timeout -gt 0 ]; do
2083 Linux
) if [ "$SS" ]; then
2084 l
=$
($SS -l -n -t |
grep "^LISTEN .*:$port\>")
2086 l
=$
(netstat
-a -n -t |
grep '^tcp .* .*[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') ;;
2094 AIX
) l
=$
(netstat
-an |
grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2095 SunOS
) l
=$
(netstat
-an -f inet
-P tcp |
grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2096 HP-UX
) l
=$
(netstat
-an |
grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2097 OSF1
) l
=$
(/usr
/sbin
/netstat
-an |
grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2098 CYGWIN
*) l
=$
(netstat
-an -p TCP |
grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2099 DragonFly
) l
=$
(netstat
-ant |
grep '^tcp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2100 *) l
=$
(netstat
-an |
grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;;
2102 if [ \
( \
( $logic -ne 0 \
) -a -n "$l" \
) -o \
2103 \
( \
( $logic -eq 0 \
) -a -z "$l" \
) ]; then
2108 timeout
=$
((timeout-1
))
2111 $ECHO "!port $port timed out! \c" >&2
2116 # wait until a UDP4 port is ready
2119 local logic
="$2" # 0..wait until free; 1..wait until listening
2122 local vx
=+; case $
- in *vx
*) set +vx
; vx
=-; esac # no tracing here
2123 [ "$logic" ] || logic
=1
2124 [ "$timeout" ] || timeout
=5
2125 while [ $timeout -gt 0 ]; do
2127 Linux
) if [ "$SS" ]; then
2128 l
=$
($SS -4 -l -n -u |
grep "^UNCONN .*:$port\>")
2130 l
=$
(netstat
-a -n -u -l |
grep '^udp .* .*[0-9*]:'$port' [ ]*0\.0\.0\.0:\*')
2132 FreeBSD
) l
=$
(netstat
-an |
egrep '^udp46? .*[0-9*]\.'$port' .* \*\.\*') ;;
2133 NetBSD
) l
=$
(netstat
-an |
grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2134 OpenBSD
) l
=$
(netstat
-an |
grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2135 Darwin
) case "$(uname -r)" in
2136 [1-5]*) l
=$
(netstat
-an |
grep '^udp.* .*[0-9*]\.'$port' .* \*\.\*') ;;
2137 *) l
=$
(netstat
-an |
grep '^udp4.* .*[0-9*]\.'$port' .* \*\.\* .*') ;;
2139 AIX
) l
=$
(netstat
-an |
grep '^udp[4 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2140 SunOS
) l
=$
(netstat
-an -f inet
-P udp |
grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2141 HP-UX
) l
=$
(netstat
-an |
grep '^udp 0 0 .*[0-9*]\.'$port' .* \*\.\* ') ;;
2142 OSF1
) l
=$
(/usr
/sbin
/netstat
-an |
grep '^udp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2143 DragonFly
) l
=$
(netstat
-an |
grep '^udp4 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2144 *) l
=$
(netstat
-an |
grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2146 if [ \
( \
( $logic -ne 0 \
) -a -n "$l" \
) -o \
2147 \
( \
( $logic -eq 0 \
) -a -z "$l" \
) ]; then
2152 timeout
=$
((timeout-1
))
2155 $ECHO "!port $port timed out! \c" >&2
2160 # wait until an SCTP4 listen port is ready
2163 local logic
="$2" # 0..wait until free; 1..wait until listening
2166 local vx
=+; case $
- in *vx
*) set +vx
; vx
=-; esac # no tracing here
2167 [ "$logic" ] || logic
=1
2168 [ "$timeout" ] || timeout
=5
2169 while [ $timeout -gt 0 ]; do
2171 Linux
) if [ "$SS" ]; then
2172 l
=$
($SS -4 -n -A sctp
2>/dev
/null |
grep "^LISTEN .*:$port\>")
2174 l
=$
(netstat
-n -a |
grep '^sctp .* .*[0-9*]:'$port' .* LISTEN')
2176 # FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2177 # NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2178 # Darwin) case "$(uname -r)" in
2179 # [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2180 # *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;;
2182 # AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2183 SunOS
) l
=$
(netstat
-an -f inet
-P sctp |
grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;;
2184 # HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;;
2185 # OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;;
2186 # CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;;
2187 *) l
=$
(netstat
-an |
grep -i 'sctp .*[0-9*][:.]'$port' .* listen') ;;
2189 if [ \
( \
( $logic -ne 0 \
) -a -n "$l" \
) -o \
2190 \
( \
( $logic -eq 0 \
) -a -z "$l" \
) ]; then
2195 timeout
=$
((timeout-1
))
2198 $ECHO "!port $port timed out! \c" >&2
2203 # wait until a tcp6 listen port is ready
2206 local logic
="$2" # 0..wait until free; 1..wait until listening
2209 local vx
=+; case $
- in *vx
*) set +vx
; vx
=-; esac # no tracing here
2210 [ "$logic" ] || logic
=1
2211 [ "$timeout" ] || timeout
=5
2212 while [ $timeout -gt 0 ]; do
2214 Linux
) if [ "$SS" ]; then
2215 l
=$
($SS -6 -n -t -l |
grep "^LISTEN .*:$port\>")
2217 l
=$
(netstat
-an |
grep -E '^tcp6? .* [0-9a-f:%]*:'$port' .* LISTEN')
2219 FreeBSD
) l
=$
(netstat
-an |
egrep -i 'tcp(6|46) .*[0-9*][:.]'$port' .* listen') ;;
2220 NetBSD
) l
=$
(netstat
-an |
grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2221 OpenBSD
) l
=$
(netstat
-an |
grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2222 Darwin
) l
=$
(netstat
-an |
egrep '^tcp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+ +LISTEN') ;;
2223 AIX
) l
=$
(netstat
-an |
grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2224 SunOS
) l
=$
(netstat
-an -f inet6
-P tcp |
grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2225 #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2226 DragonFly
) l
=$
(netstat
-ant |
grep '^tcp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;;
2227 *) l
=$
(netstat
-an |
grep -i 'tcp6 .*:'$port' .* listen') ;;
2229 if [ \
( \
( $logic -ne 0 \
) -a -n "$l" \
) -o \
2230 \
( \
( $logic -eq 0 \
) -a -z "$l" \
) ]; then
2235 timeout
=$
((timeout-1
))
2238 $ECHO "!port $port timed out! \c" >&2
2239 #echo set ${vx}vx >&2
2244 # wait until a UDP6 port is ready
2247 local logic
="$2" # 0..wait until free; 1..wait until listening
2250 local vx
=+; case $
- in *vx
*) set +vx
; vx
=-; esac # no tracing here
2251 [ "$logic" ] || logic
=1
2252 [ "$timeout" ] || timeout
=5
2253 while [ $timeout -gt 0 ]; do
2255 Linux
) if [ "$SS" ]; then
2256 l
=$
($SS -6 -u -l -n |
grep "^UNCONN .*:$port\>")
2258 l
=$
(netstat
-an |
grep -E '^udp6? .* .*[0-9*:%]:'$port' [ ]*:::\*')
2260 FreeBSD
) l
=$
(netstat
-an |
egrep '^udp(6|46) .*[0-9*]\.'$port' .* \*\.\*') ;;
2261 NetBSD
) l
=$
(netstat
-an |
grep '^udp6 .* \*\.'$port' [ ]* \*\.\*') ;;
2262 OpenBSD
) l
=$
(netstat
-an |
grep '^udp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2263 Darwin
) l
=$
(netstat
-an |
egrep '^udp4?6 +[0-9]+ +[0-9]+ +[0-9a-z:%*]+\.'$port' +[0-9a-z:%*.]+') ;;
2264 AIX
) l
=$
(netstat
-an |
grep '^udp[6 ] 0 0 .*[*0-9]\.'$port' .* \*\.\*[ ]*$') ;;
2265 SunOS
) l
=$
(netstat
-an -f inet6
-P udp |
grep '.*[1-9*]\.'$port' [ ]*Idle') ;;
2266 #HP-UX) l=$(netstat -an |grep '^udp 0 0 .*[0-9*]\.'$port' ') ;;
2267 #OSF1) l=$(/usr/sbin/netstat -an |grep '^udp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\*') ;;
2268 DragonFly
) l
=$
(netstat
-ant |
grep '^udp6 .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]*') ;;
2269 *) l
=$
(netstat
-an |
grep -i 'udp .*[0-9*][:.]'$port' ') ;;
2271 if [ \
( \
( $logic -ne 0 \
) -a -n "$l" \
) -o \
2272 \
( \
( $logic -eq 0 \
) -a -z "$l" \
) ]; then
2277 timeout
=$
((timeout-1
))
2280 $ECHO "!port $port timed out! \c" >&2
2285 # wait until a sctp6 listen port is ready
2286 # not all (Linux) variants show this in netstat
2289 local logic
="$2" # 0..wait until free; 1..wait until listening
2292 local vx
=+; case $
- in *vx
*) set +vx
; vx
=-; esac # no tracing here
2293 [ "$logic" ] || logic
=1
2294 [ "$timeout" ] || timeout
=5
2295 while [ $timeout -gt 0 ]; do
2297 Linux
) if [ "$SS" ]; then
2298 l
=$
($SS -6 -n -A sctp
2>/dev
/null |
grep "^LISTEN .*:$port\>")
2300 l
=$
(netstat
-an |
grep '^sctp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN')
2302 # FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;;
2303 # NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;;
2304 # OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;;
2305 # AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;;
2306 SunOS
) l
=$
(netstat
-an -f inet6
-P sctp |
grep '.*[1-9*]\.'$port' .*\* [ ]* 0 .* LISTEN') ;;
2307 # #OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp6 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') /*?*/;;
2308 *) l
=$
(netstat
-an |
grep -i 'stcp6 .*:'$port' .* listen') ;;
2310 if [ \
( \
( $logic -ne 0 \
) -a -n "$l" \
) -o \
2311 \
( \
( $logic -eq 0 \
) -a -z "$l" \
) ]; then
2316 timeout
=$
((timeout-1
))
2319 $ECHO "!port $port timed out! \c" >&2
2324 # we need this misleading function name for canonical reasons
2326 waitfile
"$1" "$2" "$3"
2329 # wait until a filesystem entry exists
2332 case "X$1" in X-
*) crit
="$1"; shift ;; esac
2334 local logic
="$2" # 0..wait until gone; 1..wait until exists (default);
2335 # 2..wait until not empty
2337 local vx
=+; case $
- in *vx
*) set +vx
; vx
=-; esac # no tracing here
2338 [ "$logic" ] || logic
=1
2339 [ "$logic" -eq 2 ] && crit
=-s
2340 [ "$timeout" ] || timeout
=5
2341 while [ $timeout -gt 0 ]; do
2342 if [ \
( \
( $logic -ne 0 \
) -a $crit "$file" \
) -o \
2343 \
( \
( $logic -eq 0 \
) -a ! $crit "$file" \
) ]; then
2348 timeout
=$
((timeout-1
))
2351 echo "file $file timed out" >&2
2356 # generate a test certificate and key
2359 if ! [ -f testcert.dh
]; then
2360 openssl dhparam
-out testcert.dh
$RSABITS
2362 if [ -s $name.key
-a -s $name.crt
-a -s $name.pem
]; then return; fi
2363 openssl genrsa
$OPENSSL_RAND -out $name.key
$RSABITS >/dev
/null
2>&1
2364 openssl req
-new -config $TESTCERT_CONF -key $name.key
-x509 -out $name.crt
-days 3653 >/dev
/null
2>&1
2365 cat $name.key
$name.crt testcert.dh
>$name.pem
2368 # generate a test DSA key and certificate
2371 if [ -s $name.key
-a -s $name.crt
-a -s $name.pem
]; then return; fi
2372 openssl dsaparam
-out $name-dsa.pem
1024 >/dev
/null
2>&1
2373 openssl dhparam
-dsaparam -out $name-dh.pem
1024 >/dev
/null
2>&1
2374 openssl req
-newkey dsa
:$name-dsa.pem
-keyout $name.key
-nodes -x509 -config $TESTCERT_CONF -out $name.crt
-days 3653 >/dev
/null
2>&1
2375 cat $name-dsa.pem
$name-dh.pem
$name.key
$name.crt
>$name.pem
2378 # generate a test EC key and certificate
2381 if [ -s $name.key
-a -s $name.crt
-a -s $name.pem
]; then return; fi
2382 openssl ecparam
-name secp521r1
-out $name-ec.pem
>/dev
/null
2>&1
2383 chmod 0400 $name-ec.pem
2384 openssl req
-newkey ec
:$name-ec.pem
-keyout $name.key
-nodes -x509 -config $TESTCERT_CONF -out $name.crt
-days 3653 >/dev
/null
2>&1
2385 cat $name-ec.pem
$name.key
$name.crt
>$name.pem
2390 if [ -s $name.key
-a -s $name.crt
-a -s $name.pem
]; then return; fi
2391 cat $TESTCERT_CONF |
2392 { echo "# automatically generated by $0"; cat; } |
2393 sed 's/\(commonName\s*=\s*\).*/\1[::1]/' >$TESTCERT6_CONF
2394 openssl genrsa
$OPENSSL_RAND -out $name.key
$RSABITS >/dev
/null
2>&1
2395 openssl req
-new -config $TESTCERT6_CONF -key $name.key
-x509 -out $name.crt
-days 3653 >/dev
/null
2>&1
2396 cat $name.key
$name.crt
>$name.pem
2402 *%$N%*|
*%functions
%*|
*%stdio
%*|
*%$NAME%*)
2403 TEST
="$NAME: unidirectional throughput from stdin to stdout"
2404 testecho
"$N" "$TEST" "stdin" "stdout" "$opts -u"
2411 *%$N%*|
*%functions
%*|
*%stdio
%*|
*%$NAME%*)
2412 TEST
="$NAME: stdio with simple echo via internal pipe"
2413 testecho
"$N" "$TEST" "stdio" "pipe" "$opts"
2420 *%$N%*|
*%functions
%*|
*%stdio
%*|
*%$NAME%*)
2421 TEST
="$NAME: short form of stdio ('-') with simple echo via internal pipe"
2422 testecho
"$N" "$TEST" "-" "pipe" "$opts"
2429 *%$N%*|
*%functions
%*|
*%stdio
%*|
*%$NAME%*)
2430 TEST
="$NAME: splitted form of stdio ('stdin!!stdout') with simple echo via internal pipe"
2431 testecho
"$N" "$TEST" "stdin!!stdout" "pipe" "$opts"
2438 *%$N%*|
*%functions
%*|
*%stdio
%*|
*%$NAME%*)
2439 TEST
="$NAME: short splitted form of stdio ('-!!-') with simple echo via internal pipe"
2440 testecho
"$N" "$TEST" "-!!-" "pipe" "$opts"
2447 *%$N%*|
*%functions
%*|
*%fd
%*|
*%$NAME%*)
2448 TEST
="$NAME: file descriptors with simple echo via internal pipe"
2449 testecho
"$N" "$TEST" "0!!1" "pipe" "$opts"
2456 *%$N%*|
*%functions
%*|
*%pipe
%*|
*%$NAME%*)
2457 TEST
="$NAME: simple echo via named pipe"
2458 # with MacOS, this test hangs if nonblock is not used. Is an OS bug.
2460 # note: the nonblock is required by MacOS 10.1(?), otherwise it hangs (OS bug?)
2461 testecho
"$N" "$TEST" "" "pipe:$tp,nonblock" "$opts"
2468 *%$N%*|
*%functions
%*|
*%pipe
%*|
*%$NAME%*)
2469 TEST
="$NAME: simple echo via named pipe, specified twice"
2471 testecho
"$N" "$TEST" "" "pipe:$tp,nonblock!!pipe:$tp" "$opts"
2478 *%$N%*|
*%functions
%*|
*%engine
%*|
*%file%*|
*%ignoreeof
%*|
*%$NAME%*)
2479 TEST
="$NAME: simple echo via file"
2481 testecho
"$N" "$TEST" "" "$tf,ignoreeof!!$tf" "$opts"
2488 *%$N%*|
*%functions
%*|
*%exec%*|
*%$NAME%*)
2489 TEST
="$NAME: simple echo via exec of cat with socketpair"
2490 testecho
"$N" "$TEST" "" "exec:$CAT" "$opts"
2497 *%$N%*|
*%functions
%*|
*%system
%*|
*%$NAME%*)
2498 TEST
="$NAME: simple echo via system() of cat with socketpair"
2499 testecho
"$N" "$TEST" "" "system:$CAT" "$opts" "$val_t"
2506 *%$N%*|
*%functions
%*|
*%pipe
%*|
*%$NAME%*)
2507 TEST
="$NAME: simple echo via exec of cat with pipes"
2508 testecho
"$N" "$TEST" "" "exec:$CAT,pipes" "$opts"
2515 *%$N%*|
*%functions
%*|
*%pipes
%*|
*%$NAME%*)
2516 TEST
="$NAME: simple echo via system() of cat with pipes"
2517 testecho
"$N" "$TEST" "" "system:$CAT,pipes" "$opts"
2524 *%$N%*|
*%functions
%*|
*%exec%*|
*%pty
%*|
*%$NAME%*)
2525 TEST
="$NAME: simple echo via exec of cat with pseudo terminal"
2526 if ! eval $NUMCOND; then :;
2527 elif ! testaddrs pty
>/dev
/null
; then
2528 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2529 numCANT
=$
((numCANT
+1))
2531 testecho
"$N" "$TEST" "" "exec:$CAT,pty,$PTYOPTS" "$opts"
2539 *%$N%*|
*%functions
%*|
*%system
%*|
*%pty
%*|
*%$NAME%*)
2540 TEST
="$NAME: simple echo via system() of cat with pseudo terminal"
2541 if ! eval $NUMCOND; then :;
2542 elif ! testaddrs pty
>/dev
/null
; then
2543 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2544 numCANT
=$
((numCANT
+1))
2546 testecho
"$N" "$TEST" "" "system:$CAT,pty,$PTYOPTS" "$opts"
2554 *%$N%*|
*%functions
%*|
*%system
%*|
*%$NAME%*)
2555 TEST
="$NAME: simple echo via system() of cat with pipes, non stdio"
2556 testecho
"$N" "$TEST" "" "system:$CAT>&9 <&8,pipes,fdin=8,fdout=9" "$opts"
2563 *%$N%*|
*%functions
%*|
*%system
%*|
*%$NAME%*)
2564 TEST
="$NAME: echo via dual system() of cat"
2565 testecho
"$N" "$TEST" "system:$CAT>&6,fdout=6!!system:$CAT<&7,fdin=7" "" "$opts" "$val_t"
2570 # test: send EOF to exec'ed sub process, let it finish its operation, and
2571 # check if the sub process returns its data before terminating.
2572 NAME
=EXECSOCKETFLUSH
2573 # idea: have socat exec'ing od; send data and EOF, and check if the od'ed data
2576 *%$N%*|
*%functions
%*|
*%exec%*|
*%$NAME%*)
2577 TEST
="$NAME: call to od via exec with socketpair"
2578 testod
"$N" "$TEST" "" "exec:$OD_C" "$opts"
2583 NAME
=SYSTEMSOCKETFLUSH
2585 *%$N%*|
*%functions
%*|
*%system
%*|
*%$NAME%*)
2586 TEST
="$NAME: call to od via system() with socketpair"
2587 testod
"$N" "$TEST" "" "system:$OD_C" "$opts" $val_t
2594 *%$N%*|
*%functions
%*|
*%exec%*|
*%$NAME%*)
2595 TEST
="$NAME: call to od via exec with pipes"
2596 testod
"$N" "$TEST" "" "exec:$OD_C,pipes" "$opts"
2601 NAME
=SYSTEMPIPESFLUSH
2603 *%$N%*|
*%functions
%*|
*%system
%*|
*%$NAME%*)
2604 TEST
="$NAME: call to od via system() with pipes"
2605 testod
"$N" "$TEST" "" "system:$OD_C,pipes" "$opts" "$val_t"
2613 #*%$N%*|*%functions%*|*%exec%*|*%pty%*|*%$NAME%*)
2614 #TEST="$NAME: call to od via exec with pseudo terminal"
2615 #if ! testaddrs pty >/dev/null; then
2616 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2617 # numCANT=$((numCANT+1))
2619 #testod "$N" "$TEST" "" "exec:$OD_C,pty,$PTYOPTS" "$opts"
2626 #NAME=SYSTEMPTYFLUSH
2628 #*%$N%*|*%functions%*|*%system%*|*%pty%*|*%$NAME%*)
2629 #TEST="$NAME: call to od via system() with pseudo terminal"
2630 #if ! testaddrs pty >/dev/null; then
2631 # $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
2632 # numCANT=$((numCANT+1))
2634 #testod "$N" "$TEST" "" "system:$OD_C,pty,$PTYOPTS" "$opts"
2640 NAME
=SYSTEMPIPESFDSFLUSH
2642 *%$N%*|
*%functions
%*|
*%system
%*|
*%$NAME%*)
2643 TEST
="$NAME: call to od via system() with pipes, non stdio"
2644 testod
"$N" "$TEST" "" "system:$OD_C>&9 <&8,pipes,fdin=8,fdout=9" "$opts" "$val_t"
2649 NAME
=DUALSYSTEMFDSFLUSH
2651 *%$N%*|
*%functions
%*|
*%system
%*|
*%$NAME%*)
2652 TEST
="$NAME: call to od via dual system()"
2653 testod
"$N" "$TEST" "system:$OD_C>&6,fdout=6!!system:$CAT<&7,fdin=7" "pipe" "$opts" "$val_t"
2659 Linux
) IPPROTO
=254 ;;
2660 Darwin
) IPPROTO
=255 ;;
2661 *) IPPROTO
=254 ;; # just a guess
2666 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%rawip
%*|
*%root
%*|
*%$NAME%*)
2667 TEST
="$NAME: simple echo via self receiving raw IPv4 protocol"
2668 if ! eval $NUMCOND; then :;
2669 elif ! feat
=$
(testaddrs ip4
) ||
! runsip4
>/dev
/null
; then
2670 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2671 numCANT
=$
((numCANT
+1))
2672 elif ! feat
=$
(testaddrs rawip
) >/dev
/null
; then
2673 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2674 numCANT
=$
((numCANT
+1))
2675 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
2676 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2677 numCANT
=$
((numCANT
+1))
2679 testecho
"$N" "$TEST" "" "ip4:127.0.0.1:$IPPROTO" "$opts"
2686 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%rawip
%*|
*%root
%*|
*%$NAME%*)
2687 TEST
="$NAME: simple echo via self receiving raw IP protocol, v4 by target"
2688 if ! eval $NUMCOND; then :;
2689 elif ! feat
=$
(testaddrs ip4
) ||
! runsip4
>/dev
/null
; then
2690 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
2691 numCANT
=$
((numCANT
+1))
2692 elif ! feat
=$
(testaddrs rawip
) >/dev
/null
; then
2693 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2694 numCANT
=$
((numCANT
+1))
2695 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
2696 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2697 numCANT
=$
((numCANT
+1))
2699 testecho
"$N" "$TEST" "" "ip:127.0.0.1:$IPPROTO" "$opts"
2700 fi ;; # NUMCOND, feats
2706 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%rawip
%*|
*%root
%*|
*%$NAME%*)
2707 TEST
="$NAME: simple echo via self receiving raw IPv6 protocol"
2708 if ! eval $NUMCOND; then :;
2709 elif ! feat
=$
(testaddrs ip6
) ||
! runsip6
>/dev
/null
; then
2710 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2711 numCANT
=$
((numCANT
+1))
2712 elif ! feat
=$
(testaddrs rawip
) ||
! runsip6
>/dev
/null
; then
2713 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2714 numCANT
=$
((numCANT
+1))
2715 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
2716 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2717 numCANT
=$
((numCANT
+1))
2719 testecho
"$N" "$TEST" "" "ip6:[::1]:$IPPROTO" "$opts"
2720 fi ;; # NUMCOND, feats
2726 *%$N%*|
*%functions
%*|
*%ip
%*|
*%ip6
%*|
*%rawip
%*|
*%rawip6
%*|
*%root
%*|
*%$NAME%*)
2727 TEST
="$NAME: simple echo via self receiving raw IP protocol, v6 by target"
2728 if ! eval $NUMCOND; then :;
2729 elif ! feat
=$
(testaddrs ip6
) ||
! runsip6
>/dev
/null
; then
2730 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2731 numCANT
=$
((numCANT
+1))
2732 elif ! feat
=$
(testaddrs rawip
) ||
! runsip6
>/dev
/null
; then
2733 $PRINTF "test $F_n $TEST... ${YELLOW}RAWIP not available${NORMAL}\n" $N
2734 numCANT
=$
((numCANT
+1))
2735 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
2736 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
2737 numCANT
=$
((numCANT
+1))
2739 testecho
"$N" "$TEST" "" "ip:[::1]:$IPPROTO" "$opts"
2747 *%$N%*|
*%functions
%*|
*%$NAME%*)
2748 TEST
="$NAME: echo via self connection of TCP IPv4 socket"
2749 if ! eval $NUMCOND; then :;
2750 elif [ "$UNAME" != Linux
]; then
2751 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2752 numCANT
=$
((numCANT
+1))
2754 #ts="127.0.0.1:$tsl"
2755 testecho
"$N" "$TEST" "" "tcp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR,reuseaddr" "$opts"
2763 if ! eval $NUMCOND; then :; else
2765 *%$N%*|
*%functions
%*|
*%$NAME%*)
2766 TEST
="$NAME: echo via self connection of UDP IPv4 socket"
2767 if [ "$UNAME" != Linux
]; then
2768 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux$NORMAL\n" $N
2769 numCANT
=$
((numCANT
+1))
2771 testecho
"$N" "$TEST" "" "udp:$SECONDADDR:$PORT,sp=$PORT,bind=$SECONDADDR" "$opts"
2781 *%$N%*|
*%functions
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%$NAME%*)
2782 TEST
="$NAME: echo via self connection of UDP IPv6 socket"
2783 if ! eval $NUMCOND; then :;
2784 elif [ "$UNAME" != Linux
]; then
2785 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
2786 numCANT
=$
((numCANT
+1))
2787 elif ! testaddrs udp ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
2788 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
2789 numCANT
=$
((numCANT
+1))
2792 testecho
"$N" "$TEST" "" "udp6:[::1]:$PORT,sp=$PORT,bind=[::1]" "$opts"
2800 if ! eval $NUMCOND; then :; else
2802 *%$N%*|
*%functions
%*|
*%$NAME%*)
2803 TEST
="$NAME: echo via two unidirectional UDP IPv4 sockets"
2807 testecho
"$N" "$TEST" "" "udp:127.0.0.1:$p2,sp=$p1!!udp:127.0.0.1:$p1,sp=$p2" "$opts"
2814 #function testdual {
2820 if ! eval $NUMCOND; then :; else
2822 *%$N%*|
*%functions
%*|
*%unix
%*|
*%$NAME%*)
2823 TEST
="$NAME: echo via connection to UNIX domain socket"
2824 tf
="$td/test$N.stdout"
2825 te
="$td/test$N.stderr"
2826 ts
="$td/test$N.socket"
2827 tdiff
="$td/test$N.diff"
2828 da
="test$N $(date) $RANDOM"
2829 CMD1
="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
2830 CMD2
="$TRACE $SOCAT $opts -!!- UNIX-CONNECT:$ts"
2831 printf "test $F_n $TEST... " $N
2832 $CMD1 </dev
/null
>$tf 2>"${te}1" &
2833 bg=$
! # background process id
2835 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
2837 if [ "$rc2" -ne 0 ]; then
2838 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2844 numFAIL
=$
((numFAIL
+1))
2845 listFAIL
="$listFAIL $N"
2846 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
2847 $PRINTF "$FAILED: diff:\n"
2849 numFAIL
=$
((numFAIL
+1))
2850 listFAIL
="$listFAIL $N"
2853 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2856 kill $bg 2>/dev
/null
2863 if ! eval $NUMCOND; then :; else
2865 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
2866 TEST
="$NAME: echo via connection to TCP V4 socket"
2867 tf
="$td/test$N.stdout"
2868 te
="$td/test$N.stderr"
2869 tdiff
="$td/test$N.diff"
2872 da
="test$N $(date) $RANDOM"
2873 CMD1
="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
2874 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
2875 printf "test $F_n $TEST... " $N
2876 $CMD1 >"$tf" 2>"${te}1" &
2879 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
2880 if [ $?
-ne 0 ]; then
2881 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2886 numFAIL
=$
((numFAIL
+1))
2887 listFAIL
="$listFAIL $N"
2888 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
2891 numFAIL
=$
((numFAIL
+1))
2892 listFAIL
="$listFAIL $N"
2895 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2898 kill $pid1 2>/dev
/null
2909 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
2910 TEST
="$NAME: echo via connection to TCP V6 socket"
2911 if ! eval $NUMCOND; then :;
2912 elif ! testaddrs tcp ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
2913 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
2914 numCANT
=$
((numCANT
+1))
2916 tf
="$td/test$N.stdout"
2917 te
="$td/test$N.stderr"
2918 tdiff
="$td/test$N.diff"
2921 da
="test$N $(date) $RANDOM"
2922 CMD1
="$TRACE $SOCAT $opts TCP6-listen:$tsl,$REUSEADDR PIPE"
2923 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
2924 printf "test $F_n $TEST... " $N
2925 $CMD1 >"$tf" 2>"${te}1" &
2926 pid
=$
! # background process id
2928 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
2929 if [ $?
-ne 0 ]; then
2930 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2934 numFAIL
=$
((numFAIL
+1))
2935 listFAIL
="$listFAIL $N"
2936 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
2937 $PRINTF "$FAILED: diff:\n"
2939 numFAIL
=$
((numFAIL
+1))
2940 listFAIL
="$listFAIL $N"
2943 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2946 kill $pid 2>/dev
/null
2956 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
2957 TEST
="$NAME: echo via connection to TCP socket, v4 by target"
2958 if ! eval $NUMCOND; then :;
2959 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
2960 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
2961 numCANT
=$
((numCANT
+1))
2962 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
2963 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
2964 numCANT
=$
((numCANT
+1))
2966 tf
="$td/test$N.stdout"
2967 te
="$td/test$N.stderr"
2968 tdiff
="$td/test$N.diff"
2971 da
="test$N $(date) $RANDOM"
2972 CMD1
="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip4,$REUSEADDR PIPE"
2973 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
2974 printf "test $F_n $TEST... " $N
2975 $CMD1 >"$tf" 2>"${te}1" &
2976 pid
=$
! # background process id
2978 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
2979 if [ $?
-ne 0 ]; then
2980 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
2984 numFAIL
=$
((numFAIL
+1))
2985 listFAIL
="$listFAIL $N"
2986 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
2987 $PRINTF "$FAILED: diff:\n"
2989 numFAIL
=$
((numFAIL
+1))
2990 listFAIL
="$listFAIL $N"
2993 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
2996 kill $pid 2>/dev
/null
3005 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3006 TEST
="$NAME: echo via connection to TCP socket, v6 by target"
3007 if ! eval $NUMCOND; then :;
3008 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3009 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3010 numCANT
=$
((numCANT
+1))
3011 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3012 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3013 numCANT
=$
((numCANT
+1))
3015 tf
="$td/test$N.stdout"
3016 te
="$td/test$N.stderr"
3017 tdiff
="$td/test$N.diff"
3020 da
="test$N $(date) $RANDOM"
3021 CMD1
="$TRACE $SOCAT $opts TCP-listen:$tsl,pf=ip6,$REUSEADDR PIPE"
3022 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP:$ts"
3023 printf "test $F_n $TEST... " $N
3024 $CMD1 >"$tf" 2>"${te}1" &
3025 pid
=$
! # background process id
3027 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3028 if [ $?
-ne 0 ]; then
3029 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3033 numFAIL
=$
((numFAIL
+1))
3034 listFAIL
="$listFAIL $N"
3035 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3036 $PRINTF "$FAILED: diff:\n"
3038 numFAIL
=$
((numFAIL
+1))
3039 listFAIL
="$listFAIL $N"
3042 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3045 kill $pid 2>/dev
/null
3051 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
3052 # ipv6-v6only=0 shows this behaviour.
3055 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3056 TEST
="$NAME: option ipv6-v6only=0 listens on IPv4"
3057 # create a listening TCP6 socket and try to connect to the port using TCP4
3058 if ! eval $NUMCOND; then :;
3059 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3060 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3061 numCANT
=$
((numCANT
+1))
3062 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3063 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3064 numCANT
=$
((numCANT
+1))
3065 elif ! feat
=$
(testoptions ipv6-v6only
); then
3066 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3067 numCANT
=$
((numCANT
+1))
3069 tf
="$td/test$N.stdout"
3070 te
="$td/test$N.stderr"
3071 tdiff
="$td/test$N.diff"
3074 da
="test$N $(date) $RANDOM"
3075 CMD1
="$TRACE $SOCAT $opts TCP6-LISTEN:$tsl,ipv6-v6only=0,$REUSEADDR PIPE"
3076 CMD2
="$TRACE $SOCAT $opts STDIN!!STDOUT TCP4:$ts"
3077 printf "test $F_n $TEST... " $N
3078 $CMD1 >"$tf" 2>"${te}1" &
3079 pid
=$
! # background process id
3081 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3082 if [ $?
-ne 0 ]; then
3083 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3086 cat "${te}1" "${te}2"
3087 numFAIL
=$
((numFAIL
+1))
3088 listFAIL
="$listFAIL $N"
3089 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3090 $PRINTF "$FAILED: diff:\n"
3092 numFAIL
=$
((numFAIL
+1))
3093 listFAIL
="$listFAIL $N"
3096 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3099 kill $pid 2>/dev
/null
3106 # TCP6-LISTEN may also listen for IPv4 connections. Test if option
3107 # ipv6-v6only=1 turns off this behaviour.
3110 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3111 TEST
="$NAME: option ipv6-v6only=1 does not listen on IPv4"
3112 if ! eval $NUMCOND; then :;
3113 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3114 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3115 numCANT
=$
((numCANT
+1))
3116 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3117 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3118 numCANT
=$
((numCANT
+1))
3119 elif ! feat
=$
(testoptions ipv6-v6only
); then
3120 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3121 numCANT
=$
((numCANT
+1))
3123 tf
="$td/test$N.stdout"
3124 te
="$td/test$N.stderr"
3125 tdiff
="$td/test$N.diff"
3128 da
="test$N $(date) $RANDOM"
3129 CMD1
="$TRACE $SOCAT $opts TCP6-listen:$tsl,ipv6-v6only=1,$REUSEADDR PIPE"
3130 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3131 printf "test $F_n $TEST... " $N
3132 $CMD1 >"$tf" 2>"${te}1" &
3133 pid
=$
! # background process id
3135 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3136 if [ $?
-eq 0 ]; then
3137 $PRINTF "$FAILED:\n"
3138 cat "${te}1" "${te}2"
3139 numFAIL
=$
((numFAIL
+1))
3140 listFAIL
="$listFAIL $N"
3141 elif echo "$da" |
diff - "$tf" >"$tdiff"; then
3142 $PRINTF "$FAILED:\n"
3143 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3144 numFAIL
=$
((numFAIL
+1))
3145 listFAIL
="$listFAIL $N"
3160 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3161 TEST
="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv4 preference on listen"
3162 if ! eval $NUMCOND; then :;
3163 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3164 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3165 numCANT
=$
((numCANT
+1))
3166 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3167 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3168 numCANT
=$
((numCANT
+1))
3169 elif ! feat
=$
(testoptions ipv6-v6only
); then
3170 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3171 numCANT
=$
((numCANT
+1))
3173 tf
="$td/test$N.stdout"
3174 te
="$td/test$N.stderr"
3175 tdiff
="$td/test$N.diff"
3178 da
="test$N $(date) $RANDOM"
3179 CMD1
="$TRACE $SOCAT $opts TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3180 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3181 printf "test $F_n $TEST... " $N
3182 SOCAT_DEFAULT_LISTEN_IP
=4 $CMD1 >"$tf" 2>"${te}1" &
3183 pid
=$
! # background process id
3185 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3186 if [ $?
-ne 0 ]; then
3187 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3190 cat "${te}1" "${te}2"
3191 numFAIL
=$
((numFAIL
+1))
3192 listFAIL
="$listFAIL $N"
3193 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3194 $PRINTF "$FAILED: diff:\n"
3196 numFAIL
=$
((numFAIL
+1))
3197 listFAIL
="$listFAIL $N"
3200 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3203 kill $pid 2>/dev
/null
; wait
3211 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3212 TEST
="$NAME: env SOCAT_DEFAULT_LISTEN_IP for IPv6 preference on listen"
3213 if ! eval $NUMCOND; then :;
3214 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3215 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3216 numCANT
=$
((numCANT
+1))
3217 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3218 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3219 numCANT
=$
((numCANT
+1))
3221 tf
="$td/test$N.stdout"
3222 te
="$td/test$N.stderr"
3223 tdiff
="$td/test$N.diff"
3226 da
="test$N $(date) $RANDOM"
3227 CMD1
="$TRACE $SOCAT $opts TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3228 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3229 printf "test $F_n $TEST... " $N
3230 SOCAT_DEFAULT_LISTEN_IP
=6 $CMD1 >"$tf" 2>"${te}1" &
3231 pid
=$
! # background process id
3233 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3234 if [ $?
-ne 0 ]; then
3235 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3238 cat "${te}1" "${te}2"
3239 numFAIL
=$
((numFAIL
+1))
3240 listFAIL
="$listFAIL $N"
3241 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3242 $PRINTF "$FAILED: diff:\n"
3244 numFAIL
=$
((numFAIL
+1))
3245 listFAIL
="$listFAIL $N"
3248 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3251 kill $pid 2>/dev
/null
; wait
3257 NAME
=LISTEN_OPTION_4
3259 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3260 TEST
="$NAME: option -4 for IPv4 preference on listen"
3261 if ! eval $NUMCOND; then :;
3262 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3263 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3264 numCANT
=$
((numCANT
+1))
3265 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3266 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3267 numCANT
=$
((numCANT
+1))
3268 elif ! feat
=$
(testoptions ipv6-v6only
); then
3269 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3270 numCANT
=$
((numCANT
+1))
3272 tf
="$td/test$N.stdout"
3273 te
="$td/test$N.stderr"
3274 tdiff
="$td/test$N.diff"
3277 da
="test$N $(date) $RANDOM"
3278 CMD1
="$TRACE $SOCAT $opts -4 TCP-LISTEN:$tsl,$REUSEADDR PIPE"
3279 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3280 printf "test $F_n $TEST... " $N
3281 SOCAT_DEFAULT_LISTEN_IP
=6 $CMD1 >"$tf" 2>"${te}1" &
3282 pid
=$
! # background process id
3284 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3285 if [ $?
-ne 0 ]; then
3286 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3289 cat "${te}1" "${te}2"
3290 numFAIL
=$
((numFAIL
+1))
3291 listFAIL
="$listFAIL $N"
3292 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3293 $PRINTF "$FAILED: diff:\n"
3295 numFAIL
=$
((numFAIL
+1))
3296 listFAIL
="$listFAIL $N"
3299 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3302 kill $pid 2>/dev
/null
; wait
3308 NAME
=LISTEN_OPTION_6
3310 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3311 TEST
="$NAME: option -6 for IPv6 preference on listen"
3312 if ! eval $NUMCOND; then :;
3313 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3314 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3315 numCANT
=$
((numCANT
+1))
3316 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3317 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3318 numCANT
=$
((numCANT
+1))
3320 tf
="$td/test$N.stdout"
3321 te
="$td/test$N.stderr"
3322 tdiff
="$td/test$N.diff"
3325 da
="test$N $(date) $RANDOM"
3326 CMD1
="$TRACE $SOCAT $opts -6 TCP-listen:$tsl,$REUSEADDR PIPE"
3327 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3328 printf "test $F_n $TEST... " $N
3329 SOCAT_DEFAULT_LISTEN_IP
=4 $CMD1 >"$tf" 2>"${te}1" &
3330 pid
=$
! # background process id
3332 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3333 if [ $?
-ne 0 ]; then
3334 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3337 cat "${te}1" "${te}2"
3338 numFAIL
=$
((numFAIL
+1))
3339 listFAIL
="$listFAIL $N"
3340 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3341 $PRINTF "$FAILED: diff:\n"
3343 numFAIL
=$
((numFAIL
+1))
3344 listFAIL
="$listFAIL $N"
3347 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3350 kill $pid 2>/dev
/null
; wait
3359 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3360 TEST
="$NAME: pf=4 overrides option -6 on listen"
3361 if ! eval $NUMCOND; then :;
3362 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3363 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3364 numCANT
=$
((numCANT
+1))
3365 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3366 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3367 numCANT
=$
((numCANT
+1))
3368 elif ! feat
=$
(testoptions ipv6-v6only
); then
3369 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
3370 numCANT
=$
((numCANT
+1))
3372 tf
="$td/test$N.stdout"
3373 te
="$td/test$N.stderr"
3374 tdiff
="$td/test$N.diff"
3377 da
="test$N $(date) $RANDOM"
3378 CMD1
="$TRACE $SOCAT $opts -6 TCP-LISTEN:$tsl,pf=ip4,$REUSEADDR PIPE"
3379 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
3380 printf "test $F_n $TEST... " $N
3381 SOCAT_DEFAULT_LISTEN_IP
=6 $CMD1 >"$tf" 2>"${te}1" &
3382 pid
=$
! # background process id
3384 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3385 if [ $?
-ne 0 ]; then
3386 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3389 cat "${te}1" "${te}2"
3390 numFAIL
=$
((numFAIL
+1))
3391 listFAIL
="$listFAIL $N"
3392 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3393 $PRINTF "$FAILED: diff:\n"
3395 numFAIL
=$
((numFAIL
+1))
3396 listFAIL
="$listFAIL $N"
3399 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3402 kill $pid 2>/dev
/null
; wait
3410 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
3411 TEST
="$NAME: pf=6 overrides option -4 on listen"
3412 if ! eval $NUMCOND; then :;
3413 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
3414 $PRINTF "test $F_n $TEST... ${YELLOW}TCP4 not available${NORMAL}\n" $N
3415 numCANT
=$
((numCANT
+1))
3416 elif ! testaddrs ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
3417 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
3418 numCANT
=$
((numCANT
+1))
3420 tf
="$td/test$N.stdout"
3421 te
="$td/test$N.stderr"
3422 tdiff
="$td/test$N.diff"
3425 da
="test$N $(date) $RANDOM"
3426 CMD1
="$TRACE $SOCAT $opts -4 TCP-LISTEN:$tsl,pf=ip6,$REUSEADDR PIPE"
3427 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
3428 printf "test $F_n $TEST... " $N
3429 SOCAT_DEFAULT_LISTEN_IP
=4 $CMD1 >"$tf" 2>"${te}1" &
3430 pid
=$
! # background process id
3432 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3433 if [ $?
-ne 0 ]; then
3434 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3437 cat "${te}1" "${te}2"
3438 numFAIL
=$
((numFAIL
+1))
3439 listFAIL
="$listFAIL $N"
3440 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3441 $PRINTF "$FAILED: diff:\n"
3443 numFAIL
=$
((numFAIL
+1))
3444 listFAIL
="$listFAIL $N"
3447 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3450 kill $pid 2>/dev
/null
; wait
3451 fi ;; # NUMCOND, feats
3459 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%udp
%*|
*%$NAME%*)
3460 TEST
="$NAME: echo via connection to UDP V4 socket"
3461 if ! eval $NUMCOND; then :; else
3462 tf
="$td/test$N.stdout"
3463 te
="$td/test$N.stderr"
3464 tdiff
="$td/test$N.diff"
3466 ts
="$LOCALHOST:$tsl"
3467 da
="test$N $(date) $RANDOM"
3468 CMD1
="$TRACE $SOCAT $opts UDP4-LISTEN:$tsl,$REUSEADDR PIPE"
3469 CMD2
="$TRACE $SOCAT $opts - UDP4:$ts"
3470 printf "test $F_n $TEST... " $N
3471 $CMD1 >"$tf" 2>"${te}1" &
3474 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3476 kill $pid1 2>/dev
/null
; wait
3477 if [ $rc2 -ne 0 ]; then
3478 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3481 cat "${te}1" "${te}2"
3482 numFAIL
=$
((numFAIL
+1))
3483 listFAIL
="$listFAIL $N"
3484 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3491 numFAIL
=$
((numFAIL
+1))
3492 listFAIL
="$listFAIL $N"
3495 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3506 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%udp
%*|
*%$NAME%*)
3507 TEST
="$NAME: echo via connection to UDP V6 socket"
3508 if ! eval $NUMCOND; then :;
3509 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
3510 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
3511 numCANT
=$
((numCANT
+1))
3513 tf
="$td/test$N.stdout"
3514 te
="$td/test$N.stderr"
3515 tdiff
="$td/test$N.diff"
3517 ts
="$LOCALHOST6:$tsl"
3518 da
="test$N $(date) $RANDOM"
3519 CMD1
="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,$REUSEADDR PIPE"
3520 CMD2
="$TRACE $SOCAT $opts - UDP6:$ts"
3521 printf "test $F_n $TEST... " $N
3522 $CMD1 >"$tf" 2>"${te}1" &
3525 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
3527 kill $pid1 2>/dev
/null
; wait
3528 if [ $rc2 -ne 0 ]; then
3529 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3532 cat "${te}1" "${te}2"
3533 numFAIL
=$
((numFAIL
+1))
3534 listFAIL
="$listFAIL $N"
3535 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3538 numFAIL
=$
((numFAIL
+1))
3539 listFAIL
="$listFAIL $N"
3542 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3553 *%$N%*|
*%functions
%*|
*%engine
%*|
*%gopen
%*|
*%file%*|
*%ignoreeof
%*|
*%$NAME%*)
3554 TEST
="$NAME: file opening with gopen"
3555 if ! eval $NUMCOND; then :; else
3556 tf1
="$td/test$N.1.stdout"
3557 tf2
="$td/test$N.2.stdout"
3558 te
="$td/test$N.stderr"
3559 tdiff
="$td/test$N.diff"
3560 da
="test$N $(date) $RANDOM"
3562 CMD
="$TRACE $SOCAT $opts $tf1!!/dev/null /dev/null,ignoreeof!!-"
3563 printf "test $F_n $TEST... " $N
3564 $CMD >"$tf2" 2>"$te"
3565 if [ $?
-ne 0 ]; then
3566 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3569 numFAIL
=$
((numFAIL
+1))
3570 listFAIL
="$listFAIL $N"
3571 elif ! diff "$tf1" "$tf2" >"$tdiff"; then
3572 $PRINTF "$FAILED: diff:\n"
3574 numFAIL
=$
((numFAIL
+1))
3575 listFAIL
="$listFAIL $N"
3578 if [ -n "$debug" ]; then cat $te; fi
3588 *%$N%*|
*%functions
%*|
*%gopen
%*|
*%pipe
%*|
*%ignoreeof
%*|
*%$NAME%*)
3589 TEST
="$NAME: pipe opening with gopen for reading"
3590 if ! eval $NUMCOND; then :; else
3592 tf
="$td/test$N.stdout"
3593 te
="$td/test$N.stderr"
3594 tdiff
="$td/test$N.diff"
3595 da
="test$N $(date) $RANDOM"
3596 CMD
="$TRACE $SOCAT $opts $tp!!/dev/null /dev/null,ignoreeof!!$tf"
3597 printf "test $F_n $TEST... " $N
3598 #mknod $tp p # no mknod p on FreeBSD
3601 #($CMD >$tf 2>"$te" || rm -f "$tp") 2>/dev/null &
3602 bg=$
! # background process id
3604 if [ ! -p "$tp" ]; then
3605 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3608 numFAIL
=$
((numFAIL
+1))
3609 listFAIL
="$listFAIL $N"
3611 #echo "$da" >"$tp" # might hang forever
3612 echo "$da" >"$tp" & export pid
=$
!; (sleep 1; kill $pid 2>/dev
/null
) &
3613 # Solaris needs more time:
3615 kill "$bg" 2>/dev
/null
; wait
3616 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3617 if [ -s "$te" ]; then
3618 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3622 $PRINTF "$FAILED: diff:\n"
3625 numFAIL
=$
((numFAIL
+1))
3626 listFAIL
="$listFAIL $N"
3629 if [ -n "$debug" ]; then cat $te; fi
3639 NAME
=GOPENUNIXSTREAM
3641 *%$N%*|
*%functions
%*|
*%gopen
%*|
*%unix
%*|
*%listen
%*|
*%$NAME%*)
3642 TEST
="$NAME: GOPEN on UNIX stream socket"
3643 if ! eval $NUMCOND; then :; else
3644 ts
="$td/test$N.socket"
3645 tf
="$td/test$N.stdout"
3646 te
="$td/test$N.stderr"
3647 tdiff
="$td/test$N.diff"
3648 da1
="test$N $(date) $RANDOM"
3649 #establish a listening unix socket in background
3650 SRV
="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
3652 CMD
="$TRACE $SOCAT $opts - $ts"
3653 $PRINTF "test $F_n $TEST... " $N
3654 eval "$SRV 2>${te}s &"
3657 echo "$da1" |
eval "$CMD" >"${tf}1" 2>"${te}1"
3658 if [ $?
-ne 0 ]; then
3659 kill "$pids" 2>/dev
/null
3660 $PRINTF "$FAILED:\n"
3665 numFAIL
=$
((numFAIL
+1))
3666 listFAIL
="$listFAIL $N"
3667 elif ! echo "$da1" |
diff - "${tf}1" >"$tdiff"; then
3668 kill "$pids" 2>/dev
/null
3669 $PRINTF "$FAILED:\n"
3675 numFAIL
=$
((numFAIL
+1))
3676 listFAIL
="$listFAIL $N"
3679 if [ -n "$debug" ]; then cat $te; fi
3690 *%$N%*|
*%functions
%*|
*%gopen
%*|
*%unix
%*|
*%dgram
%*|
*%$NAME%*)
3691 TEST
="$NAME: GOPEN on UNIX datagram socket"
3692 if ! eval $NUMCOND; then :; else
3693 ts
="$td/test$N.socket"
3694 tf
="$td/test$N.stdout"
3695 te
="$td/test$N.stderr"
3696 tdiff
="$td/test$N.diff"
3697 da1
="test$N $(date) $RANDOM"
3698 #establish a receiving unix socket in background
3699 SRV
="$TRACE $SOCAT $opts -u -lpserver UNIX-RECV:\"$ts\" file:\"$tf\",create"
3701 CMD
="$TRACE $SOCAT $opts -u - $ts"
3702 $PRINTF "test $F_n $TEST... " $N
3703 eval "$SRV 2>${te}s &"
3706 echo "$da1" |
eval "$CMD" 2>"${te}1"
3708 if [ $?
-ne 0 ]; then
3709 $PRINTF "$FAILED:\n"
3714 numFAIL
=$
((numFAIL
+1))
3715 listFAIL
="$listFAIL $N"
3716 elif ! echo "$da1" |
diff - "${tf}" >"$tdiff"; then
3717 $PRINTF "$FAILED:\n"
3723 numFAIL
=$
((numFAIL
+1))
3724 listFAIL
="$listFAIL $N"
3727 if [ -n "$debug" ]; then cat $te; fi
3730 kill "$pids" 2>/dev
/null
; wait
3738 *%$N%*|
*%functions
%*|
*%engine
%*|
*%ignoreeof
%*|
*%$NAME%*)
3739 TEST
="$NAME: ignoreeof on file"
3740 if ! eval $NUMCOND; then :; else
3741 ti
="$td/test$N.file"
3742 tf
="$td/test$N.stdout"
3743 te
="$td/test$N.stderr"
3744 tdiff
="$td/test$N.diff"
3745 da
="test$N $(date) $RANDOM"
3746 CMD
="$TRACE $SOCAT $opts -u file:\"$ti\",ignoreeof -"
3747 printf "test $F_n $TEST... " $N
3749 $CMD >"$tf" 2>"$te" &
3754 kill $bg 2>/dev
/null
; wait
3755 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3756 $PRINTF "$FAILED: diff:\n"
3758 listFAIL
="$listFAIL $N"
3759 numFAIL
=$
((numFAIL
+1))
3762 if [ -n "$debug" ]; then cat $te; fi
3771 *%$N%*|
*%functions
%*|
*%engine
%*|
*%ignoreeof
%*|
*%$NAME%*)
3772 TEST
="$NAME: ignoreeof on file right-to-left"
3773 if ! eval $NUMCOND; then :; else
3774 ti
="$td/test$N.file"
3775 tf
="$td/test$N.stdout"
3776 te
="$td/test$N.stderr"
3777 tdiff
="$td/test$N.diff"
3778 da
="test$N $(date) $RANDOM"
3779 CMD
="$SOCAT $opts -U - file:\"$ti\",ignoreeof"
3780 printf "test $F_n $TEST... " $N
3782 $CMD >"$tf" 2>"$te" &
3787 kill $bg 2>/dev
/null
3788 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3789 $PRINTF "$FAILED: diff:\n"
3791 listFAIL
="$listFAIL $N"
3792 numFAIL
=$
((numFAIL
+1))
3795 if [ -n "$debug" ]; then cat $te; fi
3806 *%$N%*|
*%functions
%*|
*%engine
%*|
*%ignoreeof
%*|
*%$NAME%*)
3807 TEST
="$NAME: exec against address with ignoreeof"
3808 if ! eval $NUMCOND; then :; else
3809 tf
="$td/test$N.stdout"
3810 te
="$td/test$N.stderr"
3811 CMD
="$TRACE $SOCAT $opts -lf /dev/null EXEC:$TRUE /dev/null,ignoreeof"
3812 printf "test $F_n $TEST... " $N
3814 if [ -s "$te" ]; then
3815 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3818 numFAIL
=$
((numFAIL
+1))
3819 listFAIL
="$listFAIL $N"
3822 if [ -n "$debug" ]; then cat $te; fi
3832 *%$N%*|
*%functions
%*|
*%pty
%*|
*%$NAME%*)
3833 TEST
="$NAME: generation of pty for other processes"
3834 if ! eval $NUMCOND; then :;
3835 elif ! testaddrs pty
>/dev
/null
; then
3836 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
3837 numCANT
=$
((numCANT
+1))
3840 tf
="$td/test$N.stdout"
3841 te
="$td/test$N.stderr"
3842 tdiff
="$td/test$N.diff"
3843 da
="test$N $(date) $RANDOM"
3844 CMD1
="$TRACE $SOCAT $opts pty,link=$tt pipe"
3845 CMD2
="$TRACE $SOCAT $opts - $tt,$PTYOPTS2"
3846 printf "test $F_n $TEST... " $N
3848 pid
=$
! # background process id
3850 # this hangs on HP-UX, so we use a timeout
3851 (echo "$da"; sleep 1) |
$CMD2 >$tf 2>"${te}2" &
3853 #sleep 5 && kill $rc2 2>/dev/null &
3855 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
3856 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3863 numFAIL
=$
((numFAIL
+1))
3864 listFAIL
="$listFAIL $N"
3867 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
3870 kill $pid 2>/dev
/null
; wait
3871 fi ;; # NUMCOND, feats
3878 *%$N%*|
*%functions
%*|
*%$NAME%*)
3879 TEST
="$NAME: option o-trunc"
3880 if ! eval $NUMCOND; then :; else
3881 ff
="$td/test$N.file"
3882 tf
="$td/test$N.stdout"
3883 te
="$td/test$N.stderr"
3884 tdiff
="$td/test$N.diff"
3885 da
="test$N $(date) $RANDOM"
3886 CMD
="$TRACE $SOCAT -u $opts - open:$ff,append,o-trunc"
3887 printf "test $F_n $TEST... " $N
3888 rm -f $ff; $ECHO "prefix-\c" >$ff
3889 echo "$da" |
$CMD >$tf 2>"$te"
3891 if ! [ $rc0 = 0 ] ||
3892 ! echo "$da" |
diff - $ff >"$tdiff"; then
3893 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3897 numFAIL
=$
((numFAIL
+1))
3898 listFAIL
="$listFAIL $N"
3901 if [ -n "$debug" ]; then cat $te; fi
3911 *%$N%*|
*%functions
%*|
*%$NAME%*)
3912 TEST
="$NAME: option ftruncate"
3913 if ! eval $NUMCOND; then :; else
3914 ff
="$td/test$N.file"
3915 tf
="$td/test$N.stdout"
3916 te
="$td/test$N.stderr"
3917 tdiff
="$td/test$N.diff"
3918 da
="test$N $(date) $RANDOM"
3919 CMD
="$TRACE $SOCAT -u $opts - open:$ff,append,ftruncate=0"
3920 printf "test $F_n $TEST... " $N
3921 rm -f $ff; $ECHO "prefix-\c" >$ff
3922 if ! echo "$da" |
$CMD >$tf 2>"$te" ||
3923 ! echo "$da" |
diff - $ff >"$tdiff"; then
3924 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
3928 numFAIL
=$
((numFAIL
+1))
3929 listFAIL
="$listFAIL $N"
3932 if [ -n "$debug" ]; then cat $te; fi
3942 *%$N%*|
*%functions
%*|
*%$NAME%*)
3943 TEST
="$NAME: unidirectional throughput from stdin to stdout, right to left"
3944 testecho
"$N" "$TEST" "stdout" "stdin" "$opts -U"
3951 *%$N%*|
*%functions
%*|
*%$NAME%*)
3952 if ! eval $NUMCOND; then :; else
3953 TEST
="$NAME: child process default properties"
3954 tf
="$td/test$N.stdout"
3955 te
="$td/test$N.stderr"
3956 CMD
="$TRACE $SOCAT $opts -u exec:$PROCAN -"
3957 printf "test $F_n $TEST... " $N
3959 MYPID
=`expr "\`grep "process id =" $tf\
`" : '[^0-9]*\([0-9]*\).*'`
3960 MYPPID
=`expr "\`grep "process parent id =" $tf\
`" : '[^0-9]*\([0-9]*\).*'`
3961 MYPGID
=`expr "\`grep "process group id =" $tf\
`" : '[^0-9]*\([0-9]*\).*'`
3962 MYSID
=`expr "\`grep "process session id =" $tf\
`" : '[^0-9]*\([0-9]*\).*'`
3963 #echo "PID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3964 if [ "$MYPID" = "$MYPPID" -o "$MYPID" = "$MYPGID" -o "$MYPID" = "$MYSID" -o \
3965 "$MYPPID" = "$MYPGID" -o "$MYPPID" = "$MYSID" -o "$MYPGID" = "$MYSID" ];
3967 $PRINTF "$FAILED:\n"
3970 numFAIL
=$
((numFAIL
+1))
3971 listFAIL
="$listFAIL $N"
3983 *%$N%*|
*%functions
%*|
*%$NAME%*)
3984 TEST
="$NAME: child process with setsid"
3985 if ! eval $NUMCOND; then :; else
3986 tf
="$td/test$N.stdout"
3987 te
="$td/test$N.stderr"
3988 CMD
="$TRACE $SOCAT $opts -u exec:$PROCAN,setsid -"
3989 printf "test $F_n $TEST... " $N
3991 MYPID
=`grep "process id =" $tf |(expr "\`cat\
`" : '[^0-9]*\([0-9]*\).*')`
3992 MYPPID
=`grep "process parent id =" $tf |(expr "\`cat\
`" : '[^0-9]*\([0-9]*\).*')`
3993 MYPGID
=`grep "process group id =" $tf |(expr "\`cat\
`" : '[^0-9]*\([0-9]*\).*')`
3994 MYSID
=`grep "process session id =" $tf |(expr "\`cat\
`" : '[^0-9]*\([0-9]*\).*')`
3995 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
3996 # PID, PGID, and SID must be the same
3997 if [ "$MYPID" = "$MYPPID" -o \
3998 "$MYPID" != "$MYPGID" -o "$MYPID" != "$MYSID" ];
4003 numFAIL
=$
((numFAIL
+1))
4004 listFAIL
="$listFAIL $N"
4016 *%$N%*|
*%functions
%*|
*%$NAME%*)
4017 TEST
="$NAME: main process with setsid"
4018 if ! eval $NUMCOND; then :; else
4019 tf
="$td/test$N.stdout"
4020 te
="$td/test$N.stderr"
4021 CMD
="$TRACE $SOCAT $opts -U -,setsid exec:$PROCAN"
4022 printf "test $F_n $TEST... " $N
4024 MYPID
=`grep "process id =" $tf |(expr "\`cat\
`" : '[^0-9]*\([0-9]*\).*')`
4025 MYPPID
=`grep "process parent id =" $tf |(expr "\`cat\
`" : '[^0-9]*\([0-9]*\).*')`
4026 MYPGID
=`grep "process group id =" $tf |(expr "\`cat\
`" : '[^0-9]*\([0-9]*\).*')`
4027 MYSID
=`grep "process session id =" $tf |(expr "\`cat\
`" : '[^0-9]*\([0-9]*\).*')`
4028 #$ECHO "\nPID=$MYPID, PPID=$MYPPID, PGID=$MYPGID, SID=$MYSID"
4029 # PPID, PGID, and SID must be the same
4030 if [ "$MYPID" = "$MYPPID" -o \
4031 "$MYPPID" != "$MYPGID" -o "$MYPPID" != "$MYSID" ];
4036 numFAIL
=$
((numFAIL
+1))
4037 listFAIL
="$listFAIL $N"
4049 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4050 TEST
="$NAME: openssl connect"
4051 if ! eval $NUMCOND; then :;
4052 elif ! testaddrs openssl
>/dev
/null
; then
4053 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4054 numCANT
=$
((numCANT
+1))
4055 elif ! type openssl
>/dev
/null
2>&1; then
4056 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
4057 numCANT
=$
((numCANT
+1))
4058 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4059 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4060 numCANT
=$
((numCANT
+1))
4063 tf
="$td/test$N.stdout"
4064 te
="$td/test$N.stderr"
4065 tdiff
="$td/test$N.diff"
4066 da
="test$N $(date) $RANDOM"
4067 CMD2
="$TRACE $SOCAT $opts exec:'openssl s_server -accept "$PORT" -quiet -cert testsrv.pem' pipe"
4068 #! CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT"
4069 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
4070 printf "test $F_n $TEST... " $N
4071 eval "$CMD2 2>\"${te}1\" &"
4072 pid
=$
! # background process id
4073 # this might timeout when openssl opens tcp46 port like " :::$PORT"
4075 echo "$da" |
$CMD >$tf 2>"${te}2"
4076 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4077 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4083 numFAIL
=$
((numFAIL
+1))
4084 listFAIL
="$listFAIL $N"
4087 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4090 kill $pid 2>/dev
/null
; wait
4091 fi ;; # NUMCOND, feats
4097 NAME
=OPENSSLLISTEN_TCP4
4099 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4100 TEST
="$NAME: openssl listen"
4101 if ! eval $NUMCOND; then :;
4102 elif ! testaddrs openssl
>/dev
/null
; then
4103 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4104 numCANT
=$
((numCANT
+1))
4105 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4106 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4107 numCANT
=$
((numCANT
+1))
4110 tf
="$td/test$N.stdout"
4111 te
="$td/test$N.stderr"
4112 tdiff
="$td/test$N.diff"
4113 da
="test$N $(date) $RANDOM"
4114 CMD2
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4115 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
4116 printf "test $F_n $TEST... " $N
4117 eval "$CMD2 2>\"${te}1\" &"
4118 pid
=$
! # background process id
4120 echo "$da" |
$CMD >$tf 2>"${te}2"
4121 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4122 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4128 numFAIL
=$
((numFAIL
+1))
4129 listFAIL
="$listFAIL $N"
4132 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4135 kill $pid 2>/dev
/null
4137 fi ;; # NUMCOND, feats
4142 NAME
=OPENSSLLISTEN_TCP6
4144 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%$NAME%*)
4145 TEST
="$NAME: openssl listen"
4146 if ! eval $NUMCOND; then :;
4147 elif ! testaddrs openssl
>/dev
/null
; then
4148 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4149 numCANT
=$
((numCANT
+1))
4150 elif ! testaddrs listen tcp ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
4151 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4152 numCANT
=$
((numCANT
+1))
4155 tf
="$td/test$N.stdout"
4156 te
="$td/test$N.stderr"
4157 tdiff
="$td/test$N.diff"
4158 da
="test$N $(date) $RANDOM"
4159 CMD2
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4160 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST6:$PORT,verify=0,$SOCAT_EGD"
4161 printf "test $F_n $TEST... " $N
4162 eval "$CMD2 2>\"${te}1\" &"
4163 pid
=$
! # background process id
4165 echo "$da" |
$CMD >$tf 2>"${te}2"
4166 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4167 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4173 numFAIL
=$
((numFAIL
+1))
4174 listFAIL
="$listFAIL $N"
4177 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4180 kill $pid 2>/dev
/null
4182 fi ;; # NUMCOND, feats
4188 while read NAMEKEYW FEAT RUNS TESTTMPL PEERTMPL WAITTMPL
; do
4189 if [ -z "$NAMEKEYW" ] ||
[[ "$NAMEKEYW" == \
#* ]]; then continue; fi
4191 export ts
="$td/test$N.socket"
4192 WAITTMPL
="$(echo "$WAITTMPL" |sed -e 's/\040/ /g')"
4193 TESTADDR
=$
(eval echo $TESTTMPL)
4194 PEERADDR
=$
(eval echo $PEERTMPL)
4195 WAITCMD
=$
(eval echo $WAITTMPL)
4196 TESTKEYW
=${TESTADDR%%:*}
4198 # does our address implementation support halfclose?
4199 NAME
=${NAMEKEYW}_HALFCLOSE
4201 *%$N%*|
*%functions
%*|
*%$FEAT%*|
*%socket
%*|
*%halfclose
%*|
*%$NAME%*)
4202 TEST
="$NAME: $TESTKEYW half close"
4203 # have a "peer" socat "peer" that executes "$OD_C" and see if EOF on the
4204 # connecting socat brings the result of od
4205 if ! eval $NUMCOND; then :;
4206 elif [ "$FEAT" != ',' ] && ! testaddrs
"$FEAT" >/dev
/null
; then
4207 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
4208 numCANT
=$
((numCANT
+1))
4209 elif ! runs
$RUNS; then
4210 $PRINTF "test $F_n $TEST... ${YELLOW}$RUNS not available${NORMAL}\n" $N
4211 numCANT
=$
((numCANT
+1))
4213 tf
="$td/test$N.stdout"
4214 te
="$td/test$N.stderr"
4215 tdiff
="$td/test$N.diff"
4216 da
="test$N $(date) $RANDOM"
4217 CMD2
="$TRACE $SOCAT $opts \"$PEERADDR\" EXEC:'$OD_C'"
4218 CMD
="$TRACE $SOCAT -T1 $opts - $TESTADDR"
4219 printf "test $F_n $TEST... " $N
4220 eval "$CMD2 2>\"${te}1\" &"
4221 pid
=$
! # background process id
4223 echo "$da" |
$CMD >$tf 2>"${te}2"
4224 if ! echo "$da" |
$OD_C |
diff - "$tf" >"$tdiff"; then
4225 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4231 numFAIL
=$
((numFAIL
+1))
4232 listFAIL
="$listFAIL $N"
4235 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4238 kill $pid 2>/dev
/null
4240 fi ;; # NUMCOND, feats
4246 UNIXCONNECT , unix UNIX-CONNECT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4247 UNIXCLIENT , unix UNIX-CLIENT:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4248 GOPEN_UNIXSTREAM , unix GOPEN:\$ts UNIX-LISTEN:\$ts waitfile\040\$ts
4249 UNIXLISTEN , unix UNIX-LISTEN:\$ts UNIX-CONNECT:\$ts,retry=3 sleep\040\1
4250 TCP4CONNECT , tcp4 TCP4-CONNECT:\$LOCALHOST:\$PORT TCP4-LISTEN:\$PORT,$REUSEADDR waittcp4port\040\$PORT
4251 TCP4LISTEN , tcp4 TCP4-LISTEN:\$PORT,$REUSEADDR TCP4-CONNECT:\$LOCALHOST:\$PORT,retry=3
4252 TCP6CONNECT , tcp6 TCP6-CONNECT:\$LOCALHOST6:\$PORT TCP6-LISTEN:\$PORT,$REUSEADDR waittcp6port\040\$PORT
4253 TCP6LISTEN , tcp6 TCP6-LISTEN:\$PORT,$REUSEADDR TCP6-CONNECT:\$LOCALHOST6:\$PORT,retry=3
4254 OPENSSL4CLIENT OPENSSL tcp4 OPENSSL:\$LOCALHOST:\$PORT,verify=0 OPENSSL-LISTEN:\$PORT,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp4port\040\$PORT
4255 OPENSSL4SERVER OPENSSL tcp4 OPENSSL-LISTEN:\$PORT,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST:\$PORT,$REUSEADDR,verify=0,retry=3
4256 OPENSSL6CLIENT OPENSSL tcp6 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,verify=0 OPENSSL-LISTEN:\$PORT,pf=ip6,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 waittcp6port\040\$PORT
4257 OPENSSL6SERVER OPENSSL tcp6 OPENSSL-LISTEN:\$PORT,pf=ip6,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 OPENSSL:\$LOCALHOST6:\$PORT,pf=ip6,$REUSEADDR,verify=0,retry=3
4261 NAME
=OPENSSL_SERVERAUTH
4263 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4264 TEST
="$NAME: openssl server authentication"
4265 if ! eval $NUMCOND; then :;
4266 elif ! testaddrs openssl
>/dev
/null
; then
4267 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4268 numCANT
=$
((numCANT
+1))
4269 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4270 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4271 numCANT
=$
((numCANT
+1))
4275 tf
="$td/test$N.stdout"
4276 te
="$td/test$N.stderr"
4277 tdiff
="$td/test$N.diff"
4278 da
="test$N $(date) $RANDOM"
4279 CMD2
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe"
4280 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=1,cafile=testsrv.crt,$SOCAT_EGD"
4281 printf "test $F_n $TEST... " $N
4282 eval "$CMD2 2>\"${te}1\" &"
4283 pid
=$
! # background process id
4285 echo "$da" |
$CMD >$tf 2>"${te}2"
4286 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4287 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4293 numFAIL
=$
((numFAIL
+1))
4294 listFAIL
="$listFAIL $N"
4297 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4300 kill $pid 2>/dev
/null
4302 fi ;; # NUMCOND, feats
4307 NAME
=OPENSSL_CLIENTAUTH
4309 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4310 TEST
="$NAME: openssl client authentication"
4311 if ! eval $NUMCOND; then :;
4312 elif ! testaddrs openssl
>/dev
/null
; then
4313 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4314 numCANT
=$
((numCANT
+1))
4315 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4316 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4317 numCANT
=$
((numCANT
+1))
4321 tf
="$td/test$N.stdout"
4322 te
="$td/test$N.stderr"
4323 tdiff
="$td/test$N.diff"
4324 da
="test$N $(date) $RANDOM"
4325 CMD2
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,verify=1,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt,$SOCAT_EGD pipe"
4326 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=0,cert=testcli.crt,key=testcli.key,$SOCAT_EGD"
4327 printf "test $F_n $TEST... " $N
4328 eval "$CMD2 2>\"${te}1\" &"
4329 pid
=$
! # background process id
4331 echo "$da" |
$CMD >$tf 2>"${te}2"
4332 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4333 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4339 numFAIL
=$
((numFAIL
+1))
4340 listFAIL
="$listFAIL $N"
4343 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4346 kill $pid 2>/dev
/null
4348 fi ;; # NUMCOND, feats
4353 NAME
=OPENSSL_FIPS_BOTHAUTH
4355 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%fips
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4356 TEST
="$NAME: OpenSSL+FIPS client and server authentication"
4357 if ! eval $NUMCOND; then :;
4358 elif ! testaddrs openssl
>/dev
/null
; then
4359 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4360 numCANT
=$
((numCANT
+1))
4361 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4362 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4363 numCANT
=$
((numCANT
+1))
4364 elif ! testoptions fips
>/dev
/null
; then
4365 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
4366 numCANT
=$
((numCANT
+1))
4368 OPENSSL_FIPS
=1 gentestcert testsrvfips
4369 OPENSSL_FIPS
=1 gentestcert testclifips
4370 tf
="$td/test$N.stdout"
4371 te
="$td/test$N.stderr"
4372 tdiff
="$td/test$N.diff"
4373 da
="test$N $(date) $RANDOM"
4374 CMD2
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,fips,$SOCAT_EGD,cert=testsrvfips.crt,key=testsrvfips.key,cafile=testclifips.crt pipe"
4375 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,fips,verify=1,cert=testclifips.crt,key=testclifips.key,cafile=testsrvfips.crt,$SOCAT_EGD"
4376 printf "test $F_n $TEST... " $N
4377 eval "$CMD2 2>\"${te}1\" &"
4378 pid
=$
! # background process id
4380 echo "$da" |
$CMD >$tf 2>"${te}2"
4381 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4382 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4388 numFAIL
=$
((numFAIL
+1))
4389 listFAIL
="$listFAIL $N"
4392 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4395 kill $pid 2>/dev
/null
4397 fi ;; # NUMCOND, feats
4403 NAME
=OPENSSL_COMPRESS
4405 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4406 TEST
="$NAME: OpenSSL compression"
4407 if ! eval $NUMCOND; then :;
4408 elif ! testaddrs openssl
>/dev
/null
; then
4409 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
4410 numCANT
=$
((numCANT
+1))
4411 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4412 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4413 numCANT
=$
((numCANT
+1))
4414 elif ! testoptions openssl-compress
>/dev
/null
; then
4415 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL compression option not available${NORMAL}\n" $N
4416 numCANT
=$
((numCANT
+1))
4419 printf "test $F_n $TEST... " $N
4420 tf
="$td/test$N.stdout"
4421 te
="$td/test$N.stderr"
4422 tdiff
="$td/test$N.diff"
4423 da
="test$N $(date) $RANDOM"
4425 for srccompr
in '' compress=auto
compress=none
; do
4426 for dstcompr
in '' compress=auto
compress=none
; do
4427 CMD2
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0,$dstcompr pipe"
4428 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD,$srccompr"
4429 eval "$CMD2 2>\"${te}1\" &"
4430 pid
=$
! # background process id
4432 echo "$da" |
$CMD >$tf 2>"${te}2"
4433 kill $pid 2>/dev
/null
4434 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4440 if test -z "$success"; then
4441 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4447 numFAIL
=$
((numFAIL
+1))
4448 listFAIL
="$listFAIL $N"
4451 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4454 fi ;; # NUMCOND, feats
4460 NAME
=SOCKS4CONNECT_TCP4
4462 *%$N%*|
*%functions
%*|
*%socks
%*|
*%socks4
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4463 TEST
="$NAME: socks4 connect over TCP/IPv4"
4464 if ! eval $NUMCOND; then :;
4465 elif ! testaddrs socks4
>/dev
/null
; then
4466 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4467 numCANT
=$
((numCANT
+1))
4468 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4469 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4470 numCANT
=$
((numCANT
+1))
4472 tf
="$td/test$N.stdout"
4473 te
="$td/test$N.stderr"
4474 tdiff
="$td/test$N.diff"
4475 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
4476 # we have a normal tcp echo listening - so the socks header must appear in answer
4477 CMD2
="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR exec:\"./socks4echo.sh\""
4478 CMD
="$TRACE $SOCAT $opts - socks4:$LOCALHOST:32.98.76.54:32109,pf=ip4,socksport=$PORT",socksuser
="nobody"
4479 printf "test $F_n $TEST... " $N
4480 eval "$CMD2 2>\"${te}1\" &"
4481 pid
=$
! # background process id
4482 waittcp4port
$PORT 1
4483 echo "$da" |
$CMD >$tf 2>"${te}2"
4484 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4485 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4491 numFAIL
=$
((numFAIL
+1))
4492 listFAIL
="$listFAIL $N"
4495 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4498 kill $pid 2>/dev
/null
4500 fi ;; # NUMCOND, feats
4505 NAME
=SOCKS4CONNECT_TCP6
4507 *%$N%*|
*%functions
%*|
*%socks
%*|
*%socks4
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%$NAME%*)
4508 TEST
="$NAME: socks4 connect over TCP/IPv6"
4509 if ! eval $NUMCOND; then :;
4510 elif ! testaddrs socks4
>/dev
/null
; then
4511 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4 not available${NORMAL}\n" $N
4512 numCANT
=$
((numCANT
+1))
4513 elif ! testaddrs listen tcp ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
4514 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4515 numCANT
=$
((numCANT
+1))
4517 tf
="$td/test$N.stdout"
4518 te
="$td/test$N.stderr"
4519 tdiff
="$td/test$N.diff"
4520 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
4521 # we have a normal tcp echo listening - so the socks header must appear in answer
4522 CMD2
="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR exec:\"./socks4echo.sh\""
4523 CMD
="$TRACE $SOCAT $opts - socks4:$LOCALHOST6:32.98.76.54:32109,socksport=$PORT",socksuser
="nobody"
4524 printf "test $F_n $TEST... " $N
4525 eval "$CMD2 2>\"${te}1\" &"
4526 pid
=$
! # background process id
4527 waittcp6port
$PORT 1
4528 echo "$da" |
$CMD >$tf 2>"${te}2"
4529 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4530 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4536 numFAIL
=$
((numFAIL
+1))
4537 listFAIL
="$listFAIL $N"
4540 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4543 kill $pid 2>/dev
/null
4545 fi ;; # NUMCOND, feats
4551 NAME
=SOCKS4ACONNECT_TCP4
4553 *%$N%*|
*%functions
%*|
*%socks
%*|
*%socks4a
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4554 TEST
="$NAME: socks4a connect over TCP/IPv4"
4555 if ! eval $NUMCOND; then :;
4556 elif ! testaddrs socks4a
>/dev
/null
; then
4557 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4558 numCANT
=$
((numCANT
+1))
4559 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4560 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4561 numCANT
=$
((numCANT
+1))
4563 tf
="$td/test$N.stdout"
4564 te
="$td/test$N.stderr"
4565 tdiff
="$td/test$N.diff"
4566 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
4567 # we have a normal tcp echo listening - so the socks header must appear in answer
4568 CMD2
="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR exec:\"./socks4a-echo.sh\""
4569 CMD
="$TRACE $SOCAT $opts - socks4a:$LOCALHOST:localhost:32109,pf=ip4,socksport=$PORT",socksuser
="nobody"
4570 printf "test $F_n $TEST... " $N
4571 eval "$CMD2 2>\"${te}1\" &"
4572 pid
=$
! # background process id
4573 waittcp4port
$PORT 1
4574 echo "$da" |
$CMD >$tf 2>"${te}2"
4575 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4576 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4582 numFAIL
=$
((numFAIL
+1))
4583 listFAIL
="$listFAIL $N"
4586 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4589 kill $pid 2>/dev
/null
4591 fi ;; # NUMCOND, feats
4596 NAME
=SOCKS4ACONNECT_TCP6
4598 *%$N%*|
*%functions
%*|
*%socks
%*|
*%socks4a
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%$NAME%*)
4599 TEST
="$NAME: socks4a connect over TCP/IPv6"
4600 if ! eval $NUMCOND; then :;
4601 elif ! testaddrs socks4a
>/dev
/null
; then
4602 $PRINTF "test $F_n $TEST... ${YELLOW}SOCKS4A not available${NORMAL}\n" $N
4603 numCANT
=$
((numCANT
+1))
4604 elif ! testaddrs listen tcp ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
4605 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4606 numCANT
=$
((numCANT
+1))
4608 tf
="$td/test$N.stdout"
4609 te
="$td/test$N.stderr"
4610 tdiff
="$td/test$N.diff"
4611 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
4612 # we have a normal tcp echo listening - so the socks header must appear in answer
4613 CMD2
="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR exec:\"./socks4a-echo.sh\""
4614 CMD
="$TRACE $SOCAT $opts - socks4a:$LOCALHOST6:localhost:32109,socksport=$PORT",socksuser
="nobody"
4615 printf "test $F_n $TEST... " $N
4616 eval "$CMD2 2>\"${te}1\" &"
4617 pid
=$
! # background process id
4618 waittcp6port
$PORT 1
4619 echo "$da" |
$CMD >$tf 2>"${te}2"
4620 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4621 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4627 numFAIL
=$
((numFAIL
+1))
4628 listFAIL
="$listFAIL $N"
4631 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4634 kill $pid 2>/dev
/null
4636 fi ;; # NUMCOND, feats
4642 NAME
=PROXYCONNECT_TCP4
4644 *%$N%*|
*%functions
%*|
*%proxyconnect
%*|
*%proxy
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
4645 TEST
="$NAME: proxy connect over TCP/IPv4"
4646 if ! eval $NUMCOND; then :;
4647 elif ! testaddrs proxy
>/dev
/null
; then
4648 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4649 numCANT
=$
((numCANT
+1))
4650 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
4651 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
4652 numCANT
=$
((numCANT
+1))
4655 tf
="$td/test$N.stdout"
4656 te
="$td/test$N.stderr"
4657 tdiff
="$td/test$N.diff"
4658 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
4659 #CMD2="$TRACE $SOCAT tcp4-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4660 CMD2
="$TRACE $SOCAT $opts TCP4-L:$PORT,$REUSEADDR,crlf exec:\"/usr/bin/env bash proxyecho.sh\""
4661 CMD
="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4662 printf "test $F_n $TEST... " $N
4663 eval "$CMD2 2>\"${te}2\" &"
4664 pid
=$
! # background process id
4665 waittcp4port
$PORT 1
4666 echo "$da" |
$CMD >"$tf" 2>"${te}1"
4667 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4668 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4674 numFAIL
=$
((numFAIL
+1))
4675 listFAIL
="$listFAIL $N"
4678 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4681 kill $pid 2>/dev
/null
4683 fi ;; # NUMCOND, feats
4688 NAME
=PROXYCONNECT_TCP6
4690 *%$N%*|
*%functions
%*|
*%proxyconnect
%*|
*%proxy
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%$NAME%*)
4691 TEST
="$NAME: proxy connect over TCP/IPv6"
4692 if ! eval $NUMCOND; then :;
4693 elif ! testaddrs proxy
>/dev
/null
; then
4694 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4695 numCANT
=$
((numCANT
+1))
4696 elif ! testaddrs listen tcp ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
4697 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv6 not available${NORMAL}\n" $N
4698 numCANT
=$
((numCANT
+1))
4701 tf
="$td/test$N.stdout"
4702 te
="$td/test$N.stderr"
4703 tdiff
="$td/test$N.diff"
4704 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
4705 #CMD2="$TRACE $SOCAT $opts tcp6-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4706 CMD2
="$TRACE $SOCAT $opts TCP6-L:$PORT,$REUSEADDR,crlf exec:\"/usr/bin/env bash proxyecho.sh\""
4707 CMD
="$TRACE $SOCAT $opts - proxy:$LOCALHOST6:127.0.0.1:1000,proxyport=$PORT"
4708 printf "test $F_n $TEST... " $N
4709 eval "$CMD2 2>\"${te}2\" &"
4710 pid
=$
! # background process id
4711 waittcp6port
$PORT 1
4712 echo "$da" |
$CMD >"$tf" 2>"${te}1"
4713 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4714 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4720 numFAIL
=$
((numFAIL
+1))
4721 listFAIL
="$listFAIL $N"
4724 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4727 kill $pid 2>/dev
/null
4729 fi ;; # NUMCOND, feats
4737 *%$N%*|
*%functions
%*|
*%$NAME%*)
4738 TEST
="$NAME: echo via connection to TCP V4 socket with nofork'ed exec"
4739 if ! eval $NUMCOND; then :; else
4740 tf
="$td/test$N.stdout"
4741 te
="$td/test$N.stderr"
4742 tdiff
="$td/test$N.diff"
4745 da
="test$N $(date) $RANDOM"
4746 CMD1
="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR exec:$CAT,nofork"
4747 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
4748 printf "test $F_n $TEST... " $N
4749 #$CMD1 >"$tf" 2>"${te}1" &
4750 $CMD1 >/dev
/null
2>"${te}1" &
4753 echo "$da" |
$CMD2 >"$tf" 2>>"${te}2"
4754 if [ $?
-ne 0 ]; then
4755 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4760 numFAIL
=$
((numFAIL
+1))
4761 listFAIL
="$listFAIL $N"
4762 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4765 numFAIL
=$
((numFAIL
+1))
4766 listFAIL
="$listFAIL $N"
4769 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4780 *%$N%*|
*%functions
%*|
*%$NAME%*)
4781 TEST
="$NAME: simple echo via exec of cat with nofork"
4782 testecho
"$N" "$TEST" "" "exec:$CAT,nofork" "$opts"
4787 NAME
=SYSTEMCATNOFORK
4789 *%$N%*|
*%functions
%*|
*%$NAME%*)
4790 TEST
="$NAME: simple echo via system() of cat with nofork"
4791 testecho
"$N" "$TEST" "" "system:$CAT,nofork" "$opts"
4798 *%$N%*|
*%functions
%*|
*%$NAME%*)
4799 TEST
="$NAME: simple echo via exec() of cat with nofork and setsid"
4800 testecho
"$N" "$TEST" "" "system:$CAT,nofork,setsid" "$opts"
4804 #==============================================================================
4805 #TEST="$NAME: echo via 'connection' to UDP V4 socket"
4806 #if ! eval $NUMCOND; then :; else
4809 #ts="127.0.0.1:$tsl"
4810 #da="test$N $(date) $RANDOM"
4811 #$TRACE $SOCAT UDP-listen:$tsl,$REUSEADDR PIPE &
4813 #echo "$da" |$TRACE $SOCAT stdin!!stdout UDP:$ts >"$tf"
4814 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
4815 # $ECHO "... test $N succeeded"
4816 # numOK=$((numOK+1))
4818 # $ECHO "*** test $N $FAILED"
4819 # numFAIL=$((numFAIL+1))
4820 # listFAIL="$listFAIL $N"
4824 #==============================================================================
4825 # TEST 4 - simple echo via new file
4826 #if ! eval $NUMCOND; then :; else
4830 #da="test$N $(date) $RANDOM"
4832 #echo "$da" |$TRACE $SOCAT - FILE:$tf.tmp,ignoreeof >"$tf"
4833 #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then
4834 # $ECHO "... test $N succeeded"
4835 # numOK=$((numOK+1))
4837 # $ECHO "*** test $N $FAILED"
4838 # numFAIL=$((numFAIL+1))
4839 # listFAIL="$listFAIL $N"
4843 #==============================================================================
4847 *%$N%*|
*%functions
%*|
*%engine
%*|
*%timeout
%*|
*%$NAME%*)
4848 TEST
="$NAME: socat inactivity timeout"
4849 if ! eval $NUMCOND; then :; else
4851 tf
="$td/test$N.stdout"
4852 te
="$td/test$N.stderr"
4853 tdiff
="$td/test$N.diff"
4854 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
4855 CMD2
="$TRACE $SOCAT $opts -T 1 TCP4-LISTEN:$PORT,$REUSEADDR pipe"
4856 CMD
="$TRACE $SOCAT $opts - tcp4-connect:$LOCALHOST:$PORT"
4857 printf "test $F_n $TEST... " $N
4858 eval "$CMD2 2>${te}1 &"
4859 pid
=$
! # background process id
4860 waittcp4port
$PORT 1
4861 (echo "$da"; sleep 2; echo X
) |
$CMD >"$tf" 2>"${te}2"
4862 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4863 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4869 numFAIL
=$
((numFAIL
+1))
4870 listFAIL
="$listFAIL $N"
4873 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4876 kill $pid 2>/dev
/null
4885 NAME
=IGNOREEOF
+TOTALTIMEOUT
4887 *%$N%*|
*%functions
%*|
*%engine
%*|
*%timeout
%*|
*%ignoreeof
%*|
*%$NAME%*)
4888 TEST
="$NAME: ignoreeof and inactivity timeout"
4889 if ! eval $NUMCOND; then :; else
4891 ti
="$td/test$N.file"
4892 tf
="$td/test$N.stdout"
4893 te
="$td/test$N.stderr"
4894 tdiff
="$td/test$N.diff"
4895 da
="test$N $(date) $RANDOM"
4896 CMD
="$TRACE $SOCAT $opts -T 2 -u file:\"$ti\",ignoreeof -"
4897 printf "test $F_n $TEST... " $N
4899 $CMD >"$tf" 2>"$te" &
4900 bg=$
! # background process id
4906 kill $bg 2>/dev
/null
4907 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4908 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4912 numFAIL
=$
((numFAIL
+1))
4913 listFAIL
="$listFAIL $N"
4916 if [ -n "$debug" ]; then cat "$te"; fi
4920 fi ;; # NUMCOND, feats
4927 *%$N%*|
*%functions
%*|
*%proxy
%*|
*%$NAME%*)
4928 TEST
="$NAME: proxy connect accepts status with multiple spaces"
4929 if ! eval $NUMCOND; then :;
4930 elif ! testaddrs proxy
>/dev
/null
; then
4931 $PRINTF "test $F_n $TEST... ${YELLOW}PROXY not available${NORMAL}\n" $N
4932 numCANT
=$
((numCANT
+1))
4935 tf
="$td/test$N.stdout"
4936 te
="$td/test$N.stderr"
4937 tdiff
="$td/test$N.diff"
4938 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
4939 #CMD2="$TRACE $SOCAT $opts tcp-l:$PORT,crlf SYSTEM:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\""
4940 CMD2
="$TRACE $SOCAT $opts tcp4-l:$PORT,reuseaddr,crlf exec:\"/usr/bin/env bash proxyecho.sh -w 2\""
4941 CMD
="$TRACE $SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT"
4942 printf "test $F_n $TEST... " $N
4943 eval "$CMD2 2>\"${te}1\" &"
4944 pid
=$
! # background process id
4945 waittcp4port
$PORT 1
4946 echo "$da" |
$CMD >"$tf" 2>"${te}2"
4947 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
4948 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
4954 numFAIL
=$
((numFAIL
+1))
4955 listFAIL
="$listFAIL $N"
4958 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
4961 kill $pid 2>/dev
/null
4963 fi ;; # NUMCOND, feats
4971 *%$N%*|
*%functions
%*|
*%$NAME%*)
4972 TEST
="$NAME: for bug with address options on both stdin/out in unidirectional mode"
4973 if ! eval $NUMCOND; then :; else
4974 tf
="$td/test$N.stdout"
4975 te
="$td/test$N.stderr"
4977 printf "test $F_n $TEST... " $N
4979 #$TRACE $SOCAT $opts -u /dev/null -,setlk <"$ff" 2>"$te"
4980 CMD
="$TRACE $SOCAT $opts -u /dev/null -,setlk"
4982 if [ "$?" -eq 0 ]; then
4986 if [ "$UNAME" = "Linux" ]; then
4990 numFAIL
=$
((numFAIL
+1))
4991 listFAIL
="$listFAIL $N"
4993 $PRINTF "${YELLOW}failed (don't care)${NORMAL}\n"
4994 numCANT
=$
((numCANT
+1))
5002 NAME
=SINGLEEXECOUTSOCKETPAIR
5004 *%$N%*|
*%functions
%*|
*%$NAME%*)
5005 TEST
="$NAME: inheritance of stdout to single exec with socketpair"
5006 testecho
"$N" "$TEST" "-!!exec:cat" "" "$opts" 1
5010 NAME
=SINGLEEXECOUTPIPE
5012 *%$N%*|
*%functions
%*|
*%$NAME%*)
5013 TEST
="$NAME: inheritance of stdout to single exec with pipe"
5014 testecho
"$N" "$TEST" "-!!exec:cat,pipes" "" "$opts" 1
5018 NAME
=SINGLEEXECOUTPTY
5020 *%$N%*|
*%functions
%*|
*%pty
%*|
*%$NAME%*)
5021 TEST
="$NAME: inheritance of stdout to single exec with pty"
5022 if ! eval $NUMCOND; then :;
5023 elif ! testaddrs pty
>/dev
/null
; then
5024 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5025 numCANT
=$
((numCANT
+1))
5027 testecho
"$N" "$TEST" "-!!exec:cat,pty,raw" "" "$opts" 1
5028 fi ;; # NUMCOND, feats
5032 NAME
=SINGLEEXECINSOCKETPAIR
5034 *%$N%*|
*%functions
%*|
*%$NAME%*)
5035 TEST
="$NAME: inheritance of stdin to single exec with socketpair"
5036 testecho
"$N" "$TEST" "exec:cat!!-" "" "$opts"
5040 NAME
=SINGLEEXECINPIPE
5042 *%$N%*|
*%functions
%*|
*%$NAME%*)
5043 TEST
="$NAME: inheritance of stdin to single exec with pipe"
5044 testecho
"$N" "$TEST" "exec:cat,pipes!!-" "" "$opts"
5048 NAME
=SINGLEEXECINPTYDELAY
5050 *%$N%*|
*%functions
%*|
*%pty
%*|
*%$NAME%*)
5051 TEST
="$NAME: inheritance of stdin to single exec with pty, with delay"
5052 if ! eval $NUMCOND; then :;
5053 elif ! testaddrs pty
>/dev
/null
; then
5054 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5055 numCANT
=$
((numCANT
+1))
5057 testecho
"$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts" $MISCDELAY
5058 fi ;; # NUMCOND, feats
5062 NAME
=SINGLEEXECINPTY
5064 *%$N%*|
*%functions
%*|
*%pty
%*|
*%$NAME%*)
5065 TEST
="$NAME: inheritance of stdin to single exec with pty"
5066 if ! eval $NUMCOND; then :;
5067 elif ! testaddrs pty
>/dev
/null
; then
5068 $PRINTF "test $F_n $TEST... ${YELLOW}PTY not available${NORMAL}\n" $N
5069 numCANT
=$
((numCANT
+1))
5071 testecho
"$N" "$TEST" "exec:cat,pty,raw!!-" "" "$opts"
5072 fi ;; # NUMCOND, feats
5080 *%$N%*|
*%functions
%*|
*%pty
%*|
*%readline
%*|
*%$NAME%*)
5081 TEST
="$NAME: readline with password and sigint"
5082 if ! eval $NUMCOND; then :;
5083 elif ! feat
=$
(testaddrs readline pty
); then
5084 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5085 numCANT
=$
((numCANT
+1))
5087 SAVETERM
="$TERM"; TERM
= # 'cause konsole might print controls even in raw
5091 to
="$td/test$N.stdout"
5092 tpi
="$td/test$N.inpipe"
5093 tpo
="$td/test$N.outpipe"
5094 te
="$td/test$N.stderr"
5096 tdiff
="$td/test$N.diff"
5097 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
5098 # the feature that we really want to test is in the readline.sh script:
5099 CMD
="$TRACE $SOCAT $opts -t1 open:$tpi,nonblock!!open:$tpo exec:\"./readline.sh -nh ./readline-test.sh\",pty,ctty,setsid,raw,echo=0,isig"
5102 printf "test $F_n $TEST... " $N
5107 # during development of this test, the following command line succeeded:
5108 # (sleep 1; $ECHO "user\n\c"; sleep 1; $ECHO "password\c"; sleep 1; $ECHO "\n\c"; sleep 1; $ECHO "test 1\n\c"; sleep 1; $ECHO "\003\c"; sleep 1; $ECHO "test 2\n\c"; sleep 1; $ECHO "exit\n\c"; sleep 1) |$TRACE $SOCAT -d -d -d -d -lf/tmp/gerhard/debug1 -v -x - exec:'./readline.sh ./readline-test.sh',pty,ctty,setsid,raw,echo=0,isig
5110 PATH
=${SOCAT%socat}:$PATH eval "$CMD 2>$te &"
5111 pid
=$
! # background process id
5115 usleep $
((3*MICROS
))
5133 readline feature test program
5134 Authentication required
5139 prog> ./readline-test.sh got SIGINT
5145 #0 if ! sed 's/.*\r//g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5146 #0 if ! sed 's/.*'"$($ECHO '\r\c')"'/</g' "$tpo" |diff -q "$tr" - >/dev/null 2>&1; then
5148 if ! tr "$($ECHO '\r \c')" "% " <$tpo |
sed 's/%$//g' |
sed 's/.*%//g' |
diff "$tr" - >"$tdiff" 2>&1; then
5149 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5153 numFAIL
=$
((numFAIL
+1))
5154 listFAIL
="$listFAIL $N"
5157 if [ -n "$debug" ]; then cat $te; fi
5160 kill $pid 2>/dev
/null
# necc on OpenBSD
5164 fi ;; # NUMCOND, feats
5172 *%$N%*|
*%functions
%*|
*%$NAME%*)
5173 TEST
="$NAME: TCP4 \"gender changer\""
5174 if ! eval $NUMCOND; then :; else
5175 tf
="$td/test$N.stdout"
5176 te
="$td/test$N.stderr"
5177 tdiff
="$td/test$N.diff"
5178 da
="test$N $(date) $RANDOM"
5179 # this is the server in the protected network that we want to reach
5180 CMD1
="$TRACE $SOCAT -lpserver $opts tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5181 # this is the double client in the protected network
5182 CMD2
="$TRACE $SOCAT -lp2client $opts tcp4:$LOCALHOST:$((PORT+1)),retry=10,interval=1 tcp4:$LOCALHOST:$PORT"
5183 # this is the double server in the outside network
5184 CMD3
="$TRACE $SOCAT -lp2server $opts tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST"
5185 # this is the outside client that wants to use the protected server
5186 CMD4
="$TRACE $SOCAT -lpclient $opts -t1 - tcp4:$LOCALHOST:$((PORT+2))"
5187 printf "test $F_n $TEST... " $N
5188 eval "$CMD1 2>${te}1 &"
5190 eval "$CMD2 2>${te}2 &"
5192 eval "$CMD3 2>${te}3 &"
5194 waittcp4port
$PORT 1 &&
5195 waittcp4port $
((PORT
+2)) 1
5197 echo "$da" |
$CMD4 >$tf 2>"${te}4"
5198 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
5199 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5204 cat "${te}1" "${te}2" "${te}3" "${te}4"
5206 numFAIL
=$
((numFAIL
+1))
5207 listFAIL
="$listFAIL $N"
5210 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4"; fi
5213 kill $pid1 $pid2 $pid3 $pid4 2>/dev
/null
5226 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%proxy
%*|
*%$NAME%*)
5227 TEST
="$NAME: gender changer via SSL through HTTP proxy, oneshot"
5228 if ! eval $NUMCOND; then :;
5229 elif ! feat
=$
(testaddrs openssl proxy
); then
5230 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5231 numCANT
=$
((numCANT
+1))
5235 tf
="$td/test$N.stdout"
5236 te
="$td/test$N.stderr"
5237 tdiff
="$td/test$N.diff"
5238 da
="test$N $(date) $RANDOM"
5239 # this is the server in the protected network that we want to reach
5240 CMD1
="$TRACE $SOCAT $opts -lpserver tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo"
5241 # this is the proxy in the protected network that provides a way out
5242 CMD2
="$TRACE $SOCAT $opts -lpproxy tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5243 # this is our proxy connect wrapper in the protected network
5244 CMD3
="$TRACE $SOCAT $opts -lpwrapper tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
5245 # this is our double client in the protected network using SSL
5246 #CMD4="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5247 CMD4
="$TRACE $SOCAT $opts -lp2client ssl:$LOCALHOST:$((PORT+2)),pf=ip4,cert=testcli.pem,cafile=testsrv.crt,$SOCAT_EGD tcp4:$LOCALHOST:$PORT"
5248 # this is the double server in the outside network
5249 CMD5
="$TRACE $SOCAT $opts -lp2server -t1 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt"
5250 # this is the outside client that wants to use the protected server
5251 CMD6
="$TRACE $SOCAT $opts -lpclient -t5 - tcp4:$LOCALHOST:$((PORT+4))"
5252 printf "test $F_n $TEST... " $N
5253 eval "$CMD1 2>${te}1 &"
5255 eval "$CMD2 2>${te}2 &"
5257 eval "$CMD3 2>${te}3 &"
5259 waittcp4port
$PORT 1 ||
$PRINTF "$FAILED: port $PORT\n" >&2 </dev
/null
5260 waittcp4port $
((PORT
+1)) 1 ||
$PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev
/null
5261 waittcp4port $
((PORT
+2)) 1 ||
$PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev
/null
5262 eval "$CMD5 2>${te}5 &"
5264 waittcp4port $
((PORT
+4)) 1 ||
$PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev
/null
5265 echo "$da" |
$CMD6 >$tf 2>"${te}6" &
5267 waittcp4port $
((PORT
+3)) 1 ||
$PRINTF "$FAILED: port $((PORT+3))\n" >&2 </dev
/null
5268 eval "$CMD4 2>${te}4 &"
5271 if ! (echo "$da"; sleep 2) |
diff - "$tf" >"$tdiff"; then
5272 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5286 numFAIL
=$
((numFAIL
+1))
5287 listFAIL
="$listFAIL $N"
5290 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" "${te}6"; fi
5293 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev
/null
5295 fi ;; # NUMCOND, feats
5301 # test the TCP gender changer with almost production requirements: a double
5302 # client repeatedly tries to connect to a double server via SSL through an HTTP
5303 # proxy. the double servers SSL port becomes active for one connection only
5304 # after a (real) client has connected to its TCP port. when the double client
5305 # succeeded to establish an SSL connection, it connects with its second client
5306 # side to the specified (protected) server. all three consecutive connections
5307 # must function for full success of this test.
5308 PORT
=$
((RANDOM
+16184))
5312 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%proxy
%*|
*%$NAME%*)
5313 TEST
="$NAME: gender changer via SSL through HTTP proxy, daemons"
5314 if ! eval $NUMCOND; then :;
5315 elif ! feat
=$
(testaddrs openssl proxy
); then
5316 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
5317 numCANT
=$
((numCANT
+1))
5321 tf
="$td/test$N.stdout"
5322 te
="$td/test$N.stderr"
5323 tdiff
="$td/test$N.diff"
5324 da1
="test$N.1 $(date) $RANDOM"
5325 da2
="test$N.2 $(date) $RANDOM"
5326 da3
="test$N.3 $(date) $RANDOM"
5327 # this is the server in the protected network that we want to reach
5328 CMD1
="$TRACE $SOCAT $opts -lpserver -t1 tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST,fork echo"
5329 # this is the proxy in the protected network that provides a way out
5330 # note: the proxy.sh script starts one or two more socat processes without
5331 # setting the program name
5332 CMD2
="$TRACE $SOCAT $opts -lpproxy -t1 tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh"
5333 # this is our proxy connect wrapper in the protected network
5334 CMD3
="$TRACE $SOCAT $opts -lpwrapper -t3 tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve"
5335 # this is our double client in the protected network using SSL
5336 CMD4
="$TRACE $SOCAT $opts -lp2client -t3 ssl:$LOCALHOST:$((PORT+2)),retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,verify,fork,$SOCAT_EGD tcp4:$LOCALHOST:$PORT,forever,interval=0.1"
5337 # this is the double server in the outside network
5338 CMD5
="$TRACE $SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,backlog=3,fork ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt,retry=20,interval=0.5"
5339 # this is the outside client that wants to use the protected server
5340 CMD6
="$TRACE $SOCAT $opts -lpclient -t6 - tcp4:$LOCALHOST:$((PORT+4)),retry=3"
5341 printf "test $F_n $TEST... " $N
5342 # start the intranet infrastructure
5343 eval "$CMD1 2>\"${te}1\" &"
5345 eval "$CMD2 2>\"${te}2\" &"
5347 waittcp4port
$PORT 1 ||
$PRINTF "$FAILED: port $PORT\n" >&2 </dev
/null
5348 waittcp4port $
((PORT
+1)) 1 ||
$PRINTF "$FAILED: port $((PORT+1))\n" >&2 </dev
/null
5349 # initiate our internal measures
5350 eval "$CMD3 2>\"${te}3\" &"
5352 eval "$CMD4 2>\"${te}4\" &"
5354 waittcp4port $
((PORT
+2)) 1 ||
$PRINTF "$FAILED: port $((PORT+2))\n" >&2 </dev
/null
5355 # now we start the external daemon
5356 eval "$CMD5 2>\"${te}5\" &"
5358 waittcp4port $
((PORT
+4)) 1 ||
$PRINTF "$FAILED: port $((PORT+4))\n" >&2 </dev
/null
5359 # and this is the outside client:
5360 echo "$da1" |
$CMD6 >${tf}_1
2>"${te}6_1" &
5362 echo "$da2" |
$CMD6 >${tf}_2
2>"${te}6_2" &
5364 echo "$da3" |
$CMD6 >${tf}_3
2>"${te}6_3" &
5366 wait $pid6_1 $pid6_2 $pid6_3
5368 (echo "$da1"; sleep 2) |
diff - "${tf}_1" >"${tdiff}1"
5369 (echo "$da2"; sleep 2) |
diff - "${tf}_2" >"${tdiff}2"
5370 (echo "$da3"; sleep 2) |
diff - "${tf}_3" >"${tdiff}3"
5371 if test -s "${tdiff}1" -o -s "${tdiff}2" -o -s "${tdiff}3"; then
5372 # FAILED only when none of the three transfers succeeded
5373 if test -s "${tdiff}1" -a -s "${tdiff}2" -a -s "${tdiff}3"; then
5374 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
5394 numFAIL
=$
((numFAIL
+1))
5395 listFAIL
="$listFAIL $N"
5397 $PRINTF "$OK ${YELLOW}(partial failure)${NORMAL}\n"
5398 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5403 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi
5406 kill $pid1 $pid2 $pid3 $pid4 $pid5 2>/dev
/null
5408 fi ;; # NUMCOND, feats
5414 # let us test the security features with -s, retry, and fork
5415 # method: first test without security feature if it works
5416 # then try with security feature, must fail
5418 # test the security features of a server address
5423 local arg1
="$4" # the server address
5424 local secopt0
="$5" # option without security for server, mostly empty
5425 local secopt1
="$6" # the security option for server, to be tested
5426 local arg2
="$7" # the client address
5427 local ipvers
="$8" # IP version, for check of listen port
5428 local proto
="$9" # protocol, for check of listen port
5429 local port
="${10}" # start client when this port is listening
5430 local expect
="${11}" # expected behaviour of client: 0..empty output; -1..error
5431 local T
="${12}"; [ -z "$T" ] && T
=0
5432 local tf
="$td/test$N.stdout"
5433 local te
="$td/test$N.stderr"
5434 local tdiff1
="$td/test$N.diff1"
5435 local tdiff2
="$td/test$N.diff2"
5436 local da
="test$N.1 $(date) $RANDOM"
5439 $PRINTF "test $F_n %s... " $N "$title"
5440 # first: without security
5442 $TRACE $SOCAT $opts "$arg1,$secopt0" echo 2>"${te}1" &
5444 if [ "$port" ] && ! wait${proto}${ipvers}port
$port 1; then
5445 kill $spid 2>/dev
/null
5446 $PRINTF "$NO_RESULT (ph.1 server not working):\n"
5447 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5449 numCANT
=$
((numCANT
+1))
5453 (echo "$da"; sleep $T) |
$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}2"
5455 kill $spid 2>/dev
/null
5456 #killall $TRACE $SOCAT 2>/dev/null
5457 if [ "$stat" != 0 ]; then
5458 $PRINTF "$NO_RESULT (ph.1 function fails): $TRACE $SOCAT:\n"
5459 echo "$TRACE $SOCAT $opts \"$arg1,$secopt0\" echo &"
5461 echo "$TRACE $SOCAT $opts - \"$arg2\""
5463 numCANT
=$
((numCANT
+1))
5465 elif echo "$da" |
diff - "$tf" >"$tdiff1" 2>&1; then
5466 : # function without security is ok, go on
5468 $PRINTF "$NO_RESULT (ph.1 function fails): diff:\n"
5469 echo "$TRACE $SOCAT $opts $arg1,$secopt0 echo &"
5471 echo "$TRACE $SOCAT $opts - $arg2"
5474 numCANT
=$
((numCANT
+1))
5478 # then: with security
5479 if [ "$port" ] && ! wait${proto}${ipvers}port
$port 0; then
5480 $PRINTF "$NO_RESULT (ph.1 port remains in use)\n"
5481 numCANT
=$
((numCANT
+1))
5487 # assemble address w/ security option; on dual, take read part:
5489 *!!*) arg
="${arg1%!!*},$secopt1!!${arg1#*!!}" ;;
5490 *) arg
="$arg1,$secopt1" ;;
5493 # use -s to make sure that it fails due to a sec violation, not some other failure
5494 CMD3
="$TRACE $SOCAT $opts -s $arg echo"
5497 if [ "$port" ] && ! wait${proto}${ipvers}port
$port 1; then
5498 kill $spid 2>/dev
/null
5499 $PRINTF "$NO_RESULT (ph.2 server not working)\n"
5503 numCANT
=$
((numCANT
+1))
5507 da
="test$N.2 $(date) $RANDOM"
5508 (echo "$da"; sleep $T) |
$TRACE $SOCAT $opts - "$arg2" >"$tf" 2>"${te}4"
5510 kill $spid 2>/dev
/null
5512 #killall $TRACE $SOCAT 2>/dev/null
5513 if [ "$stat" != 0 ]; then
5514 result
=-1; # socat had error
5515 elif [ ! -s "$tf" ]; then
5516 result
=0; # empty output
5517 elif echo "$da" |
diff - "$tf" >"$tdiff2" 2>&1; then
5518 result
=1; # output is copy of input
5520 result
=2; # output differs from input
5522 if [ X
$result != X
$expect ]; then
5524 X-1
) $PRINTF "$NO_RESULT (ph.2 client error): $TRACE $SOCAT:\n"
5525 echo "$TRACE $SOCAT $opts $arg echo"
5527 echo "$TRACE $SOCAT $opts - $arg2"
5529 numCANT
=$
((numCANT
+1)) ;;
5530 X0
) $PRINTF "$NO_RESULT (ph.2 diff failed): diff:\n"
5531 echo "$TRACE $SOCAT $opts $arg echo"
5533 echo "$TRACE $SOCAT $opts - $arg2"
5536 numCANT
=$
((numCANT
+1)) ;;
5537 X1
) $PRINTF "$FAILED: SECURITY BROKEN\n"
5538 echo "$TRACE $SOCAT $opts $arg echo"
5540 echo "$TRACE $SOCAT $opts - $arg2"
5543 numFAIL
=$
((numFAIL
+1))
5544 listFAIL
="$listFAIL $N" ;;
5545 X2
) $PRINTF "$FAILED: diff:\n"
5546 echo "$TRACE $SOCAT $opts $arg echo"
5548 echo "$TRACE $SOCAT $opts - $arg2"
5551 numFAIL
=$
((numFAIL
+1))
5552 listFAIL
="$listFAIL $N" ;;
5556 [ "$VERBOSE" ] && echo " $TRACE $SOCAT $opts $arg echo"
5557 [ "$debug" ] && cat ${te}3
5558 [ "$VERBOSE" ] && echo " $TRACE $SOCAT $opts - $arg2"
5559 [ "$debug" ] && cat ${te}4
5569 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%range
%*|
*%$NAME%*)
5570 TEST
="$NAME: security of TCP4-L with RANGE option"
5571 if ! eval $NUMCOND; then :;
5572 elif [ -z "$SECONDADDR" ]; then
5573 # we need access to a second addresses
5574 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5575 numCANT
=$
((numCANT
+1))
5577 testserversec
"$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp
$PORT 0
5578 fi ;; # $SECONDADDR, NUMCOND
5585 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%range
%*|
*%$NAME%*)
5586 TEST
="$NAME: security of TCP4-L with RANGE option"
5587 if ! eval $NUMCOND; then :;
5588 elif [ -z "$SECONDADDR" ]; then
5589 # we need access to a second addresses
5590 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
5591 numCANT
=$
((numCANT
+1))
5593 testserversec
"$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR:255.255.255.255" "tcp4:127.0.0.1:$PORT" 4 tcp
$PORT 0
5594 fi ;; # $SECONDADDR, NUMCOND
5599 # like TCP4RANGEMASK, but the "bad" address is within the same class A network
5600 NAME
=TCP4RANGEMASKHAIRY
5602 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%range
%*|
*%$NAME%*)
5603 TEST
="$NAME: security of TCP4-L with RANGE option"
5604 if ! eval $NUMCOND; then :; else
5605 testserversec
"$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=127.0.0.0:255.255.0.0" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp
$PORT 0
5606 fi ;; # Linux, NUMCOND
5614 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%sourceport
%*|
*%$NAME%*)
5615 TEST
="$NAME: security of TCP4-L with SOURCEPORT option"
5616 if ! eval $NUMCOND; then :; else
5617 testserversec
"$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp4:127.0.0.1:$PORT" 4 tcp
$PORT 0
5625 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%lowport
%*|
*%$NAME%*)
5626 TEST
="$NAME: security of TCP4-L with LOWPORT option"
5627 if ! eval $NUMCOND; then :; else
5628 testserversec
"$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp4:127.0.0.1:$PORT" 4 tcp
$PORT 0
5634 NAME
=TCP4WRAPPERS_ADDR
5636 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%tcpwrap
%*|
*%$NAME%*)
5637 TEST
="$NAME: security of TCP4-L with TCPWRAP option"
5638 if ! eval $NUMCOND; then :;
5639 elif ! feat
=$
(testaddrs tcp ip4 libwrap
) ||
! runsip4
>/dev
/null
; then
5640 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5641 numCANT
=$
((numCANT
+1))
5643 ha
="$td/hosts.allow"
5645 $ECHO "socat: $SECONDADDR" >"$ha"
5646 $ECHO "ALL: ALL" >"$hd"
5647 testserversec
"$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:127.0.0.1:$PORT" 4 tcp
$PORT 0
5648 fi ;; # NUMCOND, feats
5653 NAME
=TCP4WRAPPERS_NAME
5655 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%tcpwrap
%*|
*%$NAME%*)
5656 TEST
="$NAME: security of TCP4-L with TCPWRAP option"
5657 if ! eval $NUMCOND; then :;
5658 elif ! feat
=$
(testaddrs tcp ip4 libwrap
) ||
! runsip4
>/dev
/null
; then
5659 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5660 numCANT
=$
((numCANT
+1))
5662 ha
="$td/hosts.allow"
5664 $ECHO "socat: $LOCALHOST" >"$ha"
5665 $ECHO "ALL: ALL" >"$hd"
5666 testserversec
"$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp4:$SECONDADDR:$PORT,bind=$SECONDADDR" 4 tcp
$PORT 0
5667 fi ;; # NUMCOND, feats
5675 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%range
%*|
*%$NAME%*)
5676 TEST
="$NAME: security of TCP6-L with RANGE option"
5677 if ! eval $NUMCOND; then :;
5678 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
5679 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5680 numCANT
=$
((numCANT
+1))
5682 testserversec
"$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "range=[::2]/128" "tcp6:[::1]:$PORT" 6 tcp
$PORT 0
5683 fi ;; # NUMCOND, feats
5690 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%sourceport
%*|
*%$NAME%*)
5691 TEST
="$NAME: security of TCP6-L with SOURCEPORT option"
5692 if ! eval $NUMCOND; then :;
5693 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
5694 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5695 numCANT
=$
((numCANT
+1))
5697 testserversec
"$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "sp=$PORT" "tcp6:[::1]:$PORT" 6 tcp
$PORT 0
5698 fi ;; # NUMCOND, feats
5705 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%lowport
%*|
*%$NAME%*)
5706 TEST
="$NAME: security of TCP6-L with LOWPORT option"
5707 if ! eval $NUMCOND; then :;
5708 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
5709 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5710 numCANT
=$
((numCANT
+1))
5712 testserversec
"$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "lowport" "tcp6:[::1]:$PORT" 6 tcp
$PORT 0
5713 fi ;; # NUMCOND, feats
5720 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%tcpwrap
%*|
*%$NAME%*)
5721 TEST
="$NAME: security of TCP6-L with TCPWRAP option"
5722 if ! eval $NUMCOND; then :;
5723 elif ! feat
=$
(testaddrs tcp ip6 libwrap
) ||
! runsip6
>/dev
/null
; then
5724 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5725 numCANT
=$
((numCANT
+1))
5727 ha
="$td/hosts.allow"
5729 $ECHO "socat: [::2]" >"$ha"
5730 $ECHO "ALL: ALL" >"$hd"
5731 testserversec
"$N" "$TEST" "$opts" "tcp6-l:$PORT,reuseaddr,fork,retry=1" "" "hosts-allow=$ha,hosts-deny=$hd" "tcp6:[::1]:$PORT" 6 tcp
$PORT 0
5732 fi ;; # NUMCOND, feats
5740 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%range
%*|
*%$NAME%*)
5741 TEST
="$NAME: security of UDP4-L with RANGE option"
5742 if ! eval $NUMCOND; then :; else
5743 #testserversec "$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp $PORT 0
5744 testserversec
"$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4:127.0.0.1:$PORT" 4 udp
$PORT 0
5752 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%sourceport
%*|
*%$NAME%*)
5753 TEST
="$NAME: security of UDP4-L with SOURCEPORT option"
5754 if ! eval $NUMCOND; then :; else
5755 testserversec
"$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "sp=$PORT" "udp4:127.0.0.1:$PORT" 4 udp
$PORT 0
5763 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%lowport
%*|
*%$NAME%*)
5764 TEST
="$NAME: security of UDP4-L with LOWPORT option"
5765 if ! eval $NUMCOND; then :; else
5766 testserversec
"$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "lowport" "udp4:127.0.0.1:$PORT" 4 udp
$PORT 0
5774 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%tcpwrap
%*|
*%$NAME%*)
5775 TEST
="$NAME: security of UDP4-L with TCPWRAP option"
5776 if ! eval $NUMCOND; then :;
5777 elif ! feat
=$
(testaddrs udp ip4 libwrap
) ||
! runsip4
>/dev
/null
; then
5778 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5779 numCANT
=$
((numCANT
+1))
5781 ha
="$td/hosts.allow"
5783 $ECHO "socat: $SECONDADDR" >"$ha"
5784 $ECHO "ALL: ALL" >"$hd"
5785 testserversec
"$N" "$TEST" "$opts" "udp4-l:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4:127.0.0.1:$PORT" 4 udp
$PORT 0
5786 fi ;; # NUMCOND, feats
5794 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%range
%*|
*%$NAME%*)
5795 TEST
="$NAME: security of UDP6-L with RANGE option"
5796 if ! eval $NUMCOND; then :;
5797 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
5798 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5799 numCANT
=$
((numCANT
+1))
5801 #testserversec "$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr,fork" "" "range=[::2]/128" "udp6:[::1]:$PORT" 6 udp $PORT 0
5802 testserversec
"$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "range=[::2]/128" "udp6:[::1]:$PORT" 6 udp
$PORT 0
5803 fi ;; # NUMCOND, feats
5810 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%sourceport
%*|
*%$NAME%*)
5811 TEST
="$NAME: security of UDP6-L with SOURCEPORT option"
5812 if ! eval $NUMCOND; then :;
5813 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
5814 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
5815 numCANT
=$
((numCANT
+1))
5817 testserversec
"$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "sp=$PORT" "udp6:[::1]:$PORT" 6 udp
$PORT 0
5818 fi ;; # NUMCOND, feats
5825 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%lowport
%*|
*%$NAME%*)
5826 TEST
="$NAME: security of UDP6-L with LOWPORT option"
5827 if ! eval $NUMCOND; then :;
5828 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
5829 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
5830 numCANT
=$
((numCANT
+1))
5832 testserversec
"$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp
$PORT 0
5833 fi ;; # NUMCOND, feats
5840 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%tcpwrap
%*|
*%$NAME%*)
5841 TEST
="$NAME: security of UDP6-L with TCPWRAP option"
5842 if ! eval $NUMCOND; then :;
5843 elif ! feat
=$
(testaddrs tcp ip6 libwrap
) ||
! runsip6
>/dev
/null
; then
5844 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5845 numCANT
=$
((numCANT
+1))
5847 ha
="$td/hosts.allow"
5849 $ECHO "socat: [::2]" >"$ha"
5850 $ECHO "ALL: ALL" >"$hd"
5851 testserversec
"$N" "$TEST" "$opts" "udp6-l:$PORT,reuseaddr" "" "lowport" "udp6:[::1]:$PORT" 6 udp
$PORT 0
5852 fi ;; # NUMCOND, feats
5858 NAME
=OPENSSLTCP4_RANGE
5860 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%openssl
%*|
*%range
%*|
*%$NAME%*)
5861 TEST
="$NAME: security of SSL-L over TCP/IPv4 with RANGE option"
5862 if ! eval $NUMCOND; then :;
5863 elif ! testaddrs openssl
>/dev
/null
; then
5864 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5865 numCANT
=$
((numCANT
+1))
5868 testserversec
"$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "range=$SECONDADDR/32" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp
$PORT -1
5869 fi ;; # NUMCOND, feats
5874 NAME
=OPENSSLTCP4_SOURCEPORT
5876 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%openssl
%*|
*%sourceport
%*|
*%$NAME%*)
5877 TEST
="$NAME: security of SSL-L with SOURCEPORT option"
5878 if ! eval $NUMCOND; then :;
5879 elif ! testaddrs openssl
>/dev
/null
; then
5880 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5881 numCANT
=$
((numCANT
+1))
5884 testserversec
"$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "sp=$PORT" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp
$PORT -1
5885 fi ;; # NUMCOND, feats
5890 NAME
=OPENSSLTCP4_LOWPORT
5892 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%openssl
%*|
*%lowport
%*|
*%$NAME%*)
5893 TEST
="$NAME: security of SSL-L with LOWPORT option"
5894 if ! eval $NUMCOND; then :;
5895 elif ! testaddrs openssl
>/dev
/null
; then
5896 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5897 numCANT
=$
((numCANT
+1))
5900 testserversec
"$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "lowport" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp
$PORT -1
5901 fi ;; # NUMCOND, feats
5906 NAME
=OPENSSLTCP4_TCPWRAP
5908 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%openssl
%*|
*%tcpwrap
%*|
*%$NAME%*)
5909 TEST
="$NAME: security of SSL-L with TCPWRAP option"
5910 if ! eval $NUMCOND; then :;
5911 elif ! feat
=$
(testaddrs ip4 tcp libwrap openssl
); then
5912 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
5913 numCANT
=$
((numCANT
+1))
5916 ha
="$td/hosts.allow"
5918 $ECHO "socat: $SECONDADDR" >"$ha"
5919 $ECHO "ALL: ALL" >"$hd"
5920 testserversec
"$N" "$TEST" "$opts" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv.crt,key=testsrv.key" "" "tcpwrap-etc=$td" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,$SOCAT_EGD" 4 tcp
$PORT -1
5921 fi ;; # NUMCOND, feats
5926 NAME
=OPENSSLCERTSERVER
5928 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%openssl
%*|
*%$NAME%*)
5929 TEST
="$NAME: security of SSL-L with client certificate"
5930 if ! eval $NUMCOND; then :;
5931 elif ! testaddrs openssl
>/dev
/null
; then
5932 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5933 numCANT
=$
((numCANT
+1))
5937 testserversec
"$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,fork,retry=1,$SOCAT_EGD,verify,cert=testsrv.crt,key=testsrv.key" "cafile=testcli.crt" "cafile=testsrv.crt" "SSL:$LOCALHOST:$PORT,cafile=testsrv.crt,cert=testcli.pem,$SOCAT_EGD" 4 tcp
$PORT -1
5938 fi ;; # NUMCOND, feats
5943 NAME
=OPENSSLCERTCLIENT
5945 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%openssl
%*|
*%$NAME%*)
5946 TEST
="$NAME: security of SSL with server certificate"
5947 if ! eval $NUMCOND; then :;
5948 elif ! testaddrs openssl
>/dev
/null
; then
5949 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5950 numCANT
=$
((numCANT
+1))
5954 testserversec
"$N" "$TEST" "$opts -lu -d" "ssl:$LOCALHOST:$PORT,pf=ip4,fork,retry=2,verify,cert=testcli.pem,$SOCAT_EGD" "cafile=testsrv.crt" "cafile=testcli.crt" "ssl-l:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cafile=testcli.crt,cert=testsrv.crt,key=testsrv.key" 4 tcp
"" -1
5955 fi ;; # NUMCOND, feats
5961 NAME
=OPENSSLTCP6_RANGE
5963 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%openssl
%*|
*%range
%*|
*%$NAME%*)
5964 TEST
="$NAME: security of SSL-L over TCP/IPv6 with RANGE option"
5965 if ! eval $NUMCOND; then :;
5966 elif ! testaddrs openssl
>/dev
/null
; then
5967 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5968 numCANT
=$
((numCANT
+1))
5969 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
5970 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5971 numCANT
=$
((numCANT
+1))
5973 gentestcert6 testsrv6
5974 testserversec
"$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "range=[::2]/128" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp
$PORT -1
5975 fi ;; # NUMCOND, feats
5980 NAME
=OPENSSLTCP6_SOURCEPORT
5982 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%openssl
%*|
*%sourceport
%*|
*%$NAME%*)
5983 TEST
="$NAME: security of SSL-L over TCP/IPv6 with SOURCEPORT option"
5984 if ! eval $NUMCOND; then :;
5985 elif ! testaddrs openssl
>/dev
/null
; then
5986 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
5987 numCANT
=$
((numCANT
+1))
5988 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
5989 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
5990 numCANT
=$
((numCANT
+1))
5992 gentestcert6 testsrv6
5993 testserversec
"$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "sp=$PORT" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp
$PORT -1
5994 fi ;; # NUMCOND, feats
5999 NAME
=OPENSSLTCP6_LOWPORT
6001 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%openssl
%*|
*%lowport
%*|
*%$NAME%*)
6002 TEST
="$NAME: security of SSL-L over TCP/IPv6 with LOWPORT option"
6003 if ! eval $NUMCOND; then :;
6004 elif ! testaddrs openssl
>/dev
/null
; then
6005 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6006 numCANT
=$
((numCANT
+1))
6007 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
6008 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6009 numCANT
=$
((numCANT
+1))
6011 gentestcert6 testsrv6
6012 testserversec
"$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "lowport" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp
$PORT -1
6013 fi ;; # NUMCOND, feats
6018 NAME
=OPENSSLTCP6_TCPWRAP
6020 *%$N%*|
*%functions
%*|
*%security
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%openssl
%*|
*%tcpwrap
%*|
*%$NAME%*)
6021 TEST
="$NAME: security of SSL-L over TCP/IPv6 with TCPWRAP option"
6022 if ! eval $NUMCOND; then :;
6023 elif ! feat
=$
(testaddrs ip6 tcp libwrap openssl
) ||
! runsip6
>/dev
/null
; then
6024 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
6025 numCANT
=$
((numCANT
+1))
6027 gentestcert6 testsrv6
6028 ha
="$td/hosts.allow"
6030 $ECHO "socat: [::2]" >"$ha"
6031 $ECHO "ALL: ALL" >"$hd"
6032 testserversec
"$N" "$TEST" "$opts" "ssl-l:$PORT,pf=ip6,reuseaddr,fork,retry=1,$SOCAT_EGD,verify=0,cert=testsrv6.crt,key=testsrv6.key" "" "tcpwrap-etc=$td" "ssl:[::1]:$PORT,cafile=testsrv6.crt,$SOCAT_EGD" 6 tcp
$PORT -1
6033 fi ;; # NUMCOND, feats
6039 # test security with the openssl-commonname option on client side
6040 NAME
=OPENSSL_CN_CLIENT_SECURITY
6042 *%$N%*|
*%functions
%*|
*%security
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
6043 TEST
="$NAME: security of client openssl-commonname option"
6044 # connect using non matching server name/address with commonname
6045 # options, this should succeed. Then without this option, should fail
6046 if ! eval $NUMCOND; then :;
6047 elif ! testaddrs openssl
>/dev
/null
; then
6048 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6049 numCANT
=$
((numCANT
+1))
6050 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
6051 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6052 numCANT
=$
((numCANT
+1))
6056 testserversec
"$N" "$TEST" "$opts -4" "SSL:127.0.0.1:$PORT,fork,retry=2,verify,cafile=testsrv.crt" "commonname=$LOCALHOST" "" "SSL-L:$PORT,pf=ip4,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0" 4 tcp
"" 0
6057 fi ;; # testaddrs, NUMCOND
6062 # test security with the openssl-commonname option on server side
6063 NAME
=OPENSSL_CN_SERVER_SECURITY
6065 *%$N%*|
*%functions
%*|
*%security
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
6066 TEST
="$NAME: security of server openssl-commonname option"
6067 # connect using with client certificate to server, this should succeed.
6068 # Then use the server with a non matching openssl-commonname option,
6070 if ! eval $NUMCOND; then :;
6071 elif ! testaddrs openssl
>/dev
/null
; then
6072 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6073 numCANT
=$
((numCANT
+1))
6074 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
6075 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6076 numCANT
=$
((numCANT
+1))
6080 testserversec
"$N" "$TEST" "$opts -4" "SSL-L:$PORT,pf=ip4,reuseaddr,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt" "" "commonname=onlyyou" "SSL:$LOCALHOST:$PORT,$REUSEADDR,verify=0,cafile=testsrv.crt,cert=testcli.crt,key=testcli.key" 4 tcp
"" 0
6081 fi ;; # testaddrs, NUMCOND
6087 NAME
=OPENSSL_FIPS_SECURITY
6089 *%$N%*|
*%functions
%*|
*%security
%*|
*%openssl
%*|
*%fips
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
6090 TEST
="$NAME: OpenSSL restrictions by FIPS"
6091 if ! eval $NUMCOND; then :;
6092 elif ! testaddrs openssl
>/dev
/null
; then
6093 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6094 numCANT
=$
((numCANT
+1))
6095 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
6096 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
6097 numCANT
=$
((numCANT
+1))
6098 elif ! testoptions fips
>/dev
/null
; then
6099 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL/FIPS not available${NORMAL}\n" $N
6100 numCANT
=$
((numCANT
+1))
6104 # openssl client accepts a "normal" certificate only when not in fips mode
6105 testserversec
"$N" "$TEST" "$opts" "ssl:$LOCALHOST:$PORT,fork,retry=2,verify,cafile=testsrv.crt" "" "fips" "SSL-L:$PORT,pf=ip4,$REUSEADDR,cert=testsrv.crt,key=testsrv.key" 4 tcp
"" -1
6106 fi ;; # testaddrs, NUMCOND
6114 *%$N%*|
*%functions
%*|
*%$NAME%*)
6115 TEST
="$NAME: give exec'd write-only process a chance to flush (-u)"
6116 testod
"$N" "$TEST" "" exec:"$OD_C" "$opts -u"
6123 *%$N%*|
*%functions
%*|
*%$NAME%*)
6124 TEST
="$NAME: give exec'd write-only process a chance to flush (-U)"
6125 testod
"$N" "$TEST" exec:"$OD_C" "-" "$opts -U"
6132 *%$N%*|
*%filan
%*|
*%$NAME%*)
6133 TEST
="$NAME: check type printed for directories"
6134 if ! eval $NUMCOND; then :; else
6135 te
="$td/test$N.stderr"
6136 printf "test $F_n $TEST... " $N
6137 type=$
($FILAN -f .
2>$te |
tail -n 1 |
awk '{print($2);}')
6138 if [ "$type" = "dir" ]; then
6144 numFAIL
=$
((numFAIL
+1))
6145 listFAIL
="$listFAIL $N"
6154 *%$N%*|
*%filan
%*|
*%$NAME%*)
6155 TEST
="$NAME: capability to analyze named unix socket"
6156 if ! eval $NUMCOND; then :; else
6157 ts
="$td/test$N.socket"
6158 te1
="$td/test$N.stderr1" # socat
6159 te2
="$td/test$N.stderr2" # filan
6160 printf "test $F_n $TEST... " $N
6161 $TRACE $SOCAT $opts UNIX-LISTEN
:"$ts" /dev
/null
</dev
/null
2>"$te1" &
6164 type=$
($FILAN -f "$ts" 2>$te2 |
tail -n 1 |
awk '{print($2);}')
6165 if [ "$type" = "socket" ]; then
6172 numFAIL
=$
((numFAIL
+1))
6173 listFAIL
="$listFAIL $N"
6175 kill $spid 2>/dev
/null
6182 testptywaitslave
() {
6185 local PTYTYPE
="$3" # ptmx or openpty
6188 local tp
="$td/test$N.pty"
6189 local ts
="$td/test$N.socket"
6190 local tf
="$td/test$N.file"
6191 local tdiff
="$td/test$N.diff"
6192 local te1
="$td/test$N.stderr1"
6193 local te2
="$td/test$N.stderr2"
6194 local te3
="$td/test$N.stderr3"
6195 local te4
="$td/test$N.stderr4"
6196 local da
="test$N $(date) $RANDOM"
6197 printf "test $F_n $TEST... " $N
6198 # first generate a pty, then a socket
6199 ($TRACE $SOCAT $opts -lpsocat1 pty
,$PTYTYPE,pty-wait-slave
,link
="$tp" unix-listen
:"$ts" 2>"$te1"; rm -f "$tp") 2>/dev
/null
&
6202 # if pty was non-blocking, the socket is active, and socat1 will term
6203 $TRACE $SOCAT $opts -T 10 -lpsocat2 file:/dev
/null unix-connect
:"$ts" 2>"$te2"
6204 # if pty is blocking, first socat is still active and we get a connection now
6205 #((echo "$da"; sleep 2) |$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6206 ( (waitfile
"$ts"; echo "$da"; sleep 1) |
$TRACE $SOCAT -lpsocat3 $opts - file:"$tp",$PTYOPTS2 >"$tf" 2>"$te3") &
6208 # but we need an echoer on the socket
6209 $TRACE $SOCAT $opts -lpsocat4 unix
:"$ts" echo 2>"$te4"
6210 # now $tf file should contain $da
6211 #kill $pid 2>/dev/null
6214 if echo "$da" |
diff - "$tf"> "$tdiff"; then
6218 $PRINTF "${YELLOW}FAILED${NORMAL}\n"
6220 #cat "$te2" # not of interest
6224 numCANT
=$
((numCANT
+1))
6231 *%$N%*|
*%functions
%*|
*%pty
%*|
*%$NAME%*)
6232 TEST
="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6233 if ! eval $NUMCOND; then :; else
6234 if ! feat
=$
(testaddrs pty
); then
6235 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6236 numCANT
=$
((numCANT
+1))
6237 elif ! feat
=$
(testoptions
"$PTYTYPE" pty-wait-slave
); then
6238 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6239 numCANT
=$
((numCANT
+1))
6241 testptywaitslave
"$N" "$TEST" "$PTYTYPE" "$opts"
6247 NAME
=OPENPTYWAITSLAVE
6250 *%$N%*|
*%functions
%*|
*%pty
%*|
*%$NAME%*)
6251 TEST
="$NAME: test if master pty ($PTYTYPE) waits for slave connection"
6252 if ! eval $NUMCOND; then :;
6253 elif ! feat
=$
(testaddrs pty
); then
6254 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6255 numCANT
=$
((numCANT
+1))
6256 elif ! feat
=$
(testoptions
"$PTYTYPE" pty-wait-slave
); then
6257 $PRINTF "test $F_n $TEST... ${YELLOW}option $(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6258 numCANT
=$
((numCANT
+1))
6260 testptywaitslave
"$N" "$TEST" "$PTYTYPE" "$opts"
6261 fi ;; # NUMCOND, feats
6268 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%tcp
%*|
*%timeout
%*|
*%$NAME%*)
6269 TEST
="$NAME: test the connect-timeout option"
6270 if ! eval $NUMCOND; then :;
6271 elif ! feat
=$
(testaddrs tcp
); then
6272 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6273 numCANT
=$
((numCANT
+1))
6274 elif ! feat
=$
(testoptions connect-timeout
); then
6275 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6276 numCANT
=$
((numCANT
+1))
6278 # we need a hanging connection attempt, guess an address for this
6280 Linux
) HANGIP
=1.0.0.1 ;;
6281 *) HANGIP
=255.255.255.254 ;;
6283 te1
="$td/test$N.stderr1"
6284 tk1
="$td/test$N.kill1"
6285 te2
="$td/test$N.stderr2"
6286 tk2
="$td/test$N.kill2"
6287 $PRINTF "test $F_n $TEST... " $N
6288 # first, try to make socat hang and see if it can be killed
6289 #$TRACE $SOCAT $opts - tcp:$HANGIP:1 >"$te1" 2>&1 </dev/null &
6290 CMD
="$TRACE $SOCAT $opts - tcp:$HANGIP:1"
6291 $CMD >"$te1" 2>&1 </dev
/null
&
6294 if ! kill $pid1 2>"$tk1"; then
6295 $PRINTF "${YELLOW}does not hang${NORMAL}\n"
6296 numCANT
=$
((numCANT
+1))
6298 # second, set connect-timeout and see if socat exits before kill
6299 $TRACE $SOCAT $opts - tcp
:$HANGIP:1,connect-timeout
=1.0 >"$te2" 2>&1 </dev
/null
&
6302 if kill $pid2 2>"$tk2"; then
6307 numFAIL
=$
((numFAIL
+1))
6308 listFAIL
="$listFAIL $N"
6315 fi ;; # testaddrs, NUMCOND
6320 # version 1.7.0.0 had a bug with the connect-timeout option: while it correctly
6321 # terminated a hanging connect attempt, it prevented a successful connection
6322 # establishment from being recognized by socat, instead the timeout occurred
6323 NAME
=CONNECTTIMEOUT_CONN
6324 if ! eval $NUMCOND; then :; else
6326 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%tcp
%*|
*%timeout
%*|
*%$NAME%*)
6327 TEST
="$NAME: TCP4 connect-timeout option when server replies"
6328 # just try a connection that is expected to succeed with the usual data
6329 # transfer; with the bug it will fail
6330 tf
="$td/test$N.stdout"
6331 te
="$td/test$N.stderr"
6332 tdiff
="$td/test$N.diff"
6335 da
="test$N $(date) $RANDOM"
6336 CMD1
="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
6337 CMD2
="$TRACE $SOCAT $opts STDIO TCP4:$ts,connect-timeout=1"
6338 printf "test $F_n $TEST... " $N
6339 $CMD1 >"$tf" 2>"${te}1" &
6342 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
6343 if [ $?
-ne 0 ]; then
6344 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6349 numFAIL
=$
((numFAIL
+1))
6350 listFAIL
="$listFAIL $N"
6351 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
6354 numFAIL
=$
((numFAIL
+1))
6355 listFAIL
="$listFAIL $N"
6358 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
6361 kill $pid1 2>/dev
/null
6369 NAME
=OPENSSLLISTENDSA
6371 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%$NAME%*)
6372 TEST
="$NAME: openssl listen with DSA certificate"
6373 if ! eval $NUMCOND; then :;
6374 elif ! testaddrs openssl
>/dev
/null
; then
6375 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
6376 numCANT
=$
((numCANT
+1))
6379 gentestdsacert
$SRVCERT
6380 tf
="$td/test$N.stdout"
6381 te
="$td/test$N.stderr"
6382 tdiff
="$td/test$N.diff"
6383 da
="test$N $(date) $RANDOM"
6384 CMD2
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,$REUSEADDR,$SOCAT_EGD,cert=$SRVCERT.pem,key=$SRVCERT.key,verify=0 pipe"
6385 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
6386 $PRINTF "test $F_n $TEST... " $N
6387 eval "$CMD2 2>\"${te}1\" &"
6388 pid
=$
! # background process id
6390 echo "$da" |
$CMD >$tf 2>"${te}2"
6391 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
6398 numFAIL
=$
((numFAIL
+1))
6399 listFAIL
="$listFAIL $N"
6402 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
6405 kill $pid 2>/dev
/null
6407 fi ;; # testaddrs, NUMCOND
6413 # derive signal number from signal name
6414 # kill -l should provide the info
6416 if [ ! "$BASH_VERSION" -o -o posix
]; then
6418 for i
in $
(POSIXLY_CORRECT
=1 kill -l); do echo "$i"; done |
grep -n -i "^$1$" |cut
-d: -f1
6421 # " 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL"
6423 kill -l </dev
/null |
6424 while read l
; do printf "%s %s\n%s %s\n%s %s\n%s %s\n" $l; done |
6425 grep -e "SIG$signam\$" |
6430 # problems with QUIT, INT (are blocked in system() )
6431 for signam
in TERM ILL
; do
6432 NAME
=EXITCODESIG
$signam
6434 *%$N%*|
*%functions
%*|
*%pty
%*|
*%signal
%*|
*%$NAME%*)
6435 TEST
="$NAME: exit status when dying on SIG$signam"
6436 if ! eval $NUMCOND; then :;
6437 elif ! feat
=$
(testaddrs pty
); then
6438 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
6439 numCANT
=$
((numCANT
+1))
6441 SIG
="$(signum $signam)"
6442 te
="$td/test$N.stderr"
6443 tpp
="$td/test$N.ppid"
6445 $PRINTF "test $F_n $TEST... " $N
6446 (sleep 1; kill -"$SIG" "$(cat "$tpp")") &
6447 # a simple "system:echo $PPID..." does not work on NetBSD, OpenBSD
6448 #$TRACE $SOCAT $opts echo SYSTEM:'exec /usr/bin/env bash -c "echo \$PPID '">$tpp"'; echo \$$ '">$tp; read x\"",nofork 2>"$te"; stat=$?
6451 #! /usr/bin/env bash
6457 #$TRACE $SOCAT $opts echo SYSTEM:"exec \"$tsh\"",pty,setsid,nofork 2>"$te"; stat=$?
6458 CMD
="$TRACE $SOCAT $opts ECHO SYSTEM:\"exec\\\ \\\"$tsh\\\"\",pty,setsid,nofork"
6459 $TRACE $SOCAT $opts ECHO SYSTEM
:"exec \"$tsh\"",pty
,setsid
,nofork
2>"$te"
6461 sleep 1; kill -INT $
(cat $tp)
6463 if [ "$stat" -eq $
((128+$SIG)) ]; then
6470 numFAIL
=$
((numFAIL
+1))
6471 listFAIL
="$listFAIL $N"
6474 fi ;; # NUMCOND, feats
6483 *%$N%*|
*%functions
%*|
*%$NAME%*)
6484 TEST
="$NAME: restrict reading from file with bytes option"
6485 if ! eval $NUMCOND; then :;
6487 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
6488 numCANT
=$
((numCANT
+1))
6494 tdiff
="$td/test$N.diff"
6495 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
6496 # the feature that we really want to test is in the readline.sh script:
6497 CMD
="$TRACE $SOCAT $opts -u open:$ti,readbytes=100 -"
6498 printf "test $F_n $TEST... " $N
6499 rm -f "$tf" "$ti" "$to"
6501 echo "AAAAAAAAAAAAAAAAAAAAAAAA
6502 AAAAAAAAAAAAAAAAAAAAAAAA
6503 AAAAAAAAAAAAAAAAAAAAAAAA
6504 AAAAAAAAAAAAAAAAAAAAAAAA" >"$tr" # 100 bytes
6505 cat "$tr" "$tr" >"$ti" # 200 bytes
6507 if ! diff "$tr" "$to" >"$tdiff" 2>&1; then
6508 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6512 numFAIL
=$
((numFAIL
+1))
6513 listFAIL
="$listFAIL $N"
6516 if [ -n "$debug" ]; then cat $te; fi
6519 fi ;; # NUMCOND, feats
6526 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%udp
%*|
*%listen
%*|
*%fork
%*|
*%$NAME%*)
6527 TEST
="$NAME: UDP socket rebinds after first connection"
6528 if ! eval $NUMCOND; then :; else
6529 tf
="$td/test$N.stdout"
6530 te
="$td/test$N.stderr"
6531 tdiff
="$td/test$N.diff"
6532 da1
="test$N $(date) $RANDOM"
6533 da2
="test$N $(date) $RANDOM"
6534 #establish a listening and forking udp socket in background
6535 #processes hang forever without -T
6536 SRV
="$TRACE $SOCAT -T 5 $opts -lpserver UDP4-LISTEN:$PORT,bind=$LOCALHOST,$REUSEADDR,fork PIPE"
6537 #make a first and a second connection
6538 CLI
="$TRACE $SOCAT $opts -lpclient - UDP4-CONNECT:$LOCALHOST:$PORT"
6539 $PRINTF "test $F_n $TEST... " $N
6540 eval "$SRV 2>${te}s &"
6542 waitudp4port
"$PORT"
6543 echo "$da1" |
eval "$CLI" >"${tf}1" 2>"${te}1"
6544 if [ $?
-ne 0 ]; then
6545 kill "$pids" 2>/dev
/null
6546 $PRINTF "$NO_RESULT (first conn failed):\n"
6549 cat "${te}s" "${te}1"
6550 numCANT
=$
((numCANT
+1))
6551 elif ! echo "$da1" |
diff - "${tf}1" >"$tdiff"; then
6552 kill "$pids" 2>/dev
/null
6553 $PRINTF "$NO_RESULT (first conn failed); diff:\n"
6555 numCANT
=$
((numCANT
+1))
6557 sleep 2 # UDP-LISTEN sleeps 1s
6558 echo "$da2" |
eval "$CLI" >"${tf}2" 2>"${te}2"
6559 rc
="$?"; kill "$pids" 2>/dev
/null
6560 if [ $rc -ne 0 ]; then
6561 $PRINTF "$FAILED:\n"
6564 cat "${te}s" "${te}2"
6565 numFAIL
=$
((numFAIL
+1))
6566 listFAIL
="$listFAIL $N"
6567 elif ! echo "$da2" |
diff - "${tf}2" >"$tdiff"; then
6568 $PRINTF "$FAILED: diff\n"
6570 numFAIL
=$
((numFAIL
+1))
6571 listFAIL
="$listFAIL $N"
6578 fi ;; # NUMCOND, feats
6584 # is a listen address capable of forking to child processes and have both
6586 while read PROTOV MAJADDR MINADDR
; do
6587 if [ -z "$PROTOV" ] ||
[[ "$PROTOV" == \
#* ]]; then continue; fi
6588 protov
="$(echo "$PROTOV" |tr A-Z a-z)"
6589 proto
="${protov%%[0-9]}"
6590 NAME
=${PROTOV}LISTENFORK
6592 *%$N%*|
*%functions
%*|
*%$protov%*|
*%$proto%*|
*%listen
%*|
*%fork
%*|
*%$NAME%*)
6593 TEST
="$NAME: $PROTOV listen handles 2 concurrent connections"
6594 # have a listening address with fork option. connect with client1, send a piece
6595 # of data, wait 1s, connect with client2, send another piece of data, wait 1s,
6596 # and send another piece of data with client1. The server processes append all
6597 # data to the same file. Check all data are written to the file in correct
6599 if ! eval $NUMCOND; then :;
6600 #elif ! feat=$(testaddrs $PROTOV); then
6601 # $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$PROTOV" |tr a-z A-Z) not available${NORMAL}\n" $N
6602 # numCANT=$((numCANT+1))
6603 elif ! runs
$protov; then
6604 $PRINTF "test $F_n $TEST... ${YELLOW}$PROTOV not available${NORMAL}\n" $N
6605 numCANT
=$
((numCANT
+1))
6607 ts
="$td/test$N.sock"
6608 tref
="$td/test$N.ref"
6609 tf
="$td/test$N.stdout"
6610 te
="$td/test$N.stderr"
6611 tdiff
="$td/test$N.diff"
6612 da1a
="test$N $(date) 1a $RANDOM"
6613 da1b
="test$N $(date) 1b $RANDOM"
6614 da2
="test$N $(date) 2 $RANDOM"
6624 tla
="$PORT,bind=$MAJADDR"
6625 tca
="$MAJADDR:$PORT"
6626 waitproto
="${protov}port"
6630 echo -e "$da1a\n$da2\n$da1b" >"$tref"
6631 # establish a listening and forking listen socket in background
6632 # UDP processes hang forever without -T
6633 CMD0
="$TRACE $SOCAT -T 5 $opts -lpserver $PROTOV-LISTEN:$tla,$REUSEADDR,fork PIPE"
6634 # make a first and a second connection
6635 CMD1
="$TRACE $SOCAT $opts -lpclient - $PROTOV-CONNECT:$tca"
6636 $PRINTF "test $F_n $TEST... " $N
6637 eval "$CMD0 2>${te}0 &"
6639 wait$waitproto "$waitfor" 1 2
6640 (echo "$da1a"; sleep 2; echo "$da1b") |
eval "$CMD1" >>"${tf}" 2>"${te}1" &
6642 # trailing sleep req for sctp because no half close
6643 (echo "$da2"; sleep 1) |
eval "$CMD1" >>"${tf}" 2>"${te}2" &
6645 kill $pid0 2>/dev
/null
6647 if ! diff "$tref" "$tf" >"$tdiff"; then
6649 cat "${te}0" "${te}1" "${te}2"
6651 numFAIL
=$
((numFAIL
+1))
6652 listFAIL
="$listFAIL $N"
6658 fi ;; # NUMCOND, feats
6663 TCP4 $LOCALHOST PORT
6664 TCP6 $LOCALHOST6 PORT
6665 UDP4 $LOCALHOST PORT
6666 UDP6 $LOCALHOST6 PORT
6667 SCTP4 $LOCALHOST PORT
6668 SCTP6 $LOCALHOST6 PORT
6675 *%$N%*|
*%functions
%*|
*%unix
%*|
*%listen
%*|
*%$NAME%*)
6676 TEST
="$NAME: generic UNIX client connects to stream socket"
6677 if ! eval $NUMCOND; then :; else
6678 ts
="$td/test$N.socket"
6679 tf
="$td/test$N.stdout"
6680 te
="$td/test$N.stderr"
6681 tdiff
="$td/test$N.diff"
6682 da1
="test$N $(date) $RANDOM"
6683 #establish a listening unix socket in background
6684 SRV
="$TRACE $SOCAT $opts -lpserver UNIX-LISTEN:\"$ts\" PIPE"
6686 CLI
="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts\""
6687 $PRINTF "test $F_n $TEST... " $N
6688 eval "$SRV 2>${te}s &"
6691 echo "$da1" |
eval "$CLI" >"${tf}1" 2>"${te}1"
6692 if [ $?
-ne 0 ]; then
6693 kill "$pids" 2>/dev
/null
6694 $PRINTF "$FAILED:\n"
6697 cat "${te}s" "${te}1"
6698 numFAIL
=$
((numFAIL
+1))
6699 listFAIL
="$listFAIL $N"
6700 elif ! echo "$da1" |
diff - "${tf}1" >"$tdiff"; then
6701 kill "$pids" 2>/dev
/null
6702 $PRINTF "$FAILED; diff:\n"
6704 numFAIL
=$
((numFAIL
+1))
6705 listFAIL
="$listFAIL $N"
6718 *%$N%*|
*%functions
%*|
*%engine
%*|
*%unix
%*|
*%recv
%*|
*%$NAME%*)
6719 TEST
="$NAME: generic UNIX client connects to datagram socket"
6720 if ! eval $NUMCOND; then :; else
6721 ts1
="$td/test$N.socket1"
6722 ts2
="$td/test$N.socket2"
6723 tf
="$td/test$N.stdout"
6724 te
="$td/test$N.stderr"
6725 tdiff
="$td/test$N.diff"
6726 da1
="test$N $(date) $RANDOM"
6727 #establish a receiving unix datagram socket in background
6728 SRV
="$TRACE $SOCAT $opts -lpserver UNIX-RECVFROM:\"$ts1\" PIPE"
6730 CLI
="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\",bind=\"$ts2\""
6731 #CLI="$TRACE $SOCAT $opts -lpclient - UNIX:\"$ts1\""
6732 $PRINTF "test $F_n $TEST... " $N
6733 eval "$SRV 2>${te}s &"
6736 echo "$da1" |
eval "$CLI" >"${tf}1" 2>"${te}1"
6739 if [ $rc -ne 0 ]; then
6740 kill "$pids" 2>/dev
/null
6741 $PRINTF "$FAILED:\n"
6745 cat "${te}1" "${te}1"
6746 numFAIL
=$
((numFAIL
+1))
6747 listFAIL
="$listFAIL $N"
6748 elif ! echo "$da1" |
diff - "${tf}1" >"$tdiff"; then
6749 kill "$pids" 2>/dev
/null
6750 $PRINTF "$FAILED:\n"
6756 numFAIL
=$
((numFAIL
+1))
6757 listFAIL
="$listFAIL $N"
6767 # there was an error in address EXEC with options pipes,stderr
6768 NAME
=EXECPIPESSTDERR
6770 *%$N%*|
*%functions
%*|
*%$NAME%*)
6771 TEST
="$NAME: simple echo via exec of cat with pipes,stderr"
6772 # this test is known to fail when logging is enabled with OPTS/opts env var.
6774 opts
="$(echo "$opts" |sed 's/-d//g')"
6775 testecho
"$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
6780 # EXEC and SYSTEM with stderr injected socat messages into the data stream.
6783 *%$N%*|
*%functions
%*|
*%$NAME%*)
6784 TEST
="$NAME: simple echo via exec of cat with pipes,stderr"
6786 # make sure at least two -d are there
6789 *-d*) opts
="$opts -d" ;;
6792 testecho
"$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts"
6800 *%$N%*|
*%functions
%*|
*%PARSE
%*|
*%$NAME%*)
6801 TEST
="$NAME: invoke socat from socat"
6802 testecho
"$N" "$TEST" "" exec:"$SOCAT - exec\:$CAT,pipes" "$opts"
6809 *%$N%*|
*%functions
%*|
*%parse
%*|
*%$NAME%*)
6810 TEST
="$NAME: correctly parse special chars"
6811 if ! eval $NUMCOND; then :; else
6812 $PRINTF "test $F_n $TEST... " $N
6813 tf
="$td/test$N.stdout"
6814 te
="$td/test$N.stderr"
6815 tdiff
="$td/test$N.diff"
6816 # a string where commas are hidden in nesting lexical constructs
6817 # if they are scanned incorrectly, socat will see an "unknown option"
6818 dain
='(,)[,]{,}","([),])hugo'
6819 daout
='(,)[,]{,},([),])hugo'
6820 $TRACE "$SOCAT" $opts -u "exec:echo $dain" - >"$tf" 2>"$te"
6822 echo "$daout" |
diff "$tf" - >"$tdiff"
6823 if [ "$rc" -ne 0 ]; then
6824 $PRINTF "$FAILED:\n"
6825 echo "$TRACE $SOCAT" -u "exec:echo $da" -
6827 numFAIL
=$
((numFAIL
+1))
6828 listFAIL
="$listFAIL $N"
6829 elif [ -s "$tdiff" ]; then
6830 $PRINTF "$FAILED:\n"
6833 if [ -n "$debug" ]; then cat $te; fi
6834 numFAIL
=$
((numFAIL
+1))
6835 listFAIL
="$listFAIL $N"
6838 if [ -n "$debug" ]; then cat $te; fi
6845 NAME
=NESTEDSOCATEXEC
6847 *%parse
%*|
*%$N%*|
*%functions
%*|
*%$NAME%*)
6848 TEST
="$NAME: does lexical analysis work sensibly (exec)"
6849 testecho
"$N" "$TEST" "" "exec:'$SOCAT - exec:$CAT,pipes'" "$opts" 1
6853 NAME
=NESTEDSOCATSYSTEM
6855 *%parse
%*|
*%$N%*|
*%functions
%*|
*%$NAME%*)
6856 TEST
="$NAME: does lexical analysis work sensibly (system)"
6857 testecho
"$N" "$TEST" "" "system:\"$SOCAT - exec:$CAT,pipes\"" "$opts" 1
6864 *%$N%*|
*%functions
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%$NAME%*)
6865 TEST
="$NAME: TCP4 mapped into TCP6 address space"
6866 if ! eval $NUMCOND; then :;
6868 $PRINTF "test $F_n $TEST... ${YELLOW}Feature reoved${NORMAL}\n" $N
6869 elif ! testaddrs tcp ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
6870 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6871 numCANT
=$
((numCANT
+1))
6873 tf
="$td/test$N.stdout"
6874 te
="$td/test$N.stderr"
6875 tdiff
="$td/test$N.diff"
6878 da
="test$N $(date) $RANDOM"
6879 CMD1
="$TRACE $SOCAT $opts TCP6-listen:$tsl,$REUSEADDR PIPE"
6880 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP6:$ts"
6881 printf "test $F_n $TEST... " $N
6882 $CMD1 >"$tf" 2>"${te}1" &
6883 pid
=$
! # background process id
6885 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
6886 if [ $?
-ne 0 ]; then
6887 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6892 numFAIL
=$
((numFAIL
+1))
6893 listFAIL
="$listFAIL $N"
6894 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
6895 $PRINTF "$FAILED: diff:\n"
6897 numFAIL
=$
((numFAIL
+1))
6898 listFAIL
="$listFAIL $N"
6901 if [ -n "$debug" ]; then cat $te; fi
6904 kill $pid 2>/dev
/null
; wait
6905 fi ;; # NUMCOND, feats
6911 # test the UDP4-SENDTO and UDP4-RECVFROM addresses together
6914 *%$N%*|
*%functions
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%dgram
%*|
*%$NAME%*)
6915 TEST
="$NAME: UDP/IPv4 sendto and recvfrom"
6916 # start a UDP4-RECVFROM process that echoes data, and send test data using
6917 # UDP4-SENDTO. The sent data should be returned.
6918 if ! eval $NUMCOND; then :; else
6919 tf
="$td/test$N.stdout"
6920 te
="$td/test$N.stderr"
6921 tdiff
="$td/test$N.diff"
6922 ts1p
=$PORT; PORT
=$
((PORT
+1))
6925 ts2p
=$PORT; PORT
=$
((PORT
+1))
6926 ts2
="127.0.0.1:$ts2p"
6927 da
="test$N $(date) $RANDOM"
6928 CMD1
="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
6929 CMD2
="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=$ts2"
6930 printf "test $F_n $TEST... " $N
6933 waitudp4port
$ts1p 1
6934 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
6936 kill "$pid1" 2>/dev
/null
; wait;
6937 if [ "$rc2" -ne 0 ]; then
6938 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6943 numFAIL
=$
((numFAIL
+1))
6944 listFAIL
="$listFAIL $N"
6945 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
6952 numFAIL
=$
((numFAIL
+1))
6953 listFAIL
="$listFAIL $N"
6956 if [ -n "$debug" ]; then cat $te; fi
6968 *%$N%*|
*%functions
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%dgram
%*|
*%$NAME%*)
6969 TEST
="$NAME: UDP/IPv6 datagram"
6970 if ! eval $NUMCOND; then :;
6971 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
6972 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
6973 numCANT
=$
((numCANT
+1))
6975 tf
="$td/test$N.stdout"
6976 te
="$td/test$N.stderr"
6977 tdiff
="$td/test$N.diff"
6978 ts1p
=$PORT; PORT
=$
((PORT
+1))
6981 ts2p
=$PORT; PORT
=$
((PORT
+1))
6983 da
="test$N $(date) $RANDOM"
6984 CMD1
="$TRACE $SOCAT $opts UDP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
6985 CMD2
="$TRACE $SOCAT $opts - UDP6-SENDTO:$ts1,bind=$ts2"
6986 printf "test $F_n $TEST... " $N
6988 waitudp6port
$ts1p 1
6989 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
6990 if [ $?
-ne 0 ]; then
6991 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
6996 numFAIL
=$
((numFAIL
+1))
6997 listFAIL
="$listFAIL $N"
6998 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7001 numFAIL
=$
((numFAIL
+1))
7002 listFAIL
="$listFAIL $N"
7005 if [ -n "$debug" ]; then cat ${te}1 ${te}2; fi
7008 fi ;; # NUMCOND, feats
7016 *%$N%*|
*%functions
%*|
*%ip
%*|
*%ip4
%*|
*%rawip
%*|
*%rawip4
%*|
*%dgram
%*|
*%root
%*|
*%$NAME%*)
7017 TEST
="$NAME: raw IPv4 datagram"
7018 if ! eval $NUMCOND; then :;
7019 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7020 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7021 numCANT
=$
((numCANT
+1))
7023 tf
="$td/test$N.stdout"
7024 te
="$td/test$N.stderr"
7025 tdiff
="$td/test$N.diff"
7026 ts1p
=$PROTO; PROTO
=$
((PROTO
+1))
7031 da
="test$N $(date) $RANDOM"
7032 CMD1
="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE"
7033 CMD2
="$TRACE $SOCAT $opts - IP4-SENDTO:$ts1,bind=$ts2a"
7034 printf "test $F_n $TEST... " $N
7037 waitip4proto
$ts1p 1
7038 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
7040 kill $pid1 2>/dev
/null
; wait
7041 if [ $rc2 -ne 0 ]; then
7042 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7047 numFAIL
=$
((numFAIL
+1))
7048 listFAIL
="$listFAIL $N"
7049 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7052 numFAIL
=$
((numFAIL
+1))
7053 listFAIL
="$listFAIL $N"
7056 if [ -n "$debug" ]; then cat $te; fi
7059 fi ;; # root, NUMCOND
7067 *%$N%*|
*%functions
%*|
*%ip
%*|
*%ip6
%*|
*%rawip
%*|
*%rawip6
%*|
*%dgram
%*|
*%root
%*|
*%$NAME%*)
7068 TEST
="$NAME: raw IPv6 datagram by self addressing"
7069 if ! eval $NUMCOND; then :;
7070 elif ! feat
=$
(testaddrs ip6 rawip
) ||
! runsip6
>/dev
/null
; then
7071 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7072 numCANT
=$
((numCANT
+1))
7073 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7074 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7075 numCANT
=$
((numCANT
+1))
7077 tf
="$td/test$N.stdout"
7078 te
="$td/test$N.stderr"
7079 tdiff
="$td/test$N.diff"
7080 ts1p
=$PROTO; PROTO
=$
((PROTO
+1))
7084 da
="test$N $(date) $RANDOM"
7085 #CMD1="$TRACE $SOCAT $opts IP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE"
7086 CMD2
="$TRACE $SOCAT $opts - IP6-SENDTO:$ts1,bind=$ts2"
7087 printf "test $F_n $TEST... " $N
7089 waitip6proto
$ts1p 1
7090 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
7091 if [ $?
-ne 0 ]; then
7092 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7097 numFAIL
=$
((numFAIL
+1))
7098 listFAIL
="$listFAIL $N"
7099 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7102 numFAIL
=$
((numFAIL
+1))
7103 listFAIL
="$listFAIL $N"
7106 if [ -n "$debug" ]; then cat "$te"; fi
7109 fi ;; # root, NUMCOND
7117 *%$N%*|
*%functions
%*|
*%engine
%*|
*%unix
%*|
*%dgram
%*|
*%$NAME%*)
7118 TEST
="$NAME: UNIX datagram"
7119 if ! eval $NUMCOND; then :; else
7120 tf
="$td/test$N.stdout"
7121 te
="$td/test$N.stderr"
7122 tdiff
="$td/test$N.diff"
7123 ts1
="$td/test$N.socket1"
7124 ts2
="$td/test$N.socket2"
7125 da
="test$N $(date) $RANDOM"
7126 CMD1
="$TRACE $SOCAT $opts UNIX-RECVFROM:$ts1,reuseaddr PIPE"
7127 CMD2
="$TRACE $SOCAT $opts - UNIX-SENDTO:$ts1,bind=$ts2"
7128 printf "test $F_n $TEST... " $N
7132 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
7134 kill "$pid1" 2>/dev
/null
; wait
7135 if [ $rc2 -ne 0 ]; then
7136 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7141 numFAIL
=$
((numFAIL
+1))
7142 listFAIL
="$listFAIL $N"
7143 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7146 numFAIL
=$
((numFAIL
+1))
7147 listFAIL
="$listFAIL $N"
7150 if [ -n "$debug" ]; then cat $te; fi
7161 *%$N%*|
*%functions
%*|
*%engine
%*|
*%ip4
%*|
*%dgram
%*|
*%udp
%*|
*%udp4
%*|
*%recv
%*|
*%$NAME%*)
7162 TEST
="$NAME: UDP/IPv4 receive"
7163 if ! eval $NUMCOND; then :; else
7164 tf
="$td/test$N.stdout"
7165 te
="$td/test$N.stderr"
7166 tdiff
="$td/test$N.diff"
7167 ts1p
=$PORT; PORT
=$
((PORT
+1))
7170 da
="test$N $(date) $RANDOM"
7171 CMD1
="$TRACE $SOCAT $opts -u UDP4-RECV:$ts1p,reuseaddr -"
7172 CMD2
="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1"
7173 printf "test $F_n $TEST... " $N
7174 $CMD1 >"$tf" 2>"${te}1" &
7176 waitudp4port
$ts1p 1
7177 echo "$da" |
$CMD2 2>>"${te}2"
7180 i
=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i
=$
((i
+1)); done
7181 kill "$pid1" 2>/dev
/null
; wait
7182 if [ "$rc2" -ne 0 ]; then
7183 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7188 numFAIL
=$
((numFAIL
+1))
7189 listFAIL
="$listFAIL $N"
7190 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7197 numFAIL
=$
((numFAIL
+1))
7198 listFAIL
="$listFAIL $N"
7201 if [ -n "$debug" ]; then cat $te; fi
7212 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%dgram
%*|
*%udp
%*|
*%udp6
%*|
*%recv
%*|
*%$NAME%*)
7213 TEST
="$NAME: UDP/IPv6 receive"
7214 if ! eval $NUMCOND; then :;
7215 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
7216 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7217 numCANT
=$
((numCANT
+1))
7219 tf
="$td/test$N.stdout"
7220 te
="$td/test$N.stderr"
7221 tdiff
="$td/test$N.diff"
7222 ts1p
=$PORT; PORT
=$
((PORT
+1))
7225 da
="test$N $(date) $RANDOM"
7226 CMD1
="$TRACE $SOCAT $opts -u UDP6-RECV:$ts1p,reuseaddr -"
7227 CMD2
="$TRACE $SOCAT $opts -u - UDP6-SENDTO:$ts1"
7228 printf "test $F_n $TEST... " $N
7229 $CMD1 >"$tf" 2>"${te}1" &
7231 waitudp6port
$ts1p 1
7232 echo "$da" |
$CMD2 2>>"${te}2"
7235 i
=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i
=$
((i
+1)); done
7236 kill "$pid1" 2>/dev
/null
; wait
7237 if [ "$rc2" -ne 0 ]; then
7238 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7243 numFAIL
=$
((numFAIL
+1))
7244 listFAIL
="$listFAIL $N"
7245 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7248 numFAIL
=$
((numFAIL
+1))
7249 listFAIL
="$listFAIL $N"
7252 if [ -n "$debug" ]; then cat $te; fi
7255 fi ;; # NUMCOND, feats
7262 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%dgram
%*|
*%rawip
%*|
*%rawip4
%*|
*%recv
%*|
*%root
%*|
*%$NAME%*)
7263 TEST
="$NAME: raw IPv4 receive"
7264 if ! eval $NUMCOND; then :;
7265 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7266 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7267 numCANT
=$
((numCANT
+1))
7269 tf
="$td/test$N.stdout"
7270 te
="$td/test$N.stderr"
7271 tdiff
="$td/test$N.diff"
7272 ts1p
=$PROTO; PROTO
=$
((PROTO
+1))
7275 da
="test$N $(date) $RANDOM"
7276 CMD1
="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,reuseaddr -"
7277 CMD2
="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
7278 printf "test $F_n $TEST... " $N
7279 $CMD1 >"$tf" 2>"${te}1" &
7281 waitip4proto
$ts1p 1
7282 echo "$da" |
$CMD2 2>>"${te}2"
7285 i
=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i
=$
((i
+1)); done
7286 kill "$pid1" 2>/dev
/null
; wait
7287 if [ "$rc2" -ne 0 ]; then
7288 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7293 numFAIL
=$
((numFAIL
+1))
7294 listFAIL
="$listFAIL $N"
7295 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7298 numFAIL
=$
((numFAIL
+1))
7299 listFAIL
="$listFAIL $N"
7302 if [ -n "$debug" ]; then cat $te; fi
7305 fi ;; # NUMCOND, root
7312 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%dgram
%*|
*%rawip
%*|
*%rawip6
%*|
*%recv
%*|
*%root
%*|
*%$NAME%*)
7313 TEST
="$NAME: raw IPv6 receive"
7314 if ! eval $NUMCOND; then :;
7315 elif ! feat
=$
(testaddrs ip6 rawip
) ||
! runsip6
>/dev
/null
; then
7316 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7317 numCANT
=$
((numCANT
+1))
7318 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7319 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7320 numCANT
=$
((numCANT
+1))
7322 tf
="$td/test$N.stdout"
7323 te
="$td/test$N.stderr"
7324 tdiff
="$td/test$N.diff"
7325 ts1p
=$PROTO; PROTO
=$
((PROTO
+1))
7328 da
="test$N $(date) $RANDOM"
7329 CMD1
="$TRACE $SOCAT $opts -u IP6-RECV:$ts1p,reuseaddr -"
7330 CMD2
="$TRACE $SOCAT $opts -u - IP6-SENDTO:$ts1"
7331 printf "test $F_n $TEST... " $N
7332 $CMD1 >"$tf" 2>"${te}1" &
7334 waitip6proto
$ts1p 1
7335 echo "$da" |
$CMD2 2>>"${te}2"
7337 i
=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i
=$
((i
+1)); done
7338 kill "$pid1" 2>/dev
/null
; wait
7339 if [ "$rc2" -ne 0 ]; then
7340 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7345 numFAIL
=$
((numFAIL
+1))
7346 listFAIL
="$listFAIL $N"
7347 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7350 numFAIL
=$
((numFAIL
+1))
7351 listFAIL
="$listFAIL $N"
7354 if [ -n "$debug" ]; then cat $te; fi
7357 fi ;; # NUMCOND, root
7364 *%$N%*|
*%functions
%*|
*%unix
%*|
*%dgram
%*|
*%recv
%*|
*%$NAME%*)
7365 TEST
="$NAME: UNIX receive"
7366 if ! eval $NUMCOND; then :; else
7367 ts
="$td/test$N.socket"
7368 tf
="$td/test$N.stdout"
7369 te
="$td/test$N.stderr"
7370 tdiff
="$td/test$N.diff"
7372 da
="test$N $(date) $RANDOM"
7373 CMD1
="$TRACE $SOCAT $opts -u UNIX-RECV:$ts1,reuseaddr -"
7374 CMD2
="$TRACE $SOCAT $opts -u - UNIX-SENDTO:$ts1"
7375 printf "test $F_n $TEST... " $N
7376 $CMD1 >"$tf" 2>"${te}1" &
7379 echo "$da" |
$CMD2 2>>"${te}2"
7381 i
=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i
=$
((i
+1)); done
7382 kill "$pid1" 2>/dev
/null
; wait
7383 if [ "$rc2" -ne 0 ]; then
7384 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7389 numFAIL
=$
((numFAIL
+1))
7390 listFAIL
="$listFAIL $N"
7391 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
7394 numFAIL
=$
((numFAIL
+1))
7395 listFAIL
="$listFAIL $N"
7398 if [ -n "$debug" ]; then cat $te; fi
7407 NAME
=UDP4RECVFROM_SOURCEPORT
7409 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%sourceport
%*|
*%$NAME%*)
7410 TEST
="$NAME: security of UDP4-RECVFROM with SOURCEPORT option"
7411 if ! eval $NUMCOND; then :;
7412 elif ! feat
=$
(testaddrs udp ip4
) ||
! runsip4
>/dev
/null
; then
7413 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7414 numCANT
=$
((numCANT
+1))
7416 testserversec
"$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp4-sendto:127.0.0.1:$PORT" 4 udp
$PORT 0
7417 fi ;; # NUMCOND, feats
7422 NAME
=UDP4RECVFROM_LOWPORT
7424 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%lowport
%*|
*%$NAME%*)
7425 TEST
="$NAME: security of UDP4-RECVFROM with LOWPORT option"
7426 if ! eval $NUMCOND; then :;
7427 elif ! feat
=$
(testaddrs udp ip4
) ||
! runsip4
>/dev
/null
; then
7428 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7429 numCANT
=$
((numCANT
+1))
7431 testserversec
"$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "lowport" "udp4-sendto:127.0.0.1:$PORT" 4 udp
$PORT 0
7432 fi ;; # NUMCOND, feats
7437 NAME
=UDP4RECVFROM_RANGE
7439 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%range
%*|
*%$NAME%*)
7440 TEST
="$NAME: security of UDP4-RECVFROM with RANGE option"
7441 #testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7442 if ! eval $NUMCOND; then :; else
7443 testserversec
"$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "range=$SECONDADDR/32" "udp4-sendto:127.0.0.1:$PORT" 4 udp
$PORT 0
7449 NAME
=UDP4RECVFROM_TCPWRAP
7451 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%tcpwrap
%*|
*%$NAME%*)
7452 TEST
="$NAME: security of UDP4-RECVFROM with TCPWRAP option"
7453 if ! eval $NUMCOND; then :;
7454 elif ! feat
=$
(testaddrs ip4 udp libwrap
) ||
! runsip4
>/dev
/null
; then
7455 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7456 numCANT
=$
((numCANT
+1))
7458 ha
="$td/hosts.allow"
7460 $ECHO "socat: $SECONDADDR" >"$ha"
7461 $ECHO "ALL: ALL" >"$hd"
7462 #testserversec "$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr,fork" "" "tcpwrap=$d" "udp4-sendto:127.0.0.1:$PORT" 4 udp $PORT 0
7463 testserversec
"$N" "$TEST" "$opts" "udp4-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp4-sendto:127.0.0.1:$PORT" 4 udp
$PORT 0
7464 fi ;; # NUMCOND, feats
7470 NAME
=UDP4RECV_SOURCEPORT
7472 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%sourceport
%*|
*%$NAME%*)
7473 TEST
="$NAME: security of UDP4-RECV with SOURCEPORT option"
7474 if ! eval $NUMCOND; then :;
7475 elif ! feat
=$
(testaddrs udp ip4
) ||
! runsip4
>/dev
/null
; then
7476 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7477 numCANT
=$
((numCANT
+1))
7479 PORT1
=$PORT; PORT
=$
((PORT
+1))
7480 PORT2
=$PORT; PORT
=$
((PORT
+1))
7482 # we use the forward channel (PORT1) for testing, and have a backward channel
7483 # (PORT2) to get the data back, so we get the classical echo behaviour
7484 testserversec
"$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "sp=$PORT3" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp
$PORT1 0
7485 fi ;; # NUMCOND, feats
7490 NAME
=UDP4RECV_LOWPORT
7492 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%lowport
%*|
*%$NAME%*)
7493 TEST
="$NAME: security of UDP4-RECV with LOWPORT option"
7494 if ! eval $NUMCOND; then :;
7495 elif ! feat
=$
(testaddrs udp ip4
) ||
! runsip4
>/dev
/null
; then
7496 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7497 numCANT
=$
((numCANT
+1))
7499 PORT1
=$PORT; PORT
=$
((PORT
+1))
7501 # we use the forward channel (PORT1) for testing, and have a backward channel
7502 # (PORT2) to get the data back, so we get the classical echo behaviour
7503 testserversec
"$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "lowport" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp
$PORT1 0
7504 fi ;; # NUMCOND, feats
7511 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%range
%*|
*%$NAME%*)
7512 TEST
="$NAME: security of UDP4-RECV with RANGE option"
7513 if ! eval $NUMCOND; then :;
7514 elif ! feat
=$
(testaddrs udp ip4
) ||
! runsip4
>/dev
/null
; then
7515 $PRINTF "test $F_n $TEST... ${YELLOW}UDP4 not available${NORMAL}\n" $N
7516 numCANT
=$
((numCANT
+1))
7518 PORT1
=$PORT; PORT
=$
((PORT
+1))
7520 # we use the forward channel (PORT1) for testing, and have a backward channel
7521 # (PORT2) to get the data back, so we get the classical echo behaviour
7522 testserversec
"$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "range=$SECONDADDR/32" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp
$PORT1 0
7523 fi ;; # NUMCOND, feats
7528 NAME
=UDP4RECV_TCPWRAP
7530 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%tcpwrap
%*|
*%$NAME%*)
7531 TEST
="$NAME: security of UDP4-RECV with TCPWRAP option"
7532 if ! eval $NUMCOND; then :;
7533 elif ! feat
=$
(testaddrs udp ip4 libwrap
) ||
! runsip4
>/dev
/null
; then
7534 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7535 numCANT
=$
((numCANT
+1))
7537 PORT1
=$PORT; PORT
=$
((PORT
+1))
7539 ha
="$td/hosts.allow"
7541 $ECHO "socat: $SECONDADDR" >"$ha"
7542 $ECHO "ALL: ALL" >"$hd"
7543 # we use the forward channel (PORT1) for testing, and have a backward channel
7544 # (PORT2) to get the data back, so we get the classical echo behaviour
7545 testserversec
"$N" "$TEST" "$opts" "udp4-recv:$PORT1,reuseaddr!!udp4-sendto:127.0.0.1:$PORT2" "" "tcpwrap-etc=$td" "udp4-recv:$PORT2!!udp4-sendto:127.0.0.1:$PORT1" 4 udp
$PORT1 0
7546 fi ;; # NUMCOND, feats
7552 NAME
=UDP6RECVFROM_SOURCEPORT
7554 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%sourceport
%*|
*%$NAME%*)
7555 TEST
="$NAME: security of UDP6-RECVFROM with SOURCEPORT option"
7556 if ! eval $NUMCOND; then :;
7557 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
7558 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7559 numCANT
=$
((numCANT
+1))
7561 testserversec
"$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "sp=$PORT" "udp6-sendto:[::1]:$PORT" 6 udp
$PORT 0
7562 fi ;; # NUMCOND, feats
7567 NAME
=UDP6RECVFROM_LOWPORT
7569 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%lowport
%*|
*%$NAME%*)
7570 TEST
="$NAME: security of UDP6-RECVFROM with LOWPORT option"
7571 if ! eval $NUMCOND; then :;
7572 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
7573 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7574 numCANT
=$
((numCANT
+1))
7576 testserversec
"$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "lowport" "udp6-sendto:[::1]:$PORT" 6 udp
$PORT 0
7577 fi ;; # NUMCOND, feats
7582 NAME
=UDP6RECVFROM_RANGE
7584 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%range
%*|
*%$NAME%*)
7585 TEST
="$NAME: security of UDP6-RECVFROM with RANGE option"
7586 if ! eval $NUMCOND; then :;
7587 elif ! feat
=$
(testaddrs tcp ip6
) ||
! runsip6
>/dev
/null
; then
7588 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
7589 numCANT
=$
((numCANT
+1))
7591 #testserversec "$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr,fork" "" "range=[::2]/128" "udp6-sendto:[::1]:$PORT" 6 udp $PORT 0
7592 testserversec
"$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "range=[::2]/128" "udp6-sendto:[::1]:$PORT" 6 udp
$PORT 0
7593 fi ;; # NUMCOND, feats
7598 NAME
=UDP6RECVFROM_TCPWRAP
7600 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%tcpwrap
%*|
*%$NAME%*)
7601 TEST
="$NAME: security of UDP6-RECVFROM with TCPWRAP option"
7602 if ! eval $NUMCOND; then :;
7603 elif ! feat
=$
(testaddrs udp ip6 libwrap
) ||
! runsip6
>/dev
/null
; then
7604 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7605 numCANT
=$
((numCANT
+1))
7607 ha
="$td/hosts.allow"
7609 $ECHO "socat: [::2]" >"$ha"
7610 $ECHO "ALL: ALL" >"$hd"
7611 testserversec
"$N" "$TEST" "$opts" "udp6-recvfrom:$PORT,reuseaddr" "" "tcpwrap-etc=$td" "udp6-sendto:[::1]:$PORT" 6 udp
$PORT 0
7612 fi ;; # NUMCOND, feats
7618 NAME
=UDP6RECV_SOURCEPORT
7620 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%sourceport
%*|
*%$NAME%*)
7621 TEST
="$NAME: security of UDP6-RECV with SOURCEPORT option"
7622 if ! eval $NUMCOND; then :;
7623 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
7624 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7625 numCANT
=$
((numCANT
+1))
7627 PORT1
=$PORT; PORT
=$
((PORT
+1))
7628 PORT2
=$PORT; PORT
=$
((PORT
+1))
7630 # we use the forward channel (PORT1) for testing, and have a backward channel
7631 # (PORT2) to get the data back, so we get the classical echo behaviour
7632 testserversec
"$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "sp=$PORT3" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp
$PORT1 0
7633 fi ;; # NUMCOND, feats
7638 NAME
=UDP6RECV_LOWPORT
7640 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%lowport
%*|
*%$NAME%*)
7641 TEST
="$NAME: security of UDP6-RECV with LOWPORT option"
7642 if ! eval $NUMCOND; then :;
7643 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
7644 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7645 numCANT
=$
((numCANT
+1))
7647 PORT1
=$PORT; PORT
=$
((PORT
+1))
7649 # we use the forward channel (PORT1) for testing, and have a backward channel
7650 # (PORT2) to get the data back, so we get the classical echo behaviour
7651 testserversec
"$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "lowport" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp
$PORT1 0
7652 fi ;; # NUMCOND, feats
7659 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%range
%*|
*%$NAME%*)
7660 TEST
="$NAME: security of UDP6-RECV with RANGE option"
7661 if ! eval $NUMCOND; then :;
7662 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
7663 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
7664 numCANT
=$
((numCANT
+1))
7666 PORT1
=$PORT; PORT
=$
((PORT
+1))
7668 # we use the forward channel (PORT1) for testing, and have a backward channel
7669 # (PORT2) to get the data back, so we get the classical echo behaviour
7670 testserversec
"$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "range=[::2]/128" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp
$PORT1 0
7671 fi ;; # NUMCOND, feats
7676 NAME
=UDP6RECV_TCPWRAP
7678 *%$N%*|
*%functions
%*|
*%security
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%tcpwrap
%*|
*%$NAME%*)
7679 TEST
="$NAME: security of UDP6-RECV with TCPWRAP option"
7680 if ! eval $NUMCOND; then :;
7681 elif ! feat
=$
(testaddrs udp ip6 libwrap
) ||
! runsip6
>/dev
/null
; then
7682 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7683 numCANT
=$
((numCANT
+1))
7685 ha
="$td/hosts.allow"
7687 $ECHO "socat: [::2]" >"$ha"
7688 $ECHO "ALL: ALL" >"$hd"
7689 PORT1
=$PORT; PORT
=$
((PORT
+1))
7691 # we use the forward channel (PORT1) for testing, and have a backward channel
7692 # (PORT2) to get the data back, so we get the classical echo behaviour
7693 testserversec
"$N" "$TEST" "$opts" "udp6-recv:$PORT1,reuseaddr!!udp6-sendto:[::1]:$PORT2" "" "tcpwrap-etc=$td" "udp6-recv:$PORT2!!udp6-sendto:[::1]:$PORT1" 6 udp
$PORT1 0
7694 fi ;; # NUMCOND, feats
7700 NAME
=IP4RECVFROM_RANGE
7702 *%$N%*|
*%functions
%*|
*%security
%*|
*%ip
%*|
*%ip4
%*|
*%range
%*|
*%root
%*|
*%$NAME%*)
7703 TEST
="$NAME: security of IP4-RECVFROM with RANGE option"
7704 if ! eval $NUMCOND; then :;
7705 elif ! feat
=$
(testaddrs ip4 rawip
) ||
! runsip4
>/dev
/null
; then
7706 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7707 numCANT
=$
((numCANT
+1))
7708 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7709 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7710 numCANT
=$
((numCANT
+1))
7712 #testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "range=$SECONDADDR/32" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7713 testserversec
"$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr!!udp4-sendto:127.0.0.1:$PORT" "" "range=$SECONDADDR/32" "udp4-recv:$PORT!!ip4-sendto:127.0.0.1:$PROTO" 4 ip
$PROTO 0
7714 fi ;; # NUMCOND, feats, root
7720 NAME
=IP4RECVFROM_TCPWRAP
7722 *%$N%*|
*%functions
%*|
*%security
%*|
*%ip
%*|
*%ip4
%*|
*%tcpwrap
%*|
*%root
%*|
*%$NAME%*)
7723 TEST
="$NAME: security of IP4-RECVFROM with TCPWRAP option"
7724 if ! eval $NUMCOND; then :;
7725 elif ! feat
=$
(testaddrs ip4 rawip libwrap
) ||
! runsip4
>/dev
/null
; then
7726 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7727 numCANT
=$
((numCANT
+1))
7728 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7729 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7730 numCANT
=$
((numCANT
+1))
7732 ha
="$td/hosts.allow"
7734 $ECHO "socat: $SECONDADDR" >"$ha"
7735 $ECHO "ALL: ALL" >"$hd"
7736 #testserversec "$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip4-sendto:127.0.0.1:$PROTO" 4 ip $PROTO 0
7737 testserversec
"$N" "$TEST" "$opts" "ip4-recvfrom:$PROTO,reuseaddr!!udp4-sendto:127.0.0.1:$PORT" "" "tcpwrap-etc=$td" "udp4-recv:$PORT!!ip4-sendto:127.0.0.1:$PROTO" 4 ip
$PROTO 0
7738 fi # NUMCOND, feats, root
7748 *%$N%*|
*%functions
%*|
*%security
%*|
*%ip
%*|
*%ip4
%*|
*%range
%*|
*%root
%*|
*%$NAME%*)
7749 TEST
="$NAME: security of IP4-RECV with RANGE option"
7750 if ! eval $NUMCOND; then :;
7751 elif ! feat
=$
(testaddrs ip4 rawip
) ||
! runsip4
>/dev
/null
; then
7752 $PRINTF "test $F_n $TEST... ${YELLOW}IP4 not available${NORMAL}\n" $N
7753 numCANT
=$
((numCANT
+1))
7754 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7755 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7756 numCANT
=$
((numCANT
+1))
7758 PROTO1
=$PROTO; PROTO
=$
((PROTO
+1))
7760 # we use the forward channel (PROTO1) for testing, and have a backward channel
7761 # (PROTO2) to get the data back, so we get the classical echo behaviour
7762 testserversec
"$N" "$TEST" "$opts" "ip4-recv:$PROTO1,reuseaddr!!ip4-sendto:127.0.0.1:$PROTO2" "" "range=$SECONDADDR/32" "ip4-recv:$PROTO2!!ip4-sendto:127.0.0.1:$PROTO1" 4 ip
$PROTO1 0
7763 fi ;; # NUMCOND, feats, root
7770 NAME
=IP4RECV_TCPWRAP
7772 *%$N%*|
*%functions
%*|
*%security
%*|
*%ip
%*|
*%ip4
%*|
*%tcpwrap
%*|
*%root
%*|
*%$NAME%*)
7773 TEST
="$NAME: security of IP4-RECV with TCPWRAP option"
7774 if ! eval $NUMCOND; then :;
7775 elif ! feat
=$
(testaddrs ip4 rawip libwrap
) ||
! runsip4
>/dev
/null
; then
7776 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7777 numCANT
=$
((numCANT
+1))
7778 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7779 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7780 numCANT
=$
((numCANT
+1))
7782 PROTO1
=$PROTO; PROTO
=$
((PROTO
+1))
7784 ha
="$td/hosts.allow"
7786 $ECHO "socat: $SECONDADDR" >"$ha"
7787 $ECHO "ALL: ALL" >"$hd"
7788 # we use the forward channel (PROTO1) for testing, and have a backward channel
7789 # (PROTO2) to get the data back, so we get the classical echo behaviour
7790 testserversec
"$N" "$TEST" "$opts" "ip4-recv:$PROTO1,reuseaddr!!ip4-sendto:127.0.0.1:$PROTO2" "" "tcpwrap-etc=$td" "ip4-recv:$PROTO2!!ip4-sendto:127.0.0.1:$PROTO1" 4 ip
$PROTO1 0
7791 fi ;; # NUMCOND, feats, root
7797 NAME
=IP6RECVFROM_RANGE
7799 *%$N%*|
*%functions
%*|
*%security
%*|
*%ip
%*|
*%ip6
%*|
*%range
%*|
*%root
%*|
*%$NAME%*)
7800 TEST
="$NAME: security of IP6-RECVFROM with RANGE option"
7801 if ! eval $NUMCOND; then :;
7802 elif ! feat
=$
(testaddrs ip6 rawip
) ||
! runsip6
>/dev
/null
; then
7803 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7804 numCANT
=$
((numCANT
+1))
7805 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7806 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7807 numCANT
=$
((numCANT
+1))
7809 #testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "range=[::2]/128" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7810 testserversec
"$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "range=[::2]/128" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip
$PROTO 0
7811 fi ;; # NUMCOND, feats
7817 NAME
=IP6RECVFROM_TCPWRAP
7819 *%$N%*|
*%functions
%*|
*%security
%*|
*%ip
%*|
*%ip6
%*|
*%tcpwrap
%*|
*%root
%*|
*%$NAME%*)
7820 TEST
="$NAME: security of IP6-RECVFROM with TCPWRAP option"
7821 if ! eval $NUMCOND; then :;
7822 elif ! feat
=$
(testaddrs ip6 rawip libwrap
) ||
! runsip6
>/dev
/null
; then
7823 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7824 numCANT
=$
((numCANT
+1))
7825 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7826 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7827 numCANT
=$
((numCANT
+1))
7829 ha
="$td/hosts.allow"
7831 $ECHO "socat: [::2]" >"$ha"
7832 $ECHO "ALL: ALL" >"$hd"
7833 #testserversec "$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr,fork" "" "tcpwrap-etc=$td" "ip6-sendto:[::1]:$PROTO" 6 ip $PROTO 0
7834 testserversec
"$N" "$TEST" "$opts" "ip6-recvfrom:$PROTO,reuseaddr!!udp6-sendto:[::1]:$PORT" "" "tcpwrap-etc=$td" "udp6-recv:$PORT!!ip6-sendto:[::1]:$PROTO" 6 ip
$PROTO 0
7835 fi ;; # NUMCOND, feats
7844 *%$N%*|
*%functions
%*|
*%security
%*|
*%ip
%*|
*%ip6
%*|
*%range
%*|
*%root
%*|
*%$NAME%*)
7845 TEST
="$NAME: security of IP6-RECV with RANGE option"
7846 if ! eval $NUMCOND; then :;
7847 elif ! feat
=$
(testaddrs ip6 rawip
) ||
! runsip6
>/dev
/null
; then
7848 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP6 not available${NORMAL}\n" $N
7849 numCANT
=$
((numCANT
+1))
7850 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7851 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7852 numCANT
=$
((numCANT
+1))
7854 PROTO1
=$PROTO; PROTO
=$
((PROTO
+1))
7856 # we use the forward channel (PROTO1) for testing, and have a backward channel
7857 # (PROTO2) to get the data back, so we get the classical echo behaviour
7858 testserversec
"$N" "$TEST" "$opts" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "range=[::2]/128" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip
$PROTO1 0
7859 fi ;; # NUMCOND, feats
7864 NAME
=IP6RECV_TCPWRAP
7866 *%$N%*|
*%functions
%*|
*%security
%*|
*%ip
%*|
*%ip6
%*|
*%tcpwrap
%*|
*%root
%*|
*%$NAME%*)
7867 TEST
="$NAME: security of IP6-RECV with TCPWRAP option"
7868 if ! eval $NUMCOND; then :;
7869 elif ! feat
=$
(testaddrs ip6 rawip libwrap
) ||
! runsip6
>/dev
/null
; then
7870 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
7871 numCANT
=$
((numCANT
+1))
7872 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
7873 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
7874 numCANT
=$
((numCANT
+1))
7876 PROTO1
=$PROTO; PROTO
=$
((PROTO
+1))
7878 ha
="$td/hosts.allow"
7880 $ECHO "socat: [::2]" >"$ha"
7881 $ECHO "ALL: ALL" >"$hd"
7882 # we use the forward channel (PROTO1) for testing, and have a backward channel
7883 # (PROTO2) to get the data back, so we get the classical echo behaviour
7884 testserversec
"$N" "$TEST" "$opts" "ip6-recv:$PROTO1,reuseaddr!!ip6-sendto:[::1]:$PROTO2" "" "tcpwrap-etc=$td" "ip6-recv:$PROTO2!!ip6-sendto:[::1]:$PROTO1" 6 ip
$PROTO1 0
7885 fi ;; # NUMCOND, feats
7893 *%$N%*|
*%functions
%*|
*%open
%*|
*%noatime
%*|
*%$NAME%*)
7894 TEST
="$NAME: option O_NOATIME on file"
7895 # idea: create a file with o-noatime option; one second later create a file
7896 # without this option (using touch); one second later read from the first file.
7897 # Then we check which file has the later ATIME stamp. For this check we use
7898 # "ls -ltu" because it is more portable than "test ... -nt ..."
7899 if ! eval $NUMCOND; then :;
7900 elif ! testoptions o-noatime
>/dev
/null
; then
7901 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
7902 numCANT
=$
((numCANT
+1))
7904 tf
="$td/test$N.file"
7905 te
="$td/test$N.stderr"
7906 tdiff
="$td/test$N.diff"
7907 da
="test$N $(date) $RANDOM"
7908 $PRINTF "test $F_n $TEST... " $N
7909 CMD
="$TRACE $SOCAT $opts -u open:\"${tf}1\",o-noatime /dev/null"
7913 # generate a reference file
7916 # read from the first file
7918 if [ $?
-ne 0 ]; then # command failed
7919 $PRINTF "${FAILED}:\n"
7922 numFAIL
=$
((numFAIL
+1))
7923 listFAIL
="$listFAIL $N"
7925 # check which file has a later atime stamp
7926 if [ $
(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
7928 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7931 numFAIL
=$
((numFAIL
+1))
7932 listFAIL
="$listFAIL $N"
7935 if [ -n "$debug" ]; then cat "$te"; fi
7937 fi # wrong time stamps
7939 fi ;; # NUMCOND, feats
7945 *%$N%*|
*%functions
%*|
*%noatime
%*|
*%$NAME%*)
7946 TEST
="$NAME: option O_NOATIME on file descriptor"
7947 # idea: use a fd of a file with o-noatime option; one second later create a file
7948 # without this option (using touch); one second later read from the first file.
7949 # Then we check which file has the later ATIME stamp. For this check we use
7950 # "ls -ltu" because it is more portable than "test ... -nt ..."
7951 if ! eval $NUMCOND; then :;
7952 elif ! testoptions o-noatime
>/dev
/null
; then
7953 $PRINTF "test $F_n $TEST... ${YELLOW}o-noatime not available${NORMAL}\n" $N
7954 numCANT
=$
((numCANT
+1))
7956 tf
="$td/test$N.file"
7957 te
="$td/test$N.stderr"
7958 tdiff
="$td/test$N.diff"
7959 da
="test$N $(date) $RANDOM"
7960 $PRINTF "test $F_n $TEST... " $N
7962 CMD
="$TRACE $SOCAT $opts -u -,o-noatime /dev/null <${tf}1"
7963 # generate a file, len >= 1
7966 # generate a reference file
7969 # read from the first file
7970 sh
-c "$CMD" 2>"$te"
7971 if [ $?
-ne 0 ]; then # command failed
7972 $PRINTF "${FAILED}:\n"
7975 numFAIL
=$
((numFAIL
+1))
7976 listFAIL
="$listFAIL $N"
7978 # check which file has a later atime stamp
7979 if [ $
(ls -ltu "${tf}1" "${tf}2" |head -1 |sed 's/.* //') != "${tf}2" ];
7981 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
7984 numFAIL
=$
((numFAIL
+1))
7985 listFAIL
="$listFAIL $N"
7988 if [ -n "$debug" ]; then cat "$te"; fi
7990 fi # wrong time stamps
7992 fi ;; # NUMCOND, feats
7998 *%$N%*|
*%functions
%*|
*%ext2
%*|
*%noatime
%*|
*%$NAME%*)
7999 TEST
="$NAME: extended file system options using ext2fs noatime option"
8000 # idea: create a file with ext2-noatime option; one second later create a file
8001 # without this option (using touch); one second later read from the first file.
8002 # Then we check which file has the later ATIME stamp. For this check we use
8003 # "ls -ltu" because it is more portable than "test ... -nt ..."
8004 if ! eval $NUMCOND; then :;
8005 elif ! testoptions ext2-noatime
>/dev
/null
; then
8006 $PRINTF "test $F_n $TEST... ${YELLOW}ext2-noatime not available${NORMAL}\n" $N
8007 numCANT
=$
((numCANT
+1))
8009 ts
="$td/test$N.socket"
8010 tf
="$td/test$N.file"
8011 te
="$td/test$N.stderr"
8012 tdiff
="$td/test$N.diff"
8014 da
="test$N $(date) $RANDOM"
8015 $PRINTF "test $F_n $TEST... " $N
8016 CMD0
="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\""
8017 CMD
="$TRACE $SOCAT $opts -u /dev/null create:\"${tf}1\",ext2-noatime"
8018 # check if this is a capable FS; lsattr does other things on AIX, thus socat
8020 if [ $?
-ne 0 ]; then
8021 $PRINTF "${YELLOW} cannot test${NORMAL}\n"
8022 numCANT
=$
((numCANT
+1))
8024 # generate a file with noatime, len >= 1
8026 if [ $?
-ne 0 ]; then # command failed
8027 $PRINTF "${YELLOW}impotent file system?${NORMAL}\n"
8030 numCANT
=$
((numCANT
+1))
8033 # generate a reference file
8036 # read from the first file
8037 cat "${tf}1" >/dev
/null
8038 # check which file has a later atime stamp
8039 #if [ $(ls -ltu "${tf}1" "${tf}2" |head -n 1 |awk '{print($8);}') != "${tf}2" ];
8040 if [ $
(ls -ltu "${tf}1" "${tf}2" |head -n 1 |sed "s|.*\\($td.*\\)|\1|g") != "${tf}2" ];
8042 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8045 numFAIL
=$
((numFAIL
+1))
8046 listFAIL
="$listFAIL $N"
8049 if [ -n "$debug" ]; then cat "$te"; fi
8054 fi ;; # NUMCOND, feats
8061 *%$N%*|
*%functions
%*|
*%engine
%*|
*%timeout
%*|
*%coolwrite
%*|
*%$NAME%*)
8062 TEST
="$NAME: option cool-write"
8063 if ! eval $NUMCOND; then :;
8064 elif ! testoptions cool-write
>/dev
/null
; then
8065 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
8066 numCANT
=$
((numCANT
+1))
8069 ti
="$td/test$N.pipe"
8070 tf
="$td/test$N.stdout"
8071 te
="$td/test$N.stderr"
8072 tdiff
="$td/test$N.diff"
8073 da
="test$N $(date) $RANDOM"
8074 # a reader that will terminate after 1 byte
8075 CMD1
="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8076 CMD
="$TRACE $SOCAT $opts -u - file:\"$ti\",cool-write"
8077 printf "test $F_n $TEST... " $N
8079 bg=$
! # background process id
8081 (echo .
; sleep 1; echo) |
$CMD 2>"$te"
8083 kill $bg 2>/dev
/null
; wait
8084 if [ $rc -ne 0 ]; then
8085 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8088 numFAIL
=$
((numFAIL
+1))
8089 listFAIL
="$listFAIL $N"
8092 if [ -n "$debug" ]; then cat "$te"; fi
8095 fi ;; # NUMCOND, feats
8100 # test if option coolwrite can be applied to bidirectional address stdio
8101 # this failed up to socat 1.6.0.0
8104 *%$N%*|
*%functions
%*|
*%engine
%*|
*%timeout
%*|
*%coolwrite
%*|
*%$NAME%*)
8105 TEST
="$NAME: option cool-write on bidirectional stdio"
8106 # this test starts a socat reader that terminates after receiving one+
8107 # bytes (option readbytes); and a test process that sends two bytes via
8108 # named pipe to the receiving process and, a second later, sends another
8109 # byte. The last write will fail with "broken pipe"; if option coolwrite
8110 # has been applied successfully, socat will terminate with 0 (OK),
8111 # otherwise with error.
8112 if ! eval $NUMCOND; then :;
8113 elif ! testoptions cool-write
>/dev
/null
; then
8114 $PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
8115 numCANT
=$
((numCANT
+1))
8118 ti
="$td/test$N.pipe"
8119 tf
="$td/test$N.stdout"
8120 te
="$td/test$N.stderr"
8121 tdiff
="$td/test$N.diff"
8122 da
="test$N $(date) $RANDOM"
8123 # a reader that will terminate after 1 byte
8124 CMD1
="$TRACE $SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
8125 CMD
="$TRACE $SOCAT $opts -,cool-write pipe >\"$ti\""
8126 printf "test $F_n $TEST... " $N
8128 bg=$
! # background process id
8130 (echo .
; sleep 1; echo) |
eval "$CMD" 2>"$te"
8132 kill $bg 2>/dev
/null
; wait
8133 if [ $rc -ne 0 ]; then
8134 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8137 numFAIL
=$
((numFAIL
+1))
8138 listFAIL
="$listFAIL $N"
8141 if [ -n "$debug" ]; then cat "$te"; fi
8144 fi ;; # NUMCOND, feats
8151 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
8152 TEST
="$NAME: end-close keeps TCP V4 socket open"
8153 if ! eval $NUMCOND; then :; else
8154 tf
="$td/test$N.stdout"
8155 te
="$td/test$N.stderr"
8156 tdiff
="$td/test$N.diff"
8157 p1
=$PORT; PORT
=$
((PORT
+1))
8159 da1a
="$(date) $RANDOM"
8160 da1b
="$(date) $RANDOM"
8161 CMD1
="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$LOCALHOST:$p1"
8162 CMD
="$TRACE $SOCAT $opts -U TCP4:$LOCALHOST:$p2,end-close TCP4-LISTEN:$p1,bind=$LOCALHOST,$REUSEADDR,fork"
8163 CMD3
="$TRACE $SOCAT $opts -u TCP4-LISTEN:$p2,$REUSEADDR,bind=$LOCALHOST -"
8164 printf "test $F_n $TEST... " $N
8165 $CMD3 >"$tf" 2>"${te}3" &
8172 echo "$da1a" |
$CMD1 2>>"${te}1a"
8173 echo "$da1b" |
$CMD1 2>>"${te}1b"
8175 kill "$pid3" "$pid2" 2>/dev
/null
8177 if [ $?
-ne 0 ]; then
8178 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8181 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8182 numFAIL
=$
((numFAIL
+1))
8183 listFAIL
="$listFAIL $N"
8184 elif ! $ECHO "$da1a\n$da1b" |
diff - "$tf" >"$tdiff"; then
8187 cat "${te}1a" "${te}1b" "${te}2" "${te}3"
8188 numFAIL
=$
((numFAIL
+1))
8189 listFAIL
="$listFAIL $N"
8192 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2" "${te}3"; fi
8203 *%$N%*|
*%functions
%*|
*%exec%*|
*%$NAME%*)
8204 TEST
="$NAME: end-close keeps EXEC child running"
8205 if ! eval $NUMCOND; then :; else
8206 tf
="$td/test$N.stdout"
8207 te
="$td/test$N.stderr"
8208 ts
="$td/test$N.sock"
8209 tdiff
="$td/test$N.diff"
8210 da1a
="$(date) $RANDOM"
8211 da1b
="$(date) $RANDOM"
8212 CMD1
="$TRACE $SOCAT $opts - UNIX-CONNECT:$ts"
8213 CMD
="$TRACE $SOCAT $opts EXEC:"$CAT",end-close UNIX-LISTEN:$ts,fork"
8214 printf "test $F_n $TEST... " $N
8218 echo "$da1a" |
$CMD1 2>>"${te}1a" >"$tf"
8220 echo "$da1b" |
$CMD1 2>>"${te}1b" >>"$tf"
8222 kill "$pid2" 2>/dev
/null
8224 if [ $?
-ne 0 ]; then
8225 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8228 cat "${te}1a" "${te}1b" "${te}2"
8229 numFAIL
=$
((numFAIL
+1))
8230 listFAIL
="$listFAIL $N"
8231 elif ! $ECHO "$da1a\n$da1b" |
diff - "$tf" >"$tdiff"; then
8234 cat "${te}1a" "${te}1b" "${te}2"
8235 numFAIL
=$
((numFAIL
+1))
8236 listFAIL
="$listFAIL $N"
8239 if [ -n "$debug" ]; then cat "${te}1a" "${te}1b" "${te}2"; fi
8247 # up to 1.7.0.0 option end-close led to an error with some address types due to
8248 # bad internal handling. here we check it for address PTY
8251 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%pty
%*|
*%$NAME%*)
8252 TEST
="$NAME: PTY handles option end-close"
8253 # with the bug, socat exits with error. we invoke socat in a no-op mode and
8254 # check its return status.
8255 if ! eval $NUMCOND; then :;
8257 tf
="$td/test$N.stout"
8258 te
="$td/test$N.stderr"
8259 CMD
="$TRACE $SOCAT $opts /dev/null pty,end-close"
8260 printf "test $F_n $TEST... " $N
8263 if [ "$rc" = 0 ]; then
8270 numFAIL
=$
((numFAIL
+1))
8271 listFAIL
="$listFAIL $N"
8279 # test the shut-null and null-eof options
8282 *%$N%*|
*%functions
%*|
*%socket
%*|
*%$NAME%*)
8283 TEST
="$NAME: options shut-null and null-eof"
8284 # run a receiving background process with option null-eof.
8285 # start a sending process with option shut-null that sends a test record to the
8286 # receiving process and then terminates.
8287 # send another test record.
8288 # whe the receiving process just got the first test record the test succeeded
8289 if ! eval $NUMCOND; then :; else
8290 tf
="$td/test$N.stout"
8291 te
="$td/test$N.stderr"
8292 tdiff
="$td/test$N.diff"
8293 da
="test$N $(date) $RANDOM"
8294 CMD0
="$TRACE $SOCAT $opts -u UDP-RECV:$PORT,null-eof CREAT:$tf"
8295 CMD1
="$TRACE $SOCAT $opts -u - UDP-SENDTO:127.0.0.1:$PORT,shut-null"
8296 printf "test $F_n $TEST... " $N
8297 $CMD0 >/dev
/null
2>"${te}0" &
8299 waitudp4port
$PORT 1
8300 echo "$da" |
$CMD1 >"${tf}1" 2>"${te}1"
8302 echo "xyz" |
$CMD1 >"${tf}2" 2>"${te}2"
8304 kill $pid0 2>/dev
/null
; wait
8305 if [ $rc1 != 0 -o $rc2 != 0 ]; then
8312 numFAIL
=$
((numFAIL
+1))
8313 listFAIL
="$listFAIL $N"
8314 elif echo "$da" |
diff - "${tf}" >"$tdiff"; then
8324 numFAIL
=$
((numFAIL
+1))
8325 listFAIL
="$listFAIL $N"
8334 # this tests for a bug in (up to) 1.5.0.0:
8335 # with udp*-listen, the bind option supported only IPv4
8337 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%ip6
%*|
*%ipapp
%*|
*%udp
%*|
*%udp6
%*|
*%$NAME%*)
8338 TEST
="$NAME: UDP6-LISTEN with bind"
8339 if ! eval $NUMCOND; then :;
8340 elif ! feat
=$
(testaddrs udp ip6
) ||
! runsip6
>/dev
/null
; then
8341 $PRINTF "test $F_n $TEST... ${YELLOW}UDP6 not available${NORMAL}\n" $N
8342 numCANT
=$
((numCANT
+1))
8344 tf
="$td/test$N.stdout"
8345 te
="$td/test$N.stderr"
8346 tdiff
="$td/test$N.diff"
8348 ts
="$LOCALHOST6:$tsl"
8349 da
="test$N $(date) $RANDOM"
8350 CMD1
="$TRACE $SOCAT $opts UDP6-LISTEN:$tsl,$REUSEADDR,bind=$LOCALHOST6 PIPE"
8351 CMD2
="$TRACE $SOCAT $opts - UDP6:$ts"
8352 printf "test $F_n $TEST... " $N
8353 $CMD1 >"$tf" 2>"${te}1" &
8356 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
8358 kill $pid1 2>/dev
/null
; wait
8359 if [ $rc2 -ne 0 ]; then
8360 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8363 cat "${te}1" "${te}2"
8364 numFAIL
=$
((numFAIL
+1))
8365 listFAIL
="$listFAIL $N"
8366 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8369 numFAIL
=$
((numFAIL
+1))
8370 listFAIL
="$listFAIL $N"
8373 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8376 fi ;; # NUMCOND, feats
8382 NAME
=TCPWRAPPERS_MULTIOPTS
8383 # this tests for a bug in 1.5.0.0 that let socat fail when more than one
8384 # tcp-wrappers related option was specified in one address
8386 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%tcpwrap
%*|
*%$NAME%*)
8387 TEST
="$NAME: use of multiple tcpwrapper enabling options"
8388 if ! eval $NUMCOND; then :;
8389 elif ! feat
=$
(testaddrs tcp ip4 libwrap
) ||
! runsip4
>/dev
/null
; then
8390 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8391 numCANT
=$
((numCANT
+1))
8393 tf
="$td/test$N.stdout"
8394 te
="$td/test$N.stderr"
8395 tdiff
="$td/test$N.diff"
8396 da
="test$N $(date) $RANDOM"
8397 ha
="$td/hosts.allow"
8398 $ECHO "test : ALL : allow" >"$ha"
8399 CMD1
="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,$REUSEADDR,hosts-allow=$ha,tcpwrap=test pipe"
8400 CMD2
="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT"
8401 printf "test $F_n $TEST... " $N
8404 echo "$da" |
$CMD2 >"$tf" 2>"${te}2"
8405 if [ $?
-ne 0 ]; then
8406 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8411 numFAIL
=$
((numFAIL
+1))
8412 listFAIL
="$listFAIL $N"
8413 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8416 numFAIL
=$
((numFAIL
+1))
8417 listFAIL
="$listFAIL $N"
8420 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8423 fi ;; # NUMCOND, feats
8429 NAME
=TCPWRAPPERS_TCP6ADDR
8430 # this tests for a bug in 1.5.0.0 that brought false results with tcp-wrappers
8433 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%tcp
%*|
*%tcp6
%*|
*%ip6
%*|
*%tcpwrap
%*|
*%$NAME%*)
8434 TEST
="$NAME: specification of TCP6 address in hosts.allow"
8435 if ! eval $NUMCOND; then :;
8436 elif ! feat
=$
(testaddrs tcp ip6 libwrap
) ||
! runsip6
>/dev
/null
; then
8437 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8438 numCANT
=$
((numCANT
+1))
8440 tf
="$td/test$N.stdout"
8441 te
="$td/test$N.stderr"
8442 tdiff
="$td/test$N.diff"
8443 da
="test$N $(date) $RANDOM"
8444 ha
="$td/hosts.allow"
8446 $ECHO "socat : [::1] : allow" >"$ha"
8447 $ECHO "ALL : ALL : deny" >"$hd"
8448 CMD1
="$TRACE $SOCAT $opts TCP6-LISTEN:$PORT,$REUSEADDR,tcpwrap-etc=$td,tcpwrappers=socat pipe"
8449 CMD2
="$TRACE $SOCAT $opts - TCP6:[::1]:$PORT"
8450 printf "test $F_n $TEST... " $N
8454 echo "$da" |
$CMD2 >"$tf" 2>"${te}2"
8455 kill $pid1 2>/dev
/null
; wait
8456 if [ $?
-ne 0 ]; then
8457 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8462 numFAIL
=$
((numFAIL
+1))
8463 listFAIL
="$listFAIL $N"
8464 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8467 numFAIL
=$
((numFAIL
+1))
8468 listFAIL
="$listFAIL $N"
8471 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
8474 fi ;; # NUMCOND, feats
8482 *%$N%*|
*%functions
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%dgram
%*|
*%broadcast
%*|
*%$NAME%*)
8483 TEST
="$NAME: UDP/IPv4 broadcast"
8484 if ! eval $NUMCOND; then :;
8485 elif [ -z "$BCADDR" ]; then
8486 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8487 numCANT
=$
((numCANT
+1))
8489 tf
="$td/test$N.stdout"
8490 te
="$td/test$N.stderr"
8491 tdiff
="$td/test$N.diff"
8492 ts1p
=$PORT; PORT
=$
((PORT
+1))
8493 #ts1="$BCADDR/8:$ts1p"
8495 ts2p
=$PORT; PORT
=$
((PORT
+1))
8496 ts2
="$BCIFADDR:$ts2p"
8497 da
="test$N $(date) $RANDOM"
8498 CMD1
="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,broadcast PIPE"
8499 #CMD2="$TRACE $SOCAT $opts - UDP4-BROADCAST:$ts1"
8500 CMD2
="$TRACE $SOCAT $opts - UDP4-DATAGRAM:$ts1,broadcast"
8501 printf "test $F_n $TEST... " $N
8504 waitudp4port
$ts1p 1
8505 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
8507 kill "$pid1" 2>/dev
/null
; wait;
8508 if [ "$rc2" -ne 0 ]; then
8509 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8514 numFAIL
=$
((numFAIL
+1))
8515 listFAIL
="$listFAIL $N"
8516 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8519 numFAIL
=$
((numFAIL
+1))
8520 listFAIL
="$listFAIL $N"
8523 if [ -n "$tut" ]; then
8527 if [ -n "$debug" ]; then cat $te; fi
8530 fi ;; # NUMCOND, feats
8536 # test a local broadcast of a raw IPv4 protocol.
8537 # because we receive - in addition to the regular reply - our own broadcast,
8538 # we use a token XXXX that is changed to YYYY in the regular reply packet.
8540 *%$N%*|
*%functions
%*|
*%engine
%*|
*%rawip
%*|
*%rawip4
%*|
*%ip4
%*|
*%dgram
%*|
*%broadcast
%*|
*%root
%*|
*%$NAME%*)
8541 TEST
="$NAME: raw IPv4 broadcast"
8542 if ! eval $NUMCOND; then :;
8543 elif ! feat
=$
(testaddrs ip4 rawip
) ||
! runsip4
>/dev
/null
; then
8544 $PRINTF "test $F_n $TEST... ${YELLOW}raw IP4 not available${NORMAL}\n" $N
8545 numCANT
=$
((numCANT
+1))
8546 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
8547 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8548 numCANT
=$
((numCANT
+1))
8549 elif [ -z "$BCADDR" ]; then
8550 $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8552 tf
="$td/test$N.stdout"
8553 te
="$td/test$N.stderr"
8554 tdiff
="$td/test$N.diff"
8556 #ts1="$BCADDR/8:$ts1p"
8560 da
="test$N $(date) $RANDOM XXXX"
8561 sh
="$td/test$N-sed.sh"
8562 echo 'sed s/XXXX/YYYY/' >"$sh"
8564 CMD1
="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,broadcast exec:$sh"
8565 #CMD2="$TRACE $SOCAT $opts - IP4-BROADCAST:$ts1"
8566 CMD2
="$TRACE $SOCAT $opts - IP4-DATAGRAM:$ts1,broadcast"
8567 printf "test $F_n $TEST... " $N
8571 echo "$da" |
$CMD2 2>>"${te}2" |
grep -v XXXX
>>"$tf"
8573 kill "$pid1" 2>/dev
/null
; wait;
8574 if [ "$rc2" -ne 0 ]; then
8575 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8580 numFAIL
=$
((numFAIL
+1))
8581 listFAIL
="$listFAIL $N"
8582 elif ! echo "$da" |
sed 's/XXXX/YYYY/'|
diff - "$tf" >"$tdiff"; then
8585 numFAIL
=$
((numFAIL
+1))
8586 listFAIL
="$listFAIL $N"
8589 if [ -n "$debug" ]; then cat $te; fi
8592 fi ;; # NUMCOND, feats
8598 #NAME=UDP4BROADCAST_RANGE
8600 #*%$N%*|*%functions%*|*%security%*|*%udp%*|*%udp4%*|*%ip4%*|*%dgram%*|*%broadcast%*|*%range%*|*%$NAME%*)
8601 #TEST="$NAME: security of UDP4-BROADCAST with RANGE option"
8602 #if ! eval $NUMCOND; then :;
8603 #elif [ -z "$BCADDR" ]; then
8604 # $PRINTF "test $F_n $TEST... ${YELLOW}dont know a broadcast address${NORMAL}\n" $N
8606 #testserversec "$N" "$TEST" "$opts" "UDP4-BROADCAST:$BCADDR/8:$PORT" "" "range=127.1.0.0:255.255.0.0" "udp4:127.1.0.0:$PORT" 4 udp $PORT 0
8607 #fi ;; # NUMCOND, feats
8613 NAME
=UDP4MULTICAST_UNIDIR
8615 *%$N%*|
*%functions
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%dgram
%*|
*%multicast
%*|
*%$NAME%*)
8616 TEST
="$NAME: UDP/IPv4 multicast, send only"
8617 if ! eval $NUMCOND; then :;
8618 elif ! feat
=$
(testaddrs ip4 udp
) ||
! runsip4
>/dev
/null
; then
8619 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8620 numCANT
=$
((numCANT
+1))
8622 tf
="$td/test$N.stdout"
8623 te
="$td/test$N.stderr"
8624 tdiff
="$td/test$N.diff"
8625 ts1p
=$PORT; PORT
=$
((PORT
+1))
8628 da
="test$N $(date) $RANDOM"
8629 CMD1
="$TRACE $SOCAT -u $opts UDP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
8630 CMD2
="$TRACE $SOCAT -u $opts - UDP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
8631 printf "test $F_n $TEST... " $N
8632 $CMD1 2>"${te}1" >"${tf}" &
8634 waitudp4port
$ts1p 1
8635 echo "$da" |
$CMD2 2>>"${te}2"
8638 kill "$pid1" 2>/dev
/null
; wait;
8639 if [ "$rc2" -ne 0 ]; then
8640 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8645 numFAIL
=$
((numFAIL
+1))
8646 listFAIL
="$listFAIL $N"
8647 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8650 numFAIL
=$
((numFAIL
+1))
8651 listFAIL
="$listFAIL $N"
8654 if [ -n "$debug" ]; then cat $te; fi
8657 fi ;; # NUMCOND, feats
8661 NAME
=IP4MULTICAST_UNIDIR
8663 *%$N%*|
*%functions
%*|
*%rawip
%*|
*%ip4
%*|
*%dgram
%*|
*%multicast
%*|
*%root
%*|
*%$NAME%*)
8664 TEST
="$NAME: IPv4 multicast"
8665 if ! eval $NUMCOND; then :;
8666 elif ! feat
=$
(testaddrs ip4 rawip
) ||
! runsip4
>/dev
/null
; then
8667 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8668 numCANT
=$
((numCANT
+1))
8669 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
8670 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8671 numCANT
=$
((numCANT
+1))
8673 tf
="$td/test$N.stdout"
8674 te
="$td/test$N.stderr"
8675 tdiff
="$td/test$N.diff"
8679 da
="test$N $(date) $RANDOM"
8680 CMD1
="$TRACE $SOCAT -u $opts IP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -"
8681 CMD2
="$TRACE $SOCAT -u $opts - IP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a"
8682 printf "test $F_n $TEST... " $N
8683 $CMD1 2>"${te}1" >"${tf}" &
8685 waitip4proto
$ts1p 1
8687 echo "$da" |
$CMD2 2>>"${te}2"
8691 kill "$pid1" 2>/dev
/null
; wait;
8692 if [ "$rc2" -ne 0 ]; then
8693 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8698 numFAIL
=$
((numFAIL
+1))
8699 listFAIL
="$listFAIL $N"
8700 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8703 numFAIL
=$
((numFAIL
+1))
8704 listFAIL
="$listFAIL $N"
8707 if [ -n "$debug" ]; then cat $te; fi
8710 fi ;; # NUMCOND, feats
8716 NAME
=UDP6MULTICAST_UNIDIR
8718 *%$N%*|
*%functions
%*|
*%udp
%*|
*%udp6
%*|
*%ip6
%*|
*%dgram
%*|
*%multicast
%*|
*%$NAME%*)
8719 TEST
="$NAME: UDP/IPv6 multicast"
8720 if ! eval $NUMCOND; then :;
8721 elif ! feat
=$
(testaddrs ip6 udp
) ||
! runsip6
>/dev
/null
; then
8722 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8723 numCANT
=$
((numCANT
+1))
8725 tf
="$td/test$N.stdout"
8726 te
="$td/test$N.stderr"
8727 tdiff
="$td/test$N.diff"
8728 ts1p
=$PORT; PORT
=$
((PORT
+1))
8731 da
="test$N $(date) $RANDOM"
8732 CMD1
="$TRACE $SOCAT -u $opts UDP6-RECV:$ts1p,reuseaddr,ipv6-join-group=[ff02::2]:$if1 -"
8733 CMD2
="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p,bind=$ts1a"
8734 #CMD2="$TRACE $SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p"
8735 printf "test $F_n $TEST... " $N
8736 $CMD1 2>"${te}1" >"${tf}" &
8738 waitudp6port
$ts1p 1
8739 echo "$da" |
$CMD2 2>>"${te}2"
8742 kill "$pid1" 2>/dev
/null
; wait;
8743 if [ "$rc2" -ne 0 ]; then
8744 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8745 echo -e "$CMD1 &\n$CMD2"
8748 numFAIL
=$
((numFAIL
+1))
8749 listFAIL
="$listFAIL $N"
8750 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8755 numFAIL
=$
((numFAIL
+1))
8756 listFAIL
="$listFAIL $N"
8759 if [ "$VERBOSE" ]; then echo -e "$CMD1 &\n$CMD2"; fi
8760 if [ -n "$debug" ]; then cat $te; fi
8763 fi ;; # NUMCOND, feats
8768 NAME
=UDP4MULTICAST_BIDIR
8770 *%$N%*|
*%functions
%*|
*%udp
%*|
*%udp4
%*|
*%ip4
%*|
*%dgram
%*|
*%multicast
%*|
*%$NAME%*)
8771 TEST
="$NAME: UDP/IPv4 multicast, with reply"
8772 if ! eval $NUMCOND; then :; else
8773 tf
="$td/test$N.stdout"
8774 te
="$td/test$N.stderr"
8775 tdiff
="$td/test$N.diff"
8776 ts1p
=$PORT; PORT
=$
((PORT
+1))
8779 ts2p
=$PORT; PORT
=$
((PORT
+1))
8780 ts2
="$BCIFADDR:$ts2p"
8781 da
="test$N $(date) $RANDOM"
8782 CMD1
="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
8783 #CMD2="$TRACE $SOCAT $opts - UDP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
8784 CMD2
="$TRACE $SOCAT $opts - UDP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
8785 printf "test $F_n $TEST... " $N
8788 waitudp4port
$ts1p 1
8789 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
8791 kill "$pid1" 2>/dev
/null
; wait;
8792 if [ "$rc2" -ne 0 ]; then
8793 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8798 numFAIL
=$
((numFAIL
+1))
8799 listFAIL
="$listFAIL $N"
8800 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8803 numFAIL
=$
((numFAIL
+1))
8804 listFAIL
="$listFAIL $N"
8807 if [ -n "$VERBOSE" ]; then
8811 if [ -n "$debug" ]; then cat $te; fi
8818 NAME
=IP4MULTICAST_BIDIR
8820 *%$N%*|
*%functions
%*|
*%rawip
%*|
*%ip4
%*|
*%dgram
%*|
*%multicast
%*|
*%root
%*|
*%$NAME%*)
8821 TEST
="$NAME: IPv4 multicast, with reply"
8822 if ! eval $NUMCOND; then :;
8823 elif ! feat
=$
(testaddrs ip4 rawip
) ||
! runsip4
>/dev
/null
; then
8824 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8825 numCANT
=$
((numCANT
+1))
8826 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
8827 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8828 numCANT
=$
((numCANT
+1))
8830 tf
="$td/test$N.stdout"
8831 te
="$td/test$N.stderr"
8832 tdiff
="$td/test$N.diff"
8836 da
="test$N $(date) $RANDOM"
8837 CMD1
="$TRACE $SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE"
8838 #CMD2="$TRACE $SOCAT $opts - IP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a"
8839 CMD2
="$TRACE $SOCAT $opts - IP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a"
8840 printf "test $F_n $TEST... " $N
8844 usleep 100000 # give process a chance to add multicast membership
8845 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
8847 kill "$pid1" 2>/dev
/null
; wait;
8848 if [ "$rc2" -ne 0 ]; then
8849 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8854 numFAIL
=$
((numFAIL
+1))
8855 listFAIL
="$listFAIL $N"
8856 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8859 numFAIL
=$
((numFAIL
+1))
8860 listFAIL
="$listFAIL $N"
8863 if [ -n "$tut" ]; then
8867 if [ -n "$debug" ]; then cat $te; fi
8870 fi ;; # NUMCOND, feats
8878 *%$N%*|
*%functions
%*|
*%tun
%*|
*%root
%*|
*%$NAME%*)
8879 TEST
="$NAME: reading data sent through tun interface"
8880 #idea: create a TUN interface and send a datagram to one of the addresses of
8881 # its virtual network. On the tunnel side, read the packet and compare its last
8882 # bytes with the datagram payload
8883 if ! eval $NUMCOND; then :;
8884 elif ! feat
=$
(testaddrs ip4 tun
) ||
! runsip4
>/dev
/null
; then
8885 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8886 numCANT
=$
((numCANT
+1))
8887 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
8888 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8889 numCANT
=$
((numCANT
+1))
8891 tf
="$td/test$N.stdout"
8892 te
="$td/test$N.stderr"
8893 tdiff
="$td/test$N.diff"
8894 tl
="$td/test$N.lock"
8895 da
="test$N $(date) $RANDOM"
8898 CMD1
="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$TUNNET.2:$PORT"
8899 #CMD="$TRACE $SOCAT $opts -u -L $tl TUN,ifaddr=$TUNNET.1,netmask=255.255.255.0,iff-up=1 -"
8900 CMD
="$TRACE $SOCAT $opts -u -L $tl TUN:$TUNNET.1/24,iff-up=1 -"
8901 printf "test $F_n $TEST... " $N
8902 $CMD 2>"${te}" |
tail -c $dalen >"${tf}" &
8904 echo "$da" |
$CMD1 2>"${te}1"
8906 kill "$(cat $tl 2>/dev/null)" 2>/dev
/null
8908 if [ $?
-ne 0 ]; then
8909 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8912 cat "${te}" "${te}1"
8913 numFAIL
=$
((numFAIL
+1))
8914 listFAIL
="$listFAIL $N"
8915 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8920 cat "${te}" "${te}1"
8921 numFAIL
=$
((numFAIL
+1))
8922 listFAIL
="$listFAIL $N"
8925 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
8928 fi ;; # NUMCOND, feats
8934 # use the INTERFACE address on a tun/tap device and transfer data fully
8938 *%$N%*|
*%functions
%*|
*%tun
%*|
*%interface
%*|
*%root
%*|
*%$NAME%*)
8939 TEST
="$NAME: pass data through tun interface using INTERFACE"
8940 #idea: create a TUN interface and send a raw packet on the interface side.
8941 # It should arrive unmodified on the tunnel side.
8942 if ! eval $NUMCOND; then :;
8943 elif ! feat
=$
(testaddrs ip4 tun interface
) ||
! runsip4
>/dev
/null
; then
8944 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
8945 numCANT
=$
((numCANT
+1))
8946 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
8947 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
8948 numCANT
=$
((numCANT
+1))
8950 tf
="$td/test$N.stdout"
8951 te
="$td/test$N.stderr"
8952 tdiff
="$td/test$N.diff"
8953 tl
="$td/test$N.lock"
8954 da
="$(date) $RANDOM"
8958 CMD1
="$TRACE $SOCAT $opts -L $tl TUN:$TUNNET.1/24,iff-up=1,tun-type=tun,tun-name=$TUNNAME echo"
8959 CMD
="$TRACE $SOCAT $opts - INTERFACE:$TUNNAME"
8960 printf "test $F_n $TEST... " $N
8963 #waitinterface "$TUNNAME"
8965 echo "$da" |
$CMD 2>"${te}1" >"$tf" 2>"${te}"
8966 kill $pid1 2>/dev
/null
8968 if [ $?
-ne 0 ]; then
8969 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
8972 cat "${te}" "${te}1"
8973 numFAIL
=$
((numFAIL
+1))
8974 listFAIL
="$listFAIL $N"
8975 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
8980 cat "${te}" "${te}1"
8981 numFAIL
=$
((numFAIL
+1))
8982 listFAIL
="$listFAIL $N"
8985 if [ -n "$debug" ]; then cat "${te}" "${te}1"; fi
8988 fi ;; # NUMCOND, feats
8996 *%$N%*|
*%functions
%*|
*%unix
%*|
*%abstract
%*|
*%connect
%*|
*%listen
%*|
*%$NAME%*)
8997 TEST
="$NAME: abstract UNIX stream socket, listen and connect"
8998 if ! eval $NUMCOND; then :;
8999 elif ! feat
=$
(testaddrs abstract-unixsocket
); then
9000 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9001 numCANT
=$
((numCANT
+1))
9003 ts
="$td/test$N.socket"
9004 tf
="$td/test$N.stdout"
9005 te
="$td/test$N.stderr"
9006 tdiff
="$td/test$N.diff"
9007 da1
="test$N $(date) $RANDOM"
9008 #establish a listening abstract unix socket
9009 SRV
="$TRACE $SOCAT $opts -lpserver ABSTRACT-LISTEN:\"$ts\",$REUSEADDR PIPE"
9011 CMD
="$TRACE $SOCAT $opts - ABSTRACT-CONNECT:$ts"
9012 $PRINTF "test $F_n $TEST... " $N
9013 touch "$ts" # make a file with same name, so non-abstract fails
9014 eval "$SRV 2>${te}s &"
9018 echo "$da1" |
eval "$CMD" >"${tf}1" 2>"${te}1"
9019 if [ $?
-ne 0 ]; then
9020 kill "$pids" 2>/dev
/null
9021 $PRINTF "$FAILED:\n"
9026 numFAIL
=$
((numFAIL
+1))
9027 listFAIL
="$listFAIL $N"
9028 elif ! echo "$da1" |
diff - "${tf}1" >"$tdiff"; then
9029 kill "$pids" 2>/dev
/null
9030 $PRINTF "$FAILED:\n"
9036 numFAIL
=$
((numFAIL
+1))
9037 listFAIL
="$listFAIL $N"
9040 if [ -n "$debug" ]; then cat $te; fi
9044 fi ;; # NUMCOND, feats
9051 *%$N%*|
*%functions
%*|
*%unix
%*|
*%abstract
%*|
*%dgram
%*|
*%$NAME%*)
9052 TEST
="$NAME: abstract UNIX datagram"
9053 if ! eval $NUMCOND; then :;
9054 elif ! feat
=$
(testaddrs abstract-unixsocket
); then
9055 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9056 numCANT
=$
((numCANT
+1))
9058 tf
="$td/test$N.stdout"
9059 te
="$td/test$N.stderr"
9060 tdiff
="$td/test$N.diff"
9061 ts1
="$td/test$N.socket1"
9062 ts2
="$td/test$N.socket2"
9063 da
="test$N $(date) $RANDOM"
9064 CMD1
="$TRACE $SOCAT $opts ABSTRACT-RECVFROM:$ts1,reuseaddr PIPE"
9065 #CMD2="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
9066 CMD2
="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2"
9067 printf "test $F_n $TEST... " $N
9068 touch "$ts1" # make a file with same name, so non-abstract fails
9072 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
9074 kill "$pid1" 2>/dev
/null
; wait
9075 if [ $rc2 -ne 0 ]; then
9076 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9081 numFAIL
=$
((numFAIL
+1))
9082 listFAIL
="$listFAIL $N"
9083 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9086 numFAIL
=$
((numFAIL
+1))
9087 listFAIL
="$listFAIL $N"
9090 if [ -n "$debug" ]; then cat $te; fi
9093 fi ;; # NUMCOND, feats
9100 *%$N%*|
*%functions
%*|
*%unix
%*|
*%abstract
%*|
*%dgram
%*|
*%recv
%*|
*%$NAME%*)
9101 TEST
="$NAME: abstract UNIX datagram receive"
9102 if ! eval $NUMCOND; then :;
9103 elif ! feat
=$
(testaddrs abstract-unixsocket
); then
9104 $PRINTF "test $F_n $TEST... ${YELLOW}$feat not available${NORMAL}\n" $N
9105 numCANT
=$
((numCANT
+1))
9107 ts
="$td/test$N.socket"
9108 tf
="$td/test$N.stdout"
9109 te
="$td/test$N.stderr"
9110 tdiff
="$td/test$N.diff"
9112 da
="test$N $(date) $RANDOM"
9113 CMD1
="$TRACE $SOCAT $opts -u ABSTRACT-RECV:$ts1,reuseaddr -"
9114 CMD2
="$TRACE $SOCAT $opts -u - ABSTRACT-SENDTO:$ts1"
9115 printf "test $F_n $TEST... " $N
9116 touch "$ts1" # make a file with same name, so non-abstract fails
9117 $CMD1 >"$tf" 2>"${te}1" &
9121 echo "$da" |
$CMD2 2>>"${te}2"
9123 i
=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i
=$
((i
+1)); done
9124 kill "$pid1" 2>/dev
/null
; wait
9125 if [ "$rc2" -ne 0 ]; then
9126 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9131 numFAIL
=$
((numFAIL
+1))
9132 listFAIL
="$listFAIL $N"
9133 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9136 numFAIL
=$
((numFAIL
+1))
9137 listFAIL
="$listFAIL $N"
9140 if [ -n "$debug" ]; then cat $te; fi
9143 fi ;; # NUMCOND, feats
9148 # bind with Linux abstract UNIX domain addresses bound to filesystem socket
9149 # instead of abstract namespace
9152 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%socket
%*|
*%unix
%*|
*%abstract
%*|
*%$NAME%*)
9153 TEST
="$NAME: abstract bind"
9154 # open an abstract client address with bind option, bind to the target socket.
9156 # when socat outputs the datagram it got the test succeeded
9157 if ! eval $NUMCOND; then :;
9158 elif [ "$UNAME" != Linux
]; then
9159 $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
9160 numCANT
=$
((numCANT
+1))
9162 tf
="$td/test$N.stdout"
9163 te
="$td/test$N.stderr"
9164 tdiff
="$td/test$N.diff"
9165 ts1
="$td/test$N.sock1"
9166 da
="test$N $(date) $RANDOM"
9167 CMD1
="$TRACE $SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts1"
9168 printf "test $F_n $TEST... " $N
9169 echo "$da" |
$CMD1 >$tf 2>"${te}1"
9171 if [ $rc1 -ne 0 ]; then
9176 numFAIL
=$
((numFAIL
+1))
9177 listFAIL
="$listFAIL $N"
9178 elif echo "$da" |
diff -q - $tf; then
9185 echo "$da" |
diff - "$tf" >&2
9186 numFAIL
=$
((numFAIL
+1))
9187 listFAIL
="$listFAIL $N"
9197 # socat determined availability of data using select(). With openssl, the
9198 # following situation might occur:
9199 # a SSL data block with more than 8192 bytes (socats default blocksize)
9200 # arrives; socat calls SSL_read, and the SSL routine reads the complete block.
9201 # socat then reads 8192 bytes from the SSL layer, the rest remains buffered.
9202 # If the TCP connection stays idle for some time, the data in the SSL layer
9203 # keeps there and is not transferred by socat until the socket indicates more
9206 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%$NAME%*)
9207 TEST
="$NAME: socat handles data buffered by openssl"
9208 #idea: have a socat process (server) that gets an SSL block that is larger than
9209 # socat transfer block size; keep the socket connection open and kill the
9210 # server process after a short time; if not the whole data block has been
9211 # transferred, the test has failed.
9212 if ! eval $NUMCOND; then :;
9213 elif ! feat
=$
(testaddrs openssl
) >/dev
/null
; then
9214 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9215 numCANT
=$
((numCANT
+1))
9219 tdiff
="$td/test$N.diff"
9220 da
="test$N $(date) $RANDOM"
9222 gentestcert
"$SRVCERT"
9223 CMD1
="$TRACE $SOCAT $opts -u -T 1 -b $($ECHO "$da\c
" |wc -c) OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=$SRVCERT.pem,verify=0 -"
9224 CMD2
="$TRACE $SOCAT $opts -u - OPENSSL-CONNECT:$LOCALHOST:$PORT,verify=0"
9225 printf "test $F_n $TEST... " $N
9227 $CMD1 2>"${te}1" >"$tf" &
9228 pid
=$
! # background process id
9230 (echo "$da"; sleep 2) |
$CMD2 2>"${te}2"
9231 kill "$pid" 2>/dev
/null
; wait
9232 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9233 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9239 numFAIL
=$
((numFAIL
+1))
9240 listFAIL
="$listFAIL $N"
9243 if [ -n "$debug" ]; then cat $te; fi
9247 fi # NUMCOND, featsesac
9253 # test: there is a bug with the readbytes option: when the socket delivered
9254 # exacly that many bytes as specified with readbytes and the stays idle (no
9255 # more data, no EOF), socat waits for more data instead of generating EOF on
9256 # this in put stream.
9260 *%$N%*|
*%functions
%*|
*%$NAME%*)
9261 TEST
="$NAME: trigger EOF after that many bytes, even when socket idle"
9262 #idea: we deliver that many bytes to socat; the process should terminate then.
9263 # we try to transfer data in the other direction then; if transfer succeeds,
9264 # the process did not terminate and the bug is still there.
9265 if ! eval $NUMCOND; then :;
9267 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
9268 numCANT
=$
((numCANT
+1))
9274 tdiff
="$td/test$N.diff"
9275 da
="test$N $(date) $RANDOM"; da
="$da$($ECHO '\r')"
9276 CMD
="$TRACE $SOCAT $opts SYSTEM:\"echo A; sleep $((2*SECONDs))\",readbytes=2!!- -!!/dev/null"
9277 printf "test $F_n $TEST... " $N
9278 (usleep $
((2*MICROS
)); echo) |
eval "$CMD" >"$to" 2>"$te"
9279 if test -s "$to"; then
9280 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9282 numFAIL
=$
((numFAIL
+1))
9283 listFAIL
="$listFAIL $N"
9286 if [ -n "$debug" ]; then cat $te; fi
9289 fi ;; # NUMCOND, feats
9294 # test: there was a bug with exec:...,pty that did not kill the exec'd sub
9295 # process under some circumstances.
9298 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%exec%*|
*%$NAME%*)
9299 TEST
="$NAME: exec:...,pty explicitely kills sub process"
9300 # we want to check if the exec'd sub process is killed in time
9301 # for this we have a shell script that generates a file after two seconds;
9302 # it should be killed after one second, so if the file was generated the test
9304 if ! eval $NUMCOND; then :; else
9305 tf
="$td/test$N.stdout"
9306 te
="$td/test$N.stderr"
9307 ts
="$td/test$N.sock"
9308 tda
="$td/test$N.data"
9310 tdiff
="$td/test$N.diff"
9312 sleep $SECONDs; echo; sleep $SECONDs; touch "$tda"; echo
9315 CMD1
="$TRACE $SOCAT $opts -t $SECONDs -U UNIX-LISTEN:$ts,fork EXEC:$tsh,pty"
9316 CMD
="$TRACE $SOCAT $opts -t $SECONDs /dev/null UNIX-CONNECT:$ts"
9317 printf "test $F_n $TEST... " $N
9321 waitfile
$ts $SECONDs
9322 $CMD 2>>"${te}1" >>"$tf"
9323 sleep $
((2*SECONDs
))
9324 kill "$pid1" 2>/dev
/null
9326 if [ $?
-ne 0 ]; then
9327 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9330 cat "${te}1" "${te}2"
9331 numFAIL
=$
((numFAIL
+1))
9332 listFAIL
="$listFAIL $N"
9333 elif [ -f "$tda" ]; then
9335 cat "${te}1" "${te}2"
9336 numFAIL
=$
((numFAIL
+1))
9337 listFAIL
="$listFAIL $N"
9340 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9349 # test if service name resolution works; this was buggy in 1.5 and 1.6.0.0
9352 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%tcp
%*|
*%$NAME%*)
9353 TEST
="$NAME: echo via connection to TCP V4 socket"
9354 # select a tcp entry from /etc/services, have a server listen on the port
9355 # number and connect using the service name; with the bug, connection will to a
9357 if ! eval $NUMCOND; then :; else
9358 tf
="$td/test$N.stdout"
9359 te
="$td/test$N.stderr"
9360 tdiff
="$td/test$N.diff"
9361 # find a service entry we do not need root for (>=1024; here >=1100 for ease)
9362 SERVENT
="$(grep '^[a-z][a-z]*[^!-~][^!-~]*[1-9][1-9][0-9][0-9]/tcp' /etc/services |head -n 1)"
9363 SERVICE
="$(echo $SERVENT |cut -d' ' -f1)"
9365 PORT
="$(echo $SERVENT |sed 's/.* \([1-9][0-9]*\).*/\1/')"
9367 ts
="127.0.0.1:$SERVICE"
9368 da
="test$N $(date) $RANDOM"
9369 CMD1
="$TRACE $SOCAT $opts TCP4-LISTEN:$tsl,$REUSEADDR PIPE"
9370 CMD2
="$TRACE $SOCAT $opts stdin!!stdout TCP4:$ts"
9371 printf "test $F_n $TEST... " $N
9372 $CMD1 >"$tf" 2>"${te}1" &
9375 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
9376 if [ $?
-ne 0 ]; then
9377 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9382 numFAIL
=$
((numFAIL
+1))
9383 listFAIL
="$listFAIL $N"
9384 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9387 numFAIL
=$
((numFAIL
+1))
9388 listFAIL
="$listFAIL $N"
9391 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9394 kill $pid1 2>/dev
/null
9402 # test: up to socat 1.6.0.0, the highest file descriptor supported in socats
9403 # transfer engine was FOPEN_MAX-1; this usually worked fine but would fail when
9404 # socat was invoked with many file descriptors already opened. socat would
9405 # just hang in the select() call. Thanks to Daniel Lucq for reporting this
9407 # FOPEN_MAX on different OS's:
9408 # OS FOPEN_ ulimit ulimit FD_
9409 # MAX -H -n -S -n SETSIZE
9410 # Linux 2.6: 16 1024 1024 1024
9411 # HP-UX 11.11: 60 2048 2048 2048
9412 # FreeBSD: 20 11095 11095 1024
9413 # Cygwin: 20 unlimit 256 64
9414 # AIX: 32767 65534 65534
9416 NAME
=EXCEED_FOPEN_MAX
9418 *%$N%*|
*%functions
%*|
*%maxfds
%*|
*%$NAME%*)
9419 TEST
="$NAME: more than FOPEN_MAX FDs in use"
9420 # this test opens a number of FDs before socat is invoked. socat will have to
9421 # allocate higher FD numbers and thus hang if it cannot handle them.
9422 if ! eval $NUMCOND; then :; else
9425 FOPEN_MAX
=$
($PROCAN -c 2>/dev
/null |
grep '^#define[ ][ ]*FOPEN_MAX' |
awk '{print($3);}')
9426 if [ -z "$FOPEN_MAX" ]; then
9427 $PRINTF "test $F_n $TEST... ${YELLOW}could not determine FOPEN_MAX${NORMAL}\n" "$N"
9428 numCANT
=$
((numCANT
+1))
9430 OPEN_FILES
=$FOPEN_MAX # more than the highest FOPEN_MAX
9431 i
=3; while [ "$i" -lt "$OPEN_FILES" ]; do
9432 REDIR
="$REDIR $i>&2"
9436 #testecho "$N" "$TEST" "" "pipe" "$opts -T 3" "" 1
9438 eval testecho
"\"$N\"" "\"$TEST\"" "\"\"" "pipe" "\"$opts -T $((2*SECONDs))\"" 1 $REDIR
9440 fi # could determine FOPEN_MAX
9446 # there was a bug with udp-listen and fork: terminating sub processes became
9447 # zombies because the master process did not catch SIGCHLD
9448 NAME
=UDP4LISTEN_SIGCHLD
9450 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%udp
%*|
*%zombie
%*|
*%signal
%*|
*%$NAME%*)
9451 TEST
="$NAME: test if UDP4-LISTEN child becomes zombie"
9452 # idea: run a udp-listen process with fork and -T. Connect once, so a sub
9453 # process is forked off. Make some transfer and wait until the -T timeout is
9454 # over. Now check for the child process: if it is zombie the test failed.
9455 # Correct is that child process terminated
9456 if ! eval $NUMCOND; then :; else
9457 tf
="$td/test$N.stdout"
9458 te
="$td/test$N.stderr"
9459 tdiff
="$td/test$N.diff"
9461 ts
="$LOCALHOST:$tsl"
9462 da
="test$N $(date) $RANDOM"
9463 CMD1
="$TRACE $SOCAT $opts -T 0.5 UDP4-LISTEN:$tsl,$REUSEADDR,fork PIPE"
9464 CMD2
="$TRACE $SOCAT $opts - UDP4:$ts"
9465 printf "test $F_n $TEST... " $N
9466 $CMD1 >"$tf" 2>"${te}1" &
9469 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
9473 l
="$(childprocess $pid1)"
9474 kill $pid1 2>/dev
/null
; wait
9475 if [ $rc2 -ne 0 ]; then
9476 $PRINTF "$NO_RESULT (client failed)\n" # already handled in test UDP4STREAM
9477 numCANT
=$
((numCANT
+1))
9478 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9479 $PRINTF "$NO_RESULT (diff failed)\n" # already handled in test UDP4STREAM
9480 numCANT
=$
((numCANT
+1))
9481 elif $
(isdefunct
"$l"); then
9482 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9485 cat "${te}1" "${te}2"
9486 numFAIL
=$
((numFAIL
+1))
9487 listFAIL
="$listFAIL $N"
9490 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9499 # there was a bug with udp-recvfrom and fork: terminating sub processes became
9500 # zombies because the master process caught SIGCHLD but did not wait()
9501 NAME
=UDP4RECVFROM_SIGCHLD
9503 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%udp
%*|
*%dgram
%*|
*%zombie
%*|
*%signal
%*|
*%$NAME%*)
9504 TEST
="$NAME: test if UDP4-RECVFROM child becomes zombie"
9505 # idea: run a udp-recvfrom process with fork and -T. Send it one packet, so a
9506 # sub process is forked off. Make some transfer and wait until the -T timeout
9507 # is over. Now check for the child process: if it is zombie the test failed.
9508 # Correct is that child process terminated
9509 if ! eval $NUMCOND; then :; else
9510 tf
="$td/test$N.stdout"
9511 te
="$td/test$N.stderr"
9512 tdiff
="$td/test$N.diff"
9514 ts
="$LOCALHOST:$tsl"
9515 da
="test$N $(date) $RANDOM"
9516 CMD1
="$TRACE $SOCAT $opts -T 0.5 UDP4-RECVFROM:$tsl,reuseaddr,fork PIPE"
9517 CMD2
="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts"
9518 printf "test $F_n $TEST... " $N
9519 $CMD1 >"$tf" 2>"${te}1" &
9522 echo "$da" |
$CMD2 >>"$tf" 2>>"${te}2"
9526 l
="$(childprocess $pid1)"
9527 kill $pid1 2>/dev
/null
; wait
9528 if [ $rc2 -ne 0 ]; then
9529 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9530 numCANT
=$
((numCANT
+1))
9531 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9532 $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM
9533 numCANT
=$
((numCANT
+1))
9534 elif $
(isdefunct
"$l"); then
9535 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9538 cat "${te}1" "${te}2"
9539 numFAIL
=$
((numFAIL
+1))
9540 listFAIL
="$listFAIL $N"
9543 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
9552 # test: there was a bug with ip*-recv and bind option: it would not bind, and
9553 # with the first received packet an error:
9554 # socket_init(): unknown address family 0
9558 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%dgram
%*|
*%rawip
%*|
*%rawip4
%*|
*%recv
%*|
*%root
%*|
*%$NAME%*)
9559 TEST
="$NAME: raw IPv4 receive with bind"
9560 # idea: start a socat process with ip4-recv:...,bind=... and send it a packet
9561 # if the packet passes the test succeeded
9562 if ! eval $NUMCOND; then :;
9563 elif [ $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
9564 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9565 numCANT
=$
((numCANT
+1))
9567 tf
="$td/test$N.stdout"
9568 te
="$td/test$N.stderr"
9569 tdiff
="$td/test$N.diff"
9570 ts1p
=$PROTO; PROTO
=$
((PROTO
+1))
9573 da
="test$N $(date) $RANDOM"
9574 CMD1
="$TRACE $SOCAT $opts -u IP4-RECV:$ts1p,bind=$ts1a,reuseaddr -"
9575 CMD2
="$TRACE $SOCAT $opts -u - IP4-SENDTO:$ts1"
9576 printf "test $F_n $TEST... " $N
9577 $CMD1 >"$tf" 2>"${te}1" &
9579 waitip4proto
$ts1p 1
9580 echo "$da" |
$CMD2 2>>"${te}2"
9583 i
=0; while [ ! -s "$tf" -a "$i" -lt 10 ]; do usleep 100000; i
=$
((i
+1)); done
9584 kill "$pid1" 2>/dev
/null
; wait
9585 if [ "$rc2" -ne 0 ]; then
9586 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9591 numFAIL
=$
((numFAIL
+1))
9592 listFAIL
="$listFAIL $N"
9593 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9596 numFAIL
=$
((numFAIL
+1))
9597 listFAIL
="$listFAIL $N"
9600 if [ -n "$debug" ]; then cat $te; fi
9603 fi ;; # NUMCOND, root
9609 # there was a bug in *-recvfrom with fork: due to an error in the appropriate
9610 # signal handler the master process would hang after forking off the first
9612 NAME
=UDP4RECVFROM_FORK
9614 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%udp
%*|
*%dgram
%*|
*%$NAME%*)
9615 TEST
="$NAME: test if UDP4-RECVFROM handles more than one packet"
9616 # idea: run a UDP4-RECVFROM process with fork and -T. Send it one packet;
9617 # send it a second packet and check if this is processed properly. If yes, the
9619 if ! eval $NUMCOND; then :; else
9620 tf
="$td/test$N.stdout"
9621 te
="$td/test$N.stderr"
9622 tdiff
="$td/test$N.diff"
9624 ts
="$LOCALHOST:$tsp"
9625 da
="test$N $(date) $RANDOM"
9626 CMD1
="$TRACE $SOCAT $opts -T 2 UDP4-RECVFROM:$tsp,reuseaddr,fork PIPE"
9627 CMD2
="$TRACE $SOCAT $opts -T 1 - UDP4-SENDTO:$ts"
9628 printf "test $F_n $TEST... " $N
9629 $CMD1 >/dev
/null
2>"${te}1" &
9632 echo "$da" |
$CMD2 >/dev
/null
2>>"${te}2" # this should always work
9635 echo "$da" |
$CMD2 >"$tf" 2>>"${te}3" # this would fail when bug
9637 kill $pid1 2>/dev
/null
; wait
9638 if [ $rc2b -ne 0 ]; then
9639 $PRINTF "$NO_RESULT\n"
9640 numCANT
=$
((numCANT
+1))
9641 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9642 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9645 cat "${te}1" "${te}2" "${te}3"
9647 numFAIL
=$
((numFAIL
+1))
9648 listFAIL
="$listFAIL $N"
9651 if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3"; fi
9660 # there was a bug in parsing the arguments of exec: consecutive spaces resulted
9661 # in additional empty arguments
9664 *%$N%*|
*%functions
%*|
*%exec%*|
*%parse
%*|
*%$NAME%*)
9665 TEST
="$NAME: correctly parse exec with consecutive spaces"
9666 if ! eval $NUMCOND; then :; else
9667 $PRINTF "test $F_n $TEST... " $N
9668 tf
="$td/test$N.stdout"
9669 te
="$td/test$N.stderr"
9670 da
="test$N $(date) $RANDOM" # with a double space
9671 tdiff
="$td/test$N.diff"
9672 # put the test data as first argument after two spaces. expect the data in the
9673 # first argument of the exec'd command.
9674 $TRACE $SOCAT $opts -u "exec:\"bash -c \\\"echo \\\\\\\"\$1\\\\\\\"\\\" \\\"\\\" \\\"$da\\\"\"" - >"$tf" 2>"$te"
9676 echo "$da" |
diff - "$tf" >"$tdiff"
9677 if [ "$rc" -ne 0 ]; then
9678 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9680 numFAIL
=$
((numFAIL
+1))
9681 listFAIL
="$listFAIL $N"
9682 elif [ -s "$tdiff" ]; then
9683 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9686 if [ -n "$debug" ]; then cat $te; fi
9687 numFAIL
=$
((numFAIL
+1))
9688 listFAIL
="$listFAIL $N"
9691 if [ -n "$debug" ]; then cat $te; fi
9699 # a bug was found in the way UDP-LISTEN handles the listening socket:
9700 # when UDP-LISTEN continued to listen after a packet had been dropped by, e.g.,
9701 # range option, the old listen socket would not be closed but a new one created.
9704 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%ip4
%*|
*%udp
%*|
*%$NAME%*)
9705 TEST
="$NAME: let range drop a packet and see if old socket is closed"
9706 # idea: run a UDP4-LISTEN process with range option. Send it one packet from an
9707 # address outside range and check if two listening sockets are open then
9708 if ! eval $NUMCOND; then :; else
9709 tf
="$td/test$N.stdout"
9710 te
="$td/test$N.stderr"
9711 tdiff
="$td/test$N.diff"
9713 while [ "$($SS -anu |grep "127\
.0\
.0\
.1:$PORT\
>" |wc -l)" -ne 0 ]; do
9717 while [ "$(netstat -an |grep "^udp.
*127\
.0\
.0\
.1:$PORT\
>" |wc -l)" -ne 0 ]; do
9722 da1
="test$N $(date) $RANDOM"
9725 #CMD0="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,bind=$a1,range=$a2/32 PIPE"
9726 CMD0
="$TRACE $SOCAT $opts UDP4-LISTEN:$tp,$REUSEADDR,range=$a2/32 PIPE"
9727 CMD1
="$TRACE $SOCAT $opts - UDP-CONNECT:$a1:$tp"
9728 printf "test $F_n $TEST... " $N
9729 $CMD0 >/dev
/null
2>"${te}0" &
9732 echo "$da1" |
$CMD1 >"${tf}1" 2>"${te}1" # this should fail
9736 nsocks
="$($SS -anu |grep ":$PORT\
>" |wc -l)"
9738 nsocks
="$(netstat -an |grep "^udp.
*[:.
]$PORT\
>" |wc -l)"
9740 kill $pid1 2>/dev
/null
; wait
9741 if [ $rc1 -ne 0 ]; then
9742 $PRINTF "$NO_RESULT\n"
9743 numCANT
=$
((numCANT
+1))
9744 elif [ $nsocks -eq 0 ]; then
9745 $PRINTF "$NO_RESULT\n"
9746 numCANT
=$
((numCANT
+1))
9747 elif [ $nsocks -ne 1 ]; then
9748 $PRINTF "$FAILED ($nsocks listening sockets)\n"
9751 cat "${te}0" "${te}1"
9752 numFAIL
=$
((numFAIL
+1))
9753 listFAIL
="$listFAIL $N"
9756 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
9765 # during wait for next poll time option ignoreeof blocked the data transfer in
9766 # the reverse direction
9767 NAME
=IGNOREEOFNOBLOCK
9769 *%$N%*|
*%functions
%*|
*%engine
%*|
*%socket
%*|
*%ignoreeof
%*|
*%$NAME%*)
9770 TEST
="$NAME: ignoreeof does not block other direction"
9771 # have socat poll in ignoreeof mode. while it waits one second for next check,
9772 # we send data in the reverse direction and then the total timeout fires.
9773 # it the data has passed, the test succeeded.
9774 if ! eval $NUMCOND; then :; else
9775 tf
="$td/test$N.stout"
9776 te
="$td/test$N.stderr"
9777 tdiff
="$td/test$N.diff"
9778 da
="test$N $(date) $RANDOM"
9779 CMD0
="$TRACE $SOCAT $opts /dev/null,ignoreeof!!- -!!/dev/null"
9780 printf "test $F_n $TEST... " $N
9781 (usleep 333333; echo "$da") |
$CMD0 >"$tf" 2>"${te}0"
9783 if [ $rc0 != 0 ]; then
9789 numFAIL
=$
((numFAIL
+1))
9790 listFAIL
="$listFAIL $N"
9791 elif echo "$da" |
diff - "$tf" >/dev
/null
; then
9799 numFAIL
=$
((numFAIL
+1))
9800 listFAIL
="$listFAIL $N"
9807 # test the escape option
9810 *%$N%*|
*%functions
%*|
*%engine
%*|
*%escape
%*|
*%$NAME%*)
9811 TEST
="$NAME: escape character triggers EOF"
9812 # idea: start socat just echoing input, but apply escape option. send a string
9813 # containing the escape character and check if the output is truncated
9814 if ! eval $NUMCOND; then :; else
9815 tf
="$td/test$N.stdout"
9816 te
="$td/test$N.stderr"
9817 tdiff
="$td/test$N.diff"
9818 da
="test$N $(date) $RANDOM"
9819 CMD
="$TRACE $SOCAT $opts -,escape=27 pipe"
9820 printf "test $F_n $TEST... " $N
9821 $ECHO "$da\n\x1bXYZ" |
$CMD >"$tf" 2>"$te"
9822 if [ $?
-ne 0 ]; then
9823 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
9826 numFAIL
=$
((numFAIL
+1))
9827 listFAIL
="$listFAIL $N"
9828 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9829 $PRINTF "$FAILED: diff:\n"
9831 numFAIL
=$
((numFAIL
+1))
9832 listFAIL
="$listFAIL $N"
9835 if [ -n "$debug" ]; then cat $te; fi
9842 # test the escape option combined with ignoreeof
9843 NAME
=ESCAPE_IGNOREEOF
9845 *%$N%*|
*%functions
%*|
*%engine
%*|
*%ignoreeof
%*|
*%escape
%*|
*%$NAME%*)
9846 TEST
="$NAME: escape character triggers EOF"
9847 # idea: start socat just echoing input, but apply escape option. send a string
9848 # containing the escape character and check if the output is truncated
9849 if ! eval $NUMCOND; then :; else
9850 ti
="$td/test$N.file"
9851 tf
="$td/test$N.stdout"
9852 te
="$td/test$N.stderr"
9853 tdiff
="$td/test$N.diff"
9854 da
="test$N $(date) $RANDOM"
9855 CMD
="$TRACE $SOCAT -T 5 $opts file:$ti,ignoreeof,escape=27!!- pipe"
9856 printf "test $F_n $TEST... " $N
9858 $CMD >"$tf" 2>"$te" &
9859 $ECHO "$da\n\x1bXYZ" >>"$ti"
9861 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
9862 $PRINTF "$FAILED: diff:\n"
9865 numFAIL
=$
((numFAIL
+1))
9866 listFAIL
="$listFAIL $N"
9869 if [ -n "$debug" ]; then cat $te; fi
9877 # test: logging of ancillary message
9878 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_TYPE SCM_NAME ROOT SCM_VALUE
9880 if [ -z "$PF" ] ||
[[ "$PF" == \
#* ]]; then continue; fi
9882 pf
="$(echo "$PF" |tr A-Z a-z)"
9883 proto
="$(echo "$KEYW" |tr A-Z a-z)"
9884 NAME
=${KEYW}SCM_
$SCM_TYPE
9886 *%$N%*|
*%functions
%*|
*%socket
%*|
*%$pf%*|
*%dgram
%*|
*%udp
%*|
*%$proto%*|
*%recv
%*|
*%ancillary
%*|
*%$ROOT%*|
*%$NAME%*)
9887 TEST
="$NAME: $KEYW log ancillary message $SCM_TYPE $SCM_NAME"
9888 # idea: start a socat process with *-RECV:..,... , ev. with ancillary message
9889 # enabling option and send it a packet, ev. with some option. check the info log
9890 # for the appropriate output.
9891 if ! eval $NUMCOND; then :;
9892 #elif [[ "$PF" == "#*" ]]; then :
9893 elif [ "$ROOT" = root
-a $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
9894 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
9895 numCANT
=$
((numCANT
+1))
9896 elif [ "$PF" = "IP6" ] && ( ! feat
=$
(testaddrs ip6
) ||
! runsip6
>/dev
/null
); then
9897 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
9898 numCANT
=$
((numCANT
+1))
9899 elif ! testoptions
$SCM_RECV >/dev
/null
; then
9900 $PRINTF "test $F_n $TEST... ${YELLOW}option $SCM_RECV not available${NORMAL}\n" $N
9901 numCANT
=$
((numCANT
+1))
9903 tf
="$td/test$N.stdout"
9904 te
="$td/test$N.stderr"
9907 tra
="$PORT" # test recv address
9908 tsa
="$ADDR:$PORT" # test sendto address
9911 tra
="$PROTO" # test recv address
9912 tsa
="$ADDR:$PROTO" # test sendto address
9913 PROTO
=$
((PROTO
+1)) ;;
9915 tra
="$(eval echo "$ADDR")" # resolve $N
9918 CMD0
="$TRACE $SOCAT $opts -d -d -d -u $KEYW-RECV:$tra,reuseaddr,$SCM_RECV -"
9919 CMD1
="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
9920 printf "test $F_n $TEST... " $N
9921 # is this option supported?
9922 if $TRACE $SOCAT -hhh |
grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev
/null
; then
9923 $CMD0 >"$tf" 2>"${te}0" &
9925 wait${proto}port
$tra 1
9926 echo "XYZ" |
$CMD1 2>"${te}1"
9929 i
=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i
=$
((i
+1)); done
9930 kill "$pid0" 2>/dev
/null
; wait
9931 # do not show more messages than requested
9933 *-d*-d*-d*-d*) LEVELS
="[EWNID]" ;;
9934 *-d*-d*-d*) LEVELS
="[EWNI]" ;;
9935 *-d*-d*) LEVELS
="[EWN]" ;;
9936 *-d*) LEVELS
="[EW]" ;;
9939 if [ "$SCM_VALUE" = "timestamp" ]; then
9940 SCM_VALUE
="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
9942 if [ "$rc1" -ne 0 ]; then
9943 $PRINTF "$NO_RESULT: $TRACE $SOCAT:\n"
9946 grep " $LEVELS " "${te}0"
9947 grep " $LEVELS " "${te}1"
9948 numCANT
=$
((numCANT
+1))
9949 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=" ${te}0 >/dev
/null
; then
9951 echo "variable $SCM_TYPE: $SCM_NAME not set"
9954 grep " $LEVELS " "${te}0"
9955 grep " $LEVELS " "${te}1"
9956 numFAIL
=$
((numFAIL
+1))
9957 listFAIL
="$listFAIL $N"
9958 elif ! grep "ancillary message: $SCM_TYPE: $SCM_NAME=$SCM_VALUE\$" ${te}0 >/dev
/null
; then
9960 badval
="$(grep "ancillary message
: $SCM_TYPE: $SCM_NAME" ${te}0 |sed 's/.*=//g')"
9961 echo "variable $SCM_TYPE: $SCM_NAME has value \"$badval\" instead of pattern \"$SCM_VALUE\"" >&2
9964 grep " $LEVELS " "${te}0"
9965 grep " $LEVELS " "${te}1"
9966 numFAIL
=$
((numFAIL
+1))
9967 listFAIL
="$listFAIL $N"
9970 if [ -n "$debug" ]; then
9971 grep " $LEVELS " "${te}0"; echo; grep " $LEVELS " "${te}1";
9975 else # option is not supported
9976 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
9977 numCANT
=$
((numCANT
+1))
9978 fi # option is not supported
9979 fi # NUMCOND, root, feats
9985 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS options user x01000000
9986 IP4 UDP4 127.0.0.1 PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
9987 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL ttl user 53
9988 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS tos user 7
9989 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO locaddr user 127.0.0.1
9990 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO dstaddr user 127.0.0.1
9991 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_PKTINFO if user lo
9992 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_RECVIF if user lo0
9993 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_RECVDSTADDR dstaddr user 127.0.0.1
9994 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS options root x01000000
9995 IP4 IP4 127.0.0.1 PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
9996 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL ttl root 53
9997 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS tos root 7
9998 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO locaddr root 127.0.0.1
9999 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO dstaddr root 127.0.0.1
10000 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_PKTINFO if root lo
10001 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_RECVIF if root lo0
10002 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_RECVDSTADDR dstaddr root 127.0.0.1
10003 IP6 UDP6 [::1] PORT , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10004 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_PKTINFO dstaddr user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10005 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit user 35
10006 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass user x000000aa
10007 IP6 IP6 [::1] PROTO , so-timestamp SCM_TIMESTAMP timestamp root timestamp
10008 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_PKTINFO dstaddr root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10009 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT hoplimit root 35
10010 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS tclass root x000000aa
10011 #UNIX UNIX $td/test\$N.server - , so-timestamp SCM_TIMESTAMP timestamp user timestamp
10013 # this one fails, appearently due to a Linux weakness:
10014 # UNIX so-timestamp
10017 # test: setting of environment variables that describe a stream socket
10018 # connection: SOCAT_SOCKADDR, SOCAT_PEERADDR; and SOCAT_SOCKPORT,
10019 # SOCAT_PEERPORT when applicable
10020 while read KEYW FEAT TEST_SOCKADDR TEST_PEERADDR TEST_SOCKPORT TEST_PEERPORT
; do
10021 if [ -z "$KEYW" ] ||
[[ "$KEYW" == \
#* ]]; then continue; fi
10023 test_proto
="$(echo "$KEYW" |tr A-Z a-z)"
10024 NAME
=${KEYW}LISTENENV
10026 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%tcp
%*|
*%$test_proto%*|
*%envvar
%*|
*%$NAME%*)
10027 TEST
="$NAME: $KEYW-LISTEN sets environment variables with socket addresses"
10028 # have a server accepting a connection and invoking some shell code. The shell
10029 # code extracts and prints the SOCAT related environment vars.
10030 # outside code then checks if the environment contains the variables correctly
10031 # describing the peer and local sockets.
10032 if ! eval $NUMCOND; then :;
10033 elif ! feat
=$
(testaddrs
$FEAT); then
10034 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat" |tr a-z A-Z) not available${NORMAL}\n" $N
10035 numCANT
=$
((numCANT
+1))
10036 elif [ "$KEYW" = "TCP6" -o "$KEYW" = "UDP6" -o "$KEYW" = "SCTP6" ] && \
10037 ! runsip6
>/dev
/null
; then
10038 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10039 numCANT
=$
((numCANT
+1))
10040 elif [ "$KEYW" = "SCTP4" ] && ! runssctp4
"$((PORT))"; then
10041 $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
10042 elif [ "$KEYW" = "SCTP6" ] && ! runssctp6
"$((PORT))"; then
10043 #!!! branch not reached - caught above!
10044 $PRINTF "test $F_n $TEST... ${YELLOW}$KEYW not available${NORMAL}\n" $N
10046 tf
="$td/test$N.stdout"
10047 te
="$td/test$N.stderr"
10048 TEST_SOCKADDR
="$(echo "$TEST_SOCKADDR" |sed "s
/\
$N/$N/g
")" # actual vars
10049 tsa
="$TEST_SOCKADDR" # test server address
10050 tsp
="$TEST_SOCKPORT" # test server port
10051 if [ "$tsp" != ',' ]; then
10052 tsa1
="$tsp"; tsa2
="$tsa"; tsa
="$tsa:$tsp" # tsa2 used for server bind=
10054 tsa1
="$tsa"; tsa2
= # tsa1 used for addr parameter
10056 TEST_PEERADDR
="$(echo "$TEST_PEERADDR" |sed "s
/\
$N/$N/g
")" # actual vars
10057 tca
="$TEST_PEERADDR" # test client address
10058 tcp
="$TEST_PEERPORT" # test client port
10059 if [ "$tcp" != ',' ]; then
10062 #CMD0="$TRACE $SOCAT $opts -u $KEYW-LISTEN:$tsa1 SYSTEM:\"export -p\""
10063 CMD0
="$TRACE $SOCAT $opts -u -lpsocat $KEYW-LISTEN:$tsa1,$REUSEADDR SYSTEM:\"echo SOCAT_SOCKADDR=\\\$SOCAT_SOCKADDR; echo SOCAT_PEERADDR=\\\$SOCAT_PEERADDR; echo SOCAT_SOCKPORT=\\\$SOCAT_SOCKPORT; echo SOCAT_PEERPORT=\\\$SOCAT_PEERPORT; sleep 1\""
10064 CMD1
="$TRACE $SOCAT $opts -u - $KEYW-CONNECT:$tsa,bind=$tca"
10065 printf "test $F_n $TEST... " $N
10066 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
10068 wait${test_proto}port
$tsa1 1
10069 echo |
$CMD1 2>"${te}1"
10072 kill $pid0 2>/dev
/null
; wait
10074 if [ $rc1 != 0 ]; then
10075 $PRINTF "$NO_RESULT (client failed):\n"
10080 numCANT
=$
((numCANT
+1))
10081 elif [ "$(grep SOCAT_SOCKADDR "${tf}" |sed -e 's/^[^=]*=//' |sed -e "s
/[\"']//g")" = "$TEST_SOCKADDR" -a \
10082 "$(grep SOCAT_PEERADDR "${tf}" |sed -e 's
/^
[^
=]*=//' -e "s/[\"']//g
")" = "$TEST_PEERADDR" -a \
10083 \
( "$TEST_SOCKPORT" = ',' -o "$(grep SOCAT_SOCKPORT "${tf}" |sed -e 's/^[^=]*=//' |sed -e 's/"//g
')" = "$tsp" \) -a \
10084 \( "$TEST_PEERPORT" = ',' -o "$(grep SOCAT_PEERPORT "${tf}" |sed -e 's
/^
[^
=]*=//' |sed -e 's
/"//g')" = "$tcp" \
) \
10087 if [ "$debug" ]; then
10095 $PRINTF "$FAILED\n"
10100 echo -e "SOCAT_SOCKADDR=$TEST_SOCKADDR\nSOCAT_PEERADDR=$TEST_PEERADDR\nSOCAT_SOCKPORT=$TEST_SOCKPORT\nSOCAT_PEERPORT=$TEST_PEERPORT" |
10102 numFAIL
=$
((numFAIL
+1))
10103 listFAIL
="$listFAIL $N"
10105 fi # NUMCOND, feats
10112 TCP4 TCP 127.0.0.1 $SECONDADDR $PORT $((PORT+1))
10113 TCP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+2)) $((PORT+3))
10114 UDP6 IP6 [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+6)) $((PORT+7))
10115 SCTP4 SCTP 127.0.0.1 $SECONDADDR $((PORT+8)) $((PORT+9))
10116 SCTP6 SCTP [0000:0000:0000:0000:0000:0000:0000:0001] [0000:0000:0000:0000:0000:0000:0000:0001] $((PORT+10)) $((PORT+11))
10117 UNIX UNIX $td/test\$N.server $td/test\$N.client , ,
10119 # this one fails due to weakness in socats UDP4-LISTEN implementation:
10120 #UDP4 $LOCALHOST $SECONDADDR $((PORT+4)) $((PORT+5))
10123 # test: environment variables from ancillary message
10124 while read PF KEYW ADDR IPPORT SCM_ENABLE SCM_RECV SCM_ENVNAME ROOT SCM_VALUE
10126 if [ -z "$PF" ] ||
[[ "$PF" == \
#* ]]; then continue; fi
10128 pf
="$(echo "$PF" |tr A-Z a-z)"
10129 proto
="$(echo "$KEYW" |tr A-Z a-z)"
10130 NAME
=${KEYW}ENV_
$SCM_ENVNAME
10132 *%$N%*|
*%functions
%*|
*%socket
%*|
*%$pf%*|
*%dgram
%*|
*%udp
%*|
*%$proto%*|
*%recv
%*|
*%ancillary
%*|
*%envvar
%*|
*%$ROOT%*|
*%$NAME%*)
10134 TEST
="$NAME: $KEYW ancillary message sets env SOCAT_$SCM_ENVNAME"
10135 # idea: start a socat process with *-RECVFROM:..,... , ev. with ancillary
10136 # message enabling option and send it a packet, ev. with some option. write
10137 # the resulting environment to a file and check its contents for the
10138 # appropriate variable.
10139 if ! eval $NUMCOND; then :;
10140 elif [ "$ROOT" = root
-a $
(id
-u) -ne 0 -a "$withroot" -eq 0 ]; then
10141 $PRINTF "test $F_n $TEST... ${YELLOW}must be root${NORMAL}\n" $N
10142 numCANT
=$
((numCANT
+1))
10143 elif [ "$PF" = "IP6" ] && ( ! feat
=$
(testaddrs ip6
) ||
! runsip6
) >/dev
/null
; then
10144 $PRINTF "test $F_n $TEST... ${YELLOW}IP6 not available${NORMAL}\n" $N
10145 numCANT
=$
((numCANT
+1))
10147 tf
="$td/test$N.stdout"
10148 te
="$td/test$N.stderr"
10151 tra
="$PORT" # test recv address
10152 tsa
="$ADDR:$PORT" # test sendto address
10153 PORT
=$
((PORT
+1)) ;;
10155 tra
="$PROTO" # test recv address
10156 tsa
="$ADDR:$PROTO" # test sendto address
10157 PROTO
=$
((PROTO
+1)) ;;
10159 tra
="$(eval echo "$ADDR")" # resolve $N
10162 #CMD0="$TRACE $SOCAT $opts -u $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"export -p\""
10163 CMD0
="$TRACE $SOCAT $opts -u -lpsocat $KEYW-RECVFROM:$tra,reuseaddr,$SCM_RECV SYSTEM:\"echo \\\$SOCAT_$SCM_ENVNAME\""
10164 CMD1
="$TRACE $SOCAT $opts -u - $KEYW-SENDTO:$tsa,$SCM_ENABLE"
10165 printf "test $F_n $TEST... " $N
10166 # is this option supported?
10167 if $SOCAT -hhh |
grep "[[:space:]]$SCM_RECV[[:space:]]" >/dev
/null
; then
10168 eval "$CMD0 >\"$tf\" 2>\"${te}0\" &"
10170 wait${proto}port
$tra 1
10171 echo "XYZ" |
$CMD1 2>"${te}1"
10174 #i=0; while [ ! -s "${te}0" -a "$i" -lt 10 ]; do usleep 100000; i=$((i+1)); done
10175 kill "$pid0" 2>/dev
/null
; wait
10176 # do not show more messages than requested
10177 if [ "$SCM_VALUE" = "timestamp" ]; then
10178 SCM_VALUE
="$(date '+%a %b %e %H:%M:.. %Y'), ...... usecs"
10180 if [ "$rc1" -ne 0 ]; then
10181 $PRINTF "$NO_RESULT: $SOCAT:\n"
10186 numCANT
=$
((numCANT
+1))
10187 #elif ! egrep "^export SOCAT_$SCM_ENVNAME=[\"']?$SCM_VALUE[\"']?\$" ${tf} >/dev/null; then
10188 #elif ! eval echo "$TRACE $SOCAT_\$SCM_VALUE" |diff - "${tf}" >/dev/null; then
10189 elif ! expr "$(cat "$tf")" : "$(eval echo "\
$SCM_VALUE")\$" >/dev
/null
; then
10190 $PRINTF "$FAILED\n"
10191 echo "logged value \"$(cat "$tf")\" instead of \"$(eval echo "\
$SCM_VALUE")\""
10196 numFAIL
=$
((numFAIL
+1))
10197 listFAIL
="$listFAIL $N"
10200 if [ -n "$debug" ]; then
10201 cat "${te}0"; echo; cat "${te}1";
10205 else # option is not supported
10206 $PRINTF "${YELLOW}$SCM_RECV not available${NORMAL}\n"
10207 numCANT
=$
((numCANT
+1))
10208 fi # option is not supported
10209 fi ;; # NUMCOND, feats
10214 IP4 UDP4 127.0.0.1 PORT ip-options=x01000000 ip-recvopts IP_OPTIONS user x01000000
10215 IP4 UDP4 127.0.0.1 PORT , so-timestamp TIMESTAMP user timestamp
10216 IP4 UDP4 127.0.0.1 PORT ip-ttl=53 ip-recvttl IP_TTL user 53
10217 IP4 UDP4 127.0.0.1 PORT ip-tos=7 ip-recvtos IP_TOS user 7
10218 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_LOCADDR user 127.0.0.1
10219 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_DSTADDR user 127.0.0.1
10220 IP4 UDP4 127.0.0.1 PORT , ip-pktinfo IP_IF user lo
10221 IP4 UDP4 127.0.0.1 PORT , ip-recvif IP_IF user lo0
10222 IP4 UDP4 127.0.0.1 PORT , ip-recvdstaddr IP_DSTADDR user 127.0.0.1
10223 IP4 IP4 127.0.0.1 PROTO ip-options=x01000000 ip-recvopts IP_OPTIONS root x01000000
10224 IP4 IP4 127.0.0.1 PROTO , so-timestamp TIMESTAMP root timestamp
10225 IP4 IP4 127.0.0.1 PROTO ip-ttl=53 ip-recvttl IP_TTL root 53
10226 IP4 IP4 127.0.0.1 PROTO ip-tos=7 ip-recvtos IP_TOS root 7
10227 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_LOCADDR root 127.0.0.1
10228 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_DSTADDR root 127.0.0.1
10229 IP4 IP4 127.0.0.1 PROTO , ip-pktinfo IP_IF root lo
10230 IP4 IP4 127.0.0.1 PROTO , ip-recvif IP_IF root lo0
10231 IP4 IP4 127.0.0.1 PROTO , ip-recvdstaddr IP_DSTADDR root 127.0.0.1
10232 IP6 UDP6 [::1] PORT , ipv6-recvpktinfo IPV6_DSTADDR user [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10233 IP6 UDP6 [::1] PORT ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT user 35
10234 IP6 UDP6 [::1] PORT ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS user x000000aa
10235 IP6 IP6 [::1] PROTO , ipv6-recvpktinfo IPV6_DSTADDR root [[]0000:0000:0000:0000:0000:0000:0000:0001[]]
10236 IP6 IP6 [::1] PROTO ipv6-unicast-hops=35 ipv6-recvhoplimit IPV6_HOPLIMIT root 35
10237 IP6 IP6 [::1] PROTO ipv6-tclass=0xaa ipv6-recvtclass IPV6_TCLASS root x000000aa
10238 #UNIX UNIX $td/test\$N.server - , so-timestamp TIMESTAMP user timestamp
10242 # test the SOCKET-CONNECT address (against TCP4-LISTEN)
10243 NAME
=SOCKET_CONNECT_TCP4
10245 *%$N%*|
*%functions
%*|
*%generic
%*|
*%socket
%*|
*%$NAME%*)
10246 TEST
="$NAME: socket connect with TCP/IPv4"
10247 # start a TCP4-LISTEN process that echoes data, and send test data using
10248 # SOCKET-CONNECT, selecting TCP/IPv4. The sent data should be returned.
10249 if ! eval $NUMCOND; then :; else
10250 tf
="$td/test$N.stdout"
10251 te
="$td/test$N.stderr"
10252 tdiff
="$td/test$N.diff"
10253 ts0p
=$PORT; PORT
=$
((PORT
+1))
10255 ts1p
=$
(printf "%04x" $ts0p);
10256 ts1a
="7f000001" # "127.0.0.1"
10257 ts1
="x${ts1p}${ts1a}x0000000000000000"
10258 ts1b
=$
(printf "%04x" $PORT); PORT
=$
((PORT
+1))
10259 da
="test$N $(date) $RANDOM"
10260 CMD0
="$TRACE $SOCAT $opts TCP4-LISTEN:$ts0p,$REUSEADDR,bind=$ts0a PIPE"
10261 CMD1
="$TRACE $SOCAT $opts - SOCKET-CONNECT:2:6:$ts1,bind=x${ts1b}00000000x0000000000000000"
10262 printf "test $F_n $TEST... " $N
10265 waittcp4port
$ts0p 1
10266 echo "$da" |
$CMD1 >>"$tf" 2>>"${te}1"
10268 kill "$pid0" 2>/dev
/null
; wait;
10269 if [ "$rc1" -ne 0 ]; then
10270 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10275 numFAIL
=$
((numFAIL
+1))
10276 listFAIL
="$listFAIL $N"
10277 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10278 $PRINTF "$FAILED\n"
10284 numFAIL
=$
((numFAIL
+1))
10285 listFAIL
="$listFAIL $N"
10288 if [ -n "$debug" ]; then cat $te; fi
10297 PF_INET6
="$($PROCAN -c |grep "^
#define[[:space:]]*PF_INET6[[:space:]]" |cut -d' ' -f3)"
10299 # test the SOCKET-CONNECT address (against TCP6-LISTEN)
10300 NAME
=SOCKET_CONNECT_TCP6
10302 *%$N%*|
*%functions
%*|
*%generic
%*|
*%tcp6
%*|
*%socket
%*|
*%$NAME%*)
10303 TEST
="$NAME: socket connect with TCP/IPv6"
10304 if ! eval $NUMCOND; then :;
10305 elif ! testaddrs tcp ip6
>/dev
/null ||
! runsip6
>/dev
/null
; then
10306 $PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
10307 numCANT
=$
((numCANT
+1))
10309 # start a TCP6-LISTEN process that echoes data, and send test data using
10310 # SOCKET-CONNECT, selecting TCP/IPv6. The sent data should be returned.
10311 tf
="$td/test$N.stdout"
10312 te
="$td/test$N.stderr"
10313 tdiff
="$td/test$N.diff"
10314 ts0p
=$PORT; PORT
=$
((PORT
+1))
10316 ts1p
=$
(printf "%04x" $ts0p);
10317 ts1a
="00000000000000000000000000000001" # "[::1]"
10318 ts1
="x${ts1p}x00000000x${ts1a}x00000000"
10319 ts1b
=$
(printf "%04x" $PORT); PORT
=$
((PORT
+1))
10320 da
="test$N $(date) $RANDOM"
10321 CMD0
="$TRACE $SOCAT $opts TCP6-LISTEN:$ts0p,$REUSEADDR,bind=$ts0a PIPE"
10322 CMD1
="$TRACE $SOCAT $opts - SOCKET-CONNECT:$PF_INET6:6:$ts1,bind=x${ts1b}x00000000x00000000000000000000000000000000x00000000"
10323 printf "test $F_n $TEST... " $N
10326 waittcp6port
$ts0p 1
10327 echo "$da" |
$CMD1 >>"$tf" 2>>"${te}1"
10329 kill "$pid0" 2>/dev
/null
; wait;
10330 if [ "$rc1" -ne 0 ]; then
10331 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10336 numFAIL
=$
((numFAIL
+1))
10337 listFAIL
="$listFAIL $N"
10338 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10339 $PRINTF "$FAILED\n"
10345 numFAIL
=$
((numFAIL
+1))
10346 listFAIL
="$listFAIL $N"
10349 if [ -n "$debug" ]; then cat $te; fi
10357 # test the SOCKET-CONNECT address (against UNIX-LISTEN)
10358 NAME
=SOCKET_CONNECT_UNIX
10360 *%$N%*|
*%functions
%*|
*%generic
%*|
*%unix
%*|
*%socket
%*|
*%$NAME%*)
10361 TEST
="$NAME: socket connect with UNIX domain"
10362 # start a UNIX-LISTEN process that echoes data, and send test data using
10363 # SOCKET-CONNECT, selecting UNIX socket. The sent data should be returned.
10364 if ! eval $NUMCOND; then :; else
10365 tf
="$td/test$N.stdout"
10366 te
="$td/test$N.stderr"
10367 tdiff
="$td/test$N.diff"
10368 ts0
="$td/test$N.server"
10369 ts1
="$td/test$N.client"
10370 da
="test$N $(date) $RANDOM"
10371 CMD0
="$TRACE $SOCAT $opts UNIX-LISTEN:$ts0,$REUSEADDR PIPE"
10372 CMD1
="$TRACE $SOCAT $opts - SOCKET-CONNECT:1:0:\\\"$ts0\\\0\\\",bind=\\\"$ts1\\\0\\\""
10373 printf "test $F_n $TEST... " $N
10377 echo "$da" |
$CMD1 >>"$tf" 2>>"${te}1"
10379 kill "$pid0" 2>/dev
/null
; wait;
10380 if [ "$rc1" -ne 0 ]; then
10381 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10386 numFAIL
=$
((numFAIL
+1))
10387 listFAIL
="$listFAIL $N"
10388 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10389 $PRINTF "$FAILED\n"
10395 numFAIL
=$
((numFAIL
+1))
10396 listFAIL
="$listFAIL $N"
10399 if [ -n "$debug" ]; then cat $te; fi
10406 # test the SOCKET-LISTEN address (with TCP4-CONNECT)
10409 *%$N%*|
*%functions
%*|
*%generic
%*|
*%socket
%*|
*%$NAME%*)
10410 TEST
="$NAME: socket recvfrom with TCP/IPv4"
10411 # start a SOCKET-LISTEN process that uses TCP/IPv4 and echoes data, and
10412 # send test data using TCP4-CONNECT. The sent data should be returned.
10413 if ! eval $NUMCOND; then :; else
10414 tf
="$td/test$N.stdout"
10415 te
="$td/test$N.stderr"
10416 tdiff
="$td/test$N.diff"
10417 ts1p
=$PORT; PORT
=$
((PORT
+1))
10419 ts0p
=$
(printf "%04x" $ts1p);
10420 ts0a
="7f000001" # "127.0.0.1"
10421 ts0
="x${ts0p}${ts0a}x0000000000000000"
10422 ts1b
=$PORT; PORT
=$
((PORT
+1))
10424 da
="test$N $(date) $RANDOM"
10425 CMD0
="$TRACE $SOCAT $opts SOCKET-LISTEN:2:6:$ts0,$REUSEADDR PIPE"
10426 CMD1
="$TRACE $SOCAT $opts - TCP4-CONNECT:$ts1,bind=:$ts1b"
10427 printf "test $F_n $TEST... " $N
10431 waittcp4port
$ts1p 1
10432 echo "$da" |
$CMD1 >>"$tf" 2>>"${te}1"
10434 kill "$pid0" 2>/dev
/null
; wait;
10435 if [ "$rc1" -ne 0 ]; then
10436 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10441 numFAIL
=$
((numFAIL
+1))
10442 listFAIL
="$listFAIL $N"
10443 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10444 $PRINTF "$FAILED\n"
10450 numFAIL
=$
((numFAIL
+1))
10451 listFAIL
="$listFAIL $N"
10454 if [ -n "$debug" ]; then cat $te; fi
10462 SOCK_DGRAM
="$($PROCAN -c |grep "^
#define[[:space:]]*SOCK_DGRAM[[:space:]]" |cut -d' ' -f3)"
10464 # test the SOCKET-SENDTO address (against UDP4-RECVFROM)
10467 *%$N%*|
*%functions
%*|
*%generic
%*|
*%socket
%*|
*%ip4
%*|
*%udp
%*|
*%dgram
%*|
*%$NAME%*)
10468 TEST
="$NAME: socket sendto with UDP/IPv4"
10469 # start a UDP4-RECVFROM process that echoes data, and send test data using
10470 # SOCKET-SENDTO, selecting UDP/IPv4. The sent data should be returned.
10471 if ! eval $NUMCOND; then :; else
10472 tf
="$td/test$N.stdout"
10473 te
="$td/test$N.stderr"
10474 tdiff
="$td/test$N.diff"
10475 ts0p
=$PORT; PORT
=$
((PORT
+1))
10477 ts1p
=$
(printf "%04x" $ts0p);
10478 ts1a
="7f000001" # "127.0.0.1"
10479 ts1
="x${ts1p}${ts1a}x0000000000000000"
10480 ts1b
=$
(printf "%04x" $PORT); PORT
=$
((PORT
+1))
10481 da
="test$N $(date) $RANDOM"
10482 CMD0
="$TRACE $SOCAT $opts UDP4-RECVFROM:$ts0p,reuseaddr,bind=$ts0a PIPE"
10483 CMD1
="$TRACE $SOCAT $opts - SOCKET-SENDTO:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10484 printf "test $F_n $TEST... " $N
10487 waitudp4port
$ts0p 1
10488 echo "$da" |
$CMD1 >>"$tf" 2>>"${te}1"
10490 kill "$pid0" 2>/dev
/null
; wait;
10491 if [ "$rc1" -ne 0 ]; then
10492 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10497 numFAIL
=$
((numFAIL
+1))
10498 listFAIL
="$listFAIL $N"
10499 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10500 $PRINTF "$FAILED\n"
10506 numFAIL
=$
((numFAIL
+1))
10507 listFAIL
="$listFAIL $N"
10510 if [ -n "$debug" ]; then cat $te; fi
10518 # test the SOCKET-RECVFROM address (with UDP4-SENDTO)
10519 NAME
=SOCKET_RECVFROM
10521 *%$N%*|
*%functions
%*|
*%generic
%*|
*%socket
%*|
*%ip4
%*|
*%udp
%*|
*%dgram
%*|
*%$NAME%*)
10522 TEST
="$NAME: socket recvfrom with UDP/IPv4"
10523 # start a SOCKET-RECVFROM process that uses UDP/IPv4 and echoes data, and
10524 # send test data using UDP4-SENDTO. The sent data should be returned.
10525 if ! eval $NUMCOND; then :; else
10526 tf
="$td/test$N.stdout"
10527 te
="$td/test$N.stderr"
10528 tdiff
="$td/test$N.diff"
10529 ts1p
=$PORT; PORT
=$
((PORT
+1))
10531 ts0p
=$
(printf "%04x" $ts1p);
10532 ts0a
="7f000001" # "127.0.0.1"
10533 ts0
="x${ts0p}${ts0a}x0000000000000000"
10534 ts1b
=$PORT; PORT
=$
((PORT
+1))
10536 da
="test$N $(date) $RANDOM"
10537 CMD0
="$TRACE $SOCAT $opts SOCKET-RECVFROM:2:$SOCK_DGRAM:17:$ts0,reuseaddr PIPE"
10538 CMD1
="$TRACE $SOCAT $opts - UDP4-SENDTO:$ts1,bind=:$ts1b"
10539 printf "test $F_n $TEST... " $N
10542 sleep 1 # waitudp4port $ts1p 1
10543 echo "$da" |
$CMD1 >>"$tf" 2>>"${te}1"
10545 kill "$pid0" 2>/dev
/null
; wait;
10546 if [ "$rc1" -ne 0 ]; then
10547 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10552 numFAIL
=$
((numFAIL
+1))
10553 listFAIL
="$listFAIL $N"
10554 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10555 $PRINTF "$FAILED\n"
10561 numFAIL
=$
((numFAIL
+1))
10562 listFAIL
="$listFAIL $N"
10565 if [ -n "$debug" ]; then cat $te; fi
10574 # test the SOCKET-RECV address (with UDP4-SENDTO)
10577 *%$N%*|
*%functions
%*|
*%generic
%*|
*%socket
%*|
*%ip4
%*|
*%udp
%*|
*%dgram
%*|
*%$NAME%*)
10578 TEST
="$NAME: socket recv with UDP/IPv4"
10579 # start a SOCKET-RECV process that uses UPD/IPv4 and writes received data to file, and
10580 # send test data using UDP4-SENDTO.
10581 if ! eval $NUMCOND; then :; else
10582 tf
="$td/test$N.stdout"
10583 te
="$td/test$N.stderr"
10584 tdiff
="$td/test$N.diff"
10585 ts1p
=$PORT; PORT
=$
((PORT
+1))
10587 ts0p
=$
(printf "%04x" $ts1p);
10588 ts0a
="7f000001" # "127.0.0.1"
10589 ts0
="x${ts0p}${ts0a}x0000000000000000"
10590 ts1b
=$PORT; PORT
=$
((PORT
+1))
10592 da
="test$N $(date) $RANDOM"
10593 CMD0
="$TRACE $SOCAT $opts -u SOCKET-RECV:2:$SOCK_DGRAM:17:$ts0,reuseaddr -"
10594 CMD1
="$TRACE $SOCAT $opts -u - UDP4-SENDTO:$ts1,bind=:$ts1b"
10595 printf "test $F_n $TEST... " $N
10596 $CMD0 2>"${te}0" >"$tf" &
10598 sleep 1 # waitudp4port $ts1p 1
10599 echo "$da" |
$CMD1 2>>"${te}1"
10602 kill "$pid0" 2>/dev
/null
; wait;
10603 if [ "$rc1" -ne 0 ]; then
10604 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10609 numFAIL
=$
((numFAIL
+1))
10610 listFAIL
="$listFAIL $N"
10611 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10612 $PRINTF "$FAILED\n"
10618 numFAIL
=$
((numFAIL
+1))
10619 listFAIL
="$listFAIL $N"
10622 if [ -n "$debug" ]; then cat $te; fi
10630 # test SOCKET-DATAGRAM (with UDP4-DATAGRAM)
10631 NAME
=SOCKET_DATAGRAM
10633 *%$N%*|
*%functions
%*|
*%generic
%*|
*%socket
%*|
*%ip4
%*|
*%udp
%*|
*%dgram
%*|
*%$NAME%*)
10634 TEST
="$NAME: socket datagram via UDP/IPv4"
10635 # start a UDP4-DATAGRAM process that echoes data, and send test data using
10636 # SOCKET-DATAGRAM, selecting UDP/IPv4. The sent data should be returned.
10637 if ! eval $NUMCOND; then :; else
10638 tf
="$td/test$N.stdout"
10639 te
="$td/test$N.stderr"
10640 tdiff
="$td/test$N.diff"
10641 ts0p
=$PORT; PORT
=$
((PORT
+1))
10642 ts1p
=$PORT; PORT
=$
((PORT
+1))
10644 ts1b
=$
(printf "%04x" $ts0p);
10645 ts1a
="7f000001" # "127.0.0.1"
10646 ts0b
=$
(printf "%04x" $ts0p)
10647 ts1b
=$
(printf "%04x" $ts1p)
10648 ts1
="x${ts0b}${ts1a}x0000000000000000"
10649 da
="test$N $(date) $RANDOM"
10650 CMD0
="$TRACE $SOCAT $opts UDP4-DATAGRAM:$ts0a:$ts1p,bind=:$ts0p,reuseaddr PIPE"
10651 CMD1
="$TRACE $SOCAT $opts - SOCKET-DATAGRAM:2:$SOCK_DGRAM:17:$ts1,bind=x${ts1b}x00000000x0000000000000000"
10652 printf "test $F_n $TEST... " $N
10655 waitudp4port
$ts0p 1
10656 echo "$da" |
$CMD1 2>>"${te}1" >"$tf"
10658 kill "$pid0" 2>/dev
/null
; wait;
10659 if [ "$rc1" -ne 0 ]; then
10660 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10665 numFAIL
=$
((numFAIL
+1))
10666 listFAIL
="$listFAIL $N"
10667 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10668 $PRINTF "$FAILED\n"
10674 numFAIL
=$
((numFAIL
+1))
10675 listFAIL
="$listFAIL $N"
10678 if [ -n "$debug" ]; then cat $te; fi
10686 NAME
=SOCKETRANGEMASK
10688 *%$N%*|
*%functions
%*|
*%security
%*|
*%generic
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%socket
%*|
*%range
%*|
*%$NAME%*)
10689 TEST
="$NAME: security of generic socket-listen with RANGE option"
10690 if ! eval $NUMCOND; then :;
10691 elif [ -z "$SECONDADDR" ]; then
10692 # we need access to more loopback addresses
10693 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
10694 numCANT
=$
((numCANT
+1))
10696 ts1p
=$
(printf "%04x" $PORT);
10697 testserversec
"$N" "$TEST" "$opts" "SOCKET-LISTEN:2:6:x${ts1p}x00000000x0000000000000000,$REUSEADDR,fork,retry=1" "" "range=x0000x7f000000:x0000xffffffff" "SOCKET-CONNECT:2:6:x${ts1p}x${SECONDADDRHEX}x0000000000000000" 4 tcp
$PORT 0
10698 fi ;; # NUMCOND, $SECONDADDR
10704 TIOCEXCL
="$($PROCAN -c |grep "^
#define[[:space:]]*TIOCEXCL[[:space:]]" |cut -d' ' -f3)"
10706 # test the generic ioctl-void option
10709 *%$N%*|
*%functions
%*|
*%pty
%*|
*%generic
%*|
*%$NAME%*)
10710 TEST
="$NAME: test the ioctl-void option"
10711 # there are not many ioctls that apply to non global resources and do not
10712 # require root. TIOCEXCL seems to fit:
10713 # process 0 provides a pty;
10714 # process 1 opens it with the TIOCEXCL ioctl;
10715 # process 2 opens it too and fails with "device or resource busy" only when the
10716 # previous ioctl was successful
10717 if ! eval $NUMCOND; then :;
10718 elif [ -z "$TIOCEXCL" ]; then
10719 # we use the numeric value of TIOCEXL which is system dependent
10720 $PRINTF "test $F_n $TEST... ${YELLOW}no value of TIOCEXCL${NORMAL}\n" $N
10721 numCANT
=$
((numCANT
+1))
10723 tp
="$td/test$N.pty"
10724 tf
="$td/test$N.stdout"
10725 te
="$td/test$N.stderr"
10726 tdiff
="$td/test$N.diff"
10727 da
="test$N $(date) $RANDOM"
10728 CMD0
="$TRACE $SOCAT $opts PTY,LINK=$tp pipe"
10729 CMD1
="$TRACE $SOCAT $opts - file:$tp,ioctl-void=$TIOCEXCL,raw,echo=0"
10730 CMD2
="$TRACE $SOCAT $opts - file:$tp,raw,echo=0"
10731 printf "test $F_n $TEST... " $N
10732 $CMD0 >/dev
/null
2>"${te}0" &
10735 (echo "$da"; sleep 2) |
$CMD1 >"$tf" 2>"${te}1" & # this should always work
10738 $CMD2 >/dev
/null
2>"${te}2" </dev
/null
10740 kill $pid0 $pid1 2>/dev
/null
; wait
10741 if ! echo "$da" |
diff - "$tf" >/dev
/null
; then
10742 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
10745 echo "$da" |
diff - "$tf"
10746 numCANT
=$
((numCANT
+1))
10747 elif [ $rc2 -eq 0 ]; then
10748 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10752 cat "${te}0" "${te}1" "${te}2"
10753 numFAIL
=$
((numFAIL
+1))
10754 listFAIL
="$listFAIL $N"
10757 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
10760 fi # NUMCOND, TIOCEXCL
10766 SOL_SOCKET
="$($PROCAN -c |grep "^
#define[[:space:]]*SOL_SOCKET[[:space:]]" |cut -d' ' -f3)"
10767 SO_REUSEADDR
="$($PROCAN -c |grep "^
#define[[:space:]]*SO_REUSEADDR[[:space:]]" |cut -d' ' -f3)"
10769 # test the generic setsockopt-int option
10771 # this test no longer works due to fix for options on listening sockets
10772 NAME
=SETSOCKOPT_INT
10774 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%tcp
%*|
*%generic
%*|
*%$NAME%*)
10775 TEST
="$NAME: test the setsockopt-int option"
10776 # there are not many socket options that apply to non global resources, do not
10777 # require root, do not require a network connection, and can easily be
10778 # tested. SO_REUSEADDR seems to fit:
10779 # process 0 provides a tcp listening socket with reuseaddr;
10780 # process 1 connects to this port; thus the port is connected but no longer
10782 # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
10783 # (generically specified) SO_REUSEADDR socket options did not work
10784 # process 3 connects to this port; only if it is successful the test is ok
10785 if ! eval $NUMCOND; then :;
10786 elif [ -z "$SO_REUSEADDR" ]; then
10787 # we use the numeric value of SO_REUSEADDR which might be system dependent
10788 $PRINTF "test $F_n $TEST... ${YELLOW}value of SO_REUSEADDR not known${NORMAL}\n" $N
10789 numCANT
=$
((numCANT
+1))
10792 tf
="$td/test$N.stdout"
10793 te
="$td/test$N.stderr"
10794 tdiff
="$td/test$N.diff"
10795 da
="test$N $(date) $RANDOM"
10796 CMD0
="$TRACE $SOCAT $opts TCP4-L:$tp,setsockopt-int=$SOL_SOCKET:$SO_REUSEADDR:1 PIPE"
10797 CMD1
="$TRACE $SOCAT $opts - TCP:localhost:$tp"
10800 printf "test $F_n $TEST... " $N
10801 $CMD0 >/dev
/null
2>"${te}0" &
10804 (echo "$da"; sleep 3) |
$CMD1 >"$tf" 2>"${te}1" & # this should always work
10807 $CMD2 >/dev
/null
2>"${te}2" &
10810 (echo "$da") |
$CMD3 >"${tf}3" 2>"${te}3"
10812 kill $pid0 $pid1 $pid2 2>/dev
/null
; wait
10813 if ! echo "$da" |
diff - "$tf"; then
10814 $PRINTF "${YELLOW}phase 1 failed${NORMAL}\n"
10817 numCANT
=$
((numCANT
+1))
10818 elif [ $rc3 -ne 0 ]; then
10819 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10824 cat "${te}2" "${te}3"
10825 numFAIL
=$
((numFAIL
+1))
10826 listFAIL
="$listFAIL $N"
10827 elif ! echo "$da" |
diff - "${tf}3"; then
10828 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10833 echo "$da" |
diff - "${tf}3"
10834 numCANT
=$
((numCANT
+1))
10837 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
10840 fi # NUMCOND, SO_REUSEADDR
10851 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%sctp
%*|
*%$NAME%*)
10852 TEST
="$NAME: echo via connection to SCTP V4 socket"
10854 if ! eval $NUMCOND; then :;
10855 elif ! testaddrs sctp ip4
>/dev
/null ||
! runsip4
>/dev
/null ||
! runssctp4
"$((PORT-1))" >/dev
/null
; then
10856 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP4 not available${NORMAL}\n" $N
10857 numCANT
=$
((numCANT
+1))
10858 elif [ "$UNAME" = Linux
] && ! grep ^sctp
/proc
/modules
>/dev
/null
; then
10859 # RHEL5 based systems became unusable when an sctp socket was created but
10860 # module sctp not loaded
10861 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
10862 numCANT
=$
((numCANT
+1))
10864 tf
="$td/test$N.stdout"
10865 te
="$td/test$N.stderr"
10866 tdiff
="$td/test$N.diff"
10868 ts
="127.0.0.1:$tsl"
10870 CMD1
="$TRACE $SOCAT $opts SCTP4-LISTEN:$tsl,$REUSEADDR PIPE"
10871 CMD2
="$TRACE $SOCAT $opts stdin!!stdout SCTP4:$ts"
10872 printf "test $F_n $TEST... " $N
10873 $CMD1 >"$tf" 2>"${te}1" &
10875 waitsctp4port
$tsl 1
10876 # SCTP does not seem to support half close, so we give it 1s to finish
10877 (echo "$da"; sleep 1) |
$CMD2 >>"$tf" 2>>"${te}2"
10878 if [ $?
-ne 0 ]; then
10879 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10884 numFAIL
=$
((numFAIL
+1))
10885 listFAIL
="$listFAIL $N"
10886 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10887 $PRINTF "$FAILED\n"
10889 numFAIL
=$
((numFAIL
+1))
10890 listFAIL
="$listFAIL $N"
10893 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
10896 kill $pid1 2>/dev
/null
10898 fi # NUMCOND, feats
10906 *%$N%*|
*%functions
%*|
*%ip6
%*|
*%ipapp
%*|
*%sctp
%*|
*%$NAME%*)
10907 TEST
="$NAME: echo via connection to SCTP V6 socket"
10909 if ! eval $NUMCOND; then :;
10910 elif ! testaddrs sctp ip6
>/dev
/null ||
! runsip6
>/dev
/null ||
! runssctp6
"$((PORT-1))" >/dev
/null
; then
10911 $PRINTF "test $F_n $TEST... ${YELLOW}SCTP6 not available${NORMAL}\n" $N
10912 numCANT
=$
((numCANT
+1))
10913 elif [ "$UNAME" = Linux
] && ! grep ^sctp
/proc
/modules
>/dev
/null
; then
10914 $PRINTF "test $F_n $TEST...${YELLOW}load sctp module!${NORMAL}\n" $N
10915 numCANT
=$
((numCANT
+1))
10917 tf
="$td/test$N.stdout"
10918 te
="$td/test$N.stderr"
10919 tdiff
="$td/test$N.diff"
10923 CMD1
="$TRACE $SOCAT $opts SCTP6-listen:$tsl,$REUSEADDR PIPE"
10924 CMD2
="$TRACE $SOCAT $opts stdin!!stdout SCTP6:$ts"
10925 printf "test $F_n $TEST... " $N
10926 $CMD1 >"$tf" 2>"${te}1" &
10927 pid
=$
! # background process id
10928 waitsctp6port
$tsl 1
10929 # SCTP does not seem to support half close, so we let it 1s to finish
10930 (echo "$da"; sleep 1) |
$CMD2 >>"$tf" 2>>"${te}2"
10931 if [ $?
-ne 0 ]; then
10932 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
10937 numFAIL
=$
((numFAIL
+1))
10938 listFAIL
="$listFAIL $N"
10939 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
10940 $PRINTF "$FAILED: diff:\n"
10942 numFAIL
=$
((numFAIL
+1))
10943 listFAIL
="$listFAIL $N"
10946 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
10949 kill $pid 2>/dev
/null
10950 fi # NUMCOND, feats
10957 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
10958 # performed a renegotiation. Test if this is fixed.
10961 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%openssl
%*|
*%socket
%*|
*%$NAME%*)
10962 TEST
="$NAME: OpenSSL connections survive renogotiation"
10963 # connect with s_client to socat ssl-l; force a renog, then transfer data. When
10964 # data is passed the test succeeded
10965 if ! eval $NUMCOND; then :;
10966 elif ! testaddrs openssl
>/dev
/null
; then
10967 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
10968 numCANT
=$
((numCANT
+1))
10969 elif ! type openssl
>/dev
/null
2>&1; then
10970 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
10971 numCANT
=$
((numCANT
+1))
10972 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
10973 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
10974 numCANT
=$
((numCANT
+1))
10976 gentestcert testsrv
10977 tf
="$td/test$N.stdout"
10978 te
="$td/test$N.stderr"
10979 tdiff
="$td/test$N.diff"
10980 da
="test$N $(date) $RANDOM"
10981 CMD0
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
10982 #CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
10983 CMD1
="openssl s_client -port $PORT"
10984 printf "test $F_n $TEST... " $N
10985 $CMD0 >/dev
/null
2>"${te}0" &
10987 waittcp4port
$PORT 1
10988 (echo "R"; sleep 1; echo "$da"; sleep 1) |
$CMD1 2>"${te}1" |fgrep
"$da" >"${tf}1"
10990 kill $pid0 2>/dev
/null
; wait
10991 if echo "$da" |
diff - ${tf}1 >"$tdiff"; then
10995 $PRINTF "$FAILED\n"
11001 numFAIL
=$
((numFAIL
+1))
11002 listFAIL
="$listFAIL $N"
11011 # socat up to 1.7.1.1 (and 2.0.0-b3) terminated with error when an openssl peer
11012 # performed a renegotiation. The first temporary fix to this problem might
11013 # leave socat in a blocking ssl-read state. Test if this has been fixed.
11016 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%openssl
%*|
*%socket
%*|
*%$NAME%*)
11017 TEST
="$NAME: OpenSSL connections do not block after renogotiation"
11018 # connect with s_client to socat ssl-l; force a renog, then transfer data from
11019 # socat to the peer. When data is passed this means that the former ssl read no
11020 # longer blocks and the test succeeds
11021 if ! eval $NUMCOND; then :;
11022 elif ! testaddrs openssl
>/dev
/null
; then
11023 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11024 numCANT
=$
((numCANT
+1))
11025 elif ! type openssl
>/dev
/null
2>&1; then
11026 $PRINTF "test $F_n $TEST... ${YELLOW}openssl executable not available${NORMAL}\n" $N
11027 numCANT
=$
((numCANT
+1))
11028 elif ! testaddrs tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
11029 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11030 numCANT
=$
((numCANT
+1))
11032 gentestcert testsrv
11033 tf
="$td/test$N.stdout"
11034 te
="$td/test$N.stderr"
11035 tdiff
="$td/test$N.diff"
11036 da
="test$N $(date) $RANDOM"
11037 CMD0
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 SYSTEM:\"sleep 1; echo \\\\\\\"\\\"$da\\\"\\\\\\\"; sleep 1\"!!STDIO"
11038 #CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
11039 CMD1
="openssl s_client -port $PORT"
11040 printf "test $F_n $TEST... " $N
11041 eval "$CMD0 >/dev/null 2>\"${te}0\" &"
11043 waittcp4port
$PORT 1
11044 (echo "R"; sleep 2) |
$CMD1 2>"${te}1" |fgrep
"$da" >"${tf}1"
11046 kill $pid0 2>/dev
/null
; wait
11047 if echo "$da" |
diff - ${tf}1 >"$tdiff"; then
11051 $PRINTF "$FAILED\n"
11057 numFAIL
=$
((numFAIL
+1))
11058 listFAIL
="$listFAIL $N"
11067 # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
11068 # command line arguments (whole addresses, host names, file names) were longer
11072 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%security
%*|
*%socket
%*|
*%$NAME%*)
11073 TEST
="$NAME: stack overflow on overly long host name"
11074 # provide a long host name to TCP-CONNECT and check socats exit code
11075 if ! eval $NUMCOND; then :; else
11076 tf
="$td/test$N.stdout"
11077 te
="$td/test$N.stderr"
11078 tdiff
="$td/test$N.diff"
11079 da
="test$N $(date) $RANDOM"
11080 # prepare long data - perl might not be installed
11081 rm -f "$td/test$N.dat"
11082 i
=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i
=$
((i
+1)); done
11083 CMD0
="$TRACE $SOCAT $opts TCP-CONNECT:$(cat "$td/test$N.dat
"):$PORT STDIO"
11084 printf "test $F_n $TEST... " $N
11085 $CMD0 </dev
/null
1>&0 2>"${te}0"
11087 if [ $rc0 -lt 128 ] ||
[ $rc0 -eq 255 ]; then
11091 $PRINTF "$FAILED\n"
11094 numFAIL
=$
((numFAIL
+1))
11095 listFAIL
="$listFAIL $N"
11103 # socat up to 1.7.1.2 had a stack overflow vulnerability that occurred when
11104 # command line arguments (whole addresses, host names, file names) were longer
11108 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%security
%*|
*%openssl
%*|
*%$NAME%*)
11109 TEST
="$NAME: stack overflow on overly long file name"
11110 # provide a 600 bytes long key file option to OPENSSL-CONNECT and check socats exit code
11111 if ! eval $NUMCOND; then :; else
11112 tf
="$td/test$N.stdout"
11113 te
="$td/test$N.stderr"
11114 tdiff
="$td/test$N.diff"
11115 da
="test$N $(date) $RANDOM"
11116 i
=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i
=$
((i
+1)); done
11117 CMD0
="$TRACE $SOCAT $opts OPENSSL:localhost:$PORT,key=$(cat "$td/test$N.dat
") STDIO"
11118 printf "test $F_n $TEST... " $N
11119 $CMD0 </dev
/null
1>&0 2>"${te}0"
11121 if [ $rc0 -lt 128 ] ||
[ $rc0 -eq 255 ]; then
11125 $PRINTF "$FAILED\n"
11128 numFAIL
=$
((numFAIL
+1))
11129 listFAIL
="$listFAIL $N"
11137 # socat up to 1.7.3.0 had a stack overflow vulnerability that occurred when
11138 # command line arguments (whole addresses, host names, file names) were longer
11139 # than 512 bytes and specially crafted.
11142 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%security
%*|
*%exec%*|
*%$NAME%*)
11143 TEST
="$NAME: stack overflow on overly long nested arg"
11144 # provide a long host name to TCP-CONNECT and check socats exit code
11145 if ! eval $NUMCOND; then :; else
11146 tf
="$td/test$N.stdout"
11147 te
="$td/test$N.stderr"
11148 tdiff
="$td/test$N.diff"
11149 da
="test$N $(date) $RANDOM"
11150 # prepare long data - perl might not be installed
11151 rm -f "$td/test$N.dat"
11152 i
=0; while [ $i -lt 64 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$td/test$N.dat"; i
=$
((i
+1)); done
11153 CMD0
="$TRACE $SOCAT $opts EXEC:[$(cat "$td/test$N.dat
")] STDIO"
11154 printf "test $F_n $TEST... " $N
11155 $CMD0 </dev
/null
1>&0 2>"${te}0"
11157 if [ $rc0 -lt 128 ] ||
[ $rc0 -eq 255 ]; then
11161 $PRINTF "$FAILED\n"
11164 numFAIL
=$
((numFAIL
+1))
11165 listFAIL
="$listFAIL $N"
11174 # test for a bug in gopen that lead to crash or warning when opening a unix
11175 # domain socket with GOPEN
11176 NAME
=GOPEN_UNIX_CRASH
11178 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%gopen
%*|
*%unix
%*|
*%socket
%*|
*%$NAME%*)
11179 TEST
="$NAME: check crash when connecting to a unix domain socket using address GOPEN"
11180 # a unix domain server is started in background. the check process connects to
11181 # its socket. when this process crashes or issues a warning the bug is present.
11182 # please note that a clean behaviour does not proof anything; behaviour of bug
11183 # depends on the value of an uninitialized var
11185 if ! eval $NUMCOND; then :; else
11186 tf
="$td/test$N.stdout"
11187 te
="$td/test$N.stderr"
11188 ts
="$td/test$N.sock"
11189 tdiff
="$td/test$N.diff"
11190 da
="test$N $(date) $RANDOM"
11191 CMD0
="$TRACE $SOCAT $opts UNIX-LISTEN:$ts PIPE"
11192 CMD1
="$TRACE $SOCAT $opts -d - GOPEN:$ts"
11193 printf "test $F_n $TEST... " $N
11194 $CMD0 >/dev
/null
2>"${te}0" </dev
/null
&
11196 waitunixport
"$ts" 1
11197 echo "$da" |
$CMD1 >"${tf}1" 2>"${te}1"
11199 kill $pid0 2>/dev
/null
; wait
11200 if [ $rc1 -ne 0 ]; then
11201 $PRINTF "$FAILED\n"
11206 numFAIL
=$
((numFAIL
+1))
11207 listFAIL
="$listFAIL $N"
11208 elif grep -q ' W ' "${te}1"; then
11209 $PRINTF "$FAILED\n"
11214 numFAIL
=$
((numFAIL
+1))
11215 listFAIL
="$listFAIL $N"
11216 elif ! echo "$da" |
diff - ${tf}1 >"$tdiff"; then
11217 $PRINTF "$FAILED\n"
11223 numFAIL
=$
((numFAIL
+1))
11224 listFAIL
="$listFAIL $N"
11235 # test if socat keeps an existing file where it wanted to create a UNIX socket
11236 NAME
=UNIXLISTEN_KEEPFILE
11238 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%unix
%*|
*%socket
%*|
*%$NAME%*)
11239 TEST
="$NAME: socat keeps an existing file where it wanted to create a UNIX socket"
11240 # we create a file and start socat with UNIX-LISTEN on this file. expected
11241 # behaviour: socat exits immediately with error, but keeps the file
11242 # up to 1.7.1.3, it removed the file
11243 if ! eval $NUMCOND; then :; else
11244 tf
="$td/test$N.file"
11245 te
="$td/test$N.stderr"
11246 CMD0
="$TRACE $SOCAT $opts -u UNIX-LISTEN:$tf /dev/null"
11247 printf "test $F_n $TEST... " $N
11248 rm -f "$tf"; touch "$tf"
11249 $CMD0 >/dev
/null
2>"${te}0"
11251 if [ $rc0 -ne 0 -a -f "$tf" ]; then
11255 $PRINTF "$FAILED\n"
11258 numFAIL
=$
((numFAIL
+1))
11259 listFAIL
="$listFAIL $N"
11267 # PTY address allowed to sepcify address parameters but ignored them
11270 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%pty
%*|
*%$NAME%*)
11271 TEST
="$NAME: check if address params of PTY produce error"
11272 # invoke socat with address PTY and some param; expect an error
11273 if ! eval $NUMCOND; then :; else
11274 tf
="$td/test$N.stdout"
11275 te
="$td/test$N.stderr"
11276 tdiff
="$td/test$N.diff"
11277 da
="test$N $(date) $RANDOM"
11278 CMD0
="$TRACE $SOCAT $opts /dev/null PTY:/tmp/xyz"
11279 printf "test $F_n $TEST... " $N
11280 $CMD0 >/dev
/null
2>"${te}0"
11282 if [ $rc0 -ne 0 ]; then
11286 $PRINTF "$FAILED\n"
11289 numFAIL
=$
((numFAIL
+1))
11290 listFAIL
="$listFAIL $N"
11298 # incomplete writes were reported but led to data loss
11299 NAME
=INCOMPLETE_WRITE
11301 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%$NAME%*)
11302 TEST
="$NAME: check if incomplete writes are handled properly"
11303 # write to a nonblocking fd a block that is too large for atomic write
11304 # and check if all data arrives
11305 if ! eval $NUMCOND; then :; else
11306 tf
="$td/test$N.stdout"
11307 te
="$td/test$N.stderr"
11308 tp
="$td/test$N.pipe"
11309 tw
="$td/test$N.wc-c"
11310 # this is the size we write() in one call; data is never stored on disk, so
11311 # make it large enough to exceed any atomic write size; but higher number might
11313 bytes
=100000 # for Linux 2.6.? this must be >65536
11314 CMD0
="$TRACE $SOCAT $opts -u PIPE:$tp STDOUT"
11315 CMD1
="$TRACE $SOCAT $opts -u -b $bytes OPEN:/dev/zero,readbytes=$bytes FILE:$tp,o-nonblock"
11316 printf "test $F_n $TEST... " $N
11317 $CMD0 2>"${te}0" |
wc -c >"$tw" &
11320 $CMD1 2>"${te}1" >"${tf}1"
11323 if [ $rc1 -ne 0 ]; then
11324 $PRINTF "$NO_RESULT\n"
11325 numCANT
=$
((numCANT
+1))
11326 elif [ ! -e "$tw" ]; then
11327 $PRINTF "$NO_RESULT\n"
11328 numCANT
=$
((numCANT
+1))
11329 elif [ "$bytes" -eq $
(cat "$tw") ]; then
11333 $PRINTF "$FAILED\n"
11334 echo "transferred only $(cat $tw) of $bytes bytes" >&2
11335 numFAIL
=$
((numFAIL
+1))
11336 listFAIL
="$listFAIL $N"
11346 *%$N%*|
*%functions
%*|
*%openssl
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%$NAME%*)
11347 TEST
="$NAME: OpenSSL server with cipher aNULL "
11348 if ! eval $NUMCOND; then :;
11349 elif ! testaddrs openssl
>/dev
/null
; then
11350 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11351 numCANT
=$
((numCANT
+1))
11352 elif ! testaddrs listen tcp ip4
>/dev
/null ||
! runsip4
>/dev
/null
; then
11353 $PRINTF "test $F_n $TEST... ${YELLOW}TCP/IPv4 not available${NORMAL}\n" $N
11354 numCANT
=$
((numCANT
+1))
11356 tf
="$td/test$N.stdout"
11357 te
="$td/test$N.stderr"
11358 tdiff
="$td/test$N.diff"
11359 da
="test$N $(date) $RANDOM"
11360 CMD2
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,$SOCAT_EGD,ciphers=aNULL,verify=0 pipe"
11361 CMD
="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,ciphers=aNULL,verify=0,$SOCAT_EGD"
11362 printf "test $F_n $TEST... " $N
11363 eval "$CMD2 2>\"${te}1\" &"
11364 pid
=$
! # background process id
11366 echo "$da" |
$CMD >$tf 2>"${te}2"
11367 if ! echo "$da" |
diff - "$tf" >"$tdiff"; then
11368 $PRINTF "${YELLOW}FAILED${NORMAL}\n"
11377 if [ -n "$debug" ]; then cat "${te}1" "${te}2"; fi
11380 kill $pid 2>/dev
/null
11382 fi ;; # NUMCOND, feats
11388 while read KEYW FEAT ADDR IPPORT
; do
11389 if [ -z "$KEYW" ]||
[[ "$KEYW" == \
#* ]]; then continue; fi
11391 proto
="$(echo "$PROTO" |tr A-Z a-z)"
11392 # test the max-children option on really connection oriented sockets
11393 NAME
=${KEYW}MAXCHILDREN
11395 *%$N%*|
*%functions
%*|
*%maxchildren
%*|
*%socket
%*|
*%$NAME%*)
11396 TEST
="$NAME: max-children option"
11397 # start a listen process with max-children=1; connect with a client, let it
11398 # sleep some time before sending data; connect with second client that sends
11399 # data immediately. If max-children is working correctly the first data should
11400 # arrive first because the second process has to wait.
11401 if ! eval $NUMCOND; then :; else
11404 tsl
=$PORT # test socket listen address
11405 tsc
="$ADDR:$PORT" # test socket connect address
11406 PORT
=$
((PORT
+1)) ;;
11408 tsl
="$(eval echo "$ADDR")" # resolve $N
11411 #ts="$td/test$N.sock"
11412 tf
="$td/test$N.stdout"
11413 te
="$td/test$N.stderr"
11414 tdiff
="$td/test$N.diff"
11415 da
="test$N $(date) $RANDOM"
11416 CMD0
="$TRACE $SOCAT $opts -U FILE:$tf,o-trunc,o-creat,o-append $PROTO-LISTEN:$tsl,$REUSEADDR,fork,max-children=1"
11417 CMD1
="$TRACE $SOCAT $opts -u - $PROTO-CONNECT:$tsc,shut-null"
11418 printf "test $F_n $TEST... " $N
11419 $CMD0 >/dev
/null
2>"${te}0" &
11421 wait${proto}port
$tsl 1
11422 (echo "$da 1"; sleep 2) |
$CMD1 >"${tf}1" 2>"${te}1" &
11425 echo "$da 2" |
$CMD1 >"${tf}2" 2>"${te}2" &
11428 kill $pid1 $pid2 $pid0 2>/dev
/null
; wait
11429 if echo -e "$da 1\n$da 2" |
diff - $tf >$tdiff; then
11433 $PRINTF "$FAILED\n"
11435 echo "(echo \"$da 1\"; sleep 2) |$CMD1"
11436 echo "echo \"$da 2\" |$CMD1"
11441 numFAIL
=$
((numFAIL
+1))
11442 listFAIL
="$listFAIL $N"
11449 TCP4 TCP 127.0.0.1 PORT
11450 TCP6 TCP [::1] PORT
11451 SCTP4 TCP 127.0.0.1 PORT
11452 SCTP6 TCP [::1] PORT
11453 UNIX UNIX $td/test\$N.server -
11455 # debugging this hanging test was difficult - following lessons learned:
11456 # kill <parent> had no effect when child process existed
11457 # strace -f (on Fedora-23) sometimes writes/pads? blocks with \0, overwriting client traces
11458 # using the TRACE feature lets above kill command kill strace, not socat
11459 # care for timing, understand what you want :-)
11462 while read KEYW FEAT ADDR IPPORT SHUT
; do
11463 if [ -z "$KEYW" ]||
[[ "$KEYW" == \
#* ]]; then continue; fi
11465 proto
="$(echo "$PROTO" |tr A-Z a-z)"
11466 # test the max-children option on pseudo connected sockets
11467 NAME
=${KEYW}MAXCHILDREN
11469 *%$N%*|
*%functions
%*|
*%maxchildren
%*|
*%socket
%*|
*%$NAME%*)
11470 TEST
="$NAME: max-children option"
11471 # start a listen process with max-children=1; connect with a client, let it
11472 # send data and then sleep; connect with second client that wants to send
11473 # data immediately, but keep first client active until server terminates.
11474 #If max-children is working correctly only the first data should
11476 if ! eval $NUMCOND; then :; else
11479 tsl
=$PORT # test socket listen address
11480 tsc
="$ADDR:$PORT" # test socket connect address
11481 PORT
=$
((PORT
+1)) ;;
11483 tsl
="$(eval echo "$ADDR")" # resolve $N
11486 #ts="$td/test$N.sock"
11487 tf
="$td/test$N.stdout"
11488 te
="$td/test$N.stderr"
11489 tdiff
="$td/test$N.diff"
11490 da
="test$N $(date) $RANDOM"
11491 # on some Linux distributions it hangs, thus -T option here
11492 CMD0
="$TRACE $SOCAT $opts -U -T 4 FILE:$tf,o-trunc,o-creat,o-append $PROTO-LISTEN:$tsl,$REUSEADDR,fork,max-children=1"
11493 CMD1
="$TRACE $SOCAT $opts -u - $PROTO-CONNECT:$tsc,$SHUT"
11494 printf "test $F_n $TEST... " $N
11495 $CMD0 >/dev
/null
2>"${te}0" &
11497 wait${proto}port
$tsl 1
11498 (echo "$da 1"; sleep 3) |
$CMD1 >"${tf}1" 2>"${te}1" &
11501 echo "$da 2" |
$CMD1 >"${tf}2" 2>"${te}2" &
11504 cpids
="$(childpids $pid0)"
11505 kill $pid1 $pid2 $pid0 $cpids 2>/dev
/null
; wait
11506 if echo -e "$da 1" |
diff - $tf >$tdiff; then
11510 $PRINTF "$FAILED\n"
11512 echo "(echo \"$da 1\"; sleep 2) |$CMD1"
11513 echo "echo \"$da 2\" |$CMD1"
11518 numFAIL
=$
((numFAIL
+1))
11519 listFAIL
="$listFAIL $N"
11526 UDP4 UDP 127.0.0.1 PORT shut-null
11527 UDP6 UDP [::1] PORT shut-null
11529 # debugging this hanging test was difficult - following lessons learned:
11530 # kill <parent> had no effect when child process existed
11531 # strace -f (on Fedora-23) sometimes writes/pads? blocks with \0, overwriting client traces
11532 # using the TRACE feature lets above kill command kill strace, not socat
11533 # care for timing, understand what you want :-)
11536 # socat up to 1.7.2.0 had a bug in xioscan_readline() that could be exploited
11537 # to overflow a heap based buffer (socat security advisory 3)
11538 # problem reported by Johan Thillemann
11541 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%security
%*|
*%readline
%*|
*%$NAME%*)
11542 TEST
="$NAME: test for buffer overflow in readline prompt handling"
11543 # address 1 is the readline where write data was handled erroneous
11544 # address 2 provides data to trigger the buffer overflow
11545 # when no SIGSEGV or so occurs the test succeeded (bug fixed)
11546 if ! eval $NUMCOND; then :;
11547 elif ! feat
=$
(testaddrs readline pty
); then
11548 $PRINTF "test $F_n $TEST... ${YELLOW}$(echo "$feat"| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N
11549 numCANT
=$
((numCANT
+1))
11551 tf
="$td/test$N.stdout"
11552 te
="$td/test$N.stderr"
11553 ti
="$td/test$N.data"
11554 CMD0
="$SOCAT $opts READLINE $ti"
11555 printf "test $F_n $TEST... " $N
11556 # prepare long data - perl might not be installed
11557 #perl -e 'print "\r","Z"x513' >"$ti"
11558 echo $E -n "\rA" >"$ti"
11559 i
=0; while [ $i -lt 32 ]; do echo -n "AAAAAAAAAAAAAAAA" >>"$ti"; let i
=i
+1; done
11560 $TRACE $SOCAT - SYSTEM
:"$CMD0; echo rc=\$? >&2",pty
>/dev
/null
2>"${te}0"
11562 rc0
="$(grep ^rc= "${te}0" |sed 's/.*=//')"
11563 if [ $rc -ne 0 ]; then
11564 $PRINTF "${YELLOW}framework failed${NORMAL}\n"
11565 elif [ $rc0 -eq 0 ]; then
11569 $PRINTF "$FAILED\n"
11571 grep -v ^rc
= "${te}0"
11572 numFAIL
=$
((numFAIL
+1))
11573 listFAIL
="$listFAIL $N"
11582 # socat up to 1.7.2.1 did only shutdown() but not close() an accept() socket
11583 # that was rejected due to range, tcpwrap, lowport, or sourceport option.
11584 # This file descriptor leak could be used for a denial of service attack.
11587 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%security
%*|
*%socket
%*|
*%$NAME%*)
11588 TEST
="$NAME: file descriptor leak with range option"
11589 # have a TCP-LISTEN with range option; connect with wrong source address until
11590 # "open files" limit would exceed. When server continues operation the bug is
11592 if ! eval $NUMCOND; then :; else
11593 tf
="$td/test$N.stdout"
11594 te
="$td/test$N.stderr"
11595 tdiff
="$td/test$N.diff"
11596 da
="test$N $(date) $RANDOM"
11597 RLIMIT_NOFILE
="$(ulimit -n)"
11598 if ! [[ "$RLIMIT_NOFILE" =~ ^
[0-9][0-9]*$
]]; then
11599 $PRINTF "${YELLOW}cannot determine ulimit -n"
11601 CMD0
="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,$REUSEADDR,range=$LOCALHOST:255.255.255.255 PIPE"
11602 CMD1
="$TRACE $SOCAT $opts -t 0 /dev/null TCP:$SECONDADDR:$PORT,bind=$SECONDADDR"
11603 CMD2
="$TRACE $SOCAT $opts - TCP:$LOCALHOST:$PORT,bind=$LOCALHOST"
11604 printf "test $F_n $TEST... " $N
11605 $CMD0 >/dev
/null
2>"${te}0" &
11607 waittcp4port
$PORT 1
11608 while [ $RLIMIT_NOFILE -gt 0 ]; do
11609 $CMD1 >/dev
/null
2>>"${te}1"
11610 let RLIMIT_NOFILE
=RLIMIT_NOFILE-1
11612 echo "$da" |
$CMD2 >"${tf}2" 2>"${te}2"
11614 kill $pid0 2>/dev
/null
; wait
11615 echo -e "$da" |
diff "${tf}2" - >$tdiff
11616 if [ $rc2 -ne 0 ]; then
11617 $PRINTF "$FAILED\n"
11620 numFAIL
=$
((numFAIL
+1))
11621 listFAIL
="$listFAIL $N"
11622 elif [ -f "$tdiff" -a ! -s "$tdiff" ]; then
11626 $PRINTF "$FAILED\n"
11633 numFAIL
=$
((numFAIL
+1))
11634 listFAIL
="$listFAIL $N"
11644 if false
; then # this overflow is not reliably reproducable
11645 # socat up to 2.0.0-b6 did not check the length of the PROXY-CONNECT command line paramters when copying them into the HTTP request buffer. This could lead to a buffer overflow.
11646 NAME
=PROXY_ADDR_OVFL
11648 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%security
%*|
*%socket
%*|
*%$NAME%*)
11649 TEST
="$NAME: proxy address parameters overflow"
11650 # invoke socat PROXY-CONNECT with long proxy server and target server names. If it terminates with exit code >= 128 it is vulnerable
11651 # However, even if vulnerable it often does not crash. Therefore we try to use a boundary check program like ElectricFence; only with its help we can tell that clean run proofs absence of vulnerability
11652 if ! eval $NUMCOND; then :; else
11653 tf
="$td/test$N.stdout"
11654 te
="$td/test$N.stderr"
11655 tdiff
="$td/test$N.diff"
11656 da
="test$N $(date) $RANDOM"
11657 EF
=; for p
in ef
; do
11658 if type ef
>/dev
/null
2>&1; then
11662 CMD0
="$TRACE $SOCAT $opts TCP-LISTEN:$PORT,$REUSEADDR FILE:/dev/null"
11663 #CMD1="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:$(perl -e "print 'A' x 256"):$(perl -e "print 'A' x 256"):80"
11664 CMD1
="$EF $TRACE $SOCAT $opts FILE:/dev/null PROXY-CONNECT:localhost:$(perl -e "print
'A' x
384"):80,proxyport=$PORT"
11665 printf "test $F_n $TEST... " $N
11666 $CMD0 >/dev
/null
2>"${te}0" &
11668 waittcp4port
$PORT 1
11669 $CMD1 >/dev
/null
2>"${te}1"
11671 if [ $rc1 -lt 128 ]; then
11676 $PRINTF "$UNKNOWN $RED(install ElectricFEnce!)$NORMAL\n"
11680 $PRINTF "$FAILED\n"
11683 numFAIL
=$
((numFAIL
+1))
11684 listFAIL
="$listFAIL $N"
11694 # LISTEN addresses in socat up to 1.7.2.1 applied many file descriptor, socket,
11695 # and TCP options only to the listening socket instead of the connection socket.
11696 NAME
=LISTEN_KEEPALIVE
11698 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%listen
%*|
*%keepalive
%*|
*%socket
%*|
*%$NAME%*)
11699 TEST
="$NAME: keepalive option is applied to connection socket"
11700 # instance 0 has TCP-LISTEN with option so-keepalive and invokes filan after
11701 # accept(). filan writes its output to the socket. instance 1 connects to
11702 # instance 0. The value of the sockets so-keepalive option is checked, it must
11704 if ! eval $NUMCOND; then :; else
11705 tf
="$td/test$N.stdout"
11706 te
="$td/test$N.stderr"
11707 #tdiff="$td/test$N.diff"
11708 #da="test$N $(date) $RANDOM"
11709 CMD0
="$TRACE $SOCAT $opts TCP4-LISTEN:$PORT,$REUSEADDR,so-keepalive EXEC:\"$FILAN -i 1\",nofork"
11710 CMD1
="$TRACE $SOCAT $opts - TCP4:$LOCALHOST:$PORT"
11711 printf "test $F_n $TEST... " $N
11712 eval $CMD0 >/dev
/null
2>"${te}0" &
11714 waittcp4port
$PORT 1
11715 $CMD1 >"${tf}1" 2>"${te}1"
11716 KEEPALIVE
="$(cat "${tf}1" |tail -n +2 |sed -e "s
/.
*KEEPALIVE
=//" -e "s
/[[:space
:]].
*//")"
11718 kill $pid0 2>/dev
/null
; wait
11719 if [ -z "$KEEPALIVE" ]; then
11720 $PRINTF "$NO_RESULT\n"
11725 numCANT
=$
((numCANT
+1))
11726 elif [ "$KEEPALIVE" = "1" ]; then
11730 $PRINTF "$FAILED\n"
11735 numFAIL
=$
((numFAIL
+1))
11736 listFAIL
="$listFAIL $N"
11745 # OPENSSL-CONNECT with bind option failed on some systems (eg.FreeBSD, but not
11746 # Linux) with "Invalid argument".
11747 NAME
=OPENSSL_CONNECT_BIND
11749 *%$N%*|
*%functions
%*|
*%bugs
%*|
*%socket
%*|
*%openssl
%*|
*%$NAME%*)
11750 TEST
="$NAME: test OPENSSL-CONNECT with bind option"
11751 # have a simple SSL server that just echoes data.
11752 # connect with socat using OPENSSL-CONNECT with bind, send data and check if the
11753 # reply is identical.
11754 if ! eval $NUMCOND; then :;
11755 elif ! testaddrs openssl
>/dev
/null
; then
11756 $PRINTF "test $F_n $TEST... ${YELLOW}OPENSSL not available${NORMAL}\n" $N
11757 numCANT
=$
((numCANT
+1))
11759 gentestcert testsrv
11760 tf0
="$td/test$N.0.stdout"
11761 te0
="$td/test$N.0.stderr"
11762 tf1
="$td/test$N.1.stdout"
11763 te1
="$td/test$N.1.stderr"
11764 tdiff
="$td/test$N.diff"
11765 da
="test$N $(date) $RANDOM"
11766 CMD0
="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.pem,verify=0 PIPE"
11767 CMD1
="$TRACE $SOCAT $opts - OPENSSL-CONNECT:$LOCALHOST:$PORT,bind=$LOCALHOST,verify=0"
11768 printf "test $F_n $TEST... " $N
11769 $CMD0 >/dev
/null
2>"$te0" &
11771 waittcp4port
$PORT 1
11772 echo "$da" |
$CMD1 >"$tf1" 2>"$te1"
11774 kill $pid0 2>/dev
/null
; wait
11775 if [ "$rc1" -ne 0 ]; then
11776 $PRINTF "$FAILED\n"
11781 numFAIL
=$
((numFAIL
+1))
11782 listFAIL
="$listFAIL $N"
11783 elif ! echo "$da" |
diff - $tf1 >"$tdiff"; then
11784 $PRINTF "$FAILED\n"
11790 numFAIL
=$
((numFAIL
+1))
11791 listFAIL
="$listFAIL $N"
11803 # socat up to version 1.7.2.3
11804 # had a bug that converted a bit mask of 0 internally to 0xffffffff
11805 NAME
=TCP4RANGE_0BITS
11807 *%$N%*|
*%functions
%*|
*%tcp
%*|
*%tcp4
%*|
*%ip4
%*|
*%range
%*|
*%$NAME%*)
11808 TEST
="$NAME: correct evaluation of range mask 0"
11809 if ! eval $NUMCOND; then :;
11810 elif [ -z "$SECONDADDR" ]; then
11811 # we need access to a second addresses
11812 $PRINTF "test $F_n $TEST... ${YELLOW}need a second IPv4 address${NORMAL}\n" $N
11813 numCANT
=$
((numCANT
+1))
11815 tf
="$td/test$N.stdout"
11816 te
="$td/test$N.stderr"
11817 tdiff
="$td/test$N.diff"
11818 da
="test$N $(date) $RANDOM"
11819 #testserversec "$N" "$TEST" "$opts" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=$SECONDADDR/32" "tcp4:127.0.0.1:$PORT" 4 tcp $PORT 0
11820 CMD0
="$TRACE $SOCAT $opts -u TCP4-LISTEN:$PORT,$REUSEADDR,range=127.0.0.1/0 CREATE:$tf"
11821 CMD1
="$TRACE $SOCAT $opts -u - TCP4-CONNECT:$SECONDADDR:$PORT,bind=$SECONDADDR"
11822 printf "test $F_n $TEST... " $N
11825 waittcp4port
$PORT 1
11826 echo "$da" |
$CMD1 >"${tf}1" 2>"${te}1"
11828 kill $pid0 2>/dev
/null
; wait
11829 if [ $rc1 != 0 ]; then
11830 $PRINTF "${YELLOW}invocation failed${NORMAL}\n"
11831 numCANT
=$
((numCANT
+1))
11832 elif ! [ -f "$tf" ]; then
11833 $PRINTF "$FAILED\n"
11838 numFAIL
=$
((numFAIL
+1))
11839 listFAIL
="$listFAIL $N"
11840 elif ! echo "$da" |
diff - "$tf" >"$tdiff"; then
11841 $PRINTF "${YELLOW}diff failed${NORMAL}\n"
11842 numCANT
=$
((numCANT
+1))
11848 fi ;; # $SECONDADDR, NUMCOND
11854 # test: OPENSSL sets of environment variables with important values of peer certificate
11855 while read ssldist MODE MODULE FIELD TESTADDRESS PEERADDRESS VALUE
; do
11856 if [ -z "$ssldist" ] ||
[[ "$ssldist" == \
#* ]]; then continue; fi
11858 SSLDIST
=${ssldist^^*}
11859 NAME
="ENV_${SSLDIST}_${MODE}_${MODULE}_${FIELD}"
11861 *%$N%*|
*%functions
%*|
*%ip4
%*|
*%ipapp
%*|
*%tcp
%*|
*%$ssldist%*|
*%envvar
%*|
*%$NAME%*)
11862 TEST
="$NAME: $SSLDIST sets env SOCAT_${SSLDIST}_${MODULE}_${FIELD}"
11863 # have a server accepting a connection and invoking some shell code. The shell
11864 # code extracts and prints the SOCAT related environment vars.
11865 # outside code then checks if the environment contains the variables correctly
11866 # describing the desired field.
11867 FEAT
=$
(echo "$ssldist" |
tr a-z A-Z
)
11868 if ! eval $NUMCOND; then :;
11869 elif ! testaddrs
$FEAT >/dev
/null
; then
11870 $PRINTF "test $F_n $TEST... ${YELLOW}$FEAT not available${NORMAL}\n" $N
11871 numCANT
=$
((numCANT
+1))
11873 tf
="$td/test$N.stdout"
11874 te
="$td/test$N.stderr"
11875 gentestcert testsrv
11876 gentestcert testcli
11880 CMD0
="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
11881 CMD1
="$SOCAT $opts -u /dev/null $PEERADDRESS"
11882 printf "test $F_n $TEST... " $N
11883 eval "$CMD0 2>\"${te}0\" >\"$tf\" &"
11885 wait${test_proto}port
$PORT 1
11889 kill $pid0 2>/dev
/null
; wait
11892 CMD0
="$SOCAT $opts -u /dev/null $PEERADDRESS"
11893 CMD1
="$SOCAT $opts -u $TESTADDRESS system:\"echo SOCAT_${SSLDIST}_${MODULE}_${FIELD}=\\\$SOCAT_${SSLDIST}_${MODULE}_${FIELD}; sleep 1\""
11894 printf "test $F_n $TEST... " $N
11897 wait${test_proto}port
$PORT 1
11898 eval "$CMD1 2>\"${te}1\" >\"$tf\""
11901 kill $pid0 2>/dev
/null
; wait
11904 if [ $rc1 != 0 ]; then
11905 $PRINTF "$NO_RESULT (client failed):\n"
11910 numCANT
=$
((numCANT
+1))
11911 elif effval
="$(grep SOCAT_${SSLDIST}_${MODULE}_${FIELD} "${tf}" |
sed -e 's/^[^=]*=//' |
sed -e "s/[\"']//g")";
11912 [ "$effval" = "$VALUE" ]; then
11914 if [ "$debug" ]; then
11922 $PRINTF "$FAILED\n"
11923 echo "expected
\"$VALUE\", got
\"$effval\"" >&2
11928 numFAIL=$((numFAIL+1))
11929 listFAIL="$listFAIL $N"
11931 fi # NUMCOND, feats
11937 openssl SERVER X509 ISSUER OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 $TESTCERT_ISSUER
11938 openssl SERVER X509 SUBJECT OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 $TESTCERT_SUBJECT
11939 openssl SERVER X509 COMMONNAME OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 $TESTCERT_COMMONNAME
11940 openssl SERVER X509 COUNTRYNAME OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 $TESTCERT_COUNTRYNAME
11941 openssl SERVER X509 LOCALITYNAME OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 $TESTCERT_LOCALITYNAME
11942 openssl SERVER X509 ORGANIZATIONALUNITNAME OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 $TESTCERT_ORGANIZATIONALUNITNAME
11943 openssl SERVER X509 ORGANIZATIONNAME OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 $TESTCERT_ORGANIZATIONNAME
11944 openssl CLIENT X509 SUBJECT OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 $TESTCERT_SUBJECT
11945 openssl CLIENT X509 ISSUER OPENSSL-CONNECT
:$LOCALHOST:$PORT,cert
=testcli.pem
,cafile
=testsrv.crt
,verify
=1 OPENSSL-LISTEN
:$PORT,$REUSEADDR,bind=$LOCALHOST,cert
=testsrv.pem
,cafile
=testcli.crt
,verify
=1 $TESTCERT_ISSUER
11949 ###############################################################################
11950 # tests: option umask with "passive
" NAMED group addresses
11951 while read addr fileopt addropts proto diropt ADDR2; do
11952 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
11953 # some passive (listening...) filesystem based addresses did not implement the
11958 if [ "$diropt" = ".
" ]; then diropt=; fi
11959 if [ "$fileopt" = ".
" ]; then fileopt=; fi
11960 if [ "$addropts" = ".
" ]; then addropts=; fi
11961 NAME=${ADDR_}_UMASK
11963 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%$NAME%*)
11964 TEST="$NAME: $ADDR applies option
umask"
11965 # start a socat process with passive/listening file system entry. Check the
11966 # permissions of the FS entry, then terminate the process.
11967 # Test succeeds when FS entry exists and has expected permissions.
11968 if ! eval $NUMCOND; then :; else
11969 if [ $ADDR = PTY ]; then set -xv; fi
11970 tlog="$td/test$N.log
"
11971 te0="$td/test$N.0.stderr
"
11972 tsock="$td/test$N.sock
"
11973 if [ -z "$fileopt" ]; then
11974 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,unlink-close
=0,umask=177 $ADDR2"
11976 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,unlink-close
=0,umask=177 $ADDR2"
11978 printf "test $F_n $TEST...
" $N
11979 $CMD0 >/dev/null 2>"$te0" &
11981 wait${proto} $tsock 1 2>"$tlog"
11982 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
11983 perms=$(fileperms "$tsock")
11984 kill $pid0 2>>"$tlog"
11986 if [ "$ERRNOENT" ]; then
11987 $PRINTF "${RED}no entry
${NORMAL}\n"
11991 let numFAIL=numFAIL+1
11992 listFAIL="$listFAIL $N"
11993 elif [ "$perms" != "600" ]; then
11994 $PRINTF "${RED}perms
\"$perms\", expected
\"600\" ${NORMAL}\n"
11997 let numFAIL=numFAIL+1
11998 listFAIL="$listFAIL $N"
12011 # address fileopt addropts waitfor direction ADDR2
12012 create . .
file -U FILE
:/dev
/null
12013 open . creat
file . FILE
:/dev
/null
12014 gopen . creat
file . FILE
:/dev
/null
12015 unix-listen . . unixport . FILE
:/dev
/null
12016 unix-recvfrom . . unixport . FILE
:/dev
/null
12017 unix-recv . . unixport
-u FILE
:/dev
/null
12018 pipe . .
file -u FILE
:/dev
/null
12019 # pty does not seem to honor umask:
12020 #pty link . file . PIPE
12024 # tests: option perm with "passive
" NAMED group addresses
12025 while read addr fileopt addropts proto diropt; do
12026 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12027 # test if passive (listening...) filesystem based addresses implement option perm
12031 if [ "$diropt" = ".
" ]; then diropt=; fi
12032 if [ "$fileopt" = ".
" ]; then fileopt=; fi
12033 if [ "$addropts" = ".
" ]; then addropts=; fi
12036 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%ignoreeof%*|*%$NAME%*)
12037 TEST="$NAME: $ADDR applies option perm
"
12038 # start a socat process with passive/listening file system entry. Check the
12039 # permissions of the FS entry, then terminate the process.
12040 # Test succeeds when FS entry exists and has expected permissions.
12041 if ! eval $NUMCOND; then :; else
12042 tlog="$td/test$N.log
"
12043 te0="$td/test$N.0.stderr
"
12044 tsock="$td/test$N.sock
"
12046 if [ -z "$fileopt" ]; then
12047 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,perm
=511 FILE
:/dev
/null
,ignoreeof
"
12049 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,perm
=511 FILE
:/dev
/null
,ignoreeof
"
12051 printf "test $F_n $TEST...
" $N
12052 $CMD0 >/dev/null 2>"$te0" &
12054 wait${proto} $tsock 1 2>"$tlog"
12055 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12056 perms=$(fileperms "$tsock")
12057 kill $pid0 2>>"$tlog"
12059 if [ "$ERRNOENT" ]; then
12060 $PRINTF "${RED}no entry
${NORMAL}\n"
12064 let numFAIL=numFAIL+1
12065 listFAIL="$listFAIL $N"
12066 elif [ "$perms" != "511" ]; then
12067 $PRINTF "${RED}perms
\"$perms\", expected
\"511\" ${NORMAL}\n"
12070 let numFAIL=numFAIL+1
12071 listFAIL="$listFAIL $N"
12084 # address fileopt addropts waitfor direction
12086 open . creat
file .
12087 gopen . creat
file .
12088 unix-listen . . unixport .
12089 unix-recvfrom . . unixport .
12090 unix-recv . . unixport
-u
12096 # tests: option user with "passive
" NAMED group addresses
12097 while read addr fileopt addropts proto diropt; do
12098 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12099 # test if passive (listening...) filesystem based addresses implement option user
12103 if [ "$diropt" = ".
" ]; then diropt=; fi
12104 if [ "$fileopt" = ".
" ]; then fileopt=; fi
12105 if [ "$addropts" = ".
" ]; then addropts=; fi
12108 *%$N%*|*%functions%*|*%bugs%*|*%proto%*|*%socket%*|*%$proto%*|*%root%*|*%ignoreeof%*|*%$NAME%*)
12109 TEST="$NAME: $ADDR applies option user
"
12110 # start a socat process with passive/listening file system entry with user option.
12111 # Check the owner of the FS entry, then terminate the process.
12112 # Test succeeds when FS entry exists and has expected owner.
12113 if ! eval $NUMCOND; then :;
12114 elif [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
12115 $PRINTF "test $F_n $TEST...
${YELLOW}must be root
${NORMAL}\n" $N
12116 numCANT=$((numCANT+1))
12118 tlog="$td/test$N.log
"
12119 te0="$td/test$N.0.stderr
"
12120 tsock="$td/test$N.sock
"
12122 if [ -z "$fileopt" ]; then
12123 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts,user
=$SUBSTUSER FILE
:/dev
/null
,ignoreeof
"
12125 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts,user
=$SUBSTUSER FILE
:/dev
/null
,ignoreeof
"
12127 printf "test $F_n $TEST...
" $N
12128 $CMD0 >/dev/null 2>"$te0" &
12130 wait${proto} $tsock 1 2>"$tlog"
12131 ERRNOENT=; if ! [ -e "$tsock" ]; then ERRNOENT=1; fi
12132 user=$(fileuser "$tsock")
12133 kill $pid0 2>>"$tlog"
12135 if [ "$ERRNOENT" ]; then
12136 $PRINTF "${RED}no entry
${NORMAL}\n"
12140 let numFAIL=numFAIL+1
12141 listFAIL="$listFAIL $N"
12142 elif [ "$user" != "$SUBSTUSER" ]; then
12143 $PRINTF "${RED}user
\"$user\", expected
\"$SUBSTUSER\" ${NORMAL}\n"
12146 let numFAIL=numFAIL+1
12147 listFAIL="$listFAIL $N"
12160 # address fileopt addropts waitfor direction
12162 open . creat
file .
12163 gopen . creat
file .
12164 unix-listen . . unixport .
12165 unix-recvfrom . . unixport .
12166 unix-recv . . unixport
-u
12172 # tests: is "passive
" filesystem entry removed at the end? (without fork)
12173 while read addr fileopt addropts proto diropt crit ADDR2; do
12174 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12175 # some passive (listening...) filesystem based addresses did not remove the file
12176 # system entry at the end
12180 if [ "$diropt" = ".
" ]; then diropt=; fi
12181 if [ "$fileopt" = ".
" ]; then fileopt=; fi
12182 if [ "$addropts" = ".
" ]; then addropts=; fi
12183 # $ADDR removes the file system entry when the process is terminated
12184 NAME=${ADDR_}_REMOVE
12186 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
12187 TEST="$NAME: $ADDR removes socket entry when terminated during accept
"
12188 # start a socat process with listening unix domain socket etc. Terminate the
12189 # process and check if the file system socket entry still exists.
12190 # Test succeeds when entry does not exist.
12191 if ! eval $NUMCOND; then :; else
12192 tlog="$td/test$N.log
"
12193 te0="$td/test$N.0.stderr
"
12194 tsock="$td/test$N.sock
"
12195 if [ -z "$fileopt" ]; then
12196 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,$addropts $ADDR2"
12198 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,$fileopt=$tsock,$addropts $ADDR2"
12200 printf "test $F_n $TEST...
" $N
12201 $CMD0 >/dev/null 2>"$te0" &
12203 wait${proto} "$crit" $tsock 1 2>"$tlog"
12204 kill $pid0 2>>"$tlog"
12207 if [ $rc1 != 0 ]; then
12208 $PRINTF "${YELLOW}setup failed
${NORMAL}\n"
12212 let numCANT=numCANT+1
12213 elif ! [ $crit $tsock ]; then
12217 $PRINTF "$FAILED\n"
12221 let numFAIL=numFAIL+1
12222 listFAIL="$listFAIL $N"
12231 # address fileopt addropts waitfor direction crit ADDR2
12232 unix-listen . . unixport .
-e FILE
:/dev
/null
12233 unix-recvfrom . . unixport .
-e FILE
:/dev
/null
12234 unix-recv . . unixport
-u -e FILE
:/dev
/null
12235 pipe . .
file -u -e FILE
:/dev
/null
12236 pty link .
file .
-L PIPE
12240 # tests: is "passive
" filesystem entry removed at the end? (with fork)
12241 while read addr fileopt addropts proto diropt crit ADDR2; do
12242 if [ -z "$addr" ] || [[ "$addr" == \#* ]]; then continue; fi
12243 # some passive (listening...) filesystem based addresses with fork did not remove
12244 # the file system entry at the end
12248 if [ "$diropt" = ".
" ]; then diropt=; fi
12249 if [ "$fileopt" = ".
" ]; then fileopt=; fi
12250 if [ "$addropts" = ".
" ]; then addropts=; fi
12251 # $ADDR with fork removes the file system entry when the process is terminated
12252 NAME=${ADDR_}_REMOVE_FORK
12254 *%$N%*|*%functions%*|*%bugs%*|*%unix%*|*%socket%*|*%$NAME%*)
12255 TEST="$NAME: $ADDR with fork removes socket entry when terminated during accept
"
12256 # start a socat process with listening unix domain socket etc and option fork.
12257 # Terminate the process and check if the file system socket entry still exists.
12258 # Test succeeds when entry does not exist.
12259 if ! eval $NUMCOND; then :; else
12260 tlog="$td/test$N.log
"
12261 te0="$td/test$N.0.stderr
"
12262 tsock="$td/test$N.sock
"
12263 if [ -z "$fileopt" ]; then
12264 CMD0="$TRACE $SOCAT $opts $diropt $ADDR:$tsock,fork
,$addropts $ADDR2"
12266 CMD0="$TRACE $SOCAT $opts $diropt $ADDR,fork
,$fileopt=$tsock,$addropts $ADDR2"
12268 printf "test $F_n $TEST...
" $N
12269 $CMD0 >/dev/null 2>"$te0" &
12271 wait${proto} "$crit" $tsock 1 2>"$tlog"
12272 kill $pid0 2>>"$tlog"
12275 if [ $rc1 != 0 ]; then
12276 $PRINTF "${YELLOW}setup failed
${NORMAL}\n"
12280 let numCANT=numCANT+1
12281 elif ! [ $crit $tsock ]; then
12285 $PRINTF "$FAILED\n"
12289 let numFAIL=numFAIL+1
12290 listFAIL="$listFAIL $N"
12299 # address fileopt addropts waitfor direction crit ADDR2
12300 unix-listen . . unixport .
-e FILE
:/dev
/null
12301 unix-recvfrom . . unixport .
-e FILE
:/dev
/null
12305 # bug fix: SYSTEM address child process shut down parents sockets including
12306 # SSL connection under some circumstances.
12307 NAME=SYSTEM_SHUTDOWN
12309 *%$N%*|*%functions%*|*%bugs%*|*%system%*|*%openssl%*|*%socket%*|*%$NAME%*)
12310 TEST="$NAME: SYSTEM address does not shutdown its parents addresses
"
12311 # start an OpenSSL echo server using SYSTEM:cat
12312 # start an OpenSSL client that sends data
12313 # when the client recieves its data and terminates without error the test succeeded
12314 # in case of the bug the client issues an error like:
12315 # SSL_connect(): error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac
12316 if ! eval $NUMCOND; then :;
12317 elif ! testaddrs openssl >/dev/null; then
12318 $PRINTF "test $F_n $TEST...
${YELLOW}OPENSSL not available
${NORMAL}\n" $N
12319 numCANT=$((numCANT+1))
12321 gentestcert testsrv
12322 tf="$td/test$N.stdout
"
12323 te="$td/test$N.stderr
"
12324 tdiff="$td/test$N.
diff"
12325 da="test$N $
(date) $RANDOM"
12326 CMD0="$SOCAT $opts OPENSSL-LISTEN
:$PORT,$REUSEADDR,cert
=testsrv.pem
,verify
=0 SYSTEM
:cat"
12327 CMD1="$SOCAT $opts - OPENSSL-CONNECT
:$LOCALHOST:$PORT,verify
=0"
12328 printf "test $F_n $TEST...
" $N
12329 $CMD0 >/dev/null 2>"${te}0" &
12331 waittcp4port $PORT 1
12332 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12334 kill $pid0 2>/dev/null; wait
12335 if [ $rc1 -ne 0 ]; then
12336 $PRINTF "$FAILED\n"
12342 numFAIL=$((numFAIL+1))
12343 listFAIL="$listFAIL $N"
12344 elif ! echo "$da" |diff - "${tf}1" >"$tdiff" 2>&1; then
12345 $PRINTF "$FAILED\n"
12352 numFAIL=$((numFAIL+1))
12353 listFAIL="$listFAIL $N"
12365 # test if TCP4-LISTEN with empty port arg terminates with error
12368 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%tcp%*|*%tcp4%*|*%$NAME%*)
12369 TEST="$NAME: test if TCP4-LISTEN with empty port arg bails out
"
12370 # run socat with TCP4-LISTEN with empty port arg. Check if it terminates
12371 # immediately with return code 1
12372 if ! eval $NUMCOND; then :; else
12373 tf="$td/test$N.stdout
"
12374 te="$td/test$N.stderr
"
12375 t0rc="$td/test$N.rc
"
12376 tdiff="$td/test$N.
diff"
12377 da="test$N $
(date) $RANDOM"
12378 CMD0="$SOCAT $opts TCP4-LISTEN
: /dev
/null
"
12379 printf "test $F_n $TEST...
" $N
12380 { $CMD0 >/dev/null 2>"${te}0"; echo $? >"$t0rc"; } & 2>/dev/null
12383 kill $pid0 2>/dev/null; wait
12384 if [ ! -f "$t0rc" ]; then
12385 $PRINTF "$FAILED\n"
12386 echo "no
return code of CMD0 stored
" >&2
12389 numFAIL=$((numFAIL+1))
12390 listFAIL="$listFAIL $N"
12391 elif ! echo 1 |diff - "$t0rc" >"$tdiff"; then
12392 $PRINTF "$FAILED\n"
12393 echo "CMD0 exited with $
(cat $t0rc), expected
1"
12396 numFAIL=$((numFAIL+1))
12397 listFAIL="$listFAIL $N"
12409 # tests of various SSL methods:
12410 OPENSSL_METHODS_OBSOLETE="SSL3 SSL23
"
12411 OPENSSL_METHODS_EXPECTED="TLS1 TLS1.1 TLS1.2 DTLS1
"
12413 # the OPENSSL_METHOD_DTLS1 test hangs sometimes, probably depending on the openssl version.
12414 OPENSSL_VERSION="$
(openssl version
)"
12415 OPENSSL_VERSION="${OPENSSL_VERSION#* }"
12416 OPENSSL_VERSION="${OPENSSL_VERSION%%-*}"
12417 OPENSSL_VERSION_GOOD=1.0.2 # this is just a guess.
12418 # known bad: 1.0.1e
12419 # known good: 1.0.2j
12422 # test if the obsolete SSL methods can be used with OpenSSL
12423 for method in $OPENSSL_METHODS_OBSOLETE; do
12425 NAME=OPENSSL_METHOD_$method
12427 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
12428 TEST="$NAME: test OpenSSL method
$method"
12429 # Start a socat process with obsoelete OpenSSL method, it should fail
12430 if ! eval $NUMCOND; then :;
12431 elif ! testaddrs openssl >/dev/null; then
12432 $PRINTF "test $F_n $TEST...
${YELLOW}OPENSSL not available
${NORMAL}\n" $N
12433 numCANT=$((numCANT+1))
12434 elif ! socat -hhh |grep -q "^
[[:space
:]]*openssl-method
[[:space
:]]"; then
12435 $PRINTF "test $F_n $TEST...
${YELLOW}Option openssl-method not available
${NORMAL}\n" $N
12436 numCANT=$((numCANT+1))
12438 gentestcert testsrv
12439 tf="$td/test$N.stdout
"
12440 te="$td/test$N.stderr
"
12441 tdiff="$td/test$N.
diff"
12442 da="test$N $
(date) $RANDOM"
12443 CMD0="$SOCAT $opts OPENSSL-LISTEN
:$PORT,$REUSEADDR,openssl-method
=$method,cert
=testsrv.pem
,verify
=0 PIPE
"
12444 CMD1="$SOCAT $opts - OPENSSL-CONNECT
:$LOCALHOST:$PORT,opensslmethod
=$method,verify
=0"
12445 printf "test $F_n $TEST...
" $N
12446 if [ "$method" = DTLS1 -a "$
(echo -e "$OPENSSL_VERSION\n1.0.2" |
sort -V |
tail -n 1)" = "$OPENSSL_VERSION_GOOD" ]; then
12447 $PRINTF "${YELLOW}might hang
, skipping
${NORMAL}\n"
12448 numCANT=$((numCANT+1))
12450 $CMD0 >/dev/null 2>"${te}0" &
12452 waittcp4port $PORT 1 1 2>/dev/null; w0=$? # result of waiting for process 0
12453 if [ $w0 -eq 0 ]; then
12454 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12456 kill $pid0 2>/dev/null; wait
12458 if [ $w0 -eq 0 ] && echo "$da" |diff - "${tf}1"; then
12459 $PRINTF "${YELLOW}WARN
${NORMAL} (obsolete method succeeds
)\n"
12462 $PRINTF "$OK (obsolete method fails
)\n"
12465 if [ "$VERBOSE" ]; then
12467 echo " echo \"$da\" |
$CMD1"
12478 # test if the various SSL methods can be used with OpenSSL
12479 for method in $OPENSSL_METHODS_EXPECTED; do
12481 NAME=OPENSSL_METHOD_$method
12483 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%openssl%*|*%$NAME%*)
12484 TEST="$NAME: test OpenSSL method
$method"
12485 # Start a socat process listening with OpenSSL and echoing data,
12486 # using the selected method
12487 # Start a second socat process connecting to the listener using
12488 # the same method, send some data and catch the reply.
12489 # If the reply is identical to the sent data the test succeeded.
12490 if ! eval $NUMCOND; then :;
12491 elif ! testaddrs openssl >/dev/null; then
12492 $PRINTF "test $F_n $TEST...
${YELLOW}OPENSSL not available
${NORMAL}\n" $N
12493 numCANT=$((numCANT+1))
12494 elif ! socat -hhh |grep -q "^
[[:space
:]]*openssl-method
[[:space
:]]"; then
12495 $PRINTF "test $F_n $TEST...
${YELLOW}Option openssl-method not available
${NORMAL}\n" $N
12496 numCANT=$((numCANT+1))
12498 gentestcert testsrv
12499 tf="$td/test$N.stdout
"
12500 te="$td/test$N.stderr
"
12501 tdiff="$td/test$N.
diff"
12502 da="test$N $
(date) $RANDOM"
12503 CMD0="$SOCAT $opts OPENSSL-LISTEN
:$PORT,$REUSEADDR,openssl-method
=$method,cert
=testsrv.pem
,verify
=0 PIPE
"
12504 CMD1="$SOCAT $opts - OPENSSL-CONNECT
:$LOCALHOST:$PORT,openssl-method
=$method,verify
=0"
12505 printf "test $F_n $TEST...
" $N
12506 if [ "$method" = DTLS1 -a "$
(echo -e "$OPENSSL_VERSION\n1.0.2" |
sort -V |
tail -n 1)" = "$OPENSSL_VERSION_GOOD" ]; then
12507 $PRINTF "${YELLOW}might hang
, skipping
${NORMAL}\n"
12508 numCANT=$((numCANT+1))
12510 $CMD0 >/dev/null 2>"${te}0" &
12512 waittcp4port $PORT 1
12513 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12515 kill $pid0 2>/dev/null; wait
12516 if echo "$da" |diff - "${tf}1"; then
12519 if [ "$VERBOSE" ]; then
12521 echo " echo \"$da\" |
$CMD1"
12524 $PRINTF "$FAILED\n"
12529 numFAIL=$((numFAIL+1))
12530 listFAIL="$listFAIL $N"
12543 # Address options fdin and fdout were silently ignored when not applicable
12544 # due to -u or -U option. Now these combinations are caught as errors.
12547 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
12548 TEST="$NAME: fdout bails out
in write-only context
"
12549 # use EXEC in write-only context with option fdout. Expected behaviour: error
12550 if ! eval $NUMCOND; then :; else
12551 tf="$td/test$N.stdout
"
12552 te="$td/test$N.stderr
"
12553 tdiff="$td/test$N.
diff"
12554 da="test$N $
(date) $RANDOM"
12555 CMD="$SOCAT $opts -u /dev
/null EXEC
:cat,fdout
=1"
12556 printf "test $F_n $TEST...
" $N
12557 $CMD >/dev/null 2>"${te}"
12559 if [ $rc -eq 1 ]; then
12563 $PRINTF "$FAILED\n"
12566 echo "command did not terminate with error
!"
12567 numFAIL=$((numFAIL+1))
12568 listFAIL="$listFAIL $N"
12577 # test if failure exit code of SYSTEM invocation causes socat to also exit
12581 *%$N%*|*%functions%*|*%system%*|*%$NAME%*)
12582 TEST="$NAME: promote failure of SYSTEM
"
12583 # run socat with SYSTEM:false and check if socat exits with !=0
12584 if ! eval $NUMCOND; then :; else
12585 tf="$td/test$N.stdout
"
12586 te="$td/test$N.stderr
"
12587 tdiff="$td/test$N.
diff"
12588 da="test$N $
(date) $RANDOM"
12589 # shut-none makes sure that the child is not killed by parent
12590 CMD0="$TRACE $SOCAT $opts - SYSTEM
:false
,shut-none
"
12591 printf "test $F_n $TEST...
" $N
12592 sleep 1 |$CMD0 >/dev/null 2>"${te}0"
12594 if [ $rc0 -eq 0 ]; then
12595 $PRINTF "$FAILED\n"
12598 numFAIL=$((numFAIL+1))
12599 listFAIL="$listFAIL $N"
12611 # test if failure exit code of EXEC invocation causes socat to also exit
12615 *%$N%*|*%functions%*|*%exec%*|*%$NAME%*)
12616 TEST="$NAME: promote failure of EXEC
"
12617 # run socat with EXEC:false and check if socat exits with !=0
12618 if ! eval $NUMCOND; then :; else
12619 tf="$td/test$N.stdout
"
12620 te="$td/test$N.stderr
"
12621 tdiff="$td/test$N.
diff"
12622 da="test$N $
(date) $RANDOM"
12623 # shut-none makes sure that the child is not killed by parent
12624 CMD0="$TRACE $SOCAT $opts - EXEC
:false
,shut-none
"
12625 printf "test $F_n $TEST...
" $N
12626 sleep 1 |$CMD0 >/dev/null 2>"${te}0"
12628 if [ $rc0 -eq 0 ]; then
12629 $PRINTF "$FAILED\n"
12632 numFAIL=$((numFAIL+1))
12633 listFAIL="$listFAIL $N"
12645 # test the so-reuseaddr option
12648 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%socket%*|*%$NAME%*)
12649 TEST="$NAME: test the so-reuseaddr option
"
12650 # process 0 provides a tcp listening socket with so-reuseaddr;
12651 # process 1 connects to this port; thus the port is connected but no longer
12653 # process 2 tries to listen on this port with SO_REUSEADDR, will fail if the
12654 # SO_REUSEADDR socket options did not work
12655 # process 3 connects to this port; only if it is successful the test is ok
12656 if ! eval $NUMCOND; then :;
12657 elif ! feat=$(testoptions so-reuseaddr); then
12658 $PRINTF "test $F_n $TEST...
${YELLOW}$feat not available
${NORMAL}\n" $N
12659 numCANT=$((numCANT+1))
12662 tf="$td/test$N.stdout
"
12663 te="$td/test$N.stderr
"
12664 tdiff="$td/test$N.
diff"
12665 da="test$N $
(date) $RANDOM"
12666 CMD0="$TRACE $SOCAT $opts TCP4-L
:$tp,$REUSEADDR PIPE
"
12667 CMD1="$TRACE $SOCAT $opts - TCP
:localhost
:$tp"
12670 printf "test $F_n $TEST...
" $N
12671 $CMD0 >/dev/null 2>"${te}0" &
12674 (echo "$da"; sleep 3) |$CMD1 >"$tf" 2>"${te}1" & # this should always work
12677 $CMD2 >/dev/null 2>"${te}2" &
12680 (echo "$da") |$CMD3 >"${tf}3" 2>"${te}3"
12682 kill $pid0 $pid1 $pid2 2>/dev/null; wait
12683 if ! echo "$da" |diff - "$tf"; then
12684 $PRINTF "${YELLOW}phase
1 failed
${NORMAL}\n"
12687 numCANT=$((numCANT+1))
12688 elif [ $rc3 -ne 0 ]; then
12689 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
12694 cat "${te}2" "${te}3"
12695 numFAIL=$((numFAIL+1))
12696 listFAIL="$listFAIL $N"
12697 elif ! echo "$da" |diff - "${tf}3"; then
12698 $PRINTF "$FAILED: $TRACE $SOCAT:\n"
12703 echo "$da" |diff - "${tf}3"
12704 numCANT=$((numCANT+1))
12707 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
12710 fi # NUMCOND, SO_REUSEADDR
12717 # test the so-reuseport option
12720 *%$N%*|*%functions%*|*%ip4%*|*%tcp%*|*%socket%*|*%$NAME%*)
12721 TEST="$NAME: test the so-reuseport option
"
12722 # process 0 provides a tcp listening socket with so-reuseport;
12723 # process 1 provides an equivalent tcp listening socket with so-reuseport;
12724 # process 2 connects to this port and transfers data
12725 # process 3 connects to this port and transfers data
12726 # test succeeds when both data transfers work
12727 if ! eval $NUMCOND; then :;
12728 elif ! feat=$(testoptions so-reuseport); then
12729 $PRINTF "test $F_n $TEST...
${YELLOW}$feat not available
${NORMAL}\n" $N
12730 numCANT=$((numCANT+1))
12733 tf="$td/test$N.stdout
"
12734 te="$td/test$N.stderr
"
12735 tdiff="$td/test$N.
diff"
12736 da2="test$N $
(date) $RANDOM"
12737 da3="test$N $
(date) $RANDOM"
12738 CMD0="$TRACE $SOCAT $opts TCP4-L
:$tp,$REUSEADDR,so-reuseport PIPE
"
12740 CMD2="$TRACE $SOCAT $opts - TCP
:localhost
:$tp"
12742 printf "test $F_n $TEST...
" $N
12743 $CMD0 >/dev/null 2>"${te}0" &
12745 $CMD1 >/dev/null 2>"${te}1" &
12748 (echo "$da2") |$CMD2 >"${tf}2" 2>"${te}2" # this should always work
12750 (echo "$da3") |$CMD3 >"${tf}3" 2>"${te}3"
12752 kill $pid0 $pid1 $pid2 2>/dev/null; wait
12753 if ! echo "$da2" |diff - "${tf}2"; then
12754 $PRINTF "${YELLOW}phase
1 failed
${NORMAL}\n"
12758 cat "${te}0" "${te}1" "${te}2"
12759 numCANT=$((numCANT+1))
12760 elif [ $rc3 -ne 0 ]; then
12761 $PRINTF "$FAILED:\n"
12766 cat "${te}0" "${te}1" "${te}2" "${te}3"
12767 numFAIL=$((numFAIL+1))
12768 listFAIL="$listFAIL $N"
12769 elif ! echo "$da2" |diff - "${tf}2"; then
12770 $PRINTF "$FAILED:\n"
12775 cat "${te}0" "${te}1" "${te}2" "${te}3"
12776 echo "$da2" |diff - "${tf}2"
12777 numFAIL=$((numFAIL+1))
12778 listFAIL="$listFAIL $N"
12779 elif ! echo "$da3" |diff - "${tf}3"; then
12780 $PRINTF "$FAILED:\n"
12785 cat "${te}0" "${te}1" "${te}2" "${te}3"
12786 echo "$da3" |diff - "${tf}3"
12787 numFAIL=$((numFAIL+1))
12788 listFAIL="$listFAIL $N"
12791 if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2" "${te}3"; fi
12794 fi # NUMCOND, SO_REUSEPORT
12801 # Programs invoked with EXEC, nofork, and -u or -U had stdin and stdout assignment swapped.
12802 NAME=EXEC_NOFORK_UNIDIR
12804 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
12805 TEST="$NAME: Programs invoked with EXEC
, nofork
, and
-u or
-U had stdin and stdout assignment swapped
"
12806 # invoke a simple echo command with EXEC, nofork, and -u
12807 # expected behaviour: output appears on stdout
12808 if ! eval $NUMCOND; then :; else
12809 tf="$td/test$N.stdout
"
12810 te="$td/test$N.stderr
"
12811 tdiff="$td/test$N.
diff"
12812 da="test$N $
(date) $RANDOM"
12813 CMD0="$TRACE $SOCAT $opts -u /dev
/null EXEC
:\"echo \\\\\\\"\\\"$da\\\"\\\\\\\"\",nofork
"
12814 printf "test $F_n $TEST...
" $N
12815 eval "$CMD0" >"${tf}0" 2>"${te}0"
12817 if echo "$da" |diff - "${tf}0" >"$tdiff"; then
12821 $PRINTF "$FAILED\n"
12825 numFAIL=$((numFAIL+1))
12826 listFAIL="$listFAIL $N"
12835 # OpenSSL ECDHE ciphers were introduced in socat 1.7.3.0 but in the same release
12836 # they were broken by a porting effort. This test checks if OpenSSL ECDHE works
12837 # 2019-02: this does no longer work (Ubuntu-18.04)
12840 *%$N%*|*%functions%*|*%bugs%*|*%openssl%*|*%socket%*|*%$NAME%*)
12841 TEST="$NAME: test OpenSSL ECDHE
"
12842 # generate a ECDHE key, start an OpenSSL server, connect with a client and try to
12844 if ! eval $NUMCOND; then :;
12845 elif ! testaddrs openssl >/dev/null; then
12846 $PRINTF "test $F_n $TEST...
${YELLOW}OPENSSL not available
${NORMAL}\n" $N
12847 numCANT=$((numCANT+1))
12849 tf="$td/test$N.stdout
"
12850 te="$td/test$N.stderr
"
12851 tdiff="$td/test$N.
diff"
12852 da="test$N $
(date) $RANDOM"
12853 #TESTSRV=./testsrvec; gentesteccert $TESTSRV
12854 TESTSRV=./testsrv; gentestcert $TESTSRV
12855 CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN
:$PORT,$REUSEADDR,cert
=$TESTSRV.crt
,key
=$TESTSRV.pem
,verify
=0 PIPE
"
12856 CMD1="$TRACE $SOCAT $opts - OPENSSL-CONNECT
:$LOCALHOST:$PORT,cipher
=ECDHE-ECDSA-AES256-GCM-SHA384
,cafile
=$TESTSRV.crt
,verify
=0"
12857 printf "test $F_n $TEST...
" $N
12858 $CMD0 >/dev/null 2>"${te}0" &
12860 waittcp4port $PORT 1
12861 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
12863 kill $pid0 2>/dev/null; wait
12864 if [ $rc1 -ne 0 ]; then
12865 $PRINTF "$FAILED\n"
12866 echo "failure symptom
: client error
" >&2
12867 echo "server and stderr
:" >&2
12870 echo "client and stderr
:" >&2
12873 numFAIL=$((numFAIL+1))
12874 listFAIL="$listFAIL $N"
12875 elif echo "$da" |diff - "${tf}1" >"$tdiff"; then
12879 $PRINTF "$FAILED\n"
12880 echo "server and stderr
:" >&2
12883 echo "client and stderr
:" >&2
12886 numFAIL=$((numFAIL+1))
12887 listFAIL="$listFAIL $N"
12896 # option ipv6-join-group "could not be used
"
12898 NAME=USE_IPV6_JOIN_GROUP
12900 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%ip6%*|*%udp%*|*%udp6%*|*%dgram%*|*%$NAME%*)
12901 TEST="$NAME: is option ipv6-join-group used
"
12902 # Invoke socat with option ipv6-join-group on UDP6 address.
12903 # Terminate immediately, do not transfer data.
12904 # If socat exits with 0 the test succeeds.
12905 # Up to 1.7.3.1 it failed with "1 option
(s
) could not be used
"
12906 if ! eval $NUMCOND; then :; else
12907 tf="$td/test$N.stdout
"
12908 te="$td/test$N.stderr
"
12909 tdiff="$td/test$N.
diff"
12910 da="test$N $
(date) $RANDOM"
12911 CMD0="$TRACE $SOCAT $opts UDP6-RECV
:$PORT,ipv6-join-group
=[ff02
::2]:$MCINTERFACE /dev
/null
"
12912 printf "test $F_n $TEST...
" $N
12913 $CMD0 >/dev/null 2>"${te}0"
12915 if [ $rc0 -eq 0 ]; then
12919 $PRINTF "$FAILED\n"
12922 numFAIL=$((numFAIL+1))
12923 listFAIL="$listFAIL $N"
12932 # The fix to "Make code async-signal-safe
" used internally FD 3 and FD 4.
12933 # Using option fdin=3 did not pass data to executed program.
12936 *%$N%*|*%functions%*|*%bugs%*|*%exec%*|*%$NAME%*)
12937 TEST="$NAME: test use of fdin
=3"
12938 # Use FD 3 explicitely with fdin and test if Socat passes data to executed
12940 if ! eval $NUMCOND; then :; else
12941 tf="$td/test$N.stdout
"
12942 te="$td/test$N.stderr
"
12943 tdiff="$td/test$N.
diff"
12944 da="test$N $
(date) $RANDOM"
12945 CMD0="$TRACE $SOCAT $opts - SYSTEM
:\"cat >&3 <&4\",fdin
=4,fdout
=3"
12946 printf "test $F_n $TEST...
" $N
12947 echo "$da" |$TRACE $SOCAT $opts - SYSTEM:"cat <&3 >&4",fdin=3,fdout=4 >${tf}0 2>"${te}0"
12949 if [ $rc0 -ne 0 ]; then
12950 $PRINTF "$FAILED\n"
12953 numFAIL=$((numFAIL+1))
12954 listFAIL="$listFAIL $N"
12955 elif echo "$da" |diff - ${tf}0 >$tdiff; then
12959 $PRINTF "$FAILED\n"
12963 numFAIL=$((numFAIL+1))
12964 listFAIL="$listFAIL $N"
12973 NAME=SOCAT_OPT_HINT
12975 *%$N%*|*%socat%*|*%$NAME%*)
12976 TEST="$NAME: check
if merging single character options is rejected
"
12977 if ! eval $NUMCOND; then :; else
12978 te="$td/test$N.stderr
"
12979 CMD0="$TRACE $SOCAT $opts -vx FILE
:/dev
/null ECHO
"
12980 printf "test $F_n $TEST...
" $N
12981 $CMD0 >/dev/null 2>"${te}0"
12983 if [ "$rc0" = "1" ]; then
12987 $PRINTF "$FAILED\n"
12989 numFAIL=$((numFAIL+1))
12990 listFAIL="$listFAIL $N"
12997 ##################################################################################
12998 #=================================================================================
12999 # here come tests that might affect your systems integrity. Put normal tests
13000 # before this paragraph.
13001 # tests must be explicitely selected by roottough or name (not number)
13005 *%roottough%*|*%$NAME%*)
13006 TEST="$NAME: pty with group-late works on pty
"
13007 # up to socat 1.7.1.1 address pty changed the ownership of /dev/ptmx instead of
13008 # the pty with options user-late, group-late, or perm-late.
13009 # here we check for correct behaviour.
13010 # ATTENTION: in case of failure of this test the
13011 # group of /dev/ptmx might be changed!
13012 if ! eval $NUMCOND; then :; else
13013 # save current /dev/ptmx properties
13015 for f in /dev/ptmx /dev/ptc; do
13017 F=$(echo "$f" |tr / ..)
13018 ls -l $f >"$td/test$N.
$F.ls-l
"
13022 printf "test $F_n $TEST...
" $N
13023 if [ -z "$F" ]; then
13024 echo -e "${YELLOW}no
/dev
/ptmx or
/dev
/ptc
${NORMAL}"
13027 tf="$td/test$N.stdout
"
13028 te="$td/test$N.stderr
"
13029 tl="$td/test$N.pty
"
13030 tdiff="$td/test$N.
diff"
13031 da="test$N $
(date) $RANDOM"
13032 CMD0="$TRACE $SOCAT $opts pty
,link
=$tl,group-late
=$GROUP,escape
=0x1a PIPE
"
13033 CMD1="$TRACE $SOCAT $opts - $tl,raw
,echo=0"
13034 $CMD0 >/dev/null 2>"${te}0" &
13036 (echo "$da"; usleep $MICROS; echo -e "\x1a") |$CMD1 >"${tf}1" 2>"${te}1" >"$tf"
13038 kill $pid0 2>/dev/null; wait
13039 if [ $rc1 -ne 0 ]; then
13040 $PRINTF "$FAILED\n"
13045 numFAIL=$((numFAIL+1))
13046 listFAIL="$listFAIL $N"
13047 elif echo "$da" |diff - "$tf" >$tdiff; then
13051 $PRINTF "$FAILED\n"
13053 numFAIL=$((numFAIL+1))
13054 listFAIL="$listFAIL $N"
13056 if ! ls -l $f |diff "$td/test$N.
$F.ls-l
" -; then
13057 $PRINTF "${RED}this
test changed properties of
$f!${NORMAL}\n"
13066 echo "summary
: $
((N-1
)) tests
, $
((numOK
+numFAIL
+numCANT
)) selected
; $numOK ok
, $numFAIL failed
, $numCANT could not be performed
"
13068 if [ "$numFAIL" -gt 0 ]; then
13069 echo "FAILED
: $listFAIL"
13074 #==============================================================================
13076 rm -f testsrv.* testcli.* testsrvdsa* testsrvfips* testclifips*
13080 # too dangerous - run as root and having a shell problem, it might purge your
13084 # sometimes subprocesses hang; we want to see this
13091 # give a description of what is tested (a bugfix, a new feature...)
13092 NAME=SHORT_UNIQUE_TESTNAME
13094 *%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*)
13095 TEST="$NAME: give a one line description of
test"
13096 # describe how the test is performed, and what's the success criteria
13097 if ! eval $NUMCOND; then :; else
13098 tf="$td/test$N.stdout
"
13099 te="$td/test$N.stderr
"
13100 tdiff="$td/test$N.
diff"
13101 da="test$N $
(date) $RANDOM"
13102 CMD0="$TRACE $SOCAT $opts server-address PIPE
"
13103 CMD1="$TRACE $SOCAT $opts - client-address
"
13104 printf "test $F_n $TEST...
" $N
13105 $CMD0 >/dev/null 2>"${te}0" &
13107 wait<something>port $PORT 1
13108 echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
13110 kill $pid0 2>/dev/null; wait
13115 $PRINTF "$FAILED\n"
13120 numFAIL=$((numFAIL+1))
13121 listFAIL="$listFAIL $N"