mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-07 11:08:36 +00:00
added parsing of arp table to find peers in the face of transient loss
of broadcast reception by peers.
This commit is contained in:
parent
45dcebc048
commit
cd346861d1
41
batman.c
41
batman.c
@ -90,6 +90,47 @@ int readRoutingTable(struct in_addr peers[],int *peer_count,int peer_max){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int readArpTable(struct in_addr peers[],int *peer_count,int peer_max){
|
||||
char devname[64];
|
||||
unsigned long d;
|
||||
int q1,q2,q3,q4;
|
||||
|
||||
if (debug) fprintf(stderr,"Reading ARP table\n");
|
||||
|
||||
FILE *fp = fopen("/proc/net/arp","r");
|
||||
if (!fp) return -1;
|
||||
|
||||
fprintf(stderr,"Skipping line\n");
|
||||
if (fscanf(fp, "%*[^\n]\n") < 0)
|
||||
goto ERROR;
|
||||
|
||||
while(1){
|
||||
int r;
|
||||
if (debug>1) fprintf(stderr,"Reading next arp entry\n");
|
||||
r = fscanf(fp, "%d.%d.%d.%d",
|
||||
&q1,&q2,&q3,&q4);
|
||||
|
||||
d = (q1&0xff)
|
||||
+((q2&0xff)<<8)
|
||||
+((q3&0xff)<<16)
|
||||
+((q4&0xff)<<24);
|
||||
|
||||
if (r != 4) {
|
||||
if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */
|
||||
if (debug>1) fprintf(stderr,"eof\n");
|
||||
break;
|
||||
}
|
||||
ERROR:
|
||||
fclose(fp);
|
||||
return setReason("Unable to parse arp table");
|
||||
}
|
||||
|
||||
if (*peer_count<peer_max) peers[(*peer_count)++].s_addr=d;
|
||||
}
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int readBatmanPeerFile(char *file_path,struct in_addr peers[],int *peer_count,int peer_max)
|
||||
{
|
||||
/* Shiny new code to read the flat file containing peer list */
|
||||
|
3
peers.c
3
peers.c
@ -170,6 +170,9 @@ int getPeerList()
|
||||
getBatmanPeerList(batman_socket,peers,&peer_count,MAX_PEERS);
|
||||
else
|
||||
readRoutingTable(peers,&peer_count,MAX_PEERS);
|
||||
/* Read ARP table for good measure as a defence against transient loss of broadcast reception,
|
||||
e.g., when screens go off on phones. */
|
||||
readArpTable(peers,&peer_count,MAX_PEERS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user