MoonGen
 All Files Functions Variables Pages
icmp.lua File Reference

Internet control message protocol utility. More...

Go to the source code of this file.

Functions

function icmpHeader setType (int)
 Set the type. More...
 
function icmpHeader getType ()
 Retrieve the type. More...
 
function icmpHeader getTypeString ()
 Retrieve the type. More...
 
function icmpHeader setCode (int)
 Set the code. More...
 
function icmpHeader getCode ()
 Retrieve the code. More...
 
function icmpHeader getCodeString ()
 Retrieve the code. More...
 
function icmpHeader setChecksum (int)
 Set the checksum. More...
 
function icmpHeader calculateChecksum (len)
 Calculate the checksum. More...
 
function icmpHeader getChecksum ()
 Retrieve the checksum. More...
 
function icmpHeader getChecksumString ()
 Retrieve the checksum. More...
 
function icmpHeader setMessageBody (body)
 Set the message body. More...
 
function icmpHeader getMessageBody ()
 Retrieve the message body. More...
 
function icmpHeader getMessageBodyString ()
 Retrieve the message body. More...
 
function icmpHeader fill (args, pre)
 Set all members of the icmp header. More...
 
function icmpHeader get (pre)
 Retrieve the values of all members. More...
 
function icmpHeader getString ()
 Retrieve the values of all members. More...
 
function icmpHeader resolveNextHeader ()
 Resolve which header comes after this one (in a packet). More...
 
function icmpHeader setDefaultNamedArgs (pre, namedArgs, nextHeader, accumulatedLength)
 Change the default values for namedArguments (for fill/get). More...
 

Variables

local icmp = {}
 Icmp4 protocol constants.
 
icmp ECHO_REPLY = { type = 0, code = 0 }
 Icmp4 type-code pair: echo reply. More...
 
icmp ECHO_REQUEST = { type = 8, code = 0 }
 Icmp4 type-code pair: echo request. More...
 
icmp DST_UNR_PORT_UNR = { type = 3, code = 3 }
 Icmp4 type-code pair: destination unreachable - port unreachable.
 
icmp TIME_EXCEEDED_TTL_EXPIRED = { type = 11, code = 0 }
 Icmp4 type-code pair: time exceeded - TTL exceeded.
 
local icmp6 = {}
 Icmp6 protocol constants.
 
local icmpHeader = {}
 Module for icmp_header struct (see headers.lua).
 
pkt getIcmp4Packet = packetCreate("eth", "ip4", "icmp")
 Cast the packet to an Icmp4 packet.
 
pkt getIcmp6Packet = packetCreate("eth", "ip6", "icmp")
 Cast the packet to an Icmp6 packet.
 

Detailed Description

Internet control message protocol utility.

Utility functions for the icmp_header struct defined in headers.lua .
Includes:

  • Icmp4 constants
  • Icmp6 constants
  • Icmp header utility
  • Definition of Icmp packets

Definition in file icmp.lua.

Function Documentation

function icmpHeader calculateChecksum ( len  )

Calculate the checksum.

Parameters
lenNumber of bytes that the checksum will be computed over
function icmpHeader fill ( args  ,
pre   
)

Set all members of the icmp header.

Per default, all members are set to default values specified in the respective set function. Optional named arguments can be used to set a member to a user-provided value.

Parameters
argsTable of named arguments. Available arguments: Type, Code, Checksum, MessageBody
preprefix for namedArgs. Default 'icmp'.
fill() --- only default values
fill{ icmpCode=3 } --- all members are set to default values with the exception of icmpCode
function icmpHeader get ( pre  )

Retrieve the values of all members.

Parameters
preprefix for namedArgs. Default 'icmp'.
Returns
Table of named arguments. For a list of arguments see "See also".
See Also
icmpHeader:fill
function icmpHeader getChecksum ( )

Retrieve the checksum.

Returns
Checksum as 16 bit integer.
function icmpHeader getChecksumString ( )

Retrieve the checksum.

Returns
Checksum as string.
function icmpHeader getCode ( )

Retrieve the code.

Returns
Code as 8 bit integer.
function icmpHeader getCodeString ( )

Retrieve the code.

does not work for ICMPv6

Returns
Code as string.
function icmpHeader getMessageBody ( )

Retrieve the message body.

Returns
Message body as TODO.
function icmpHeader getMessageBodyString ( )

Retrieve the message body.

Returns
Message body as string TODO.
function icmpHeader getString ( )

Retrieve the values of all members.

Does not work correctly for ICMPv6 packets

Returns
Values in string format.
function icmpHeader getType ( )

Retrieve the type.

Returns
Type as 8 bit integer.
function icmpHeader getTypeString ( )

Retrieve the type.

does not work for ICMPv6 (ICMPv6 uses different values)

Returns
Type as string.
function icmpHeader resolveNextHeader ( )

Resolve which header comes after this one (in a packet).

For instance: in tcp/udp based on the ports. This function must exist and is only used when get/dump is executed on an unknown (mbuf not yet casted to e.g. tcpv6 packet) packet (mbuf)

Returns
String next header (e.g. 'udp', 'icmp', nil)
function icmpHeader setChecksum ( int  )

Set the checksum.

Parameters
intChecksum of the icmp header as 16 bit integer.
function icmpHeader setCode ( int  )

Set the code.

Parameters
intCode of the icmp header as 8 bit integer.
function icmpHeader setDefaultNamedArgs ( pre  ,
namedArgs  ,
nextHeader  ,
accumulatedLength   
)

Change the default values for namedArguments (for fill/get).

This can be used to for instance calculate a length value based on the total packet length. See proto/ip4.setDefaultNamedArgs as an example. This function must exist and is only used by packet.fill.

Parameters
preThe prefix used for the namedArgs, e.g. 'icmp'
namedArgsTable of named arguments (see See Also)
nextHeaderThe header following after this header in a packet
accumulatedLengthThe so far accumulated length for previous headers in a packet
Returns
Table of namedArgs
See Also
icmpHeader:fill
function icmpHeader setMessageBody ( body  )

Set the message body.

Parameters
intMessage body of the icmp header as TODO.
function icmpHeader setType ( int  )

Set the type.

Parameters
intType of the icmp header as 8 bit integer.

Variable Documentation

icmp6 ECHO_REPLY = { type = 0, code = 0 }

Icmp4 type-code pair: echo reply.

Icmp6 type-code pair: echo reply.

Definition at line 28 of file icmp.lua.

icmp6 ECHO_REQUEST = { type = 8, code = 0 }

Icmp4 type-code pair: echo request.

Icmp6 type-code pair: echo request.

Definition at line 30 of file icmp.lua.