hello folk
Iam tring to develop C code to get MAC address from ARP cache after adding entry on it, can some body give me simple code or try correct this one
Code:
#include <string.h>
#include <net/if_arp.h>
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <strings.h>
#include <stdlib.h>
int sock,sockfd,n,s,count;
char comand [61];//to handle arping command
int main(int argc, char **argv) {
struct sockaddr_in sin;
struct arpreq myarp;
strcpy(myarp.arp_dev , "eth0");
if(inet_aton(argv[1],&sin.sin_addr)==0){//obtain Next Router IP
printf("%s: IP address not valid\n",argv[1]);
exit(0);
}//if
memcpy(&myarp.arp_pa,&sin,sizeof sin);//for arp cache
count =0;//cache counter
while((ioctl(sockfd,SIOCGARP,&myarp)==-1)&&(count <=1)){//Get MAC from cache
sprintf(comand ,"arping -I eth0 %s -c 1>/dev/null ",argv[1]);
system(comand);//execute ARPING Command
count++;
}//arp while
}