curl-library
Re: How to ping IP using libcurl?
Date: Sun, 11 Nov 2012 00:01:30 +0200
>
> On 09-11-12 14:51, JALINDAR wrote:
> > Hi Forum,
> >
> > I want to ping IP addresses and grab the respond to save it if it
> > is received within the time bound.
> > It must be similar to command line ping.
> >
> > how should I do it?
>
As already responded, libcurl does not implement ping functionality as it
implements mostly (if not only) application level (in OSI) protocols like
FTP, HTTP, etc.
Here is some key info based on experience:
I assume you mean the ping functionality which is consisting of echo
request (ICMP message type 8) and echo reply (ICMP message type 0) messages
based on the ICMP protocol. ICMP protocol is a layer 3 (internet layer)
protocol like IP, so no "port" information is involved.
To implement a ping functionality yourself, you need:
1. to use a raw socket to be able to send ICMP requests and receive ICMP
replies which requires admin privileges on most of the systems.
2. to be able to distinguish between the echo replies by inspecting the
received packets yourself if more than one IP is pinged at a time. It is
different than UDP/TCP based protocol programming, since there is no "port"
information whenever an ICMP echo reply is received, all of the sockets
waiting for readability for an echo reply will be notified!!
For the 2nd item, here is an example.
Suppose you send echo requests to IP addresses A and B, with sockets a and
b. Then you called the select() on the sockets on the same thread or on
different threads. Whenever one echo reply is received from either of the
IP addresses, your both sockets will be readable, therefore notified!!! So
you will not have a chance to understand which IP address you got the echo
reply other than looking at the target IP information in the packet you
received. This was the biggest challenge in implementing a ping framework
myself.
I know this is libcurl mailing list and sorry for the adding a little more
out-of-scope content.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-11-10