forked from lsof-org/lsof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcase-20-udp-socket-state.bash
More file actions
executable file
·44 lines (36 loc) · 1004 Bytes
/
case-20-udp-socket-state.bash
File metadata and controls
executable file
·44 lines (36 loc) · 1004 Bytes
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
#!/bin/bash
source tests/common.bash
if [ -z "$(nc -h 2>&1 | grep '\s\-4')" ]; then
echo "nc does not support -4 option, skipping" >> $report
exit 77
fi
if [ -z "$(nc -h 2>&1 | grep '\s\-u')" ]; then
echo "nc does not support -u option, skipping" >> $report
exit 77
fi
# Use sleep as stdin to keep nc alive without flooding data.
# /dev/zero causes "Message too long" with ncat (nmap) on UDP.
sleep 60 | nc -l -u -4 127.0.0.1 10001 > /dev/null &
server=$!
sleep 1
sleep 60 | nc -u -4 127.0.0.1 10001 > /dev/null &
client=$!
sleep 1
killBoth()
{
kill -9 $1
sleep 1
kill -9 $2
} 2> /dev/null > /dev/null
fclient=/tmp/${name}-client-$$
$lsof -n -P -p $client -a -i UDP > $fclient
if ! cat $fclient | grep -q "UDP.*127.0.0.1:.*->127.0.0.1:10001 (ESTABLISHED)"; then
echo "connected UDP socket missing ESTABLISHED state" >> $report
cat $fclient >> $report
killBoth $client $server
rm -f $fclient
exit 1
fi
rm -f $fclient
killBoth $client $server
exit 0