Documentation ¶
Overview ¶
The factory package contains functions for constructing packets.
Index ¶
- func CreateARPPacket(srcMAC net.HardwareAddr, srcIP, dstIP net.IP) ([]byte, error)
- func CreateICMPPacket() ([]byte, error)
- func CreateSYNPacket(srcIP, dstIP net.IP, srcPort, dstPort uint16) ([]byte, *layers.IPv4, *layers.TCP, error)
- func GenerateRandomPort() (uint16, error)
- func ReleasePort(port uint16)
- func SendICMPRequest(target net.IP) (bool, error)
- type PortStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateARPPacket ¶
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 ¶
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 ¶
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.
Types ¶
type PortStatus ¶
type PortStatus int