From: Denis Ovsienko Date: Wed, 30 Sep 2020 18:15:42 +0000 (+0100) Subject: Prefix all cpack function names with "nd_". [skip ci] X-Git-Tag: tcpdump-4.99-bp~169 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/7810dd37c23ea1d304dd90235ba1c145b49c473f Prefix all cpack function names with "nd_". [skip ci] Gisle Vanem reported in GH #881 that in Windows tcpdump failed to link with static AirPcap because the latter seems to include its own variant of cpack code: airpcap_static.lib(RadiotapDecode.obj) : error LNK2005: _cpack_init already defined in cpack.obj airpcap_static.lib(RadiotapDecode.obj) : error LNK2005: _cpack_uint16 already defined in cpack.obj airpcap_static.lib(RadiotapDecode.obj) : error LNK2005: _cpack_uint32 already defined in cpack.obj airpcap_static.lib(RadiotapDecode.obj) : error LNK2005: _cpack_uint64 already defined in cpack.obj airpcap_static.lib(RadiotapDecode.obj) : error LNK2005: _cpack_uint8 already defined in cpack.obj He confirms this change resolves the issue. --- diff --git a/cpack.c b/cpack.c index db3b6dc2..9be7b47d 100644 --- a/cpack.c +++ b/cpack.c @@ -41,7 +41,7 @@ #include "cpack.h" const uint8_t * -cpack_next_boundary(const uint8_t *buf, const uint8_t *p, size_t alignment) +nd_cpack_next_boundary(const uint8_t *buf, const uint8_t *p, size_t alignment) { size_t misalignment = (size_t)(p - buf) % alignment; @@ -56,12 +56,12 @@ cpack_next_boundary(const uint8_t *buf, const uint8_t *p, size_t alignment) * return a pointer to the boundary. */ const uint8_t * -cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize) +nd_cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize) { const uint8_t *next; /* Ensure alignment. */ - next = cpack_next_boundary(cs->c_buf, cs->c_next, wordsize); + next = nd_cpack_next_boundary(cs->c_buf, cs->c_next, wordsize); /* Too little space for wordsize bytes? */ if (next - cs->c_buf + wordsize > cs->c_len) @@ -72,7 +72,7 @@ cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize) /* Advance by N bytes without returning them. */ int -cpack_advance(struct cpack_state *cs, const size_t toskip) +nd_cpack_advance(struct cpack_state *cs, const size_t toskip) { /* No space left? */ if (cs->c_next - cs->c_buf + toskip > cs->c_len) @@ -82,7 +82,7 @@ cpack_advance(struct cpack_state *cs, const size_t toskip) } int -cpack_init(struct cpack_state *cs, const uint8_t *buf, size_t buflen) +nd_cpack_init(struct cpack_state *cs, const uint8_t *buf, size_t buflen) { memset(cs, 0, sizeof(*cs)); @@ -95,11 +95,11 @@ cpack_init(struct cpack_state *cs, const uint8_t *buf, size_t buflen) /* Unpack a 64-bit unsigned integer. */ int -cpack_uint64(netdissect_options *ndo, struct cpack_state *cs, uint64_t *u) +nd_cpack_uint64(netdissect_options *ndo, struct cpack_state *cs, uint64_t *u) { const uint8_t *next; - if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL) + if ((next = nd_cpack_align_and_reserve(cs, sizeof(*u))) == NULL) return -1; *u = GET_LE_U_8(next); @@ -111,11 +111,11 @@ cpack_uint64(netdissect_options *ndo, struct cpack_state *cs, uint64_t *u) /* Unpack a 64-bit signed integer. */ int -cpack_int64(netdissect_options *ndo, struct cpack_state *cs, int64_t *u) +nd_cpack_int64(netdissect_options *ndo, struct cpack_state *cs, int64_t *u) { const uint8_t *next; - if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL) + if ((next = nd_cpack_align_and_reserve(cs, sizeof(*u))) == NULL) return -1; *u = GET_LE_S_8(next); @@ -127,11 +127,11 @@ cpack_int64(netdissect_options *ndo, struct cpack_state *cs, int64_t *u) /* Unpack a 32-bit unsigned integer. */ int -cpack_uint32(netdissect_options *ndo, struct cpack_state *cs, uint32_t *u) +nd_cpack_uint32(netdissect_options *ndo, struct cpack_state *cs, uint32_t *u) { const uint8_t *next; - if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL) + if ((next = nd_cpack_align_and_reserve(cs, sizeof(*u))) == NULL) return -1; *u = GET_LE_U_4(next); @@ -143,11 +143,11 @@ cpack_uint32(netdissect_options *ndo, struct cpack_state *cs, uint32_t *u) /* Unpack a 32-bit signed integer. */ int -cpack_int32(netdissect_options *ndo, struct cpack_state *cs, int32_t *u) +nd_cpack_int32(netdissect_options *ndo, struct cpack_state *cs, int32_t *u) { const uint8_t *next; - if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL) + if ((next = nd_cpack_align_and_reserve(cs, sizeof(*u))) == NULL) return -1; *u = GET_LE_S_4(next); @@ -159,11 +159,11 @@ cpack_int32(netdissect_options *ndo, struct cpack_state *cs, int32_t *u) /* Unpack a 16-bit unsigned integer. */ int -cpack_uint16(netdissect_options *ndo, struct cpack_state *cs, uint16_t *u) +nd_cpack_uint16(netdissect_options *ndo, struct cpack_state *cs, uint16_t *u) { const uint8_t *next; - if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL) + if ((next = nd_cpack_align_and_reserve(cs, sizeof(*u))) == NULL) return -1; *u = GET_LE_U_2(next); @@ -175,11 +175,11 @@ cpack_uint16(netdissect_options *ndo, struct cpack_state *cs, uint16_t *u) /* Unpack a 16-bit signed integer. */ int -cpack_int16(netdissect_options *ndo, struct cpack_state *cs, int16_t *u) +nd_cpack_int16(netdissect_options *ndo, struct cpack_state *cs, int16_t *u) { const uint8_t *next; - if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL) + if ((next = nd_cpack_align_and_reserve(cs, sizeof(*u))) == NULL) return -1; *u = GET_LE_S_2(next); @@ -191,7 +191,7 @@ cpack_int16(netdissect_options *ndo, struct cpack_state *cs, int16_t *u) /* Unpack an 8-bit unsigned integer. */ int -cpack_uint8(netdissect_options *ndo, struct cpack_state *cs, uint8_t *u) +nd_cpack_uint8(netdissect_options *ndo, struct cpack_state *cs, uint8_t *u) { /* No space left? */ if ((size_t)(cs->c_next - cs->c_buf) >= cs->c_len) @@ -206,7 +206,7 @@ cpack_uint8(netdissect_options *ndo, struct cpack_state *cs, uint8_t *u) /* Unpack an 8-bit signed integer. */ int -cpack_int8(netdissect_options *ndo, struct cpack_state *cs, int8_t *u) +nd_cpack_int8(netdissect_options *ndo, struct cpack_state *cs, int8_t *u) { /* No space left? */ if ((size_t)(cs->c_next - cs->c_buf) >= cs->c_len) diff --git a/cpack.h b/cpack.h index 71ab4f87..4e89300c 100644 --- a/cpack.h +++ b/cpack.h @@ -38,20 +38,20 @@ struct cpack_state { size_t c_len; }; -int cpack_init(struct cpack_state *, const uint8_t *, size_t); +int nd_cpack_init(struct cpack_state *, const uint8_t *, size_t); -int cpack_uint8(netdissect_options *, struct cpack_state *, uint8_t *); -int cpack_int8(netdissect_options *, struct cpack_state *, int8_t *); -int cpack_uint16(netdissect_options *, struct cpack_state *, uint16_t *); -int cpack_int16(netdissect_options *, struct cpack_state *, int16_t *); -int cpack_uint32(netdissect_options *, struct cpack_state *, uint32_t *); -int cpack_int32(netdissect_options *, struct cpack_state *, int32_t *); -int cpack_uint64(netdissect_options *, struct cpack_state *, uint64_t *); -int cpack_int64(netdissect_options *, struct cpack_state *, int64_t *); +int nd_cpack_uint8(netdissect_options *, struct cpack_state *, uint8_t *); +int nd_cpack_int8(netdissect_options *, struct cpack_state *, int8_t *); +int nd_cpack_uint16(netdissect_options *, struct cpack_state *, uint16_t *); +int nd_cpack_int16(netdissect_options *, struct cpack_state *, int16_t *); +int nd_cpack_uint32(netdissect_options *, struct cpack_state *, uint32_t *); +int nd_cpack_int32(netdissect_options *, struct cpack_state *, int32_t *); +int nd_cpack_uint64(netdissect_options *, struct cpack_state *, uint64_t *); +int nd_cpack_int64(netdissect_options *, struct cpack_state *, int64_t *); -const uint8_t *cpack_next_boundary(const uint8_t *buf, const uint8_t *p, size_t alignment); -const uint8_t *cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize); +const uint8_t *nd_cpack_next_boundary(const uint8_t *buf, const uint8_t *p, size_t alignment); +const uint8_t *nd_cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize); -extern int cpack_advance(struct cpack_state *, const size_t); +extern int nd_cpack_advance(struct cpack_state *, const size_t); #endif /* ND_CPACK_H */ diff --git a/print-802_11.c b/print-802_11.c index 1129af43..e901752a 100644 --- a/print-802_11.c +++ b/print-802_11.c @@ -2699,7 +2699,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_TSFT: { uint64_t tsft; - rc = cpack_uint64(ndo, s, &tsft); + rc = nd_cpack_uint64(ndo, s, &tsft); if (rc != 0) goto trunc; ND_PRINT("%" PRIu64 "us tsft ", tsft); @@ -2709,7 +2709,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_FLAGS: { uint8_t flagsval; - rc = cpack_uint8(ndo, s, &flagsval); + rc = nd_cpack_uint8(ndo, s, &flagsval); if (rc != 0) goto trunc; *flagsp = flagsval; @@ -2729,7 +2729,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_RATE: { uint8_t rate; - rc = cpack_uint8(ndo, s, &rate); + rc = nd_cpack_uint8(ndo, s, &rate); if (rc != 0) goto trunc; /* @@ -2780,10 +2780,10 @@ print_radiotap_field(netdissect_options *ndo, uint16_t frequency; uint16_t flags; - rc = cpack_uint16(ndo, s, &frequency); + rc = nd_cpack_uint16(ndo, s, &frequency); if (rc != 0) goto trunc; - rc = cpack_uint16(ndo, s, &flags); + rc = nd_cpack_uint16(ndo, s, &flags); if (rc != 0) goto trunc; /* @@ -2800,10 +2800,10 @@ print_radiotap_field(netdissect_options *ndo, uint8_t hopset; uint8_t hoppat; - rc = cpack_uint8(ndo, s, &hopset); + rc = nd_cpack_uint8(ndo, s, &hopset); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &hoppat); + rc = nd_cpack_uint8(ndo, s, &hoppat); if (rc != 0) goto trunc; ND_PRINT("fhset %u fhpat %u ", hopset, hoppat); @@ -2813,7 +2813,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: { int8_t dbm_antsignal; - rc = cpack_int8(ndo, s, &dbm_antsignal); + rc = nd_cpack_int8(ndo, s, &dbm_antsignal); if (rc != 0) goto trunc; ND_PRINT("%ddBm signal ", dbm_antsignal); @@ -2823,7 +2823,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_DBM_ANTNOISE: { int8_t dbm_antnoise; - rc = cpack_int8(ndo, s, &dbm_antnoise); + rc = nd_cpack_int8(ndo, s, &dbm_antnoise); if (rc != 0) goto trunc; ND_PRINT("%ddBm noise ", dbm_antnoise); @@ -2833,7 +2833,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_LOCK_QUALITY: { uint16_t lock_quality; - rc = cpack_uint16(ndo, s, &lock_quality); + rc = nd_cpack_uint16(ndo, s, &lock_quality); if (rc != 0) goto trunc; ND_PRINT("%u sq ", lock_quality); @@ -2843,7 +2843,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_TX_ATTENUATION: { int16_t tx_attenuation; - rc = cpack_int16(ndo, s, &tx_attenuation); + rc = nd_cpack_int16(ndo, s, &tx_attenuation); if (rc != 0) goto trunc; ND_PRINT("%d tx power ", -tx_attenuation); @@ -2853,7 +2853,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_DB_TX_ATTENUATION: { int8_t db_tx_attenuation; - rc = cpack_int8(ndo, s, &db_tx_attenuation); + rc = nd_cpack_int8(ndo, s, &db_tx_attenuation); if (rc != 0) goto trunc; ND_PRINT("%ddB tx attenuation ", -db_tx_attenuation); @@ -2863,7 +2863,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_DBM_TX_POWER: { int8_t dbm_tx_power; - rc = cpack_int8(ndo, s, &dbm_tx_power); + rc = nd_cpack_int8(ndo, s, &dbm_tx_power); if (rc != 0) goto trunc; ND_PRINT("%ddBm tx power ", dbm_tx_power); @@ -2873,7 +2873,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_ANTENNA: { uint8_t antenna; - rc = cpack_uint8(ndo, s, &antenna); + rc = nd_cpack_uint8(ndo, s, &antenna); if (rc != 0) goto trunc; ND_PRINT("antenna %u ", antenna); @@ -2883,7 +2883,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_DB_ANTSIGNAL: { uint8_t db_antsignal; - rc = cpack_uint8(ndo, s, &db_antsignal); + rc = nd_cpack_uint8(ndo, s, &db_antsignal); if (rc != 0) goto trunc; ND_PRINT("%udB signal ", db_antsignal); @@ -2893,7 +2893,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_DB_ANTNOISE: { uint8_t db_antnoise; - rc = cpack_uint8(ndo, s, &db_antnoise); + rc = nd_cpack_uint8(ndo, s, &db_antnoise); if (rc != 0) goto trunc; ND_PRINT("%udB noise ", db_antnoise); @@ -2903,7 +2903,7 @@ print_radiotap_field(netdissect_options *ndo, case IEEE80211_RADIOTAP_RX_FLAGS: { uint16_t rx_flags; - rc = cpack_uint16(ndo, s, &rx_flags); + rc = nd_cpack_uint16(ndo, s, &rx_flags); if (rc != 0) goto trunc; /* Do nothing for now */ @@ -2916,16 +2916,16 @@ print_radiotap_field(netdissect_options *ndo, uint8_t channel; uint8_t maxpower; - rc = cpack_uint32(ndo, s, &flags); + rc = nd_cpack_uint32(ndo, s, &flags); if (rc != 0) goto trunc; - rc = cpack_uint16(ndo, s, &frequency); + rc = nd_cpack_uint16(ndo, s, &frequency); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &channel); + rc = nd_cpack_uint8(ndo, s, &channel); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &maxpower); + rc = nd_cpack_uint8(ndo, s, &maxpower); if (rc != 0) goto trunc; print_chaninfo(ndo, frequency, flags, presentflags); @@ -2944,13 +2944,13 @@ print_radiotap_field(netdissect_options *ndo, }; float htrate; - rc = cpack_uint8(ndo, s, &known); + rc = nd_cpack_uint8(ndo, s, &known); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &flags); + rc = nd_cpack_uint8(ndo, s, &flags); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &mcs_index); + rc = nd_cpack_uint8(ndo, s, &mcs_index); if (rc != 0) goto trunc; if (known & IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN) { @@ -3032,16 +3032,16 @@ print_radiotap_field(netdissect_options *ndo, uint8_t delim_crc; uint8_t reserved; - rc = cpack_uint32(ndo, s, &reference_num); + rc = nd_cpack_uint32(ndo, s, &reference_num); if (rc != 0) goto trunc; - rc = cpack_uint16(ndo, s, &flags); + rc = nd_cpack_uint16(ndo, s, &flags); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &delim_crc); + rc = nd_cpack_uint8(ndo, s, &delim_crc); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &reserved); + rc = nd_cpack_uint8(ndo, s, &reserved); if (rc != 0) goto trunc; /* Do nothing for now */ @@ -3091,27 +3091,27 @@ print_radiotap_field(netdissect_options *ndo, "unknown (31)" }; - rc = cpack_uint16(ndo, s, &known); + rc = nd_cpack_uint16(ndo, s, &known); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &flags); + rc = nd_cpack_uint8(ndo, s, &flags); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &bandwidth); + rc = nd_cpack_uint8(ndo, s, &bandwidth); if (rc != 0) goto trunc; for (i = 0; i < 4; i++) { - rc = cpack_uint8(ndo, s, &mcs_nss[i]); + rc = nd_cpack_uint8(ndo, s, &mcs_nss[i]); if (rc != 0) goto trunc; } - rc = cpack_uint8(ndo, s, &coding); + rc = nd_cpack_uint8(ndo, s, &coding); if (rc != 0) goto trunc; - rc = cpack_uint8(ndo, s, &group_id); + rc = nd_cpack_uint8(ndo, s, &group_id); if (rc != 0) goto trunc; - rc = cpack_uint16(ndo, s, &partial_aid); + rc = nd_cpack_uint16(ndo, s, &partial_aid); if (rc != 0) goto trunc; for (i = 0; i < 4; i++) { @@ -3252,13 +3252,13 @@ ieee802_11_radio_print(netdissect_options *ndo, nd_print_trunc(ndo); return caplen; } - cpack_init(&cpacker, (const uint8_t *)hdr, len); /* align against header start */ - cpack_advance(&cpacker, sizeof(*hdr)); /* includes the 1st bitmap */ + nd_cpack_init(&cpacker, (const uint8_t *)hdr, len); /* align against header start */ + nd_cpack_advance(&cpacker, sizeof(*hdr)); /* includes the 1st bitmap */ for (last_presentp = &hdr->it_present; (const u_char*)(last_presentp + 1) <= p + len && IS_EXTENDED(last_presentp); last_presentp++) - cpack_advance(&cpacker, sizeof(hdr->it_present)); /* more bitmaps */ + nd_cpack_advance(&cpacker, sizeof(hdr->it_present)); /* more bitmaps */ /* are there more bitmap extensions than bytes in header? */ if ((const u_char*)(last_presentp + 1) > p + len) { @@ -3294,7 +3294,7 @@ ieee802_11_radio_print(netdissect_options *ndo, * it'd be added here; use vendor_oui and * vendor_subnamespace to interpret the fields. */ - if (cpack_advance(&cpacker, skip_length) != 0) { + if (nd_cpack_advance(&cpacker, skip_length) != 0) { /* * Ran out of space in the packet. */ @@ -3357,27 +3357,27 @@ ieee802_11_radio_print(netdissect_options *ndo, */ bit0 = 0; vendor_namespace = 1; - if ((cpack_align_and_reserve(&cpacker, 2)) == NULL) { + if ((nd_cpack_align_and_reserve(&cpacker, 2)) == NULL) { nd_print_trunc(ndo); break; } - if (cpack_uint8(ndo, &cpacker, &vendor_oui[0]) != 0) { + if (nd_cpack_uint8(ndo, &cpacker, &vendor_oui[0]) != 0) { nd_print_trunc(ndo); break; } - if (cpack_uint8(ndo, &cpacker, &vendor_oui[1]) != 0) { + if (nd_cpack_uint8(ndo, &cpacker, &vendor_oui[1]) != 0) { nd_print_trunc(ndo); break; } - if (cpack_uint8(ndo, &cpacker, &vendor_oui[2]) != 0) { + if (nd_cpack_uint8(ndo, &cpacker, &vendor_oui[2]) != 0) { nd_print_trunc(ndo); break; } - if (cpack_uint8(ndo, &cpacker, &vendor_subnamespace) != 0) { + if (nd_cpack_uint8(ndo, &cpacker, &vendor_subnamespace) != 0) { nd_print_trunc(ndo); break; } - if (cpack_uint16(ndo, &cpacker, &skip_length) != 0) { + if (nd_cpack_uint16(ndo, &cpacker, &skip_length) != 0) { nd_print_trunc(ndo); break; }