I had a similar question and googled around until I
found the following ioctl. Hope this helps....
/* Try to find an entry in arp cache for the ip address specified */
printf("Find arp entry for IP : %s\n", ip);
sin = (struct sockaddr_in *) &arpreq.arp_pa;
memset(sin, 0, sizeof(struct sockaddr_in));
sin->sin_family = AF_INET;
ina.s_addr = inet_addr(ip);
memcpy(&sin->sin_addr, (char *)&ina, sizeof(struct in_addr));
strcpy(arpreq.arp_dev, "eth0");
arpreq.arp_ha.sa_family = AF_UNSPEC;
/*
rc = ioctl(sd, SIOCGARP, &arpreq);
if (rc < 0)
{
perror("Entry not available in cache. Sending arp req...\n");
send_arp_req(ip);
rc = ioctl(sd, SIOCGARP, &arpreq);
if (rc < 0)
{
printf("No arp reply. \n");
exit(1);
}
}
*/
send_arp_req(ip);
rc = ioctl(sd, SIOCGARP, &arpreq);
if (rc < 0)
{
printf("No arp reply. \n");
exit(1);
}
hw_addr = (unsigned char *) arpreq.arp_ha.sa_data;
printf("HWAddr found : %x:%x:%x:%x:%x:%x\n", hw_addr[0],
hw_addr[1], hw_addr[2], hw_addr[3], hw_addr[4], hw_addr[5]);
return 1;
}
void send_arp_req(char *ip_addr)
{
/* Sending the arp Request here */
}
Dirk Förster wrote:
> Hi all,
>
> I have an IP Address, and I'm sure, that the corresponding MAC Address
> is inside the ARP cache.
> Is there a C-Function to get the MAC Address?
>
> Regards
> Dirk
>
|