|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.dalsemi.tininet.icmp.Ping
Ping provides a TINI Java application the ability to send ICMP echo request and read the raw ICMP response. When a machine receives an ICMP echo request from a remote host it responds with an ICMP echo reply message that contains an exact copy of the request packet.
Ping allows an application to programmatically determine whether a particular service running on a remote host has died or whether the host machine itself has become unreachable on the network.
InetAddress addr = InetAddress.getByName("www.dalsemi.com");
boolean response = Ping.pingNode(addr);
System.out.println(response ? "Got reply from node" : "Node was unreachable");
Field Summary | |
static byte |
DEFAULT_TTL
Field DEFAULT_TTL |
Method Summary | |
static boolean |
pingNode(InetAddress addr)
Transmit a single ICMP echo request packet to a node. |
static long |
pingNode(InetAddress addr,
byte ttl,
byte[] response)
Transmit a single ICMP echo request packet to a node. |
static int |
pingNode(InetAddress addr,
int count)
Transmit multiple ICMP echo request packets to a node. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final byte DEFAULT_TTL
Method Detail |
public static int pingNode(InetAddress addr, int count)
addr
- ip address to be pingedcount
- number of times to pingInetAddress
public static boolean pingNode(InetAddress addr)
addr
- ip address to be pingedInetAddress
public static long pingNode(InetAddress addr, byte ttl, byte[] response)
Transmit a single ICMP echo request packet to a node.
This version of pingNode
requires two additional parameters:
the ttl byte specifying the time to live field in the IP datagram header
of the oubound ICMP echo request and a byte array which is filled in with
entire IP datagram received in response to the echo request. The method
returns the time, measured in milliseconds, between transmitting the
ICMP echo request message and receiving a response. If no response is
received prior to the time-out period pingNode
returns -1.
The round trip time (RTT) estimate is measured in the native network
stack and is therefore reasonably (within a few milliseconds) accurate.
Any inaccuracy is on the high side and therefore the return value of
pingNode
provides an upper bound on the true round trip time.
As mentioned the response buffer receives the entire IP datagram containing
the echo request response. Within the buffer the ICMP header and ICMP data are
located after the IP header and can be located by calculating the IP header
length as int ipHdrLength = (response[0] & 0x0f) << 2);
. Using the
IP header length as an offset the first field of the ICMP header, ICMP packet type,
can be accessed as int type = response[ipHdrLength];
ICMP is specified in RFC 792
addr
- ip address to be pingedttl
- Time To Live (hop count) used in the IP headerresponse
- buffer filled in with the repsonse, the
length of the array should be >= 128InetAddress
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |