summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Ovsienko <infrastation@yandex.ru>2014-03-14 09:52:40 +0400
committerDenis Ovsienko <infrastation@yandex.ru>2014-03-14 09:55:30 +0400
commitdbfdf97bdedca08dc9bd59bb706b0ccc827633ac (patch)
tree6f0c04ddf5059f5dc52cc5dbe6d63e3557687d00
parentd29f3dab95d8b28a62848fcb043b8ba40348bc3d (diff)
downloadtcpdump-dbfdf97bdedca08dc9bd59bb706b0ccc827633ac.tar.gz
justify min()/max() macros declarations and usage
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
-rw-r--r--interface.h11
-rw-r--r--print-smb.c32
-rw-r--r--print-zeromq.c4
-rw-r--r--smb.h2
-rw-r--r--smbutil.c2
-rw-r--r--tcpdump-stdinc.h7
6 files changed, 26 insertions, 32 deletions
diff --git a/interface.h b/interface.h
index 2103bc02..757e1381 100644
--- a/interface.h
+++ b/interface.h
@@ -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 */
diff --git a/print-smb.c b/print-smb.c
index 32edd196..f0e992c4 100644
--- a/print-smb.c
+++ b/print-smb.c
@@ -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)));
}
}
}
diff --git a/print-zeromq.c b/print-zeromq.c
index b2cf6db4..98a9e928 100644
--- a/print-zeromq.c
+++ b/print-zeromq.c
@@ -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 fea9fa46..97a43638 100644
--- 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 */
diff --git a/smbutil.c b/smbutil.c
index 43783aa4..da861232 100644
--- 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;
diff --git a/tcpdump-stdinc.h b/tcpdump-stdinc.h
index 77dccd5c..d971341c 100644
--- a/tcpdump-stdinc.h
+++ b/tcpdump-stdinc.h
@@ -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 */