The following commit has been merged in the master branch: commit 49ae6131bee14aebb3c19e0833b4f8085158f0f0 Author: Simon Wunderlich siwu@hrz.tu-chemnitz.de Date: Thu Jan 25 21:23:54 2007 +0100
- add htons() and ntohs() for seqno, we want endianess compatibility!! - change originator_interval to unsigned long which makes no difference on 32bit, but removes nasty compiler warnings when checking for LONG_MIN and LONG_MAX. (long is 64bit on amd64)
diff --git a/batman.c b/batman.c index ed23613..3b36154 100644 --- a/batman.c +++ b/batman.c @@ -82,7 +82,7 @@ short gateway_class = 0; short routing_class = 0;
-unsigned int orginator_interval = 1000; /* orginator message interval in miliseconds */ +unsigned long orginator_interval = 1000; /* orginator message interval in miliseconds */
unsigned int bidirectional_timeout = 0; /* bidirectional neighbour reply timeout in ms */
diff --git a/batman.h b/batman.h index 0c1dc60..901b715 100644 --- a/batman.h +++ b/batman.h @@ -65,7 +65,7 @@ extern short debug_level; extern short gateway_class; extern short routing_class; extern short num_hna; -extern unsigned int orginator_interval; +extern unsigned long orginator_interval; extern unsigned int pref_gateway;
extern unsigned char *hna_buff; diff --git a/posix-specific.c b/posix-specific.c index 316ef60..41464ed 100644 --- a/posix-specific.c +++ b/posix-specific.c @@ -443,7 +443,7 @@ void apply_init_args( int argc, char *argv[] ) { errno = 0; orginator_interval = strtol (optarg, NULL , 10);
- if ( (errno == ERANGE && (orginator_interval == LONG_MAX || orginator_interval == LONG_MIN) ) || (errno != 0 && orginator_interval == 0) ) { + if ( (errno == ERANGE && ((orginator_interval == LONG_MAX) || (orginator_interval == LONG_MIN)) ) || (errno != 0 && orginator_interval == 0) ) { perror("strtol"); exit(EXIT_FAILURE); } @@ -1287,6 +1287,7 @@ int receive_packet( unsigned char *packet_buff, int packet_buff_len, int *hna_bu struct timeval tv; struct list_head *if_pos; struct batman_if *batman_if; + struct packet *p;
tv.tv_sec = timeout / 1000; @@ -1336,8 +1337,11 @@ int receive_packet( unsigned char *packet_buff, int packet_buff_len, int *hna_bu
if ( *hna_buff_len < sizeof(struct packet) ) return 0; + p = (struct packet *) packet_buff; + p->seqno = ntohs(p->seqno); /* network to host order for our 16bit seqno. + * ip adress shall remain in network order, + * so we don't swap bytes for p->orig. */
- packet_buff[*hna_buff_len] = '\0';
(*if_incoming) = batman_if; break; @@ -1356,6 +1360,9 @@ int receive_packet( unsigned char *packet_buff, int packet_buff_len, int *hna_bu
int send_packet(unsigned char *buff, int len, struct sockaddr_in *broad, int sock) { + struct packet *p; + p=(struct packet *)buff; + p->seqno = htons(p->seqno); /* change sequence number to network order. ip address(es) remain in network order */
if ( sendto( sock, buff, len, 0, (struct sockaddr *)broad, sizeof (struct sockaddr_in) ) < 0 ) {