5 # Pretty that we're the shell and that this command could not be
7 if [ "$FAKE_NETSTAT_NOT_FOUND" = "yes" ] ; then
8 echo "sh: ${prog}: command not found" >&2
15 Usage: $prog [ -t | --unix ] [ -n ] [ -a ] [ -l ]
17 A fake netstat stub that prints items depending on the variables
18 FAKE_NETSTAT_TCP_ESTABLISHED, FAKE_TCP_LISTEN,
19 FAKE_NETSTAT_UNIX_LISTEN, depending on command-line options.
21 Note that -n is ignored.
35 # $POSIXLY_CORRECT means that the command passed to onnode can
36 # take options and getopt won't reorder things to make them
37 # options to this script.
38 _temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "tnalh" -l unix -l help -- "$@")
47 -a) all=true ; shift ;;
48 -t) tcp=true ; shift ;;
49 -l) listen=true ; shift ;;
50 --unix) unix=true ; shift ;;
52 -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
58 # If neither -t or --unix specified then print all.
59 $tcp || $unix || { tcp=true ; unix=true ; }
66 echo "Active Internet connections (servers only)"
68 echo "Active Internet connections (servers and established)"
70 echo "Active Internet connections (w/o servers)"
73 echo "Proto Recv-Q Send-Q Local Address Foreign Address State"
75 tcp_fmt="tcp 0 0 %-23s %-23s %s\n"
76 for i in $FAKE_NETSTAT_TCP_ESTABLISHED ; do
79 printf "$tcp_fmt" $src $dst "ESTABLISHED"
81 while read src dst ; do
82 printf "$tcp_fmt" $src $dst "ESTABLISHED"
83 done <"$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
85 if $all || $listen ; then
86 for i in $FAKE_TCP_LISTEN ; do
87 printf "$tcp_fmt" $i "0.0.0.0:*" "LISTEN"
94 echo "Active UNIX domain sockets (servers only)"
96 echo "Active UNIX domain sockets (servers and established)"
98 echo "Active UNIX domain sockets (w/o servers)"
101 echo "Proto RefCnt Flags Type State I-Node Path"
103 unix_fmt="unix 2 [ ACC ] STREAM LISTENING %-8d %s\n"
104 if $all || $listen ; then
105 for i in $FAKE_NETSTAT_UNIX_LISTEN ; do
106 printf "$unix_fmt" 12345 "$i"