From 5c2027db88176ff4073d552a887429a3c9d3acee Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Mon, 24 Aug 2020 21:53:58 +0100 Subject: [PATCH] Rename min() and max() to ND_MIN() and ND_MAX(). [skip ci] As discussed on tcpdump-workers, it was a place for a potential clash with non-macros. --- netdissect.h | 8 ++------ print-decnet.c | 6 +++--- print-mptcp.c | 2 +- print-olsr.c | 2 +- print-rx.c | 4 ++-- print-smb.c | 34 +++++++++++++++++----------------- print-zeromq.c | 12 ++++++------ smbutil.c | 2 +- 8 files changed, 33 insertions(+), 37 deletions(-) diff --git a/netdissect.h b/netdissect.h index 546d38b0..b774ae63 100644 --- a/netdissect.h +++ b/netdissect.h @@ -288,12 +288,8 @@ extern void nd_pop_all_packet_info(netdissect_options *); #define PT_SOMEIP 19 /* Autosar SOME/IP Protocol */ #define PT_DOMAIN 20 /* Domain Name System (DNS) */ -#ifndef min -#define min(a,b) ((a)>(b)?(b):(a)) -#endif -#ifndef max -#define max(a,b) ((b)>(a)?(b):(a)) -#endif +#define ND_MIN(a,b) ((a)>(b)?(b):(a)) +#define ND_MAX(a,b) ((b)>(a)?(b):(a)) /* For source or destination ports tests (UDP, TCP, ...) */ #define IS_SRC_OR_DST_PORT(p) (sport == (p) || dport == (p)) diff --git a/print-decnet.c b/print-decnet.c index 047916d3..3266c931 100644 --- a/print-decnet.c +++ b/print-decnet.c @@ -530,7 +530,7 @@ decnet_print(netdissect_options *ndo, if (mflags & RMF_FVER) { ND_PRINT("future-version-decnet"); - ND_DEFAULTPRINT(ap, min(length, caplen)); + ND_DEFAULTPRINT(ap, ND_MIN(length, caplen)); return; } @@ -566,7 +566,7 @@ decnet_print(netdissect_options *ndo, break; default: ND_PRINT("unknown message flags under mask"); - ND_DEFAULTPRINT((const u_char *)ap, min(length, caplen)); + ND_DEFAULTPRINT((const u_char *)ap, ND_MIN(length, caplen)); return; } @@ -711,7 +711,7 @@ print_decnet_ctlmsg(netdissect_options *ndo, default: ND_PRINT("unknown control message"); - ND_DEFAULTPRINT((const u_char *)rhp, min(length, caplen)); + ND_DEFAULTPRINT((const u_char *)rhp, ND_MIN(length, caplen)); ret = 1; break; } diff --git a/print-mptcp.c b/print-mptcp.c index c2d61e15..cf01d9c9 100644 --- a/print-mptcp.c +++ b/print-mptcp.c @@ -464,7 +464,7 @@ mptcp_print(netdissect_options *ndo, opt = (const struct mptcp_option *) cp; ND_TCHECK_SIZE(opt); - subtype = min(MPTCP_OPT_SUBTYPE(opt->sub_etc), MPTCP_SUB_FCLOSE + 1); + subtype = ND_MIN(MPTCP_OPT_SUBTYPE(opt->sub_etc), MPTCP_SUB_FCLOSE + 1); ND_PRINT(" %s", mptcp_options[subtype].name); return mptcp_options[subtype].print(ndo, cp, len, flags); diff --git a/print-olsr.c b/print-olsr.c index e640ee18..d6e40927 100644 --- a/print-olsr.c +++ b/print-olsr.c @@ -340,7 +340,7 @@ olsr_print(netdissect_options *ndo, ND_TCHECK_LEN(tptr, sizeof(struct olsr_common)); ptr.common = (const struct olsr_common *)tptr; - length = min(length, GET_BE_U_2(ptr.common->packet_len)); + length = ND_MIN(length, GET_BE_U_2(ptr.common->packet_len)); ND_PRINT("OLSRv%i, seq 0x%04x, length %u", (is_ipv6 == 0) ? 4 : 6, diff --git a/print-rx.c b/print-rx.c index 6c4ce858..a503d3d4 100644 --- a/print-rx.c +++ b/print-rx.c @@ -959,7 +959,7 @@ fs_print(netdissect_options *ndo, i = GET_BE_U_4(bp); bp += sizeof(uint32_t); ND_TCHECK_LEN(bp, i); - i = min(AFSOPAQUEMAX, i); + i = ND_MIN(AFSOPAQUEMAX, i); strncpy(a, (const char *) bp, i); a[i] = '\0'; acl_print(ndo, (u_char *) a, (u_char *) a + i); @@ -1095,7 +1095,7 @@ fs_reply_print(netdissect_options *ndo, i = GET_BE_U_4(bp); bp += sizeof(uint32_t); ND_TCHECK_LEN(bp, i); - i = min(AFSOPAQUEMAX, i); + i = ND_MIN(AFSOPAQUEMAX, i); strncpy(a, (const char *) bp, i); a[i] = '\0'; acl_print(ndo, (u_char *) a, (u_char *) a + i); diff --git a/print-smb.c b/print-smb.c index 77d9f814..1e53eed0 100644 --- a/print-smb.c +++ b/print-smb.c @@ -365,7 +365,7 @@ print_trans(netdissect_options *ndo, } smb_fdata(ndo, words + 1, f1, - min(words + 1 + 2 * GET_U_1(words), maxbuf), + ND_MIN(words + 1 + 2 * GET_U_1(words), maxbuf), unicodestr); ND_TCHECK_2(data1); @@ -391,9 +391,9 @@ print_trans(netdissect_options *ndo, #undef PIPE_LANMAN_STR if (paramlen) - smb_fdata(ndo, param, f3, min(param + paramlen, maxbuf), unicodestr); + smb_fdata(ndo, param, f3, ND_MIN(param + paramlen, maxbuf), unicodestr); if (datalen) - smb_fdata(ndo, data, f4, min(data + datalen, maxbuf), unicodestr); + smb_fdata(ndo, data, f4, ND_MIN(data + datalen, maxbuf), unicodestr); } return; trunc: @@ -422,21 +422,21 @@ print_negprot(netdissect_options *ndo, } if (f1) - smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf), + smb_fdata(ndo, words + 1, f1, ND_MIN(words + 1 + wct * 2, maxbuf), unicodestr); else - smb_data_print(ndo, words + 1, min(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1))); + smb_data_print(ndo, words + 1, ND_MIN(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1))); ND_TCHECK_2(data); bcc = GET_LE_U_2(data); ND_PRINT("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data), + smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data), maxbuf), unicodestr); else smb_data_print(ndo, data + 2, - min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); + ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); } return; trunc: @@ -467,21 +467,21 @@ print_sesssetup(netdissect_options *ndo, } if (f1) - smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf), + smb_fdata(ndo, words + 1, f1, ND_MIN(words + 1 + wct * 2, maxbuf), unicodestr); else - smb_data_print(ndo, words + 1, min(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1))); + smb_data_print(ndo, words + 1, ND_MIN(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1))); ND_TCHECK_2(data); bcc = GET_LE_U_2(data); ND_PRINT("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data), + smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data), maxbuf), unicodestr); else smb_data_print(ndo, data + 2, - min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); + ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); } return; trunc: @@ -509,7 +509,7 @@ print_lockingandx(netdissect_options *ndo, f1 = "Com2=[w]\nOff2=[u]\n"; } - maxwords = min(words + 1 + wct * 2, maxbuf); + maxwords = ND_MIN(words + 1 + wct * 2, maxbuf); if (wct) smb_fdata(ndo, words + 1, f1, maxwords, unicodestr); @@ -518,11 +518,11 @@ print_lockingandx(netdissect_options *ndo, ND_PRINT("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data), + smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data), maxbuf), unicodestr); else smb_data_print(ndo, data + 2, - min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); + ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2))); } return; trunc: @@ -864,7 +864,7 @@ print_smb(netdissect_options *ndo, ND_TCHECK_1(words); wct = GET_U_1(words); data = words + 1 + wct * 2; - maxwords = min(data, maxbuf); + maxwords = ND_MIN(data, maxbuf); if (request) { f1 = fn->descript.req_f1; @@ -902,7 +902,7 @@ print_smb(netdissect_options *ndo, } else { if (bcc > 0) { ND_PRINT("smb_buf[]=\n"); - smb_data_print(ndo, data + 2, min(bcc, ND_BYTES_BETWEEN(maxbuf, data + 2))); + smb_data_print(ndo, data + 2, ND_MIN(bcc, ND_BYTES_BETWEEN(maxbuf, data + 2))); } } } @@ -1237,7 +1237,7 @@ nbt_udp137_print(netdissect_options *ndo, } else { if (p >= maxbuf) goto out; - smb_data_print(ndo, p, min(rdlen, length - ND_BYTES_BETWEEN(p, data))); + smb_data_print(ndo, p, ND_MIN(rdlen, length - ND_BYTES_BETWEEN(p, data))); p += rdlen; } } diff --git a/print-zeromq.c b/print-zeromq.c index 31d69968..cfab5878 100644 --- a/print-zeromq.c +++ b/print-zeromq.c @@ -103,7 +103,7 @@ zmtp1_print_frame(netdissect_options *ndo, const u_char *cp, const u_char *ep) ND_PRINT(", flags 0x%02x", flags); if (ndo->ndo_vflag) { - uint64_t body_len_printed = min(body_len_captured, body_len_declared); + uint64_t body_len_printed = ND_MIN(body_len_captured, body_len_declared); ND_PRINT(" (%s|%s|%s|%s|%s|%s|%s|%s)", flags & 0x80 ? "MBZ" : "-", @@ -116,7 +116,7 @@ zmtp1_print_frame(netdissect_options *ndo, const u_char *cp, const u_char *ep) flags & 0x01 ? "MORE" : "-"); if (ndo->ndo_vflag == 1) - body_len_printed = min(VBYTES + 1, body_len_printed); + body_len_printed = ND_MIN(VBYTES + 1, body_len_printed); if (body_len_printed > 1) { ND_PRINT(", first %" PRIu64 " byte(s) of body:", body_len_printed - 1); hex_and_ascii_print(ndo, "\n\t ", cp + header_len + 1, body_len_printed - 1); @@ -141,7 +141,7 @@ trunc: void zmtp1_print(netdissect_options *ndo, const u_char *cp, u_int len) { - const u_char *ep = min(ndo->ndo_snapend, cp + len); + const u_char *ep = ND_MIN(ndo->ndo_snapend, cp + len); ndo->ndo_protocol = "zmtp1"; ND_PRINT(": ZMTP/1.0"); @@ -190,10 +190,10 @@ zmtp1_print_intermediate_part(netdissect_options *ndo, const u_char *cp, const u if (frame_offset > remaining_len) ND_PRINT(" (%u captured)", remaining_len); if (ndo->ndo_vflag) { - u_int len_printed = min(frame_offset, remaining_len); + u_int len_printed = ND_MIN(frame_offset, remaining_len); if (ndo->ndo_vflag == 1) - len_printed = min(VBYTES, len_printed); + len_printed = ND_MIN(VBYTES, len_printed); if (len_printed > 1) { ND_PRINT(", first %u byte(s):", len_printed); hex_and_ascii_print(ndo, "\n\t ", cp, len_printed); @@ -210,7 +210,7 @@ trunc: void zmtp1_datagram_print(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 = ND_MIN(ndo->ndo_snapend, cp + len); ndo->ndo_protocol = "zmtp1"; cp = zmtp1_print_intermediate_part(ndo, cp, len); diff --git a/smbutil.c b/smbutil.c index a8203bf6..23c59ab2 100644 --- a/smbutil.c +++ b/smbutil.c @@ -320,7 +320,7 @@ smb_data_print(netdissect_options *ndo, const u_char *buf, u_int len) while (n--) ND_PRINT(" "); - n = min(8, i % 16); + n = ND_MIN(8, i % 16); print_asc(ndo, buf + i - (i % 16), n); ND_PRINT(" "); n = (i % 16) - n;