Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!spool.mu.edu!howland.erols.net!newsfeed.internetmci.com!news.mathworks.com!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news
From: j@uriah.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: tun device not available.....
Date: 18 Aug 1996 07:48:59 GMT
Organization: Private BSD site, Dresden
Lines: 79
Message-ID: <4v6htb$8v@uriah.heep.sax.de>
References: <4v3f8e$u8a@news3.realtime.net>
<840326864.8170.0@arg1.demon.co.uk>
Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
NNTP-Posting-Host: localhost.heep.sax.de
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: knews 0.9.6
X-Phone: +49-351-2012 669
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E
Andrew Gordon <andrew.gordon@net-tel.co.uk> wrote:
> If you look at the source, you will observe that src/sys/usr.sbin/ppp/os.c
> doesn't cope with more than 10 devices. The following patch (untested) might
> fix this - try it and see:
Uh-oh, now i know why i haven't seen it -- i was looking into
-current, and this problem has been fixed there (but without mention
in the cvs log).
So here's the fix from -current, just FYI. (Trimmed down to the tun
unit# fix only.)
Index: os.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/ppp/os.c,v
retrieving revision 1.3.4.2
retrieving revision 1.7
diff -u -u -r1.3.4.2 -r1.7
--- os.c 1996/06/03 21:39:23 1.3.4.2
+++ os.c 1996/06/03 21:35:21 1.7
@@ -255,28 +255,39 @@
/*
* Open tunnel device and returns its descriptor
*/
+
+#define MAX_TUN 256
+/* MAX_TUN is set at an arbitrarily large value *
+ * as the loop aborts when it reaches the first *
+ * 'Device not configured' (ENXIO), or the third *
+ * 'No such file or directory' (ENOENT) error. */
int
OpenTunnel(ptun)
int *ptun;
{
int s;
- char *cp;
- char *suffix = "0123456789";
char ifname[IFNAMSIZ];
- char devname[12];
+ char devname[14]; /* sufficient room for "/dev/tun65535" */
+ unsigned unit, enoentcount=0;
- strcpy(devname, "/dev/tun0");
- for (cp = suffix; *cp; cp++) {
- devname[8] = *cp;
+ for( unit=0; unit <= MAX_TUN ; unit++ ) {
+ sprintf( devname, "/dev/tun%d", unit );
tun_out = open(devname, O_RDWR);
- if (tun_out >= 0)
- break;
+ if( tun_out >= 0 )
+ break;
+ if( errno == ENXIO )
+ unit=MAX_TUN+1;
+ else if( errno == ENOENT ) {
+ enoentcount++;
+ if( enoentcount > 2 )
+ unit=MAX_TUN+1;
+ }
}
- *ptun = cp - suffix;
- if (*cp == '\0') {
+ if( unit > MAX_TUN ) {
fprintf(stderr, "No tunnel device is available.\n");
return(-1);
}
+ *ptun = unit;
/*
* At first, name the interface.
--
cheers, J"org
joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)