X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Futils.c;h=38a69778a270e926d17937d8a7609de8dcacb730;hp=f305ea339903501ee95a36aa57f70ea1ed8af874;hb=bcfa20820fc9ff3b25bcf62308e3e737c1897dc6;hpb=b18e8ba1f8883d9558a7dcbef89e632a02a4071e diff --git a/pppd/utils.c b/pppd/utils.c index f305ea3..38a6977 100644 --- a/pppd/utils.c +++ b/pppd/utils.c @@ -17,7 +17,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define RCSID "$Id: utils.c,v 1.13 2001/03/16 02:08:13 paulus Exp $" +#define RCSID "$Id: utils.c,v 1.18 2002/03/05 15:14:04 dfs Exp $" #include #include @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,8 @@ #endif #include "pppd.h" +#include "fsm.h" +#include "lcp.h" static const char rcsid[] = RCSID; @@ -206,6 +209,28 @@ vslprintf(buf, buflen, fmt, args) neg = 0; ++fmt; switch (c) { + case 'l': + c = *fmt++; + switch (c) { + case 'd': + val = va_arg(args, long); + if (val < 0) { + neg = 1; + val = -val; + } + base = 10; + break; + case 'u': + val = va_arg(args, unsigned long); + base = 10; + break; + default: + *buf++ = '%'; --buflen; + *buf++ = 'l'; --buflen; + --fmt; /* so %lz outputs %lz etc. */ + continue; + } + break; case 'd': i = va_arg(args, int); if (i < 0) { @@ -761,6 +786,36 @@ dbglog __V((char *fmt, ...)) va_end(pvar); } +/* + * dump_packet - print out a packet in readable form if it is interesting. + * Assumes len >= PPP_HDRLEN. + */ +void +dump_packet(const char *tag, unsigned char *p, int len) +{ + int proto; + + if (!debug) + return; + + /* + * don't print LCP echo request/reply packets if debug <= 1 + * and the link is up. + */ + proto = (p[2] << 8) + p[3]; + if (debug <= 1 && unsuccess == 0 && proto == PPP_LCP + && len >= PPP_HDRLEN + HEADERLEN) { + unsigned char *lcp = p + PPP_HDRLEN; + int l = (lcp[2] << 8) + lcp[3]; + + if ((lcp[0] == ECHOREQ || lcp[0] == ECHOREP) + && l >= HEADERLEN && l <= len - PPP_HDRLEN) + return; + } + + dbglog("%s %P", tag, p, len); +} + /* Procedures for locking the serial device using a lock file. */ #ifndef LOCK_DIR #ifdef _linux_ @@ -788,7 +843,7 @@ lock(dev) result = mklock (dev, (void *) 0); if (result == 0) { - strlcpy(lock_file, sizeof(lock_file), dev); + strlcpy(lock_file, dev, sizeof(lock_file)); return 0; } @@ -819,9 +874,20 @@ lock(dev) major(sbuf.st_rdev), minor(sbuf.st_rdev)); #else char *p; + char lockdev[MAXPATHLEN]; + + if ((p = strstr(dev, "dev/")) != NULL) { + dev = p + 4; + strncpy(lockdev, dev, MAXPATHLEN-1); + lockdev[MAXPATHLEN-1] = 0; + while ((p = strrchr(lockdev, '/')) != NULL) { + *p = '_'; + } + dev = lockdev; + } else + if ((p = strrchr(dev, '/')) != NULL) + dev = p + 1; - if ((p = strrchr(dev, '/')) != NULL) - dev = p + 1; slprintf(lock_file, sizeof(lock_file), "%s/LCK..%s", LOCK_DIR, dev); #endif