mirror of
https://github.com/evilsocket/opensnitch.git
synced 2025-03-04 08:34:40 +01:00
Merge pull request #229 from DarkSpyro003/master
Fixes #228: Parse IP and port to uint
This commit is contained in:
commit
0316580e92
4 changed files with 19 additions and 19 deletions
|
@ -18,9 +18,9 @@ import (
|
||||||
type Connection struct {
|
type Connection struct {
|
||||||
Protocol string
|
Protocol string
|
||||||
SrcIP net.IP
|
SrcIP net.IP
|
||||||
SrcPort int
|
SrcPort uint
|
||||||
DstIP net.IP
|
DstIP net.IP
|
||||||
DstPort int
|
DstPort uint
|
||||||
DstHost string
|
DstHost string
|
||||||
Entry *netstat.Entry
|
Entry *netstat.Entry
|
||||||
Process *procmon.Process
|
Process *procmon.Process
|
||||||
|
@ -137,15 +137,15 @@ func (c *Connection) parseDirection() bool {
|
||||||
if layer.LayerType() == layers.LayerTypeTCP {
|
if layer.LayerType() == layers.LayerTypeTCP {
|
||||||
if tcp, ok := layer.(*layers.TCP); ok == true && tcp != nil {
|
if tcp, ok := layer.(*layers.TCP); ok == true && tcp != nil {
|
||||||
c.Protocol = "tcp"
|
c.Protocol = "tcp"
|
||||||
c.DstPort = int(tcp.DstPort)
|
c.DstPort = uint(tcp.DstPort)
|
||||||
c.SrcPort = int(tcp.SrcPort)
|
c.SrcPort = uint(tcp.SrcPort)
|
||||||
ret = true
|
ret = true
|
||||||
}
|
}
|
||||||
} else if layer.LayerType() == layers.LayerTypeUDP {
|
} else if layer.LayerType() == layers.LayerTypeUDP {
|
||||||
if udp, ok := layer.(*layers.UDP); ok == true && udp != nil {
|
if udp, ok := layer.(*layers.UDP); ok == true && udp != nil {
|
||||||
c.Protocol = "udp"
|
c.Protocol = "udp"
|
||||||
c.DstPort = int(udp.DstPort)
|
c.DstPort = uint(udp.DstPort)
|
||||||
c.SrcPort = int(udp.SrcPort)
|
c.SrcPort = uint(udp.SrcPort)
|
||||||
ret = true
|
ret = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,14 @@ import (
|
||||||
type Entry struct {
|
type Entry struct {
|
||||||
Proto string
|
Proto string
|
||||||
SrcIP net.IP
|
SrcIP net.IP
|
||||||
SrcPort int
|
SrcPort uint
|
||||||
DstIP net.IP
|
DstIP net.IP
|
||||||
DstPort int
|
DstPort uint
|
||||||
UserId int
|
UserId int
|
||||||
INode int
|
INode int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEntry(proto string, srcIP net.IP, srcPort int, dstIP net.IP, dstPort int, userId int, iNode int) Entry {
|
func NewEntry(proto string, srcIP net.IP, srcPort uint, dstIP net.IP, dstPort uint, userId int, iNode int) Entry {
|
||||||
return Entry{
|
return Entry{
|
||||||
Proto: proto,
|
Proto: proto,
|
||||||
SrcIP: srcIP,
|
SrcIP: srcIP,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/evilsocket/opensnitch/daemon/log"
|
"github.com/evilsocket/opensnitch/daemon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FindEntry(proto string, srcIP net.IP, srcPort int, dstIP net.IP, dstPort int) *Entry {
|
func FindEntry(proto string, srcIP net.IP, srcPort uint, dstIP net.IP, dstPort uint) *Entry {
|
||||||
entries, err := Parse(proto)
|
entries, err := Parse(proto)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warning("Error while searching for %s netstat entry: %s", proto, err)
|
log.Warning("Error while searching for %s netstat entry: %s", proto, err)
|
||||||
|
|
|
@ -36,32 +36,32 @@ func decToInt(n string) int {
|
||||||
return int(d)
|
return int(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hexToInt(h string) int {
|
func hexToInt(h string) uint {
|
||||||
d, err := strconv.ParseInt(h, 16, 64)
|
d, err := strconv.ParseUint(h, 16, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error while parsing %s to int: %s", h, err)
|
log.Fatal("Error while parsing %s to int: %s", h, err)
|
||||||
}
|
}
|
||||||
return int(d)
|
return uint(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func hexToInt2(h string) (int, int) {
|
func hexToInt2(h string) (uint, uint) {
|
||||||
if len(h) > 16 {
|
if len(h) > 16 {
|
||||||
d, err := strconv.ParseInt(h[:16], 16, 64)
|
d, err := strconv.ParseUint(h[:16], 16, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error while parsing %s to int: %s", h[16:], err)
|
log.Fatal("Error while parsing %s to int: %s", h[16:], err)
|
||||||
}
|
}
|
||||||
d2, err := strconv.ParseInt(h[16:], 16, 64)
|
d2, err := strconv.ParseUint(h[16:], 16, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error while parsing %s to int: %s", h[16:], err)
|
log.Fatal("Error while parsing %s to int: %s", h[16:], err)
|
||||||
}
|
}
|
||||||
return int(d), int(d2)
|
return uint(d), uint(d2)
|
||||||
} else {
|
} else {
|
||||||
d, err := strconv.ParseInt(h, 16, 64)
|
d, err := strconv.ParseUint(h, 16, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error while parsing %s to int: %s", h[16:], err)
|
log.Fatal("Error while parsing %s to int: %s", h[16:], err)
|
||||||
}
|
}
|
||||||
return int(d), 0
|
return uint(d), 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue