java.net
Class IcmpSocket

java.lang.Object
  |
  +--java.net.RawSocket
        |
        +--java.net.IcmpSocket

public class IcmpSocket
extends RawSocket

This class represents a socket for sending and receiving Icmp packets.

An Icmp socket is the sending or receiving point for a packet delivery service. Each packet sent or received on a datagram socket is individually addressed and routed. Multiple packets sent from one machine to another may be routed differently, and may arrive in any order.

Since:
JDK1.2
See Also:
RawPacket

Constructor Summary
IcmpSocket()
          Creates an Icmp socket.
IcmpSocket(InetAddress laddr)
          Creates an Icmp socket, bound to the specified local address.
 
Method Summary
 void close()
          Closes this Icmp socket.
 void receive(IcmpPacket p)
          Receives an Icmp packet from this socket.
 void receive(RawPacket p)
          This method overrides the one of the RawSocket class.
 void send(IcmpPacket p)
          Sends an Icmp packet from this socket.
 void send(RawPacket p)
          This method overrides the one of the RawSocket class.
 void setChecksum(int offset)
          This method overrides the one of the RawSocket class.
 
Methods inherited from class java.net.RawSocket
getChecksum, getFlowLabel, getLocalAddress, getNetAuthenticate, getNetEncryption, getReceiveBufferSize, getSendBufferSize, getSoTimeout, getTrafficClass, getTransportAuthenticate, getTransportEncryption, setFlowLabel, setNetAuthenticate, setNetEncryption, setReceiveBufferSize, setSendBufferSize, setSoTimeout, setTrafficClass, setTransportAuthenticate, setTransportEncryption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IcmpSocket

public IcmpSocket()
           throws java.net.SocketException
Creates an Icmp socket.
Since:
JDK1.2
See Also:
RawSocket

IcmpSocket

public IcmpSocket(InetAddress laddr)
           throws java.net.SocketException
Creates an Icmp socket, bound to the specified local address.
Parameters:
laddr - local address to bind
Since:
JDK1.2
See Also:
RawSocket
Method Detail

send

public void send(IcmpPacket p)
          throws java.io.IOException
Sends an Icmp packet from this socket. The IcmpPacket includes information indicating the data to be sent, its length, the IP address of the remote host.
Parameters:
p - the IcmpPacket to be sent.
Throws:
java.io.IOException - if an I/O error occurs.
Since:
JDK1.2
See Also:
IcmpPacket

send

public void send(RawPacket p)
          throws java.io.IOException
This method overrides the one of the RawSocket class. It throws an IOException to prevent people from hacking the protocol.
Overrides:
send in class RawSocket
Throws:
java.io.IOException -  
Since:
JDK1.2
See Also:
RawSocket

receive

public void receive(IcmpPacket p)
             throws java.io.IOException
Receives an Icmp packet from this socket. When this method returns, the IcmpPacket's buffer is filled with the data received. The Icmp packet also contains the sender's IP address, and the type and code of the packet.

This method blocks until a datagram is received. The length field of the datagram packet object contains the length of the received message. If the message is longer than the buffer length, the message is truncated.

Parameters:
p - the IcmpPacket into which to place the incoming data.
Throws:
java.io.IOException - if an I/O error occurs.
Since:
JDK1.2
See Also:
IcmpPacket, RawSocket

receive

public void receive(RawPacket p)
             throws java.io.IOException
This method overrides the one of the RawSocket class. It throws an IOException to prevent people from hacking the protocol.
Overrides:
receive in class RawSocket
Throws:
java.io.IOException -  
Since:
JDK1.2
See Also:
RawSocket

setChecksum

public void setChecksum(int offset)
                 throws java.net.SocketException
This method overrides the one of the RawSocket class. It throws an IOException to prevent people from hacking the protocol.
Overrides:
setChecksum in class RawSocket
Throws:
java.net.SocketException -  
Since:
JDK1.2
See Also:
RawSocket

close

public void close()
Closes this Icmp socket.
Overrides:
close in class RawSocket
Since:
JDK1.2