]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/lcp.c
added stuff to print packets in readable form
[ppp.git] / pppd / lcp.c
index c475f4ce97c3ea3d3b0cd55906cb6763ffa30587..e03432ca32885ad631443a182247df2119547605 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: lcp.c,v 1.1 1993/11/11 03:54:25 paulus Exp $";
+static char rcsid[] = "$Id: lcp.c,v 1.2 1994/04/11 07:13:44 paulus Exp $";
 #endif
 
 /*
@@ -1279,3 +1279,139 @@ lcp_finished(f)
     link_terminated(f->unit);
 }
 
+
+/*
+ * lcp_printpkt - print the contents of an LCP packet.
+ */
+char *lcp_codenames[] = {
+    "ConfReq", "ConfAck", "ConfNak", "ConfRej",
+    "TermReq", "TermAck", "CodeRej", "ProtRej",
+    "EchoReq", "EchoRep", "DiscReq"
+};
+
+int
+lcp_printpkt(p, plen, printer, arg)
+    u_char *p;
+    int plen;
+    void (*printer) __ARGS((void *, char *, ...));
+    void *arg;
+{
+    int code, id, len, olen;
+    u_char *pstart, *optend;
+    u_short cishort;
+    u_long cilong;
+
+    if (plen < HEADERLEN)
+       return 0;
+    pstart = p;
+    GETCHAR(code, p);
+    GETCHAR(id, p);
+    GETSHORT(len, p);
+    if (len < HEADERLEN || len > plen)
+       return 0;
+
+    if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
+       printer(arg, " %s", lcp_codenames[code-1]);
+    else
+       printer(arg, " code=0x%x", code);
+    printer(arg, " id=0x%x", id);
+    len -= HEADERLEN;
+    switch (code) {
+    case CONFREQ:
+    case CONFACK:
+    case CONFNAK:
+    case CONFREJ:
+       /* print option list */
+       while (len >= 2) {
+           GETCHAR(code, p);
+           GETCHAR(olen, p);
+           p -= 2;
+           if (olen < 2 || olen > len) {
+               break;
+           }
+           printer(arg, " <");
+           len -= olen;
+           optend = p + olen;
+           switch (code) {
+           case CI_MRU:
+               if (olen == CILEN_SHORT) {
+                   p += 2;
+                   GETSHORT(cishort, p);
+                   printer(arg, "mru %d", cishort);
+               }
+               break;
+           case CI_ASYNCMAP:
+               if (olen == CILEN_LONG) {
+                   p += 2;
+                   GETLONG(cilong, p);
+                   printer(arg, "asyncmap 0x%x", cilong);
+               }
+               break;
+           case CI_AUTHTYPE:
+               if (olen >= CILEN_SHORT) {
+                   p += 2;
+                   printer(arg, "auth ");
+                   GETSHORT(cishort, p);
+                   switch (cishort) {
+                   case UPAP:
+                       printer(arg, "upap");
+                       break;
+                   case CHAP:
+                       printer(arg, "chap");
+                       break;
+                   default:
+                       printer(arg, "0x%x", cishort);
+                   }
+               }
+               break;
+           case CI_QUALITY:
+               if (olen >= CILEN_SHORT) {
+                   p += 2;
+                   printer(arg, "quality ");
+                   GETSHORT(cishort, p);
+                   switch (cishort) {
+                   case LQR:
+                       printer(arg, "lqr");
+                       break;
+                   default:
+                       printer(arg, "0x%x", cishort);
+                   }
+               }
+               break;
+           case CI_MAGICNUMBER:
+               if (olen == CILEN_LONG) {
+                   p += 2;
+                   GETLONG(cilong, p);
+                   printer(arg, "magic 0x%x", cilong);
+               }
+               break;
+           case CI_PCOMPRESSION:
+               if (olen == CILEN_VOID) {
+                   p += 2;
+                   printer(arg, "pcomp");
+               }
+               break;
+           case CI_ACCOMPRESSION:
+               if (olen == CILEN_VOID) {
+                   p += 2;
+                   printer(arg, "accomp");
+               }
+               break;
+           }
+           while (p < optend) {
+               GETCHAR(code, p);
+               printer(arg, " %.2x", code);
+           }
+           printer(arg, ">");
+       }
+       break;
+    }
+
+    /* print the rest of the bytes in the packet */
+    for (; len > 0; --len) {
+       GETCHAR(code, p);
+       printer(arg, " %.2x", code);
+    }
+
+    return p - pstart;
+}