]> git.ozlabs.org Git - ppp.git/commitdiff
added stuff to print packets in readable form
authorPaul Mackerras <paulus@samba.org>
Mon, 11 Apr 1994 07:13:44 +0000 (07:13 +0000)
committerPaul Mackerras <paulus@samba.org>
Mon, 11 Apr 1994 07:13:44 +0000 (07:13 +0000)
pppd/chap.c
pppd/chap.h
pppd/lcp.c
pppd/lcp.h
pppd/upap.c
pppd/upap.h

index e0ea4afeee00e569bb28879fc4f32909043ae20d..043dad9d00987cf5e61b93528940ed16cb5160a6 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: chap.c,v 1.1 1993/11/11 03:54:25 paulus Exp $";
+static char rcsid[] = "$Id: chap.c,v 1.2 1994/04/11 07:13:44 paulus Exp $";
 #endif
 
 /*
@@ -738,6 +738,71 @@ ChapSendResponse(cstate)
     ++cstate->resp_transmits;
 }
 
+/*
+ * ChapPrintPkt - print the contents of a CHAP packet.
+ */
+char *ChapCodenames[] = {
+    "Challenge", "Response", "Success", "Failure"
+};
+
+int
+ChapPrintPkt(p, plen, printer, arg)
+    u_char *p;
+    int plen;
+    void (*printer) __ARGS((void *, char *, ...));
+    void *arg;
+{
+    int code, id, len;
+    int clen, nlen;
+    u_char x;
+
+    if (plen < CHAP_HEADERLEN)
+       return 0;
+    GETCHAR(code, p);
+    GETCHAR(id, p);
+    GETSHORT(len, p);
+    if (len < CHAP_HEADERLEN || len > plen)
+       return 0;
+
+    if (code >= 1 && code <= sizeof(ChapCodenames) / sizeof(char *))
+       printer(arg, " %s", ChapCodenames[code-1]);
+    else
+       printer(arg, " code=0x%x", code);
+    printer(arg, " id=0x%x", id);
+    len -= CHAP_HEADERLEN;
+    switch (code) {
+    case CHAP_CHALLENGE:
+    case CHAP_RESPONSE:
+       if (len < 1)
+           break;
+       clen = p[0];
+       if (len < clen + 1)
+           break;
+       ++p;
+       nlen = len - clen - 1;
+       printer(arg, " <");
+       for (; clen > 0; --clen) {
+           GETCHAR(x, p);
+           printer(arg, "%.2x", x);
+       }
+       printer(arg, ">, name = ");
+       print_string((char *)p, nlen, printer, arg);
+       break;
+    case CHAP_FAILURE:
+    case CHAP_SUCCESS:
+       printer(arg, " ");
+       print_string((char *)p, len, printer, arg);
+       break;
+    default:
+       for (clen = len; clen > 0; --clen) {
+           GETCHAR(x, p);
+           printer(arg, " %.2x", x);
+       }
+    }
+
+    return len + CHAP_HEADERLEN;
+}
+
 #ifdef NO_DRAND48
 
 double drand48()
index e91d4fb524a064985f6fc0840fc4bb386b23359f..682ecb864d170e6b66e5dccdfd10b521d3dcbe3a 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * chap.h - Cryptographic Handshake Authentication Protocol definitions.
- *          based on November 1991 draft of PPP Authentication RFC
  *
  * Copyright (c) 1991 Gregory M. Christy
  * All rights reserved.
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: chap.h,v 1.1 1993/11/11 03:54:25 paulus Exp $
+ * $Id: chap.h,v 1.2 1994/04/11 07:13:44 paulus Exp $
  */
 
 #ifndef __CHAP_INCLUDE__
 
 /* Code + ID + length */
-#define CHAP_HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
+#define CHAP_HEADERLEN         4
 
 /*
  * CHAP codes.
@@ -106,6 +105,8 @@ void ChapLowerUp __ARGS((int));
 void ChapLowerDown __ARGS((int));
 void ChapInput __ARGS((int, u_char *, int));
 void ChapProtocolReject __ARGS((int));
+int  ChapPrintPkt __ARGS((u_char *, int,
+                         void (*) __ARGS((void *, char *, ...)), void *));
 
 #define __CHAP_INCLUDE__
 #endif /* __CHAP_INCLUDE__ */
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;
+}
index f7d5ea265c71556c21cfab2ec49aec4fd2a35a0a..586efd68cf03e73ae85f426ab13d289194985a16 100644 (file)
@@ -16,7 +16,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: lcp.h,v 1.1 1993/11/11 03:54:25 paulus Exp $
+ * $Id: lcp.h,v 1.2 1994/04/11 07:13:44 paulus Exp $
  */
 
 /*
 #define CI_AUTHTYPE    3       /* Authentication Type */
 #define CI_QUALITY     4       /* Quality Protocol */
 #define CI_MAGICNUMBER 5       /* Magic Number */
-#define CI_KEEPALIVE   6       /* Keep Alive Parameters - OBSOLETE */
 #define CI_PCOMPRESSION        7       /* Protocol Field Compression */
 #define CI_ACCOMPRESSION 8     /* Address/Control Field Compression */
 
+/*
+ * LCP-specific packet types.
+ */
+#define PROTREJ                8       /* Protocol Reject */
+#define ECHOREQ                9       /* Echo Request */
+#define ECHOREP                10      /* Echo Reply */
+#define DISCREQ                11      /* Discard Request */
 
 /*
  * The state of options is described by an lcp_options structure.
@@ -73,6 +79,8 @@ void lcp_lowerdown __ARGS((int));
 void lcp_input __ARGS((int, u_char *, int));
 void lcp_protrej __ARGS((int));
 void lcp_sprotrej __ARGS((int, u_char *, int));
+int  lcp_printpkt __ARGS((u_char *, int,
+                         void (*) __ARGS((void *, char *, ...)), void *));
 
 extern int lcp_warnloops;      /* Warn about a loopback this often */
 #define DEFWARNLOOPS   10      /* Default value for above */
index 47b3477dfbf06d7e983ccd54343a748ad13d4fb6..61d22acbf286372abc7ef0d5bd8fc4fe57a33f10 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: upap.c,v 1.1 1993/11/11 03:54:25 paulus Exp $";
+static char rcsid[] = "$Id: upap.c,v 1.2 1994/04/11 07:13:44 paulus Exp $";
 #endif
 
 /*
@@ -310,7 +310,7 @@ upap_rauthreq(u, inp, id, len)
        return;
     }
     GETCHAR(ruserlen, inp);
-    len -= sizeof (u_char) + ruserlen + sizeof (u_char);;
+    len -= sizeof (u_char) + ruserlen + sizeof (u_char);
     if (len < 0) {
        UPAPDEBUG((LOG_INFO, "upap_rauth: rcvd short packet."));
        return;
@@ -482,3 +482,80 @@ upap_sresp(u, code, id, msg, msglen)
 
     UPAPDEBUG((LOG_INFO, "upap_sresp: Sent code %d, id %d.", code, id));
 }
+
+/*
+ * upap_printpkt - print the contents of a PAP packet.
+ */
+char *upap_codenames[] = {
+    "AuthReq", "AuthAck", "AuthNak"
+};
+
+int
+upap_printpkt(p, plen, printer, arg)
+    u_char *p;
+    int plen;
+    void (*printer) __ARGS((void *, char *, ...));
+    void *arg;
+{
+    int code, id, len;
+    int mlen, ulen, wlen;
+    char *user, *pwd, *msg;
+    u_char *pstart;
+
+    if (plen < UPAP_HEADERLEN)
+       return 0;
+    pstart = p;
+    GETCHAR(code, p);
+    GETCHAR(id, p);
+    GETSHORT(len, p);
+    if (len < UPAP_HEADERLEN || len > plen)
+       return 0;
+
+    if (code >= 1 && code <= sizeof(upap_codenames) / sizeof(char *))
+       printer(arg, " %s", upap_codenames[code-1]);
+    else
+       printer(arg, " code=0x%x", code);
+    printer(arg, " id=0x%x", id);
+    len -= UPAP_HEADERLEN;
+    switch (code) {
+    case UPAP_AUTHREQ:
+       if (len < 1)
+           break;
+       ulen = p[0];
+       if (len < ulen + 2)
+           break;
+       wlen = p[ulen + 1];
+       if (len < ulen + wlen + 2)
+           break;
+       user = (char *) (p + 1);
+       pwd = (char *) (p + ulen + 2);
+       p += ulen + wlen + 2;
+       len -= ulen + wlen + 2;
+       printer(arg, " user=");
+       print_string(user, ulen, printer, arg);
+       printer(arg, " password=");
+       print_string(pwd, wlen, printer, arg);
+       break;
+    case UPAP_AUTHACK:
+    case UPAP_AUTHNAK:
+       if (len < 1)
+           break;
+       mlen = p[0];
+       if (len < mlen + 1)
+           break;
+       msg = (char *) (p + 1);
+       p += mlen + 1;
+       len -= mlen + 1;
+       printer(arg, "msg=");
+       print_string(msg, mlen, 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;
+}
index c77c198a28e83a249e92fdc69403344bf56ee4dc..10c3414a0afa78b90144c624438370e0658ac0ab 100644 (file)
@@ -16,7 +16,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: upap.h,v 1.1 1993/11/11 03:54:25 paulus Exp $
+ * $Id: upap.h,v 1.2 1994/04/11 07:13:44 paulus Exp $
  */
 
 /*
@@ -87,3 +87,5 @@ void upap_lowerup __ARGS((int));
 void upap_lowerdown __ARGS((int));
 void upap_input __ARGS((int, u_char *, int));
 void upap_protrej __ARGS((int));
+int  upap_printpkt __ARGS((u_char *, int,
+                          void (*) __ARGS((void *, char *, ...)), void *));