From 417a288b42b44c23047fbe21bf47d6a5b76fc904 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Tue, 23 Jan 2018 17:35:45 +0100 Subject: [PATCH] refact: minor refactoring to endpoint structure --- net/endpoint.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/net/endpoint.go b/net/endpoint.go index f31f4913..c628cd2d 100644 --- a/net/endpoint.go +++ b/net/endpoint.go @@ -27,17 +27,25 @@ type Endpoint struct { 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 { + addr := net.ParseIP(ip) hw, _ := net.ParseMAC(mac) now := time.Now() e := &Endpoint{ - IP: net.ParseIP(ip), + IP: addr, + IpAddress: ip, + IpAddressUint32: ip2int(addr), Net: nil, HW: hw, - IpAddress: ip, SubnetBits: bits, - IpAddressUint32: binary.BigEndian.Uint32(net.ParseIP(ip)[12:16]), HwAddress: mac, Hostname: name, Vendor: OuiLookup(mac),