The following commit has been merged in the master branch: commit e803d634cdc6d7ead93d03cc55b18dde195409de Author: Stefan Sperling stsp@stsp.in-berlin.de Date: Wed Sep 20 20:50:28 2006 +0200
Refactor check for tun device availability into probe_tun() routine for portability.
diff --git a/freebsd.c b/freebsd.c index c490df1..e799aee 100644 --- a/freebsd.c +++ b/freebsd.c @@ -184,7 +184,8 @@ void add_del_route(unsigned int dest, unsigned int router, int del, }
-int del_ipip_tun(int fd) { +int del_ipip_tun(int fd) +{ return 1; }
@@ -193,3 +194,7 @@ int add_ipip_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun return 0; }
+int probe_tun() +{ + return 1; +} diff --git a/linux.c b/linux.c index 54309f8..ca0896d 100755 --- a/linux.c +++ b/linux.c @@ -113,6 +113,18 @@ void add_del_route(unsigned int dest, unsigned int router, int del, char *dev, i } }
+/* Probe for tun interface availability */ +int probe_tun() +{ + if ( ( fd = open( "/dev/net/tun", O_RDWR ) ) < 0 ) { + + fprintf( stderr, "Error - could not open '/dev/net/tun' ! Is the tun kernel module loaded ?\n" ); + close_all_sockets(); + return 0; + } + return 1; +} + int del_ipip_tun( int fd ) {
if ( ioctl( fd, TUNSETPERSIST, 0 ) < 0 ) { diff --git a/posix.c b/posix.c index 67f9d45..790594e 100644 --- a/posix.c +++ b/posix.c @@ -804,14 +804,9 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); }
- if ( ( fd = open( "/dev/net/tun", O_RDWR ) ) < 0 ) { - - fprintf( stderr, "Error - could not open '/dev/net/tun' ! Is the tun kernel module loaded ?\n" ); - close_all_sockets(); + if(!probe_tun()) exit(EXIT_FAILURE);
- } - close( fd );