-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.go
54 lines (40 loc) · 1.12 KB
/
util.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
43
44
45
46
47
48
49
50
51
52
53
54
package reassembler
import (
"encoding/binary"
"math/big"
"github.com/google/gopacket/layers"
)
func generateKeyIPV4(tcp *layers.TCP, ip *layers.IPv4) string {
IPv4Src := big.NewInt(0)
IPv4Src.SetBytes(ip.SrcIP.To4())
IPv4Dst := big.NewInt(0)
IPv4Dst.SetBytes(ip.DstIP.To4())
spI := big.NewInt(0)
spB := make([]byte, 2)
binary.BigEndian.PutUint16(spB, uint16(tcp.SrcPort))
spI.SetBytes(spB)
dpI := big.NewInt(0)
dpB := make([]byte, 2)
binary.BigEndian.PutUint16(dpB, uint16(tcp.DstPort))
dpI.SetBytes(dpB)
x := IPv4Src.Add(IPv4Src, IPv4Dst)
y := dpI.Add(dpI, spI)
return x.Add(x, y).String()
}
func generateKeyIPV6(tcp *layers.TCP, ip *layers.IPv6) string {
IPv6Src := big.NewInt(0)
IPv6Src.SetBytes(ip.SrcIP.To16())
IPv6IDst := big.NewInt(0)
IPv6IDst.SetBytes(ip.DstIP.To16())
spI := big.NewInt(0)
spB := make([]byte, 2)
binary.BigEndian.PutUint16(spB, uint16(tcp.SrcPort))
spI.SetBytes(spB)
dpI := big.NewInt(0)
dpB := make([]byte, 2)
binary.BigEndian.PutUint16(dpB, uint16(tcp.DstPort))
dpI.SetBytes(dpB)
x := IPv6Src.Add(IPv6Src, IPv6IDst)
y := dpI.Add(dpI, spI)
return x.Add(x, y).String()
}