From d7a376447558a671376800c0c910d0afb90918d1 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 6 Mar 2019 02:46:20 -0800 Subject: Some cleanups. hdr_ethernet is a flag indicating whether we should add a fake Ethernet header or not; make it a Boolean. Move number_of_padding_bytes() closer to where it is in ui/text_import.c, and make it more like the version there. Shift the direction flag to put it in the right bit position - or, at least, throw in the shift constant to clarify that we're trying to put it there, even if it's already in the right position (i.e., the shift constant happens to be 0, as it happens to be in the low-order bits). Fix a comment. Change-Id: Ia643d9ab2188951a682bf773239d0175c0d578c2 Reviewed-on: https://code.wireshark.org/review/32337 Reviewed-by: Guy Harris --- text2pcap.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'text2pcap.c') diff --git a/text2pcap.c b/text2pcap.c index 30cc579f1d..762370a3bb 100644 --- a/text2pcap.c +++ b/text2pcap.c @@ -146,7 +146,7 @@ static int debug = 0; static gboolean quiet = FALSE; /* Dummy Ethernet header */ -static int hdr_ethernet = FALSE; +static gboolean hdr_ethernet = FALSE; static guint8 hdr_eth_dest_addr[6] = {0x0a, 0x02, 0x02, 0x02, 0x02, 0x02}; static guint8 hdr_eth_src_addr[6] = {0x0a, 0x02, 0x02, 0x02, 0x02, 0x01}; static guint32 hdr_ethernet_proto = 0; @@ -202,7 +202,7 @@ static guint32 direction = PACK_FLAGS_DIRECTION_UNKNOWN; static guint8 packet_buf[WTAP_MAX_PACKET_SIZE_STANDARD]; static guint32 header_length; static guint32 ip_offset; -static guint32 curr_offset; +static guint32 curr_offset = 0; static guint32 max_offset = WTAP_MAX_PACKET_SIZE_STANDARD; static guint32 packet_start = 0; @@ -461,6 +461,22 @@ unwrite_bytes (guint32 nbytes) curr_offset -= nbytes; } +/*---------------------------------------------------------------------- + * Determine SCTP chunk padding length + */ +static guint32 +number_of_padding_bytes (guint32 length) +{ + guint32 remainder; + + remainder = length % 4; + + if (remainder == 0) + return 0; + else + return 4 - remainder; +} + /*---------------------------------------------------------------------- * Compute one's complement checksum (from RFC1071) */ @@ -590,19 +606,6 @@ finalize_crc32c (guint32 crc) return result; } -static guint16 -number_of_padding_bytes (guint32 length) -{ - guint16 remainder; - - remainder = length % 4; - - if (remainder == 0) - return 0; - else - return 4 - remainder; -} - /*---------------------------------------------------------------------- * Write current packet out */ @@ -834,7 +837,8 @@ write_current_packet (gboolean cont) length, length, 0, 1000000000, - packet_buf, direction, + packet_buf, + (direction << PACK_FLAGS_DIRECTION_SHIFT), &bytes_written, &err); } else { success = libpcap_write_packet(output_file, @@ -1048,7 +1052,7 @@ parse_preamble (void) } else { /* * Convert that number to a number - * of microseconds; if it's N digits + * of nanoseconds; if it's N digits * long, it's in units of 10^(-N) seconds, * so, to convert it to units of * 10^-9 seconds, we multiply by -- cgit v1.2.3