mirror of
https://github.com/soypat/lneto.git
synced 2026-09-11 09:09:30 +00:00
fix TCP checksum in internet.StackBasic; more logging
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/soypat/lneto"
|
||||
"github.com/soypat/lneto/ethernet"
|
||||
"github.com/soypat/lneto/internal/ltesto"
|
||||
"github.com/soypat/lneto/ipv4"
|
||||
@@ -114,3 +115,36 @@ func testMoveTCPPacket(t *testing.T, src, dst []byte) {
|
||||
t.Fatalf("payload mismatch %d %d", len(payload), len(tfrm2.Payload()))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPv4TCPChecksum(t *testing.T) {
|
||||
var tcpPackets = [][]byte{
|
||||
{0xc0, 0xff, 0xee, 0x00, 0xde, 0xad, 0x4e, 0x8b, 0x3a, 0xf9, 0xfb, 0x6b, 0x08, 0x00, 0x45, 0x00,
|
||||
0x00, 0x3c, 0x01, 0xbe, 0x40, 0x00, 0x40, 0x06, 0xa3, 0xaa, 0xc0, 0xa8, 0x0a, 0x01, 0xc0, 0xa8,
|
||||
0x0a, 0x02, 0xe7, 0x0a, 0x00, 0x50, 0x40, 0x60, 0xd5, 0xcc, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x02,
|
||||
0xfa, 0xf0, 0x62, 0xbc, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4, 0x04, 0x02, 0x08, 0x0a, 0xbb, 0xac,
|
||||
0x9b, 0xca, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07},
|
||||
{0xc0, 0xff, 0xee, 0x00, 0xde, 0xad, 0x4e, 0x8b, 0x3a, 0xf9, 0xfb, 0x6b, 0x08, 0x00, 0x45, 0x00,
|
||||
0x00, 0x3c, 0xfa, 0xfd, 0x40, 0x00, 0x40, 0x06, 0xaa, 0x6a, 0xc0, 0xa8, 0x0a, 0x01, 0xc0, 0xa8,
|
||||
0x0a, 0x02, 0xe7, 0x0e, 0x00, 0x50, 0x9c, 0xdc, 0xfe, 0x05, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x02,
|
||||
0xfa, 0xf0, 0xde, 0x02, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4, 0x04, 0x02, 0x08, 0x0a, 0xbb, 0xac,
|
||||
0x9b, 0xca, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07},
|
||||
}
|
||||
for _, tcpPacket := range tcpPackets {
|
||||
efrm, _ := ethernet.NewFrame(tcpPacket)
|
||||
ifrm, _ := ipv4.NewFrame(efrm.Payload())
|
||||
tfrm, _ := tcp.NewFrame(ifrm.Payload())
|
||||
wantCRC := ifrm.CRC()
|
||||
gotCRC := ifrm.CalculateHeaderCRC()
|
||||
if wantCRC != gotCRC {
|
||||
t.Errorf("IPv4 CRC miscalculated. want %x, got %x", wantCRC, gotCRC)
|
||||
}
|
||||
wantCRC = tfrm.CRC()
|
||||
var crc lneto.CRC791
|
||||
ifrm.CRCWriteTCPPseudo(&crc)
|
||||
tfrm.CRCWrite(&crc)
|
||||
gotCRC = crc.Sum16()
|
||||
if wantCRC != gotCRC {
|
||||
t.Errorf("TCP CRC miscalculated. want %x, got %x", wantCRC, gotCRC)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user