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:
Guy Harris 2021-06-16 02:01:23 -07:00
parent f541e5e769
commit 25a254823f
19 changed files with 82 additions and 50 deletions

View File

@ -18,6 +18,7 @@
#include <epan/exceptions.h>
#include <epan/to_str.h>
#include <wsutil/pint.h>
#include <wsutil/ws_roundup.h>
/*
* The Aeron protocol is defined at
@ -55,7 +56,7 @@ typedef struct
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)

View File

@ -12,6 +12,7 @@
#include "config.h"
#include <epan/packet.h>
#include <epan/expert.h>
#include <wsutil/ws_roundup.h>
void proto_register_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_ardp = -1; /* This is the top ARDP tree. */
#define ROUND_TO_2BYTE(len) ((len + 1) & ~1)
#define ROUND_TO_4BYTE(len) ((len + 3) & ~3)
#define ROUND_TO_8BYTE(len) ((len + 7) & ~7)
#define ROUND_TO_2BYTE(len) WS_ROUNDUP_2(len)
#define ROUND_TO_4BYTE(len) WS_ROUNDUP_4(len)
#define ROUND_TO_8BYTE(len) WS_ROUNDUP_8(len)
static const value_string endian_encoding_vals[] = {
{ 'B', "Big endian" },

View File

@ -18,6 +18,7 @@
#include <wiretap/wtap.h>
#include <epan/expert.h>
#include <epan/ptvcursor.h>
#include <wsutil/ws_roundup.h>
#include "packet-tcp.h"
#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 = (len_hdr + 7) & ~7;
len_hdr = WS_ROUNDUP_8(len_hdr);
len_body = get_guint32(tvb, offset + 4);
return len_hdr + len_body;

View File

@ -53,6 +53,7 @@
#include <epan/exceptions.h>
#include <wsutil/pint.h>
#include <wsutil/str_util.h>
#include <wsutil/ws_roundup.h>
#include <epan/addr_resolv.h>
#include <epan/address_types.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 */
}
#ifndef roundup2
#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
#endif
/* bitmask for bits [l..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);
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);
offset += csi_matrix_size;
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);
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);
offset += csi_matrix_size;
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);
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 = 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);
offset += csi_matrix_size;
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
* 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;
else
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);
/* 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
* recognize the mesh header.
*/
hdr_len = roundup2(hdr_len, 4);
hdr_len = WS_ROUNDUP_4(hdr_len);
}
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);
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);
subframe_tree = proto_item_add_subtree(parent_item, ett_msdu_aggregation_subframe_tree);
i += 1;
@ -33929,7 +33926,7 @@ dissect_ieee80211_pv0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
msdu_offset += 14;
msdu_tvb = tvb_new_subset_length(next_tvb, msdu_offset, msdu_length);
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);
} else {
/* I guess some bridges take Netware Ethernet_802_3 frames,

View File

@ -30,6 +30,7 @@
#include <epan/crc32-tvb.h>
#include <wsutil/crc32.h>
#include <wsutil/strtoi.h>
#include <wsutil/ws_roundup.h>
void proto_register_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 */
if(ahs_offset & 3){
ahs_offset=(ahs_offset+3) & ~3;
ahs_offset=WS_ROUNDUP_4(ahs_offset);
}
}

View File

@ -17,6 +17,7 @@
#include <epan/arptypes.h>
#include <epan/exceptions.h>
#include <wiretap/wtap.h>
#include <wsutil/ws_roundup.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. */
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 */
if (data_length < rta_len)
THROW(ReportedBoundsError);

View File

@ -15,6 +15,7 @@
#include <epan/etypes.h>
#include <epan/packet.h>
#include <wiretap/wtap.h>
#include <wsutil/ws_roundup.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)
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) {

View File

@ -19,6 +19,7 @@
#include <epan/expert.h>
#include <epan/ipproto.h>
#include <epan/addr_resolv.h>
#include <wsutil/ws_roundup.h>
void proto_register_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;
}
padding = ((stats_length + 7) & ~7) - stats_length;
padding = WS_ROUNDUP_8(stats_length) - stats_length;
if (padding) {
proto_tree_add_item(tree, hf_openflow_v6_stats_pad, tvb, oxs_end, padding, ENC_NA);
offset += padding;
@ -2863,7 +2864,7 @@ dissect_openflow_port_desc_prop_v6(tvbuff_t *tvb, packet_info *pinfo _U_, proto_
while(offset < fields_end) {
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;
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);
offset += 4;
}
offset+=((prop_length + 7) & ~7) - prop_length;
offset+=WS_ROUNDUP_8(prop_length) - prop_length;
break;
case OFPPDPT_EXPERIMENTER:

View File

@ -62,6 +62,7 @@
#include <epan/in_cksum.h>
#include <epan/expert.h>
#include <epan/addr_resolv.h>
#include <wsutil/ws_roundup.h>
#include "packet-rsvp.h"
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);
break;
}
stlv_offset += 4 + ((stlv_length + 3) & ~3);
stlv_offset += 4 + WS_ROUNDUP_4(stlv_length);
}
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
* 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);
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
* 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);
break;
}
stlv_offset += 4 + ((stlv_length + 3) & ~3);
stlv_offset += 4 + WS_ROUNDUP_4(stlv_length);
}
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
* is not included in the length.
* */
offset += 4 + ((tlv_length + 3) & ~3);
offset += 4 + WS_ROUNDUP_4(tlv_length);
}
}

View File

@ -12,7 +12,7 @@
#include "config.h"
#include <epan/packet.h>
#include <epan/to_str.h>
#include <wsutil/ws_roundup.h>
#define PATHPORT_UDP_PORT 3792 /* Not IANA registered */
#define PATHPORT_MIN_LENGTH 24 /* HEADER + 1 PDU */
@ -26,7 +26,7 @@
#define PATHPORT_HEADER_END (PATHPORT_HEADER_OFFSET + PATHPORT_HEADER_LENGTH)
/** 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_register_pathport(void);

View File

@ -25,6 +25,7 @@
#include <epan/prefs.h>
#include <epan/strutil.h>
#include <epan/expert.h>
#include <wsutil/ws_roundup.h>
#include "packet-tcp.h"
#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;
}
#define roundup4(x) (((x) + 3) & ~3)
#define roundup8(x) (((x) + 7) & ~7)
static int
dissect_pvfs_opaque_data(tvbuff_t *tvb, int offset,
proto_tree *tree,
@ -813,9 +811,9 @@ dissect_pvfs_opaque_data(tvbuff_t *tvb, int offset,
*/
if (!string_data)
string_length_full = roundup4(string_length);
string_length_full = WS_ROUNDUP_4(string_length);
else
string_length_full = roundup8(4 + string_length);
string_length_full = WS_ROUNDUP_8(4 + string_length);
if (string_length_captured < string_length) {
/* 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);
/* '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) &&
(g_ascii_strncasecmp(tmpstr, PVFS_DIST_SIMPLE_STRIPE_NAME,

View File

@ -41,6 +41,7 @@
#include "read_keytab_file.h"
#include <wsutil/wsgcrypt.h>
#include <wsutil/ws_roundup.h>
//#define 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++) {
offset = (offset + 7) & ~7;
offset = WS_ROUNDUP_8(offset);
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++) {
offset = (offset + 7) & ~7;
offset = WS_ROUNDUP_8(offset);
offset = dissect_smb2_negotiate_context(tvb, pinfo, tree, offset, si);
}

View File

@ -54,6 +54,7 @@
#include <epan/packet.h>
#include <epan/expert.h>
#include <epan/to_str.h>
#include <wsutil/ws_roundup.h>
#include "packet-tcp.h"
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_length = tvb_get_ntohs(tvb, offset+2); /* Attribute length field in attribute header */
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
att_length_pad = att_length;
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 */
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)
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);

View File

@ -26,6 +26,7 @@
#include <epan/decode_as.h>
#include <epan/proto_data.h>
#include <wsutil/pint.h>
#include <wsutil/ws_roundup.h>
#include "packet-usb.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 */
offset += frame_header_length;
offset = ((offset + 3) & ~3);
offset = WS_ROUNDUP_4(offset);
iso_tree_start = offset;
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,
framelen, ENC_NA);
offset += (framelen + 3) & ~3;
offset += WS_ROUNDUP_4(framelen);
}
proto_item_set_end(ti, tvb, offset);
}

View File

@ -19,6 +19,7 @@
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/to_str.h>
#include <wsutil/ws_roundup.h>
#include "packet-tcp.h"
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);
proto_item_append_text(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);
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);
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);
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);
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);
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_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, "}");
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);
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_item_append_text(ti, "}");

View File

@ -27,6 +27,7 @@
#include <wsutil/strtoi.h>
#include <wsutil/glib-compat.h>
#include <wsutil/ws_assert.h>
#include <wsutil/ws_roundup.h>
#include "wtap-int.h"
#include "file_wrappers.h"
@ -37,7 +38,7 @@
#include "pcapng_module.h"
#include "secrets-types.h"
#define ROUND_TO_4BYTE(len) ((len + 3) & ~3)
#define ROUND_TO_4BYTE(len) WS_ROUNDUP_4(len)
static gboolean
pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,

View File

@ -14,6 +14,7 @@
#include "atm.h"
#include "snoop.h"
#include <wsutil/802_11-utils.h>
#include <wsutil/ws_roundup.h>
/* 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. */
padlen = ((reclen + 3) & ~3) - reclen;
padlen = WS_ROUNDUP_4(reclen) - reclen;
reclen += padlen;
/* Don't write anything we're not willing to read. */

View File

@ -71,6 +71,7 @@ set(WSUTIL_PUBLIC_HEADERS
ws_mempbrk.h
ws_mempbrk_int.h
ws_pipe.h
ws_roundup.h
wsjson.h
wslog.h
xtea.h

22
wsutil/ws_roundup.h Normal file
View File

@ -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__ */