factory

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

The factory package contains functions for constructing packets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateARPPacket

func CreateARPPacket(srcMAC net.HardwareAddr, srcIP, dstIP net.IP) ([]byte, error)

CreateARPPacket constructs an ARP packet to determine the MAC Address of the default gateway on the network

ARP is used in gomap to determine the MAC Address of the default gateway on the network and the MAC address of local targets

func CreateICMPPacket

func CreateICMPPacket() ([]byte, error)

CreateICMPPacket constructs an ICMP packet and returns the bytes Uses the net/ipv4 and net/icmp packages

func CreateSYNPacket

func CreateSYNPacket(srcIP, dstIP net.IP, srcPort, dstPort uint16) ([]byte, *layers.IPv4, *layers.TCP, error)

CreateSYNPacket creates a TCP SYN packet with the specified source and destination IP and port. It returns the serialized packet bytes, the IPv4 layer, and the TCP layer. If there is an error generating the packet, it returns an error.

func GenerateRandomPort

func GenerateRandomPort() (uint16, error)

GenerateRandomPort generates a random, unused TCP port number.

This function will attempt to find an unused port by generating random port numbers within the dynamic/private port range (49152-65535) and checking if the port is available. It will try up to 100 times before returning an error.

The returned port number is marked as used in the usedPorts map to prevent it from being returned by subsequent calls to this function. When you're done using the port, call ReleasePort to mark it as available again.

Returns:

  • The generated port number as a uint16.
  • An error if no unused port could be found after 100 attempts.

func ReleasePort

func ReleasePort(port uint16)

ReleasePort marks a port as no longer in use, allowing it to be returned by future calls to GenerateRandomPort.

This function should be called when you're done using a port that was allocated by GenerateRandomPort.

Usage:

ReleasePort(port)

Parameters:

  • port: The uint16 port number to be released.

func SendICMPRequest

func SendICMPRequest(target net.IP) (bool, error)

SendICMPRequest sends an ICMP request to the provided target with given timeout duration and returns true if it receives a reply

Types

type PortStatus

type PortStatus int

Jump to

Keyboard shortcuts

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