]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-llc.c
Add CAP_FCNTL and use cap_fcntls_limit().
[tcpdump] / print-llc.c
index 590496a36262f847dcdef811c552884dd8a0a999..e8a3314c5c79b9c305c06736fefc72b4a88b383e 100644 (file)
@@ -124,7 +124,7 @@ static const struct tok null_values[] = {
 };
 
 struct oui_tok {
-       u_int32_t       oui;
+       uint32_t        oui;
        const struct tok *tok;
 };
 
@@ -144,17 +144,17 @@ int
 llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
          const u_char *esrc, const u_char *edst, u_short *extracted_ethertype)
 {
-       u_int8_t dsap_field, dsap, ssap_field, ssap;
-       u_int16_t control;
+       uint8_t dsap_field, dsap, ssap_field, ssap;
+       uint16_t control;
        int is_u;
        register int ret;
 
        *extracted_ethertype = 0;
 
-       if (caplen < 3) {
+       if (caplen < 3 || length < 3) {
                ND_PRINT((ndo, "[|llc]"));
-               default_print((u_char *)p, caplen);
-               return(0);
+               ND_DEFAULTPRINT((u_char *)p, caplen);
+               return (1);
        }
 
        dsap_field = *p;
@@ -177,10 +177,10 @@ llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
                 * The control field in I and S frames is
                 * 2 bytes...
                 */
-               if (caplen < 4) {
+               if (caplen < 4 || length < 4) {
                        ND_PRINT((ndo, "[|llc]"));
-                       default_print((u_char *)p, caplen);
-                       return(0);
+                       ND_DEFAULTPRINT((u_char *)p, caplen);
+                       return (1);
                }
 
                /*
@@ -234,12 +234,17 @@ llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
 
        if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D &&
            control == LLC_UI) {
-               stp_print(p+3, length-3);
+               stp_print(ndo, p+3, length-3);
                return (1);
        }
 
        if (ssap == LLCSAP_IP && dsap == LLCSAP_IP &&
            control == LLC_UI) {
+               if (caplen < 4 || length < 4) {
+                       ND_PRINT((ndo, "[|llc]"));
+                       ND_DEFAULTPRINT((u_char *)p, caplen);
+                       return (1);
+               }
                ip_print(ndo, p+4, length-4);
                return (1);
        }
@@ -284,13 +289,13 @@ llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
                        p += 4;
                        length -= 4;
                }
-               netbeui_print(control, p, length);
+               netbeui_print(ndo, control, p, length);
                return (1);
        }
 #endif
        if (ssap == LLCSAP_ISONS && dsap == LLCSAP_ISONS
            && control == LLC_UI) {
-               isoclns_print(p + 3, length - 3, caplen - 3);
+               isoclns_print(ndo, p + 3, length - 3, caplen - 3);
                return (1);
        }
 
@@ -312,8 +317,8 @@ llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
                                ND_PRINT((ndo, "%s ", tok2str(llc_values, "Unknown DSAP 0x%02x", dsap)));
                        else
                                ND_PRINT((ndo, "%s > %s %s ",
-                                               etheraddr_string(esrc),
-                                               etheraddr_string(edst),
+                                               etheraddr_string(ndo, esrc),
+                                               etheraddr_string(ndo, edst),
                                                tok2str(llc_values, "Unknown DSAP 0x%02x", dsap)));
                } else {
                        if (esrc == NULL || edst == NULL)
@@ -322,9 +327,9 @@ llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
                                        tok2str(llc_values, "Unknown DSAP 0x%02x", dsap)));
                        else
                                ND_PRINT((ndo, "%s %s > %s %s ",
-                                       etheraddr_string(esrc),
+                                       etheraddr_string(ndo, esrc),
                                         tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
-                                       etheraddr_string(edst),
+                                       etheraddr_string(ndo, edst),
                                        tok2str(llc_values, "Unknown DSAP 0x%02x", dsap)));
                }
        }
@@ -363,11 +368,13 @@ llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
 int
 snap_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen, u_int bridge_pad)
 {
-       u_int32_t orgcode;
+       uint32_t orgcode;
        register u_short et;
        register int ret;
 
        ND_TCHECK2(*p, 5);
+       if (caplen < 5 || length < 5)
+               goto trunc;
        orgcode = EXTRACT_24BITS(p);
        et = EXTRACT_16BITS(p + 3);
 
@@ -425,7 +432,7 @@ snap_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
        case OUI_CISCO:
                 switch (et) {
                 case PID_CISCO_CDP:
-                        cdp_print(p, length, caplen);
+                        cdp_print(ndo, p, length, caplen);
                         return (1);
                 case PID_CISCO_DTP:
                         dtp_print(ndo, p, length);
@@ -434,15 +441,16 @@ snap_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
                         udld_print(ndo, p, length);
                         return (1);
                 case PID_CISCO_VTP:
-                        vtp_print(p, length);
+                        vtp_print(ndo, p, length);
                         return (1);
                 case PID_CISCO_PVST:
                 case PID_CISCO_VLANBRIDGE:
-                        stp_print(p, length);
+                        stp_print(ndo, p, length);
                         return (1);
                 default:
                         break;
                 }
+               break;
 
        case OUI_RFC2684:
                switch (et) {
@@ -510,7 +518,7 @@ snap_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
                        return (1);
 
                case PID_RFC2684_BPDU:
-                       stp_print(p, length);
+                       stp_print(ndo, p, length);
                        return (1);
                }
        }