What port is ping?

What port does ping use?

This seems like a simple question, but I cannot find a definitive answer.

Linux manual page for ping mentions an ECHO_REQUEST datagram:

"Ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams (``pings'') have an IP and ICMP header, followed by a ``struct timeval'' and then an arbitrary number of ``pad'' bytes used to fill out the packet."

I searched the include directory and found this C preprocessor define:
/usr/include/netinet/icmp6.h
#define ICMP6_ECHO_REQUEST 128

What I'm trying to do is write a ping program in Java, if that's at all possible. I know that the standard ping uses the ICMP (Internet Control Message Protocol) which is a low-level network administration protocol not supported in Java nor in Microsoft's Winsock. ICMP on Win32 is provided by an unsupported and undocumented library icmp.dll. I also know that it's sending an ICMP datagram.

However, all ping does is simply send a message to the host and report if it arrived. That takes all of three lines of code in Java. But, it's not working for most of the hosts I've tried where the standard ping program does. I keep getting an exception of "Connection refused" every time.

These are the port numbers I've tried:

7 Echo service
13 Daytime
23 Telnet
128 ICMP6_ECHO_REQUEST

There may be some other reason why my Java ping program fails where the standard ping succeeds, but trying every possible port number with a range of hosts is impractical. By knowing definitively what port ping uses, I can eliminate the other factors.

I'm asking this question in the Java area because I think the answer would benefit this community most, not because I think a Java expert would necessarily know the answer (I may be wrong, if so I apologize). So, I've referenced this question in several other topic areas.

as you already know ICMP is low-level network protocol, which is not directly supported in Java.

in Java you can use TCP packets and UDP datagrams - both of them are relatively hi-level (and work over IP) (for TCP connection you need not only working network connection, but remote server app that listens on some port)

(Sect. 15) How can I write the "ping" program?
You can't do it directly. Quoting from the Java Networking FAQ,
Ping requires ICMP packets. These packets can only be created via a socket of the SOCK_RAW type. Currently, Java only allows SOCK_STREAM (TCP) and SOCK_DGRAM (UDP) sockets. It seems unlikely that this will be added very soon, since many Unix versions only allow SOCK_RAW sockets to be created by root, and winsock does not address ICMP packets (win32 includes an unsupported and undocumented ICMP.DLL).
You could write a program that handshakes with a remote system, to simulate ping, or you could use native code for the raw socket. Other sites:
You can find the Java Networking FAQ at http://www.io.com/~maus/JavaNetworkingFAQ.html
There is an additional Java Networking FAQ (which is being modified and reposted regularly) at http://www.davidreilly.com/java/java_network_programming/

Packet InterNet Groper (sorry, just found out the name, so had to use it) is handled before/below it ever gets to a port.

0

ArtimageCommented: 1999-12-06

I actually wrote this code.

Here is the java part.

/*
This was written by Artimage@ishiboo.com for Appnet.com

This software (and its source code) are freely usable, modifiable,
and redistributable under the terms of the GNU General Public License,
available at http://www.gnu.org/copyleft/gpl.html, and in the ./COPYING
file in the MARS distribution.
*/

/* Probes the host, returns the result. The results should be interpreted
as follows: true means the probe is OK (set status to Host.OK), false
means the probe has timed out (set status to Host.TO), and if an
exception is thrown, the probe failed outright (set status to Host.FAIL)
*/

Yah, I noticed it too after reading more of my e-mail. Not everyone is understands the reason for thread referencing. You do that so that experts in other threads can all contribute to a single thread in the most proper topic area. No one's supposed to comment on those zero point referencing threads. They're supposed to comment in only the original thread (this one). It makes for a more valuable PAQ.

Once the original thread becomes a PAQ, the referencing threads should be deleted.