summary refs log tree commit diff
path: root/Completion/Unix/Command/_arp
blob: 80e829022db739494ac46c883a05afd57898af77 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#compdef arp

local state line expl curcontext="$curcontext" ret=1
typeset -A opt_args
local -a cmds args

flags=( temp pub )
cmds=(
  '(2 3)-a[show entries for all hosts]'
  '(2 -d)-d[delete entry from table]'
  '(-n -v)-s[create an arp entry]'
  '(2 3 -n -v)-f[read multiple entries from file]'
)
args=( '-n[show numeric addresses]' )
vopt='-v[be verbose]'

if (( ${+words[(r)-d]} )) && [[ $OSTYPE = (*bsd|dragonfly|darwin)* ]]; then
  args+=( '(1 *)-a[delete all entries]' )
fi

case $OSTYPE in
  linux*)
    cmds=(
      '(2 * -D --use-device)-a[show entries in BSD style output format]'
      '!(2 * -D --use-device)-e'
      '(2 -n --numeric -D --use-device -H --hw-type)'{-d,--delete}'[delete entry from table]'
      '(-n --numeric)'{-s,--set}'[create an ARP entry]'
      '(2 * -D --use-device)'{-f,--file}'[read multiple entries from file]'
    )
    args=(
      '(-i --device)'{-i+,--device=}'[select an interface]:interface:_net_interfaces'
      '(-D --use-device -a --display -d --delete)'{-D,--use-device}"[use specified interface's hardware address]"
      '(-H --hw-type -d --delete)'{-H+,--hw-type=}'[specify class of entries to check for]:class:(ash ether arcnet pronet ax25 netrom rose dlci fddi hippi irda x25 infiniband eui64)'
      '(* -n --numeric -d --delete -s --set -f --file)'{-n,--numeric}'[show numeric addresses]'
      '(-v --verbose)'{-v,--verbose}'[be verbose]'
    )
    flags+=( netmask )
  ;;
  darwin*|freebsd*|dragonfly*)
    cmds+=( '(-n -v -i)-S[create an arp entry, replacing any existing entry]' )
  ;|
  darwin*|freebsd*)
    args+=( '(-s -Q -f)-i+[select an interface]:interface:_net_interfaces' )
  ;|
  darwin*)
    args+=(
      '(-d -s -S -f)-l[show link-layer reachability information]'
      '(-d -s -S -f)-x[show extended link-layer reachability information]'
    )
    flags+=( reject blackhole only ifscope )
  ;;
  dragonfly*)
    flags+=( only )
    args+=( '-c:cpu' )
  ;;
  netbsd*)
    flags+=( proxy )
    args+=( $vopt )
  ;;
  freebsd*)
    args+=( $vopt )
    flags+=( blackhole reject )
  ;;
  openbsd*)
    args+=(
      '(-a -d -W)-F[overwrite existing entries]'
      '(-W)-V+[select the routing domain]:routing domain'
    )
    cmds+=(
      '(- 1)-W[send the wake on LAN frame]'
    )
    flags+=( permanent )
  ;;
  solaris*) flags+=( trail permanent) ;;
esac

_arguments -C -s -S $args \
  '1: :->hostintable' \
  '2:ethernet address' \
  "*: :->flags" \
  + '(cmds)' $cmds && ret=0

if [[ "$state" = hostintable ]]; then
  if [[ -n $opt_args[(i)-(D|-use-device)] ]]; then
    _wanted interfaces expl interface _net_interfaces && ret=0
  elif [[ -n $opt_args[(i)-(f|-file)] ]]; then
    _files && ret=0
  elif [[ -n $opt_args[(i)-(s|S|-set)] ]]; then
    _hosts && ret=0
  else
    _wanted hosts expl 'host' compadd ${${${(f)"$(${words[1]} -an)"}##[ ?(]#}%%[ )]*} && ret=0
  fi
elif [[ "$state" = flags ]]; then
  if [[ $words[CURRENT-1] = netmask ]]; then
    _message -e netmasks netmask
  elif (( $+opt_args[-W] )) || [[ $words[CURRENT-1] = ifscope ]]; then
    _wanted interfaces expl interface _net_interfaces && ret=0
  else
    _wanted flags expl flag compadd -F line $flags && ret=0
  fi
fi

return ret