1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-08 04:58:40 +03:00
Martin Schwenke 506be3cb26 Tests: eventscripts and onnode tests use stubs/ subdirectory instead of bin/.
This sets up a more useful convention and avoids future .gitignore
problems.

Signed-off-by: Martin Schwenke <martin@meltin.net>

(This used to be ctdb commit 58c696dc600f1073e693930da061776b6fb199f2)
2011-08-08 13:38:07 +10:00

100 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
prog="netstat"
usage ()
{
cat >&2 <<EOF
Usage: $prog [ -t | --unix ] [ -n ] [ -a ] [ -l ]
A fake netstat stub that prints items depending on the variables
FAKE_NETSTAT_TCP_ESTABLISHED, FAKE_NETSTAT_TCP_LISTEN,
FAKE_NETSTAT_UNIX_LISTEN, depending on command-line options.
Note that -n is ignored.
EOF
exit 1
}
# Defaults.
tcp=false
unix=false
all=false
listen=false
parse_options ()
{
# $POSIXLY_CORRECT means that the command passed to onnode can
# take options and getopt won't reorder things to make them
# options to this script.
_temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "tnalh" -l unix -l help -- "$@")
[ $? != 0 ] && usage
eval set -- "$_temp"
while true ; do
case "$1" in
-n) shift ;;
-a) all=true ; shift ;;
-t) tcp=true ; shift ;;
-l) listen=true ; shift ;;
--unix) unix=true ; shift ;;
--) shift ; break ;;
-h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
esac
done
[ $# -gt 0 ] && usage
# If neither -t or --unix specified then print all.
$tcp || $unix || { tcp=true ; unix=true ; }
}
parse_options "$@"
if $tcp ; then
if $listen ; then
echo "Active Internet connections (servers only)"
elif $all ; then
echo "Active Internet connections (servers and established)"
else
echo "Active Internet connections (w/o servers)"
fi
echo "Proto Recv-Q Send-Q Local Address Foreign Address State"
tcp_fmt="tcp 0 0 %-23s %-23s %s\n"
for i in $FAKE_NETSTAT_TCP_ESTABLISHED ; do
src="${i%|*}"
dst="${i#*|}"
printf "$tcp_fmt" $src $dst "ESTABLISHED"
done
if $all || $listen ; then
for i in $FAKE_NETSTAT_TCP_LISTEN ; do
printf "$tcp_fmt" $i "0.0.0.0:*" "LISTEN"
done
fi
fi
if $unix ; then
if $listen ; then
echo "Active UNIX domain sockets (servers only)"
elif $all ; then
echo "Active UNIX domain sockets (servers and established)"
else
echo "Active UNIX domain sockets (w/o servers)"
fi
echo "Proto RefCnt Flags Type State I-Node Path"
unix_fmt="unix 2 [ ACC ] STREAM LISTENING %-8d %s\n"
if $all || $listen ; then
for i in $FAKE_NETSTAT_UNIX_LISTEN ; do
printf "$unix_fmt" 12345 "$i"
done
fi
fi