|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.savarese.vserv.tcpip.IPPacket
public class 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_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 |
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 | |
---|---|
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 |
getIPChecksum()
|
int |
getIPHeaderByteLength()
|
int |
getIPHeaderLength()
|
int |
getIPPacketLength()
|
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()
|
void |
setData(byte[] data)
Sets the raw packet byte array. |
void |
setDestinationAsWord(int dest)
Sets the destination IP address using a word representation. |
void |
setIPHeaderLength(int length)
Sets the IP header length field. |
void |
setIPPacketLength(int length)
Sets the IP packet total length header value. |
void |
setProtocol(int protocol)
Sets the protocol number. |
void |
setSourceAsWord(int src)
Sets the source IP address using a word representation. |
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_TOTAL_LENGTH
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 setIPPacketLength(int length)
length
- The total IP packet length in bytes.public final int getIPPacketLength()
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 setProtocol(int protocol)
protocol
- The protocol number.public final int getProtocol()
public final int getTTL()
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 |