Note that “reachability” on IP networks is kind of tricky to test for.
It’s perfectly possible that a server machine is running any number of real services (www, ftp, whatever), but has been configured not to reply to pings since some people do that.
If possible, it’s better to just connect like the real service you want to check for.
2
solved How to check if an ip-address is reachable in C for linux [closed]