forked from sandia-minimega/discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arp.go
49 lines (40 loc) · 1.04 KB
/
arp.go
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
// Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
package main
import (
"net"
"github.com/google/gopacket/layers"
)
func IsUnspecifiedMAC(addr net.HardwareAddr) bool {
for _, v := range addr {
if v != 0 {
return false
}
}
return true
}
func (s *State) HandleARP() {
// For now, only care about IPv4
if s.arp.Protocol != layers.EthernetTypeIPv4 {
return
}
srcAddr := net.HardwareAddr(s.arp.SourceHwAddress)
srcIP := net.IP(s.arp.SourceProtAddress)
dstAddr := net.HardwareAddr(s.arp.DstHwAddress)
dstIP := net.IP(s.arp.DstProtAddress)
if s.arp.Operation == layers.ARPReply {
if !dstIP.IsUnspecified() && !IsUnspecifiedMAC(dstAddr) {
s.events <- &EventNeighbor{
HardwareAddr: dstAddr,
IP: dstIP,
}
}
}
if !srcIP.IsUnspecified() && !IsUnspecifiedMAC(srcAddr) {
s.events <- &EventNeighbor{
HardwareAddr: srcAddr,
IP: srcIP,
}
}
}