Actually, I would go in a different direction.. ping can be useful, but so often is ICMP Echo blocked by firewalls.
Why not use ARP instead? there are a few portable utilities out there.. in C.
ARPing
ARP Tools
The first is in OpenBSD ports, the second.. isn't... it also includes some, spoofing utilities.. but the arpdiscover program should be adequate.
Both use libpcap and libnet, the latter being in ports.. the former in base (usually..)