* Track MAC addresses in the client cache (when we can find them); so if we have an expired cache entry, but the MAC hasn't changed, we can assume the original ID is still valid.

This commit is contained in:
Justin Maggard
2009-07-31 01:41:10 +00:00
parent 780ae7ad8b
commit 51e61e3973
4 changed files with 66 additions and 7 deletions

View File

@ -127,3 +127,38 @@ getifhwaddr(const char * ifname, char * buf, int len)
}
return 0;
}
int
get_remote_mac(struct in_addr ip_addr, unsigned char * mac)
{
struct in_addr arp_ent;
FILE * arp;
char remote_ip[16];
int matches, hwtype, flags;
memset(mac, 0xFF, 6);
arp = fopen("/proc/net/arp", "r");
if( !arp )
return 1;
while( !feof(arp) )
{
matches = fscanf(arp, "%s 0x%X 0x%X %hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
remote_ip, &hwtype, &flags,
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
if( matches != 9 )
continue;
inet_pton(AF_INET, remote_ip, &arp_ent);
if( ip_addr.s_addr == arp_ent.s_addr )
break;
mac[0] = 0xFF;
}
fclose(arp);
if( mac[0] == 0xFF )
{
memset(mac, 0xFF, 6);
return 1;
}
return 0;
}