Broadcast on each interface now works, at least for OSX.

This commit is contained in:
gardners 2011-08-12 09:58:25 +02:00
parent b8e8a78828
commit 9108fd5c59
2 changed files with 17 additions and 14 deletions

8
dna.c
View File

@ -262,12 +262,8 @@ int usage(char *complaint)
fprintf(stderr," -G - Offer gateway services. Argument specifies locations of necessary files.\n"); fprintf(stderr," -G - Offer gateway services. Argument specifies locations of necessary files.\n");
fprintf(stderr," Use -G [potato|android|custom:...] to set defaults for your device type.\n"); fprintf(stderr," Use -G [potato|android|custom:...] to set defaults for your device type.\n");
fprintf(stderr," -N - Specify one or more interfaces for the DNA overlay mesh to operate.\n"); fprintf(stderr," -N - Specify one or more interfaces for the DNA overlay mesh to operate.\n");
fprintf(stderr," Interface specifications take the form IP[:speed[:type[:port]]], and\n"); fprintf(stderr," Interface specifications take the form <+|->[interface[=type][,...]\n");
fprintf(stderr," multiple interfaces can be specified by comma separating them.\n"); fprintf(stderr," e.g., -N -en0,+ to use all interfaces except en0\n");
fprintf(stderr," Speed is the interface speed in bits per second (K,M or G suffixes allowed)\n");
fprintf(stderr," Type is WiFi,ethernet,catear or other.\n");
fprintf(stderr," Port specifies an alternate UDP port, otherwise %d is used.\n",PORT_DNA);
fprintf(stderr," e.g., -N 10.1.2.3,10.1.130.45:2M:wifi\n");
fprintf(stderr,"\n"); fprintf(stderr,"\n");
exit(-1); exit(-1);
} }

View File

@ -178,7 +178,7 @@ int overlay_interface_init(char *name,struct sockaddr_in src_addr,struct sockadd
I(mtu)=1200; I(mtu)=1200;
I(bits_per_second)=speed_in_bits; I(bits_per_second)=speed_in_bits;
I(port)=ntohs(src_addr.sin_port); I(port)=port;
I(type)=type; I(type)=type;
I(tick_ms)=500; I(tick_ms)=500;
switch(type) { switch(type) {
@ -235,6 +235,7 @@ int overlay_broadcast_ensemble(int interface_number,unsigned char *bytes,int len
memset(&s, '\0', sizeof(struct sockaddr_in)); memset(&s, '\0', sizeof(struct sockaddr_in));
s = overlay_interfaces[interface_number].broadcast_address; s = overlay_interfaces[interface_number].broadcast_address;
s.sin_family = AF_INET; s.sin_family = AF_INET;
fprintf(stderr,"Port=%d\n",overlay_interfaces[interface_number].port);
s.sin_port = htons( overlay_interfaces[interface_number].port ); s.sin_port = htons( overlay_interfaces[interface_number].port );
if(sendto(overlay_interfaces[interface_number].socket, bytes, len, 0, (struct sockaddr *)&s, sizeof(struct sockaddr_in)) < 0) if(sendto(overlay_interfaces[interface_number].socket, bytes, len, 0, (struct sockaddr *)&s, sizeof(struct sockaddr_in)) < 0)
@ -430,23 +431,29 @@ int overlay_check_ticks()
struct timeval nowtv; struct timeval nowtv;
long long now; long long now;
/* Check for changes to interfaces */
overlay_interface_discover();
if (gettimeofday(&nowtv,NULL)) if (gettimeofday(&nowtv,NULL))
return WHY("gettimeofday() failed"); return WHY("gettimeofday() failed");
/* Get current time in milliseconds */ /* Get current time in milliseconds */
now=nowtv.tv_sec*1000; now=nowtv.tv_sec*1000;
now=now+nowtv.tv_usec/1000; now=now+nowtv.tv_usec/1000;
/* Now check if the next tick time for the interfaces is no later than that time. /* Now check if the next tick time for the interfaces is no later than that time.
If so, trigger a tick on the interface. */ If so, trigger a tick on the interface. */
for(i=0;i<overlay_interface_count;i++) for(i=0;i<overlay_interface_count;i++)
{ {
if (now>=overlay_interfaces[i].last_tick_ms+overlay_interfaces[i].tick_ms) /* Only tick live interfaces */
{ if (overlay_interfaces[i].observed>0)
/* This interface is due for a tick */ if (now>=overlay_interfaces[i].last_tick_ms+overlay_interfaces[i].tick_ms)
overlay_tick_interface(i,now); {
overlay_interfaces[i].last_tick_ms=now; /* This interface is due for a tick */
} overlay_tick_interface(i,now);
overlay_interfaces[i].last_tick_ms=now;
}
} }
return 0; return 0;