new: basic ipv6 support

This commit is contained in:
Simone Margaritelli 2021-04-03 18:42:14 +02:00
parent d0b5c34763
commit bef4c6abaa
8 changed files with 115 additions and 35 deletions

View file

@ -6,24 +6,50 @@ import (
)
func NewTCPSyn(from net.IP, from_hw net.HardwareAddr, to net.IP, to_hw net.HardwareAddr, srcPort int, dstPort int) (error, []byte) {
eth := layers.Ethernet{
SrcMAC: from_hw,
DstMAC: to_hw,
EthernetType: layers.EthernetTypeIPv4,
}
ip4 := layers.IPv4{
Protocol: layers.IPProtocolTCP,
Version: 4,
TTL: 64,
SrcIP: from,
DstIP: to,
}
tcp := layers.TCP{
SrcPort: layers.TCPPort(srcPort),
DstPort: layers.TCPPort(dstPort),
SYN: true,
}
tcp.SetNetworkLayerForChecksum(&ip4)
from4 := from.To4()
to4 := to.To4()
return Serialize(&eth, &ip4, &tcp)
if from4 != nil && to4 != nil {
eth := layers.Ethernet{
SrcMAC: from_hw,
DstMAC: to_hw,
EthernetType: layers.EthernetTypeIPv4,
}
ip4 := layers.IPv4{
Protocol: layers.IPProtocolTCP,
Version: 4,
TTL: 64,
SrcIP: from,
DstIP: to,
}
tcp := layers.TCP{
SrcPort: layers.TCPPort(srcPort),
DstPort: layers.TCPPort(dstPort),
SYN: true,
}
tcp.SetNetworkLayerForChecksum(&ip4)
return Serialize(&eth, &ip4, &tcp)
} else {
eth := layers.Ethernet{
SrcMAC: from_hw,
DstMAC: to_hw,
EthernetType: layers.EthernetTypeIPv6,
}
ip6 := layers.IPv6{
Version: 6,
NextHeader: layers.IPProtocolTCP,
HopLimit: 64,
SrcIP: from,
DstIP: to,
}
tcp := layers.TCP{
SrcPort: layers.TCPPort(srcPort),
DstPort: layers.TCPPort(dstPort),
SYN: true,
}
tcp.SetNetworkLayerForChecksum(&ip6)
return Serialize(&eth, &ip6, &tcp)
}
}