java.net
Class RawPacket

java.lang.Object
  |
  +--java.net.RawPacket
Direct Known Subclasses:
IcmpPacket

public class RawPacket
extends java.lang.Object

This class represents a raw packet.

Raw packets are used to implement a connectionless raw packet delivery service. Each message is routed from one machine to another based solely on information contained within that packet. Multiple packets sent from one machine to another might be routed differently, and might arrive in any order.

Since:
JDK1.2

Constructor Summary
RawPacket(byte[] buf, int length)
          Constructs a RawPacket for receiving packets of length ilength.
RawPacket(byte[] buf, int length, InetAddress address)
          Constructs a raw packet for sending packets of length ilength on the specified host.
RawPacket(byte[] buf, int offset, int length)
          Constructs a RawPacket for receiving packets of length ilength.
RawPacket(byte[] buf, int offset, int length, InetAddress address)
          Constructs a raw packet for sending packets of length ilength on the specified host.
 
Method Summary
 InetAddress getAddress()
          Returns the IP address of the machine to which this packet is being sent or from which the packet was received.
 byte[] getData()
          Returns the data received or the data to be sent.
 int getLength()
          Returns the length of the data to be sent or the length of the data received.
 int getOffset()
          Returns the current position of the offset
 void setAddress(InetAddress iaddr)
           
 void setData(byte[] buf)
          Set the data in the packet
 void setData(byte[] buf, int offset, int length)
          Insert data of size length<\code> at offset offset<\code>.
 void setLength(int length)
          Set the length for this packet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RawPacket

public RawPacket(byte[] buf,
                 int length)
Constructs a RawPacket for receiving packets of length ilength.

The length argument must be less than or equal to ibuf.length.

Parameters:
buf - buffer for holding the incoming datagram.
length - the number of bytes to read.
Since:
JDK1.2

RawPacket

public RawPacket(byte[] buf,
                 int offset,
                 int length)
Constructs a RawPacket for receiving packets of length ilength.
Parameters:
buf - buffer for holding the incoming datagram.
offset - offset to put the data at.
length - the number of bytes to read.
Since:
JDK1.2

RawPacket

public RawPacket(byte[] buf,
                 int offset,
                 int length,
                 InetAddress address)
Constructs a raw packet for sending packets of length ilength on the specified host.
Parameters:
buf - the packet data.
length - the packet length.
offset - offset to put the data at.
addres - the destination address.
Since:
JDK1.2
See Also:
InetAddress

RawPacket

public RawPacket(byte[] buf,
                 int length,
                 InetAddress address)
Constructs a raw packet for sending packets of length ilength on the specified host.
Parameters:
buf - the packet data.
length - the packet length.
addres - the destination address.
Since:
JDK1.2
See Also:
InetAddress
Method Detail

getAddress

public InetAddress getAddress()
Returns the IP address of the machine to which this packet is being sent or from which the packet was received.
Returns:
the IP address of the machine to which this packet is being sent or from which the packet was received.
Since:
JDK1.2
See Also:
InetAddress

getData

public byte[] getData()
Returns the data received or the data to be sent.
Returns:
the data received or the data to be sent.
Since:
JDK1.2

getOffset

public int getOffset()
Returns the current position of the offset
Returns:
the offset that is curently used
Since:
JDK1.2

getLength

public int getLength()
Returns the length of the data to be sent or the length of the data received.
Returns:
the length of the data to be sent or the length of the data received.
Since:
JDK1.2

setData

public void setData(byte[] buf,
                    int offset,
                    int length)
Insert data of size length<\code> at offset offset<\code>.
Parameters:
buf - the data to insert
offset - the offset to put the data at
length - the length of the data to insert

setAddress

public void setAddress(InetAddress iaddr)
Since:
JDK1.2

setData

public void setData(byte[] buf)
Set the data in the packet
Parameters:
buf - the data to put in the packet

setLength

public void setLength(int length)
Set the length for this packet. The length of the packet is the number of bytes from the packet's data buffer that will be sent, or the number of bytes of the packet's data buffer that will be used for receiving data. The length must be lesser or equal to the length of the packet's buffer.
Parameters:
length - the length to set for this packet.
Throws:
java.lang.IllegalArgumentException - if the length is negative of if the length is greater than the packet's data buffer length.
Since:
JDK1.2
See Also:
getLength(), setData(byte[], int, int)