MCPcopy Create free account
hub / github.com/SamNet-dev/snix / synPacket

Function synPacket

core/engine/packet_test.go:10–33  ·  view source on GitHub ↗

handcrafted IPv4+TCP SYN packet for testing the parser. Fields chosen to be distinct so any byte-order mistake surfaces immediately.

(srcIP, dstIP [4]byte, srcPort, dstPort uint16, seq uint32)

Source from the content-addressed store, hash-verified

8// handcrafted IPv4+TCP SYN packet for testing the parser. Fields chosen to
9// be distinct so any byte-order mistake surfaces immediately.
10func synPacket(srcIP, dstIP [4]byte, srcPort, dstPort uint16, seq uint32) []byte {
11 ipHL, tcpHL := 20, 20
12 total := ipHL + tcpHL
13 b := make([]byte, total)
14 b[0] = 0x45
15 binary.BigEndian.PutUint16(b[2:4], uint16(total))
16 binary.BigEndian.PutUint16(b[4:6], 0x1234) // ident
17 b[8] = 64
18 b[9] = 6
19 copy(b[12:16], srcIP[:])
20 copy(b[16:20], dstIP[:])
21 // Valid IP checksum (important: parser does not verify but builder does).
22 binary.BigEndian.PutUint16(b[10:12], checksum(b[:ipHL]))
23
24 tcp := b[ipHL:]
25 binary.BigEndian.PutUint16(tcp[0:2], srcPort)
26 binary.BigEndian.PutUint16(tcp[2:4], dstPort)
27 binary.BigEndian.PutUint32(tcp[4:8], seq)
28 binary.BigEndian.PutUint32(tcp[8:12], 0)
29 tcp[12] = 5 << 4
30 tcp[13] = flagSYN
31 binary.BigEndian.PutUint16(tcp[14:16], 0x0800)
32 return b
33}
34
35func TestParseSYN(t *testing.T) {
36 src := [4]byte{10, 0, 0, 1}

Callers 3

TestParseSYNFunction · 0.85

Calls 1

checksumFunction · 0.85

Tested by

no test coverage detected