На всякий случай отстальная часть кода
(к логике работы самого icmp не относится).
#include <error.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <resolv.h>
#include <netinet/ip_icmp.h>
#define PACKETSIZE 64
void usage()
{
printf("USAGE:\t prog_name <IP_address>\n");
exit(1);
}
int main(int argc, char *argv[])
{
if(argv[1] == NULL)
usage();
if (ping(argv[1]) > 0)
printf("PING\t\tOK\n");
else
printf("PING\t\tNO_ANSWER\n");
return 0;
}