pktdump

package module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 4 Imported by: 4

README

pktdump

CircleCI GoDoc Go Report Card Codecov

Format gopacket.Packet network packets similar to the tcpdump CLI output

example

package pktdump_test

import (
	"fmt"

	"github.com/google/gopacket"
	"github.com/google/gopacket/layers"

	"github.com/x-way/pktdump"
)

func ExampleFormat() {
	raw := []byte{0x45, 0x00, 0x00, 0x42, 0x9a, 0x66, 0x00, 0x00, 0x40, 0x11, 0xce, 0xc0, 0xc0, 0xa8, 0x48, 0x32, 0xc0, 0xa8, 0x48, 0x01, 0xfb, 0x6a, 0x00, 0x35, 0x00, 0x2e, 0x02, 0xeb, 0x29, 0x84, 0x01, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x73, 0x69, 0x67, 0x69, 0x6e, 0x74, 0x02, 0x63, 0x68, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

	packet := gopacket.NewPacket(raw, layers.LayerTypeIPv4, gopacket.Default)

	fmt.Println(pktdump.Format(packet))
}

This would produce the following result

IP 192.168.72.50.64362 > 192.168.72.1.53: 10628+ [1au] A CH? sigint.ch. (38)

Documentation

Overview

Package pktdump formats gopacket.Packet network packets similar to the tcpdump CLI output

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(packet gopacket.Packet) string

Format parses a packet and returns a string with a textual representation similar to the tcpdump output

Example
package main

import (
	"fmt"

	"github.com/google/gopacket"
	"github.com/google/gopacket/layers"

	"github.com/x-way/pktdump"
)

func main() {
	raw := []byte{0x45, 0x00, 0x00, 0x42, 0x9a, 0x66, 0x00, 0x00, 0x40, 0x11, 0xce, 0xc0, 0xc0, 0xa8, 0x48, 0x32, 0xc0, 0xa8, 0x48, 0x01, 0xfb, 0x6a, 0x00, 0x35, 0x00, 0x2e, 0x02, 0xeb, 0x29, 0x84, 0x01, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x73, 0x69, 0x67, 0x69, 0x6e, 0x74, 0x02, 0x63, 0x68, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

	packet := gopacket.NewPacket(raw, layers.LayerTypeIPv4, gopacket.Default)

	fmt.Println(pktdump.Format(packet))
}
Output:

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL