func TestUnpackOptions(t *testing.T) { var p tcp.Packet var b packet.Buffer b.Init(test_options) err := p.Unpack(&b) if err != nil { t.Fatalf("Error unpacking: %s", err) } if len(p.Options) != 4 { t.Fatalf("Options number mismatch: %d", len(p.Options)) } if p.Options[0].Type != tcp.MSS { t.Fatalf("Option MSS mismatch: %x", p.Options[0].Data) } if p.Options[1].Type != tcp.SAckOk { t.Fatalf("Option SAckOk mismatch: %x", p.Options[1].Data) } if p.Options[2].Type != tcp.Timestamp { t.Fatalf("Option Timestamp mismatch: %x", p.Options[2].Data) } if p.Options[3].Type != tcp.WindowScale { t.Fatalf("Option WindowScale mismatch: %x", p.Options[3].Data) } }
func BenchmarkUnpack(bn *testing.B) { var p tcp.Packet var b packet.Buffer for n := 0; n < bn.N; n++ { b.Init(test_simple) p.Unpack(&b) } }
func TestUnpack(t *testing.T) { var p tcp.Packet cmp := MakeTestSimple() var b packet.Buffer b.Init(test_simple) err := p.Unpack(&b) if err != nil { t.Fatalf("Error unpacking: %s", err) } if !p.Equals(cmp) { t.Fatalf("Packet mismatch:\n%s\n%s", &p, cmp) } }
func TestUnpackWithIPv4(t *testing.T) { var p tcp.Packet cmp := MakeTestSimple() cmp.Checksum = 0xa64f var b packet.Buffer b.Init(test_with_ipv4) err := p.Unpack(&b) if err != nil { t.Fatalf("Error unpacking: %s", err) } if !p.Equals(cmp) { t.Fatalf("Packet mismatch:\n%s\n%s", &p, cmp) } }