Add a new wsutil header with macros that compute the amount of padding needed to round up to a 4-byte boundary (without any conditional tests) - it ends up being a negate and an AND. Use that in pcapng code. (Next step: use it everywhere else.) Have an inline function that takes a number of bytes of padding to write, between 0 and 3, and writes out that many bytes worth of zeroes. Use it.
23 lines
593 B
C
23 lines
593 B
C
/** @file
|
|
*
|
|
* Wireshark - Network traffic analyzer
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
* Copyright 1998 Gerald Combs
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#ifndef __WS_PADDING_TO_H__
|
|
#define __WS_PADDING_TO_H__
|
|
|
|
/*
|
|
* Amount needed to pad to various powers of 2.
|
|
*/
|
|
#define WS_PADDING_TO_2(n) ((2U - ((n) % 2U)) % 2U)
|
|
#define WS_PADDING_TO_4(n) ((4U - ((n) % 4U)) % 4U)
|
|
#define WS_PADDING_TO_8(n) ((8U - ((n) % 8U)) % 8U)
|
|
#define WS_PADDING_TO_16(n) ((16U - ((n) % 16U)) % 16U)
|
|
#define WS_PADDING_TO_32(n) ((32U - ((n) % 32U)) % 32U)
|
|
|
|
#endif /* __WS_PADDING_TO_H__ */
|