diff options
Diffstat (limited to 'usr.sbin/ppp/os.c')
-rw-r--r-- | usr.sbin/ppp/os.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/usr.sbin/ppp/os.c b/usr.sbin/ppp/os.c index 691e258..f42318d 100644 --- a/usr.sbin/ppp/os.c +++ b/usr.sbin/ppp/os.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: os.c,v 1.3 1995/05/30 03:50:52 rgrimes Exp $ + * $Id: os.c,v 1.4 1996/01/11 17:48:55 phk Exp $ * */ #include "fsm.h" @@ -181,7 +181,7 @@ OsLinkup() logprintf("setuid failed\n"); peer_addr = IpcpInfo.his_ipaddr; s = (char *)inet_ntoa(peer_addr); - LogPrintf(LOG_PHASE, "OsLinkup: %s\n", s); + LogPrintf(LOG_LINK_BIT|LOG_LCP_BIT, "OsLinkup: %s\n", s); if (SelectSystem(inet_ntoa(IpcpInfo.want_ipaddr), LINKFILE) < 0) { if (dstsystem) { @@ -201,7 +201,7 @@ OsLinkdown() if (linkup) { s = (char *)inet_ntoa(peer_addr); - LogPrintf(LOG_PHASE, "OsLinkdown: %s\n", s); + LogPrintf(LOG_LINK_BIT|LOG_LCP_BIT, "OsLinkdown: %s\n", s); if (!(mode & MODE_AUTO)) DeleteIfRoutes(0); linkup = 0; @@ -253,25 +253,35 @@ int type, mtu, speed; /* * 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); } @@ -317,7 +327,7 @@ int *ptun; return(-1); } printf("Using interface: %s\r\n", IfDevName); - LogPrintf(LOG_PHASE, "Using interface: %s\n", IfDevName); + LogPrintf(LOG_PHASE_BIT, "Using interface: %s\n", IfDevName); close(s); return(0); } |