]> The Tcpdump Group git mirrors - tcpdump/commitdiff
justify min()/max() macros declarations and usage
authorDenis Ovsienko <[email protected]>
Fri, 14 Mar 2014 05:52:40 +0000 (09:52 +0400)
committerDenis Ovsienko <[email protected]>
Fri, 14 Mar 2014 05:55:30 +0000 (09:55 +0400)
This change moves the macros to tcpdump-stdinc.h to make sure these are
available without interface.h. It also dismisses two redundant macros
MIN() and SMBMIN(). It is intended to fix the following Solaris compile
error:

Undefined                       first referenced
 symbol                             in file
MIN                                 print-zeromq.o

interface.h
print-smb.c
print-zeromq.c
smb.h
smbutil.c
tcpdump-stdinc.h

index 2103bc02853baa8ab1a7e010ac9d54cc2f525e2f..757e13815e7287a7aef074f7b3f1d3d538e55408 100644 (file)
@@ -82,13 +82,6 @@ extern char *strsep(char **, const char *);
 #define PT_PGM_ZMTP1   15      /* ZMTP/1.0 inside PGM (native or UDP-encapsulated) */
 #define PT_LMP         16      /* Link Management Protocol */
 
-#ifndef min
-#define min(a,b) ((a)>(b)?(b):(a))
-#endif
-#ifndef max
-#define max(a,b) ((b)>(a)?(b):(a))
-#endif
-
 #define ESRC(ep) ((ep)->ether_shost)
 #define EDST(ep) ((ep)->ether_dhost)
 
@@ -100,10 +93,6 @@ extern char *strsep(char **, const char *);
 #endif
 #endif
 
-#ifndef MIN
-#define MIN(a,b) ((a)<(b)?(a):(b))
-#endif
-
 extern char *program_name;     /* used to generate self-identifying messages */
 
 extern int32_t thiszone;       /* seconds offset from gmt to local time */
index 32edd196d261152dabff6f9340110d0e7cedcd7c..f0e992c4a7232548c074f9e4d59f8664f285fc3b 100644 (file)
@@ -360,7 +360,7 @@ print_trans(const u_char *words, const u_char *data1, const u_char *buf, const u
        f4 = "|Data ";
     }
 
-    smb_fdata(words + 1, f1, SMBMIN(words + 1 + 2 * words[0], maxbuf),
+    smb_fdata(words + 1, f1, min(words + 1 + 2 * words[0], maxbuf),
         unicodestr);
 
     TCHECK2(*data1, 2);
@@ -380,9 +380,9 @@ print_trans(const u_char *words, const u_char *data1, const u_char *buf, const u
        }
 
        if (paramlen)
-           smb_fdata(param, f3, SMBMIN(param + paramlen, maxbuf), unicodestr);
+           smb_fdata(param, f3, min(param + paramlen, maxbuf), unicodestr);
        if (datalen)
-           smb_fdata(data, f4, SMBMIN(data + datalen, maxbuf), unicodestr);
+           smb_fdata(data, f4, min(data + datalen, maxbuf), unicodestr);
     }
     return;
 trunc:
@@ -411,20 +411,20 @@ print_negprot(const u_char *words, const u_char *data, const u_char *buf _U_, co
     }
 
     if (f1)
-       smb_fdata(words + 1, f1, SMBMIN(words + 1 + wct * 2, maxbuf),
+       smb_fdata(words + 1, f1, min(words + 1 + wct * 2, maxbuf),
            unicodestr);
     else
-       print_data(words + 1, SMBMIN(wct * 2, PTR_DIFF(maxbuf, words + 1)));
+       print_data(words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
 
     TCHECK2(*data, 2);
     bcc = EXTRACT_LE_16BITS(data);
     printf("smb_bcc=%u\n", bcc);
     if (bcc > 0) {
        if (f2)
-           smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data),
+           smb_fdata(data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
                maxbuf), unicodestr);
        else
-           print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
+           print_data(data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -455,20 +455,20 @@ print_sesssetup(const u_char *words, const u_char *data, const u_char *buf _U_,
     }
 
     if (f1)
-       smb_fdata(words + 1, f1, SMBMIN(words + 1 + wct * 2, maxbuf),
+       smb_fdata(words + 1, f1, min(words + 1 + wct * 2, maxbuf),
            unicodestr);
     else
-       print_data(words + 1, SMBMIN(wct * 2, PTR_DIFF(maxbuf, words + 1)));
+       print_data(words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
 
     TCHECK2(*data, 2);
     bcc = EXTRACT_LE_16BITS(data);
     printf("smb_bcc=%u\n", bcc);
     if (bcc > 0) {
        if (f2)
-           smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data),
+           smb_fdata(data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
                maxbuf), unicodestr);
        else
-           print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
+           print_data(data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -496,7 +496,7 @@ print_lockingandx(const u_char *words, const u_char *data, const u_char *buf _U_
        f1 = "Com2=[w]\nOff2=[d]\n";
     }
 
-    maxwords = SMBMIN(words + 1 + wct * 2, maxbuf);
+    maxwords = min(words + 1 + wct * 2, maxbuf);
     if (wct)
        smb_fdata(words + 1, f1, maxwords, unicodestr);
 
@@ -505,10 +505,10 @@ print_lockingandx(const u_char *words, const u_char *data, const u_char *buf _U_
     printf("smb_bcc=%u\n", bcc);
     if (bcc > 0) {
        if (f2)
-           smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data),
+           smb_fdata(data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
                maxbuf), unicodestr);
        else
-           print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
+           print_data(data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -844,7 +844,7 @@ print_smb(const u_char *buf, const u_char *maxbuf)
        TCHECK(words[0]);
        wct = words[0];
        data = words + 1 + wct * 2;
-       maxwords = SMBMIN(data, maxbuf);
+       maxwords = min(data, maxbuf);
 
        if (request) {
            f1 = fn->descript.req_f1;
@@ -881,7 +881,7 @@ print_smb(const u_char *buf, const u_char *maxbuf)
            } else {
                if (bcc > 0) {
                    printf("smb_buf[]=\n");
-                   print_data(data + 2, SMBMIN(bcc, PTR_DIFF(maxbuf, data + 2)));
+                   print_data(data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2)));
                }
            }
        }
index b2cf6db4c3136ec2cdc9ac725e7161d2b21aaa32..98a9e928bf3cda68dc60039eb8138f5ef4f4fefc 100644 (file)
@@ -186,7 +186,7 @@ zmtp1_print_intermediate_part(netdissect_options *ndo, const u_char *cp, const u
                if (frame_offset > remaining_len)
                        ND_PRINT((ndo, " (%"PRIu64" captured)", remaining_len));
                if (ndo->ndo_vflag) {
-                       u_int64_t len_printed = MIN(frame_offset, remaining_len);
+                       u_int64_t len_printed = min(frame_offset, remaining_len);
 
                        if (ndo->ndo_vflag == 1)
                                len_printed = MIN(VBYTES, len_printed);
@@ -206,7 +206,7 @@ trunc:
 
 void
 zmtp1_print_datagram(netdissect_options *ndo, const u_char *cp, const u_int len) {
-       const u_char *ep = MIN(ndo->ndo_snapend, cp + len);
+       const u_char *ep = min(ndo->ndo_snapend, cp + len);
 
        cp = zmtp1_print_intermediate_part(ndo, cp, len);
        while (cp < ep)
diff --git a/smb.h b/smb.h
index fea9fa4687fc3a23e07e37443a3f9ac9087a5dbf..97a436383cf3bb6f6070cea8a642dfa1c27059a1 100644 (file)
--- a/smb.h
+++ b/smb.h
@@ -6,8 +6,6 @@
  * or later
  */
 
-#define SMBMIN(a,b) ((a)<(b)?(a):(b))
-
 /* the complete */
 #define SMBmkdir      0x00   /* create directory */
 #define SMBrmdir      0x01   /* delete directory */
index 43783aa4b0eac8b999bdd87383d95fffb20b7a61..da8612324fb2f5dc6f174d1b3bca48ef747d2cd3 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -298,7 +298,7 @@ print_data(const unsigned char *buf, int len)
        while (n--)
            printf("   ");
 
-       n = SMBMIN(8, i % 16);
+       n = min(8, i % 16);
        print_asc(&buf[i - (i % 16)], n);
        printf(" ");
        n = (i % 16) - n;
index 77dccd5c8a114a7cad0a36e331aed69e8d0da2ed..d971341cd520e663df1d2f94eca91c4a6908270b 100644 (file)
@@ -268,4 +268,11 @@ typedef char* caddr_t;
  * end of Apple deprecation workaround macros
  */
 
+#ifndef min
+#define min(a,b) ((a)>(b)?(b):(a))
+#endif
+#ifndef max
+#define max(a,b) ((b)>(a)?(b):(a))
+#endif
+
 #endif /* tcpdump_stdinc_h */