|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.savarese.vserv.tcpip.IPPacket
IPPacket wraps the raw bytes comprising an IPv4 packet and exposes
its content via setter and getter methods. After you alter the
header of an IP packet you have to recompute the checksum with
computeIPChecksum()
. The structure of
IP packets is described in
RFC 760.
Field Summary | |
protected byte[] |
_data_
Raw packet data. |
static int |
LENGTH_DESTINATION_ADDRESS
Number of bytes in destination address. |
static int |
LENGTH_SOURCE_ADDRESS
Number of bytes in source address. |
static int |
OFFSET_DESTINATION_ADDRESS
Offset into byte array of destination address header value. |
static int |
OFFSET_FLAGS
Offset into byte array of the flags header value. |
static int |
OFFSET_IDENTIFICATION
Offset into byte array of the identification header value. |
static int |
OFFSET_IP_CHECKSUM
Offset into byte array of header checksum header value. |
static int |
OFFSET_PROTOCOL
Offset into byte array of protocol number header value. |
static int |
OFFSET_SOURCE_ADDRESS
Offset into byte array of source address header value. |
static int |
OFFSET_TOTAL_LENGTH
Offset into byte array of total packet length header value. |
static int |
OFFSET_TTL
Offset into byte array of time to live header value. |
static int |
OFFSET_TYPE_OF_SERVICE
Offset into byte array of the type of service header value. |
static int |
PROTOCOL_ICMP
Protocol constant for ICMP. |
static int |
PROTOCOL_IP
Protocol constant for IPv4. |
static int |
PROTOCOL_TCP
Protocol constant for TCP. |
static int |
PROTOCOL_UDP
Protocol constant for UDP. |
Constructor Summary | |
IPPacket(int size)
Creates a new IPPacket of a given size. |
Method Summary | |
protected int |
_computeChecksum_(int startOffset,
int checksumOffset,
int length,
int virtualHeaderTotal,
boolean update)
Calculates checksums assuming the checksum is a 16-bit header field. |
int |
computeIPChecksum()
Same as computeIPChecksum(true); |
int |
computeIPChecksum(boolean update)
Computes the IP checksum, optionally updating the IP checksum header. |
void |
copy(IPPacket packet)
Copies the contents of an IPPacket to the calling instance. |
void |
getData(byte[] data)
Copies the raw packet data into a byte array. |
void |
getDestination(byte[] address)
Retrieves the destionation IP address into a byte array. |
void |
getDestination(java.lang.StringBuffer buffer)
Retrieves the destination IP address as a string into a StringBuffer. |
java.net.InetAddress |
getDestinationAsInetAddress()
|
int |
getDestinationAsWord()
|
int |
getFragmentOffset()
Returns the fragment offset header value. |
int |
getIdentification()
Returns the IP identification header value. |
int |
getIPChecksum()
|
int |
getIPFlags()
Returns the IP flags header value. |
int |
getIPHeaderByteLength()
|
int |
getIPHeaderLength()
|
int |
getIPPacketLength()
|
int |
getIPVersion()
Returns the IP version header value. |
int |
getProtocol()
|
void |
getSource(byte[] address)
Retrieves the source IP address into a byte array. |
void |
getSource(java.lang.StringBuffer buffer)
Retrieves the source IP address as a string into a StringBuffer. |
java.net.InetAddress |
getSourceAsInetAddress()
|
int |
getSourceAsWord()
|
int |
getTTL()
|
int |
getTypeOfService()
Returns the IP type of service header value. |
void |
setData(byte[] data)
Sets the raw packet byte array. |
void |
setDestinationAsWord(int dest)
Sets the destination IP address using a word representation. |
void |
setFragmentOffset(int offset)
Sets the fragment offset header value. |
void |
setIdentification(int id)
Sets the IP identification header value. |
void |
setIPFlags(int flags)
Sets the IP flags header value. |
void |
setIPHeaderLength(int length)
Sets the IP header length field. |
void |
setIPPacketLength(int length)
Sets the IP packet total length header value. |
void |
setIPVersion(int version)
Sets the IP version header value. |
void |
setProtocol(int protocol)
Sets the protocol number. |
void |
setSourceAsWord(int src)
Sets the source IP address using a word representation. |
void |
setTTL(int ttl)
Sets the time to live value in seconds. |
void |
setTypeOfService(int service)
Sets the IP type of service header value. |
int |
size()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int OFFSET_TYPE_OF_SERVICE
public static final int OFFSET_TOTAL_LENGTH
public static final int OFFSET_IDENTIFICATION
public static final int OFFSET_FLAGS
public static final int OFFSET_SOURCE_ADDRESS
public static final int LENGTH_SOURCE_ADDRESS
public static final int OFFSET_DESTINATION_ADDRESS
public static final int LENGTH_DESTINATION_ADDRESS
public static final int OFFSET_TTL
public static final int OFFSET_PROTOCOL
public static final int OFFSET_IP_CHECKSUM
public static final int PROTOCOL_IP
public static final int PROTOCOL_ICMP
public static final int PROTOCOL_TCP
public static final int PROTOCOL_UDP
protected byte[] _data_
Constructor Detail |
public IPPacket(int size)
size
- The number of bytes in the packet.Method Detail |
public int size()
public void setData(byte[] data)
data
- The raw packet byte array to wrap.public void getData(byte[] data)
data
- The raw packet byte array to wrap.public final void copy(IPPacket packet)
packet
- The packet to copy from.public final void setIPVersion(int version)
version
- A 4-bit unsigned integer.public final int getIPVersion()
public void setIPHeaderLength(int length)
length
- The length of the IP header in 32-bit words.public final int getIPHeaderLength()
public final int getIPHeaderByteLength()
public final void setTypeOfService(int service)
service
- An 8-bit unsigned integer.public final int getTypeOfService()
public final void setIPPacketLength(int length)
length
- The total IP packet length in bytes.public final int getIPPacketLength()
public void setIdentification(int id)
id
- A 16-bit unsigned integer.public final int getIdentification()
public final void setIPFlags(int flags)
flags
- A 3-bit unsigned integer.public final int getIPFlags()
public void setFragmentOffset(int offset)
offset
- A 13-bit unsigned integer.public final int getFragmentOffset()
public final void setProtocol(int protocol)
protocol
- The protocol number.public final int getProtocol()
public final void setTTL(int ttl)
ttl
- The time to live value in seconds.public final int getTTL()
protected int _computeChecksum_(int startOffset, int checksumOffset, int length, int virtualHeaderTotal, boolean update)
public final int computeIPChecksum(boolean update)
update
- Specifies whether or not to update the IP 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.
public final int computeIPChecksum()
computeIPChecksum(true);
public final int getIPChecksum()
public final void getSource(byte[] address)
LENGTH_SOURCE_ADDRESS
bytes long.
address
- The array in which to store the address.public final void getDestination(byte[] address)
LENGTH_DESTINATION_ADDRESS
bytes long.
address
- The array in which to store the address.public final void getSource(java.lang.StringBuffer buffer)
buffer
- The StringBuffer in which to store the address.public final void getDestination(java.lang.StringBuffer buffer)
buffer
- The StringBuffer in which to store the address.public final void setSourceAsWord(int src)
src
- The source IP address as a 32-bit word.public final void setDestinationAsWord(int dest)
dest
- The source IP address as a 32-bit word.public final int getSourceAsWord()
public final int getDestinationAsWord()
public final java.net.InetAddress getSourceAsInetAddress() throws java.net.UnknownHostException
java.net.UnknownHostException
public final java.net.InetAddress getDestinationAsInetAddress() throws java.net.UnknownHostException
java.net.UnknownHostException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |