MCPcopy Index your code
hub / github.com/google/gopacket / TestDecodeSimpleTCPPacket

Function TestDecodeSimpleTCPPacket

layers/decode_test.go:386–492  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

384}
385
386func TestDecodeSimpleTCPPacket(t *testing.T) {
387 equal := func(desc, want string, got fmt.Stringer) {
388 if want != got.String() {
389 t.Errorf("%s: got %q want %q", desc, got.String(), want)
390 }
391 }
392 p := gopacket.NewPacket(testSimpleTCPPacket, LinkTypeEthernet, gopacket.DecodeOptions{Lazy: true, NoCopy: true})
393 if eth := p.LinkLayer(); eth == nil {
394 t.Error("No ethernet layer found")
395 } else {
396 equal("Eth Src", "bc:30:5b:e8:d3:49", eth.LinkFlow().Src())
397 equal("Eth Dst", "00:00:0c:9f:f0:20", eth.LinkFlow().Dst())
398 }
399 if net := p.NetworkLayer(); net == nil {
400 t.Error("No net layer found")
401 } else if ip, ok := net.(*IPv4); !ok {
402 t.Error("Net layer is not IP layer")
403 } else {
404 equal("IP Src", "172.17.81.73", net.NetworkFlow().Src())
405 equal("IP Dst", "173.222.254.225", net.NetworkFlow().Dst())
406 want := &IPv4{
407 BaseLayer: BaseLayer{testSimpleTCPPacket[14:34], testSimpleTCPPacket[34:]},
408 Version: 4,
409 IHL: 5,
410 TOS: 0,
411 Length: 420,
412 Id: 14815,
413 Flags: 0x02,
414 FragOffset: 0,
415 TTL: 64,
416 Protocol: 6,
417 Checksum: 0x555A,
418 SrcIP: []byte{172, 17, 81, 73},
419 DstIP: []byte{173, 222, 254, 225},
420 }
421 if !reflect.DeepEqual(ip, want) {
422 t.Errorf("IP layer mismatch, \ngot %#v\nwant %#v\n", ip, want)
423 }
424 }
425 if trans := p.TransportLayer(); trans == nil {
426 t.Error("No transport layer found")
427 } else if tcp, ok := trans.(*TCP); !ok {
428 t.Error("Transport layer is not TCP layer")
429 } else {
430 equal("TCP Src", "50679", trans.TransportFlow().Src())
431 equal("TCP Dst", "80", trans.TransportFlow().Dst())
432 want := &TCP{
433 BaseLayer: BaseLayer{testSimpleTCPPacket[34:66], testSimpleTCPPacket[66:]},
434 SrcPort: 50679,
435 DstPort: 80,
436 Seq: 0xc57e0e48,
437 Ack: 0x49074232,
438 DataOffset: 8,
439 ACK: true,
440 PSH: true,
441 Window: 0x73,
442 Checksum: 0x9a8f,
443 Urgent: 0,

Callers

nothing calls this directly

Calls 15

LinkLayerMethod · 0.95
NetworkLayerMethod · 0.95
TransportLayerMethod · 0.95
LayerMethod · 0.95
NewPacketFunction · 0.92
equalFunction · 0.85
testSerializationFunction · 0.85
SrcMethod · 0.80
DstMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.65
LinkFlowMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…