8 Usage: $prog -tn state established [ '(' ip-filter ')' ] [ '(' port-filter ')' ]
10 A fake ss stub that prints items depending on the variables
11 FAKE_NETSTAT_TCP_ESTABLISHED and FAKE_NETSTAT_TCP_ESTABLISHED_FILE.
13 Note that "-tn state established" must be given.
19 if [ "$1" != "-tn" -o "$2" != "state" -o "$3" != "established" ] ; then
25 # Check if socket has matches in both ok_ips and ok_ports
35 if [ "$ok_ports" != "|" -a "${ok_ports#*|${port}|}" = "$ok_ports" ] ; then
38 if [ "$ok_ips" != "|" -a "${ok_ips#*|${ip}|}" = "$ok_ips" ] ; then
47 echo "Recv-Q Send-Q Local Address:Port Peer Address:Port"
49 # Very limited implementation:
50 # We only expect to find || inside parentheses
51 # We don't expect to see && - it is implied by juxtaposition
52 # Operator for port comparison is ignored and assumed to be ==
54 # Build lists of source ports and source IP addresses where each
55 # entry is surrounded by '|' characters. These lists can be
56 # easily "searched" using the POSIX prefix and suffix removal
62 while [ -n "$1" ] ; do
64 \() in_parens=true ; shift ;;
65 \)) in_parens=false ; shift ;;
66 \|\|) if ! $in_parens ; then usage ; fi ; shift ;;
67 sport) p="${3#:}" ; sports="${sports}${p}|" ; shift 3 ;;
68 src) ip="${2#\[}" ; ip="${ip%\]}" ; srcs="${srcs}${ip}|" ; shift 2 ;;
73 for i in $FAKE_NETSTAT_TCP_ESTABLISHED ; do
76 if filter_socket "$srcs" "$sports" "$src" ; then
77 echo 0 0 "$src" "$dst"
81 if [ -z "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE" ] ; then
84 while read src dst ; do
85 if filter_socket "$srcs" "$sports" "$src" ; then
86 echo 0 0 "$src" "$dst"
88 done <"$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
91 # Yes, lose the quoting so we can do a hacky parsing job