new IPv4Header(0, this.ttl, IPv4Constants.IPPROTO_ICMP, this.dst, 8);
netHeader.setDontFragment(this.dontFragment);
final IPv4NetworkLayer netLayer =
(IPv4NetworkLayer) NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_IP);
final ICMPProtocol icmpProtocol =
(ICMPProtocol) netLayer.getProtocol(ICMPProtocol.IPPROTO_ICMP);
icmpProtocol.addListener(this);
try {
int id_count = 0;
int seq_count = 0;
while (this.count != 0) {
out.format(fmt_ping, dst, seq_count);
if (!this.flood) {
this.wait = true;
}
SocketBuffer packet = new SocketBuffer();
packet.insert(this.size);
ICMPEchoHeader transportHeader = new ICMPEchoHeader(id_count, seq_count);
transportHeader.prefixTo(packet);
Request r =
new Request(this.stat, this.timeout, System.currentTimeMillis(), id_count,
seq_count);
registerRequest(r);
netLayer.transmit(netHeader, packet);
while (this.wait) {
long time = System.currentTimeMillis() - r.getTimestamp();
if (time > this.interval) {
this.wait = false;
}
Thread.sleep(500);
synchronized (this) {
if (response) {
out.format(fmt_reply,
dst.toString(), hdr1.getDataLength(), hdr1.getTtl(), hdr2.getSeqNumber(), roundt);
response = false;
}
}
}
this.count--;
seq_count++;
}
while (!isEmpty()) {
Thread.sleep(100);
}
} finally {
icmpProtocol.removeListener(this);
}
out.format(fmt_stats, this.stat.getStatistics());
}