-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·15103 lines (14339 loc) · 456 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env bash
# source: test.sh
# Copyright Gerhard Rieger and contributors (see file CHANGES)
# Published under the GNU General Public License V.2, see file COPYING
# perform lots of tests on socat
# this script uses functions; you need a shell that supports them
# you can pass general options to socat: export OPTS="-d -d -d -d -lu"
# you can eg strace socat with: export TRACE="strace -v -tt -ff -D -x -s 1024 -o /tmp/$USER/socat.strace"
#set -vx
val_t=0.1
NUMCOND=true
#NUMCOND="test \$N -gt 70"
VERBOSE=
FOREIGN=
while [ "$1" ]; do
case "X$1" in
X-t?*) val_t="${1#-t}" ;;
X-t) shift; val_t="$1" ;;
X-v) VERBOSE=1 ;; # show commands
X-n?*) NUMCOND="test \$N -eq ${1#-n}" ;;
X-n) shift; NUMCOND="test \$N -eq $1" ;;
X-N?*) NUMCOND="test \$N -gt ${1#-N}" ;;
X-N) shift; NUMCOND="test \$N -ge $1" ;;
X-C) rm -f testcert*.conf testcert.dh testcli*.* testsrv*.* ;;
X-foreign) FOREIGN=1 ;; # allow access to 3rd party Internet hosts
*) break;
esac
shift
done
opt_t="-t $val_t"
UNAME=`uname`
UNAME_R=`uname -r`
#MICROS=100000
case "X$val_t" in
X*.???????*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS:0:6}" ;;
X*.*) S="${val_t%.*}"; uS="${val_t#*.}"; uS="${uS}000000"; uS="${uS:0:6}" ;;
X*) S="${val_t}"; uS="000000" ;;
esac
MICROS=${S}${uS}
MICROS=${MICROS##0000}; MICROS=${MICROS##00}; MICROS=${MICROS##0}
#echo MICROS=$MICROS >&2
#
_MICROS=$((MICROS+999999)); SECONDs="${_MICROS%??????}"
[ -z "$SECONDs" ] && SECONDs=0
withroot=0 # perform privileged tests even if not run by root
#PATH=$PATH:/opt/freeware/bin
#PATH=$PATH:/usr/local/ssl/bin
PATH=$PATH:/sbin # RHEL6:ip
case "$0" in
*/*) PATH="${0%/*}:$PATH"
esac
#OPENSSL_RAND="-rand /dev/egd-pool"
#SOCAT_EGD="egd=/dev/egd-pool"
MISCDELAY=1
[ -z "$SOCAT" ] && SOCAT="./socat"
if ! [ -x "$SOCAT" ] && ! type $SOCAT >/dev/null 2>&1; then
echo "$SOCAT does not exist" >&2; exit 1;
fi
if [ -z "$PROCAN" ]; then if test -x ./procan; then PROCAN="./procan"; elif ! type procan >/dev/null 2>&1; then PROCAN=${SOCAT%/*}/procan; fi; fi
if [ -z "$FILAN" ]; then if test -x ./filan; then FILAN="./filan"; elif ! type filan >/dev/null 2>&1; then FILAN=${SOCAT%/*}/filan; fi; fi
opts="$opt_t $OPTS"
export SOCAT_OPTS="$opts"
#debug="1"
debug=
TESTS="$@"; export TESTS
if ! $SOCAT -V >/dev/null 2>&1; then
echo "Failed to execute $SOCAT, exiting" >&2
exit 1
fi
SOCAT_VERSION=$($SOCAT -V |head -n 2 |tail -n 1 |sed 's/.* \([0-9][1-9]*\.[0-9][0-9]*\.[0-9][^[:space:]]*\).*/\1/')
if [ -z "$SOCAT_VERSION" ]; then
echo "Warning: failed to retrieve Socat version" >&2
fi
# for some tests we need a network interface
if type ip >/dev/null 2>&1; then
INTERFACE=$(ip r get 8.8.8.8 |grep ' dev ' |head -n 1 |sed "s/.*dev[[:space:]][[:space:]]*\([^[:space:]][^[:space:]]*\).*/\1/")
else
case "$UNAME" in
Linux)
if [ "$IP" ]; then
INTERFACE="$($IP route get 8.8.8.8 |grep ' dev ' |sed -e 's/.* dev //' -e 's/ .*//')"
else
INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($8);}')"
fi ;;
FreeBSD) INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($4);}')" ;;
*) INTERFACE="$(netstat -rn |grep -e "^default" -e "^0\.0\.0\.0" |awk '{print($4);}')" ;;
esac
fi
MCINTERFACE=$INTERFACE
[ -z "$MCINTERFACE" ] && MCINTERFACE=lo # !!! Linux only - and not always
#LOCALHOST=192.168.58.1
LOCALHOST=localhost
#LOCALHOST=127.0.0.1
LOCALHOST6=[::1]
#PROTO=$(awk '{print($2);}' /etc/protocols |sort -n |tail -n 1)
#PROTO=$(($PROTO+1))
PROTO=$((144+RANDOM/2048))
PORT=12002
SOURCEPORT=2002
REUSEADDR=reuseaddr # use this with LISTEN addresses and bind options
# SSL certificate contents
TESTCERT_CONF=testcert.conf
TESTCERT6_CONF=testcert6.conf
TESTALT_CONF=testalt.conf
#
TESTCERT_COMMONNAME="$LOCALHOST"
TESTCERT_COMMONNAME6="$LOCALHOST6"
TESTCERT_COUNTRYNAME="XY"
TESTCERT_LOCALITYNAME="Lunar Base"
TESTCERT_ORGANIZATIONALUNITNAME="socat"
TESTCERT_ORGANIZATIONNAME="dest-unreach"
TESTCERT_SUBJECT="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
TESTCERT_ISSUER="C = $TESTCERT_COUNTRYNAME, CN = $TESTCERT_COMMONNAME, O = $TESTCERT_ORGANIZATIONNAME, OU = $TESTCERT_ORGANIZATIONALUNITNAME, L = $TESTCERT_LOCALITYNAME"
RSABITS=2048 # Ubuntu-20.04 with OpenSSL-1.1.1f does not work with 1024 nor 1536
DSABITS=2048
cat >$TESTCERT_CONF <<EOF
prompt=no
[ req ]
default_bits = $RSABITS
distinguished_name=Test
[ Test ]
countryName=$TESTCERT_COUNTRYNAME
commonName=$TESTCERT_COMMONNAME
O=$TESTCERT_ORGANIZATIONNAME
OU=$TESTCERT_ORGANIZATIONALUNITNAME
L=$TESTCERT_LOCALITYNAME
EOF
cat >$TESTCERT6_CONF <<EOF
prompt=no
[ req ]
default_bits = $RESBITS
distinguished_name=Test
[ Test ]
countryName=$TESTCERT_COUNTRYNAME
commonName=$TESTCERT_COMMONNAME6
O=$TESTCERT_ORGANIZATIONNAME
OU=$TESTCERT_ORGANIZATIONALUNITNAME
L=$TESTCERT_LOCALITYNAME
EOF
cat >$TESTALT_CONF <<EOF
# config for generation of self signed certificate with IP addresses in
# SubjectAltNames
prompt=no
[ req ]
default_bits = $RSABITS
distinguished_name = subject
x509_extensions = x509_ext
[ subject ]
countryName=$TESTCERT_COUNTRYNAME
commonName=servername
O=$TESTCERT_ORGANIZATIONNAME
OU=$TESTCERT_ORGANIZATIONALUNITNAME
L=$TESTCERT_LOCALITYNAME
[ x509_ext ]
subjectAltName = @alternate_names
[ alternate_names ]
DNS.1 = localhost
DNS.2 = localhost4
DNS.3 = localhost6
IP.1 = 127.0.0.1
IP.2 = ::1
EOF
# clean up from previous runs
rm -f testcli.{crt,key,pem}
rm -f testsrv.{crt,key,pem}
rm -f testcli6.{crt,key,pem}
rm -f testsrv6.{crt,key,pem}
rm -f testalt.{crt,key,pem}
CAT=cat
OD_C="od -c"
toupper () {
case ${BASH_VERSION:0:1} in
[1-3]) echo "$@" |tr a-z A-Z ;;
[4-9]) echo "${@^^*}" ;;
esac
}
tolower () {
case ${BASH_VERSION:0:1} in
[1-3]) echo "$@" |tr A-Z a-z ;;
[4-9]) echo "${@,,*}" ;;
esac
}
# precision sleep; takes seconds with fractional part
psleep () {
local T="$1"
[ "$T" = 0 ] && T=0.000002
$SOCAT -T "$T" pipe pipe
}
# time in microseconds to wait in some situations
if ! type usleep >/dev/null 2>&1 ||
usleep 0 2>&1 |grep -q deprecated; then
usleep () {
local n="$1"
case "$n" in
*???????) S="${n%??????}"; uS="${n:${#n}-6}" ;;
*) S=0; uS="00000$n"; uS="${uS:${#uS}-6}" ;;
esac
$SOCAT -T $S.$uS pipe pipe
}
fi
#USLEEP=usleep
if type ping6 >/dev/null 2>&1; then
PING6=ping6
else
PING6="ping -6"
fi
F_n="%3d" # format string for test numbers
export LC_ALL=C # for timestamps format...
export LANG=C
export LANGUAGE=C # knoppix
case "$UNAME" in
HP-UX|OSF1)
echo "$SOCAT -u stdin stdout" >cat.sh
chmod a+x cat.sh
CAT=./cat.sh
;;
SunOS)
# /usr/bin/tr doesn't handle the a-z range syntax (needs [a-z]), use
# /usr/xpg4/bin/tr instead
alias tr=/usr/xpg4/bin/tr
;;
*)
CAT=cat
;;
esac
case "$UNAME" in
#HP-UX)
# # on HP-UX, the default options (below) hang some tests (former 14, 15)
# PTYOPTS=
# PTYOPTS2=
# ;;
*)
PTYOPTS="echo=0,opost=0"
#PTYOPTS2="raw,echo=0"
PTYOPTS2="cfmakeraw"
#PTYOPTS2="rawer"
;;
esac
# for some tests we need an unprivileged user id to su to
if [ "$SUDO_USER" ]; then
SUBSTUSER="$SUDO_USER"
else
SUBSTUSER="$(grep -v '^[^:]*:^[^:]*:0:' /etc/passwd |tail -n 1 |cut -d: -f1)"
fi
if type ip >/dev/null 2>&1; then
if ip -V |grep -q "^ip utility, iproute2-"; then
IP=$(type -p ip)
else
unset IP
fi
fi
if type ss >/dev/null 2>&1; then
if ss -V |grep -q "^ss utility, iproute2-"; then
SS=$(type -p ss)
else
unset SS
fi
fi
if [ -z "$SS" ]; then
# non-root users might miss ifconfig in their path
case "$UNAME" in
AIX) IFCONFIG=/usr/sbin/ifconfig ;;
FreeBSD) IFCONFIG=/sbin/ifconfig ;;
HP-UX) IFCONFIG=/usr/sbin/ifconfig ;;
Linux) IFCONFIG=/sbin/ifconfig ;;
NetBSD)IFCONFIG=/sbin/ifconfig ;;
OpenBSD)IFCONFIG=/sbin/ifconfig ;;
OSF1) IFCONFIG=/sbin/ifconfig ;;
SunOS) IFCONFIG=/sbin/ifconfig ;;
Darwin)IFCONFIG=/sbin/ifconfig ;;
DragonFly) IFCONFIG=/sbin/ifconfig ;;
*) IFCONFIG=/sbin/ifconfig ;;
esac
fi
# need output like "644"
case "$UNAME" in
Linux) fileperms() { stat -L --print "%a\n" "$1" 2>/dev/null; } ;;
FreeBSD) fileperms() { stat -L -x "$1" |grep ' Mode:' |sed 's/.* Mode:[[:space:]]*([0-9]\([0-7][0-7][0-7]\).*/\1/'; } ;;
*) fileperms() {
local p s=0 c
p="$(ls -l -L "$1" |awk '{print($1);}')"
p="${p:1:9}"
while [ "$p" ]; do c=${p:0:1}; p=${p:1}; [ "x$c" == x- ]; let "s=2*s+$?"; done
printf "%03o\n" $s;
} ;;
esac
# need user (owner) of filesystem entry
case "$UNAME" in
Linux) fileuser() { stat -L --print "%U\n" "$tsock" 2>/dev/null; } ;;
FreeBSD) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
*) fileuser() { ls -l test.sh |awk '{print($3);}'; } ;;
esac
if2addr4() {
local IF="$1"
if [ "$IP" ]; then
$IP address show dev $IF |grep "inet " |sed -e "s/.*inet //" -e "s/ .*//"
else
$IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}' |cut -d: -f2
fi
}
if2bc4() {
local IF="$1"
if [ "$IP" ]; then
$IP address show dev $IF |grep ' inet .* brd ' |awk '{print($4);}'
else
$IFCONFIG $IF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}'
fi
}
# for some tests we need a second local IPv4 address
case "$UNAME" in
Linux)
if [ "$IP" ]; then
BROADCASTIF=$($IP r get 8.8.8.8 |grep ' dev ' |sed 's/.*\<dev[[:space:]][[:space:]]*\([a-z0-9][a-z0-9]*\).*/\1/')
else
BROADCASTIF=$(route -n |grep '^0.0.0.0 ' |awk '{print($8);}')
fi
[ -z "$BROADCASTIF" ] && BROADCASTIF=eth0
SECONDADDR=127.1.0.1
SECONDMASK=255.255.0.0
BCADDR=127.255.255.255
BCIFADDR=$(if2addr4 $BROADCASTIF) ;;
FreeBSD|NetBSD|OpenBSD)
MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
BROADCASTIF="$MAINIF"
SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
BCIFADDR="$SECONDADDR"
BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
HP-UX)
MAINIF=lan0 # might use "netstat -ni" for this
BROADCASTIF="$MAINIF"
SECONDADDR=$($IFCONFIG $MAINIF |tail -n 1 |awk '{print($2);}')
BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
SunOS)
MAINIF=$($IFCONFIG -a |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
BROADCASTIF="$MAINIF"
#BROADCASTIF=hme0
#BROADCASTIF=eri0
#SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
#BCIFADDR="$SECONDADDR"
#BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}')
;;
DragonFly)
MAINIF=$($IFCONFIG -a |grep -v ^lp |grep '^[a-z]' |grep -v '^lo0: ' |head -1 |cut -d: -f1)
BROADCASTIF="$MAINIF"
SECONDADDR=$($IFCONFIG $BROADCASTIF |grep 'inet ' |awk '{print($2);}')
BCIFADDR="$SECONDADDR"
BCADDR=$($IFCONFIG $BROADCASTIF |grep 'broadcast ' |sed 's/.*broadcast/broadcast/' |awk '{print($2);}') ;;
#AIX|FreeBSD|Solaris)
*)
SECONDADDR=$(expr "$($IFCONFIG -a |grep 'inet ' |fgrep -v ' 127.0.0.1 ' |head -n 1)" : '.*inet \([0-9.]*\) .*')
;;
esac
# for generic sockets we need this address in hex form
if [ "$SECONDADDR" ]; then
SECONDADDRHEX="$(printf "%02x%02x%02x%02x\n" $(echo "$SECONDADDR" |tr '.' '
'))"
fi
# for some tests we need a second local IPv6 address
case "$UNAME" in
Linux) if [ "$IP" ]; then
SECONDIP6ADDR=$(expr "$($IP address |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet6 \([0-9a-f:][0-9a-f:]*\)/.*')
else
SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
fi ;;
*)
SECONDIP6ADDR=$(expr "$($IFCONFIG -a |grep 'inet6 ' |fgrep -v ' ::1/128 '| head -n 1)" : '.*inet \([0-9.]*\) .*')
;;
esac
if [ -z "$SECONDIP6ADDR" ]; then
# case "$TESTS" in
# *%root2%*) $IFCONFIG eth0 ::2/128
# esac
SECONDIP6ADDR="$LOCALHOST6"
else
SECONDIP6ADDR="[$SECONDIP6ADDR]"
fi
TRUE=$(type true)
#E=-e # Linux
if [ $(echo "x\c") = "x" ]; then E=""
elif [ $(echo -e "x\c") = "x" ]; then E="-e"
else
echo "cannot suppress trailing newline on echo" >&2
exit 1
fi
ECHO="echo $E"
PRINTF="printf"
case "$TERM" in
vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color|screen)
# there are different behaviours of printf (and echo)
# on some systems, echo behaves different than printf...
if [ $($PRINTF "\0101") = "A" ]; then
RED="\0033[31m"
GREEN="\0033[32m"
YELLOW="\0033[33m"
# if [ "$UNAME" = SunOS ]; then
# NORMAL="\0033[30m"
# else
NORMAL="\0033[39m"
# fi
else
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
# if [ "$UNAME" = SunOS ]; then
# NORMAL="\033[30m"
# else
NORMAL="\033[39m"
# fi
fi
OK="${GREEN}OK${NORMAL}"
FAILED="${RED}FAILED${NORMAL}"
NO_RESULT="${YELLOW}NO RESULT${NORMAL}"
;;
*) OK="OK"
FAILED="FAILED"
NO_RESULT="NO RESULT"
;;
esac
if [ -x /usr/xpg4/bin/id ]; then
# SunOS has rather useless tools in its default path
PATH="/usr/xpg4/bin:$PATH"
fi
OPENSSL_S_CLIENT_4=
OPENSSL_S_CLIENT_DTLS=
init_openssl_s_client () {
if openssl s_client -help 2>&1 |grep -q ' -4 '; then
OPENSSL_S_CLIENT_4="-4"
else
OPENSSL_S_CLIENT_4=" "
fi
if openssl s_client -help 2>&1 | grep -q ' -dtls '; then
OPENSSL_S_CLIENT_DTLS=-dtls
else
OPENSSL_S_CLIENT_DTLS=-dtls1
fi
}
OPENSSL_S_SERVER_4=
OPENSSL_S_SERVER_DTLS=
OPENSSL_S_SERVER_NO_IGN_EOF=
init_openssl_s_server () {
if openssl s_server -help 2>&1 |grep -q ' -4 '; then
OPENSSL_S_SERVER_4="-4"
else
OPENSSL_S_SERVER_4=" "
fi
if openssl s_server -help 2>&1 | grep -q ' -dtls '; then
OPENSSL_S_SERVER_DTLS="-dtls"
else
OPENSSL_S_SERVER_DTLS="-dtls1"
fi
if openssl s_server -help 2>&1 | grep -q ' -no-ign_eof '; then
OPENSSL_S_SERVER_NO_IGN_EOF="-no-ign_eof"
else
OPENSSL_S_SERVER_NO_IGN_EOF=" "
fi
}
[ -z "$TESTS" ] && TESTS="consistency functions filan"
# use '%' as separation char
TESTS="%$(echo "$TESTS" |tr ' ' '%')%"
[ -z "$USER" ] && USER="$LOGNAME" # HP-UX
if [ -z "$TMPDIR" ]; then
if [ -z "$TMP" ]; then
TMP=/tmp
fi
TMPDIR="$TMP"
fi
TD="$TMPDIR/$USER/$$"; td="$TD"
rm -rf "$TD" || (echo "cannot rm $TD" >&2; exit 1)
mkdir -p "$TD"
#trap "rm -r $TD" 0 3
echo "Using temp directory $TD"
case "$TESTS" in
*%consistency%*)
# test if addresses are sorted alphabetically:
$ECHO "testing if address array is sorted...\c"
TF="$TD/socat-q"
IFS="$($ECHO ' \n\t')"
$SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x y; do echo "$x"; done >"$TF"
$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"
if [ -s "$TF-diff" ]; then
$ECHO "\n*** address array is not sorted. Wrong entries:" >&2
cat "$TD/socat-q-diff" >&2
exit 1
else
echo " ok"
fi
#/bin/rm "$TF"
#/bin/rm "$TF-diff"
esac
case "$TESTS" in
*%consistency%*)
# test if address options array ("optionnames") is sorted alphabetically:
$ECHO "testing if address options are sorted...\c"
TF="$TD/socat-qq"
$SOCAT -??? |sed '1,/opt:/ d' |awk '{print($1);}' >"$TF"
LC_ALL=C sort "$TF" |diff "$TF" - >"$TF-diff"
if [ -s "$TF-diff" ]; then
$ECHO "\n*** option array is not sorted. Wrong entries:" >&2
cat "$TD/socat-qq-diff" >&2
exit 1
else
echo " ok"
fi
/bin/rm "$TF"
/bin/rm "$TF-diff"
esac
#==============================================================================
case "$TESTS" in
*%options%*)
# inquire which options are available
OPTS_ANY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*ANY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_BLK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*BLK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_CHILD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHILD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_CHR=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*CHR' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_DEVICE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*DEVICE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_EXEC=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*EXEC' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_FD=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FD' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_FIFO=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FIFO' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_FORK=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*FORK' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_LISTEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*LISTEN' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_NAMED=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*NAMED' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_OPEN=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPEN[^S]' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_PARENT=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PARENT' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_READLINE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*READLINE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_RETRY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RETRY' |awk '{print($1);}' |grep -v forever|xargs echo |tr ' ' ',')
OPTS_RANGE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*RANGE' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_FILE=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*REG' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_UNIX=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UNIX' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_SOCKET=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKET' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_TERMIOS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TERMIOS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_IP4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_IP6=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*IP6' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_TCP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*TCP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_UDP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*UDP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_SOCKS4=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*SOCKS4' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_PROCESS=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PROCESS' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_OPENSSL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*OPENSSL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_PTY=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*PTY' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_HTTP=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*HTTP' |awk '{print($1);}' |xargs echo |tr ' ' ',')
OPTS_APPL=$($SOCAT -?? |sed '1,/opt:/ d' |egrep 'groups=([A-Z]+,)*APPL' |awk '{print($1);}' |xargs echo |tr ' ' ',')
# find user ids to setown to; non-root only can setown to itself
if [ $(id -u) = 0 ]; then
# up to now, it is not a big problem when these do not exist
_UID=nobody
_GID=staff
else
_UID=$(id -u)
_GID=$(id -g)
fi
# some options require values; here we try to replace these bare options with
# valid forms.
filloptionvalues() {
local OPTS=",$1,"
#
case "$OPTS" in
*,umask,*) OPTS=$(echo "$OPTS" |sed "s/,umask,/,umask=0026,/g");;
esac
case "$OPTS" in
*,user,*) OPTS=$(echo "$OPTS" |sed "s/,user,/,user=$_UID,/g");;
esac
case "$OPTS" in
*,user-early,*) OPTS=$(echo "$OPTS" |sed "s/,user-early,/,user-early=$_UID,/g");;
esac
case "$OPTS" in
*,user-late,*) OPTS=$(echo "$OPTS" |sed "s/,user-late,/,user-late=$_UID,/g");;
esac
case "$OPTS" in
*,owner,*) OPTS=$(echo "$OPTS" |sed "s/,owner,/,owner=$_UID,/g");;
esac
case "$OPTS" in
*,uid,*) OPTS=$(echo "$OPTS" |sed "s/,uid,/,uid=$_UID,/g");;
esac
case "$OPTS" in
*,uid-l,*) OPTS=$(echo "$OPTS" |sed "s/,uid-l,/,uid-l=$_UID,/g");;
esac
case "$OPTS" in
*,setuid,*) OPTS=$(echo "$OPTS" |sed "s/,setuid,/,setuid=$_UID,/g");;
esac
case "$OPTS" in
*,group,*) OPTS=$(echo "$OPTS" |sed "s/,group,/,group=$_GID,/g");;
esac
case "$OPTS" in
*,group-early,*) OPTS=$(echo "$OPTS" |sed "s/,group-early,/,group-early=$_GID,/g");;
esac
case "$OPTS" in
*,group-late,*) OPTS=$(echo "$OPTS" |sed "s/,group-late,/,group-late=$_GID,/g");;
esac
case "$OPTS" in
*,gid,*) OPTS=$(echo "$OPTS" |sed "s/,gid,/,gid=$_GID,/g");;
esac
case "$OPTS" in
*,gid-l,*) OPTS=$(echo "$OPTS" |sed "s/,gid-l,/,gid-l=$_GID,/g");;
esac
case "$OPTS" in
*,setgid,*) OPTS=$(echo "$OPTS" |sed "s/,setgid,/,setgid=$_GID,/g");;
esac
case "$OPTS" in
*,mode,*) OPTS=$(echo "$OPTS" |sed "s/,mode,/,mode=0700,/g");;
esac
case "$OPTS" in
*,perm,*) OPTS=$(echo "$OPTS" |sed "s/,perm,/,perm=0700,/g");;
esac
case "$OPTS" in
*,perm-early,*) OPTS=$(echo "$OPTS" |sed "s/,perm-early,/,perm-early=0700,/g");;
esac
case "$OPTS" in
*,perm-late,*) OPTS=$(echo "$OPTS" |sed "s/,perm-late,/,perm-late=0700,/g");;
esac
case "$OPTS" in
*,path,*) OPTS=$(echo "$OPTS" |sed "s/,path,/,path=.,/g");;
esac
# SOCKET
case "$OPTS" in
*,bind,*) OPTS=$(echo "$OPTS" |sed "s/,bind,/,bind=:,/g");;
esac
case "$OPTS" in
*,linger,*) OPTS=$(echo "$OPTS" |sed "s/,linger,/,linger=2,/g");;
esac
case "$OPTS" in
*,connect-timeout,*) OPTS=$(echo "$OPTS" |sed "s/,connect-timeout,/,connect-timeout=1,/g");;
esac
# IP
case "$OPTS" in
*,ipoptions,*) OPTS=$(echo "$OPTS" |sed "s|,ipoptions,|,ipoptions=x01,|g");;
esac
case "$OPTS" in
*,pf,*) OPTS=$(echo "$OPTS" |sed "s|,pf,|,pf=ip4,|g");;
esac
case "$OPTS" in
*,range,*) OPTS=$(echo "$OPTS" |sed "s|,range,|,range=127.0.0.1/32,|g");;
esac
case "$OPTS" in
*,if,*) OPTS=$(echo "$OPTS" |sed "s/,if,/,if=$INTERFACE,/g");;
esac
# PTY
case "$OPTS" in
*,pty-interval,*) OPTS=$(echo "$OPTS" |sed "s/,pty-interval,/,pty-interval=$INTERFACE,/g");;
esac
# RETRY
case "$OPTS" in
*,interval,*) OPTS=$(echo "$OPTS" |sed "s/,interval,/,interval=1,/g");;
esac
# READLINE
case "$OPTS" in
*,history,*) OPTS=$(echo "$OPTS" |sed "s/,history,/,history=.history,/g");;
esac
case "$OPTS" in
*,noecho,*) OPTS=$(echo "$OPTS" |sed "s/,noecho,/,noecho=password,/g");;
esac
case "$OPTS" in
*,prompt,*) OPTS=$(echo "$OPTS" |sed "s/,prompt,/,prompt=CMD,/g");;
esac
# IPAPP
case "$OPTS" in
*,sp,*) OPTS=$(echo "$OPTS" |sed "s/,sp,/,sp=$SOURCEPORT,/g");;
esac
# OPENSSL
case "$OPTS" in
*,ciphers,*) OPTS=$(echo "$OPTS" |sed "s/,ciphers,/,ciphers=NULL,/g");;
esac
case "$OPTS" in
*,method,*) OPTS=$(echo "$OPTS" |sed "s/,method,/,method=SSLv3,/g");;
esac
case "$OPTS" in
*,cafile,*) OPTS=$(echo "$OPTS" |sed "s/,cafile,/,cafile=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,capath,*) OPTS=$(echo "$OPTS" |sed "s/,capath,/,capath=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,cert,*) OPTS=$(echo "$OPTS" |sed "s/,cert,/,cert=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,key,*) OPTS=$(echo "$OPTS" |sed "s/,key,/,key=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,dh,*) OPTS=$(echo "$OPTS" |sed "s/,dh,/,dh=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,egd,*) OPTS=$(echo "$OPTS" |sed "s/,egd,/,egd=/tmp/hugo,/g");;
esac
case "$OPTS" in
*,compress,*) OPTS=$(echo "$OPTS" |sed "s/,compress,/,compress=none,/g");;
esac
# PROXY
case "$OPTS" in
*,proxyauth,*) OPTS=$(echo "$OPTS" |sed "s/,proxyauth,/,proxyauth=user:pass,/g");;
esac
case "$OPTS" in
*,proxyport,*) OPTS=$(echo "$OPTS" |sed "s/,proxyport,/,proxyport=3128,/g");;
esac
case "$OPTS" in
*,link,*) OPTS=$(echo "$OPTS" |sed "s/,link,/,link=testlink,/g");;
esac
# TCP-WRAPPERS
case "$OPTS" in
*,allow-table,*) OPTS=$(echo "$OPTS" |sed "s|,allow-table,|,allow-table=/tmp/hugo,|g");;
esac
case "$OPTS" in
*,deny-table,*) OPTS=$(echo "$OPTS" |sed "s|,deny-table,|,deny-table=/tmp/hugo,|g");;
esac
case "$OPTS" in
*,tcpwrap-dir,*) OPTS=$(echo "$OPTS" |sed "s|,tcpwrap-dir,|,tcpwrap-dir=/tmp,|g");;
esac
echo $OPTS >&2
expr "$OPTS" : ',\(.*\),'
}
# OPTS_FIFO: nothing yet
# OPTS_CHR: nothing yet
# OPTS_BLK: nothing yet
# OPTS_REG: nothing yet
OPTS_SOCKET=",$OPTS_SOCKET,"
OPTS_SOCKET=$(expr "$OPTS_SOCKET" : ',\(.*\),')
N=1
#------------------------------------------------------------------------------
#method=open
#METHOD=$(echo "$method" |tr a-z A-Z)
#TEST="$METHOD on file accepts all its options"
# echo "### $TEST"
#TF=$TD/file$N
#DA="test$N $(date) $RANDOM"
#OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//')
#for g in $(echo $OPTGROUPS |tr ',' ' '); do
# eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)";
# OPTS="$OPTS,$OPTG";
#done
##echo $OPTS
#
#for o in $(filloptionvalues $OPTS|tr ',' ' '); do
# echo testing if $METHOD accepts option $o
# touch $TF
# $SOCAT $opts -!!$method:$TF,$o /dev/null,ignoreof </dev/null
# rm -f $TF
#done
#------------------------------------------------------------------------------
# test openssl connect
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
pid=$!
for addr in openssl; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
openssl s_server -www -accept $PORT || echo "cannot start s_server" >&2 &
pid=$!
sleep 1
#waittcp4port $PORT
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
# echo $SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
kill $pid
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test proxy connect
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
pid=$!
for addr in proxy; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
# prepare dummy server
$SOCAT tcp-l:$PORT,reuseaddr,crlf exec:"/usr/bin/env bash proxyecho.sh" || echo "cannot start proxyecho.sh" >&2 &
pid=$!
sleep 1
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
# echo $SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$PORT,$o
$SOCAT $opts /dev/null $addr:$LOCALHOST:127.0.0.1:$((PORT+1)),proxyport=$PORT,$o
done
kill $pid 2>/dev/null
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+2))
fi
#------------------------------------------------------------------------------
# test tcp4
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
$SOCAT $opts tcp4-listen:$PORT,reuseaddr,fork,$o echo </dev/null &
pid=$!
for addr in tcp4; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test udp4-connect
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
$SOCAT $opts udp4-listen:$PORT,fork,$o echo </dev/null &
pid=$!
for addr in udp4-connect; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
# echo OPTGROUPS=$OPTGROUPS
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts /dev/null $addr:$LOCALHOST:$PORT,$o
done
done
kill $pid 2>/dev/null
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test tcp4-listen
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
for addr in tcp4-listen; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
pid=$!
$SOCAT /dev/null tcp4:$LOCALHOST:$PORT 2>/dev/null
kill $pid 2>/dev/null
done
done
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------
# test udp4-listen
#set -vx
if true; then
#if false; then
#opts="-s -d -d -d -d"
for addr in udp4-listen; do
ADDR=$(echo "$addr" |tr a-z A-Z)
TEST="$ADDR accepts all its options"
echo "### $TEST"
OPTGROUPS=$($SOCAT -? |fgrep " $addr:" |sed 's/.*=//')
OPTS=
for g in $(echo $OPTGROUPS |tr ',' ' '); do
eval "OPTG=\$OPTS_$(echo $g |tr a-z A-Z)";
OPTS="$OPTS,$OPTG";
done
echo $OPTS
for o in $(filloptionvalues $OPTS|tr ',' ' '); do
echo "testing if $ADDR accepts option $o"
$SOCAT $opts $ADDR:$PORT,reuseaddr,$o echo </dev/null &
pid=$!
$SOCAT /dev/null udp4:$LOCALHOST:$PORT 2>/dev/null
kill $pid 2>/dev/null
done
done
opts=
PORT=$((PORT+1))
fi
#------------------------------------------------------------------------------