]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ppp.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-ppp.c
index 2cf06c3634885f8104e4630889e1d76065ded425..f7af42a582f51bace038f1d84dc79b5dd2cd31db 100644 (file)
  * o BAP support
  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
+#include <stdlib.h>
+
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -695,7 +695,6 @@ print_lcp_config_options(netdissect_options *ndo,
                        ND_PRINT(" (length bogus, should be >= 3)");
                        return 0;
                }
-               ND_PRINT(": ");
                ND_PRINT(": Callback Operation %s (%u)",
                        tok2str(ppp_callback_values, "Unknown", GET_U_1(p + 2)),
                        GET_U_1(p + 2));
@@ -872,19 +871,13 @@ handle_chap(netdissect_options *ndo,
                }
                name_size = len - (u_int)(p - p0);
                ND_PRINT(", Name ");
-               for (i = 0; i < name_size; i++) {
-                       fn_print_char(ndo, GET_U_1(p));
-                       p++;
-               }
+               nd_printjn(ndo, p, name_size);
                break;
        case CHAP_SUCC:
        case CHAP_FAIL:
                msg_size = len - (u_int)(p - p0);
                ND_PRINT(", Msg ");
-               for (i = 0; i< msg_size; i++) {
-                       fn_print_char(ndo, GET_U_1(p));
-                       p++;
-               }
+               nd_printjn(ndo, p, msg_size);
                break;
        }
 }
@@ -897,7 +890,6 @@ handle_pap(netdissect_options *ndo,
        u_int code, len;
        u_int peerid_len, passwd_len, msg_len;
        const u_char *p0;
-       u_int i;
 
        p0 = p;
        if (length < 1) {
@@ -942,10 +934,8 @@ handle_pap(netdissect_options *ndo,
                if (length - (p - p0) < peerid_len)
                        return;
                ND_PRINT(", Peer ");
-               for (i = 0; i < peerid_len; i++) {
-                       fn_print_char(ndo, GET_U_1(p));
-                       p++;
-               }
+               nd_printjn(ndo, p, peerid_len);
+               p += peerid_len;
 
                if (length - (p - p0) < 1)
                        return;
@@ -954,10 +944,7 @@ handle_pap(netdissect_options *ndo,
                if (length - (p - p0) < passwd_len)
                        return;
                ND_PRINT(", Name ");
-               for (i = 0; i < passwd_len; i++) {
-                       fn_print_char(ndo, GET_U_1(p));
-                       p++;
-               }
+               nd_printjn(ndo, p, passwd_len);
                break;
        case PAP_AACK:
        case PAP_ANAK:
@@ -975,10 +962,7 @@ handle_pap(netdissect_options *ndo,
                if (length - (p - p0) < msg_len)
                        return;
                ND_PRINT(", Msg ");
-               for (i = 0; i< msg_len; i++) {
-                       fn_print_char(ndo, GET_U_1(p));
-                       p++;
-               }
+               nd_printjn(ndo, p, msg_len);
                break;
        }
        return;
@@ -1358,7 +1342,6 @@ ppp_hdlc(netdissect_options *ndo,
        u_char *b, *t, c;
        const u_char *s;
        u_int i, proto;
-       const void *sb, *se;
 
        if (caplen == 0)
                return;
@@ -1366,9 +1349,11 @@ ppp_hdlc(netdissect_options *ndo,
         if (length == 0)
                 return;
 
-       b = (u_char *)nd_malloc(ndo, caplen);
-       if (b == NULL)
-               return;
+       b = (u_char *)malloc(caplen);
+       if (b == NULL) {
+               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+                       "%s: malloc", __func__);
+       }
 
        /*
         * Unescape all the data into a temporary, private, buffer.
@@ -1389,13 +1374,15 @@ ppp_hdlc(netdissect_options *ndo,
        }
 
        /*
-        * Change the end pointer, so bounds checks work.
-        * Change the pointer to packet data to help debugging.
+        * Switch to the output buffer for dissection, and save it
+        * on the buffer stack so it can be freed; our caller must
+        * pop it when done.
         */
-       sb = ndo->ndo_packetp;
-       se = ndo->ndo_snapend;
-       ndo->ndo_packetp = b;
-       ndo->ndo_snapend = t;
+       if (!nd_push_buffer(ndo, b, b, (u_int)(t - b))) {
+               free(b);
+               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+                       "%s: can't push buffer on buffer stack", __func__);
+       }
        length = ND_BYTES_AVAILABLE_AFTER(b);
 
         /* now lets guess about the payload codepoint format */
@@ -1437,13 +1424,11 @@ ppp_hdlc(netdissect_options *ndo,
         }
 
 cleanup:
-       ndo->ndo_packetp = sb;
-       ndo->ndo_snapend = se;
+       nd_pop_packet_info(ndo);
         return;
 
 trunc:
-       ndo->ndo_packetp = sb;
-       ndo->ndo_snapend = se;
+       nd_pop_packet_info(ndo);
        nd_print_trunc(ndo);
 }