The following commit has been merged in the master branch: commit 07f23f2f5719906e07f897faaaf13c39485f0dbf Author: Marek Lindner lindner_marek@yahoo.de Date: Sun Oct 1 20:40:22 2006 +0200
bind to interface implemented
diff --git a/bsd.c b/bsd.c index 730434c..18c1db0 100644 --- a/bsd.c +++ b/bsd.c @@ -78,6 +78,12 @@ int get_forwarding(void) return state; }
+int bind_to_iface( int udp_recv_sock, char *dev ) { + + return 1; + +} + /* Message structure used to interface the kernel routing table. * See route(4) for details on the message passing interface for * manipulating the kernel routing table. diff --git a/linux.c b/linux.c index dd96969..e5fa92e 100755 --- a/linux.c +++ b/linux.c @@ -67,6 +67,22 @@ int get_forwarding(void) return state; }
+int bind_to_iface( int udp_recv_sock, char *dev ) { + + if ( setsockopt( udp_recv_sock, SOL_SOCKET, SO_BINDTODEVICE, dev, strlen ( dev ) + 1 ) < 0 ) + { + if ( errno == 19 ) { + fprintf( stderr, "Warning: Cannot bind socket to alias device %s\n", dev ); + } else { + fprintf( stderr, "Cannot bind socket to device %s : %s \n", dev, strerror(errno) ); + return -1; + } + } + + return 1; + +} + void add_del_route(unsigned int dest, unsigned int router, int del, char *dev, int sock) { struct rtentry route; diff --git a/os.h b/os.h index 95ecdf7..dce6861 100755 --- a/os.h +++ b/os.h @@ -35,6 +35,7 @@ void addr_to_string(unsigned int addr, char *str, int len); int receive_packet(unsigned char *buff, int len, unsigned int *neigh, unsigned int timeout, struct batman_if **if_incoming); int send_packet(unsigned char *buff, int len, struct sockaddr_in *broad, int sock); int rand_num(int limit); +int bind_to_iface( int udp_recv_sock, char *dev ); int probe_tun(); int del_ipip_tun( int fd ); int add_ipip_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun_dev, int *fd ); diff --git a/posix.c b/posix.c index d9ce121..f7d6ba4 100644 --- a/posix.c +++ b/posix.c @@ -432,7 +432,7 @@ void *gw_listen( void *arg ) {
gw_client->last_keep_alive = get_time();
- if ( debug_level >= 2 ) { + if ( debug_level >= 1 ) { addr_to_string(gw_client->addr.sin_addr.s_addr, str2, sizeof (str2)); printf( "gateway: client %s sent keep alive on interface %s\n", str2, batman_if->dev ); } @@ -712,6 +712,13 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); }
+ if ( bind_to_iface( batman_if->udp_recv_sock, batman_if->dev ) < 0 ) { + + close_all_sockets(); + exit(EXIT_FAILURE); + + } + if (bind(batman_if->udp_recv_sock, (struct sockaddr *)&batman_if->broad, sizeof (struct sockaddr_in)) < 0) { fprintf(stderr, "Cannot bind receive socket: %s\n", strerror(errno));