Skip to content

ICMP API

stjohnd edited this page Jun 6, 2018 · 2 revisions

Protocol

The Internet Control Messaging Protocol provides a definition of messages that can be useful in the general operations of the Internet. The implementation of this protocol on a platform is completely optional.

Most flags are defined in a request and response style, these include

0x01: Echo Request, Attempts to get a response from the target host's ICMP suite
0x02: Echo Reply, sent to respond to the request
0x03: Route Discovery Request, Sent to request all routes known to the router. Typically broadcasted
0x04: Discovery Reply, Sent to respond to the request, contains routes known to the host

Some flags are also defined for use as warning or control messages, these include

0x10: Destination Host Overloaded: Send by or on behalf of a host as a courtesy to the target, informs them that packets are being discarded
0x11: Destination Unreachable, which can contain many flags, including:
0x1: Host not found, extreme courtesy message from a router indicating it never found the host
0x2: Network not found, warning that no valid routing entry to the network was found, nor was there a default entry
0x12: Maximum Transmission Unit (MTU) Exceeded: This means that the packet was too large to forward onto the next media. the data of this will be the number of bytes that the message was exceeded by followed by a truncated form of the message

API

A basic ICMP library comes bundled with this distribution. It is quite small, but does have a couple of useful features:

icmp.ping(dest,data,timeout) attempts to send a ping request to the given dest, which is an IP address. returns true on success, false otherwise. data and timeout are optional and determine the data to be sent, and the number of seconds to wait before considering the packet lost.

icmp.find_routes(interface) broadcasts a route discovery message onto the given interface's LAN and collects all the route replies.

Clone this wiki locally