Skip to content

Commit

Permalink
packet data and packet direction data
Browse files Browse the repository at this point in the history
  • Loading branch information
imgurbot12 committed Sep 14, 2017
1 parent a581cf1 commit 99c7ce4
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions iplocation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package goaway2

import "net"

/***Variables***/

//PacketData : packet data containg realvent data from gopacket
type PacketData struct {
SrcIP string
DstIP string
SrcPort int64
DstPort int64
Protocol string
}

//localIPs : a hashmap of local ip-addresses
var localIPs map[string]struct{}

/***Functions***/

//getLocalIPs : return list of local ip-addresses
func getLocalIPs() map[string]struct{} {
// create binary tree for lookup
ips := make(map[string]struct{})
// get ip-addresses from interfaces
ifaces, _ := net.Interfaces()
for _, i := range ifaces {
addrs, _ := i.Addrs()
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok {
if ipnet.IP.To4() != nil {
ips[ipnet.IP.String()] = struct{}{}
}
}
}
}
return ips
}

func init() {
// get all local ip addreses
localIPs = getLocalIPs()
}

/***Methods***/

//(*PacketData).IsInbound : determine if packet is inbound
func (p *PacketData) IsInbound() bool {
_, ok := localIPs[p.SrcIP]
return !ok
}

0 comments on commit 99c7ce4

Please sign in to comment.