X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=pppd%2Futils.c;h=43ed3172c7e61ff564bdae0739488828735b592e;hb=58d58e6be99ed13fbfe222cb15af7db75154d6c9;hp=b176fbb4da6c6618edbbc730ba3291698da5289a;hpb=37a8acc7ee2527693d0c8ba82b2eaea249abde34;p=ppp.git diff --git a/pppd/utils.c b/pppd/utils.c index b176fbb..43ed317 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.11 2001/03/08 05:11:16 paulus Exp $" +#define RCSID "$Id: utils.c,v 1.16 2002/01/11 18:27:17 etbe 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; @@ -215,6 +218,10 @@ vslprintf(buf, buflen, fmt, args) val = i; base = 10; break; + case 'u': + val = va_arg(args, unsigned int); + base = 10; + break; case 'o': val = va_arg(args, unsigned int); base = 8; @@ -552,6 +559,7 @@ pr_log __V((void *arg, char *fmt, ...)) *eol = 0; log_write(llevel, p); p = eol + 1; + eol = strchr(p, '\n'); } /* assumes sizeof(buf) <= sizeof(line) */ @@ -756,6 +764,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_ @@ -814,9 +852,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