Debian Codegraph @

packets/tcp.go

raw symbols SCIP
1 package packets
2
3 import (
4 "github.com/google/gopacket/layers"
5 "net"
6 )
7
8 func NewTCPSyn(from net.IP, from_hw net.HardwareAddr, to net.IP, to_hw net.HardwareAddr, srcPort int, dstPort int) (error, []byte) {
9 from4 := from.To4()
10 to4 := to.To4()
11
12 if from4 != nil && to4 != nil {
13 eth := layers.Ethernet{
14 SrcMAC: from_hw,
15 DstMAC: to_hw,
16 EthernetType: layers.EthernetTypeIPv4,
17 }
18 ip4 := layers.IPv4{
19 Protocol: layers.IPProtocolTCP,
20 Version: 4,
21 TTL: 64,
22 SrcIP: from,
23 DstIP: to,
24 }
25 tcp := layers.TCP{
26 SrcPort: layers.TCPPort(srcPort),
27 DstPort: layers.TCPPort(dstPort),
28 SYN: true,
29 }
30 tcp.SetNetworkLayerForChecksum(&ip4)
31
32 return Serialize(&eth, &ip4, &tcp)
33 } else {
34 eth := layers.Ethernet{
35 SrcMAC: from_hw,
36 DstMAC: to_hw,
37 EthernetType: layers.EthernetTypeIPv6,
38 }
39 ip6 := layers.IPv6{
40 Version: 6,
41 NextHeader: layers.IPProtocolTCP,
42 HopLimit: 64,
43 SrcIP: from,
44 DstIP: to,
45 }
46 tcp := layers.TCP{
47 SrcPort: layers.TCPPort(srcPort),
48 DstPort: layers.TCPPort(dstPort),
49 SYN: true,
50 }
51 tcp.SetNetworkLayerForChecksum(&ip6)
52
53 return Serialize(&eth, &ip6, &tcp)
54 }
55 }