-
Notifications
You must be signed in to change notification settings - Fork 2
/
stats.go
42 lines (36 loc) · 890 Bytes
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package stats
import (
"time"
)
type PacketInfo struct {
FIN, SYN, RST, PSH, ACK, URG, ECE, CWR, NS bool
CaptureLength int
Timestamp time.Duration
Dir string
}
func (p *PacketInfo) String() string {
return getDirection(p) + " " + getFlags(p) + p.Timestamp.String()
}
func getDirection(p *PacketInfo) string {
if p.Dir == "client->server" {
return "-->"
}
return "<--"
}
func getFlags(p *PacketInfo) string {
return getElement(&p.FIN, "FIN") +
getElement(&p.SYN, "SYN") +
getElement(&p.RST, "RST") +
getElement(&p.PSH, "PSH") +
getElement(&p.ACK, "ACK") +
getElement(&p.URG, "URG") +
getElement(&p.ECE, "ECE") +
getElement(&p.CWR, "CWR") +
getElement(&p.NS, "NS")
}
func getElement(b *bool, s string) string {
if *b {
return s + " "
}
return "... "
}