summaryrefslogtreecommitdiffstats
path: root/wiretap/toshiba.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:33 +0000
commit9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9 (patch)
tree2784370cda9bbf2da9114d70f05399c0b229d28c /wiretap/toshiba.c
parentAdding debian version 4.2.6-1. (diff)
downloadwireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.tar.xz
wireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.zip
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wiretap/toshiba.c')
-rw-r--r--wiretap/toshiba.c114
1 files changed, 57 insertions, 57 deletions
diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c
index 7c08d329..b1fb8e8c 100644
--- a/wiretap/toshiba.c
+++ b/wiretap/toshiba.c
@@ -7,8 +7,8 @@
*/
#include "config.h"
-#include "wtap-int.h"
#include "toshiba.h"
+#include "wtap-int.h"
#include "file_wrappers.h"
#include <stdlib.h>
@@ -80,20 +80,20 @@ OFFSET 0001-0203-0405-0607-0809-0A0B-0C0D-0E0F 0123456789ABCDEF LEN=222
/* Magic text to check for toshiba-ness of file */
static const char toshiba_hdr_magic[] =
{ 'T', ' ', 'O', ' ', 'S', ' ', 'H', ' ', 'I', ' ', 'B', ' ', 'A' };
-#define TOSHIBA_HDR_MAGIC_SIZE (sizeof toshiba_hdr_magic / sizeof toshiba_hdr_magic[0])
+#define TOSHIBA_HDR_MAGIC_SIZE array_length(toshiba_hdr_magic)
/* Magic text for start of packet */
static const char toshiba_rec_magic[] = { '[', 'N', 'o', '.' };
-#define TOSHIBA_REC_MAGIC_SIZE (sizeof toshiba_rec_magic / sizeof toshiba_rec_magic[0])
+#define TOSHIBA_REC_MAGIC_SIZE array_length(toshiba_rec_magic)
-static gboolean toshiba_read(wtap *wth, wtap_rec *rec, Buffer *buf,
- int *err, gchar **err_info, gint64 *data_offset);
-static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off,
- wtap_rec *rec, Buffer *buf, int *err, gchar **err_info);
-static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf,
- guint byte_offset);
-static gboolean parse_toshiba_packet(FILE_T fh, wtap_rec *rec,
- Buffer *buf, int *err, gchar **err_info);
+static bool toshiba_read(wtap *wth, wtap_rec *rec, Buffer *buf,
+ int *err, char **err_info, int64_t *data_offset);
+static bool toshiba_seek_read(wtap *wth, int64_t seek_off,
+ wtap_rec *rec, Buffer *buf, int *err, char **err_info);
+static bool parse_single_hex_dump_line(char* rec, uint8_t *buf,
+ unsigned byte_offset);
+static bool parse_toshiba_packet(FILE_T fh, wtap_rec *rec,
+ Buffer *buf, int *err, char **err_info);
static int toshiba_file_type_subtype = -1;
@@ -102,11 +102,11 @@ void register_toshiba(void);
/* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure, and sets "*err" to the error
and "*err_info" to null or an additional error string. */
-static gint64 toshiba_seek_next_packet(wtap *wth, int *err, gchar **err_info)
+static int64_t toshiba_seek_next_packet(wtap *wth, int *err, char **err_info)
{
int byte;
- guint level = 0;
- gint64 cur_off;
+ unsigned level = 0;
+ int64_t cur_off;
while ((byte = file_getc(wth->fh)) != EOF) {
if (byte == toshiba_rec_magic[level]) {
@@ -136,14 +136,14 @@ static gint64 toshiba_seek_next_packet(wtap *wth, int *err, gchar **err_info)
/* Look through the first part of a file to see if this is
* a Toshiba trace file.
*
- * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
+ * Returns true if it is, false if it isn't or if we get an I/O error;
* if we get an I/O error, "*err" will be set to a non-zero value and
* "*err_info" will be set to null or an additional error string.
*/
-static gboolean toshiba_check_file_type(wtap *wth, int *err, gchar **err_info)
+static bool toshiba_check_file_type(wtap *wth, int *err, char **err_info)
{
char buf[TOSHIBA_LINE_LENGTH];
- guint i, reclen, level, line;
+ unsigned i, reclen, level, line;
char byte;
buf[TOSHIBA_LINE_LENGTH-1] = 0;
@@ -152,10 +152,10 @@ static gboolean toshiba_check_file_type(wtap *wth, int *err, gchar **err_info)
if (file_gets(buf, TOSHIBA_LINE_LENGTH, wth->fh) == NULL) {
/* EOF or error. */
*err = file_error(wth->fh, err_info);
- return FALSE;
+ return false;
}
- reclen = (guint) strlen(buf);
+ reclen = (unsigned) strlen(buf);
if (reclen < TOSHIBA_HDR_MAGIC_SIZE) {
continue;
}
@@ -166,7 +166,7 @@ static gboolean toshiba_check_file_type(wtap *wth, int *err, gchar **err_info)
if (byte == toshiba_hdr_magic[level]) {
level++;
if (level >= TOSHIBA_HDR_MAGIC_SIZE) {
- return TRUE;
+ return true;
}
}
else {
@@ -175,11 +175,11 @@ static gboolean toshiba_check_file_type(wtap *wth, int *err, gchar **err_info)
}
}
*err = 0;
- return FALSE;
+ return false;
}
-wtap_open_return_val toshiba_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val toshiba_open(wtap *wth, int *err, char **err_info)
{
/* Look for Toshiba header */
if (!toshiba_check_file_type(wth, err, err_info)) {
@@ -199,15 +199,15 @@ wtap_open_return_val toshiba_open(wtap *wth, int *err, gchar **err_info)
}
/* Find the next packet and parse it; called from wtap_read(). */
-static gboolean toshiba_read(wtap *wth, wtap_rec *rec, Buffer *buf,
- int *err, gchar **err_info, gint64 *data_offset)
+static bool toshiba_read(wtap *wth, wtap_rec *rec, Buffer *buf,
+ int *err, char **err_info, int64_t *data_offset)
{
- gint64 offset;
+ int64_t offset;
/* Find the next packet */
offset = toshiba_seek_next_packet(wth, err, err_info);
if (offset < 1)
- return FALSE;
+ return false;
*data_offset = offset;
/* Parse the packet */
@@ -215,26 +215,26 @@ static gboolean toshiba_read(wtap *wth, wtap_rec *rec, Buffer *buf,
}
/* Used to read packets in random-access fashion */
-static gboolean
-toshiba_seek_read(wtap *wth, gint64 seek_off,
+static bool
+toshiba_seek_read(wtap *wth, int64_t seek_off,
wtap_rec *rec, Buffer *buf,
- int *err, gchar **err_info)
+ int *err, char **err_info)
{
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
- return FALSE;
+ return false;
if (!parse_toshiba_packet(wth->random_fh, rec, buf, err, err_info)) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
/* Parses a packet. */
-static gboolean
+static bool
parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
- int *err, gchar **err_info)
+ int *err, char **err_info)
{
union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header;
char line[TOSHIBA_LINE_LENGTH];
@@ -242,7 +242,7 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
int pkt_len, pktnum, hr, min, sec, csec;
char channel[10], direction[10];
int i, hex_lines;
- guint8 *pd;
+ uint8_t *pd;
/* Our file pointer should be on the line containing the
* summary information for a packet. Read in that line and
@@ -253,7 +253,7 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
- return FALSE;
+ return false;
}
/* Find text in line after "[No.". Limit the length of the
@@ -265,7 +265,7 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
if (num_items_scanned != 7) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("toshiba: record header isn't valid");
- return FALSE;
+ return false;
}
/* Scan lines until we find the OFFSET line. In a "telnet" trace,
@@ -283,7 +283,7 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
- return FALSE;
+ return false;
}
/* Check for "OFFSET 0001-0203" at beginning of line */
@@ -295,22 +295,22 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
if (num_items_scanned != 1) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("toshiba: OFFSET line doesn't have valid LEN item");
- return FALSE;
+ return false;
}
if (pkt_len < 0) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("toshiba: packet header has a negative packet length");
- return FALSE;
+ return false;
}
- if ((guint)pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
+ if ((unsigned)pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
/*
* Probably a corrupt capture file; don't blow up trying
* to allocate space for an immensely-large packet.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = ws_strdup_printf("toshiba: File has %u-byte packet, bigger than maximum of %u",
- (guint)pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
- return FALSE;
+ (unsigned)pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
+ return false;
}
rec->rec_type = REC_TYPE_PACKET;
@@ -325,7 +325,7 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
case 'B':
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN;
pseudo_header->isdn.uton = (direction[0] == 'T');
- pseudo_header->isdn.channel = (guint8)
+ pseudo_header->isdn.channel = (uint8_t)
strtol(&channel[1], NULL, 10);
break;
@@ -356,15 +356,15 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
- return FALSE;
+ return false;
}
if (!parse_single_hex_dump_line(line, pd, i * 16)) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("toshiba: hex dump not valid");
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
}
/*
@@ -385,15 +385,15 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
*
* In the process, we're going to write all over the string.
*
- * Returns TRUE if good hex dump, FALSE if bad.
+ * Returns true if good hex dump, false if bad.
*/
-static gboolean
-parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset) {
+static bool
+parse_single_hex_dump_line(char* rec, uint8_t *buf, unsigned byte_offset) {
int pos, i;
char *s;
unsigned long value;
- guint16 word_value;
+ uint16_t word_value;
/* Get the byte_offset directly from the record */
rec[4] = '\0';
@@ -401,7 +401,7 @@ parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset) {
value = strtoul(s, NULL, 16);
if (value != byte_offset) {
- return FALSE;
+ return false;
}
/* Go through the substring representing the values and:
@@ -421,13 +421,13 @@ parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset) {
for (i = 0; i < 8; i++) {
rec[pos+4] = '\0';
- word_value = (guint16) strtoul(&rec[pos], NULL, 16);
- buf[byte_offset + i * 2 + 0] = (guint8) (word_value >> 8);
- buf[byte_offset + i * 2 + 1] = (guint8) (word_value & 0x00ff);
+ word_value = (uint16_t) strtoul(&rec[pos], NULL, 16);
+ buf[byte_offset + i * 2 + 0] = (uint8_t) (word_value >> 8);
+ buf[byte_offset + i * 2 + 1] = (uint8_t) (word_value & 0x00ff);
pos += 5;
}
- return TRUE;
+ return true;
}
static const struct supported_block_type toshiba_blocks_supported[] = {
@@ -439,7 +439,7 @@ static const struct supported_block_type toshiba_blocks_supported[] = {
static const struct file_type_subtype_info toshiba_info = {
"Toshiba Compact ISDN Router snoop", "toshiba", "txt", NULL,
- FALSE, BLOCKS_SUPPORTED(toshiba_blocks_supported),
+ false, BLOCKS_SUPPORTED(toshiba_blocks_supported),
NULL, NULL, NULL
};