refact: minor refactoring to endpoint structure

This commit is contained in:
evilsocket 2018-01-23 17:35:45 +01:00
commit 417a288b42

View file

@ -27,17 +27,25 @@ type Endpoint struct {
LastSeen time.Time `json:"last_seen"` LastSeen time.Time `json:"last_seen"`
} }
func ip2int(ip net.IP) uint32 {
if len(ip) == 16 {
return binary.BigEndian.Uint32(ip[12:16])
}
return binary.BigEndian.Uint32(ip)
}
func NewEndpointNoResolve(ip, mac, name string, bits uint32) *Endpoint { func NewEndpointNoResolve(ip, mac, name string, bits uint32) *Endpoint {
addr := net.ParseIP(ip)
hw, _ := net.ParseMAC(mac) hw, _ := net.ParseMAC(mac)
now := time.Now() now := time.Now()
e := &Endpoint{ e := &Endpoint{
IP: net.ParseIP(ip), IP: addr,
IpAddress: ip,
IpAddressUint32: ip2int(addr),
Net: nil, Net: nil,
HW: hw, HW: hw,
IpAddress: ip,
SubnetBits: bits, SubnetBits: bits,
IpAddressUint32: binary.BigEndian.Uint32(net.ParseIP(ip)[12:16]),
HwAddress: mac, HwAddress: mac,
Hostname: name, Hostname: name,
Vendor: OuiLookup(mac), Vendor: OuiLookup(mac),