RawPing.Socket (raw_ping v0.2.0)

Copy Markdown View Source

Low-level socket operations for ICMP using Erlang's :socket API.

This module handles opening raw ICMP sockets, sending packets, and receiving replies with proper timeout handling.

Summary

Functions

Close an ICMP socket.

Open a raw ICMP socket.

Receive an ICMP reply with timeout.

Send an ICMP packet to a destination IP.

Functions

close(socket)

@spec close(:socket.socket()) :: :ok | {:error, term()}

Close an ICMP socket.

open()

@spec open() :: {:ok, :socket.socket()} | {:error, term()}

Open a raw ICMP socket.

Returns {:ok, socket} or {:error, reason}.

Requires elevated privileges (root or CAP_NET_RAW).

recv(socket, timeout_ms)

@spec recv(:socket.socket(), non_neg_integer()) :: {:ok, binary()} | {:error, term()}

Receive an ICMP reply with timeout.

Returns {:ok, data} or {:error, :timeout} / {:error, reason}.

send(socket, packet, dest_ip)

@spec send(:socket.socket(), binary(), :inet.ip_address()) :: :ok | {:error, term()}

Send an ICMP packet to a destination IP.