protocols

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PNGSignature = []byte{137, 80, 78, 71, 13, 10, 26, 10}

PNGSignature represents the PNG file signature

Functions

func BuildIPv4Header

func BuildIPv4Header(header IPv4Header) (*bitstring.BitString, error)

BuildIPv4Header creates an IPv4 header from a structure

func BuildNetworkPacket

func BuildNetworkPacket(packet NetworkPacket) (*bitstring.BitString, error)

BuildNetworkPacket creates a network packet from a structure

func BuildPNGChunk

func BuildPNGChunk(chunk PNGChunk) ([]byte, error)

BuildPNGChunk creates a PNG chunk from a structure

func BuildPNGHeader

func BuildPNGHeader(header PNGHeader) (*bitstring.BitString, error)

BuildPNGHeader creates a PNG header from a structure

func BuildTCPFlags

func BuildTCPFlags(flags TCPFlags) (*bitstring.BitString, error)

BuildTCPFlags creates TCP flags from a structure

func BuildTCPHeader

func BuildTCPHeader(header TCPHeader) (*bitstring.BitString, error)

BuildTCPHeader creates a complete TCP header from a structure

func FormatIPAddress

func FormatIPAddress(ip uint32) string

FormatIPAddress formats an IP address from uint32 to string

func FormatNetworkPacketInfo

func FormatNetworkPacketInfo(packet *NetworkPacket) string

FormatNetworkPacketInfo formats network packet information for output

func FormatPNGIHDRInfo

func FormatPNGIHDRInfo(ihdr *PNGIHDRChunk) string

FormatPNGIHDRInfo formats IHDR chunk information for output

func GetIPv4HeaderLength

func GetIPv4HeaderLength(header *IPv4Header) uint

GetIPv4HeaderLength returns the header length in bytes

func GetIPv4PayloadLength

func GetIPv4PayloadLength(header *IPv4Header) uint

GetIPv4PayloadLength returns the payload length in bytes

func GetPNGColorTypeName

func GetPNGColorTypeName(colorType uint8) string

GetPNGColorTypeName returns the color type name

func GetPNGInterlaceMethodName

func GetPNGInterlaceMethodName(interlace uint8) string

GetPNGInterlaceMethodName returns the interlace method name

func GetTCPFlagsString

func GetTCPFlagsString(flags TCPFlags) string

GetTCPFlagsString returns a string representation of set flags

func GetTCPHeaderLength

func GetTCPHeaderLength(header *TCPHeader) uint

GetTCPHeaderLength returns the TCP header length in bytes

func IsTCPConnectionEstablished

func IsTCPConnectionEstablished(flags TCPFlags) bool

IsTCPConnectionEstablished checks if the packet is a connection establishment confirmation (SYN+ACK)

func IsTCPConnectionEstablishment

func IsTCPConnectionEstablishment(flags TCPFlags) bool

IsTCPConnectionEstablishment checks if the packet is a connection establishment (SYN)

func IsTCPConnectionTermination

func IsTCPConnectionTermination(flags TCPFlags) bool

IsTCPConnectionTermination checks if the packet is a connection termination (FIN or RST)

func IsTCPDataPacket

func IsTCPDataPacket(flags TCPFlags) bool

IsTCPDataPacket checks if the packet contains data (PSH and ACK)

func ParseIPAddress

func ParseIPAddress(ipStr string) (uint32, error)

ParseIPAddress parses an IP address from string to uint32

func ValidateIPv4Header

func ValidateIPv4Header(header *IPv4Header) error

ValidateIPv4Header performs full validation of an IPv4 header

func ValidateNetworkPacket

func ValidateNetworkPacket(packet *NetworkPacket) error

ValidateNetworkPacket performs full validation of a network packet

func ValidatePNGChunk

func ValidatePNGChunk(chunk *PNGChunk) error

ValidatePNGChunk performs PNG chunk validation

func ValidatePNGHeader

func ValidatePNGHeader(header *PNGHeader) error

ValidatePNGHeader performs PNG header validation

func ValidatePNGIHDRChunk

func ValidatePNGIHDRChunk(ihdr *PNGIHDRChunk) error

ValidatePNGIHDRChunk performs IHDR chunk validation

func ValidateTCPFlags

func ValidateTCPFlags(flags *TCPFlags) error

ValidateTCPFlags performs validation of TCP flags

func ValidateTCPHeader

func ValidateTCPHeader(header *TCPHeader) error

ValidateTCPHeader performs full validation of a TCP header

Types

type IPv4Header

type IPv4Header struct {
	Version        uint // Version (4 bits)
	HeaderLength   uint // Header length (4 bits)
	ServiceType    uint // Service type (8 bits)
	TotalLength    uint // Total length (16 bits)
	Identification uint // Identification (16 bits)
	Flags          uint // Flags (3 bits)
	FragmentOffset uint // Fragment offset (13 bits)
	TTL            uint // Time to live (8 bits)
	Protocol       uint // Protocol (8 bits)
	Checksum       uint // Checksum (16 bits)
	SourceIP       uint // Source IP address (32 bits)
	DestinationIP  uint // Destination IP address (32 bits)
}

IPv4Header represents the structure of an IPv4 header

func ParseIPv4Header

func ParseIPv4Header(data *bitstring.BitString) (*IPv4Header, error)

ParseIPv4Header parses an IPv4 header from a bitstring

type NetworkPacket

type NetworkPacket struct {
	IPv4Header IPv4Header
	TCPHeader  TCPHeader
	Payload    []byte
}

NetworkPacket represents a network packet with IPv4 and TCP headers

func CreateHTTPPacket

func CreateHTTPPacket(srcIP, dstIP string, srcPort, dstPort uint16, method, path, host string) (*NetworkPacket, error)

CreateHTTPPacket creates an HTTP request packet

func CreateTCPSynPacket

func CreateTCPSynPacket(srcIP, dstIP string, srcPort, dstPort uint16) (*NetworkPacket, error)

CreateTCPSynPacket creates a TCP SYN packet for connection establishment

func ParseNetworkPacket

func ParseNetworkPacket(data *bitstring.BitString) (*NetworkPacket, error)

ParseNetworkPacket parses a network packet from a bitstring

type PNGChunk

type PNGChunk struct {
	Length uint32 // Chunk data length (4 bytes)
	Type   []byte // Chunk type (4 bytes)
	Data   []byte // Chunk data (variable length)
	CRC    uint32 // CRC32 checksum (4 bytes)
}

PNGChunk represents the structure of a PNG chunk

func BuildPNGIHDRChunk

func BuildPNGIHDRChunk(ihdr PNGIHDRChunk) (PNGChunk, error)

BuildPNGIHDRChunk creates an IHDR chunk from a structure

func ParsePNGChunk

func ParsePNGChunk(data []byte) (PNGChunk, uint, error)

ParsePNGChunk parses a PNG chunk from bytes

type PNGHeader

type PNGHeader struct {
	Signature []byte     // PNG signature (8 bytes)
	Chunks    []PNGChunk // PNG chunks
}

PNGHeader represents the structure of a PNG header

func ParsePNGHeader

func ParsePNGHeader(data *bitstring.BitString) (*PNGHeader, error)

ParsePNGHeader parses a PNG header from a bitstring

type PNGIHDRChunk

type PNGIHDRChunk struct {
	Width       uint32 // Image width (4 bytes)
	Height      uint32 // Image height (4 bytes)
	BitDepth    uint8  // Color depth (1 byte)
	ColorType   uint8  // Color type (1 byte)
	Compression uint8  // Compression method (1 byte)
	Filter      uint8  // Filter method (1 byte)
	Interlace   uint8  // Interlace method (1 byte)
}

PNGIHDRChunk represents the IHDR chunk of PNG (image header)

func ParsePNGIHDRChunk

func ParsePNGIHDRChunk(data []byte) (*PNGIHDRChunk, error)

ParsePNGIHDRChunk parses an IHDR chunk from data

type TCPFlags

type TCPFlags struct {
	Reserved uint // Reserved bits (2 bits)
	URG      uint // Urgent flag (1 bit)
	ACK      uint // Acknowledgment flag (1 bit)
	PSH      uint // Push flag (1 bit)
	RST      uint // Reset flag (1 bit)
	SYN      uint // Synchronize flag (1 bit)
	FIN      uint // Finish flag (1 bit)
}

TCPFlags represents the structure of TCP flags

func ParseTCPFlags

func ParseTCPFlags(data *bitstring.BitString) (*TCPFlags, error)

ParseTCPFlags parses TCP flags from a bitstring

type TCPHeader

type TCPHeader struct {
	SourcePort      uint     // Source port (16 bits)
	DestinationPort uint     // Destination port (16 bits)
	SequenceNumber  uint     // Sequence number (32 bits)
	Acknowledgment  uint     // Acknowledgment number (32 bits)
	DataOffset      uint     // Data offset (4 bits)
	Reserved        uint     // Reserved (3 bits)
	Flags           TCPFlags // Flags (9 bits: 2 reserved + 7 flags)
	Window          uint     // Window size (16 bits)
	Checksum        uint     // Checksum (16 bits)
	UrgentPointer   uint     // Urgent pointer (16 bits)
}

TCPHeader represents a complete TCP header

func ParseTCPHeader

func ParseTCPHeader(data *bitstring.BitString) (*TCPHeader, error)

ParseTCPHeader parses a complete TCP header from a bitstring

Jump to

Keyboard shortcuts

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