wsutil: add a header that defines some "round to power of 2" macros.
Add macros to round to multiples of 2, 4, 8, 16, and 32. Use them instead of independently defined macros. (We don't define a general "round to a power of 2" macro to avoid the risk of somebody passing something other than a power of 2 to it.)
This commit is contained in:
parent
f541e5e769
commit
25a254823f
|
@ -18,6 +18,7 @@
|
||||||
#include <epan/exceptions.h>
|
#include <epan/exceptions.h>
|
||||||
#include <epan/to_str.h>
|
#include <epan/to_str.h>
|
||||||
#include <wsutil/pint.h>
|
#include <wsutil/pint.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The Aeron protocol is defined at
|
* The Aeron protocol is defined at
|
||||||
|
@ -55,7 +56,7 @@ typedef struct
|
||||||
|
|
||||||
static int aeron_pos_roundup(int offset)
|
static int aeron_pos_roundup(int offset)
|
||||||
{
|
{
|
||||||
return ((offset+31) & (~31));
|
return WS_ROUNDUP_32(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aeron_pos_compare(const aeron_pos_t * pos1, const aeron_pos_t * pos2)
|
static int aeron_pos_compare(const aeron_pos_t * pos1, const aeron_pos_t * pos2)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <epan/packet.h>
|
#include <epan/packet.h>
|
||||||
#include <epan/expert.h>
|
#include <epan/expert.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
void proto_register_AllJoyn(void);
|
void proto_register_AllJoyn(void);
|
||||||
void proto_reg_handoff_AllJoyn(void);
|
void proto_reg_handoff_AllJoyn(void);
|
||||||
|
@ -245,9 +246,9 @@ static gint ett_alljoyn_mess_header = -1;
|
||||||
static gint ett_alljoyn_mess_body_parameters = -1;
|
static gint ett_alljoyn_mess_body_parameters = -1;
|
||||||
static gint ett_alljoyn_ardp = -1; /* This is the top ARDP tree. */
|
static gint ett_alljoyn_ardp = -1; /* This is the top ARDP tree. */
|
||||||
|
|
||||||
#define ROUND_TO_2BYTE(len) ((len + 1) & ~1)
|
#define ROUND_TO_2BYTE(len) WS_ROUNDUP_2(len)
|
||||||
#define ROUND_TO_4BYTE(len) ((len + 3) & ~3)
|
#define ROUND_TO_4BYTE(len) WS_ROUNDUP_4(len)
|
||||||
#define ROUND_TO_8BYTE(len) ((len + 7) & ~7)
|
#define ROUND_TO_8BYTE(len) WS_ROUNDUP_8(len)
|
||||||
|
|
||||||
static const value_string endian_encoding_vals[] = {
|
static const value_string endian_encoding_vals[] = {
|
||||||
{ 'B', "Big endian" },
|
{ 'B', "Big endian" },
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <wiretap/wtap.h>
|
#include <wiretap/wtap.h>
|
||||||
#include <epan/expert.h>
|
#include <epan/expert.h>
|
||||||
#include <epan/ptvcursor.h>
|
#include <epan/ptvcursor.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
#include "packet-tcp.h"
|
#include "packet-tcp.h"
|
||||||
|
|
||||||
#define DBUS_MAX_ARRAY_LEN (64 * 1024 * 1024)
|
#define DBUS_MAX_ARRAY_LEN (64 * 1024 * 1024)
|
||||||
|
@ -1212,7 +1213,7 @@ get_dbus_message_len(packet_info *pinfo _U_, tvbuff_t *tvb,
|
||||||
}
|
}
|
||||||
|
|
||||||
len_hdr = DBUS_HEADER_LEN + get_guint32(tvb, offset + 12);
|
len_hdr = DBUS_HEADER_LEN + get_guint32(tvb, offset + 12);
|
||||||
len_hdr = (len_hdr + 7) & ~7;
|
len_hdr = WS_ROUNDUP_8(len_hdr);
|
||||||
len_body = get_guint32(tvb, offset + 4);
|
len_body = get_guint32(tvb, offset + 4);
|
||||||
|
|
||||||
return len_hdr + len_body;
|
return len_hdr + len_body;
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include <epan/exceptions.h>
|
#include <epan/exceptions.h>
|
||||||
#include <wsutil/pint.h>
|
#include <wsutil/pint.h>
|
||||||
#include <wsutil/str_util.h>
|
#include <wsutil/str_util.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
#include <epan/addr_resolv.h>
|
#include <epan/addr_resolv.h>
|
||||||
#include <epan/address_types.h>
|
#include <epan/address_types.h>
|
||||||
#include <epan/strutil.h>
|
#include <epan/strutil.h>
|
||||||
|
@ -135,10 +136,6 @@ sta_prop_equal_fn(gconstpointer v, gconstpointer w)
|
||||||
return memcmp(k1, k2, 6) == 0; /* Compare each address for equality */
|
return memcmp(k1, k2, 6) == 0; /* Compare each address for equality */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef roundup2
|
|
||||||
#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* bitmask for bits [l..h]
|
/* bitmask for bits [l..h]
|
||||||
* taken from kernel's include/linux/bitops.h
|
* taken from kernel's include/linux/bitops.h
|
||||||
*/
|
*/
|
||||||
|
@ -8359,7 +8356,7 @@ add_mimo_csi_matrices_report(proto_tree *tree, tvbuff_t *tvb, int offset, mimo_c
|
||||||
|
|
||||||
ns = get_mimo_ns(mimo_cntrl.chan_width, mimo_cntrl.grouping);
|
ns = get_mimo_ns(mimo_cntrl.chan_width, mimo_cntrl.grouping);
|
||||||
csi_matrix_size = ns*(3+(2*mimo_cntrl.nc*mimo_cntrl.nr*mimo_cntrl.coefficient_size));
|
csi_matrix_size = ns*(3+(2*mimo_cntrl.nc*mimo_cntrl.nr*mimo_cntrl.coefficient_size));
|
||||||
csi_matrix_size = roundup2(csi_matrix_size, 8) / 8;
|
csi_matrix_size = WS_ROUNDUP_8(csi_matrix_size) / 8;
|
||||||
proto_tree_add_item(snr_tree, hf_ieee80211_ff_mimo_csi_matrices, tvb, offset, csi_matrix_size, ENC_NA);
|
proto_tree_add_item(snr_tree, hf_ieee80211_ff_mimo_csi_matrices, tvb, offset, csi_matrix_size, ENC_NA);
|
||||||
offset += csi_matrix_size;
|
offset += csi_matrix_size;
|
||||||
return offset - start_offset;
|
return offset - start_offset;
|
||||||
|
@ -8387,7 +8384,7 @@ add_mimo_beamforming_feedback_report(proto_tree *tree, tvbuff_t *tvb, int offset
|
||||||
|
|
||||||
ns = get_mimo_ns(mimo_cntrl.chan_width, mimo_cntrl.grouping);
|
ns = get_mimo_ns(mimo_cntrl.chan_width, mimo_cntrl.grouping);
|
||||||
csi_matrix_size = ns*(2*mimo_cntrl.nc*mimo_cntrl.nr*mimo_cntrl.coefficient_size);
|
csi_matrix_size = ns*(2*mimo_cntrl.nc*mimo_cntrl.nr*mimo_cntrl.coefficient_size);
|
||||||
csi_matrix_size = roundup2(csi_matrix_size, 8) / 8;
|
csi_matrix_size = WS_ROUNDUP_8(csi_matrix_size) / 8;
|
||||||
proto_tree_add_item(snr_tree, hf_ieee80211_ff_mimo_csi_bf_matrices, tvb, offset, csi_matrix_size, ENC_NA);
|
proto_tree_add_item(snr_tree, hf_ieee80211_ff_mimo_csi_bf_matrices, tvb, offset, csi_matrix_size, ENC_NA);
|
||||||
offset += csi_matrix_size;
|
offset += csi_matrix_size;
|
||||||
return offset - start_offset;
|
return offset - start_offset;
|
||||||
|
@ -8430,7 +8427,7 @@ add_mimo_compressed_beamforming_feedback_report(proto_tree *tree, tvbuff_t *tvb,
|
||||||
na = get_mimo_na(mimo_cntrl.nr, mimo_cntrl.nc);
|
na = get_mimo_na(mimo_cntrl.nr, mimo_cntrl.nc);
|
||||||
ns = get_mimo_ns(mimo_cntrl.chan_width, mimo_cntrl.grouping);
|
ns = get_mimo_ns(mimo_cntrl.chan_width, mimo_cntrl.grouping);
|
||||||
csi_matrix_size = ns*(na*((mimo_cntrl.codebook_info+1)*2 + 2)/2);
|
csi_matrix_size = ns*(na*((mimo_cntrl.codebook_info+1)*2 + 2)/2);
|
||||||
csi_matrix_size = roundup2(csi_matrix_size, 8) / 8;
|
csi_matrix_size = WS_ROUNDUP_8(csi_matrix_size) / 8;
|
||||||
proto_tree_add_item(snr_tree, hf_ieee80211_ff_mimo_csi_cbf_matrices, tvb, offset, csi_matrix_size, ENC_NA);
|
proto_tree_add_item(snr_tree, hf_ieee80211_ff_mimo_csi_cbf_matrices, tvb, offset, csi_matrix_size, ENC_NA);
|
||||||
offset += csi_matrix_size;
|
offset += csi_matrix_size;
|
||||||
return offset - start_offset;
|
return offset - start_offset;
|
||||||
|
@ -8495,7 +8492,7 @@ capture_ieee80211_common(const guchar * pd, int offset, int len,
|
||||||
* is before the mesh header, possibly because it doesn't
|
* is before the mesh header, possibly because it doesn't
|
||||||
* recognize the mesh header.
|
* recognize the mesh header.
|
||||||
*/
|
*/
|
||||||
hdr_length = roundup2(hdr_length, 4);
|
hdr_length = WS_ROUNDUP_4(hdr_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -14365,7 +14362,7 @@ add_ff_vht_compressed_beamforming_report(proto_tree *tree, tvbuff_t *tvb, packet
|
||||||
carry = 1;
|
carry = 1;
|
||||||
else
|
else
|
||||||
carry = 0;
|
carry = 0;
|
||||||
len = roundup2((pos + matrix_size), 8)/8 - roundup2(pos, 8)/8;
|
len = WS_ROUNDUP_8(pos + matrix_size)/8 - WS_ROUNDUP_8(pos)/8;
|
||||||
scidx = vht_compressed_skip_scidx(chan_width, grouping, scidx);
|
scidx = vht_compressed_skip_scidx(chan_width, grouping, scidx);
|
||||||
|
|
||||||
/* TODO : For certain values from na_arr, there is always going be a carry over or overflow from the previous or
|
/* TODO : For certain values from na_arr, there is always going be a carry over or overflow from the previous or
|
||||||
|
@ -32555,7 +32552,7 @@ dissect_ieee80211_pv0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
||||||
* is before the mesh header, possibly because it doesn't
|
* is before the mesh header, possibly because it doesn't
|
||||||
* recognize the mesh header.
|
* recognize the mesh header.
|
||||||
*/
|
*/
|
||||||
hdr_len = roundup2(hdr_len, 4);
|
hdr_len = WS_ROUNDUP_4(hdr_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FCF_FRAME_TYPE (fcf) == DATA_FRAME) {
|
if (FCF_FRAME_TYPE (fcf) == DATA_FRAME) {
|
||||||
|
@ -33909,7 +33906,7 @@ dissect_ieee80211_pv0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
||||||
msdu_length = tvb_get_ntohs(next_tvb, msdu_offset+12);
|
msdu_length = tvb_get_ntohs(next_tvb, msdu_offset+12);
|
||||||
|
|
||||||
parent_item = proto_tree_add_item(mpdu_tree, hf_ieee80211_amsdu_subframe, next_tvb,
|
parent_item = proto_tree_add_item(mpdu_tree, hf_ieee80211_amsdu_subframe, next_tvb,
|
||||||
msdu_offset, roundup2(msdu_offset+14+msdu_length, 4), ENC_NA);
|
msdu_offset, WS_ROUNDUP_4(msdu_offset+14+msdu_length), ENC_NA);
|
||||||
proto_item_append_text(parent_item, " #%u", i);
|
proto_item_append_text(parent_item, " #%u", i);
|
||||||
subframe_tree = proto_item_add_subtree(parent_item, ett_msdu_aggregation_subframe_tree);
|
subframe_tree = proto_item_add_subtree(parent_item, ett_msdu_aggregation_subframe_tree);
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -33929,7 +33926,7 @@ dissect_ieee80211_pv0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
||||||
msdu_offset += 14;
|
msdu_offset += 14;
|
||||||
msdu_tvb = tvb_new_subset_length(next_tvb, msdu_offset, msdu_length);
|
msdu_tvb = tvb_new_subset_length(next_tvb, msdu_offset, msdu_length);
|
||||||
call_dissector(llc_handle, msdu_tvb, pinfo, subframe_tree);
|
call_dissector(llc_handle, msdu_tvb, pinfo, subframe_tree);
|
||||||
msdu_offset = roundup2(msdu_offset+msdu_length, 4);
|
msdu_offset = WS_ROUNDUP_4(msdu_offset+msdu_length);
|
||||||
} while (tvb_reported_length_remaining(next_tvb, msdu_offset) > 14);
|
} while (tvb_reported_length_remaining(next_tvb, msdu_offset) > 14);
|
||||||
} else {
|
} else {
|
||||||
/* I guess some bridges take Netware Ethernet_802_3 frames,
|
/* I guess some bridges take Netware Ethernet_802_3 frames,
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <epan/crc32-tvb.h>
|
#include <epan/crc32-tvb.h>
|
||||||
#include <wsutil/crc32.h>
|
#include <wsutil/crc32.h>
|
||||||
#include <wsutil/strtoi.h>
|
#include <wsutil/strtoi.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
void proto_register_iscsi(void);
|
void proto_register_iscsi(void);
|
||||||
void proto_reg_handoff_iscsi(void);
|
void proto_reg_handoff_iscsi(void);
|
||||||
|
@ -1035,7 +1036,7 @@ dissect_iscsi_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint off
|
||||||
|
|
||||||
/* strip off padding bytes */
|
/* strip off padding bytes */
|
||||||
if(ahs_offset & 3){
|
if(ahs_offset & 3){
|
||||||
ahs_offset=(ahs_offset+3) & ~3;
|
ahs_offset=WS_ROUNDUP_4(ahs_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <epan/arptypes.h>
|
#include <epan/arptypes.h>
|
||||||
#include <epan/exceptions.h>
|
#include <epan/exceptions.h>
|
||||||
#include <wiretap/wtap.h>
|
#include <wiretap/wtap.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
#include "packet-netlink.h"
|
#include "packet-netlink.h"
|
||||||
|
|
||||||
|
@ -348,7 +349,7 @@ dissect_netlink_attributes_common(tvbuff_t *tvb, header_field_info *hfi_type, in
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assume offset already aligned, next offset is rta_len plus alignment. */
|
/* Assume offset already aligned, next offset is rta_len plus alignment. */
|
||||||
rta_len = MIN((rta_len + 3) & ~3, data_length);
|
rta_len = MIN(WS_ROUNDUP_4(rta_len), data_length);
|
||||||
offset += rta_len - 4; /* Header was already skipped */
|
offset += rta_len - 4; /* Header was already skipped */
|
||||||
if (data_length < rta_len)
|
if (data_length < rta_len)
|
||||||
THROW(ReportedBoundsError);
|
THROW(ReportedBoundsError);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <epan/etypes.h>
|
#include <epan/etypes.h>
|
||||||
#include <epan/packet.h>
|
#include <epan/packet.h>
|
||||||
#include <wiretap/wtap.h>
|
#include <wiretap/wtap.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
#include "packet-netlink.h"
|
#include "packet-netlink.h"
|
||||||
|
|
||||||
|
@ -280,7 +281,7 @@ dissect_nflog(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U
|
||||||
if (tlv_type == WS_NFULA_PAYLOAD)
|
if (tlv_type == WS_NFULA_PAYLOAD)
|
||||||
next_tvb = tvb_new_subset_length(tvb, offset + 4, value_len);
|
next_tvb = tvb_new_subset_length(tvb, offset + 4, value_len);
|
||||||
|
|
||||||
offset += ((tlv_len + 3) & ~3); /* next TLV aligned to 4B */
|
offset += WS_ROUNDUP_4(tlv_len); /* next TLV aligned to 4B */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next_tvb && hw_protocol) {
|
if (next_tvb && hw_protocol) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <epan/expert.h>
|
#include <epan/expert.h>
|
||||||
#include <epan/ipproto.h>
|
#include <epan/ipproto.h>
|
||||||
#include <epan/addr_resolv.h>
|
#include <epan/addr_resolv.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
void proto_register_openflow_v6(void);
|
void proto_register_openflow_v6(void);
|
||||||
void proto_reg_handoff_openflow_v6(void);
|
void proto_reg_handoff_openflow_v6(void);
|
||||||
|
@ -1138,7 +1139,7 @@ dissect_openflow_stats_v6(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tre
|
||||||
offset = oxs_end;
|
offset = oxs_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
padding = ((stats_length + 7) & ~7) - stats_length;
|
padding = WS_ROUNDUP_8(stats_length) - stats_length;
|
||||||
if (padding) {
|
if (padding) {
|
||||||
proto_tree_add_item(tree, hf_openflow_v6_stats_pad, tvb, oxs_end, padding, ENC_NA);
|
proto_tree_add_item(tree, hf_openflow_v6_stats_pad, tvb, oxs_end, padding, ENC_NA);
|
||||||
offset += padding;
|
offset += padding;
|
||||||
|
@ -2863,7 +2864,7 @@ dissect_openflow_port_desc_prop_v6(tvbuff_t *tvb, packet_info *pinfo _U_, proto_
|
||||||
while(offset < fields_end) {
|
while(offset < fields_end) {
|
||||||
offset = dissect_openflow_oxm_v6(tvb, pinfo, prop_tree, offset, length);
|
offset = dissect_openflow_oxm_v6(tvb, pinfo, prop_tree, offset, length);
|
||||||
}
|
}
|
||||||
offset+=((prop_length + 7) & ~7) - prop_length;
|
offset+=WS_ROUNDUP_8(prop_length) - prop_length;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OFPPDPT_RECIRCULATE:
|
case OFPPDPT_RECIRCULATE:
|
||||||
|
@ -2872,7 +2873,7 @@ dissect_openflow_port_desc_prop_v6(tvbuff_t *tvb, packet_info *pinfo _U_, proto_
|
||||||
proto_tree_add_item(tree, hf_openflow_v6_port_desc_prop_recirculate_port_no, tvb, offset, 4, ENC_BIG_ENDIAN);
|
proto_tree_add_item(tree, hf_openflow_v6_port_desc_prop_recirculate_port_no, tvb, offset, 4, ENC_BIG_ENDIAN);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
}
|
}
|
||||||
offset+=((prop_length + 7) & ~7) - prop_length;
|
offset+=WS_ROUNDUP_8(prop_length) - prop_length;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OFPPDPT_EXPERIMENTER:
|
case OFPPDPT_EXPERIMENTER:
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
#include <epan/in_cksum.h>
|
#include <epan/in_cksum.h>
|
||||||
#include <epan/expert.h>
|
#include <epan/expert.h>
|
||||||
#include <epan/addr_resolv.h>
|
#include <epan/addr_resolv.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
#include "packet-rsvp.h"
|
#include "packet-rsvp.h"
|
||||||
|
|
||||||
void proto_register_ospf(void);
|
void proto_register_ospf(void);
|
||||||
|
@ -2811,7 +2812,7 @@ dissect_ospf_lsa_opaque_ri(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_
|
||||||
proto_tree_add_item(stlv_tree, hf_ospf_tlv_value, tvb, stlv_offset + 4, stlv_length, ENC_NA);
|
proto_tree_add_item(stlv_tree, hf_ospf_tlv_value, tvb, stlv_offset + 4, stlv_length, ENC_NA);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stlv_offset += 4 + ((stlv_length + 3) & ~3);
|
stlv_offset += 4 + WS_ROUNDUP_4(stlv_length);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2863,7 +2864,7 @@ dissect_ospf_lsa_opaque_ri(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_
|
||||||
* RFC 7770, section 2.3: 4-octet aligned, but type, length and padding
|
* RFC 7770, section 2.3: 4-octet aligned, but type, length and padding
|
||||||
* is not included in the length.
|
* is not included in the length.
|
||||||
* */
|
* */
|
||||||
offset += 4 + ((tlv_length + 3) & ~3);
|
offset += 4 + WS_ROUNDUP_4(tlv_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3013,7 +3014,7 @@ dissect_ospf_lsa_ext_prefix(tvbuff_t *tvb, packet_info *pinfo, int offset, proto
|
||||||
proto_tree_add_item(stlv_tree, hf_ospf_tlv_value, tvb, stlv_offset + 4, stlv_length, ENC_NA);
|
proto_tree_add_item(stlv_tree, hf_ospf_tlv_value, tvb, stlv_offset + 4, stlv_length, ENC_NA);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stlv_offset += 4 + ((stlv_length + 3) & ~3);
|
stlv_offset += 4 + WS_ROUNDUP_4(stlv_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3021,7 +3022,7 @@ dissect_ospf_lsa_ext_prefix(tvbuff_t *tvb, packet_info *pinfo, int offset, proto
|
||||||
* RFC 7770, section 2.3: 4-octet aligned, but type, length and padding
|
* RFC 7770, section 2.3: 4-octet aligned, but type, length and padding
|
||||||
* is not included in the length.
|
* is not included in the length.
|
||||||
* */
|
* */
|
||||||
offset += 4 + ((tlv_length + 3) & ~3);
|
offset += 4 + WS_ROUNDUP_4(tlv_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3180,7 +3181,7 @@ dissect_ospf_lsa_ext_link(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_t
|
||||||
proto_tree_add_item(stlv_tree, hf_ospf_tlv_value, tvb, stlv_offset + 4, stlv_length, ENC_NA);
|
proto_tree_add_item(stlv_tree, hf_ospf_tlv_value, tvb, stlv_offset + 4, stlv_length, ENC_NA);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stlv_offset += 4 + ((stlv_length + 3) & ~3);
|
stlv_offset += 4 + WS_ROUNDUP_4(stlv_length);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -3203,7 +3204,7 @@ dissect_ospf_lsa_ext_link(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_t
|
||||||
* RFC 7770, section 2.3: 4-octet aligned, but type, length and padding
|
* RFC 7770, section 2.3: 4-octet aligned, but type, length and padding
|
||||||
* is not included in the length.
|
* is not included in the length.
|
||||||
* */
|
* */
|
||||||
offset += 4 + ((tlv_length + 3) & ~3);
|
offset += 4 + WS_ROUNDUP_4(tlv_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <epan/packet.h>
|
#include <epan/packet.h>
|
||||||
#include <epan/to_str.h>
|
#include <epan/to_str.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
#define PATHPORT_UDP_PORT 3792 /* Not IANA registered */
|
#define PATHPORT_UDP_PORT 3792 /* Not IANA registered */
|
||||||
#define PATHPORT_MIN_LENGTH 24 /* HEADER + 1 PDU */
|
#define PATHPORT_MIN_LENGTH 24 /* HEADER + 1 PDU */
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
#define PATHPORT_HEADER_END (PATHPORT_HEADER_OFFSET + PATHPORT_HEADER_LENGTH)
|
#define PATHPORT_HEADER_END (PATHPORT_HEADER_OFFSET + PATHPORT_HEADER_LENGTH)
|
||||||
|
|
||||||
/** Rounds the specified integer up to the next multiple of four. */
|
/** Rounds the specified integer up to the next multiple of four. */
|
||||||
#define roof4(a) (((a)+3)&~3)
|
#define roof4(a) WS_ROUNDUP_4(a)
|
||||||
|
|
||||||
void proto_reg_handoff_pathport(void);
|
void proto_reg_handoff_pathport(void);
|
||||||
void proto_register_pathport(void);
|
void proto_register_pathport(void);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <epan/prefs.h>
|
#include <epan/prefs.h>
|
||||||
#include <epan/strutil.h>
|
#include <epan/strutil.h>
|
||||||
#include <epan/expert.h>
|
#include <epan/expert.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
#include "packet-tcp.h"
|
#include "packet-tcp.h"
|
||||||
|
|
||||||
#define TCP_PORT_PVFS2 3334 /* Not IANA registered */
|
#define TCP_PORT_PVFS2 3334 /* Not IANA registered */
|
||||||
|
@ -756,9 +757,6 @@ dissect_pvfs2_ds_type(tvbuff_t *tvb, proto_tree *tree, int offset,
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define roundup4(x) (((x) + 3) & ~3)
|
|
||||||
#define roundup8(x) (((x) + 7) & ~7)
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dissect_pvfs_opaque_data(tvbuff_t *tvb, int offset,
|
dissect_pvfs_opaque_data(tvbuff_t *tvb, int offset,
|
||||||
proto_tree *tree,
|
proto_tree *tree,
|
||||||
|
@ -813,9 +811,9 @@ dissect_pvfs_opaque_data(tvbuff_t *tvb, int offset,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!string_data)
|
if (!string_data)
|
||||||
string_length_full = roundup4(string_length);
|
string_length_full = WS_ROUNDUP_4(string_length);
|
||||||
else
|
else
|
||||||
string_length_full = roundup8(4 + string_length);
|
string_length_full = WS_ROUNDUP_8(4 + string_length);
|
||||||
|
|
||||||
if (string_length_captured < string_length) {
|
if (string_length_captured < string_length) {
|
||||||
/* truncated string */
|
/* truncated string */
|
||||||
|
@ -1148,7 +1146,7 @@ dissect_pvfs_distribution(tvbuff_t *tvb, proto_tree *tree, int offset)
|
||||||
tmpstr = (char *) tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 4, distlen, ENC_ASCII);
|
tmpstr = (char *) tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 4, distlen, ENC_ASCII);
|
||||||
|
|
||||||
/* 'distlen' does not include the NULL terminator */
|
/* 'distlen' does not include the NULL terminator */
|
||||||
total_len = roundup8(4 + distlen + 1);
|
total_len = WS_ROUNDUP_8(4 + distlen + 1);
|
||||||
|
|
||||||
if (((distlen + 1) == PVFS_DIST_SIMPLE_STRIPE_NAME_SIZE) &&
|
if (((distlen + 1) == PVFS_DIST_SIMPLE_STRIPE_NAME_SIZE) &&
|
||||||
(g_ascii_strncasecmp(tmpstr, PVFS_DIST_SIMPLE_STRIPE_NAME,
|
(g_ascii_strncasecmp(tmpstr, PVFS_DIST_SIMPLE_STRIPE_NAME,
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "read_keytab_file.h"
|
#include "read_keytab_file.h"
|
||||||
|
|
||||||
#include <wsutil/wsgcrypt.h>
|
#include <wsutil/wsgcrypt.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
//#define DEBUG_SMB2
|
//#define DEBUG_SMB2
|
||||||
#ifdef DEBUG_SMB2
|
#ifdef DEBUG_SMB2
|
||||||
|
@ -5313,7 +5314,7 @@ dissect_smb2_negotiate_protocol_request(tvbuff_t *tvb, packet_info *pinfo, proto
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ncc; i++) {
|
for (i = 0; i < ncc; i++) {
|
||||||
offset = (offset + 7) & ~7;
|
offset = WS_ROUNDUP_8(offset);
|
||||||
offset = dissect_smb2_negotiate_context(tvb, pinfo, tree, offset, si);
|
offset = dissect_smb2_negotiate_context(tvb, pinfo, tree, offset, si);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5430,7 +5431,7 @@ dissect_smb2_negotiate_protocol_response(tvbuff_t *tvb, packet_info *pinfo, prot
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ncc; i++) {
|
for (i = 0; i < ncc; i++) {
|
||||||
offset = (offset + 7) & ~7;
|
offset = WS_ROUNDUP_8(offset);
|
||||||
offset = dissect_smb2_negotiate_context(tvb, pinfo, tree, offset, si);
|
offset = dissect_smb2_negotiate_context(tvb, pinfo, tree, offset, si);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#include <epan/packet.h>
|
#include <epan/packet.h>
|
||||||
#include <epan/expert.h>
|
#include <epan/expert.h>
|
||||||
#include <epan/to_str.h>
|
#include <epan/to_str.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
#include "packet-tcp.h"
|
#include "packet-tcp.h"
|
||||||
|
|
||||||
void proto_register_stun(void);
|
void proto_register_stun(void);
|
||||||
|
@ -1068,7 +1069,7 @@ dissect_stun_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboole
|
||||||
att_type = tvb_get_ntohs(tvb, offset); /* Attribute type field in attribute header */
|
att_type = tvb_get_ntohs(tvb, offset); /* Attribute type field in attribute header */
|
||||||
att_length = tvb_get_ntohs(tvb, offset+2); /* Attribute length field in attribute header */
|
att_length = tvb_get_ntohs(tvb, offset+2); /* Attribute length field in attribute header */
|
||||||
if (network_version >= NET_VER_5389)
|
if (network_version >= NET_VER_5389)
|
||||||
att_length_pad = (att_length + 3) & ~3; /* Attribute length including padding */
|
att_length_pad = WS_ROUNDUP_4(att_length); /* Attribute length including padding */
|
||||||
else
|
else
|
||||||
att_length_pad = att_length;
|
att_length_pad = att_length;
|
||||||
att_type_display = att_type;
|
att_type_display = att_type;
|
||||||
|
@ -1304,7 +1305,7 @@ dissect_stun_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboole
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Hopefully, in case MS-TURN ever gets PASSWORD-ALGORITHM(S) support they will add it with padding */
|
/* Hopefully, in case MS-TURN ever gets PASSWORD-ALGORITHM(S) support they will add it with padding */
|
||||||
alg_param_len_pad = (alg_param_len + 3) & ~3;
|
alg_param_len_pad = WS_ROUNDUP_4(alg_param_len);
|
||||||
|
|
||||||
if (alg_param_len < alg_param_len_pad)
|
if (alg_param_len < alg_param_len_pad)
|
||||||
proto_tree_add_uint(att_tree, hf_stun_att_padding, tvb, loopoffset+alg_param_len, alg_param_len_pad-alg_param_len, alg_param_len_pad-alg_param_len);
|
proto_tree_add_uint(att_tree, hf_stun_att_padding, tvb, loopoffset+alg_param_len, alg_param_len_pad-alg_param_len, alg_param_len_pad-alg_param_len);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <epan/decode_as.h>
|
#include <epan/decode_as.h>
|
||||||
#include <epan/proto_data.h>
|
#include <epan/proto_data.h>
|
||||||
#include <wsutil/pint.h>
|
#include <wsutil/pint.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
#include "packet-usb.h"
|
#include "packet-usb.h"
|
||||||
#include "packet-mausb.h"
|
#include "packet-mausb.h"
|
||||||
|
@ -4554,7 +4555,7 @@ dissect_darwin_usb_iso_transfer(packet_info *pinfo _U_, proto_tree *tree, usb_he
|
||||||
|
|
||||||
/* Padding to align the next header */
|
/* Padding to align the next header */
|
||||||
offset += frame_header_length;
|
offset += frame_header_length;
|
||||||
offset = ((offset + 3) & ~3);
|
offset = WS_ROUNDUP_4(offset);
|
||||||
iso_tree_start = offset;
|
iso_tree_start = offset;
|
||||||
|
|
||||||
len -= frame_header_length;
|
len -= frame_header_length;
|
||||||
|
@ -4685,7 +4686,7 @@ dissect_freebsd_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, void
|
||||||
*/
|
*/
|
||||||
proto_tree_add_item(frame_tree, hf_usb_frame_data, tvb, offset,
|
proto_tree_add_item(frame_tree, hf_usb_frame_data, tvb, offset,
|
||||||
framelen, ENC_NA);
|
framelen, ENC_NA);
|
||||||
offset += (framelen + 3) & ~3;
|
offset += WS_ROUNDUP_4(framelen);
|
||||||
}
|
}
|
||||||
proto_item_set_end(ti, tvb, offset);
|
proto_item_set_end(ti, tvb, offset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <epan/packet.h>
|
#include <epan/packet.h>
|
||||||
#include <epan/prefs.h>
|
#include <epan/prefs.h>
|
||||||
#include <epan/to_str.h>
|
#include <epan/to_str.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
#include "packet-tcp.h"
|
#include "packet-tcp.h"
|
||||||
|
|
||||||
void proto_reg_handoff_yami(void);
|
void proto_reg_handoff_yami(void);
|
||||||
|
@ -145,7 +146,7 @@ dissect_yami_parameter(tvbuff_t *tvb, proto_tree *tree, int offset, proto_item *
|
||||||
name = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, name_len, ENC_ASCII | ENC_NA);
|
name = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, name_len, ENC_ASCII | ENC_NA);
|
||||||
proto_item_append_text(ti, ": %s", name);
|
proto_item_append_text(ti, ": %s", name);
|
||||||
proto_item_append_text(par_ti, "%s, ", name);
|
proto_item_append_text(par_ti, "%s, ", name);
|
||||||
offset += (name_len + 3) & ~3;
|
offset += WS_ROUNDUP_4(name_len);
|
||||||
proto_tree_add_string(yami_param, &hfi_yami_param_name, tvb, name_offset, offset - name_offset, name);
|
proto_tree_add_string(yami_param, &hfi_yami_param_name, tvb, name_offset, offset - name_offset, name);
|
||||||
|
|
||||||
type = tvb_get_letohl(tvb, offset);
|
type = tvb_get_letohl(tvb, offset);
|
||||||
|
@ -201,7 +202,7 @@ dissect_yami_parameter(tvbuff_t *tvb, proto_tree *tree, int offset, proto_item *
|
||||||
val = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, val_len, ENC_ASCII | ENC_NA);
|
val = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, val_len, ENC_ASCII | ENC_NA);
|
||||||
|
|
||||||
proto_item_append_text(ti, ", Type: string, Value: \"%s\"", val);
|
proto_item_append_text(ti, ", Type: string, Value: \"%s\"", val);
|
||||||
offset += (val_len + 3) & ~3;
|
offset += WS_ROUNDUP_4(val_len);
|
||||||
proto_tree_add_string(yami_param, &hfi_yami_param_value_str, tvb, val_offset, offset - val_offset, val);
|
proto_tree_add_string(yami_param, &hfi_yami_param_value_str, tvb, val_offset, offset - val_offset, val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +221,7 @@ dissect_yami_parameter(tvbuff_t *tvb, proto_tree *tree, int offset, proto_item *
|
||||||
repr = bytes_to_str(wmem_packet_scope(), val, val_len);
|
repr = bytes_to_str(wmem_packet_scope(), val, val_len);
|
||||||
|
|
||||||
proto_item_append_text(ti, ", Type: binary, Value: %s", repr);
|
proto_item_append_text(ti, ", Type: binary, Value: %s", repr);
|
||||||
offset += (val_len + 3) & ~3;
|
offset += WS_ROUNDUP_4(val_len);
|
||||||
proto_tree_add_bytes_format_value(yami_param, &hfi_yami_param_value_bin, tvb, val_offset, offset - val_offset, val, "%s", repr);
|
proto_tree_add_bytes_format_value(yami_param, &hfi_yami_param_value_bin, tvb, val_offset, offset - val_offset, val, "%s", repr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +355,7 @@ dissect_yami_parameter(tvbuff_t *tvb, proto_tree *tree, int offset, proto_item *
|
||||||
|
|
||||||
proto_item_append_text(ti, "\"%s\", ", val);
|
proto_item_append_text(ti, "\"%s\", ", val);
|
||||||
proto_tree_add_string(yami_param, &hfi_yami_param_value_str, tvb, val_offset, offset - val_offset, val);
|
proto_tree_add_string(yami_param, &hfi_yami_param_value_str, tvb, val_offset, offset - val_offset, val);
|
||||||
offset += (val_len + 3) & ~3;
|
offset += WS_ROUNDUP_4(val_len);
|
||||||
}
|
}
|
||||||
proto_item_append_text(ti, "}");
|
proto_item_append_text(ti, "}");
|
||||||
break;
|
break;
|
||||||
|
@ -384,7 +385,7 @@ dissect_yami_parameter(tvbuff_t *tvb, proto_tree *tree, int offset, proto_item *
|
||||||
repr = bytes_to_str(wmem_packet_scope(), val, val_len);
|
repr = bytes_to_str(wmem_packet_scope(), val, val_len);
|
||||||
|
|
||||||
proto_item_append_text(ti, "%s, ", repr);
|
proto_item_append_text(ti, "%s, ", repr);
|
||||||
offset += (val_len + 3) & ~3;
|
offset += WS_ROUNDUP_4(val_len);
|
||||||
proto_tree_add_bytes_format_value(yami_param, &hfi_yami_param_value_bin, tvb, val_offset, offset - val_offset, val, "%s", repr);
|
proto_tree_add_bytes_format_value(yami_param, &hfi_yami_param_value_bin, tvb, val_offset, offset - val_offset, val, "%s", repr);
|
||||||
}
|
}
|
||||||
proto_item_append_text(ti, "}");
|
proto_item_append_text(ti, "}");
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <wsutil/strtoi.h>
|
#include <wsutil/strtoi.h>
|
||||||
#include <wsutil/glib-compat.h>
|
#include <wsutil/glib-compat.h>
|
||||||
#include <wsutil/ws_assert.h>
|
#include <wsutil/ws_assert.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
#include "wtap-int.h"
|
#include "wtap-int.h"
|
||||||
#include "file_wrappers.h"
|
#include "file_wrappers.h"
|
||||||
|
@ -37,7 +38,7 @@
|
||||||
#include "pcapng_module.h"
|
#include "pcapng_module.h"
|
||||||
#include "secrets-types.h"
|
#include "secrets-types.h"
|
||||||
|
|
||||||
#define ROUND_TO_4BYTE(len) ((len + 3) & ~3)
|
#define ROUND_TO_4BYTE(len) WS_ROUNDUP_4(len)
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
|
pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "atm.h"
|
#include "atm.h"
|
||||||
#include "snoop.h"
|
#include "snoop.h"
|
||||||
#include <wsutil/802_11-utils.h>
|
#include <wsutil/802_11-utils.h>
|
||||||
|
#include <wsutil/ws_roundup.h>
|
||||||
|
|
||||||
/* See RFC 1761 for a description of the "snoop" file format. */
|
/* See RFC 1761 for a description of the "snoop" file format. */
|
||||||
|
|
||||||
|
@ -891,7 +892,7 @@ static gboolean snoop_dump(wtap_dumper *wdh,
|
||||||
|
|
||||||
|
|
||||||
/* ... plus enough bytes to pad it to a 4-byte boundary. */
|
/* ... plus enough bytes to pad it to a 4-byte boundary. */
|
||||||
padlen = ((reclen + 3) & ~3) - reclen;
|
padlen = WS_ROUNDUP_4(reclen) - reclen;
|
||||||
reclen += padlen;
|
reclen += padlen;
|
||||||
|
|
||||||
/* Don't write anything we're not willing to read. */
|
/* Don't write anything we're not willing to read. */
|
||||||
|
|
|
@ -71,6 +71,7 @@ set(WSUTIL_PUBLIC_HEADERS
|
||||||
ws_mempbrk.h
|
ws_mempbrk.h
|
||||||
ws_mempbrk_int.h
|
ws_mempbrk_int.h
|
||||||
ws_pipe.h
|
ws_pipe.h
|
||||||
|
ws_roundup.h
|
||||||
wsjson.h
|
wsjson.h
|
||||||
wslog.h
|
wslog.h
|
||||||
xtea.h
|
xtea.h
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ws_roundup.h
|
||||||
|
*
|
||||||
|
* Wireshark - Network traffic analyzer
|
||||||
|
* By Gerald Combs <gerald@wireshark.org>
|
||||||
|
* Copyright 1998 Gerald Combs
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __WS_ROUNDUP_H__
|
||||||
|
#define __WS_ROUNDUP_H__
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Round up to various powers of 2.
|
||||||
|
*/
|
||||||
|
#define WS_ROUNDUP_2(n) (((n) + ((guint)(2U-1U))) & (~((guint)(2U-1U))))
|
||||||
|
#define WS_ROUNDUP_4(n) (((n) + ((guint)(4U-1U))) & (~((guint)(4U-1U))))
|
||||||
|
#define WS_ROUNDUP_8(n) (((n) + ((guint)(8U-1U))) & (~((guint)(8U-1U))))
|
||||||
|
#define WS_ROUNDUP_16(n) (((n) + ((guint)(16U-1U))) & (~((guint)(16U-1U))))
|
||||||
|
#define WS_ROUNDUP_32(n) (((n) + ((guint)(32U-1U))) & (~((guint)(32U-1U))))
|
||||||
|
|
||||||
|
#endif /* __WS_ROUNDUP_H__ */
|
Loading…
Reference in New Issue