about summary refs log tree commit diff
path: root/Completion/BSD/Command/_sockstat
blob: f372fe1b362168e4d6309ef8cd739a6a93fb7e85 (plain) (blame)
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
#compdef sockstat
local -a args protocols
local proto

case $OSTYPE in
  *bsd*)
    args=(
      '-4[show AF_INET (IPv4) sockets]'
      '-6[show AF_INET6 (IPv6) sockets]'
      '-c[show connected sockets]'
      '-l[show listening sockets]'
      '*-p+[specify port number]:port numbers (comma delimited)'
      '-u[show AF_LOCAL (UNIX) sockets]'
    )
  ;|
  freebsd<12->.*)
    args+=(
      '-S[display the protocol stack if applicable]'
      '-U[display the remote UDP encapsulation port number if applicable]'
      '-v[verbose mode]'
      '-w[use wider field size for displaying addresses]'
    )
  ;|
  freebsd<13->.*)
    args+=(
      '-C[display the congestion control module]'
      '-i[display the inp_gencnt]'
      "-n[don't resolve numeric UIDs to user names]"
      '-q[quiet mode, do not print the header line]'
    )
  ;|
  freebsd*)
    for proto in ${${(M)${(f)"$(</etc/protocols)"}##[a-z0-9]*}}; do
      case $proto in
        *\#*)
          protocols+=(${${${(j: :)${(q)=proto}}// *\# /\[}/%/\]})
        ;;
        *)
          protocols+=(${${(j: :)${=proto}}// */})
      esac
    done

    args+=(
      '*-j[show sockets belonging to JID]: : _jails -0 -o jid'
      '-L[exclude loopback]'
      '*-P+[specify protocol]: : _values -s , protocols $protocols'
      '-s[display protocol state if applicable]'
    )
  ;;
  netbsd*)
    args+=(
      '*-f+[only show specified address family]:address family:(inet inet6 local unix)'
      '-n[no symbolic names for addresses/ports]'
    )
  ;;
esac

if (( $#args )); then
  _arguments -s -w : $args
  return
fi

_default