mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 01:42:18 +00:00
Adding more robust broadcast address detection.
This commit is contained in:
parent
3e58d867b7
commit
70b287a1c9
9
batman.c
9
batman.c
@ -58,14 +58,14 @@ int readRoutingTable(struct in_addr peers[],int *peer_count,int peer_max){
|
||||
|
||||
while(1){
|
||||
int r;
|
||||
fprintf(stderr,"Reading next route\n");
|
||||
if (debug>1) fprintf(stderr,"Reading next route\n");
|
||||
r = fscanf(fp, "%63s%lx%lx%X%d%d%d%lx%d%d%d\n",
|
||||
devname, &d, &g, &flgs, &ref, &use, &metric, &m,
|
||||
&mtu, &win, &ir);
|
||||
|
||||
if (r != 11) {
|
||||
if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */
|
||||
fprintf(stderr,"eof\n");
|
||||
if (debug>1) fprintf(stderr,"eof\n");
|
||||
break;
|
||||
}
|
||||
ERROR:
|
||||
@ -79,8 +79,9 @@ int readRoutingTable(struct in_addr peers[],int *peer_count,int peer_max){
|
||||
}
|
||||
|
||||
if (m!=0xFFFFFFFF){
|
||||
if (debug>1) fprintf(stderr,"Skipping non host route to %d\n",(int)d);
|
||||
continue; // only include host routes, TODO pickup any networks and send them broadcasts...
|
||||
/* Netmask indicates a network, so calculate broadcast address */
|
||||
unsigned int d=(d&m)|(0xffffffff^m);
|
||||
if (debug>1) fprintf(stderr,"Adding broadcast address %08x\n",d);
|
||||
}
|
||||
|
||||
if (*peer_count<peer_max) peers[(*peer_count)++].s_addr=d;
|
||||
|
7
peers.c
7
peers.c
@ -60,7 +60,7 @@ int getBroadcastAddresses(struct in_addr peers[],int *peer_count,int peer_max){
|
||||
size_t bytesRead;
|
||||
struct nlmsghdr *hdr;
|
||||
|
||||
if (debug>1) fprintf(stderr,"Reading broadcast addresses\n");
|
||||
if (debug>1) fprintf(stderr,"Reading broadcast addresses (linux style)\n");
|
||||
|
||||
netsock = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
|
||||
|
||||
@ -110,6 +110,8 @@ int getBroadcastAddresses(struct in_addr peers[],int *peer_count,int peer_max){
|
||||
struct ifaddrs *ifaddr,*ifa;
|
||||
int family;
|
||||
|
||||
if (debug>1) fprintf(stderr,"Reading broadcast addresses (posix style)\n");
|
||||
|
||||
if (getifaddrs(&ifaddr) == -1) {
|
||||
perror("getifaddr()");
|
||||
return WHY("getifaddrs() failed");
|
||||
@ -132,7 +134,8 @@ int getBroadcastAddresses(struct in_addr peers[],int *peer_count,int peer_max){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
if (debug>1) fprintf(stderr,"Don't know how to read broadcast addresses :(\n");
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user