Savarese.Org

org.savarese.vserv.tcpip
Class ICMPPacket

java.lang.Object
  extended byorg.savarese.vserv.tcpip.IPPacket
      extended byorg.savarese.vserv.tcpip.ICMPPacket
Direct Known Subclasses:
ICMPEchoPacket

public abstract class ICMPPacket
extends IPPacket

ICMPPacket extends IPPacket to handle ICMP packets. The ICMP packet structure is described in RFC 792.

Author:
Daniel F. Savarese

Field Summary
static int OFFSET_CODE
          Offset into the ICMP packet of the code header value.
static int OFFSET_ICMP_CHECKSUM
          Offset into the ICMP packet of the ICMP checksum.
static int OFFSET_IDENTIFIER
          Offset into the ICMP packet of the identifier header value.
static int OFFSET_SEQUENCE
          Offset into the ICMP packet of the sequence number header value.
static int OFFSET_TYPE
          Offset into the ICMP packet of the type header value.
static int TYPE_ECHO_REPLY
          The ICMP type number for an echo reply.
static int TYPE_ECHO_REQUEST
          The ICMP type number for an echo request.
 
Fields inherited from class org.savarese.vserv.tcpip.IPPacket
_data_, LENGTH_DESTINATION_ADDRESS, LENGTH_SOURCE_ADDRESS, OFFSET_DESTINATION_ADDRESS, OFFSET_FLAGS, OFFSET_IDENTIFICATION, OFFSET_IP_CHECKSUM, OFFSET_PROTOCOL, OFFSET_SOURCE_ADDRESS, OFFSET_TOTAL_LENGTH, OFFSET_TTL, OFFSET_TYPE_OF_SERVICE, PROTOCOL_ICMP, PROTOCOL_IP, PROTOCOL_TCP, PROTOCOL_UDP
 
Constructor Summary
ICMPPacket(ICMPPacket packet)
          Creates a new ICMP packet that is a copy of a given packet.
ICMPPacket(int size)
          Creates a new ICMP packet of a given size.
 
Method Summary
 int computeICMPChecksum()
          Same as computeICMPChecksum(true);
 int computeICMPChecksum(boolean update)
          Computes the ICMP checksum, optionally updating the ICMP checksum header.
 void copyData(ICMPPacket packet)
          Copies the contents of an ICMPPacket.
 int getCode()
           
 int getCombinedHeaderByteLength()
           
 int getICMPChecksum()
           
 int getICMPDataByteLength()
           
abstract  int getICMPHeaderByteLength()
           
 int getICMPPacketByteLength()
           
 int getType()
           
 void setCode(int code)
          Sets the ICMP code header field.
 void setData(byte[] data)
          Sets the raw packet byte array.
 void setICMPDataByteLength(int length)
          Sets the length of the ICMP data payload.
 void setIPHeaderLength(int length)
          Sets the IP header length field.
 void setType(int type)
          Sets the ICMP type header field.
 
Methods inherited from class org.savarese.vserv.tcpip.IPPacket
_computeChecksum_, computeIPChecksum, computeIPChecksum, copy, getData, getDestination, getDestination, getDestinationAsInetAddress, getDestinationAsWord, getFragmentOffset, getIdentification, getIPChecksum, getIPFlags, getIPHeaderByteLength, getIPHeaderLength, getIPPacketLength, getIPVersion, getProtocol, getSource, getSource, getSourceAsInetAddress, getSourceAsWord, getTTL, getTypeOfService, setDestinationAsWord, setFragmentOffset, setIdentification, setIPFlags, setIPPacketLength, setIPVersion, setProtocol, setSourceAsWord, setTTL, setTypeOfService, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OFFSET_TYPE

public static final int OFFSET_TYPE
Offset into the ICMP packet of the type header value.

See Also:
Constant Field Values

OFFSET_CODE

public static final int OFFSET_CODE
Offset into the ICMP packet of the code header value.

See Also:
Constant Field Values

OFFSET_ICMP_CHECKSUM

public static final int OFFSET_ICMP_CHECKSUM
Offset into the ICMP packet of the ICMP checksum.

See Also:
Constant Field Values

OFFSET_IDENTIFIER

public static final int OFFSET_IDENTIFIER
Offset into the ICMP packet of the identifier header value.

See Also:
Constant Field Values

OFFSET_SEQUENCE

public static final int OFFSET_SEQUENCE
Offset into the ICMP packet of the sequence number header value.

See Also:
Constant Field Values

TYPE_ECHO_REQUEST

public static final int TYPE_ECHO_REQUEST
The ICMP type number for an echo request.

See Also:
Constant Field Values

TYPE_ECHO_REPLY

public static final int TYPE_ECHO_REPLY
The ICMP type number for an echo reply.

See Also:
Constant Field Values
Constructor Detail

ICMPPacket

public ICMPPacket(int size)
Creates a new ICMP packet of a given size.

Parameters:
size - The number of bytes in the packet.

ICMPPacket

public ICMPPacket(ICMPPacket packet)
Creates a new ICMP packet that is a copy of a given packet.

Parameters:
packet - The packet to replicate.
Method Detail

getICMPHeaderByteLength

public abstract int getICMPHeaderByteLength()
Returns:
The number of bytes in the ICMP packet header.

setIPHeaderLength

public void setIPHeaderLength(int length)
Description copied from class: IPPacket
Sets the IP header length field. At most, this can be a four-bit value. The high order bits beyond the fourth bit will be ignored.

Overrides:
setIPHeaderLength in class IPPacket
Parameters:
length - The length of the IP header in 32-bit words.

getCombinedHeaderByteLength

public final int getCombinedHeaderByteLength()
Returns:
The total number of bytes in the IP and ICMP headers.

setICMPDataByteLength

public final void setICMPDataByteLength(int length)
Sets the length of the ICMP data payload.

Parameters:
length - The length of the ICMP data payload in bytes.

getICMPDataByteLength

public final int getICMPDataByteLength()
Returns:
The number of bytes in the ICMP data payload.

getICMPPacketByteLength

public final int getICMPPacketByteLength()
Returns:
The ICMP packet length. This is the size of the IP packet minus the size of the IP header.

copyData

public final void copyData(ICMPPacket packet)
Copies the contents of an ICMPPacket. If the current data array is of insufficient length to store the contents, a new array is allocated.

Parameters:
packet - The TCPPacket to copy.

setData

public void setData(byte[] data)
Description copied from class: IPPacket
Sets the raw packet byte array. Although this method would appear to violate object-oriented principles, it is necessary to implement efficient packet processing. You don't necessarily want to allocate a new IPPacket and data buffer every time a packet arrives and you need to be able to wrap packets from APIs that supply them as byte arrays.

Overrides:
setData in class IPPacket
Parameters:
data - The raw packet byte array to wrap.

setType

public final void setType(int type)
Sets the ICMP type header field.

Parameters:
type - The new type.

getType

public final int getType()
Returns:
The ICMP type header field.

setCode

public final void setCode(int code)
Sets the ICMP code header field.

Parameters:
code - The new type.

getCode

public final int getCode()
Returns:
The ICMP code header field.

getICMPChecksum

public final int getICMPChecksum()
Returns:
The ICMP checksum.

computeICMPChecksum

public final int computeICMPChecksum(boolean update)
Computes the ICMP checksum, optionally updating the ICMP checksum header.

Parameters:
update - Specifies whether or not to update the ICMP checksum header after computing the checksum. A value of true indicates the header should be updated, a value of false indicates it should not be updated.
Returns:
The computed ICMP checksum.

computeICMPChecksum

public final int computeICMPChecksum()
Same as computeICMPChecksum(true);

Returns:
The computed ICMP checksum value.

Savarese.Org

Copyright © 2004-2005 Daniel F. Savarese. All Rights Reserved.