]> The Tcpdump Group git mirrors - tcpdump/commitdiff
-add basic support for codeset shifting for IE printing in the frame-relay printer
authorhannes <hannes>
Mon, 21 Mar 2005 11:35:55 +0000 (11:35 +0000)
committerhannes <hannes>
Mon, 21 Mar 2005 11:35:55 +0000 (11:35 +0000)
-harden tok2str() and bittok2str() to catch NULL refs
-don't attempt to print a frame-relay IE if there is not enough bytes on the wire
 to print at least a full TLV

print-fr.c
util.c

index fd00202a17dbb05b729c56a98c0c59717d9af766..f8398121934291fe89dc4ebd2bc9f137dd9c8f94 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-       "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.29 2005-01-27 10:13:51 hannes Exp $ (LBL)";
+       "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.30 2005-03-21 11:35:55 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -429,7 +429,7 @@ struct tok fr_q933_msg_values[] = {
 #define FR_LMI_CCITT_LINK_VERIFY_IE    0x53
 #define FR_LMI_CCITT_PVC_STATUS_IE     0x57
 
-struct tok fr_q933_ie_values[] = {
+struct tok fr_q933_ie_values_codeset5[] = {
     { FR_LMI_ANSI_REPORT_TYPE_IE, "ANSI Report Type" },
     { FR_LMI_ANSI_LINK_VERIFY_IE_91, "ANSI Link Verify" },
     { FR_LMI_ANSI_LINK_VERIFY_IE, "ANSI Link Verify" },
@@ -451,6 +451,27 @@ struct tok fr_lmi_report_type_ie_values[] = {
     { 0, NULL }
 };
 
+/* array of 16 codepages - currently we only support codepage 5 */
+static struct tok *fr_q933_ie_codesets[] = {
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    fr_q933_ie_values_codeset5,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+
 struct common_ie_header {
     u_int8_t ie_id;
     u_int8_t ie_len;
@@ -463,13 +484,15 @@ q933_print(const u_char *p, u_int length)
        struct common_ie_header *ie_p;
         int olen;
        int is_ansi = 0;
-        u_int dlci;
+        u_int dlci,codeset;
 
        if (length < 9) {       /* shortest: Q.933a LINK VERIFY */
                printf("[|q.933]");
                return;
        }
 
+        codeset = p[2]&0x0f;   /* extract the codeset */
+
        if (p[2] == MSG_ANSI_LOCKING_SHIFT)
                is_ansi = 1;
     
@@ -500,7 +523,7 @@ q933_print(const u_char *p, u_int length)
        ptemp += 2 + is_ansi;
        
        /* Loop through the rest of IE */
-       while (length > 0) {
+       while (length > sizeof(struct common_ie_header)) {
                ie_p = (struct common_ie_header *)ptemp;
                if (length < sizeof(struct common_ie_header) ||
                    length < sizeof(struct common_ie_header) + ie_p->ie_len) {
@@ -516,7 +539,7 @@ q933_print(const u_char *p, u_int length)
                  * are also intereststing in non-verbose mode */
                 if (vflag)
                     printf("\n\t%s IE (%u), length %u: ",
-                           tok2str(fr_q933_ie_values,"unknown",ie_p->ie_id),
+                           tok2str(fr_q933_ie_codesets[codeset],"unknown",ie_p->ie_id),
                            ie_p->ie_id,
                            ie_p->ie_len);
                     
diff --git a/util.c b/util.c
index 97d352720e407cc1da965f16bd1c7f80a8a52761..2310a7d9e6a9de518359911a117ae0cad4774237 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.94 2004-06-15 23:05:06 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.95 2005-03-21 11:35:55 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -219,7 +219,7 @@ const char *
 tok2strbuf(register const struct tok *lp, register const char *fmt,
           register int v, char *buf, size_t bufsize)
 {
-       while (lp->s != NULL) {
+       while (lp->s != NULL && lp != NULL) {
                if (lp->v == v)
                        return (lp->s);
                ++lp;
@@ -260,7 +260,7 @@ bittok2str(register const struct tok *lp, register const char *fmt,
         register int rotbit; /* this is the bit we rotate through all bitpositions */
         register int tokval;
 
-       while (lp->s != NULL) {
+       while (lp->s != NULL && lp != NULL) {
             tokval=lp->v;   /* load our first value */
             rotbit=1;
             while (rotbit != 0) {