up
Some checks failed
Go CI / test (push) Has been cancelled

This commit is contained in:
Dev
2025-09-13 12:30:01 +03:00
commit 4d51c65060
14 changed files with 1227 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package fingerprint
import (
"net"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)
// BuildSYNPacket creates a minimal TCP SYN packet for the given source and destination ports.
// The packet is not sent; it is used only to demonstrate integration with gopacket.
func BuildSYNPacket(srcIP string, dstIP string, srcPort, dstPort uint16) ([]byte, error) {
ip := &layers.IPv4{
SrcIP: net.ParseIP(srcIP).To4(),
DstIP: net.ParseIP(dstIP).To4(),
Version: 4,
Protocol: layers.IPProtocolTCP,
}
tcp := &layers.TCP{
SrcPort: layers.TCPPort(srcPort),
DstPort: layers.TCPPort(dstPort),
SYN: true,
Seq: 1105024978,
Window: 14600,
}
if err := tcp.SetNetworkLayerForChecksum(ip); err != nil {
return nil, err
}
buf := gopacket.NewSerializeBuffer()
opts := gopacket.SerializeOptions{
FixLengths: true,
ComputeChecksums: true,
}
if err := gopacket.SerializeLayers(buf, opts, ip, tcp); err != nil {
return nil, err
}
return buf.Bytes(), nil
}