Neilvert Noval
Neilvert Noval

Reputation: 1695

How to do IP walk in C

my computer's IP is 192.168.1.101 over eth0.
I want to know what are other active/used IP under 192.168.1.*
I am expecting a list of IP address that is ping-able under 192.168.1.*
How can I do that in C? And preferably in linux platform.
Any C functions available?

Upvotes: 0

Views: 253

Answers (1)

x13n
x13n

Reputation: 4153

There is no built-in function in C that sends ping packet. There is, however, function that just sends packet. There is also a lot of code in the internet that already implements ping.

What you have to do is just take one of them (this for example) and ping in a loop for all addresses in your network.

You should know, however, that ping is not a reliable way of saying which addresses are in use. RFC 792 - Internet Control Message Protocol says:

The Internet Protocol is not designed to be absolutely reliable. The purpose of these control messages is to provide feedback about problems in the communication environment, not to make IP reliable. There are still no guarantees that a datagram will be delivered or a control message will be returned. Some datagrams may still be undelivered without any report of their loss.

which means that any message can be easily lost, with no notification. Furthermore, target does not have to respond.

Upvotes: 1

Related Questions