-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
packet data and packet direction data
- Loading branch information
1 parent
a581cf1
commit 99c7ce4
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |