diff options
Diffstat (limited to 'wiretap')
165 files changed, 14408 insertions, 10241 deletions
diff --git a/wiretap/.clang-tidy b/wiretap/.clang-tidy new file mode 100644 index 00000000..6be356e4 --- /dev/null +++ b/wiretap/.clang-tidy @@ -0,0 +1,3 @@ +InheritParentConfig: true + +WarningsAsErrors: misc-no-recursion diff --git a/wiretap/5views.c b/wiretap/5views.c index c474804a..c04e3063 100644 --- a/wiretap/5views.c +++ b/wiretap/5views.c @@ -7,28 +7,28 @@ */ #include "config.h" +#include "5views.h" + #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "5views.h" - typedef struct { - guint32 Signature; - guint32 Size; /* Total size of Header in bytes (included Signature) */ - guint32 Version; /* Identify version and so the format of this record */ - guint32 DataSize; /* Total size of data included in the Info Record (except the header size) */ - guint32 FileType; /* Type of the file */ - guint32 Reserved[3]; /* Reserved for future use */ + uint32_t Signature; + uint32_t Size; /* Total size of Header in bytes (included Signature) */ + uint32_t Version; /* Identify version and so the format of this record */ + uint32_t DataSize; /* Total size of data included in the Info Record (except the header size) */ + uint32_t FileType; /* Type of the file */ + uint32_t Reserved[3]; /* Reserved for future use */ }t_5VW_Info_Header; typedef struct { - guint32 Type; /* Id of the attribute */ - guint16 Size; /* Size of the data part of the attribute (not including header size) */ - guint16 Nb; /* Number of elements */ + uint32_t Type; /* Id of the attribute */ + uint16_t Size; /* Size of the data part of the attribute (not including header size) */ + uint16_t Nb; /* Number of elements */ }t_5VW_Attributes_Header; @@ -58,23 +58,23 @@ typedef struct { t_5VW_Info_Header Info_Header; t_5VW_Attributes_Header HeaderDateCreation; - guint32 Time; + uint32_t Time; t_5VW_Attributes_Header HeaderNbFrames; - guint32 TramesStockeesInFile; + uint32_t TramesStockeesInFile; }t_5VW_Capture_Header; typedef struct { - guint32 Key; /* 0x3333EEEE */ - guint16 HeaderSize; /* Actual size of this header in bytes (32) */ - guint16 HeaderType; /* Exact type of this header (0x4000) */ - guint32 RecType; /* Type of record */ - guint32 RecSubType; /* Subtype of record */ - guint32 RecSize; /* Size of one record */ - guint32 RecNb; /* Number of records */ - guint32 Utc; - guint32 NanoSecondes; - guint32 RecInfo; /* Info about Alarm / Event / Frame captured */ + uint32_t Key; /* 0x3333EEEE */ + uint16_t HeaderSize; /* Actual size of this header in bytes (32) */ + uint16_t HeaderType; /* Exact type of this header (0x4000) */ + uint32_t RecType; /* Type of record */ + uint32_t RecSubType; /* Subtype of record */ + uint32_t RecSize; /* Size of one record */ + uint32_t RecNb; /* Number of records */ + uint32_t Utc; + uint32_t NanoSecondes; + uint32_t RecInfo; /* Info about Alarm / Event / Frame captured */ }t_5VW_TimeStamped_Header; @@ -84,22 +84,22 @@ typedef struct #define CST_5VW_CAPTURES_RECORD (CST_5VW_SECTION_CAPTURES << 28) /* 0x80000000 */ #define CST_5VW_SYSTEM_RECORD 0x00000000U -static gboolean _5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset); -static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); -static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, - wtap_rec *rec, int *err, gchar **err_info); +static bool _5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + char **err_info, int64_t *data_offset); +static bool _5views_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info); +static bool _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, + wtap_rec *rec, int *err, char **err_info); -static gboolean _5views_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); -static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info); +static bool _5views_dump(wtap_dumper *wdh, const wtap_rec *rec, const uint8_t *pd, int *err, char **err_info); +static bool _5views_dump_finish(wtap_dumper *wdh, int *err, char **err_info); static int _5views_file_type_subtype = -1; void register_5views(void); wtap_open_return_val -_5views_open(wtap *wth, int *err, gchar **err_info) +_5views_open(wtap *wth, int *err, char **err_info) { t_5VW_Capture_Header Capture_Header; int encap = WTAP_ENCAP_UNKNOWN; @@ -181,9 +181,9 @@ _5views_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean +static bool _5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { t_5VW_TimeStamped_Header TimeStamped_Header; @@ -198,7 +198,7 @@ _5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, /* Read record header. */ if (!_5views_read_header(wth, wth->fh, &TimeStamped_Header, rec, err, err_info)) - return FALSE; + return false; if (TimeStamped_Header.RecSubType == CST_5VW_FRAME_RECORD) { /* @@ -211,7 +211,7 @@ _5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, * Not a packet - skip to the next record. */ if (!wtap_read_bytes(wth->fh, NULL, TimeStamped_Header.RecSize, err, err_info)) - return FALSE; + return false; } while (1); if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { @@ -222,21 +222,21 @@ _5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("5views: File has %u-byte packet, bigger than maximum of %u", rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } return wtap_read_packet_bytes(wth->fh, buf, rec->rec_header.packet_header.caplen, err, err_info); } -static gboolean -_5views_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +_5views_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { t_5VW_TimeStamped_Header TimeStamped_Header; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* * Read the header. @@ -245,7 +245,7 @@ _5views_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, rec, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } /* @@ -255,23 +255,23 @@ _5views_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, err, err_info); } -/* Read the header of the next packet. Return TRUE on success, FALSE +/* Read the header of the next packet. Return true on success, false on error. */ -static gboolean +static bool _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, - wtap_rec *rec, int *err, gchar **err_info) + wtap_rec *rec, int *err, char **err_info) { /* Read record header. */ if (!wtap_read_bytes_or_eof(fh, hdr, (unsigned int)sizeof(t_5VW_TimeStamped_Header), err, err_info)) - return FALSE; + return false; hdr->Key = pletoh32(&hdr->Key); if (hdr->Key != CST_5VW_RECORDS_HEADER_KEY) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("5views: Time-stamped header has bad key value 0x%08X", hdr->Key); - return FALSE; + return false; } hdr->RecSubType = pletoh32(&hdr->RecSubType); @@ -295,18 +295,18 @@ _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, break; } - return TRUE; + return true; } typedef struct { - guint32 nframes; + uint32_t nframes; } _5views_dump_t; static const int wtap_encap[] = { -1, /* WTAP_ENCAP_UNKNOWN -> unsupported */ CST_5VW_CAPTURE_ETH_FILEID, /* WTAP_ENCAP_ETHERNET -> Ethernet */ }; -#define NUM_WTAP_ENCAPS (sizeof wtap_encap / sizeof wtap_encap[0]) +#define NUM_WTAP_ENCAPS array_length(wtap_encap) /* Returns 0 if we could write the specified encapsulation type, an error indication otherwise. */ @@ -322,9 +322,9 @@ static int _5views_dump_can_write_encap(int encap) return 0; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean _5views_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool _5views_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { _5views_dump_t *_5views; @@ -333,7 +333,7 @@ static gboolean _5views_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _ the header when we've written out all the packets, we just skip over the header for now. */ if (wtap_dump_file_seek(wdh, sizeof(t_5VW_Capture_Header), SEEK_SET, err) == -1) - return FALSE; + return false; /* This is a 5Views file */ wdh->subtype_write = _5views_dump; @@ -342,14 +342,14 @@ static gboolean _5views_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _ wdh->priv = (void *)_5views; _5views->nframes = 0; - return TRUE; + return true; } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean _5views_dump(wtap_dumper *wdh, + Returns true on success, false on failure. */ +static bool _5views_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { _5views_dump_t *_5views = (_5views_dump_t *)wdh->priv; t_5VW_TimeStamped_Header HeaderFrame; @@ -357,7 +357,7 @@ static gboolean _5views_dump(wtap_dumper *wdh, /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -366,13 +366,13 @@ static gboolean _5views_dump(wtap_dumper *wdh, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* Don't write out something bigger than we can read. */ if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } /* Frame Header */ @@ -387,14 +387,14 @@ static gboolean _5views_dump(wtap_dumper *wdh, /* record-dependent fields */ /* * XXX - is the frame time signed, or unsigned? If it's signed, - * we should check against G_MININT32 and G_MAXINT32 and make - * Utc a gint32. + * we should check against INT32_MIN and INT32_MAX and make + * Utc an int32_t. */ if (rec->ts.secs < 0 || rec->ts.secs > WTAP_NSTIME_32BIT_SECS_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - HeaderFrame.Utc = GUINT32_TO_LE((guint32)rec->ts.secs); + HeaderFrame.Utc = GUINT32_TO_LE((uint32_t)rec->ts.secs); HeaderFrame.NanoSecondes = GUINT32_TO_LE(rec->ts.nsecs); HeaderFrame.RecSize = GUINT32_TO_LE(rec->rec_header.packet_header.len); HeaderFrame.RecInfo = GUINT32_TO_LE(0); @@ -402,33 +402,33 @@ static gboolean _5views_dump(wtap_dumper *wdh, /* write the record header */ if (!wtap_dump_file_write(wdh, &HeaderFrame, sizeof(t_5VW_TimeStamped_Header), err)) - return FALSE; + return false; /* write the data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; _5views->nframes ++; - return TRUE; + return true; } -static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool _5views_dump_finish(wtap_dumper *wdh, int *err, char **err_info _U_) { _5views_dump_t *_5views = (_5views_dump_t *)wdh->priv; t_5VW_Capture_Header file_hdr; if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) - return FALSE; + return false; /* fill in the Info_Header */ file_hdr.Info_Header.Signature = GUINT32_TO_LE(CST_5VW_INFO_HEADER_KEY); file_hdr.Info_Header.Size = GUINT32_TO_LE(sizeof(t_5VW_Info_Header)); /* Total size of Header in bytes (included Signature) */ file_hdr.Info_Header.Version = GUINT32_TO_LE(CST_5VW_INFO_RECORD_VERSION); /* Identify version and so the format of this record */ file_hdr.Info_Header.DataSize = GUINT32_TO_LE(sizeof(t_5VW_Attributes_Header) - + sizeof(guint32) + + sizeof(uint32_t) + sizeof(t_5VW_Attributes_Header) - + sizeof(guint32)); + + sizeof(uint32_t)); /* Total size of data included in the Info Record (except the header size) */ file_hdr.Info_Header.FileType = GUINT32_TO_LE(wtap_encap[wdh->file_encap]); /* Type of the file */ file_hdr.Info_Header.Reserved[0] = 0; /* Reserved for future use */ @@ -437,7 +437,7 @@ static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info /* fill in the HeaderDateCreation */ file_hdr.HeaderDateCreation.Type = GUINT32_TO_LE(CST_5VW_IA_DATE_CREATION); /* Id of the attribute */ - file_hdr.HeaderDateCreation.Size = GUINT16_TO_LE(sizeof(guint32)); /* Size of the data part of the attribute (not including header size) */ + file_hdr.HeaderDateCreation.Size = GUINT16_TO_LE(sizeof(uint32_t)); /* Size of the data part of the attribute (not including header size) */ file_hdr.HeaderDateCreation.Nb = GUINT16_TO_LE(1); /* Number of elements */ /* fill in the Time field */ @@ -448,7 +448,7 @@ static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info /* fill in the Time field */ file_hdr.HeaderNbFrames.Type = GUINT32_TO_LE(CST_5VW_IA_CAP_INF_NB_TRAMES_STOCKEES); /* Id of the attribute */ - file_hdr.HeaderNbFrames.Size = GUINT16_TO_LE(sizeof(guint32)); /* Size of the data part of the attribute (not including header size) */ + file_hdr.HeaderNbFrames.Size = GUINT16_TO_LE(sizeof(uint32_t)); /* Size of the data part of the attribute (not including header size) */ file_hdr.HeaderNbFrames.Nb = GUINT16_TO_LE(1); /* Number of elements */ /* fill in the number of frames saved */ @@ -457,9 +457,9 @@ static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info /* Write the file header. */ if (!wtap_dump_file_write(wdh, &file_hdr, sizeof(t_5VW_Capture_Header), err)) - return FALSE; + return false; - return TRUE; + return true; } static const struct supported_block_type _5views_blocks_supported[] = { @@ -471,7 +471,7 @@ static const struct supported_block_type _5views_blocks_supported[] = { static const struct file_type_subtype_info _5views_info = { "InfoVista 5View capture", "5views", "5vw", NULL, - TRUE, BLOCKS_SUPPORTED(_5views_blocks_supported), + true, BLOCKS_SUPPORTED(_5views_blocks_supported), _5views_dump_can_write_encap, _5views_dump_open, NULL }; diff --git a/wiretap/5views.h b/wiretap/5views.h index 24a069d8..b0058e64 100644 --- a/wiretap/5views.h +++ b/wiretap/5views.h @@ -11,6 +11,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val _5views_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val _5views_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/CMakeLists.txt b/wiretap/CMakeLists.txt index 90c6ce12..336fa408 100644 --- a/wiretap/CMakeLists.txt +++ b/wiretap/CMakeLists.txt @@ -43,6 +43,7 @@ set(WIRETAP_C_MODULE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/candump.c ${CMAKE_CURRENT_SOURCE_DIR}/capsa.c ${CMAKE_CURRENT_SOURCE_DIR}/catapult_dct2000.c + ${CMAKE_CURRENT_SOURCE_DIR}/cllog.c ${CMAKE_CURRENT_SOURCE_DIR}/commview.c ${CMAKE_CURRENT_SOURCE_DIR}/cosine.c ${CMAKE_CURRENT_SOURCE_DIR}/csids.c @@ -50,6 +51,7 @@ set(WIRETAP_C_MODULE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/dbs-etherwatch.c ${CMAKE_CURRENT_SOURCE_DIR}/dpa400.c ${CMAKE_CURRENT_SOURCE_DIR}/dct3trace.c + ${CMAKE_CURRENT_SOURCE_DIR}/ems.c ${CMAKE_CURRENT_SOURCE_DIR}/erf.c ${CMAKE_CURRENT_SOURCE_DIR}/eri_enb_log.c ${CMAKE_CURRENT_SOURCE_DIR}/eyesdn.c @@ -119,6 +121,7 @@ set(WIRETAP_NONGENERATED_C_FILES ${CMAKE_CURRENT_SOURCE_DIR}/file_access.c ${CMAKE_CURRENT_SOURCE_DIR}/file_wrappers.c ${CMAKE_CURRENT_SOURCE_DIR}/merge.c + ${CMAKE_CURRENT_SOURCE_DIR}/secrets-types.c ${CMAKE_CURRENT_SOURCE_DIR}/wtap.c ${CMAKE_CURRENT_SOURCE_DIR}/wtap_opttypes.c ) @@ -175,7 +178,7 @@ set_target_properties(wiretap PROPERTIES PREFIX "lib" COMPILE_DEFINITIONS "WS_BUILD_DLL" LINK_FLAGS "${WS_LINK_FLAGS}" - VERSION "14.1.6" SOVERSION 14 + VERSION "15.0.0" SOVERSION 15 FOLDER "DLLs" INSTALL_RPATH "${LIBRARY_INSTALL_RPATH}" ) @@ -189,6 +192,7 @@ target_link_libraries(wiretap ${GLIB2_LIBRARIES} PRIVATE ${ZLIB_LIBRARIES} + ${ZLIBNG_LIBRARIES} ${ZSTD_LIBRARIES} ${LZ4_LIBRARIES} ) @@ -196,6 +200,7 @@ target_link_libraries(wiretap target_include_directories(wiretap SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS} + ${ZLIBNG_INCLUDE_DIRS} ${ZSTD_INCLUDE_DIRS} ${LZ4_INCLUDE_DIRS} ) diff --git a/wiretap/README.developer b/wiretap/README.developer index 6552ad18..3ca3225e 100644 --- a/wiretap/README.developer +++ b/wiretap/README.developer @@ -85,4 +85,4 @@ To add the ability to write a new capture file format, you have to: in the "file_type_subtype_info" struct passed to wtap_register_file_type_subtypes(). -In the wiretap directory, add your source file to CMakelists.txt. +In the wiretap directory, add your source file to CMakeLists.txt. diff --git a/wiretap/aethra.c b/wiretap/aethra.c index 3216e74e..75214cfa 100644 --- a/wiretap/aethra.c +++ b/wiretap/aethra.c @@ -7,48 +7,49 @@ */ #include "config.h" +#include "aethra.h" + #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "aethra.h" /* Magic number in Aethra PC108 files. */ #define MAGIC_SIZE 5 -static const guchar aethra_magic[MAGIC_SIZE] = { +static const unsigned char aethra_magic[MAGIC_SIZE] = { 'V', '0', '2', '0', '8' }; /* Aethra file header. */ struct aethra_hdr { - guchar magic[MAGIC_SIZE]; - guint8 unknown1[39]; /* 5-43 */ - guchar sw_vers[60]; /* 44-103 - software version string, not null-terminated */ - guint8 unknown2[118]; /* 104-221 */ - guint8 start_sec; /* 222 - seconds of capture start time */ - guint8 start_min; /* 223 - minutes of capture start time */ - guint8 start_hour; /* 224 - hour of capture start time */ - guint8 unknown3[462]; /* 225-686 */ - guchar xxx_string[37]; /* 687-723 - null-terminated short comment string? */ - guint8 unknown3_5[4]; /* 724-727 */ - guchar yyy_string[4504];/* 728-5231 - null-terminated long comment string? */ - guint8 start_year[2]; /* 5232-5233 - year of capture start date */ - guint8 start_month[2]; /* 5234-5235 - month of capture start date */ - guint8 unknown4[2]; /* 5236-5237 */ - guint8 start_day[2]; /* 5238-5239 - day of capture start date */ - guint8 unknown5[8]; /* 5240-5247 */ - guchar com_info[16]; /* 5248-5263 - COM port and speed, null-padded(?) */ - guint8 unknown6[107]; /* 5264-5370 */ - guchar xxx_vers[41]; /* 5371-5411 - unknown version string (longer, null-padded?) */ + unsigned char magic[MAGIC_SIZE]; + uint8_t unknown1[39]; /* 5-43 */ + unsigned char sw_vers[60]; /* 44-103 - software version string, not null-terminated */ + uint8_t unknown2[118]; /* 104-221 */ + uint8_t start_sec; /* 222 - seconds of capture start time */ + uint8_t start_min; /* 223 - minutes of capture start time */ + uint8_t start_hour; /* 224 - hour of capture start time */ + uint8_t unknown3[462]; /* 225-686 */ + unsigned char xxx_string[37]; /* 687-723 - null-terminated short comment string? */ + uint8_t unknown3_5[4]; /* 724-727 */ + unsigned char yyy_string[4504];/* 728-5231 - null-terminated long comment string? */ + uint8_t start_year[2]; /* 5232-5233 - year of capture start date */ + uint8_t start_month[2]; /* 5234-5235 - month of capture start date */ + uint8_t unknown4[2]; /* 5236-5237 */ + uint8_t start_day[2]; /* 5238-5239 - day of capture start date */ + uint8_t unknown5[8]; /* 5240-5247 */ + unsigned char com_info[16]; /* 5248-5263 - COM port and speed, null-padded(?) */ + uint8_t unknown6[107]; /* 5264-5370 */ + unsigned char xxx_vers[41]; /* 5371-5411 - unknown version string (longer, null-padded?) */ }; /* Aethra record header. Yes, the alignment is weird. All multi-byte fields are little-endian. */ struct aethrarec_hdr { - guint8 rec_size[2]; /* record length, not counting the length itself */ - guint8 rec_type; /* record type */ - guint8 timestamp[4]; /* milliseconds since start of capture */ - guint8 flags; /* low-order bit: 0 = N->U, 1 = U->N */ + uint8_t rec_size[2]; /* record length, not counting the length itself */ + uint8_t rec_type; /* record type */ + uint8_t timestamp[4]; /* milliseconds since start of capture */ + uint8_t flags; /* low-order bit: 0 = N->U, 1 = U->N */ }; /* @@ -101,18 +102,18 @@ typedef struct { time_t start; } aethra_t; -static gboolean aethra_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset); -static gboolean aethra_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, - wtap_rec *rec, int *err, gchar **err_info); +static bool aethra_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + char **err_info, int64_t *data_offset); +static bool aethra_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, + wtap_rec *rec, int *err, char **err_info); static int aethra_file_type_subtype = -1; void register_aethra(void); -wtap_open_return_val aethra_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val aethra_open(wtap *wth, int *err, char **err_info) { struct aethra_hdr hdr; struct tm tm; @@ -171,12 +172,12 @@ wtap_open_return_val aethra_open(wtap *wth, int *err, gchar **err_info) } #if 0 -static guint packet = 0; +static unsigned packet; #endif /* Read the next packet */ -static gboolean aethra_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) +static bool aethra_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + char **err_info, int64_t *data_offset) { struct aethrarec_hdr hdr; @@ -189,7 +190,7 @@ static gboolean aethra_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, /* Read record header. */ if (!aethra_read_rec_header(wth, wth->fh, &hdr, rec, err, err_info)) - return FALSE; + return false; /* * XXX - if this is big, we might waste memory by @@ -198,7 +199,7 @@ static gboolean aethra_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, if (rec->rec_header.packet_header.caplen != 0) { if (!wtap_read_packet_bytes(wth->fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) - return FALSE; /* Read error */ + return false; /* Read error */ } #if 0 packet++; @@ -263,46 +264,46 @@ packet, hdr.rec_type, rec->rec_header.packet_header.caplen, hdr.flags); } found: - return TRUE; + return true; } -static gboolean -aethra_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +aethra_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { struct aethrarec_hdr hdr; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (!aethra_read_rec_header(wth, wth->random_fh, &hdr, rec, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } /* * Read the packet data. */ if (!wtap_read_packet_bytes(wth->random_fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) - return FALSE; /* failed */ + return false; /* failed */ - return TRUE; + return true; } -static gboolean +static bool aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, - wtap_rec *rec, int *err, gchar **err_info) + wtap_rec *rec, int *err, char **err_info) { aethra_t *aethra = (aethra_t *)wth->priv; - guint32 rec_size; - guint32 packet_size; - guint32 msecs; + uint32_t rec_size; + uint32_t packet_size; + uint32_t msecs; /* Read record header. */ if (!wtap_read_bytes_or_eof(fh, hdr, sizeof *hdr, err, err_info)) - return FALSE; + return false; rec_size = pletoh16(hdr->rec_size); if (rec_size < (sizeof *hdr - sizeof hdr->rec_size)) { @@ -311,7 +312,7 @@ aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, *err_info = ws_strdup_printf("aethra: File has %u-byte record, less than minimum of %u", rec_size, (unsigned int)(sizeof *hdr - sizeof hdr->rec_size)); - return FALSE; + return false; } if (rec_size > WTAP_MAX_PACKET_SIZE_STANDARD) { /* @@ -322,10 +323,10 @@ aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("aethra: File has %u-byte packet, bigger than maximum of %u", rec_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } - packet_size = rec_size - (guint32)(sizeof *hdr - sizeof hdr->rec_size); + packet_size = rec_size - (uint32_t)(sizeof *hdr - sizeof hdr->rec_size); msecs = pletoh32(hdr->timestamp); rec->rec_type = REC_TYPE_PACKET; @@ -338,7 +339,7 @@ aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, rec->rec_header.packet_header.pseudo_header.isdn.uton = (hdr->flags & AETHRA_U_TO_N); rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; /* XXX - D channel */ - return TRUE; + return true; } static const struct supported_block_type aethra_blocks_supported[] = { @@ -350,7 +351,7 @@ static const struct supported_block_type aethra_blocks_supported[] = { static const struct file_type_subtype_info aethra_info = { "Aethra .aps file", "aethra", "aps", NULL, - FALSE, BLOCKS_SUPPORTED(aethra_blocks_supported), + false, BLOCKS_SUPPORTED(aethra_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/aethra.h b/wiretap/aethra.h index 2cb4fe7d..b6d09673 100644 --- a/wiretap/aethra.h +++ b/wiretap/aethra.h @@ -12,6 +12,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val aethra_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val aethra_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/ascend-int.h b/wiretap/ascend-int.h index 6c5760ff..b688e444 100644 --- a/wiretap/ascend-int.h +++ b/wiretap/ascend-int.h @@ -19,39 +19,39 @@ typedef struct { time_t inittime; - gboolean adjusted; - gint64 next_packet_seek_start; + bool adjusted; + int64_t next_packet_seek_start; } ascend_t; typedef struct { int length; - guint32 u32_val; - guint16 u16_val; - guint8 u8_val; + uint32_t u32_val; + uint16_t u16_val; + uint8_t u8_val; char str_val[ASCEND_MAX_STR_LEN]; } ascend_token_t; typedef struct { FILE_T fh; - const gchar *ascend_parse_error; + const char *ascend_parse_error; int err; - gchar *err_info; + char *err_info; struct ascend_phdr *pseudo_header; - guint8 *pkt_data; + uint8_t *pkt_data; - gboolean saw_timestamp; + bool saw_timestamp; time_t timestamp; - gint64 first_hexbyte; - guint32 wirelen; - guint32 caplen; + int64_t first_hexbyte; + uint32_t wirelen; + uint32_t caplen; time_t secs; - guint32 usecs; + uint32_t usecs; ascend_token_t token; } ascend_state_t; extern bool -run_ascend_parser(guint8 *pd, ascend_state_t *parser_state, int *err, gchar **err_info); +run_ascend_parser(uint8_t *pd, ascend_state_t *parser_state, int *err, char **err_info); #endif /* ! __ASCEND_INT_H__ */ diff --git a/wiretap/ascend_parser.lemon b/wiretap/ascend_parser.lemon index 89df9268..137d8091 100644 --- a/wiretap/ascend_parser.lemon +++ b/wiretap/ascend_parser.lemon @@ -190,24 +190,24 @@ data_packet ::= wdp8_hdr datagroup . data_packet ::= wdd_date wdd_hdr datagroup . data_packet ::= wdd_hdr datagroup . -%type isdn_prefix { guint16 } +%type isdn_prefix { uint16_t } isdn_prefix(U16) ::= ISDN_PREFIX(A_TOK) . { U16 = A_TOK.u16_val; } -%type ether_prefix { guint16 } +%type ether_prefix { uint16_t } ether_prefix(U16) ::= ETHER_PREFIX(A_TOK) . { U16 = A_TOK.u16_val; } -%type wds_prefix { guint16 } +%type wds_prefix { uint16_t } wds_prefix(U16) ::= WDS_PREFIX(A_TOK) . { U16 = A_TOK.u16_val; } string ::= STRING . -%type decnum { guint32 } +%type decnum { uint32_t } decnum(U32) ::= DECNUM(A_TOK) . { U32 = A_TOK.u32_val; } -%type hexnum { guint32 } +%type hexnum { uint32_t } hexnum(U32) ::= HEXNUM(A_TOK) . { U32 = A_TOK.u32_val; } -%type wdd_decnum { guint32 } +%type wdd_decnum { uint32_t } wdd_decnum(U32) ::= WDD_DECNUM(A_TOK) . { U32 = A_TOK.u32_val; } /* @@ -356,8 +356,8 @@ wdd_date ::= WDD_DATE wdd_decnum(MONTH) wdd_decnum(MDAY) wdd_decnum(YEAR) WDD_TI wddt.tm_year = (YEAR > 1970) ? YEAR - 1900 : 70; wddt.tm_isdst = -1; - parser_state->timestamp = (guint32) mktime(&wddt); - parser_state->saw_timestamp = TRUE; + parser_state->timestamp = (uint32_t) mktime(&wddt); + parser_state->saw_timestamp = true; (void) g_strlcpy(parser_state->pseudo_header->call_num, CN_T.str_val, ASCEND_MAX_STR_LEN); } @@ -441,7 +441,7 @@ datagroup ::= dataln . /* Run the parser. */ bool -run_ascend_parser(guint8 *pd, ascend_state_t *parser_state, int *err, gchar **err_info) +run_ascend_parser(uint8_t *pd, ascend_state_t *parser_state, int *err, char **err_info) { yyscan_t scanner = NULL; void *parser; @@ -462,7 +462,7 @@ run_ascend_parser(guint8 *pd, ascend_state_t *parser_state, int *err, gchar **er /* * We haven't seen a time stamp yet. */ - parser_state->saw_timestamp = FALSE; + parser_state->saw_timestamp = false; parser_state->timestamp = 0; parser_state->first_hexbyte = 0; diff --git a/wiretap/ascend_scanner.l b/wiretap/ascend_scanner.l index f6fe4032..ba3a5e0d 100644 --- a/wiretap/ascend_scanner.l +++ b/wiretap/ascend_scanner.l @@ -66,6 +66,9 @@ */ DIAG_OFF_FLEX() +// The generated scanner is recursive if yywrap is enabled, but we disable it above. +// NOLINTBEGIN(misc-no-recursion) + static int ascend_yyinput(void *buf, ascend_state_t *parser_state) { int c = file_getc(parser_state->fh); if (c == EOF) { @@ -245,7 +248,7 @@ WDD_TYPE "type "[^\n\r\t ]+ } /* Are valid values ever > 2^32? If so we need to adjust YYSTYPE and a lot of */ /* upstream code accordingly. */ - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 10); retval = DECNUM; } g_free (atcopy); @@ -254,13 +257,13 @@ WDD_TYPE "type "[^\n\r\t ]+ <sc_wds_sess>{D}* { BEGIN(sc_gen_task); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 10); return DECNUM; } <sc_gen_task>(0x|0X)?{H}{2,8} { BEGIN(sc_gen_time_s); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 16); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 16); return HEXNUM; } @@ -270,7 +273,7 @@ WDD_TYPE "type "[^\n\r\t ]+ <sc_gen_time_s>{D}{1,10} { BEGIN(sc_gen_time_u); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 10); return DECNUM; } @@ -280,14 +283,14 @@ WDD_TYPE "type "[^\n\r\t ]+ /* only want the most significant 2 digits. convert to usecs */ if (strlen(atcopy) > 2) atcopy[2] = '\0'; - yyextra->token.u32_val = (guint32) strtoul(atcopy, NULL, 10) * 10000; + yyextra->token.u32_val = (uint32_t) strtoul(atcopy, NULL, 10) * 10000; g_free(atcopy); return DECNUM; } <sc_gen_octets>{D}{1,10} { BEGIN(sc_gen_counter); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 10); return DECNUM; } @@ -297,7 +300,7 @@ WDD_TYPE "type "[^\n\r\t ]+ } <sc_gen_byte>{H}{2} { - yyextra->token.u8_val = (guint8) strtoul(yytext, NULL, 16); + yyextra->token.u8_val = (uint8_t) strtoul(yytext, NULL, 16); return HEXBYTE; } @@ -320,19 +323,19 @@ WDD_TYPE "type "[^\n\r\t ]+ */ <sc_wdd_date_m>{D}{2} { BEGIN(sc_wdd_date_d); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 10); return WDD_DECNUM; } <sc_wdd_date_d>\/{D}{2}\/ { BEGIN(sc_wdd_date_y); - yyextra->token.u32_val = (guint32) strtoul(yytext+1, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext+1, NULL, 10); return WDD_DECNUM; } <sc_wdd_date_y>{D}{4} { BEGIN(sc_wdd_time); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 10); return WDD_DECNUM; } @@ -346,19 +349,19 @@ WDD_TYPE "type "[^\n\r\t ]+ */ <sc_wdd_time_h>{D}{2} { BEGIN(sc_wdd_time_m); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 10); return WDD_DECNUM; } <sc_wdd_time_m>:{D}{2}: { BEGIN(sc_wdd_time_s); - yyextra->token.u32_val = (guint32) strtoul(yytext+1, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext+1, NULL, 10); return WDD_DECNUM; } <sc_wdd_time_s>{D}{2} { BEGIN(sc_wdd_cause); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 10); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 10); return WDD_DECNUM; } @@ -380,7 +383,7 @@ WDD_TYPE "type "[^\n\r\t ]+ <sc_wdd_chunknum>{H}{1,8} { BEGIN(sc_wdd_type); - yyextra->token.u32_val = (guint32) strtoul(yytext, NULL, 16); + yyextra->token.u32_val = (uint32_t) strtoul(yytext, NULL, 16); return HEXNUM; } @@ -403,6 +406,8 @@ task:|task|at|time:|octets { return KEYWORD; } %% +// NOLINTEND(misc-no-recursion) + /* * Turn diagnostics back on, so we check the code that we've written. */ diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c index 71e72738..4546c3b9 100644 --- a/wiretap/ascendtext.c +++ b/wiretap/ascendtext.c @@ -7,8 +7,9 @@ */ #include "config.h" -#include "wtap-int.h" #include "ascendtext.h" + +#include "wtap-int.h" #include "ascend-int.h" #include "file_wrappers.h" @@ -50,8 +51,8 @@ */ typedef struct _ascend_magic_string { - guint type; - const gchar *strptr; + unsigned type; + const char *strptr; size_t strlength; } ascend_magic_string; @@ -75,11 +76,11 @@ static const ascend_magic_string ascend_magic[] = { #define ASCEND_DATE "Date:" -static gboolean ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, +static bool ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool ascend_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + int *err, char **err_info); static int ascend_file_type_subtype = -1; @@ -88,16 +89,16 @@ void register_ascend(void); /* Seeks to the beginning of the next packet, and returns the byte offset at which the header for that packet begins. Returns -1 on failure. */ -static gint64 ascend_find_next_packet(wtap *wth, int *err, gchar **err_info) +static int64_t ascend_find_next_packet(wtap *wth, int *err, char **err_info) { int byte; - gint64 date_off = -1, cur_off, packet_off; + int64_t date_off = -1, cur_off, packet_off; size_t string_level[ASCEND_MAGIC_STRINGS]; - guint string_i = 0; - static const gchar ascend_date[] = ASCEND_DATE; + unsigned string_i = 0; + static const char ascend_date[] = ASCEND_DATE; size_t ascend_date_len = sizeof ascend_date - 1; /* strlen of a constant string */ size_t ascend_date_string_level; - guint excessive_read_count = 262144; + unsigned excessive_read_count = 262144; memset(&string_level, 0, sizeof(string_level)); ascend_date_string_level = 0; @@ -115,8 +116,8 @@ static gint64 ascend_find_next_packet(wtap *wth, int *err, gchar **err_info) * Ascend magic string string_i. */ for (string_i = 0; string_i < ASCEND_MAGIC_STRINGS; string_i++) { - const gchar *strptr = ascend_magic[string_i].strptr; - size_t len = ascend_magic[string_i].strlength; + const char *strptr = ascend_magic[string_i].strptr; + size_t len = ascend_magic[string_i].strlength; if (byte == *(strptr + string_level[string_i])) { /* @@ -219,10 +220,10 @@ found: return packet_off; } -wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val ascend_open(wtap *wth, int *err, char **err_info) { - gint64 offset; - guint8 buf[ASCEND_MAX_PKT_LEN]; + int64_t offset; + uint8_t buf[ASCEND_MAX_PKT_LEN]; ascend_state_t parser_state = {0}; ws_statb64 statbuf; ascend_t *ascend; @@ -286,7 +287,7 @@ wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_ERROR; } ascend->inittime = statbuf.st_ctime; - ascend->adjusted = FALSE; + ascend->adjusted = false; wth->file_tsprec = WTAP_TSPREC_USEC; /* @@ -301,11 +302,11 @@ wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info) } /* Parse the capture file. - Returns TRUE if we got a packet, FALSE otherwise. */ -static gboolean + Returns true if we got a packet, false otherwise. */ +static bool parse_ascend(ascend_t *ascend, FILE_T fh, wtap_rec *rec, Buffer *buf, - guint length, gint64 *next_packet_seek_start_ret, - int *err, gchar **err_info) + unsigned length, int64_t *next_packet_seek_start_ret, + int *err, char **err_info) { ascend_state_t parser_state = {0}; int retval; @@ -348,7 +349,7 @@ parse_ascend(ascend_t *ascend, FILE_T fh, wtap_rec *rec, Buffer *buf, We won't know where the data ends until we run into the next packet. */ if (parser_state.caplen) { if (! ascend->adjusted) { - ascend->adjusted = TRUE; + ascend->adjusted = true; if (parser_state.saw_timestamp) { /* * Capture file contained a date and time. @@ -374,7 +375,7 @@ parse_ascend(ascend_t *ascend, FILE_T fh, wtap_rec *rec, Buffer *buf, rec->rec_header.packet_header.caplen = parser_state.caplen; rec->rec_header.packet_header.len = parser_state.wirelen; - return TRUE; + return true; } /* Didn't see any data. Still, perhaps the parser was happy. */ @@ -393,15 +394,15 @@ parse_ascend(ascend_t *ascend, FILE_T fh, wtap_rec *rec, Buffer *buf, *err_info = g_strdup("no data returned by parse"); } } - return FALSE; + return false; } /* Read the next packet; called from wtap_read(). */ -static gboolean ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) +static bool ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + char **err_info, int64_t *data_offset) { ascend_t *ascend = (ascend_t *)wth->priv; - gint64 offset; + int64_t offset; /* parse_ascend() will advance the point at which to look for the next packet's header, to just after the last packet's header (ie. at the @@ -409,16 +410,16 @@ static gboolean ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, packet's header because we might mistake part of it for a new header. */ if (file_seek(wth->fh, ascend->next_packet_seek_start, SEEK_SET, err) == -1) - return FALSE; + return false; offset = ascend_find_next_packet(wth, err, err_info); if (offset == -1) { /* EOF or read error */ - return FALSE; + return false; } if (!parse_ascend(ascend, wth->fh, rec, buf, wth->snapshot_length, &ascend->next_packet_seek_start, err, err_info)) - return FALSE; + return false; /* Flex might have gotten an EOF and caused *err to be set to WTAP_ERR_SHORT_READ. If so, that's not an error, as the parser @@ -430,20 +431,20 @@ static gboolean ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, *err_info = NULL; } *data_offset = offset; - return TRUE; + return true; } -static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, +static bool ascend_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { ascend_t *ascend = (ascend_t *)wth->priv; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (!parse_ascend(ascend, wth->random_fh, rec, buf, wth->snapshot_length, NULL, err, err_info)) - return FALSE; + return false; /* Flex might have gotten an EOF and caused *err to be set to WTAP_ERR_SHORT_READ. If so, that's not an error, as the parser @@ -454,7 +455,7 @@ static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, g_free(*err_info); *err_info = NULL; } - return TRUE; + return true; } static const struct supported_block_type ascend_blocks_supported[] = { @@ -466,7 +467,7 @@ static const struct supported_block_type ascend_blocks_supported[] = { static const struct file_type_subtype_info ascend_info = { "Lucent/Ascend access server trace", "ascend", "txt", NULL, - FALSE, BLOCKS_SUPPORTED(ascend_blocks_supported), + false, BLOCKS_SUPPORTED(ascend_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/ascendtext.h b/wiretap/ascendtext.h index 74ad6986..abfed13a 100644 --- a/wiretap/ascendtext.h +++ b/wiretap/ascendtext.h @@ -10,6 +10,7 @@ #ifndef __ASCENDTEXT_H__ #define __ASCENDTEXT_H__ #include <glib.h> +#include "wtap.h" /* * ASCEND_MAX_PKT_LEN is < WTAP_MAX_PACKET_SIZE_STANDARD, so we don't need to @@ -19,6 +20,6 @@ #define ASCEND_MAX_DATA_COLS 16 #define ASCEND_MAX_PKT_LEN (ASCEND_MAX_DATA_ROWS * ASCEND_MAX_DATA_COLS) -wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val ascend_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/atm.c b/wiretap/atm.c index 47b471dd..793cfbad 100644 --- a/wiretap/atm.c +++ b/wiretap/atm.c @@ -7,8 +7,8 @@ */ #include "config.h" -#include "wtap-int.h" #include "atm.h" +#include "wtap-int.h" /* * Routines to use with ATM capture file types that don't include information @@ -20,7 +20,7 @@ */ void -atm_guess_traffic_type(wtap_rec *rec, const guint8 *pd) +atm_guess_traffic_type(wtap_rec *rec, const uint8_t *pd) { /* * Start out assuming nothing other than that it's AAL5. @@ -98,7 +98,7 @@ atm_guess_traffic_type(wtap_rec *rec, const guint8 *pd) } void -atm_guess_lane_type(wtap_rec *rec, const guint8 *pd) +atm_guess_lane_type(wtap_rec *rec, const uint8_t *pd) { if (rec->rec_header.packet_header.caplen >= 2) { if (pd[0] == 0xff && pd[1] == 0x00) { diff --git a/wiretap/atm.h b/wiretap/atm.h index 4f560e3e..5ee98122 100644 --- a/wiretap/atm.h +++ b/wiretap/atm.h @@ -10,6 +10,9 @@ #define __ATM_H__ #include <glib.h> #include "ws_symbol_export.h" +#include <stdint.h> + +typedef struct wtap_rec wtap_rec; /* * Routines to use with ATM capture file types that don't include information @@ -18,9 +21,9 @@ */ extern void -atm_guess_traffic_type(wtap_rec *rec, const guint8 *pd); +atm_guess_traffic_type(wtap_rec *rec, const uint8_t *pd); extern void -atm_guess_lane_type(wtap_rec *rec, const guint8 *pd); +atm_guess_lane_type(wtap_rec *rec, const uint8_t *pd); #endif /* __ATM_H__ */ diff --git a/wiretap/autosar_dlt.c b/wiretap/autosar_dlt.c index 5310443c..721da3c7 100644 --- a/wiretap/autosar_dlt.c +++ b/wiretap/autosar_dlt.c @@ -26,34 +26,34 @@ #include "file_wrappers.h" #include "wtap-int.h" -static const guint8 dlt_magic[] = { 'D', 'L', 'T', 0x01 }; +static const uint8_t dlt_magic[] = { 'D', 'L', 'T', 0x01 }; static int autosar_dlt_file_type_subtype = -1; void register_autosar_dlt(void); -static gboolean autosar_dlt_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); -static gboolean autosar_dlt_seek_read(wtap *wth, gint64 seek_off, wtap_rec* rec, Buffer *buf, int *err, gchar **err_info); +static bool autosar_dlt_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, int64_t *data_offset); +static bool autosar_dlt_seek_read(wtap *wth, int64_t seek_off, wtap_rec* rec, Buffer *buf, int *err, char **err_info); static void autosar_dlt_close(wtap *wth); typedef struct autosar_dlt_blockheader { - guint8 magic[4]; - guint32 timestamp_s; - guint32 timestamp_us; - guint8 ecu_id[4]; + uint8_t magic[4]; + uint32_t timestamp_s; + uint32_t timestamp_us; + uint8_t ecu_id[4]; } autosar_dlt_blockheader_t; typedef struct autosar_dlt_itemheader { - guint8 header_type; - guint8 counter; - guint16 length; + uint8_t header_type; + uint8_t counter; + uint16_t length; } autosar_dlt_itemheader_t; typedef struct autosar_dlt_data { GHashTable *ecu_to_iface_ht; - guint32 next_interface_id; + uint32_t next_interface_id; } autosar_dlt_t; typedef struct autosar_dlt_params { @@ -65,18 +65,18 @@ typedef struct autosar_dlt_params { autosar_dlt_t *dlt_data; } autosar_dlt_params_t; -static gint -autosar_dlt_calc_key(guint8 ecu[4]) { - return (gint)(ecu[0] << 24 | ecu[1] << 16 | ecu[2] << 8 | ecu[3]); +static int +autosar_dlt_calc_key(uint8_t ecu[4]) { + return (int)(ecu[0] << 24 | ecu[1] << 16 | ecu[2] << 8 | ecu[3]); } -static guint32 -autosar_dlt_add_interface(autosar_dlt_params_t *params, guint8 ecu[4]) { +static uint32_t +autosar_dlt_add_interface(autosar_dlt_params_t *params, uint8_t ecu[4]) { wtap_block_t int_data = wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO); wtapng_if_descr_mandatory_t *if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data); if_descr_mand->wtap_encap = WTAP_ENCAP_AUTOSAR_DLT; - wtap_block_add_string_option(int_data, OPT_IDB_NAME, (gchar *)ecu, 4); + wtap_block_add_string_option(int_data, OPT_IDB_NAME, (char *)ecu, 4); if_descr_mand->time_units_per_second = 1000 * 1000 * 1000; if_descr_mand->tsprecision = WTAP_TSPREC_NSEC; wtap_block_add_uint8_option(int_data, OPT_IDB_TSRESOL, 9); @@ -93,23 +93,23 @@ autosar_dlt_add_interface(autosar_dlt_params_t *params, guint8 ecu[4]) { } } - gint32 key = autosar_dlt_calc_key(ecu); - guint32 iface_id = params->dlt_data->next_interface_id++; + int32_t key = autosar_dlt_calc_key(ecu); + uint32_t iface_id = params->dlt_data->next_interface_id++; g_hash_table_insert(params->dlt_data->ecu_to_iface_ht, GINT_TO_POINTER(key), GUINT_TO_POINTER(iface_id)); return iface_id; } -static guint32 -autosar_dlt_lookup_interface(autosar_dlt_params_t *params, guint8 ecu[4]) { - gint32 key = autosar_dlt_calc_key(ecu); +static uint32_t +autosar_dlt_lookup_interface(autosar_dlt_params_t *params, uint8_t ecu[4]) { + int32_t key = autosar_dlt_calc_key(ecu); if (params->dlt_data->ecu_to_iface_ht == NULL) { return 0; } - gpointer iface = NULL; - gboolean found = g_hash_table_lookup_extended(params->dlt_data->ecu_to_iface_ht, GINT_TO_POINTER(key), NULL, &iface); + void *iface = NULL; + bool found = g_hash_table_lookup_extended(params->dlt_data->ecu_to_iface_ht, GINT_TO_POINTER(key), NULL, &iface); if (found) { return GPOINTER_TO_UINT(iface); @@ -129,8 +129,8 @@ fix_endianness_autosar_dlt_itemheader(autosar_dlt_itemheader_t *header) { header->length = GUINT16_FROM_BE(header->length); } -static gboolean -autosar_dlt_read_block(autosar_dlt_params_t *params, gint64 start_pos, int *err, gchar **err_info) { +static bool +autosar_dlt_read_block(autosar_dlt_params_t *params, int64_t start_pos, int *err, char **err_info) { autosar_dlt_blockheader_t header; autosar_dlt_itemheader_t item_header; @@ -143,7 +143,7 @@ autosar_dlt_read_block(autosar_dlt_params_t *params, gint64 start_pos, int *err, g_free(*err_info); *err_info = ws_strdup_printf("AUTOSAR DLT: Capture file cut short! Cannot find storage header at pos 0x%" PRIx64 "!", start_pos); } - return FALSE; + return false; } fix_endianness_autosar_dlt_blockheader(&header); @@ -151,33 +151,33 @@ autosar_dlt_read_block(autosar_dlt_params_t *params, gint64 start_pos, int *err, if (memcmp(header.magic, dlt_magic, sizeof(dlt_magic))) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("AUTOSAR DLT: Bad capture file! Object magic is not DLT\\x01 at pos 0x%" PRIx64 "!", start_pos); - return FALSE; + return false; } /* Set to the byte after the magic. */ - guint64 current_start_of_item = file_tell(params->fh) - sizeof header + 4; + uint64_t current_start_of_item = file_tell(params->fh) - sizeof header + 4; if (!wtap_read_bytes_or_eof(params->fh, &item_header, sizeof item_header, err, err_info)) { *err = WTAP_ERR_BAD_FILE; g_free(*err_info); *err_info = ws_strdup_printf("AUTOSAR DLT: Capture file cut short! Not enough bytes for item header at pos 0x%" PRIx64 "!", start_pos); - return FALSE; + return false; } fix_endianness_autosar_dlt_itemheader(&item_header); if (file_seek(params->fh, current_start_of_item, SEEK_SET, err) < 0) { - return FALSE; + return false; } - ws_buffer_assure_space(params->buf, (gsize)(item_header.length + sizeof header)); + ws_buffer_assure_space(params->buf, (size_t)(item_header.length + sizeof header)); /* Creating AUTOSAR DLT Encapsulation Header: - * guint32 time_s - * guint32 time_us - * guint8[4] ecuname - * guint8[1] 0x00 (termination) - * guint8[3] reserved + * uint32_t time_s + * uint32_t time_us + * uint8_t[4] ecuname + * uint8_t[1] 0x00 (termination) + * uint8_t[3] reserved */ void *tmpbuf = g_malloc0(sizeof header); if (!wtap_read_bytes_or_eof(params->fh, tmpbuf, sizeof header - 4, err, err_info)) { @@ -185,24 +185,24 @@ autosar_dlt_read_block(autosar_dlt_params_t *params, gint64 start_pos, int *err, *err = WTAP_ERR_BAD_FILE; g_free(*err_info); *err_info = ws_strdup_printf("AUTOSAR DLT: Internal Error! Not enough bytes for storage header at pos 0x%" PRIx64 "!", start_pos); - return FALSE; + return false; } - ws_buffer_append(params->buf, tmpbuf, (gsize)(sizeof header)); + ws_buffer_append(params->buf, tmpbuf, (size_t)(sizeof header)); g_free(tmpbuf); tmpbuf = g_try_malloc0(item_header.length); if (tmpbuf == NULL) { *err = ENOMEM; /* we assume we're out of memory */ - return FALSE; + return false; } if (!wtap_read_bytes_or_eof(params->fh, tmpbuf, item_header.length, err, err_info)) { *err = WTAP_ERR_BAD_FILE; g_free(*err_info); *err_info = ws_strdup_printf("AUTOSAR DLT: Capture file cut short! Not enough bytes for item at pos 0x%" PRIx64 "!", start_pos); - return FALSE; + return false; } - ws_buffer_append(params->buf, tmpbuf, (gsize)(item_header.length)); + ws_buffer_append(params->buf, tmpbuf, (size_t)(item_header.length)); g_free(tmpbuf); params->rec->rec_type = REC_TYPE_PACKET; @@ -212,18 +212,18 @@ autosar_dlt_read_block(autosar_dlt_params_t *params, gint64 start_pos, int *err, params->rec->ts.secs = header.timestamp_s; params->rec->ts.nsecs = header.timestamp_us * 1000; - params->rec->rec_header.packet_header.caplen = (guint32)(item_header.length + sizeof header); - params->rec->rec_header.packet_header.len = (guint32)(item_header.length + sizeof header); + params->rec->rec_header.packet_header.caplen = (uint32_t)(item_header.length + sizeof header); + params->rec->rec_header.packet_header.len = (uint32_t)(item_header.length + sizeof header); params->rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_AUTOSAR_DLT; params->rec->rec_header.packet_header.interface_id = autosar_dlt_lookup_interface(params, header.ecu_id); - return TRUE; + return true; } - return FALSE; + return false; } -static gboolean autosar_dlt_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { +static bool autosar_dlt_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, int64_t *data_offset) { autosar_dlt_params_t dlt_tmp; dlt_tmp.wth = wth; @@ -236,13 +236,13 @@ static gboolean autosar_dlt_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err if (!autosar_dlt_read_block(&dlt_tmp, *data_offset, err, err_info)) { ws_debug("couldn't read packet block (data_offset is %" PRId64 ")", *data_offset); - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean autosar_dlt_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { +static bool autosar_dlt_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { autosar_dlt_params_t dlt_tmp; dlt_tmp.wth = wth; @@ -252,14 +252,14 @@ static gboolean autosar_dlt_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, dlt_tmp.dlt_data = (autosar_dlt_t *)wth->priv; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (!autosar_dlt_read_block(&dlt_tmp, seek_off, err, err_info)) { ws_debug("couldn't read packet block (seek_off: %" PRId64 ") (err=%d).", seek_off, *err); - return FALSE; + return false; } - return TRUE; + return true; } static void autosar_dlt_close(wtap *wth) { @@ -277,8 +277,8 @@ static void autosar_dlt_close(wtap *wth) { } wtap_open_return_val -autosar_dlt_open(wtap *wth, int *err, gchar **err_info) { - guint8 magic[4]; +autosar_dlt_open(wtap *wth, int *err, char **err_info) { + uint8_t magic[4]; autosar_dlt_t *dlt; ws_debug("opening file"); @@ -329,7 +329,7 @@ static const struct supported_block_type dlt_blocks_supported[] = { static const struct file_type_subtype_info dlt_info = { "AUTOSAR DLT Logfile", "dlt", "dlt", NULL, - FALSE, BLOCKS_SUPPORTED(dlt_blocks_supported), + false, BLOCKS_SUPPORTED(dlt_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/autosar_dlt.h b/wiretap/autosar_dlt.h index 382deb30..76890803 100644 --- a/wiretap/autosar_dlt.h +++ b/wiretap/autosar_dlt.h @@ -21,7 +21,7 @@ #include "wtap.h" -wtap_open_return_val autosar_dlt_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val autosar_dlt_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/ber.c b/wiretap/ber.c index ead975a4..cdde9fd1 100644 --- a/wiretap/ber.c +++ b/wiretap/ber.c @@ -6,12 +6,11 @@ */ #include "config.h" +#include "ber.h" #include "wtap-int.h" #include "file_wrappers.h" #include <wsutil/buffer.h> -#include "ber.h" - #define BER_CLASS_UNI 0 #define BER_CLASS_APP 1 @@ -24,41 +23,41 @@ static int ber_file_type_subtype = -1; void register_ber(void); -static gboolean ber_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, - gint64 *data_offset) +static bool ber_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, + int64_t *data_offset) { if (!wtap_full_file_read(wth, rec, buf, err, err_info, data_offset)) - return FALSE; + return false; /* Pass the file name. */ rec->rec_header.packet_header.pseudo_header.ber.pathname = wth->pathname; - return TRUE; + return true; } -static gboolean ber_full_file_seek_read(wtap *wth, gint64 seek_off, +static bool ber_full_file_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { if (!wtap_full_file_seek_read(wth, seek_off, rec, buf, err, err_info)) - return FALSE; + return false; /* Pass the file name. */ rec->rec_header.packet_header.pseudo_header.ber.pathname = wth->pathname; - return TRUE; + return true; } -wtap_open_return_val ber_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val ber_open(wtap *wth, int *err, char **err_info) { #define BER_BYTES_TO_CHECK 8 - guint8 bytes[BER_BYTES_TO_CHECK]; - guint8 ber_id; - gint8 ber_class; - gint8 ber_tag; - gboolean ber_pc; - guint8 oct, nlb = 0; + uint8_t bytes[BER_BYTES_TO_CHECK]; + uint8_t ber_id; + int8_t ber_class; + int8_t ber_tag; + bool ber_pc; + uint8_t oct, nlb = 0; int len = 0; - gint64 file_size; + int64_t file_size; int offset = 0, i; if (!wtap_read_bytes(wth->fh, &bytes, BER_BYTES_TO_CHECK, err, err_info)) { @@ -138,7 +137,7 @@ static const struct supported_block_type ber_blocks_supported[] = { static const struct file_type_subtype_info ber_info = { "ASN.1 Basic Encoding Rules", "ber", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(ber_blocks_supported), + false, BLOCKS_SUPPORTED(ber_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/ber.h b/wiretap/ber.h index 6c0c70c6..b0a3ec36 100644 --- a/wiretap/ber.h +++ b/wiretap/ber.h @@ -10,7 +10,8 @@ #define __BER_H__ #include <glib.h> #include "ws_symbol_export.h" +#include "wtap.h" -wtap_open_return_val ber_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val ber_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/blf.c b/wiretap/blf.c index 176db32f..9443ba44 100644 --- a/wiretap/blf.c +++ b/wiretap/blf.c @@ -27,23 +27,31 @@ #include <epan/value_string.h> #include <wsutil/wslog.h> #include <wsutil/exported_pdu_tlvs.h> +#include <wsutil/strtoi.h> #include "file_wrappers.h" #include "wtap-int.h" +#ifdef HAVE_ZLIBNG +#include <zlib-ng.h> +#define ZLIB_PREFIX(x) zng_ ## x +typedef zng_stream zlib_stream; +#else #ifdef HAVE_ZLIB -#define ZLIB_CONST +#define ZLIB_PREFIX(x) x #include <zlib.h> +typedef z_stream zlib_stream; #endif /* HAVE_ZLIB */ +#endif -static const guint8 blf_magic[] = { 'L', 'O', 'G', 'G' }; -static const guint8 blf_obj_magic[] = { 'L', 'O', 'B', 'J' }; +static const uint8_t blf_magic[] = { 'L', 'O', 'G', 'G' }; +static const uint8_t blf_obj_magic[] = { 'L', 'O', 'B', 'J' }; static int blf_file_type_subtype = -1; void register_blf(void); -static gboolean blf_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); -static gboolean blf_seek_read(wtap *wth, gint64 seek_off, wtap_rec* rec, Buffer *buf, int *err, gchar **err_info); +static bool blf_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, int64_t *data_offset); +static bool blf_seek_read(wtap *wth, int64_t seek_off, wtap_rec* rec, Buffer *buf, int *err, char **err_info); static void blf_close(wtap *wth); /* @@ -53,34 +61,30 @@ static void blf_close(wtap *wth); * ... * * The "real" positions, length, etc. reference this layout and not the file. - * When no compression is used the file is accessed directly. */ - typedef struct blf_log_container { - gint64 infile_start_pos; /* start position of log container in file */ - guint64 infile_length; /* length of log container in file */ - guint64 infile_data_start; /* start position of data in log container in file */ + int64_t infile_start_pos; /* start position of log container in file */ + uint64_t infile_length; /* length of log container in file */ + uint64_t infile_data_start; /* start position of data in log container in file */ - gint64 real_start_pos; /* decompressed (virtual) start position including header */ - guint64 real_length; /* decompressed length */ - gint64 real_first_object_pos; /* where does the first obj start? */ - guint64 real_leftover_bytes; /* how many bytes are left over for the next container? */ + uint64_t real_start_pos; /* decompressed (virtual) start position including header */ + uint64_t real_length; /* decompressed length */ - guint16 compression_method; /* 0: uncompressed, 2: zlib */ + uint16_t compression_method; /* 0: uncompressed, 2: zlib */ unsigned char *real_data; /* cache for decompressed data */ } blf_log_container_t; typedef struct blf_data { - gint64 start_of_last_obj; - gint64 current_real_seek_pos; - guint64 start_offset_ns; + int64_t start_of_last_obj; + int64_t current_real_seek_pos; + uint64_t start_offset_ns; - guint current_log_container; - GArray *log_containers; + GArray *log_containers; GHashTable *channel_to_iface_ht; - guint32 next_interface_id; + GHashTable *channel_to_name_ht; + uint32_t next_interface_id; } blf_t; typedef struct blf_params { @@ -88,71 +92,78 @@ typedef struct blf_params { wtap_rec *rec; Buffer *buf; FILE_T fh; + bool random; + bool pipe; blf_t *blf_data; } blf_params_t; typedef struct blf_channel_to_iface_entry { - int pkt_encap; - guint16 channel; - guint16 hwchannel; - guint32 interface_id; + int pkt_encap; + uint16_t channel; + uint16_t hwchannel; + uint32_t interface_id; } blf_channel_to_iface_entry_t; static void -blf_free_key(gpointer key) { +blf_free_key(void *key) { g_free(key); } static void -blf_free_channel_to_iface_entry(gpointer data) { +blf_free_channel_to_iface_entry(void *data) { g_free(data); } -static gint64 -blf_calc_key_value(int pkt_encap, guint16 channel, guint16 hwchannel) { - return (gint64)(((guint64)pkt_encap << 32) | ((guint64)hwchannel << 16) | (guint64)channel); +static void +blf_free_channel_to_name_entry(void *data) { + g_free(data); +} + +static int64_t +blf_calc_key_value(int pkt_encap, uint16_t channel, uint16_t hwchannel) { + return (int64_t)(((uint64_t)pkt_encap << 32) | ((uint64_t)hwchannel << 16) | (uint64_t)channel); } -static void add_interface_name(wtap_block_t *int_data, int pkt_encap, guint16 channel, guint16 hwchannel, gchar *name) { +static void add_interface_name(wtap_block_t int_data, int pkt_encap, uint16_t channel, uint16_t hwchannel, char *name) { if (name != NULL) { - wtap_block_add_string_option_format(*int_data, OPT_IDB_NAME, "%s", name); + wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "%s", name); } else { switch (pkt_encap) { case WTAP_ENCAP_ETHERNET: /* we use UINT16_MAX to encode no hwchannel */ if (hwchannel == UINT16_MAX) { - wtap_block_add_string_option_format(*int_data, OPT_IDB_NAME, "ETH-%u", channel); + wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "ETH-%u", channel); } else { - wtap_block_add_string_option_format(*int_data, OPT_IDB_NAME, "ETH-%u-%u", channel, hwchannel); + wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "ETH-%u-%u", channel, hwchannel); } break; case WTAP_ENCAP_IEEE_802_11: - wtap_block_add_string_option_format(*int_data, OPT_IDB_NAME, "WLAN-%u", channel); + wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "WLAN-%u", channel); break; case WTAP_ENCAP_FLEXRAY: - wtap_block_add_string_option_format(*int_data, OPT_IDB_NAME, "FR-%u", channel); + wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "FR-%u", channel); break; case WTAP_ENCAP_LIN: - wtap_block_add_string_option_format(*int_data, OPT_IDB_NAME, "LIN-%u", channel); + wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "LIN-%u", channel); break; case WTAP_ENCAP_SOCKETCAN: - wtap_block_add_string_option_format(*int_data, OPT_IDB_NAME, "CAN-%u", channel); + wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "CAN-%u", channel); break; default: - wtap_block_add_string_option_format(*int_data, OPT_IDB_NAME, "ENCAP_%d-%u", pkt_encap, channel); + wtap_block_add_string_option_format(int_data, OPT_IDB_NAME, "ENCAP_%d-%u", pkt_encap, channel); } } } -static guint32 -blf_add_interface(blf_params_t *params, int pkt_encap, guint32 channel, guint16 hwchannel, gchar *name) { +static uint32_t +blf_add_interface(blf_params_t *params, int pkt_encap, uint32_t channel, uint16_t hwchannel, char *name) { wtap_block_t int_data = wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO); wtapng_if_descr_mandatory_t *if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data); blf_channel_to_iface_entry_t *item = NULL; if_descr_mand->wtap_encap = pkt_encap; - add_interface_name(&int_data, pkt_encap, channel, hwchannel, name); + add_interface_name(int_data, pkt_encap, channel, hwchannel, name); /* * The time stamp resolution in these files can be per-record; * the maximum resolution is nanoseconds, so we specify that @@ -177,8 +188,8 @@ blf_add_interface(blf_params_t *params, int pkt_encap, guint32 channel, guint16 } } - gint64 *key = NULL; - key = g_new(gint64, 1); + int64_t *key = NULL; + key = g_new(int64_t, 1); *key = blf_calc_key_value(pkt_encap, channel, hwchannel); item = g_new(blf_channel_to_iface_entry_t, 1); @@ -191,10 +202,70 @@ blf_add_interface(blf_params_t *params, int pkt_encap, guint32 channel, guint16 return item->interface_id; } -static guint32 -blf_lookup_interface(blf_params_t *params, int pkt_encap, guint16 channel, guint16 hwchannel, gchar *name) { - gint64 key = blf_calc_key_value(pkt_encap, channel, hwchannel); - blf_channel_to_iface_entry_t *item = NULL; +/** This is used to save the interface name without creating it. + * + * This approach allows up to update the name of the interface + * up until the first captured packet. + */ +static bool +// NOLINTNEXTLINE(misc-no-recursion) +blf_prepare_interface_name(blf_params_t* params, int pkt_encap, uint16_t channel, uint16_t hwchannel, char* name, bool force_new_name) { + int64_t key = blf_calc_key_value(pkt_encap, channel, hwchannel); + char* old_name; + char* new_name; + char* iface_name; + int64_t* new_key; + bool ret; + + if (params->blf_data->channel_to_name_ht == NULL) { + return false; + } + + old_name = (char *)g_hash_table_lookup(params->blf_data->channel_to_name_ht, &key); + + if (old_name != NULL && force_new_name) { + if (!g_hash_table_remove(params->blf_data->channel_to_name_ht, &key)) { + return false; + } + + old_name = NULL; + } + + if (old_name == NULL && name != NULL) { + new_key = g_new(int64_t, 1); + *new_key = key; + new_name = ws_strdup(name); + if (!g_hash_table_insert(params->blf_data->channel_to_name_ht, new_key, new_name)) { + return false; + } + } + else { + new_name = old_name; + } + + if (pkt_encap == WTAP_ENCAP_ETHERNET) { + /* Just for Ethernet, prepare the equivalent STATUS interface */ + iface_name = new_name != NULL ? ws_strdup_printf("STATUS-%s", new_name) : NULL; + + // We recurse here once. + ret = blf_prepare_interface_name(params, WTAP_ENCAP_WIRESHARK_UPPER_PDU, channel, hwchannel, iface_name, force_new_name); + if (iface_name) { + g_free(iface_name); + } + if (!ret) { + return false; + } + } + + return true; +} + +static uint32_t +blf_lookup_interface(blf_params_t *params, int pkt_encap, uint16_t channel, uint16_t hwchannel, char *name) { + int64_t key = blf_calc_key_value(pkt_encap, channel, hwchannel); + blf_channel_to_iface_entry_t* item; + char* saved_name; + uint32_t ret; if (params->blf_data->channel_to_iface_ht == NULL) { return 0; @@ -204,8 +275,19 @@ blf_lookup_interface(blf_params_t *params, int pkt_encap, guint16 channel, guint if (item != NULL) { return item->interface_id; - } else { - return blf_add_interface(params, pkt_encap, channel, hwchannel, name); + } + else { + saved_name = (char*)g_hash_table_lookup(params->blf_data->channel_to_name_ht, &key); + + if (saved_name != NULL) { + ret = blf_add_interface(params, pkt_encap, channel, hwchannel, saved_name); + g_hash_table_remove(params->blf_data->channel_to_name_ht, &key); + + return ret; + } + else { + return blf_add_interface(params, pkt_encap, channel, hwchannel, name); + } } } @@ -299,6 +381,17 @@ fix_endianness_blf_ethernetframeheader_ex(blf_ethernetframeheader_ex_t *header) } static void +fix_endianness_blf_ethernet_rxerror(blf_ethernet_rxerror_t* header) { + header->struct_length = GUINT16_FROM_LE(header->struct_length); + header->channel = GUINT16_FROM_LE(header->channel); + header->direction = GUINT16_FROM_LE(header->direction); + header->hw_channel = GUINT16_FROM_LE(header->hw_channel); + header->frame_checksum = GUINT32_FROM_LE(header->frame_checksum); + header->frame_length = GUINT16_FROM_LE(header->frame_length); + header->error = GUINT32_FROM_LE(header->error); +} + +static void fix_endianness_blf_wlanframeheader(blf_wlanframeheader_t* header) { header->channel = GUINT16_FROM_LE(header->channel); header->flags = GUINT16_FROM_LE(header->flags); @@ -429,6 +522,86 @@ fix_endianness_blf_linmessage(blf_linmessage_t* message) { } static void +fix_endianness_blf_linbusevent(blf_linbusevent_t* linbusevent) { + linbusevent->sof = GUINT64_FROM_LE(linbusevent->sof); + linbusevent->eventBaudrate = GUINT32_FROM_LE(linbusevent->eventBaudrate); + linbusevent->channel = GUINT16_FROM_LE(linbusevent->channel); +} + +static void +fix_endianness_blf_linsynchfieldevent(blf_linsynchfieldevent_t* linsynchfieldevent) { + fix_endianness_blf_linbusevent(&linsynchfieldevent->linBusEvent); + linsynchfieldevent->synchBreakLength = GUINT64_FROM_LE(linsynchfieldevent->synchBreakLength); + linsynchfieldevent->synchDelLength = GUINT64_FROM_LE(linsynchfieldevent->synchDelLength); +} + +static void +fix_endianness_blf_linmessagedescriptor(blf_linmessagedescriptor_t* linmessagedescriptor) { + fix_endianness_blf_linsynchfieldevent(&linmessagedescriptor->linSynchFieldEvent); + linmessagedescriptor->supplierId = GUINT16_FROM_LE(linmessagedescriptor->supplierId); + linmessagedescriptor->messageId = GUINT16_FROM_LE(linmessagedescriptor->messageId); +} + +static void +fix_endianness_blf_lindatabytetimestampevent(blf_lindatabytetimestampevent_t* lindatabytetimestampevent) { + int i; + fix_endianness_blf_linmessagedescriptor(&lindatabytetimestampevent->linMessageDescriptor); + for (i = 0; i < 9; i++) { + lindatabytetimestampevent->databyteTimestamps[i] = GUINT64_FROM_LE(lindatabytetimestampevent->databyteTimestamps[i]); + } +} + +static void +fix_endianness_blf_linmessage2(blf_linmessage2_t* message) { + fix_endianness_blf_lindatabytetimestampevent(&message->linDataByteTimestampEvent); + message->crc = GUINT16_FROM_LE(message->crc); +/* skip the optional part + message->respBaudrate = GUINT32_FROM_LE(message->respBaudrate); + message->exactHeaderBaudrate = GUINT64_FROM_LE(message->exactHeaderBaudrate); + message->earlyStopBitOffset = GUINT32_FROM_LE(message->earlyStopBitOffset); + message->earlyStopBitOffsetResponse = GUINT32_FROM_LE(message->earlyStopBitOffsetResponse); +*/ +} + +static void +fix_endianness_blf_lincrcerror2(blf_lincrcerror2_t* message) { + fix_endianness_blf_lindatabytetimestampevent(&message->linDataByteTimestampEvent); + message->crc = GUINT16_FROM_LE(message->crc); +/* skip the optional part + message->respBaudrate = GUINT32_FROM_LE(message->respBaudrate); + message->exactHeaderBaudrate = GUINT64_FROM_LE(message->exactHeaderBaudrate); + message->earlyStopBitOffset = GUINT32_FROM_LE(message->earlyStopBitOffset); + message->earlyStopBitOffsetResponse = GUINT32_FROM_LE(message->earlyStopBitOffsetResponse); +*/ +} + +static void +fix_endianness_blf_linrcverror2(blf_linrcverror2_t* message) { + fix_endianness_blf_lindatabytetimestampevent(&message->linDataByteTimestampEvent); +/* skip the optional part + message->respBaudrate = GUINT32_FROM_LE(message->respBaudrate); + message->exactHeaderBaudrate = GUINT64_FROM_LE(message->exactHeaderBaudrate); + message->earlyStopBitOffset = GUINT32_FROM_LE(message->earlyStopBitOffset); + message->earlyStopBitOffsetResponse = GUINT32_FROM_LE(message->earlyStopBitOffsetResponse); +*/ +} + +static void +fix_endianness_blf_linsenderror2(blf_linsenderror2_t* message) { + fix_endianness_blf_linmessagedescriptor(&message->linMessageDescriptor); + message->eoh = GUINT64_FROM_LE(message->eoh); +/* skip the optional part + message->exactHeaderBaudrate = GUINT64_FROM_LE(message->exactHeaderBaudrate); + message->earlyStopBitOffset = GUINT32_FROM_LE(message->earlyStopBitOffset); +*/ +} + +static void +fix_endianness_blf_linwakeupevent2(blf_linwakeupevent2_t* message) { + fix_endianness_blf_linbusevent(&message->linBusEvent); +} + +static void fix_endianness_blf_apptext_header(blf_apptext_t *header) { header->source = GUINT32_FROM_LE(header->source); header->reservedAppText1 = GUINT32_FROM_LE(header->reservedAppText1); @@ -452,133 +625,175 @@ fix_endianness_blf_ethernet_status_header(blf_ethernet_status_t* header) { } static void +fix_endianness_blf_ethernet_phystate_header(blf_ethernet_phystate_t* header) { + header->channel = GUINT16_FROM_LE(header->channel); + header->flags = GUINT16_FROM_LE(header->flags); +} + +static void blf_init_logcontainer(blf_log_container_t *tmp) { tmp->infile_start_pos = 0; tmp->infile_length = 0; tmp->infile_data_start = 0; tmp->real_start_pos = 0; tmp->real_length = 0; - tmp->real_first_object_pos = -1; - tmp->real_leftover_bytes = G_MAXUINT64; tmp->real_data = NULL; tmp->compression_method = 0; } -static void -blf_add_logcontainer(blf_t *blf_data, blf_log_container_t log_container) { - if (blf_data->log_containers == NULL) { - blf_data->log_containers = g_array_sized_new(FALSE, FALSE, sizeof(blf_log_container_t), 1); - blf_data->current_log_container = 0; - } else { - blf_data->current_log_container++; - } +int +blf_logcontainers_cmp(const void *a, const void *b) { + blf_log_container_t* container_a = (blf_log_container_t*)a; + blf_log_container_t* container_b = (blf_log_container_t*)b; - g_array_append_val(blf_data->log_containers, log_container); + if (container_a->real_start_pos < container_b->real_start_pos) { + return -1; + } + else if (container_a->real_start_pos > container_b->real_start_pos) { + return 1; + } + else { + return 0; + } } -static gboolean -blf_get_logcontainer_by_index(blf_t *blf_data, guint container_index, blf_log_container_t **ret) { - if (blf_data == NULL || blf_data->log_containers == NULL || container_index >= blf_data->log_containers->len) { - return FALSE; - } +int +blf_logcontainers_search(const void *a, const void *b) { + blf_log_container_t* container_a = (blf_log_container_t*)a; + uint64_t pos = *(uint64_t*)b; - *ret = &g_array_index(blf_data->log_containers, blf_log_container_t, container_index); - return TRUE; + if (container_a->real_start_pos > pos) { + return 1; + } + else if (pos >= container_a->real_start_pos + container_a->real_length) { + return -1; + } + else { + return 0; + } } -static gboolean -blf_find_logcontainer_for_address(blf_t *blf_data, gint64 pos, blf_log_container_t **container, gint *container_index) { - blf_log_container_t *tmp; +/** Ensures the given log container is in memory + * + * If the log container already is not already in memory, + * it reads it from the current seek position, allocating a + * properly sized buffer. + * The file offset must be set to the start of the container + * data (container->infile_data_start) before calling this function. + */ +static bool +blf_pull_logcontainer_into_memory(blf_params_t *params, blf_log_container_t *container, int *err, char **err_info) { - if (blf_data == NULL || blf_data->log_containers == NULL) { - return FALSE; + if (container == NULL) { + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory called with NULL container"); + return false; } - for (guint i = 0; i < blf_data->log_containers->len; i++) { - tmp = &g_array_index(blf_data->log_containers, blf_log_container_t, i); - if (tmp->real_start_pos <= pos && pos < tmp->real_start_pos + (gint64)tmp->real_length) { - *container = tmp; - *container_index = i; - return TRUE; - } + if (container->real_data != NULL) { + return true; } - return FALSE; -} - -static gboolean -blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_container, int *err, gchar **err_info) { - blf_t *blf_data = params->blf_data; - blf_log_container_t tmp; - - if (index_log_container >= blf_data->log_containers->len) { + /* pull compressed data into buffer */ + if (container->infile_start_pos < 0) { /* * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a * malformed file (WTAP_ERR_BAD_FILE)? */ *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: index_log_container (%u) >= blf_data->log_containers->len (%u)", - index_log_container, blf_data->log_containers->len); - return FALSE; + *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: container.infile_start_pos (%" PRId64 ") < 0", + container->infile_start_pos); + return false; } - - tmp = g_array_index(blf_data->log_containers, blf_log_container_t, index_log_container); - - if (tmp.real_data != NULL) { - return TRUE; + if (container->infile_data_start < (uint64_t)container->infile_start_pos) { + /* + * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a + * malformed file (WTAP_ERR_BAD_FILE)? + */ + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: container.infile_data_start (%" PRIu64 ") < container.infile_start_pos (%" PRId64 ")", + container->infile_data_start, container->infile_start_pos); + return false; + } + if (container->infile_length < container->infile_data_start - (uint64_t)container->infile_start_pos) { + /* + * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a + * malformed file (WTAP_ERR_BAD_FILE)? + */ + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: container.infile_length (%" PRIu64 ") < (container.infile_data_start (%" PRIu64 ") - container.infile_start_pos (%" PRId64 ")) = %" PRIu64, + container->infile_length, + container->infile_data_start, container->infile_start_pos, + container->infile_data_start - (uint64_t)container->infile_start_pos); + return false; + } + uint64_t data_length = container->infile_length - (container->infile_data_start - (uint64_t)container->infile_start_pos); + if (data_length > UINT_MAX) { + /* + * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a + * malformed file (WTAP_ERR_BAD_FILE)? + */ + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: data_length (%" PRIu64 ") > UINT_MAX", + data_length); + return false; } - if (tmp.compression_method == BLF_COMPRESSION_ZLIB) { -#ifdef HAVE_ZLIB - if (file_seek(params->fh, tmp.infile_data_start, SEEK_SET, err) == -1) { - return FALSE; + if (container->real_length == 0) { + ws_info("blf_pull_logcontainer_into_memory: found container with 0 length"); + /* Skip empty container */ + if (!wtap_read_bytes_or_eof(params->fh, NULL, (unsigned int)data_length, err, err_info)) { + if (*err == WTAP_ERR_SHORT_READ) { + /* + * XXX - our caller will turn this into an EOF. + * How *should* it be treated? + * For now, we turn it into Yet Another Internal Error, + * pending having better documentation of the file + * format. + */ + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup("blf_pull_logcontainer_into_memory: short read on 0-length container"); + } + return false; } + return true; + } - /* pull compressed data into buffer */ - if (tmp.infile_start_pos < 0) { - /* - * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a - * malformed file (WTAP_ERR_BAD_FILE)? - */ - *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: tmp.infile_start_pos (%" G_GINT64_FORMAT ") < 0", - tmp.infile_start_pos); - return FALSE; - } - if (tmp.infile_data_start < (guint64)tmp.infile_start_pos) { + if (container->compression_method == BLF_COMPRESSION_NONE) { + unsigned char* buf = g_try_malloc((size_t)container->real_length); + if (buf == NULL) { /* - * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a - * malformed file (WTAP_ERR_BAD_FILE)? + * XXX - our caller will turn this into an EOF. + * How *should* it be treated? + * For now, we turn it into Yet Another Internal Error, + * pending having better documentation of the file + * format. */ *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: tmp.infile_data_start (%" G_GUINT64_FORMAT ") < tmp.infile_start_pos (%" G_GINT64_FORMAT ")", - tmp.infile_data_start, tmp.infile_start_pos); - return FALSE; + *err_info = ws_strdup("blf_pull_logcontainer_into_memory: cannot allocate memory"); } - if (tmp.infile_length < tmp.infile_data_start - (guint64)tmp.infile_start_pos) { - /* - * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a - * malformed file (WTAP_ERR_BAD_FILE)? - */ - *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: tmp.infile_length (%" G_GUINT64_FORMAT ") < (tmp.infile_data_start (%" G_GUINT64_FORMAT ") - tmp.infile_start_pos (%" G_GINT64_FORMAT ")) = %" G_GUINT64_FORMAT, - tmp.infile_length, - tmp.infile_data_start, tmp.infile_start_pos, - tmp.infile_data_start - (guint64)tmp.infile_start_pos); - return FALSE; - } - guint64 data_length = tmp.infile_length - (tmp.infile_data_start - (guint64)tmp.infile_start_pos); - if (data_length > UINT_MAX) { - /* - * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a - * malformed file (WTAP_ERR_BAD_FILE)? - */ - *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: data_length (%" G_GUINT64_FORMAT ") > UINT_MAX", - data_length); - return FALSE; + if (!wtap_read_bytes_or_eof(params->fh, buf, (unsigned int)data_length, err, err_info)) { + g_free(buf); + if (*err == WTAP_ERR_SHORT_READ) { + /* + * XXX - our caller will turn this into an EOF. + * How *should* it be treated? + * For now, we turn it into Yet Another Internal Error, + * pending having better documentation of the file + * format. + */ + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup("blf_pull_logcontainer_into_memory: short read on uncompressed data"); + } + return false; } - unsigned char *compressed_data = g_try_malloc0((gsize)tmp.infile_length); + container->real_data = buf; + return true; + + } + else if (container->compression_method == BLF_COMPRESSION_ZLIB) { +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) + unsigned char *compressed_data = g_try_malloc((size_t)data_length); if (!wtap_read_bytes_or_eof(params->fh, compressed_data, (unsigned int)data_length, err, err_info)) { g_free(compressed_data); if (*err == WTAP_ERR_SHORT_READ) { @@ -592,19 +807,30 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe *err = WTAP_ERR_INTERNAL; *err_info = ws_strdup("blf_pull_logcontainer_into_memory: short read on compressed data"); } - return FALSE; + return false; } - unsigned char *buf = g_try_malloc0((gsize)tmp.real_length); - z_stream infstream = {0}; + unsigned char *buf = g_try_malloc((size_t)container->real_length); + if (buf == NULL) { + /* + * XXX - our caller will turn this into an EOF. + * How *should* it be treated? + * For now, we turn it into Yet Another Internal Error, + * pending having better documentation of the file + * format. + */ + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup("blf_pull_logcontainer_into_memory: cannot allocate memory"); + } + zlib_stream infstream = {0}; infstream.avail_in = (unsigned int)data_length; infstream.next_in = compressed_data; - infstream.avail_out = (unsigned int)tmp.real_length; + infstream.avail_out = (unsigned int)container->real_length; infstream.next_out = buf; /* the actual DE-compression work. */ - if (Z_OK != inflateInit(&infstream)) { + if (Z_OK != ZLIB_PREFIX(inflateInit)(&infstream)) { /* * XXX - check the error code and handle this appropriately. */ @@ -612,21 +838,19 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe g_free(compressed_data); *err = WTAP_ERR_INTERNAL; if (infstream.msg != NULL) { - *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: inflateInit failed for LogContainer %u, message\"%s\"", - index_log_container, + *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: inflateInit failed for LogContainer, message\"%s\"", infstream.msg); } else { - *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: inflateInit failed for LogContainer %u", - index_log_container); + *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: inflateInit failed for LogContainer"); } - ws_debug("inflateInit failed for LogContainer %u", index_log_container); + ws_debug("inflateInit failed for LogContainer"); if (infstream.msg != NULL) { ws_debug("inflateInit returned: \"%s\"", infstream.msg); } - return FALSE; + return false; } - int ret = inflate(&infstream, Z_NO_FLUSH); + int ret = ZLIB_PREFIX(inflate)(&infstream, Z_NO_FLUSH); /* Z_OK should not happen here since we know how big the buffer should be */ if (Z_STREAM_END != ret) { switch (ret) { @@ -675,16 +899,16 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe } g_free(buf); g_free(compressed_data); - ws_debug("inflate failed (return code %d) for LogContainer %u", ret, index_log_container); + ws_debug("inflate failed (return code %d) for LogContainer", ret); if (infstream.msg != NULL) { ws_debug("inflate returned: \"%s\"", infstream.msg); } /* Free up any dynamically-allocated memory in infstream */ - inflateEnd(&infstream); - return FALSE; + ZLIB_PREFIX(inflateEnd)(&infstream); + return false; } - if (Z_OK != inflateEnd(&infstream)) { + if (Z_OK != ZLIB_PREFIX(inflateEnd)(&infstream)) { /* * The zlib manual says this only returns Z_OK on success * and Z_STREAM_ERROR if the stream state was inconsistent. @@ -698,336 +922,378 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe * fails. */ *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: inflateEnd failed for LogContainer %u", index_log_container); + *err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: inflateEnd failed for LogContainer"); g_free(buf); g_free(compressed_data); - ws_debug("inflateEnd failed for LogContainer %u", index_log_container); + ws_debug("inflateEnd failed for LogContainer"); if (infstream.msg != NULL) { ws_debug("inflateEnd returned: \"%s\"", infstream.msg); } - return FALSE; + return false; } g_free(compressed_data); - tmp.real_data = buf; - g_array_index(blf_data->log_containers, blf_log_container_t, index_log_container) = tmp; - return TRUE; + container->real_data = buf; + return true; #else + (void) params; *err = WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED; *err_info = ws_strdup("blf_pull_logcontainer_into_memory: reading gzip-compressed containers isn't supported"); - return FALSE; + return false; #endif } - return FALSE; + return false; } -static gboolean -blf_read_bytes_or_eof(blf_params_t *params, guint64 real_pos, void *target_buffer, unsigned int count, int *err, gchar **err_info) { - blf_log_container_t *start_container; - blf_log_container_t *end_container; - blf_log_container_t *current_container; +/** Finds the next log container starting at the current file offset + * + * Adds the container to the containers array for later access + */ +static bool +blf_find_next_logcontainer(blf_params_t* params, int* err, char** err_info) { + blf_blockheader_t header; + blf_logcontainerheader_t logcontainer_header; + blf_log_container_t tmp; + unsigned char* header_ptr; + unsigned int i; - gint start_container_index = -1; - gint end_container_index = -1; - gint current_container_index = -1; + uint64_t current_real_start; + if (params->blf_data->log_containers->len == 0) { + current_real_start = 0; + } + else { + blf_log_container_t* container = &g_array_index(params->blf_data->log_containers, blf_log_container_t, params->blf_data->log_containers->len - 1); + current_real_start = container->real_start_pos + container->real_length; + } - unsigned int copied = 0; - unsigned int data_left; - unsigned int start_in_buf; + header_ptr = (unsigned char*)&header; + i = 0; - unsigned char *buf = (unsigned char *)target_buffer; + /** Find Object + * + * We read one byte at a time so that we don't have to seek backward (allows us to do a linear read) + */ + while (i < sizeof(blf_obj_magic)) { + if (!wtap_read_bytes_or_eof(params->fh, &header_ptr[i], 1, err, err_info)) { + ws_debug("we found end of file"); + return false; + } + if (header_ptr[i] != blf_obj_magic[i]) { + if (params->pipe) { + ws_debug("container object magic is not LOBJ"); + } + else { + ws_debug("container object magic is not LOBJ (pos: 0x%" PRIx64 ")", file_tell(params->fh) - 1); + } + if (i > 0) { + int j = i; - if (!blf_find_logcontainer_for_address(params->blf_data, real_pos, &start_container, &start_container_index)) { - /* - * XXX - why is this treated as an EOF rather than an error? - * *err appears to be 0, which means our caller treats it as an - * EOF, at least when reading the log object header. - */ - ws_debug("cannot read data because start position cannot be mapped"); - return FALSE; + while (memcmp(&header_ptr[i - j + 1], blf_obj_magic, j)) { + /* Check if the last j bytes match the first j bytes of the magic */ + j--; + } + + /* The last j bytes match, and the first j bytes are already in the buffer, since j<=i */ + i = j; + } + } + else { + /* Character matches */ + i++; + } } - if (!blf_find_logcontainer_for_address(params->blf_data, real_pos + count - 1, &end_container, &end_container_index)) { - /* - * XXX - why is this treated as an EOF rather than an error? - * *err appears to be 0, which means our caller treats it as an - * EOF, at least when reading the log object header. - */ - ws_debug("cannot read data because end position cannot be mapped"); - return FALSE; + + if (!wtap_read_bytes_or_eof(params->fh, &header.header_length, sizeof(blf_blockheader_t) - sizeof(blf_obj_magic), err, err_info)) { + ws_debug("we found end of file"); + return false; } - current_container_index = start_container_index; - current_container = start_container; - start_in_buf = (unsigned int)real_pos - (unsigned int)start_container->real_start_pos; + fix_endianness_blf_blockheader(&header); - switch (start_container->compression_method) { - case BLF_COMPRESSION_NONE: - while (current_container_index <= end_container_index) { - if (!blf_get_logcontainer_by_index(params->blf_data, current_container_index, ¤t_container)) { - /* - * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a - * malformed file (WTAP_ERR_BAD_FILE)? - */ - *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_read_bytes_or_eof: cannot refresh container"); - ws_debug("cannot refresh container"); - return FALSE; - } + if (header.header_length < sizeof(blf_blockheader_t)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup("blf: header length too short while looking for object"); + return false; + } - data_left = (unsigned int)(current_container->real_length - start_in_buf); + if (header.header_type != BLF_HEADER_TYPE_DEFAULT) { + *err = WTAP_ERR_UNSUPPORTED; + *err_info = ws_strdup_printf("blf: unknown header type (%u), I know only BLF_HEADER_TYPE_DEFAULT (1)", header.header_type); + return false; + } - if (file_seek(params->fh, current_container->infile_data_start + start_in_buf, SEEK_SET, err) < 0) { - ws_debug("cannot seek data"); - return FALSE; - } + if (header.object_length < header.header_length) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup("blf: header object length less than header length while looking for objects"); + return false; + } - if (data_left < (count - copied)) { - if (!wtap_read_bytes_or_eof(params->fh, buf + copied, data_left, err, err_info)) { - ws_debug("cannot read data"); - return FALSE; - } - copied += data_left; - current_container_index++; - start_in_buf = 0; - } else { - if (!wtap_read_bytes_or_eof(params->fh, buf + copied, count - copied, err, err_info)) { - ws_debug("cannot read data"); - return FALSE; - } - return TRUE; + if (header.object_type == BLF_OBJTYPE_LOG_CONTAINER) { + /* skip unknown header part if needed */ + if (header.header_length > sizeof(blf_blockheader_t)) { + /* seek over unknown header part */ + if (!wtap_read_bytes(params->fh, NULL, header.header_length - sizeof(blf_blockheader_t), err, err_info)) { + ws_debug("error skipping unknown header bytes in log container"); + return false; } } - break; - case BLF_COMPRESSION_ZLIB: - while (current_container_index <= end_container_index) { - if (!blf_pull_logcontainer_into_memory(params, current_container_index, err, err_info)) { - return FALSE; - } + /* Read the log container header */ + if (!wtap_read_bytes_or_eof(params->fh, &logcontainer_header, sizeof(blf_logcontainerheader_t), err, err_info)) { + ws_debug("not enough bytes for log container header"); + return false; + } - if (!blf_get_logcontainer_by_index(params->blf_data, current_container_index, ¤t_container)) { - /* - * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a - * malformed file (WTAP_ERR_BAD_FILE)? - */ - *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_read_bytes_or_eof: cannot refresh container"); - ws_debug("cannot refresh container"); - return FALSE; - } + fix_endianness_blf_logcontainerheader(&logcontainer_header); - if (current_container->real_data == NULL) { - /* - * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a - * malformed file (WTAP_ERR_BAD_FILE)? - */ - *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_read_bytes_or_eof: pulling in container failed hard"); - ws_debug("pulling in container failed hard"); - return FALSE; - } + blf_init_logcontainer(&tmp); + + if (params->pipe) { + tmp.infile_start_pos = 0; + tmp.infile_data_start = sizeof(blf_logcontainerheader_t) + header.header_length; + } + else { + tmp.infile_data_start = file_tell(params->fh); + tmp.infile_start_pos = tmp.infile_data_start - sizeof(blf_logcontainerheader_t) - header.header_length; + } + tmp.infile_length = header.object_length; - data_left = (unsigned int)(current_container->real_length - start_in_buf); + tmp.real_start_pos = current_real_start; + tmp.real_length = logcontainer_header.uncompressed_size; + tmp.compression_method = logcontainer_header.compression_method; - if (data_left < (count - copied)) { - memcpy(buf + copied, current_container->real_data + start_in_buf, (unsigned int)data_left); - copied += data_left; - current_container_index++; - start_in_buf = 0; - } else { - memcpy(buf + copied, current_container->real_data + start_in_buf, count - copied); - return TRUE; + ws_debug("found log container with real_pos=0x%" PRIx64 ", real_length=0x%" PRIx64, tmp.real_start_pos, tmp.real_length); + } + else { + ws_debug("found BLF object without log container"); + + /* Create a fake log container for the lone object. + * In order to avoid seeking backwards, we need to pull the fake log container now. + */ + unsigned char* buf = g_try_malloc((size_t)header.object_length); + if (buf == NULL) { + /* + * XXX - we need an "out of memory" error code here. + */ + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup("blf_find_next_logcontainer: cannot allocate memory"); + return false; + } + + memcpy(buf, &header, sizeof(blf_blockheader_t)); + + if (header.object_length > sizeof(blf_blockheader_t)) { + if (!wtap_read_bytes(params->fh, buf + sizeof(blf_blockheader_t), header.object_length - sizeof(blf_blockheader_t), err, err_info)) { + g_free(buf); + ws_debug("cannot pull object without log container"); + return false; } } - /* - * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a - * malformed file (WTAP_ERR_BAD_FILE)? - */ - *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("blf_read_bytes_or_eof: ran out of items in container"); - return FALSE; - break; - default: - *err = WTAP_ERR_UNSUPPORTED; - *err_info = ws_strdup_printf("blf: unknown compression method %u", - start_container->compression_method); - ws_debug("unknown compression method"); - return FALSE; + blf_init_logcontainer(&tmp); + + tmp.infile_start_pos = params->pipe ? 0 : (file_tell(params->fh) - header.object_length); + tmp.infile_data_start = tmp.infile_start_pos; + tmp.infile_length = header.object_length; + + tmp.real_start_pos = current_real_start; + tmp.real_length = header.object_length; + tmp.compression_method = BLF_COMPRESSION_NONE; + + tmp.real_data = buf; + + ws_debug("found non-log-container object with real_pos=0x%" PRIx64 ", real_length=0x%" PRIx64, tmp.real_start_pos, tmp.real_length); } - return FALSE; + g_array_append_val(params->blf_data->log_containers, tmp); + + return true; } -static gboolean -blf_read_bytes(blf_params_t *params, guint64 real_pos, void *target_buffer, unsigned int count, int *err, gchar **err_info) { - if (!blf_read_bytes_or_eof(params, real_pos, target_buffer, count, err, err_info)) { - if (*err == 0) { - *err = WTAP_ERR_SHORT_READ; - } - return FALSE; +static bool +blf_pull_next_logcontainer(blf_params_t* params, int* err, char** err_info) { + blf_log_container_t* container; + if (!blf_find_next_logcontainer(params, err, err_info)) { + return false; + } + /* Is there a next log container to pull? */ + if (params->blf_data->log_containers->len == 0) { + /* No. */ + return false; + } + container = &g_array_index(params->blf_data->log_containers, blf_log_container_t, params->blf_data->log_containers->len - 1); + if (!blf_pull_logcontainer_into_memory(params, container, err, err_info)) { + return false; } - return TRUE; + return true; } -/* this is only called once on open to figure out the layout of the file */ -static gboolean -blf_scan_file_for_logcontainers(blf_params_t *params, int *err, gchar **err_info) { - blf_blockheader_t header; - blf_logcontainerheader_t logcontainer_header; - blf_log_container_t tmp; +static bool +blf_read_bytes_or_eof(blf_params_t *params, uint64_t real_pos, void *target_buffer, uint64_t count, int *err, char **err_info) { + blf_log_container_t* container; + unsigned container_index; - guint64 current_start_pos; - guint64 current_real_start = 0; + uint64_t end_pos = real_pos + count; - while (1) { - current_start_pos = file_tell(params->fh); + uint64_t copied = 0; + uint64_t data_left; + uint64_t start_in_buf; - /* Find Object */ - while (1) { - if (!wtap_read_bytes_or_eof(params->fh, &header, sizeof header, err, err_info)) { - ws_debug("we found end of file"); - - /* lets ignore some bytes at the end since some implementations think it is ok to add a few zero bytes */ - if (*err == WTAP_ERR_SHORT_READ) { - *err = 0; - } - - /* Either succeed on an EOF or fail. */ - return *err == 0; - } + unsigned char *buf = (unsigned char *)target_buffer; - fix_endianness_blf_blockheader(&header); + if (count == 0) { + ws_debug("called blf_read_bytes_or_eof with 0 count"); + return false; + } - if (memcmp(header.magic, blf_obj_magic, sizeof(blf_obj_magic))) { - ws_debug("object magic is not LOBJ (pos: 0x%" PRIx64 ")", current_start_pos); - } else { - break; - } + if (count > UINT32_MAX) { + ws_debug("trying to read too many bytes"); + return false; + } + if (params->random) { + /* + * Do a binary search for the container in which real_pos + * is included. + */ + if (!g_array_binary_search(params->blf_data->log_containers, &real_pos, blf_logcontainers_search, &container_index)) { /* - * we are moving back and try again but 1 byte later - * TODO: better understand how this paddings works... - * Note that, in at least one capture - the Example.blf - * file attached to - * https://gitlab.com/wireshark/wireshark/-/issues/19269 - - * one of the log container objects is aligned on a 2-byte - * bundary but *not* on a 4-byte boundary, with 3 bytes - * of padding. + * XXX - why is this treated as an EOF rather than an error? + * *err appears to be 0, which means our caller treats it as an + * EOF, at least when reading the log object header. */ - current_start_pos++; - if (file_seek(params->fh, current_start_pos, SEEK_SET, err) < 0) { - return FALSE; - } + ws_debug("cannot read data because start position cannot be mapped"); + return false; } - - if (header.header_length < sizeof(blf_blockheader_t)) { - *err = WTAP_ERR_BAD_FILE; - *err_info = ws_strdup("blf: log container header length too short"); - return FALSE; + container = &g_array_index(params->blf_data->log_containers, blf_log_container_t, container_index); + } + else { + if (params->blf_data->log_containers->len == 0) { + /* + * This is the first (linear) pass, and we haven't yet + * added any containers. Pull the next log container + * into memory, so that the array isn't empty. + */ + if (!blf_pull_next_logcontainer(params, err, err_info)) { + return false; + } } - if (header.header_type != BLF_HEADER_TYPE_DEFAULT) { - *err = WTAP_ERR_UNSUPPORTED; - *err_info = ws_strdup_printf("blf: unknown header type (%u), I know only BLF_HEADER_TYPE_DEFAULT (1)", header.header_type); - return FALSE; - } + /* + * Search backwards in the array, from the last entry to the + * first, to find the log container in which real_pos is + * included. + */ + container_index = params->blf_data->log_containers->len; + do { + container = &g_array_index(params->blf_data->log_containers, blf_log_container_t, --container_index); + } while (real_pos < container->real_start_pos && container_index > 0); /* For some reason we skipped past the correct container */ + } - if (header.object_length < header.header_length) { - *err = WTAP_ERR_BAD_FILE; - *err_info = ws_strdup("blf: log container header object length less than log container header length"); - return FALSE; - } + while (real_pos < end_pos) { - switch (header.object_type) { - case BLF_OBJTYPE_LOG_CONTAINER: - /* skip unknown header part if needed */ - if (header.header_length - sizeof(blf_blockheader_t) > 0) { - /* seek over unknown header part */ - if (file_seek(params->fh, current_start_pos + header.header_length, SEEK_SET, err) < 0) { - ws_debug("cannot seek file for skipping unknown header bytes in log container"); - return FALSE; + while (real_pos >= container->real_start_pos + container->real_length) { + container_index++; + if (!params->random) { /* First (linear) pass */ + if (!blf_pull_next_logcontainer(params, err, err_info)) { + return false; } } - - /* Read the log container header */ - if (!wtap_read_bytes_or_eof(params->fh, &logcontainer_header, sizeof(blf_logcontainerheader_t), err, err_info)) { - ws_debug("not enough bytes for log container header"); - return FALSE; + if (container_index >= params->blf_data->log_containers->len) { + ws_debug("cannot find real_pos in container"); + return false; } + container = &g_array_index(params->blf_data->log_containers, blf_log_container_t, container_index); + if (real_pos < container->real_start_pos) { + ws_debug("cannot find real_pos in container"); + return false; + } + } - fix_endianness_blf_logcontainerheader(&logcontainer_header); - - blf_init_logcontainer(&tmp); + if (real_pos < container->real_start_pos) { + ws_debug("cannot find real_pos in container"); + return false; + } - tmp.infile_start_pos = current_start_pos; - tmp.infile_data_start = file_tell(params->fh); - tmp.infile_length = header.object_length; + start_in_buf = real_pos - container->real_start_pos; - tmp.real_start_pos = current_real_start; - tmp.real_length = logcontainer_header.uncompressed_size; - tmp.compression_method = logcontainer_header.compression_method; + if (params->random) { + if (file_seek(params->fh, container->infile_data_start, SEEK_SET, err) == -1) { + return false; + } + if (!blf_pull_logcontainer_into_memory(params, container, err, err_info)) { + return false; + } + } - /* set up next start position */ - current_real_start += logcontainer_header.uncompressed_size; + data_left = container->real_length - start_in_buf; - if (file_seek(params->fh, current_start_pos + MAX(MAX(16, header.object_length), header.header_length), SEEK_SET, err) < 0) { - ws_debug("cannot seek file for skipping log container bytes"); - return FALSE; - } + if (data_left < (count - copied)) { + memcpy(buf + copied, container->real_data + start_in_buf, data_left); + copied += data_left; + real_pos += data_left; + } + else { + memcpy(buf + copied, container->real_data + start_in_buf, count - copied); + return true; + } - blf_add_logcontainer(params->blf_data, tmp); + } - break; - default: - ws_debug("we found a non BLF log container on top level. this is unexpected."); + /* + * XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a + * malformed file (WTAP_ERR_BAD_FILE)? + */ + *err = WTAP_ERR_INTERNAL; + *err_info = ws_strdup_printf("blf_read_bytes_or_eof: ran out of containers"); + return false; +} - /* TODO: maybe create "fake Log Container" for this */ - if (file_seek(params->fh, current_start_pos + MAX(MAX(16, header.object_length), header.header_length), SEEK_SET, err) < 0) { - return FALSE; - } +static bool +blf_read_bytes(blf_params_t *params, uint64_t real_pos, void *target_buffer, uint64_t count, int *err, char **err_info) { + if (!blf_read_bytes_or_eof(params, real_pos, target_buffer, count, err, err_info)) { + if (*err == 0) { + *err = WTAP_ERR_SHORT_READ; } + return false; } - - return TRUE; + return true; } static void -blf_init_rec(blf_params_t *params, guint32 flags, guint64 object_timestamp, int pkt_encap, guint16 channel, guint16 hwchannel, guint caplen, guint len) { +blf_init_rec(blf_params_t *params, uint32_t flags, uint64_t object_timestamp, int pkt_encap, uint16_t channel, uint16_t hwchannel, unsigned caplen, unsigned len) { params->rec->rec_type = REC_TYPE_PACKET; params->rec->block = wtap_block_create(WTAP_BLOCK_PACKET); - params->rec->presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN | WTAP_HAS_INTERFACE_ID; + params->rec->presence_flags = WTAP_HAS_CAP_LEN | WTAP_HAS_INTERFACE_ID; + params->rec->ts_rel_cap_valid = false; switch (flags) { case BLF_TIMESTAMP_RESOLUTION_10US: + params->rec->presence_flags |= WTAP_HAS_TS; params->rec->tsprec = WTAP_TSPREC_10_USEC; object_timestamp *= 10000; object_timestamp += params->blf_data->start_offset_ns; + params->rec->ts_rel_cap_valid = true; break; case BLF_TIMESTAMP_RESOLUTION_1NS: + params->rec->presence_flags |= WTAP_HAS_TS; params->rec->tsprec = WTAP_TSPREC_NSEC; object_timestamp += params->blf_data->start_offset_ns; + params->rec->ts_rel_cap_valid = true; break; default: - if (flags == 0 && object_timestamp == 0) { - /* This is not an error, but is used for metadata at the beginning of the file. */ - params->rec->tsprec = WTAP_TSPREC_NSEC; - object_timestamp = params->blf_data->start_offset_ns; - } - else { + /* Metadata objects have both flags and timestamp equal to zero, so that combination is not an error. */ + if (flags != 0 || object_timestamp != 0) { /* * XXX - report this as an error? * * Or provide a mechanism to allow file readers to report * a warning (an error that the reader tries to work * around and that the caller should report)? - * - * Set the timestamp to params->blf_data->start_offset_ns also here? */ ws_debug("Unknown combination of flags and timestamp (0x%x, %" PRIu64 ")", flags, object_timestamp); - params->rec->tsprec = WTAP_TSPREC_NSEC; object_timestamp = 0; } break; @@ -1041,7 +1307,6 @@ blf_init_rec(blf_params_t *params, guint32 flags, guint64 object_timestamp, int tmp_ts.secs = params->blf_data->start_offset_ns / (1000 * 1000 * 1000); tmp_ts.nsecs = params->blf_data->start_offset_ns % (1000 * 1000 * 1000); nstime_delta(¶ms->rec->ts_rel_cap, ¶ms->rec->ts, &tmp_ts); - params->rec->ts_rel_cap_valid = true; params->rec->rec_header.packet_header.pkt_encap = pkt_encap; params->rec->rec_header.packet_header.interface_id = blf_lookup_interface(params, pkt_encap, channel, hwchannel, NULL); @@ -1050,8 +1315,8 @@ blf_init_rec(blf_params_t *params, guint32 flags, guint64 object_timestamp, int } static void -blf_add_direction_option(blf_params_t *params, guint16 direction) { - guint32 tmp = 0; /* dont care */ +blf_add_direction_option(blf_params_t *params, uint16_t direction) { + uint32_t tmp = 0; /* dont care */ switch (direction) { case BLF_DIR_RX: @@ -1067,73 +1332,73 @@ blf_add_direction_option(blf_params_t *params, guint16 direction) { wtap_block_add_uint32_option(params->rec->block, 0x0002, tmp); } -static gboolean -blf_read_log_object_header(blf_params_t *params, int *err, gchar **err_info, gint64 header2_start, gint64 data_start, blf_logobjectheader_t *logheader) { - if (data_start - header2_start < (gint64)sizeof(blf_logobjectheader_t)) { +static bool +blf_read_log_object_header(blf_params_t *params, int *err, char **err_info, int64_t header2_start, int64_t data_start, blf_logobjectheader_t *logheader) { + if (data_start - header2_start < (int64_t)sizeof(blf_logobjectheader_t)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: not enough bytes for log object header"); ws_debug("not enough bytes for timestamp header"); - return FALSE; + return false; } if (!blf_read_bytes_or_eof(params, header2_start, logheader, sizeof(*logheader), err, err_info)) { ws_debug("not enough bytes for logheader"); - return FALSE; + return false; } fix_endianness_blf_logobjectheader(logheader); - return TRUE; + return true; } -static gboolean -blf_read_log_object_header2(blf_params_t *params, int *err, gchar **err_info, gint64 header2_start, gint64 data_start, blf_logobjectheader2_t *logheader) { - if (data_start - header2_start < (gint64)sizeof(blf_logobjectheader2_t)) { +static bool +blf_read_log_object_header2(blf_params_t *params, int *err, char **err_info, int64_t header2_start, int64_t data_start, blf_logobjectheader2_t *logheader) { + if (data_start - header2_start < (int64_t)sizeof(blf_logobjectheader2_t)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: not enough bytes for log object header"); ws_debug("not enough bytes for timestamp header"); - return FALSE; + return false; } if (!blf_read_bytes_or_eof(params, header2_start, logheader, sizeof(*logheader), err, err_info)) { ws_debug("not enough bytes for logheader"); - return FALSE; + return false; } fix_endianness_blf_logobjectheader2(logheader); - return TRUE; + return true; } -static gboolean -blf_read_log_object_header3(blf_params_t *params, int *err, gchar **err_info, gint64 header2_start, gint64 data_start, blf_logobjectheader3_t *logheader) { - if (data_start - header2_start < (gint64)sizeof(blf_logobjectheader3_t)) { +static bool +blf_read_log_object_header3(blf_params_t *params, int *err, char **err_info, int64_t header2_start, int64_t data_start, blf_logobjectheader3_t *logheader) { + if (data_start - header2_start < (int64_t)sizeof(blf_logobjectheader3_t)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: not enough bytes for log object header"); ws_debug("not enough bytes for timestamp header"); - return FALSE; + return false; } if (!blf_read_bytes_or_eof(params, header2_start, logheader, sizeof(*logheader), err, err_info)) { ws_debug("not enough bytes for logheader"); - return FALSE; + return false; } fix_endianness_blf_logobjectheader3(logheader); - return TRUE; + return true; } -static gboolean -blf_read_ethernetframe(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_ethernetframe(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { blf_ethernetframeheader_t ethheader; - guint8 tmpbuf[18]; - guint caplen, len; + uint8_t tmpbuf[18]; + unsigned caplen, len; if (object_length < (data_start - block_start) + (int) sizeof(blf_ethernetframeheader_t)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: ETHERNET_FRAME: not enough bytes for ethernet frame header in object"); ws_debug("not enough bytes for ethernet frame header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, ðheader, sizeof(ethheader), err, err_info)) { ws_debug("not enough bytes for ethernet frame header in file"); - return FALSE; + return false; } fix_endianness_blf_ethernetframeheader(ðheader); @@ -1164,45 +1429,46 @@ blf_read_ethernetframe(blf_params_t *params, int *err, gchar **err_info, gint64 tmpbuf[15] = (ethheader.tci & 0x00ff); tmpbuf[16] = (ethheader.ethtype & 0xff00) >> 8; tmpbuf[17] = (ethheader.ethtype & 0x00ff); - ws_buffer_assure_space(params->buf, (gsize)18 + ethheader.payloadlength); - ws_buffer_append(params->buf, tmpbuf, (gsize)18); - caplen = ((guint32)18 + ethheader.payloadlength); - len = ((guint32)18 + ethheader.payloadlength); + ws_buffer_assure_space(params->buf, (size_t)18 + ethheader.payloadlength); + ws_buffer_append(params->buf, tmpbuf, (size_t)18); + caplen = ((uint32_t)18 + ethheader.payloadlength); + len = ((uint32_t)18 + ethheader.payloadlength); } else { tmpbuf[12] = (ethheader.ethtype & 0xff00) >> 8; tmpbuf[13] = (ethheader.ethtype & 0x00ff); - ws_buffer_assure_space(params->buf, (gsize)14 + ethheader.payloadlength); - ws_buffer_append(params->buf, tmpbuf, (gsize)14); - caplen = ((guint32)14 + ethheader.payloadlength); - len = ((guint32)14 + ethheader.payloadlength); + ws_buffer_assure_space(params->buf, (size_t)14 + ethheader.payloadlength); + ws_buffer_append(params->buf, tmpbuf, (size_t)14); + caplen = ((uint32_t)14 + ethheader.payloadlength); + len = ((uint32_t)14 + ethheader.payloadlength); } if (!blf_read_bytes(params, data_start + sizeof(blf_ethernetframeheader_t), ws_buffer_end_ptr(params->buf), ethheader.payloadlength, err, err_info)) { ws_debug("copying ethernet frame failed"); - return FALSE; + return false; } params->buf->first_free += ethheader.payloadlength; blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_ETHERNET, ethheader.channel, UINT16_MAX, caplen, len); blf_add_direction_option(params, ethheader.direction); - return TRUE; + return true; } -static gboolean -blf_read_ethernetframe_ext(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_ethernetframe_ext(blf_params_t *params, int *err, char **err_info, int64_t block_start,int64_t data_start, + int64_t object_length, uint32_t flags, uint64_t object_timestamp, gboolean error) { blf_ethernetframeheader_ex_t ethheader; if (object_length < (data_start - block_start) + (int) sizeof(blf_ethernetframeheader_ex_t)) { *err = WTAP_ERR_BAD_FILE; - *err_info = ws_strdup_printf("blf: ETHERNET_FRAME_EX: not enough bytes for ethernet frame header in object"); + *err_info = ws_strdup_printf("blf: %s: not enough bytes for ethernet frame header in object", error ? "ETHERNET_ERROR_EX" : "ETHERNET_FRAME_EX"); ws_debug("not enough bytes for ethernet frame header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, ðheader, sizeof(blf_ethernetframeheader_ex_t), err, err_info)) { ws_debug("not enough bytes for ethernet frame header in file"); - return FALSE; + return false; } fix_endianness_blf_ethernetframeheader_ex(ðheader); @@ -1210,40 +1476,89 @@ blf_read_ethernetframe_ext(blf_params_t *params, int *err, gchar **err_info, gin if (object_length - (data_start - block_start) - sizeof(blf_ethernetframeheader_ex_t) < ethheader.frame_length) { *err = WTAP_ERR_BAD_FILE; - *err_info = ws_strdup_printf("blf: ETHERNET_FRAME_EX: frame too short"); + *err_info = ws_strdup_printf("blf: %s: frame too short", error ? "ETHERNET_ERROR_EX" : "ETHERNET_FRAME_EX"); ws_debug("frame too short"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start + sizeof(blf_ethernetframeheader_ex_t), ws_buffer_start_ptr(params->buf), ethheader.frame_length, err, err_info)) { ws_debug("copying ethernet frame failed"); - return FALSE; + return false; + } + + if (ethheader.flags & BLF_ETHERNET_EX_HARDWARECHANNEL) { + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_ETHERNET, ethheader.channel, ethheader.hw_channel, ethheader.frame_length, ethheader.frame_length); + wtap_block_add_uint32_option(params->rec->block, OPT_PKT_QUEUE, ethheader.hw_channel); + } + else { + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_ETHERNET, ethheader.channel, UINT16_MAX, ethheader.frame_length, ethheader.frame_length); + } + + blf_add_direction_option(params, ethheader.direction); + + return true; +} + +static bool +blf_read_ethernet_rxerror(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { + blf_ethernet_rxerror_t ethheader; + + if (object_length < (data_start - block_start) + (int)sizeof(blf_ethernet_rxerror_t)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: ETHERNET_RXERROR: not enough bytes for ethernet frame header in object"); + ws_debug("not enough bytes for ethernet rx error header in object"); + return false; } - blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_ETHERNET, ethheader.channel, ethheader.hw_channel, ethheader.frame_length, ethheader.frame_length); - wtap_block_add_uint32_option(params->rec->block, OPT_PKT_QUEUE, ethheader.hw_channel); + if (!blf_read_bytes(params, data_start, ðheader, sizeof(blf_ethernet_rxerror_t), err, err_info)) { + ws_debug("not enough bytes for ethernet rx error header in file"); + return false; + } + fix_endianness_blf_ethernet_rxerror(ðheader); + + ws_buffer_assure_space(params->buf, ethheader.frame_length); + + if (object_length - (data_start - block_start) < ethheader.frame_length) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: ETHERNET_RXERROR: frame too short"); + ws_debug("frame too short"); + return false; + } + + if (!blf_read_bytes(params, data_start + sizeof(blf_ethernet_rxerror_t), ws_buffer_start_ptr(params->buf), ethheader.frame_length, err, err_info)) { + ws_debug("copying ethernet rx error failed"); + return false; + } + + if (ethheader.hw_channel != 0) { /* In this object type, a value of 0 is considered invalid. */ + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_ETHERNET, ethheader.channel, ethheader.hw_channel, ethheader.frame_length, ethheader.frame_length); + wtap_block_add_uint32_option(params->rec->block, OPT_PKT_QUEUE, ethheader.hw_channel); + } + else { + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_ETHERNET, ethheader.channel, UINT16_MAX, ethheader.frame_length, ethheader.frame_length); + } blf_add_direction_option(params, ethheader.direction); - return TRUE; + return true; } /* * XXX - provide radio information to our caller in the pseudo-header. */ -static gboolean -blf_read_wlanframe(blf_params_t* params, int* err, gchar** err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_wlanframe(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { blf_wlanframeheader_t wlanheader; if (object_length < (data_start - block_start) + (int)sizeof(blf_wlanframeheader_t)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: WLAN_FRAME: not enough bytes for wlan frame header in object"); ws_debug("not enough bytes for wlan frame header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &wlanheader, sizeof(blf_wlanframeheader_t), err, err_info)) { ws_debug("not enough bytes for wlan frame header in file"); - return FALSE; + return false; } fix_endianness_blf_wlanframeheader(&wlanheader); @@ -1253,28 +1568,28 @@ blf_read_wlanframe(blf_params_t* params, int* err, gchar** err_info, gint64 bloc *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: WLAN_FRAME: frame too short"); ws_debug("frame too short"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start + sizeof(blf_wlanframeheader_t), ws_buffer_start_ptr(params->buf), wlanheader.frame_length, err, err_info)) { ws_debug("copying wlan frame failed"); - return FALSE; + return false; } blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_IEEE_802_11, wlanheader.channel, UINT16_MAX, wlanheader.frame_length, wlanheader.frame_length); blf_add_direction_option(params, wlanheader.direction); - return TRUE; + return true; } -static guint8 can_dlc_to_length[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8 }; -static guint8 canfd_dlc_to_length[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64 }; +static uint8_t can_dlc_to_length[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8 }; +static uint8_t canfd_dlc_to_length[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64 }; -static gboolean -blf_can_fill_buf_and_rec(blf_params_t *params, int *err, gchar **err_info, guint32 canid, guint8 payload_length, guint8 payload_length_valid, guint64 start_position, - guint32 flags, guint64 object_timestamp, guint16 channel, guint8 canfd_flags) { - guint8 tmpbuf[8]; - guint caplen, len; +static bool +blf_can_fill_buf_and_rec(blf_params_t *params, int *err, char **err_info, uint32_t canid, uint8_t payload_length, uint8_t payload_length_valid, uint64_t start_position, + uint32_t flags, uint64_t object_timestamp, uint16_t channel, uint8_t canfd_flags) { + uint8_t tmpbuf[8]; + unsigned caplen, len; tmpbuf[0] = (canid & 0xff000000) >> 24; tmpbuf[1] = (canid & 0x00ff0000) >> 16; @@ -1292,34 +1607,34 @@ blf_can_fill_buf_and_rec(blf_params_t *params, int *err, gchar **err_info, guint if (payload_length_valid > 0 && !blf_read_bytes(params, start_position, ws_buffer_end_ptr(params->buf), payload_length_valid, err, err_info)) { ws_debug("copying can payload failed"); - return FALSE; + return false; } params->buf->first_free += payload_length_valid; blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_SOCKETCAN, channel, UINT16_MAX, caplen, len); - return TRUE; + return true; } -static gboolean -blf_read_canmessage(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp, gboolean can_message2) { +static bool +blf_read_canmessage(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, bool can_message2) { blf_canmessage_t canheader; blf_canmessage2_trailer_t can2trailer; - guint32 canid; - guint8 payload_length; + uint32_t canid; + uint8_t payload_length; if (object_length < (data_start - block_start) + (int) sizeof(canheader)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: %s: not enough bytes for can header in object", can_message2 ? "CAN_MESSAGE2" : "CAN_MESSAGE"); ws_debug("not enough bytes for can header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &canheader, sizeof(canheader), err, err_info)) { ws_debug("not enough bytes for can header in file"); - return FALSE; + return false; } fix_endianness_blf_canmessage(&canheader); @@ -1339,7 +1654,7 @@ blf_read_canmessage(blf_params_t *params, int *err, gchar **err_info, gint64 blo } if (!blf_can_fill_buf_and_rec(params, err, err_info, canid, payload_length, payload_length, data_start + sizeof(canheader), flags, object_timestamp, canheader.channel, 0)) { - return FALSE; + return false; } /* actually, we do not really need the data, right now.... */ @@ -1348,40 +1663,40 @@ blf_read_canmessage(blf_params_t *params, int *err, gchar **err_info, gint64 blo *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: CAN_MESSAGE2: not enough bytes for can message 2 trailer"); ws_debug("not enough bytes for can message 2 trailer"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start + sizeof(canheader) + 8, &can2trailer, sizeof(can2trailer), err, err_info)) { ws_debug("not enough bytes for can message 2 trailer in file"); - return FALSE; + return false; } fix_endianness_blf_canmessage2_trailer(&can2trailer); } blf_add_direction_option(params, (canheader.flags & BLF_CANMESSAGE_FLAG_TX) == BLF_CANMESSAGE_FLAG_TX ? BLF_DIR_TX: BLF_DIR_RX); - return TRUE; + return true; } -static gboolean -blf_read_canfdmessage(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_canfdmessage(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { blf_canfdmessage_t canheader; - gboolean canfd; - guint32 canid; - guint8 payload_length; - guint8 payload_length_valid; - guint8 canfd_flags; + bool canfd; + uint32_t canid; + uint8_t payload_length; + uint8_t payload_length_valid; + uint8_t canfd_flags; if (object_length < (data_start - block_start) + (int) sizeof(canheader)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: CAN_FD_MESSAGE: not enough bytes for canfd header in object"); ws_debug("not enough bytes for canfd header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &canheader, sizeof(canheader), err, err_info)) { ws_debug("not enough bytes for canfd header in file"); - return FALSE; + return false; } fix_endianness_blf_canfdmessage(&canheader); @@ -1415,38 +1730,38 @@ blf_read_canfdmessage(blf_params_t *params, int *err, gchar **err_info, gint64 b if (payload_length_valid > object_length - (data_start - block_start) + sizeof(canheader)) { ws_debug("shortening can payload because buffer is too short!"); - payload_length_valid = (guint8)(object_length - (data_start - block_start)); + payload_length_valid = (uint8_t)(object_length - (data_start - block_start)); } if (!blf_can_fill_buf_and_rec(params, err, err_info, canid, payload_length, payload_length_valid, data_start + sizeof(canheader), flags, object_timestamp, canheader.channel, canfd_flags)) { - return FALSE; + return false; } blf_add_direction_option(params, (canheader.flags & BLF_CANMESSAGE_FLAG_TX) == BLF_CANMESSAGE_FLAG_TX ? BLF_DIR_TX : BLF_DIR_RX); - return TRUE; + return true; } -static gboolean -blf_read_canfdmessage64(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_canfdmessage64(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { blf_canfdmessage64_t canheader; - gboolean canfd; - guint32 canid; - guint8 payload_length; - guint8 payload_length_valid; - guint8 canfd_flags; + bool canfd; + uint32_t canid; + uint8_t payload_length; + uint8_t payload_length_valid; + uint8_t canfd_flags; if (object_length < (data_start - block_start) + (int) sizeof(canheader)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: CAN_FD_MESSAGE_64: not enough bytes for canfd header in object"); ws_debug("not enough bytes for canfd header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &canheader, sizeof(canheader), err, err_info)) { ws_debug("not enough bytes for canfd header in file"); - return FALSE; + return false; } fix_endianness_blf_canfdmessage64(&canheader); @@ -1480,35 +1795,35 @@ blf_read_canfdmessage64(blf_params_t *params, int *err, gchar **err_info, gint64 if (payload_length_valid > object_length - (data_start - block_start)) { ws_debug("shortening can payload because buffer is too short!"); - payload_length_valid = (guint8)(object_length - (data_start - block_start)); + payload_length_valid = (uint8_t)(object_length - (data_start - block_start)); } if (!blf_can_fill_buf_and_rec(params, err, err_info, canid, payload_length, payload_length_valid, data_start + sizeof(canheader), flags, object_timestamp, canheader.channel, canfd_flags)) { - return FALSE; + return false; } blf_add_direction_option(params, canheader.dir); - return TRUE; + return true; } -static gboolean -blf_read_canerror(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_canerror(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, bool overload) { blf_canerror_t canheader; - guint32 canid; - guint8 payload_length; - guint8 tmpbuf[16] = {0}; + uint32_t canid; + uint8_t payload_length; + uint8_t tmpbuf[16] = {0}; if (object_length < (data_start - block_start) + (int) sizeof(canheader)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: CAN_ERROR: not enough bytes for canerror header in object"); ws_debug("not enough bytes for canerror header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &canheader, sizeof(canheader), err, err_info)) { ws_debug("not enough bytes for canerror header in file"); - return FALSE; + return false; } fix_endianness_blf_canerror(&canheader); @@ -1518,6 +1833,11 @@ blf_read_canerror(blf_params_t *params, int *err, gchar **err_info, gint64 block // Fixed packet data length for socketcan error messages payload_length = CAN_ERR_DLC; + if (overload) { + tmpbuf[10] = CAN_ERR_PROT_OVERLOAD; + canid |= CAN_ERR_PROT; + } + tmpbuf[0] = (canid & 0xff000000) >> 24; tmpbuf[1] = (canid & 0x00ff0000) >> 16; tmpbuf[2] = (canid & 0x0000ff00) >> 8; @@ -1528,30 +1848,30 @@ blf_read_canerror(blf_params_t *params, int *err, gchar **err_info, gint64 block ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_SOCKETCAN, canheader.channel, UINT16_MAX, sizeof(tmpbuf), sizeof(tmpbuf)); - return TRUE; + return true; } -static gboolean -blf_read_canerrorext(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_canerrorext(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { blf_canerrorext_t canheader; - gboolean err_ack = false; - gboolean err_prot = false; - gboolean direction_tx; - guint32 canid; - guint8 payload_length; - guint8 tmpbuf[16] = {0}; + bool err_ack = false; + bool err_prot = false; + bool direction_tx; + uint32_t canid; + uint8_t payload_length; + uint8_t tmpbuf[16] = {0}; if (object_length < (data_start - block_start) + (int) sizeof(canheader)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: CAN_ERROR_EXT: not enough bytes for canerrorext header in object"); ws_debug("not enough bytes for canerrorext header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &canheader, sizeof(canheader), err, err_info)) { ws_debug("not enough bytes for canerrorext header in file"); - return FALSE; + return false; } fix_endianness_blf_canerrorext(&canheader); @@ -1617,30 +1937,30 @@ blf_read_canerrorext(blf_params_t *params, int *err, gchar **err_info, gint64 bl direction_tx = (canheader.errorCodeExt & BLF_CANERROREXT_EXTECC_TX) == BLF_CANERROREXT_EXTECC_TX; blf_add_direction_option(params, direction_tx ? BLF_DIR_TX: BLF_DIR_RX); } - return TRUE; + return true; } -static gboolean -blf_read_canfderror64(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_canfderror64(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { blf_canfderror64_t canheader; - gboolean err_ack = false; - gboolean err_prot = false; - gboolean direction_tx; - guint32 canid; - guint8 payload_length; - guint8 tmpbuf[16] = {0}; + bool err_ack = false; + bool err_prot = false; + bool direction_tx; + uint32_t canid; + uint8_t payload_length; + uint8_t tmpbuf[16] = {0}; if (object_length < (data_start - block_start) + (int) sizeof(canheader)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: CAN_FD_ERROR_64: not enough bytes for canfderror header in object"); ws_debug("not enough bytes for canfderror header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &canheader, sizeof(canheader), err, err_info)) { ws_debug("not enough bytes for canfderror header in file"); - return FALSE; + return false; } fix_endianness_blf_canfderror64(&canheader); @@ -1707,28 +2027,28 @@ blf_read_canfderror64(blf_params_t *params, int *err, gchar **err_info, gint64 b direction_tx = (canheader.errorCodeExt & BLF_CANERROREXT_EXTECC_TX) == BLF_CANERROREXT_EXTECC_TX; blf_add_direction_option(params, direction_tx ? BLF_DIR_TX: BLF_DIR_RX); } - return TRUE; + return true; } -static gboolean -blf_read_flexraydata(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_flexraydata(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { blf_flexraydata_t frheader; - guint8 payload_length; - guint8 payload_length_valid; - guint8 tmpbuf[7]; - guint caplen, len; + uint8_t payload_length; + uint8_t payload_length_valid; + uint8_t tmpbuf[7]; + unsigned caplen, len; if (object_length < (data_start - block_start) + (int) sizeof(frheader)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: FLEXRAY_DATA: not enough bytes for flexrayheader in object"); ws_debug("not enough bytes for flexrayheader in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &frheader, sizeof(frheader), err, err_info)) { ws_debug("not enough bytes for flexrayheader header in file"); - return FALSE; + return false; } fix_endianness_blf_flexraydata(&frheader); @@ -1741,7 +2061,7 @@ blf_read_flexraydata(blf_params_t *params, int *err, gchar **err_info, gint64 bl if (payload_length_valid > object_length - (data_start - block_start) - sizeof(frheader)) { ws_debug("shortening FlexRay payload because buffer is too short!"); - payload_length_valid = (guint8)(object_length - (data_start - block_start) - sizeof(frheader)); + payload_length_valid = (uint8_t)(object_length - (data_start - block_start) - sizeof(frheader)); } if (frheader.channel != 0 && frheader.channel != 1) { @@ -1772,35 +2092,35 @@ blf_read_flexraydata(blf_params_t *params, int *err, gchar **err_info, gint64 bl if (payload_length_valid > 0 && !blf_read_bytes(params, data_start + sizeof(frheader), ws_buffer_end_ptr(params->buf), payload_length_valid, err, err_info)) { ws_debug("copying flexray payload failed"); - return FALSE; + return false; } params->buf->first_free += payload_length_valid; blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_FLEXRAY, frheader.channel, UINT16_MAX, caplen, len); blf_add_direction_option(params, frheader.dir); - return TRUE; + return true; } -static gboolean -blf_read_flexraymessage(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_flexraymessage(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { blf_flexraymessage_t frheader; - guint8 payload_length; - guint8 payload_length_valid; - guint8 tmpbuf[7]; - guint caplen, len; + uint8_t payload_length; + uint8_t payload_length_valid; + uint8_t tmpbuf[7]; + unsigned caplen, len; if (object_length < (data_start - block_start) + (int) sizeof(frheader)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: FLEXRAY_MESSAGE: not enough bytes for flexrayheader in object"); ws_debug("not enough bytes for flexrayheader in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &frheader, sizeof(frheader), err, err_info)) { ws_debug("not enough bytes for flexrayheader header in file"); - return FALSE; + return false; } fix_endianness_blf_flexraymessage(&frheader); @@ -1813,7 +2133,7 @@ blf_read_flexraymessage(blf_params_t *params, int *err, gchar **err_info, gint64 if (payload_length_valid > object_length - (data_start - block_start) - sizeof(frheader)) { ws_debug("shortening FlexRay payload because buffer is too short!"); - payload_length_valid = (guint8)(object_length - (data_start - block_start) - sizeof(frheader)); + payload_length_valid = (uint8_t)(object_length - (data_start - block_start) - sizeof(frheader)); } if (frheader.channel != 0 && frheader.channel != 1) { @@ -1861,41 +2181,41 @@ blf_read_flexraymessage(blf_params_t *params, int *err, gchar **err_info, gint64 if (payload_length_valid > 0 && !blf_read_bytes(params, data_start + sizeof(frheader), ws_buffer_end_ptr(params->buf), payload_length_valid, err, err_info)) { ws_debug("copying flexray payload failed"); - return FALSE; + return false; } params->buf->first_free += payload_length_valid; blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_FLEXRAY, frheader.channel, UINT16_MAX, caplen, len); blf_add_direction_option(params, frheader.dir); - return TRUE; + return true; } -static gboolean -blf_read_flexrayrcvmessageex(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp, gboolean ext) { +static bool +blf_read_flexrayrcvmessageex(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, bool ext) { blf_flexrayrcvmessage_t frheader; - guint16 payload_length; - guint16 payload_length_valid; - guint8 tmpbuf[7]; - gint frheadersize = sizeof(frheader); - guint caplen, len; + uint16_t payload_length; + uint16_t payload_length_valid; + uint8_t tmpbuf[7]; + int frheadersize = sizeof(frheader); + unsigned caplen, len; if (ext) { frheadersize += 40; } - if ((gint64)object_length < (data_start - block_start) + frheadersize) { + if ((int64_t)object_length < (data_start - block_start) + frheadersize) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: %s: not enough bytes for flexrayheader in object", ext ? "FLEXRAY_RCVMESSAGE_EX" : "FLEXRAY_RCVMESSAGE"); ws_debug("not enough bytes for flexrayheader in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, &frheader, sizeof(frheader), err, err_info)) { ws_debug("not enough bytes for flexrayheader header in file"); - return FALSE; + return false; } fix_endianness_blf_flexrayrcvmessage(&frheader); @@ -1913,7 +2233,7 @@ blf_read_flexrayrcvmessageex(blf_params_t *params, int *err, gchar **err_info, g if (payload_length_valid > object_length - (data_start - block_start) - frheadersize) { ws_debug("shortening FlexRay payload because buffer is too short!"); - payload_length_valid = (guint8)(object_length - (data_start - block_start) - frheadersize); + payload_length_valid = (uint8_t)(object_length - (data_start - block_start) - frheadersize); } /* Measurement Header */ @@ -1958,33 +2278,33 @@ blf_read_flexrayrcvmessageex(blf_params_t *params, int *err, gchar **err_info, g if (payload_length_valid > 0 && !blf_read_bytes(params, data_start + frheadersize, ws_buffer_end_ptr(params->buf), payload_length_valid, err, err_info)) { ws_debug("copying flexray payload failed"); - return FALSE; + return false; } params->buf->first_free += payload_length_valid; blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_FLEXRAY, frheader.channelMask, UINT16_MAX, caplen, len); blf_add_direction_option(params, frheader.dir); - return TRUE; + return true; } -static gboolean -blf_read_linmessage(blf_params_t* params, int* err, gchar** err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_linmessage(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, bool crc_error) { blf_linmessage_t linmessage; - guint8 payload_length; - guint len; + uint8_t payload_length; + unsigned len; if (object_length < (data_start - block_start) + (int)sizeof(linmessage)) { *err = WTAP_ERR_BAD_FILE; - *err_info = ws_strdup_printf("blf: LIN_MESSAGE: not enough bytes for linmessage in object"); - ws_debug("not enough bytes for linmessage in object"); - return FALSE; + *err_info = ws_strdup_printf("blf: %s: not enough bytes for %s in object", crc_error ? "LIN_CRC_ERROR" : "LIN_MESSAGE", crc_error ? "lincrcerror" : "linmessage"); + ws_debug("not enough bytes for %s in object", crc_error ? "lincrcerror" : "linmessage"); + return false; } if (!blf_read_bytes(params, data_start, &linmessage, sizeof(linmessage), err, err_info)) { - ws_debug("not enough bytes for linmessage in file"); - return FALSE; + ws_debug("not enough bytes for %s in file", crc_error ? "lincrcerror" : "linmessage"); + return false; } fix_endianness_blf_linmessage(&linmessage); @@ -1993,16 +2313,20 @@ blf_read_linmessage(blf_params_t* params, int* err, gchar** err_info, gint64 blo payload_length = MIN(linmessage.dlc, 8); - guint8 tmpbuf[8]; + uint8_t tmpbuf[8]; tmpbuf[0] = 1; /* message format rev = 1 */ tmpbuf[1] = 0; /* reserved */ tmpbuf[2] = 0; /* reserved */ tmpbuf[3] = 0; /* reserved */ - tmpbuf[4] = (linmessage.dlc << 4) | 0; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ - tmpbuf[5] = linmessage.id; /* parity (2bit) | id (6bit) */ - tmpbuf[6] = (guint8)(linmessage.crc & 0xff); /* checksum */ + tmpbuf[4] = linmessage.dlc << 4; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + tmpbuf[5] = linmessage.id; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = (uint8_t)(linmessage.crc & 0xff); /* checksum */ tmpbuf[7] = 0; /* errors */ + if (crc_error) { + tmpbuf[7] |= 0x08; + } + ws_buffer_assure_space(params->buf, sizeof(tmpbuf) + payload_length); ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); ws_buffer_append(params->buf, linmessage.data, payload_length); @@ -2011,11 +2335,879 @@ blf_read_linmessage(blf_params_t* params, int* err, gchar** err_info, gint64 blo blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linmessage.channel, UINT16_MAX, len, len); blf_add_direction_option(params, linmessage.dir); - return TRUE; + return true; +} + +static bool +blf_read_linrcverror(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { + blf_linrcverror_t linmessage; + + if (object_length < (data_start - block_start) + (int)sizeof(linmessage)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_RCV_ERROR: not enough bytes for linrcverror in object"); + ws_debug("not enough bytes for linrcverror in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linmessage, sizeof(linmessage), err, err_info)) { + ws_debug("not enough bytes for linrcverror in file"); + return false; + } + linmessage.channel = GUINT16_FROM_LE(linmessage.channel); + + linmessage.dlc &= 0x0f; + linmessage.id &= 0x3f; + + uint8_t tmpbuf[8]; + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = linmessage.dlc << 4; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + tmpbuf[5] = linmessage.id; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = 0; /* checksum */ + /* XXX - This object can represent many different error types. + * For now we always treat it as framing error, + * but in the future we should expand it. */ + tmpbuf[7] = 0x02; /* errors */ + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf)); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linmessage.channel, UINT16_MAX, sizeof(tmpbuf), sizeof(tmpbuf)); + + return true; +} + +static bool +blf_read_linsenderror(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { + blf_linsenderror_t linmessage; + + if (object_length < (data_start - block_start) + (int)sizeof(linmessage)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_SND_ERROR: not enough bytes for linsenderror in object"); + ws_debug("not enough bytes for linsenderror in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linmessage, sizeof(linmessage), err, err_info)) { + ws_debug("not enough bytes for linsenderror in file"); + return false; + } + linmessage.channel = GUINT16_FROM_LE(linmessage.channel); + + linmessage.dlc &= 0x0f; + linmessage.id &= 0x3f; + + uint8_t tmpbuf[8]; + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = linmessage.dlc << 4; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + tmpbuf[5] = linmessage.id; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = 0; /* checksum */ + tmpbuf[7] = 0x01; /* errors */ + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf)); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linmessage.channel, UINT16_MAX, sizeof(tmpbuf), sizeof(tmpbuf)); + + return true; +} + +static bool +blf_read_linwakeupevent(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { + blf_linwakeupevent_t linevent; + + if (object_length < (data_start - block_start) + (int)sizeof(linevent)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_WAKEUP: not enough bytes for linwakeup in object"); + ws_debug("not enough bytes for linwakeup in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linevent, sizeof(linevent), err, err_info)) { + ws_debug("not enough bytes for linwakeup in file"); + return false; + } + linevent.channel = GUINT16_FROM_LE(linevent.channel); + + uint8_t tmpbuf[12]; /* LIN events have a fixed length of 12 bytes */ + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = 3 << 2; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + tmpbuf[5] = 0; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = 0; /* checksum */ + tmpbuf[7] = 0; /* errors */ + + /* Wake-up event */ + tmpbuf[8] = 0xB0; + tmpbuf[9] = 0xB0; + tmpbuf[10] = 0x00; + tmpbuf[11] = 0x04; + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf)); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linevent.channel, UINT16_MAX, sizeof(tmpbuf), sizeof(tmpbuf)); + + return true; +} + +static bool +blf_read_linmessage2(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, uint16_t object_version) { + blf_linmessage2_t linmessage; + + uint8_t payload_length; + unsigned len; + + if (object_length < (data_start - block_start) + (int)sizeof(linmessage)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_MESSAGE2: not enough bytes for linmessage2 in object"); + ws_debug("not enough bytes for linmessage2 in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linmessage, sizeof(linmessage), err, err_info)) { + ws_debug("not enough bytes for linmessage2 in file"); + return false; + } + fix_endianness_blf_linmessage2(&linmessage); + + linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc &= 0x0f; + linmessage.linDataByteTimestampEvent.linMessageDescriptor.id &= 0x3f; + + payload_length = MIN(linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc, 8); + + uint8_t tmpbuf[8]; + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc << 4; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + if (object_version >= 1) { /* The 'checksumModel' field is valid only if objectVersion >= 1 */ + switch (linmessage.linDataByteTimestampEvent.linMessageDescriptor.checksumModel) { + case 0: + tmpbuf[4] |= 1; /* Classic */ + break; + case 1: + tmpbuf[4] |= 2; /* Enhanced */ + break; + default: + break; + } + } + tmpbuf[5] = linmessage.linDataByteTimestampEvent.linMessageDescriptor.id; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = (uint8_t)(linmessage.crc & 0xff); /* checksum */ + tmpbuf[7] = 0; /* errors */ + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf) + payload_length); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + ws_buffer_append(params->buf, linmessage.data, payload_length); + len = sizeof(tmpbuf) + payload_length; + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linmessage.linDataByteTimestampEvent.linMessageDescriptor.linSynchFieldEvent.linBusEvent.channel, UINT16_MAX, len, len); + blf_add_direction_option(params, linmessage.dir); + + return true; +} + +static bool +blf_read_lincrcerror2(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, uint16_t object_version) { + blf_lincrcerror2_t linmessage; + + uint8_t payload_length; + unsigned len; + + if (object_length < (data_start - block_start) + (int)sizeof(linmessage)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_CRC_ERROR2: not enough bytes for lincrcerror2 in object"); + ws_debug("not enough bytes for lincrcerror2 in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linmessage, sizeof(linmessage), err, err_info)) { + ws_debug("not enough bytes for lincrcerror2 in file"); + return false; + } + fix_endianness_blf_lincrcerror2(&linmessage); + + linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc &= 0x0f; + linmessage.linDataByteTimestampEvent.linMessageDescriptor.id &= 0x3f; + + payload_length = MIN(linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc, 8); + + uint8_t tmpbuf[8]; + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc << 4; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + if (object_version >= 1) { /* The 'checksumModel' field is valid only if objectVersion >= 1 */ + switch (linmessage.linDataByteTimestampEvent.linMessageDescriptor.checksumModel) { + case 0: + tmpbuf[4] |= 1; /* Classic */ + break; + case 1: + tmpbuf[4] |= 2; /* Enhanced */ + break; + default: + break; + } + } + tmpbuf[5] = linmessage.linDataByteTimestampEvent.linMessageDescriptor.id; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = (uint8_t)(linmessage.crc & 0xff); /* checksum */ + tmpbuf[7] = 0x08; /* errors */ + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf) + payload_length); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + ws_buffer_append(params->buf, linmessage.data, payload_length); + len = sizeof(tmpbuf) + payload_length; + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linmessage.linDataByteTimestampEvent.linMessageDescriptor.linSynchFieldEvent.linBusEvent.channel, UINT16_MAX, len, len); + blf_add_direction_option(params, linmessage.dir); + + return true; +} + +static bool +blf_read_linrcverror2(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, uint16_t object_version) { + blf_linrcverror2_t linmessage; + + uint8_t payload_length; + unsigned len; + + if (object_length < (data_start - block_start) + (int)sizeof(linmessage)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_RCV_ERROR2: not enough bytes for linrcverror2 in object"); + ws_debug("not enough bytes for linrcverror2 in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linmessage, sizeof(linmessage), err, err_info)) { + ws_debug("not enough bytes for linrcverror2 in file"); + return false; + } + fix_endianness_blf_linrcverror2(&linmessage); + + linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc &= 0x0f; + linmessage.linDataByteTimestampEvent.linMessageDescriptor.id &= 0x3f; + + if (linmessage.hasDataBytes) { + payload_length = MIN(linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc, 8); + } + else { + payload_length = 0; + } + + uint8_t tmpbuf[8]; + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = linmessage.linDataByteTimestampEvent.linMessageDescriptor.dlc << 4; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + if (object_version >= 1) { /* The 'checksumModel' field is valid only if objectVersion >= 1 */ + switch (linmessage.linDataByteTimestampEvent.linMessageDescriptor.checksumModel) { + case 0: + tmpbuf[4] |= 1; /* Classic */ + break; + case 1: + tmpbuf[4] |= 2; /* Enhanced */ + break; + default: + break; + } + } + tmpbuf[5] = linmessage.linDataByteTimestampEvent.linMessageDescriptor.id; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = 0; /* checksum */ + /* XXX - This object can represent many different error types. + * For now we always treat it as framing error, + * but in the future we should expand it. */ + tmpbuf[7] = 0x02; /* errors */ + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf) + payload_length); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + if (payload_length > 0) { + ws_buffer_append(params->buf, linmessage.data, payload_length); + } + len = sizeof(tmpbuf) + payload_length; + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linmessage.linDataByteTimestampEvent.linMessageDescriptor.linSynchFieldEvent.linBusEvent.channel, UINT16_MAX, len, len); + + return true; +} + +static bool +blf_read_linsenderror2(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, uint16_t object_version) { + blf_linsenderror2_t linmessage; + + if (object_length < (data_start - block_start) + (int)sizeof(linmessage)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_SND_ERROR2: not enough bytes for linsenderror2 in object"); + ws_debug("not enough bytes for linsenderror2 in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linmessage, sizeof(linmessage), err, err_info)) { + ws_debug("not enough bytes for linsenderror2 in file"); + return false; + } + fix_endianness_blf_linsenderror2(&linmessage); + + linmessage.linMessageDescriptor.dlc &= 0x0f; + linmessage.linMessageDescriptor.id &= 0x3f; + + uint8_t tmpbuf[8]; + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = linmessage.linMessageDescriptor.dlc << 4; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + if (object_version >= 1) { /* The 'checksumModel' field is valid only if objectVersion >= 1 */ + switch (linmessage.linMessageDescriptor.checksumModel) { + case 0: + tmpbuf[4] |= 1; /* Classic */ + break; + case 1: + tmpbuf[4] |= 2; /* Enhanced */ + break; + default: + break; + } + } + tmpbuf[5] = linmessage.linMessageDescriptor.id; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = 0; /* checksum */ + tmpbuf[7] = 0x01; /* errors */ + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf)); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linmessage.linMessageDescriptor.linSynchFieldEvent.linBusEvent.channel, UINT16_MAX, sizeof(tmpbuf), sizeof(tmpbuf)); + + return true; +} + +static bool +blf_read_linwakeupevent2(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { + blf_linwakeupevent2_t linevent; + + if (object_length < (data_start - block_start) + (int)sizeof(linevent)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_WAKEUP2: not enough bytes for linwakeup2 in object"); + ws_debug("not enough bytes for linwakeup2 in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linevent, sizeof(linevent), err, err_info)) { + ws_debug("not enough bytes for linwakeup2 in file"); + return false; + } + fix_endianness_blf_linwakeupevent2(&linevent); + + uint8_t tmpbuf[12]; /* LIN events have a fixed length of 12 bytes */ + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = 3 << 2; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + tmpbuf[5] = 0; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = 0; /* checksum */ + tmpbuf[7] = 0; /* errors */ + + /* Wake-up event */ + tmpbuf[8] = 0xB0; + tmpbuf[9] = 0xB0; + tmpbuf[10] = 0x00; + tmpbuf[11] = 0x04; + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf)); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linevent.linBusEvent.channel, UINT16_MAX, sizeof(tmpbuf), sizeof(tmpbuf)); + + return true; +} + +static bool +blf_read_linsleepmodeevent(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { + blf_linsleepmodeevent_t linevent; + + if (object_length < (data_start - block_start) + (int)sizeof(linevent)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: LIN_SLEEP: not enough bytes for linsleep in object"); + ws_debug("not enough bytes for linsleep in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, &linevent, sizeof(linevent), err, err_info)) { + ws_debug("not enough bytes for linsleep in file"); + return false; + } + linevent.channel = GUINT16_FROM_LE(linevent.channel); + + uint8_t tmpbuf[12]; /* LIN events have a fixed length of 12 bytes */ + tmpbuf[0] = 1; /* message format rev = 1 */ + tmpbuf[1] = 0; /* reserved */ + tmpbuf[2] = 0; /* reserved */ + tmpbuf[3] = 0; /* reserved */ + tmpbuf[4] = 3 << 2; /* dlc (4bit) | type (2bit) | checksum type (2bit) */ + tmpbuf[5] = 0; /* parity (2bit) | id (6bit) */ + tmpbuf[6] = 0; /* checksum */ + tmpbuf[7] = 0; /* errors */ + + switch (linevent.reason) { + case BLF_LIN_SLEEP_REASON_GO_TO_SLEEP_FRAME: + /* Go-to-Sleep event by Go-to-Sleep frame */ + tmpbuf[8] = 0xB0; + tmpbuf[9] = 0xB0; + tmpbuf[10] = 0x00; + tmpbuf[11] = 0x01; + break; + case BLF_LIN_SLEEP_REASON_BUS_IDLE_TIMEOUT: + case BLF_LIN_SLEEP_REASON_SILENT_SLEEPMODE_CMD: + /* Go-to-Sleep event by Inactivity for more than 4s */ + tmpbuf[8] = 0xB0; + tmpbuf[9] = 0xB0; + tmpbuf[10] = 0x00; + tmpbuf[11] = 0x02; + break; + case BLF_LIN_WU_REASON_EXTERNAL_WAKEUP_SIG: + case BLF_LIN_WU_REASON_INTERNAL_WAKEUP_SIG: + case BLF_LIN_WU_REASON_BUS_TRAFFIC: /* There's no "wake-up by bus traffic" event in the LIN packet. */ + /* Wake-up event by Wake-up signal */ + tmpbuf[8] = 0xB0; + tmpbuf[9] = 0xB0; + tmpbuf[10] = 0x00; + tmpbuf[11] = 0x04; + break; + case BLF_LIN_WU_SLEEP_REASON_START_STATE: + case BLF_LIN_NO_SLEEP_REASON_BUS_TRAFFIC: + /* If we're just reporting on the initial state, + * or the interface doesn't want to go to sleep, + * report the current state as "event". */ + if (linevent.flags & 0x2) { + /* Wake-up event by Wake-up signal */ + tmpbuf[8] = 0xB0; + tmpbuf[9] = 0xB0; + tmpbuf[10] = 0x00; + tmpbuf[11] = 0x04; + } + else { + /* Go-to-Sleep event by Inactivity for more than 4s */ + tmpbuf[8] = 0xB0; + tmpbuf[9] = 0xB0; + tmpbuf[10] = 0x00; + tmpbuf[11] = 0x02; + } + break; + default: + tmpbuf[8] = 0x00; + tmpbuf[9] = 0x00; + tmpbuf[10] = 0x00; + tmpbuf[11] = 0x00; + break; + } + + ws_buffer_assure_space(params->buf, sizeof(tmpbuf)); + ws_buffer_append(params->buf, tmpbuf, sizeof(tmpbuf)); + + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_LIN, linevent.channel, UINT16_MAX, sizeof(tmpbuf), sizeof(tmpbuf)); + + return true; +} + +uint16_t blf_get_xml_channel_number(const char* start, const char* end) { + char* text; + size_t len; + uint16_t res; + + if (start == NULL || end == NULL || end <= start) { + return UINT16_MAX; + } + + len = (size_t)(end - start); + text = g_try_malloc(len + 1); /* Accommodate '\0' */ + if (text == NULL) { + ws_debug("cannot allocate memory"); + return UINT16_MAX; + } + memcpy(text, start, len); + text[len] = '\0'; + + if (!ws_strtou16(text, NULL, &res)) { + res = UINT16_MAX; + } + + g_free(text); + return res; +} + +char* blf_get_xml_channel_name(const char* start, const char* end) { + char* text; + size_t len; + + if (start == NULL || end == NULL || end <= start) { + return NULL; + } + + len = (size_t)(end - start); + text = g_try_malloc(len + 1); /* Accommodate '\0' */ + if (text == NULL) { + ws_debug("cannot allocate memory"); + return NULL; + } + memcpy(text, start, len); + text[len] = '\0'; + + return text; +} + +bool blf_parse_xml_port(const char* start, const char* end, char** name, uint16_t* hwchannel, bool* simulated) { + static const char name_magic[] = "name="; + static const char hwchannel_magic[] = "hwchannel="; + static const char simulated_magic[] = "simulated="; + + char* text; + size_t len; + char** tokens; + char* token; + + if (start == NULL || end == NULL || name == NULL || end <= start) { + return false; + } + + len = (size_t)(end - start); + text = g_try_malloc(len + 1); /* Accommodate '\0' */ + if (text == NULL) { + ws_debug("cannot allocate memory"); + return false; + } + memcpy(text, start, len); + text[len] = '\0'; + + tokens = g_strsplit_set(text, ";", -1); + g_free(text); + if (tokens == NULL) { + ws_debug("cannot split XML port data"); + return false; + } + + *name = NULL; + *hwchannel = UINT16_MAX; + *simulated = false; + + for (int i = 0; tokens[i] != NULL; i++) { + token = tokens[i]; + if (strncmp(token, name_magic, strlen(name_magic)) == 0) { + if (*name == NULL) { /* Avoid memory leak in case of malformed string */ + *name = ws_strdup(token + strlen(name_magic)); + } + } + else if (strncmp(token, hwchannel_magic, strlen(hwchannel_magic)) == 0) { + if (!ws_strtou16(token + strlen(hwchannel_magic), NULL, hwchannel)) { + *hwchannel = UINT16_MAX; + } + } + else if (strncmp(token, simulated_magic, strlen(simulated_magic)) == 0) { + if (strlen(token) > strlen(simulated_magic) && token[strlen(simulated_magic)] != '0') { + *simulated = true; /* TODO: Find a way to use this information */ + } + } + } + + g_strfreev(tokens); + + return true; +} + +int blf_get_xml_pkt_encap(const char* start, const char* end) { + size_t len; + + if (start == NULL || end == NULL || end <= start) { + return 0; + } + + len = (size_t)(end - start); + + if (strncmp(start, "CAN", len) == 0) { + return WTAP_ENCAP_SOCKETCAN; + } + if (strncmp(start, "FlexRay", len) == 0) { + return WTAP_ENCAP_FLEXRAY; + } + if (strncmp(start, "LIN", len) == 0) { + return WTAP_ENCAP_LIN; + } + if (strncmp(start, "Ethernet", len) == 0) { + return WTAP_ENCAP_ETHERNET; + } + if (strncmp(start, "WLAN", len) == 0) { /* Not confirmed with a real capture */ + return WTAP_ENCAP_IEEE_802_11; + } + + return 0xffffffff; +} + +/** Finds a NULL-terminated string in a block of memory. + * + * 'start' points to the first byte of the block of memory. + * 'end' points to the first byte after the end of the block of memory, + * so that the size of the block is end-start. + * 'str' is a NULL-terminated string. + */ +const char* blf_strmem(const char* start, const char* end, const char* str) { + if (start == NULL || end == NULL || str == NULL || end <= start) { + return NULL; + } + + return ws_memmem(start, end - start, str, strlen(str)); +} + +/** Extracts the channel and port names from a channels XML. + * + * A sample channels XML looks like this: + * + * <?xml version="1.0" encoding="UTF-8"?> + * <channels version="1"> + * <channel number="1" type="CAN" network="CAN01"> + * <databases> + * <database file="DB.arxml" path="C:\...\" cluster="CAN01" /> + * <database file="DB.dbc" path="C:\...\" cluster="General" /> + * </databases> + * </channel> + * <channel number="1" type="LIN" network="LIN01"> + * <databases> + * <database file="DB.dbc" path="C:\...\" cluster="General" /> + * <database file="DB.ldf" path="C:\...\" cluster="LIN01" /> + * </databases> + * </channel> + * <channel number="1" type="Ethernet" network="ETH01"> + * <databases> + * <database file="DB.dbc" path="C:\...\" cluster="General" /> + * </databases> + * <channel_properties> + * <elist name="ports"> + * <eli name="port">name=Port1;hwchannel=11;simulated=1</eli> + * <eli name="port">name=Port2;hwchannel=12;simulated=0</eli> + * </elist> + * </channel_properties> + * </channel> + * </channels> + */ +static bool +blf_set_xml_channels(blf_params_t* params, const char* text, size_t len) { + static const char xml_magic[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; + static const char channels_start_magic[] = "<channels "; + static const char channels_end_magic[] = "</channels>"; + static const char channel_start_magic[] = "<channel "; + static const char channel_end_magic[] = "</channel>"; + static const char number_start_magic[] = "number=\""; + static const char number_end_magic[] = "\""; + static const char type_start_magic[] = "type=\""; + static const char type_end_magic[] = "\""; + static const char network_start_magic[] = "network=\""; + static const char network_end_magic[] = "\""; + static const char ports_start_magic[] = "<elist name=\"ports\">"; + static const char ports_end_magic[] = "</elist>"; + static const char port_start_magic[] = "<eli name=\"port\">"; + static const char port_end_magic[] = "</eli>"; + + const char* xml_start; + const char* channels_start; + const char* channels_end; + const char* channel_start; + const char* channel_end; + const char* number_start; + const char* number_end; + const char* type_start; + const char* type_end; + const char* network_start; + const char* network_end; + const char* ports_start; + const char* ports_end; + const char* port_start; + const char* port_end; + + const char* search_start; + bool res; + + int pkt_encap; + uint16_t channel; + uint16_t hwchannel = UINT16_MAX; + char* channel_name = NULL; + char* port_name = NULL; + bool simulated = false; + char* iface_name = NULL; + + if (text == NULL || len < strlen(xml_magic)) { + return false; + } + + xml_start = blf_strmem(text, text + len, xml_magic); + if (xml_start == NULL) { + ws_debug("no valid xml magic found"); + return false; + } + search_start = xml_start + strlen(xml_magic); + + channels_start = blf_strmem(search_start, text + len, channels_start_magic); + channels_end = blf_strmem(search_start, text + len, channels_end_magic); + if (channels_start == NULL || channels_end == NULL || channels_end <= channels_start + strlen(channels_start_magic)) { + ws_debug("no channels tag found in xml"); + return false; + } + search_start = channels_start + strlen(channels_start_magic); + + while (search_start < channels_end) { + channel_start = blf_strmem(search_start, channels_end, channel_start_magic); + search_start = search_start + strlen(channel_start_magic); + channel_end = blf_strmem(search_start, channels_end, channel_end_magic); + if (channel_start == NULL || channel_end == NULL || channel_end <= channel_start + strlen(channel_start_magic)) { + ws_debug("found end of channel list"); + return true; + } + + number_start = blf_strmem(channel_start, channel_end, number_start_magic); + if (number_start == NULL) { + ws_debug("channel without number found in xml"); + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + number_end = blf_strmem(number_start + strlen(number_start_magic), channel_end, number_end_magic); + if (number_end == NULL) { + ws_debug("channel with malformed number attribute found in xml"); + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + channel = blf_get_xml_channel_number(number_start + strlen(number_start_magic), number_end); + if (channel == UINT16_MAX) { + ws_debug("invalid channel number found in xml"); + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + type_start = blf_strmem(channel_start, channel_end, type_start_magic); + if (type_start == NULL) { + ws_debug("channel without type found in xml"); + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + type_end = blf_strmem(type_start + strlen(type_start_magic), channel_end, type_end_magic); + if (type_end == NULL) { + ws_debug("channel with malformed type attribute found in xml"); + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + pkt_encap = blf_get_xml_pkt_encap(type_start + strlen(type_start_magic), type_end); + + network_start = blf_strmem(channel_start, channel_end, network_start_magic); + if (network_start == NULL) { + ws_debug("channel without name found in xml"); + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + network_end = blf_strmem(network_start + strlen(network_start_magic), channel_end, network_end_magic); + if (network_end == NULL) { + ws_debug("channel with malformed network attribute found in xml"); + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + channel_name = blf_get_xml_channel_name(network_start + strlen(network_start_magic), network_end); + if (channel_name == NULL || strlen(channel_name) == 0) { + ws_debug("channel with empty name found in xml"); + if (channel_name) { + g_free(channel_name); + channel_name = NULL; + } + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + ws_debug("Found channel in XML: PKT_ENCAP: %d, ID: %u, name: %s", pkt_encap, channel, channel_name); + blf_prepare_interface_name(params, pkt_encap, channel, UINT16_MAX, channel_name, true); + + search_start = MAX(MAX(number_end + strlen(number_end_magic), type_end + strlen(type_end_magic)), network_end + strlen(network_end_magic)); + + ports_start = blf_strmem(search_start, channel_end, ports_start_magic); + if (ports_start == NULL) { + /* Not an error, channel has no ports */ + if (channel_name) { + g_free(channel_name); + channel_name = NULL; + } + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + search_start = ports_start + strlen(ports_start_magic); + + ports_end = blf_strmem(search_start, channel_end, ports_end_magic); + if (ports_end == NULL) { + ws_debug("channel with malformed ports tag found in xml"); + if (channel_name) { + g_free(channel_name); + channel_name = NULL; + } + search_start = channel_end + strlen(channel_end_magic); + continue; + } + + while (search_start < ports_end) { + port_start = blf_strmem(search_start, ports_end, port_start_magic); + port_end = blf_strmem(search_start + strlen(port_start_magic), ports_end, port_end_magic); + if (port_start == NULL || port_end == NULL || port_end <= port_start + strlen(port_start_magic)) { + ws_debug("found end of ports list"); + search_start = ports_end + strlen(ports_end_magic); + continue; + } + + res = blf_parse_xml_port(port_start + strlen(port_start_magic), port_end, &port_name, &hwchannel, &simulated); + if (!res || port_name == NULL || hwchannel == UINT16_MAX) { + if (port_name) { + g_free(port_name); + port_name = NULL; + } + ws_debug("port with missing or malformed info found in xml"); + search_start = port_end + strlen(port_end_magic); + continue; + } + + iface_name = ws_strdup_printf("%s::%s", channel_name, port_name); + ws_debug("Found channel in XML: PKT_ENCAP: %d, ID: %u, HW ID: %u, name: %s", pkt_encap, channel, hwchannel, iface_name); + blf_prepare_interface_name(params, pkt_encap, channel, hwchannel, iface_name, true); + g_free(iface_name); + + if (port_name) { + g_free(port_name); + port_name = NULL; + } + + search_start = port_end + strlen(port_end_magic); + } + + if (channel_name) { + g_free(channel_name); + channel_name = NULL; + } + + search_start = channel_end + strlen(channel_end_magic); + } + + return true; } static int -blf_read_apptextmessage(blf_params_t *params, int *err, gchar **err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +blf_read_apptextmessage(blf_params_t *params, int *err, char **err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, size_t metadata_cont) { blf_apptext_t apptextheader; if (object_length < (data_start - block_start) + (int)sizeof(apptextheader)) { @@ -2031,8 +3223,16 @@ blf_read_apptextmessage(blf_params_t *params, int *err, gchar **err_info, gint64 } fix_endianness_blf_apptext_header(&apptextheader); + if (metadata_cont && apptextheader.source != BLF_APPTEXT_METADATA) { + /* If we're in the middle of a sequence of metadata objects, + * but we get an AppText object from another source, + * skip the previously incomplete object and start fresh. + */ + metadata_cont = 0; + } + /* Add an extra byte for a terminating '\0' */ - gchar* text = g_try_malloc((gsize)apptextheader.textLength + 1); + char* text = g_try_malloc((size_t)apptextheader.textLength + 1); if (!blf_read_bytes(params, data_start + sizeof(apptextheader), text, apptextheader.textLength, err, err_info)) { ws_debug("not enough bytes for apptext text in file"); @@ -2046,7 +3246,7 @@ blf_read_apptextmessage(blf_params_t *params, int *err, gchar **err_info, gint64 { /* returns a NULL terminated array of NULL terminates strings */ - gchar** tokens = g_strsplit_set(text, ";", -1); + char** tokens = g_strsplit_set(text, ";", -1); if (tokens == NULL || tokens[0] == NULL || tokens[1] == NULL) { if (tokens != NULL) { @@ -2056,7 +3256,7 @@ blf_read_apptextmessage(blf_params_t *params, int *err, gchar **err_info, gint64 return BLF_APPTEXT_CHANNEL; } - guint16 channel = (apptextheader.reservedAppText1 >> 8) & 0xff; + uint16_t channel = (apptextheader.reservedAppText1 >> 8) & 0xff; int pkt_encap; switch ((apptextheader.reservedAppText1 >> 16) & 0xff) { @@ -2082,64 +3282,113 @@ blf_read_apptextmessage(blf_params_t *params, int *err, gchar **err_info, gint64 default: pkt_encap = 0xffffffff; + break; } /* we use lookup to create interface, if not existing yet */ - blf_lookup_interface(params, pkt_encap, channel, UINT16_MAX, tokens[1]); + blf_prepare_interface_name(params, pkt_encap, channel, UINT16_MAX, tokens[1], false); g_strfreev(tokens); g_free(text); return BLF_APPTEXT_CHANNEL; - break; } case BLF_APPTEXT_METADATA: - case BLF_APPTEXT_COMMENT: - if (apptextheader.textLength < 5) { - /* Arbitrary length chosen */ - g_free(text); - return BLF_APPTEXT_CHANNEL; /* Cheat - no block to write */ + if (metadata_cont) { + /* Set the buffer pointer to the end of the previous object */ + params->buf->first_free = metadata_cont; + } + else { + /* First object of a sequence of one or more */ + wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_DISSECTOR_NAME, "data-text-lines"); + wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_COL_PROT_TEXT, "BLF App text"); + wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_COL_INFO_TEXT, "Metadata"); + wtap_buffer_append_epdu_end(params->buf); + } + + ws_buffer_assure_space(params->buf, apptextheader.textLength); + ws_buffer_append(params->buf, text, apptextheader.textLength); + g_free(text); + + if ((apptextheader.reservedAppText1 & 0x00ffffff) > apptextheader.textLength) { + /* Continues in the next object */ + return BLF_APPTEXT_CONT; + } + + if (((apptextheader.reservedAppText1 >> 24) & 0xff) == BLF_APPTEXT_XML_CHANNELS) { + blf_set_xml_channels(params, params->buf->data, ws_buffer_length(params->buf)); } + + /* Override the timestamp with 0 for metadata objects. Thay can only occur at the beginning of the file, and they usually alrady have a timestamp of 0. */ + blf_init_rec(params, 0, 0, WTAP_ENCAP_WIRESHARK_UPPER_PDU, 0, UINT16_MAX, (uint32_t)ws_buffer_length(params->buf), (uint32_t)ws_buffer_length(params->buf)); + return BLF_APPTEXT_METADATA; + case BLF_APPTEXT_COMMENT: + case BLF_APPTEXT_ATTACHMENT: + case BLF_APPTEXT_TRACELINE: + { wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_DISSECTOR_NAME, "data-text-lines"); wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_COL_PROT_TEXT, "BLF App text"); - if (apptextheader.source == BLF_APPTEXT_METADATA) { - wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_COL_INFO_TEXT, "Metadata"); - } else { - wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_COL_INFO_TEXT, "Comment"); + + char* info_line = NULL; + switch (apptextheader.source) { + case BLF_APPTEXT_COMMENT: + info_line = ws_strdup_printf("Comment: %s", text); + break; + case BLF_APPTEXT_ATTACHMENT: + info_line = ws_strdup_printf("Attachment: %s", text); + break; + case BLF_APPTEXT_TRACELINE: + info_line = ws_strdup_printf("Trace line%s: %s", (apptextheader.reservedAppText1 & 0x00000010) ? "" : " (hidden)", text); + break; + default: + break; } + wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_COL_INFO_TEXT, info_line); wtap_buffer_append_epdu_end(params->buf); - ws_buffer_assure_space(params->buf, apptextheader.textLength); /* The dissector doesn't need NULL-terminated strings */ - ws_buffer_append(params->buf, text, apptextheader.textLength); + size_t text_length = strlen(text); /* The string can contain '\0' before textLength bytes */ + ws_buffer_assure_space(params->buf, text_length); /* The dissector doesn't need NULL-terminated strings */ + ws_buffer_append(params->buf, text, text_length); /* We'll write this as a WS UPPER PDU packet with a text blob */ - blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_WIRESHARK_UPPER_PDU, 0, UINT16_MAX, (guint32)ws_buffer_length(params->buf), (guint32)ws_buffer_length(params->buf)); + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_WIRESHARK_UPPER_PDU, 0, UINT16_MAX, (uint32_t)ws_buffer_length(params->buf), (uint32_t)ws_buffer_length(params->buf)); g_free(text); + if (info_line) { + g_free(info_line); + } return apptextheader.source; - break; + } default: g_free(text); return BLF_APPTEXT_CHANNEL; /* Cheat - no block to write */; - break; } return BLF_APPTEXT_CHANNEL; /* Cheat - no block to write */ } -static gboolean -blf_read_ethernet_status(blf_params_t* params, int* err, gchar** err_info, gint64 block_start, gint64 data_start, gint64 object_length, guint32 flags, guint64 object_timestamp) { +static bool +blf_read_ethernet_status(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp, uint16_t object_version) { blf_ethernet_status_t ethernet_status_header; - guint8 tmpbuf[16]; + uint8_t tmpbuf[24]; + uint64_t linkUpDuration; - if (object_length < (data_start - block_start) + (int)sizeof(ethernet_status_header)) { + if (object_length < (data_start - block_start) + (int)sizeof(ethernet_status_header) + (int)(object_version >= 1 ? 8 : 0)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("blf: ETHERNET_STATUS: not enough bytes for ethernet status header in object"); ws_debug("not enough bytes for ethernet status header in object"); - return FALSE; + return false; } if (!blf_read_bytes(params, data_start, ðernet_status_header, sizeof(ethernet_status_header), err, err_info)) { ws_debug("not enough bytes for ethernet_status_header header in file"); - return FALSE; + return false; + } + + if (object_version >= 1) { + if (!blf_read_bytes(params, data_start + sizeof(ethernet_status_header), &linkUpDuration, 8, err, err_info)) { + ws_debug("not enough bytes for ethernet_status_header header in file"); + return false; + } + GUINT64_FROM_LE(linkUpDuration); } fix_endianness_blf_ethernet_status_header(ðernet_status_header); @@ -2161,11 +3410,22 @@ blf_read_ethernet_status(blf_params_t* params, int* err, gchar** err_info, gint6 tmpbuf[14] = (ethernet_status_header.bitrate & 0x0000ff00) >> 8; tmpbuf[15] = (ethernet_status_header.bitrate & 0x000000ff); + if (object_version >= 1) { + tmpbuf[16] = (linkUpDuration & UINT64_C(0xff00000000000000)) >> 56; + tmpbuf[17] = (linkUpDuration & UINT64_C(0x00ff000000000000)) >> 48; + tmpbuf[18] = (linkUpDuration & UINT64_C(0x0000ff0000000000)) >> 40; + tmpbuf[19] = (linkUpDuration & UINT64_C(0x000000ff00000000)) >> 32; + tmpbuf[20] = (linkUpDuration & UINT64_C(0x00000000ff000000)) >> 24; + tmpbuf[21] = (linkUpDuration & UINT64_C(0x0000000000ff0000)) >> 16; + tmpbuf[22] = (linkUpDuration & UINT64_C(0x000000000000ff00)) >> 8; + tmpbuf[23] = (linkUpDuration & UINT64_C(0x00000000000000ff)); + } + wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_DISSECTOR_NAME, "blf-ethernetstatus-obj"); wtap_buffer_append_epdu_end(params->buf); ws_buffer_assure_space(params->buf, sizeof(ethernet_status_header)); - ws_buffer_append(params->buf, tmpbuf, (gsize)16); + ws_buffer_append(params->buf, tmpbuf, (size_t)(object_version >= 1 ? 24 : 16)); /* We'll write this as a WS UPPER PDU packet with a data blob */ /* This will create an interface with the "name" of the matching @@ -2178,24 +3438,82 @@ blf_read_ethernet_status(blf_params_t* params, int* err, gchar** err_info, gint6 char* iface_name = ws_strdup_printf("STATUS-ETH-%u-%u", ethernet_status_header.channel, ethernet_status_header.hardwareChannel); blf_lookup_interface(params, WTAP_ENCAP_WIRESHARK_UPPER_PDU, ethernet_status_header.channel, ethernet_status_header.hardwareChannel, iface_name); g_free(iface_name); - blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_WIRESHARK_UPPER_PDU, ethernet_status_header.channel, ethernet_status_header.hardwareChannel, (guint32)ws_buffer_length(params->buf), (guint32)ws_buffer_length(params->buf)); + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_WIRESHARK_UPPER_PDU, ethernet_status_header.channel, ethernet_status_header.hardwareChannel, (uint32_t)ws_buffer_length(params->buf), (uint32_t)ws_buffer_length(params->buf)); if ((ethernet_status_header.flags & BLF_ETH_STATUS_HARDWARECHANNEL) == BLF_ETH_STATUS_HARDWARECHANNEL) { /* If HW channel valid */ wtap_block_add_uint32_option(params->rec->block, OPT_PKT_QUEUE, ethernet_status_header.hardwareChannel); } - return TRUE; + return true; +} + +static bool +blf_read_ethernet_phystate(blf_params_t* params, int* err, char** err_info, int64_t block_start, int64_t data_start, int64_t object_length, uint32_t flags, uint64_t object_timestamp) { + blf_ethernet_phystate_t ethernet_phystate_header; + uint8_t tmpbuf[8]; + + if (object_length < (data_start - block_start) + (int)sizeof(ethernet_phystate_header)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("blf: ETHERNET_PHY_STATE: not enough bytes for ethernet phystate header in object"); + ws_debug("not enough bytes for ethernet phystate header in object"); + return false; + } + + if (!blf_read_bytes(params, data_start, ðernet_phystate_header, sizeof(ethernet_phystate_header), err, err_info)) { + ws_debug("not enough bytes for ethernet phystate header in file"); + return false; + } + + fix_endianness_blf_ethernet_phystate_header(ðernet_phystate_header); + + tmpbuf[0] = (ethernet_phystate_header.channel & 0xff00) >> 8; + tmpbuf[1] = (ethernet_phystate_header.channel & 0x00ff); + tmpbuf[2] = (ethernet_phystate_header.flags & 0xff00) >> 8; + tmpbuf[3] = (ethernet_phystate_header.flags & 0x00ff); + tmpbuf[4] = (ethernet_phystate_header.phyState); + tmpbuf[5] = (ethernet_phystate_header.phyEvent); + tmpbuf[6] = (ethernet_phystate_header.hardwareChannel); + tmpbuf[7] = (ethernet_phystate_header.res1); + + wtap_buffer_append_epdu_string(params->buf, EXP_PDU_TAG_DISSECTOR_NAME, "blf-ethernetphystate-obj"); + wtap_buffer_append_epdu_end(params->buf); + + ws_buffer_assure_space(params->buf, sizeof(ethernet_phystate_header)); + ws_buffer_append(params->buf, tmpbuf, sizeof(ethernet_phystate_header)); + + /* We'll write this as a WS UPPER PDU packet with a data blob */ + /* This will create an interface with the "name" of the matching + * WTAP_ENCAP_ETHERNET interface with the same channel and hardware + * channel prefixed with "STATUS" and with a different interface ID, + * because IDBs in pcapng can only have one linktype. + * The other option would be to write everything as UPPER_PDU, including + * the Ethernet data (with one of the "eth_" dissectors.) + */ + char* iface_name = ws_strdup_printf("STATUS-ETH-%u-%u", ethernet_phystate_header.channel, ethernet_phystate_header.hardwareChannel); + blf_lookup_interface(params, WTAP_ENCAP_WIRESHARK_UPPER_PDU, ethernet_phystate_header.channel, ethernet_phystate_header.hardwareChannel, iface_name); + g_free(iface_name); + blf_init_rec(params, flags, object_timestamp, WTAP_ENCAP_WIRESHARK_UPPER_PDU, ethernet_phystate_header.channel, ethernet_phystate_header.hardwareChannel, (uint32_t)ws_buffer_length(params->buf), (uint32_t)ws_buffer_length(params->buf)); + + if ((ethernet_phystate_header.flags & BLF_PHY_STATE_HARDWARECHANNEL) == BLF_PHY_STATE_HARDWARECHANNEL) { + /* If HW channel valid */ + wtap_block_add_uint32_option(params->rec->block, OPT_PKT_QUEUE, ethernet_phystate_header.hardwareChannel); + } + + return true; } -static gboolean -blf_read_block(blf_params_t *params, gint64 start_pos, int *err, gchar **err_info) { +static bool +blf_read_block(blf_params_t *params, int64_t start_pos, int *err, char **err_info) { blf_blockheader_t header; blf_logobjectheader_t logheader; blf_logobjectheader2_t logheader2; blf_logobjectheader3_t logheader3; - guint32 flags; - guint64 object_timestamp; + uint32_t flags; + uint64_t object_timestamp; + uint16_t object_version; + int64_t last_metadata_start = 0; + size_t metadata_cont = 0; while (1) { /* Find Object */ @@ -2211,14 +3529,15 @@ blf_read_block(blf_params_t *params, gint64 start_pos, int *err, gchar **err_inf *err = 0; g_free(*err_info); } - return FALSE; + return false; } fix_endianness_blf_blockheader(&header); if (memcmp(header.magic, blf_obj_magic, sizeof(blf_obj_magic))) { ws_debug("object magic is not LOBJ (pos: 0x%" PRIx64 ")", start_pos); - } else { + } + else { break; } @@ -2228,187 +3547,271 @@ blf_read_block(blf_params_t *params, gint64 start_pos, int *err, gchar **err_inf } params->blf_data->start_of_last_obj = start_pos; + if (!params->random) { + /* Make sure that we start after this object next time, + * but only if it's a linear read. We can have random reads + * during the linear read, so we have to make sure we don't + * lose track of our position. + */ + params->blf_data->current_real_seek_pos = start_pos + MAX(MAX(16, header.object_length), header.header_length); + } + switch (header.header_type) { case BLF_HEADER_TYPE_DEFAULT: if (!blf_read_log_object_header(params, err, err_info, start_pos + sizeof(blf_blockheader_t), start_pos + header.header_length, &logheader)) { - return FALSE; + return false; } flags = logheader.flags; object_timestamp = logheader.object_timestamp; + object_version = logheader.object_version; break; case BLF_HEADER_TYPE_2: if (!blf_read_log_object_header2(params, err, err_info, start_pos + sizeof(blf_blockheader_t), start_pos + header.header_length, &logheader2)) { - return FALSE; + return false; } flags = logheader2.flags; object_timestamp = logheader2.object_timestamp; + object_version = logheader2.object_version; break; case BLF_HEADER_TYPE_3: if (!blf_read_log_object_header3(params, err, err_info, start_pos + sizeof(blf_blockheader_t), start_pos + header.header_length, &logheader3)) { - return FALSE; + return false; } flags = logheader3.flags; object_timestamp = logheader3.object_timestamp; + object_version = logheader3.object_version; break; default: *err = WTAP_ERR_UNSUPPORTED; *err_info = ws_strdup_printf("blf: unknown header type %u", header.header_type); ws_debug("unknown header type"); - return FALSE; + return false; } - /* already making sure that we start after this object next time. */ - params->blf_data->current_real_seek_pos = start_pos + MAX(MAX(16, header.object_length), header.header_length); + if (metadata_cont && header.object_type != BLF_OBJTYPE_APP_TEXT) { + /* If we're in the middle of a sequence of AppText metadata objects, + * but we get an AppText object from another source, + * skip the previous incomplete packet and start fresh. + */ + metadata_cont = 0; + last_metadata_start = 0; + } switch (header.object_type) { case BLF_OBJTYPE_LOG_CONTAINER: *err = WTAP_ERR_UNSUPPORTED; *err_info = ws_strdup_printf("blf: log container in log container not supported"); ws_debug("log container in log container not supported"); - return FALSE; - break; + return false; case BLF_OBJTYPE_ETHERNET_FRAME: return blf_read_ethernetframe(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; case BLF_OBJTYPE_ETHERNET_FRAME_EX: - return blf_read_ethernetframe_ext(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; + return blf_read_ethernetframe_ext(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, false); + + case BLF_OBJTYPE_ETHERNET_RX_ERROR: + return blf_read_ethernet_rxerror(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); + + case BLF_OBJTYPE_ETHERNET_ERROR_EX: + return blf_read_ethernetframe_ext(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, true); case BLF_OBJTYPE_WLAN_FRAME: return blf_read_wlanframe(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; case BLF_OBJTYPE_CAN_MESSAGE: - return blf_read_canmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, FALSE); - break; + return blf_read_canmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, false); case BLF_OBJTYPE_CAN_ERROR: - return blf_read_canerror(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; + return blf_read_canerror(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, false); + + case BLF_OBJTYPE_CAN_OVERLOAD: + return blf_read_canerror(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, true); case BLF_OBJTYPE_CAN_MESSAGE2: - return blf_read_canmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, TRUE); - break; + return blf_read_canmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, true); case BLF_OBJTYPE_CAN_ERROR_EXT: return blf_read_canerrorext(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; case BLF_OBJTYPE_CAN_FD_MESSAGE: return blf_read_canfdmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; case BLF_OBJTYPE_CAN_FD_MESSAGE_64: return blf_read_canfdmessage64(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; case BLF_OBJTYPE_CAN_FD_ERROR_64: return blf_read_canfderror64(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; case BLF_OBJTYPE_FLEXRAY_DATA: return blf_read_flexraydata(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; case BLF_OBJTYPE_FLEXRAY_MESSAGE: return blf_read_flexraymessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; case BLF_OBJTYPE_FLEXRAY_RCVMESSAGE: - return blf_read_flexrayrcvmessageex(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, FALSE); - break; + return blf_read_flexrayrcvmessageex(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, false); case BLF_OBJTYPE_FLEXRAY_RCVMESSAGE_EX: - return blf_read_flexrayrcvmessageex(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, TRUE); - break; + return blf_read_flexrayrcvmessageex(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, true); case BLF_OBJTYPE_LIN_MESSAGE: - return blf_read_linmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); - break; + return blf_read_linmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, false); + + case BLF_OBJTYPE_LIN_CRC_ERROR: + return blf_read_linmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, true); + + case BLF_OBJTYPE_LIN_RCV_ERROR: + return blf_read_linrcverror(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); + + case BLF_OBJTYPE_LIN_SND_ERROR: + return blf_read_linsenderror(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); + + case BLF_OBJTYPE_LIN_WAKEUP: + return blf_read_linwakeupevent(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); + + case BLF_OBJTYPE_LIN_MESSAGE2: + return blf_read_linmessage2(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, object_version); + + case BLF_OBJTYPE_LIN_CRC_ERROR2: + return blf_read_lincrcerror2(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, object_version); + + case BLF_OBJTYPE_LIN_RCV_ERROR2: + return blf_read_linrcverror2(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, object_version); + + case BLF_OBJTYPE_LIN_SND_ERROR2: + return blf_read_linsenderror2(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, object_version); + + case BLF_OBJTYPE_LIN_WAKEUP2: + return blf_read_linwakeupevent2(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); + + case BLF_OBJTYPE_LIN_SLEEP: + return blf_read_linsleepmodeevent(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); case BLF_OBJTYPE_APP_TEXT: { - int result = blf_read_apptextmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); + int result = blf_read_apptextmessage(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, metadata_cont); + if (result == BLF_APPTEXT_CONT) { + if (!metadata_cont) { + /* First object of a sequence, save its start position */ + last_metadata_start = start_pos; + } + /* Save a pointer to the end of the buffer */ + metadata_cont = params->buf->first_free; + } + else { + if (result == BLF_APPTEXT_METADATA && metadata_cont) { + /* Last object of a sequence, restore the start position of the first object */ + params->blf_data->start_of_last_obj = last_metadata_start; + } + /* Reset everything and start fresh */ + last_metadata_start = 0; + metadata_cont = 0; + } switch (result) { case BLF_APPTEXT_FAILED: - return FALSE; - case BLF_APPTEXT_METADATA: - return TRUE; + return false; case BLF_APPTEXT_COMMENT: - return TRUE; + case BLF_APPTEXT_METADATA: + case BLF_APPTEXT_ATTACHMENT: + case BLF_APPTEXT_TRACELINE: + return true; case BLF_APPTEXT_CHANNEL: + case BLF_APPTEXT_CONT: default: /* we do not return since there is no packet to show here */ - start_pos += MAX(MAX(16, header.object_length), header.header_length); + start_pos += MAX(MAX(16, header.object_length), header.header_length); + break; } } break; case BLF_OBJTYPE_ETHERNET_STATUS: - return blf_read_ethernet_status(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); + return blf_read_ethernet_status(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp, object_version); + + case BLF_OBJTYPE_ETHERNET_PHY_STATE: + return blf_read_ethernet_phystate(params, err, err_info, start_pos, start_pos + header.header_length, header.object_length, flags, object_timestamp); + + case BLF_OBJTYPE_ENV_INTEGER: + case BLF_OBJTYPE_ENV_DOUBLE: + case BLF_OBJTYPE_ENV_STRING: + case BLF_OBJTYPE_ENV_DATA: + case BLF_OBJTYPE_SYS_VARIABLE: + case BLF_OBJTYPE_RESERVED5: /* Despite the name, this is actually used. Maybe it's worth investigating the content. */ + case BLF_OBJTYPE_TEST_STRUCTURE: + ws_debug("skipping unsupported object type 0x%04x", header.object_type); + start_pos += MAX(MAX(16, header.object_length), header.header_length); break; default: - ws_debug("unknown object type 0x%04x", header.object_type); + ws_info("unknown object type 0x%04x", header.object_type); start_pos += MAX(MAX(16, header.object_length), header.header_length); + break; } } - return TRUE; + return true; } -static gboolean blf_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { +static bool blf_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, int64_t *data_offset) { blf_params_t blf_tmp; blf_tmp.wth = wth; blf_tmp.fh = wth->fh; + blf_tmp.random = false; + blf_tmp.pipe = wth->ispipe; blf_tmp.rec = rec; blf_tmp.buf = buf; blf_tmp.blf_data = (blf_t *)wth->priv; if (!blf_read_block(&blf_tmp, blf_tmp.blf_data->current_real_seek_pos, err, err_info)) { - return FALSE; + return false; } *data_offset = blf_tmp.blf_data->start_of_last_obj; - return TRUE; + return true; } -static gboolean blf_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { +static bool blf_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { blf_params_t blf_tmp; blf_tmp.wth = wth; blf_tmp.fh = wth->random_fh; + blf_tmp.random = true; + blf_tmp.pipe = wth->ispipe; blf_tmp.rec = rec; blf_tmp.buf = buf; blf_tmp.blf_data = (blf_t *)wth->priv; if (!blf_read_block(&blf_tmp, seek_off, err, err_info)) { ws_debug("couldn't read packet block (err=%d).", *err); - return FALSE; + return false; } - return TRUE; + return true; } static void blf_free(blf_t *blf) { - if (blf != NULL && blf->log_containers != NULL) { - for (guint i = 0; i < blf->log_containers->len; i++) { - blf_log_container_t *log_container = &g_array_index(blf->log_containers, blf_log_container_t, i); - if (log_container->real_data != NULL) { - g_free(log_container->real_data); + if (blf != NULL) { + if (blf->log_containers != NULL) { + for (unsigned i = 0; i < blf->log_containers->len; i++) { + blf_log_container_t* log_container = &g_array_index(blf->log_containers, blf_log_container_t, i); + if (log_container->real_data != NULL) { + g_free(log_container->real_data); + } } + g_array_free(blf->log_containers, true); + blf->log_containers = NULL; + } + if (blf->channel_to_iface_ht != NULL) { + g_hash_table_destroy(blf->channel_to_iface_ht); + blf->channel_to_iface_ht = NULL; + } + if (blf->channel_to_name_ht != NULL) { + g_hash_table_destroy(blf->channel_to_name_ht); + blf->channel_to_name_ht = NULL; } - g_array_free(blf->log_containers, TRUE); - blf->log_containers = NULL; - } - - if (blf != NULL && blf->channel_to_iface_ht != NULL) { - g_hash_table_destroy(blf->channel_to_iface_ht); - blf->channel_to_iface_ht = NULL; } } @@ -2419,14 +3822,13 @@ static void blf_close(wtap *wth) { } wtap_open_return_val -blf_open(wtap *wth, int *err, gchar **err_info) { +blf_open(wtap *wth, int *err, char **err_info) { blf_fileheader_t header; blf_t *blf; - blf_params_t params; ws_debug("opening file"); - if (!wtap_read_bytes_or_eof(wth->fh, &header, sizeof header, err, err_info)) { + if (!wtap_read_bytes_or_eof(wth->fh, &header, sizeof(blf_fileheader_t), err, err_info)) { ws_debug("wtap_read_bytes_or_eof() failed, err = %d.", *err); if (*err == 0 || *err == WTAP_ERR_SHORT_READ) { @@ -2452,14 +3854,14 @@ blf_open(wtap *wth, int *err, gchar **err_info) { /* This seems to be an BLF! */ /* Check for a valid header length */ - if (header.header_length < sizeof(blf_blockheader_t)) { + if (header.header_length < sizeof(blf_fileheader_t)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup("blf: file header length too short"); return WTAP_OPEN_ERROR; } /* skip past the header, which may include padding/reserved space */ - if (file_seek(wth->fh, header.header_length, SEEK_SET, err) < 0) { + if (!wtap_read_bytes(wth->fh, NULL, header.header_length - sizeof(blf_fileheader_t), err, err_info)) { return WTAP_OPEN_ERROR; } @@ -2474,30 +3876,15 @@ blf_open(wtap *wth, int *err, gchar **err_info) { /* Prepare our private context. */ blf = g_new(blf_t, 1); - blf->log_containers = NULL; - blf->current_log_container = 0; + blf->log_containers = g_array_new(false, false, sizeof(blf_log_container_t)); blf->current_real_seek_pos = 0; - blf->start_offset_ns = 1000 * 1000 * 1000 * (guint64)mktime(×tamp); + blf->start_offset_ns = 1000 * 1000 * 1000 * (uint64_t)mktime(×tamp); blf->start_offset_ns += 1000 * 1000 * header.start_date.ms; blf->channel_to_iface_ht = g_hash_table_new_full(g_int64_hash, g_int64_equal, &blf_free_key, &blf_free_channel_to_iface_entry); + blf->channel_to_name_ht = g_hash_table_new_full(g_int64_hash, g_int64_equal, &blf_free_key, &blf_free_channel_to_name_entry); blf->next_interface_id = 0; - /* embed in params */ - params.blf_data = blf; - params.buf = NULL; - params.fh = wth->fh; - params.rec = NULL; - params.wth = wth; - params.blf_data->current_real_seek_pos = 0; - - /* lets check out the layout of all log containers */ - if (!blf_scan_file_for_logcontainers(¶ms, err, err_info)) { - /* That didn't work. */ - blf_free(blf); - return WTAP_OPEN_ERROR; - } - wth->priv = (void *)blf; wth->file_encap = WTAP_ENCAP_NONE; wth->snapshot_length = 0; @@ -2523,7 +3910,7 @@ static const struct supported_block_type blf_blocks_supported[] = { static const struct file_type_subtype_info blf_info = { "Vector Informatik Binary Logging Format (BLF) logfile", "blf", "blf", NULL, - FALSE, BLOCKS_SUPPORTED(blf_blocks_supported), + false, BLOCKS_SUPPORTED(blf_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/blf.h b/wiretap/blf.h index fb9e117c..91866c45 100644 --- a/wiretap/blf.h +++ b/wiretap/blf.h @@ -18,10 +18,39 @@ #define __W_BLF_H__ #include "wtap.h" -#include <epan/value_string.h> -wtap_open_return_val blf_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val blf_open(wtap *wth, int *err, char **err_info); +/* + * A BLF file is of the form: + * + * BLF File Header + * Sequence of BLF objects + * + * A BLF object is of the form: + * + * BLF Block Header + * Object header (object type dependent, may be empty) + * Object contents + * + * As per + * + * https://gitlab.com/wireshark/wireshark/-/issues/19896#note_1967971057 + * + * the sequence may have one (or more?) metadata objects at the beginning. + * After those, if present, there are zero or more LOG_CONTAINER objects, + * containing data for all subsequent objects. An object may be split + * between LOG_CONTAINER objects, as per + * + * https://gitlab.com/wireshark/wireshark/-/issues/19377#note_1651998569 + * + * A LOG_CONTAINER object's contents are of the form: + * + * Log container header + * Data for contained objects. + * + * The data in a LOG_CONTAINER object may be compressed using zlib. + */ #define BLF_HEADER_TYPE_DEFAULT 1 #define BLF_HEADER_TYPE_2 2 @@ -35,57 +64,58 @@ wtap_open_return_val blf_open(wtap *wth, int *err, gchar **err_info); #define BLF_TIMESTAMP_RESOLUTION_1NS 2 typedef struct blf_date { - guint16 year; - guint16 month; - guint16 dayofweek; - guint16 day; - guint16 hour; - guint16 mins; - guint16 sec; - guint16 ms; + uint16_t year; + uint16_t month; + uint16_t dayofweek; + uint16_t day; + uint16_t hour; + uint16_t mins; + uint16_t sec; + uint16_t ms; } blf_date_t; -/* BLF Header */ +/* BLF File Header */ typedef struct blf_fileheader { - guint8 magic[4]; - guint32 header_length; + uint8_t magic[4]; /* magic number - "LOGG" */ + uint32_t header_length; /* length of the file header */ - guint8 applications[4]; - guint8 api[4]; + uint8_t applications[4]; + uint8_t api[4]; - guint64 len_compressed; - guint64 len_uncompressed; + uint64_t len_compressed; /* size of the file before uncompressing */ + uint64_t len_uncompressed; - guint32 obj_count; - guint32 obj_read; + uint32_t obj_count; /* number of objects in the file */ + uint32_t obj_read; blf_date_t start_date; blf_date_t end_date; - guint32 length3; + uint32_t length3; } blf_fileheader_t; +/* BLF Block Header */ typedef struct blf_blockheader { - guint8 magic[4]; - guint16 header_length; /* length of header starting with magic */ - guint16 header_type; /* header format ? */ - guint32 object_length; /* complete length including header */ - guint32 object_type; + uint8_t magic[4]; /* magic number = "LOBJ" */ + uint16_t header_length; /* length of header starting with magic */ + uint16_t header_type; /* header format ? */ + uint32_t object_length; /* complete length including header */ + uint32_t object_type; } blf_blockheader_t; typedef struct blf_logcontainerheader { - guint16 compression_method; /* 0 uncompressed, 2 zlib */ - guint16 res1; - guint32 res2; - guint32 uncompressed_size; - guint32 res4; + uint16_t compression_method; /* 0 uncompressed, 2 zlib */ + uint16_t res1; + uint32_t res2; + uint32_t uncompressed_size; + uint32_t res4; } blf_logcontainerheader_t; typedef struct blf_logobjectheader { - guint32 flags; - guint16 client_index; - guint16 object_version; - guint64 object_timestamp; + uint32_t flags; + uint16_t client_index; + uint16_t object_version; + uint64_t object_timestamp; } blf_logobjectheader_t; #define BLF_TS_STATUS_ORIG_TS_VALID 0x01 @@ -93,19 +123,19 @@ typedef struct blf_logobjectheader { #define BLF_TS_STATUS_PROTO_SPECIFIC 0x10 typedef struct blf_logobjectheader2 { - guint32 flags; - guint8 timestamp_status; - guint8 res1; - guint16 object_version; - guint64 object_timestamp; - guint64 original_timestamp; + uint32_t flags; + uint8_t timestamp_status; + uint8_t res1; + uint16_t object_version; + uint64_t object_timestamp; + uint64_t original_timestamp; } blf_logobjectheader2_t; typedef struct blf_logobjectheader3 { - guint32 flags; - guint16 static_size; - guint16 object_version; - guint64 object_timestamp; + uint32_t flags; + uint16_t static_size; + uint16_t object_version; + uint64_t object_timestamp; } blf_logobjectheader3_t; @@ -114,39 +144,54 @@ typedef struct blf_logobjectheader3 { #define BLF_DIR_TX_RQ 2 typedef struct blf_ethernetframeheader { - guint8 src_addr[6]; - guint16 channel; - guint8 dst_addr[6]; - guint16 direction; - guint16 ethtype; - guint16 tpid; - guint16 tci; - guint16 payloadlength; - guint64 res; + uint8_t src_addr[6]; + uint16_t channel; + uint8_t dst_addr[6]; + uint16_t direction; + uint16_t ethtype; + uint16_t tpid; + uint16_t tci; + uint16_t payloadlength; + uint64_t res; } blf_ethernetframeheader_t; typedef struct blf_ethernetframeheader_ex { - guint16 struct_length; - guint16 flags; - guint16 channel; - guint16 hw_channel; - guint64 frame_duration; - guint32 frame_checksum; - guint16 direction; - guint16 frame_length; - guint32 frame_handle; - guint32 error; + uint16_t struct_length; + uint16_t flags; + uint16_t channel; + uint16_t hw_channel; + uint64_t frame_duration; + uint32_t frame_checksum; + uint16_t direction; + uint16_t frame_length; + uint32_t frame_handle; + uint32_t error; } blf_ethernetframeheader_ex_t; +#define BLF_ETHERNET_EX_RES 0x0001 +#define BLF_ETHERNET_EX_HARDWARECHANNEL 0x0002 +#define BLF_ETHERNET_EX_FRAMEDURATION 0x0004 +#define BLF_ETHERNET_EX_FRAMEHANDLE 0x0008 + +typedef struct blf_ethernet_rxerror { + uint16_t struct_length; + uint16_t channel; + uint16_t direction; + uint16_t hw_channel; + uint32_t frame_checksum; + uint16_t frame_length; /* Number of valid raw Ethernet data bytes */ + uint32_t error; +} blf_ethernet_rxerror_t; + typedef struct blf_wlanframeheader { - guint16 channel; - guint16 flags; - guint8 direction; - guint8 radio_channel; - guint16 signal_strength; - guint16 signal_quality; - guint16 frame_length; - guint32 res; + uint16_t channel; + uint16_t flags; + uint8_t direction; + uint8_t radio_channel; + uint16_t signal_strength; + uint16_t signal_quality; + uint16_t frame_length; + uint32_t res; } blf_wlanframeheader_t; /* see https://bitbucket.org/tobylorenz/vector_blf/src/master/src/Vector/BLF/CanMessage.h */ @@ -159,20 +204,20 @@ typedef struct blf_wlanframeheader { /* shared for CAN message and CAN message2*/ typedef struct blf_canmessage { - guint16 channel; - guint8 flags; - guint8 dlc; - guint32 id; + uint16_t channel; + uint8_t flags; + uint8_t dlc; + uint32_t id; } blf_canmessage_t; /* see https://bitbucket.org/tobylorenz/vector_blf/src/master/src/Vector/BLF/CanMessage2.h */ typedef struct blf_canmessage2_trailer { - guint32 frameLength_in_ns; - guint8 bitCount; - guint8 reserved1; - guint16 reserved2; + uint32_t frameLength_in_ns; + uint8_t bitCount; + uint8_t reserved1; + uint16_t reserved2; } blf_canmessage2_trailer_t; @@ -184,18 +229,18 @@ typedef struct blf_canmessage2_trailer { #define BLF_CANFDMESSAGE_CANFDFLAG_ESI 0x04 typedef struct blf_canfdmessage { - guint16 channel; - guint8 flags; - guint8 dlc; - guint32 id; - guint32 frameLength_in_ns; - guint8 arbitration_bit_count; - guint8 canfdflags; - guint8 validDataBytes; - guint8 reservedCanFdMessage1; - guint32 reservedCanFdMessage2; + uint16_t channel; + uint8_t flags; + uint8_t dlc; + uint32_t id; + uint32_t frameLength_in_ns; + uint8_t arbitration_bit_count; + uint8_t canfdflags; + uint8_t validDataBytes; + uint8_t reservedCanFdMessage1; + uint32_t reservedCanFdMessage2; /* DATA */ - /* guint32 reservedCanFdMessage3 */ + /* uint32_t reservedCanFdMessage3 */ } blf_canfdmessage_t; @@ -216,29 +261,29 @@ typedef struct blf_canfdmessage { #define BLF_CANFDMESSAGE64_FLAG_BURST 0x200000 typedef struct blf_canfdmessage64 { - guint8 channel; - guint8 dlc; - guint8 validDataBytes; - guint8 txCount; - guint32 id; - guint32 frameLength_in_ns; - guint32 flags; - guint32 btrCfgArb; - guint32 btrCfgData; - guint32 timeOffsetBrsNs; - guint32 timeOffsetCrcDelNs; - guint16 bitCount; - guint8 dir; - guint8 extDataOffset; - guint32 crc; + uint8_t channel; + uint8_t dlc; + uint8_t validDataBytes; + uint8_t txCount; + uint32_t id; + uint32_t frameLength_in_ns; + uint32_t flags; + uint32_t btrCfgArb; + uint32_t btrCfgData; + uint32_t timeOffsetBrsNs; + uint32_t timeOffsetCrcDelNs; + uint16_t bitCount; + uint8_t dir; + uint8_t extDataOffset; + uint32_t crc; } blf_canfdmessage64_t; /* see https://bitbucket.org/tobylorenz/vector_blf/src/master/src/Vector/BLF/CanErrorFrame.h */ typedef struct blf_canerror { - guint16 channel; - guint16 length; + uint16_t channel; + uint16_t length; } blf_canerror_t; @@ -260,17 +305,17 @@ typedef struct blf_canerror { #define BLF_CANERROREXT_ECC_FDF_BIT_ERROR 0x9 typedef struct blf_canerrorext { - guint16 channel; - guint16 length; - guint32 flags; - guint8 ecc; - guint8 position; - guint8 dlc; - guint8 reserved1; - guint32 frameLength_in_ns; - guint32 id; - guint16 errorCodeExt; - guint16 reserved2; + uint16_t channel; + uint16_t length; + uint32_t flags; + uint8_t ecc; + uint8_t position; + uint8_t dlc; + uint8_t reserved1; + uint32_t frameLength_in_ns; + uint32_t id; + uint16_t errorCodeExt; + uint16_t reserved2; } blf_canerrorext_t; @@ -281,24 +326,24 @@ typedef struct blf_canerrorext { #define BLF_CANERROR65_FLAG_ESI 0x04 typedef struct blf_canfderror64 { - guint8 channel; - guint8 dlc; - guint8 validDataBytes; - guint8 ecc; - guint16 flags; - guint16 errorCodeExt; - guint16 extFlags; - guint8 extDataOffset; - guint8 reserved1; - guint32 id; - guint32 frameLength_in_ns; - guint32 btrCfgArb; - guint32 btrCfgData; - guint32 timeOffsetBrsNs; - guint32 timeOffsetCrcDelNs; - guint32 crc; - guint16 errorPosition; - guint16 reserved2; + uint8_t channel; + uint8_t dlc; + uint8_t validDataBytes; + uint8_t ecc; + uint16_t flags; + uint16_t errorCodeExt; + uint16_t extFlags; + uint8_t extDataOffset; + uint8_t reserved1; + uint32_t id; + uint32_t frameLength_in_ns; + uint32_t btrCfgArb; + uint32_t btrCfgData; + uint32_t timeOffsetBrsNs; + uint32_t timeOffsetCrcDelNs; + uint32_t crc; + uint16_t errorPosition; + uint16_t reserved2; } blf_canfderror64_t; @@ -308,14 +353,14 @@ typedef struct blf_canfderror64 { #define BLF_FLEXRAYDATA_CHANNEL_B 0x80 typedef struct blf_flexraydata { - guint16 channel; - guint8 mux; - guint8 len; - guint16 messageId; - guint16 crc; - guint8 dir; - guint8 reservedFlexRayData1; - guint16 reservedFlexRayData2; + uint16_t channel; + uint8_t mux; + uint8_t len; + uint16_t messageId; + uint16_t crc; + uint8_t dir; + uint8_t reservedFlexRayData1; + uint16_t reservedFlexRayData2; } blf_flexraydata_t; @@ -342,21 +387,21 @@ typedef struct blf_flexraydata { #define BLF_DLT_FLEXRAY_PPI 0x40 typedef struct blf_flexraymessage { - guint16 channel; - guint8 dir; /* Flags: 0 RX, 1 TX, 2 TX Req, 3 internal, 4 internal*/ - guint8 lowTime; - guint32 fpgaTick; - guint32 fpgaTickOverflow; - guint32 clientIndexFlexRayV6Message; - guint32 clusterTime; - guint16 frameId; - guint16 headerCrc; - guint16 frameState; - guint8 length; - guint8 cycle; - guint8 headerBitMask; - guint8 reservedFlexRayV6Message1; - guint16 reservedFlexRayV6Message2; + uint16_t channel; + uint8_t dir; /* Flags: 0 RX, 1 TX, 2 TX Req, 3 internal, 4 internal*/ + uint8_t lowTime; + uint32_t fpgaTick; + uint32_t fpgaTickOverflow; + uint32_t clientIndexFlexRayV6Message; + uint32_t clusterTime; + uint16_t frameId; + uint16_t headerCrc; + uint16_t frameState; + uint8_t length; + uint8_t cycle; + uint8_t headerBitMask; + uint8_t reservedFlexRayV6Message1; + uint16_t reservedFlexRayV6Message2; } blf_flexraymessage_t; @@ -381,26 +426,26 @@ typedef struct blf_flexraymessage { #define BLF_FLEXRAYRCVMSG_FRAME_FLAG_RES_80 0x00000080 typedef struct blf_flexrayrcvmessage { - guint16 channel; - guint16 version; - guint16 channelMask; /* 0 res, 1 A, 2 B, 3 A+B */ - guint16 dir; /* 0 RX, 1 TX, 2 TX Req, 3 internal, 4 internal*/ /* high byte reserved! */ - guint32 clientIndex; - guint32 clusterNo; - guint16 frameId; - guint16 headerCrc1; - guint16 headerCrc2; - guint16 payloadLength; - guint16 payloadLengthValid; - guint16 cycle; /* high byte reserved! */ - guint32 tag; - guint32 data; - guint32 frameFlags; - guint32 appParameter; + uint16_t channel; + uint16_t version; + uint16_t channelMask; /* 0 res, 1 A, 2 B, 3 A+B */ + uint16_t dir; /* 0 RX, 1 TX, 2 TX Req, 3 internal, 4 internal*/ /* high byte reserved! */ + uint32_t clientIndex; + uint32_t clusterNo; + uint16_t frameId; + uint16_t headerCrc1; + uint16_t headerCrc2; + uint16_t payloadLength; + uint16_t payloadLengthValid; + uint16_t cycle; /* high byte reserved! */ + uint32_t tag; + uint32_t data; + uint32_t frameFlags; + uint32_t appParameter; /* if ext, skip 40 bytes */ /* payload bytes */ - /* guint16 res3 */ - /* guint32 res4 */ + /* uint16_t res3 */ + /* uint32_t res4 */ } blf_flexrayrcvmessage_t; @@ -409,34 +454,34 @@ typedef struct blf_flexrayrcvmessage { /* defines see above BLF_FLEXRAYRCVMSG_* */ typedef struct blf_flexrayrcvmessageex { - guint16 channel; - guint16 version; - guint16 channelMask; /* 0 res, 1 A, 2 B, 3 A+B */ - guint16 dir; /* 0 RX, 1 TX, 2 TX Req, 3 internal, 4 internal*/ - guint32 clientIndex; - guint32 clusterNo; - guint16 frameId; - guint16 headerCrc1; - guint16 headerCrc2; - guint16 payloadLength; - guint16 payloadLengthValid; - guint16 cycle; - guint32 tag; - guint32 data; - guint32 frameFlags; - guint32 appParameter; - guint32 frameCRC; - guint32 frameLengthInNs; - guint16 frameId1; - guint16 pduOffset; - guint16 blfLogMask; - guint16 res1; - guint32 res2; - guint32 res3; - guint32 res4; - guint32 res5; - guint32 res6; - guint32 res7; + uint16_t channel; + uint16_t version; + uint16_t channelMask; /* 0 res, 1 A, 2 B, 3 A+B */ + uint16_t dir; /* 0 RX, 1 TX, 2 TX Req, 3 internal, 4 internal*/ + uint32_t clientIndex; + uint32_t clusterNo; + uint16_t frameId; + uint16_t headerCrc1; + uint16_t headerCrc2; + uint16_t payloadLength; + uint16_t payloadLengthValid; + uint16_t cycle; + uint32_t tag; + uint32_t data; + uint32_t frameFlags; + uint32_t appParameter; + uint32_t frameCRC; + uint32_t frameLengthInNs; + uint16_t frameId1; + uint16_t pduOffset; + uint16_t blfLogMask; + uint16_t res1; + uint32_t res2; + uint32_t res3; + uint32_t res4; + uint32_t res5; + uint32_t res6; + uint32_t res7; /* payload bytes */ } blf_flexrayrcvmessageex_t; @@ -444,37 +489,196 @@ typedef struct blf_flexrayrcvmessageex { /* see https://bitbucket.org/tobylorenz/vector_blf/src/master/src/Vector/BLF/LinMessage.h */ typedef struct blf_linmessage { - guint16 channel; - guint8 id; - guint8 dlc; - guint8 data[8]; - guint8 fsmId; - guint8 fsmState; - guint8 headerTime; - guint8 fullTime; - guint16 crc; - guint8 dir; /* 0 RX, 1 TX Receipt, 2 TX Req */ - guint8 res1; + uint16_t channel; + uint8_t id; + uint8_t dlc; + uint8_t data[8]; + uint8_t fsmId; + uint8_t fsmState; + uint8_t headerTime; + uint8_t fullTime; + uint16_t crc; + uint8_t dir; /* 0 RX, 1 TX Receipt, 2 TX Req */ + uint8_t res1; /* This field is optional and skipping does not hurt us. - guint32 res2; + uint32_t res2; */ } blf_linmessage_t; +typedef struct blf_linrcverror { + uint16_t channel; + uint8_t id; + uint8_t dlc; + uint8_t fsmId; + uint8_t fsmState; + uint8_t headerTime; + uint8_t fullTime; + uint8_t stateReason; + uint8_t offendingByte; + uint8_t shortError; + uint8_t timeoutDuringDlcDetection; +} blf_linrcverror_t; + +typedef struct blf_linsenderror { + uint16_t channel; + uint8_t id; + uint8_t dlc; + uint8_t fsmId; + uint8_t fsmState; + uint8_t headerTime; + uint8_t fullTime; +} blf_linsenderror_t; + +typedef struct blf_linwakeupevent { + uint16_t channel; + uint8_t signal; + uint8_t external; +} blf_linwakeupevent_t; + +typedef struct blf_linbusevent { + uint64_t sof; + uint32_t eventBaudrate; + uint16_t channel; + uint8_t res1[2]; +} blf_linbusevent_t; + +typedef struct blf_linsynchfieldevent { + blf_linbusevent_t linBusEvent; + uint64_t synchBreakLength; + uint64_t synchDelLength; +} blf_linsynchfieldevent_t; + +typedef struct blf_linmessagedescriptor { + blf_linsynchfieldevent_t linSynchFieldEvent; + uint16_t supplierId; /* LIN 2.0 or higher */ + uint16_t messageId; /* LIN 2.0: message identifier, LIN 2.1: position index as specified in LDF */ + uint8_t configuredNodeAddress; /* LIN 2.0 or higher */ + uint8_t id; + uint8_t dlc; + uint8_t checksumModel; +} blf_linmessagedescriptor_t; + +typedef struct blf_lindatabytetimestampevent { + blf_linmessagedescriptor_t linMessageDescriptor; + uint64_t databyteTimestamps[9]; /* Byte 0: Timestamp of last header byte, Bytes 1-9: Timestamps of data bytes 1-8 */ +} blf_lindatabytetimestampevent_t; + +typedef struct blf_linmessage2 { + blf_lindatabytetimestampevent_t linDataByteTimestampEvent; + uint8_t data[8]; + uint16_t crc; + uint8_t dir; /* 0 RX, 1 TX Receipt, 2 TX Req */ + uint8_t simulated; /* 0 Real frame, 1 Simulated frame */ + uint8_t isEtf; /* 0 Not event triggered frame, 1 Event triggered frame */ + uint8_t eftAssocIndex; + uint8_t eftAssocEftId; + uint8_t fsmId; /* Obsolete */ + uint8_t fsmState; /* Obsolete */ + uint8_t res1[3]; +/* These fields are optional and skipping does not hurt us. + uint32_t respBaudrate; + double exactHeaderBaudrate; + uint32_t earlyStopBitOffset; + uint32_t earlyStopBitOffsetResponse; +*/ +} blf_linmessage2_t; + +typedef struct blf_lincrcerror2 { + blf_lindatabytetimestampevent_t linDataByteTimestampEvent; + uint8_t data[8]; + uint16_t crc; + uint8_t dir; /* 0 RX, 1 TX Receipt, 2 TX Req */ + uint8_t fsmId; /* Obsolete */ + uint8_t fsmState; /* Obsolete */ + uint8_t simulated; /* 0 Real frame, 1 Simulated frame */ + uint8_t res1[2]; +/* These fields are optional and skipping does not hurt us. + uint32_t respBaudrate; + uint8_t res2[4]; + double exactHeaderBaudrate; + uint32_t earlyStopBitOffset; + uint32_t earlyStopBitOffsetResponse; +*/ +} blf_lincrcerror2_t; + +typedef struct blf_linrcverror2 { + blf_lindatabytetimestampevent_t linDataByteTimestampEvent; + uint8_t data[8]; + uint8_t fsmId; /* Obsolete */ + uint8_t fsmState; /* Obsolete */ + uint8_t stateReason; + uint8_t offendingByte; + uint8_t shortError; + uint8_t timeoutDuringDlcDetection; + uint8_t isEtf; + uint8_t hasDataBytes; +/* These fields are optional and skipping does not hurt us. + uint32_t respBaudrate; + uint8_t res[4]; + double exactHeaderBaudrate; + uint32_t earlyStopBitOffset; + uint32_t earlyStopBitOffsetResponse; +*/ +} blf_linrcverror2_t; + +typedef struct blf_linsenderror2 { + blf_linmessagedescriptor_t linMessageDescriptor; + uint64_t eoh; + uint8_t isEtf; + uint8_t fsmId; /* Obsolete */ + uint8_t fsmState; /* Obsolete */ + uint8_t res1; +/* These fields are optional and skipping does not hurt us. + uint8_t res2[4]; + double exactHeaderBaudrate; + uint32_t earlyStopBitOffset; +*/ +} blf_linsenderror2_t; + +typedef struct blf_linwakeupevent2 { + blf_linbusevent_t linBusEvent; + uint8_t lengthInfo; /* Wake-up length: 0 = OK; 1 = Too short; 2 = Too long. */ + uint8_t signal; + uint8_t external; + uint8_t res; +} blf_linwakeupevent2_t; + +typedef struct blf_linsleepmodeevent { + uint16_t channel; + uint8_t reason; + uint8_t flags; +} blf_linsleepmodeevent_t; + +#define BLF_LIN_WU_SLEEP_REASON_START_STATE 0 /* Initial state of the interface */ +#define BLF_LIN_SLEEP_REASON_GO_TO_SLEEP_FRAME 1 +#define BLF_LIN_SLEEP_REASON_BUS_IDLE_TIMEOUT 2 +#define BLF_LIN_SLEEP_REASON_SILENT_SLEEPMODE_CMD 3 /* Command to shorten bus idle timeout */ +#define BLF_LIN_WU_REASON_EXTERNAL_WAKEUP_SIG 9 +#define BLF_LIN_WU_REASON_INTERNAL_WAKEUP_SIG 10 +#define BLF_LIN_WU_REASON_BUS_TRAFFIC 11 +#define BLF_LIN_NO_SLEEP_REASON_BUS_TRAFFIC 18 /* LIN hardware does not go into Sleep mode in spite of request to do so */ + /* see https://bitbucket.org/tobylorenz/vector_blf/src/master/src/Vector/BLF/AppText.h */ typedef struct blf_apptext { - guint32 source; - guint32 reservedAppText1; - guint32 textLength; - guint32 reservedAppText2; + uint32_t source; + uint32_t reservedAppText1; + uint32_t textLength; + uint32_t reservedAppText2; } blf_apptext_t; -#define BLF_APPTEXT_COMMENT 0x00000000 -#define BLF_APPTEXT_CHANNEL 0x00000001 -#define BLF_APPTEXT_METADATA 0x00000002 -#define BLF_APPTEXT_FAILED 0x000000FF +#define BLF_APPTEXT_COMMENT 0x00000000 +#define BLF_APPTEXT_CHANNEL 0x00000001 +#define BLF_APPTEXT_METADATA 0x00000002 +#define BLF_APPTEXT_ATTACHMENT 0x00000003 +#define BLF_APPTEXT_TRACELINE 0x00000004 +#define BLF_APPTEXT_CONT 0x000000FE +#define BLF_APPTEXT_FAILED 0x000000FF +#define BLF_APPTEXT_XML_GENERAL 0x01 +#define BLF_APPTEXT_XML_CHANNELS 0x02 +#define BLF_APPTEXT_XML_IDENTITY 0x03 #define BLF_BUSTYPE_CAN 1 #define BLF_BUSTYPE_LIN 5 @@ -489,17 +693,44 @@ typedef struct blf_apptext { typedef struct blf_ethernet_status { uint16_t channel; uint16_t flags; - uint8_t linkStatus; - uint8_t ethernetPhy; - uint8_t duplex; - uint8_t mdi; - uint8_t connector; - uint8_t clockMode; - uint8_t pairs; - uint8_t hardwareChannel; + uint8_t linkStatus; + uint8_t ethernetPhy; + uint8_t duplex; + uint8_t mdi; + uint8_t connector; + uint8_t clockMode; + uint8_t pairs; + uint8_t hardwareChannel; uint32_t bitrate; +/* Starting from version 1 + uint64_t linkUpDuration; // In nanoseconds +*/ } blf_ethernet_status_t; +#define BLF_ETH_STATUS_LINKSTATUS 0x0001 +#define BLF_ETH_STATUS_BITRATE 0x0002 +#define BLF_ETH_STATUS_ETHERNETPHY 0x0004 +#define BLF_ETH_STATUS_DUPLEX 0x0008 +#define BLF_ETH_STATUS_MDITYPE 0x0010 +#define BLF_ETH_STATUS_CONNECTOR 0x0020 +#define BLF_ETH_STATUS_CLOCKMODE 0x0040 +#define BLF_ETH_STATUS_BRPAIR 0x0080 +#define BLF_ETH_STATUS_HARDWARECHANNEL 0x0100 +#define BLF_ETH_STATUS_LINKUPDURATION 0x0200 + +typedef struct blf_ethernet_phystate { + uint16_t channel; + uint16_t flags; + uint8_t phyState; + uint8_t phyEvent; + uint8_t hardwareChannel; + uint8_t res1; +} blf_ethernet_phystate_t; + +#define BLF_PHY_STATE_PHYSTATE 0x0001 +#define BLF_PHY_STATE_PHYEVENT 0x0002 +#define BLF_PHY_STATE_HARDWARECHANNEL 0x0004 + /* see https://bitbucket.org/tobylorenz/vector_blf/src/master/src/Vector/BLF/ObjectHeaderBase.h */ @@ -611,6 +842,9 @@ typedef struct blf_ethernet_status { #define BLF_OBJTYPE_A429_BUS_STATISTIC 112 #define BLF_OBJTYPE_A429_MESSAGE 113 #define BLF_OBJTYPE_ETHERNET_STATISTIC 114 +#define BLF_OBJTYPE_RESERVED5 115 +#define BLF_OBJTYPE_RESERVED6 116 +#define BLF_OBJTYPE_RESERVED7 117 #define BLF_OBJTYPE_TEST_STRUCTURE 118 #define BLF_OBJTYPE_DIAG_REQUEST_INTERPRETATION 119 #define BLF_OBJTYPE_ETHERNET_FRAME_EX 120 @@ -625,16 +859,8 @@ typedef struct blf_ethernet_status { #define BLF_OBJTYPE_CAN_SETTING_CHANGED 129 #define BLF_OBJTYPE_DISTRIBUTED_OBJECT_MEMBER 130 #define BLF_OBJTYPE_ATTRIBUTE_EVENT 131 - -#define BLF_ETH_STATUS_LINKSTATUS 0x0001 -#define BLF_ETH_STATUS_BITRATE 0x0002 -#define BLF_ETH_STATUS_ETHERNETPHY 0x0004 -#define BLF_ETH_STATUS_DUPLEX 0x0008 -#define BLF_ETH_STATUS_MDITYPE 0x0010 -#define BLF_ETH_STATUS_CONNECTOR 0x0020 -#define BLF_ETH_STATUS_CLOCKMODE 0x0040 -#define BLF_ETH_STATUS_BRPAIR 0x0080 -#define BLF_ETH_STATUS_HARDWARECHANNEL 0x0100 +#define BLF_OBJTYPE_DISTRIBUTED_OBJECT_CHANGE 132 +#define BLF_OBJTYPE_ETHERNET_PHY_STATE 133 #endif diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c index 3ef14656..85cb33e5 100644 --- a/wiretap/btsnoop.c +++ b/wiretap/btsnoop.c @@ -7,10 +7,11 @@ */ #include "config.h" +#include "btsnoop.h" + #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "btsnoop.h" /* * Symbian's btsnoop format is derived from Sun's snoop format. @@ -29,17 +30,17 @@ static const char btsnoop_magic[] = { /* "btsnoop" file header (minus magic number). */ struct btsnoop_hdr { - guint32 version; /* version number (should be 1) */ - guint32 datalink; /* datalink type */ + uint32_t version; /* version number (should be 1) */ + uint32_t datalink; /* datalink type */ }; /* "btsnoop" record header. */ struct btsnooprec_hdr { - guint32 orig_len; /* actual length of packet */ - guint32 incl_len; /* number of octets captured in file */ - guint32 flags; /* packet flags */ - guint32 cum_drops; /* cumulative number of dropped packets */ - gint64 ts_usec; /* timestamp microseconds */ + uint32_t orig_len; /* actual length of packet */ + uint32_t incl_len; /* number of octets captured in file */ + uint32_t flags; /* packet flags */ + uint32_t cum_drops; /* cumulative number of dropped packets */ + int64_t ts_usec; /* timestamp microseconds */ }; /* H1 is unframed data with the packet type encoded in the flags field of capture header */ @@ -61,20 +62,20 @@ struct btsnooprec_hdr { #define KHciLoggerACLDataFrame 0 #define KHciLoggerCommandOrEvent 0x00000002 -static const gint64 KUnixTimeBase = G_GINT64_CONSTANT(0x00dcddb30f2f8000); /* offset from symbian - unix time */ +static const int64_t KUnixTimeBase = INT64_C(0x00dcddb30f2f8000); /* offset from symbian - unix time */ -static gboolean btsnoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *offset); -static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool btsnoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *offset); +static bool btsnoop_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool btsnoop_read_record(wtap *wth, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int btsnoop_file_type_subtype = -1; void register_btsnoop(void); -wtap_open_return_val btsnoop_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val btsnoop_open(wtap *wth, int *err, char **err_info) { char magic[sizeof btsnoop_magic]; struct btsnoop_hdr hdr; @@ -153,36 +154,36 @@ wtap_open_return_val btsnoop_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_MINE; } -static gboolean btsnoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *offset) +static bool btsnoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *offset) { *offset = file_tell(wth->fh); return btsnoop_read_record(wth, wth->fh, rec, buf, err, err_info); } -static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool btsnoop_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return btsnoop_read_record(wth, wth->random_fh, rec, buf, err, err_info); } -static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool btsnoop_read_record(wtap *wth, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { struct btsnooprec_hdr hdr; - guint32 packet_size; - guint32 flags; - guint32 orig_size; - gint64 ts; + uint32_t packet_size; + uint32_t flags; + uint32_t orig_size; + int64_t ts; /* Read record header. */ if (!wtap_read_bytes_or_eof(fh, &hdr, sizeof hdr, err, err_info)) - return FALSE; + return false; packet_size = g_ntohl(hdr.incl_len); orig_size = g_ntohl(hdr.orig_len); @@ -195,7 +196,7 @@ static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("btsnoop: File has %u-byte packet, bigger than maximum of %u", packet_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } ts = GINT64_FROM_BE(hdr.ts_usec); @@ -204,15 +205,15 @@ static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, rec->rec_type = REC_TYPE_PACKET; rec->block = wtap_block_create(WTAP_BLOCK_PACKET); rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - rec->ts.secs = (guint)(ts / 1000000); - rec->ts.nsecs = (guint)((ts % 1000000) * 1000); + rec->ts.secs = (unsigned)(ts / 1000000); + rec->ts.nsecs = (unsigned)((ts % 1000000) * 1000); rec->rec_header.packet_header.caplen = packet_size; rec->rec_header.packet_header.len = orig_size; if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) { - rec->rec_header.packet_header.pseudo_header.p2p.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE; + rec->rec_header.packet_header.pseudo_header.p2p.sent = (flags & KHciLoggerControllerToHost) ? false : true; } else if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_HCI) { - rec->rec_header.packet_header.pseudo_header.bthci.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE; + rec->rec_header.packet_header.pseudo_header.bthci.sent = (flags & KHciLoggerControllerToHost) ? false : true; if(flags & KHciLoggerCommandOrEvent) { if(rec->rec_header.packet_header.pseudo_header.bthci.sent) @@ -259,20 +260,20 @@ static int btsnoop_dump_can_write_encap(int encap) return 0; } -static gboolean btsnoop_dump(wtap_dumper *wdh, +static bool btsnoop_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info) + const uint8_t *pd, int *err, char **err_info) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct btsnooprec_hdr rec_hdr; - guint32 flags; - gint64 nsecs; - gint64 ts_usec; + uint32_t flags; + int64_t nsecs; + int64_t ts_usec; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -281,13 +282,13 @@ static gboolean btsnoop_dump(wtap_dumper *wdh, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* Don't write out anything bigger than we can read. */ if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } rec_hdr.incl_len = GUINT32_TO_BE(rec->rec_header.packet_header.caplen); @@ -301,8 +302,8 @@ static gboolean btsnoop_dump(wtap_dumper *wdh, case BTHCI_CHANNEL_COMMAND: if (!pseudo_header->bthci.sent) { *err = WTAP_ERR_UNWRITABLE_REC_DATA; - *err_info = ws_strdup_printf("btsnoop: Command channel, sent FALSE"); - return FALSE; + *err_info = ws_strdup_printf("btsnoop: Command channel, sent false"); + return false; } flags = KHciLoggerCommandOrEvent|KHciLoggerHostToController; break; @@ -310,8 +311,8 @@ static gboolean btsnoop_dump(wtap_dumper *wdh, case BTHCI_CHANNEL_EVENT: if (pseudo_header->bthci.sent) { *err = WTAP_ERR_UNWRITABLE_REC_DATA; - *err_info = ws_strdup_printf("btsnoop: Event channel, sent TRUE"); - return FALSE; + *err_info = ws_strdup_printf("btsnoop: Event channel, sent true"); + return false; } flags = KHciLoggerCommandOrEvent|KHciLoggerControllerToHost; break; @@ -327,7 +328,7 @@ static gboolean btsnoop_dump(wtap_dumper *wdh, *err = WTAP_ERR_UNWRITABLE_REC_DATA; *err_info = ws_strdup_printf("btsnoop: Unknown channel %u", pseudo_header->bthci.channel); - return FALSE; + return false; } break; @@ -351,29 +352,29 @@ static gboolean btsnoop_dump(wtap_dumper *wdh, *err = WTAP_ERR_INTERNAL; *err_info = ws_strdup_printf("btsnoop: invalid encapsulation %u", wdh->file_encap); - return FALSE; + return false; } rec_hdr.flags = GUINT32_TO_BE(flags); rec_hdr.cum_drops = GUINT32_TO_BE(0); nsecs = rec->ts.nsecs; - ts_usec = ((gint64) rec->ts.secs * 1000000) + (nsecs / 1000); + ts_usec = ((int64_t) rec->ts.secs * 1000000) + (nsecs / 1000); ts_usec += KUnixTimeBase; rec_hdr.ts_usec = GINT64_TO_BE(ts_usec); if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; - return TRUE; + return false; + return true; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean btsnoop_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool btsnoop_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { struct btsnoop_hdr file_hdr; - guint32 datalink; + uint32_t datalink; /* This is a btsnoop file */ wdh->subtype_write = btsnoop_dump; @@ -398,12 +399,12 @@ static gboolean btsnoop_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _ *err = WTAP_ERR_INTERNAL; *err_info = ws_strdup_printf("btsnoop: invalid encapsulation %u", wdh->file_encap); - return FALSE; + return false; } /* Write the file header. */ if (!wtap_dump_file_write(wdh, btsnoop_magic, sizeof btsnoop_magic, err)) - return FALSE; + return false; /* current "btsnoop" format is 1 */ file_hdr.version = GUINT32_TO_BE(1); @@ -411,9 +412,9 @@ static gboolean btsnoop_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _ file_hdr.datalink = GUINT32_TO_BE(datalink); if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err)) - return FALSE; + return false; - return TRUE; + return true; } static const struct supported_block_type btsnoop_blocks_supported[] = { @@ -425,7 +426,7 @@ static const struct supported_block_type btsnoop_blocks_supported[] = { static const struct file_type_subtype_info btsnoop_info = { "Symbian OS btsnoop", "btsnoop", "log", NULL, - FALSE, BLOCKS_SUPPORTED(btsnoop_blocks_supported), + false, BLOCKS_SUPPORTED(btsnoop_blocks_supported), btsnoop_dump_can_write_encap, btsnoop_dump_open, NULL }; diff --git a/wiretap/btsnoop.h b/wiretap/btsnoop.h index 3f070212..526f2709 100644 --- a/wiretap/btsnoop.h +++ b/wiretap/btsnoop.h @@ -8,9 +8,11 @@ #ifndef __W_BTSNOOP_H__ #define __W_BTSNOOP_H__ + #include <glib.h> #include "ws_symbol_export.h" +#include "wtap.h" -wtap_open_return_val btsnoop_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val btsnoop_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/busmaster.c b/wiretap/busmaster.c index ec2b3bc8..b7cf729b 100644 --- a/wiretap/busmaster.c +++ b/wiretap/busmaster.c @@ -10,11 +10,12 @@ */ #include "config.h" +#include "busmaster.h" + #include <wtap-int.h> #include <file_wrappers.h> #include <epan/dissectors/packet-socketcan.h> #include <wsutil/exported_pdu_tlvs.h> -#include "busmaster.h" #include "busmaster_priv.h" #include <inttypes.h> #include <string.h> @@ -23,15 +24,15 @@ static void busmaster_close(wtap *wth); -static gboolean +static bool busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, - gint64 *data_offset); + int *err, char **err_info, + int64_t *data_offset); -static gboolean -busmaster_seek_read(wtap *wth, gint64 seek_off, +static bool +busmaster_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + int *err, char **err_info); static int busmaster_file_type_subtype = -1; @@ -40,55 +41,45 @@ void register_busmaster(void); /* * See * - * http://rbei-etas.github.io/busmaster/ + * https://rbei-etas.github.io/busmaster/ * * for the BUSMASTER software. */ -static gboolean +static bool busmaster_gen_packet(wtap_rec *rec, Buffer *buf, const busmaster_priv_t *priv_entry, const msg_t *msg, - int *err, gchar **err_info) + int *err, char **err_info) { time_t secs = 0; - guint32 nsecs = 0; - gboolean has_ts = FALSE; - gboolean is_fd = (msg->type == MSG_TYPE_STD_FD) + uint32_t nsecs = 0; + bool has_ts = false; + bool is_fd = (msg->type == MSG_TYPE_STD_FD) || (msg->type == MSG_TYPE_EXT_FD); - gboolean is_eff = (msg->type == MSG_TYPE_EXT) + bool is_eff = (msg->type == MSG_TYPE_EXT) || (msg->type == MSG_TYPE_EXT_RTR) || (msg->type == MSG_TYPE_EXT_FD); - gboolean is_rtr = (msg->type == MSG_TYPE_STD_RTR) + bool is_rtr = (msg->type == MSG_TYPE_STD_RTR) || (msg->type == MSG_TYPE_EXT_RTR); - gboolean is_err = (msg->type == MSG_TYPE_ERR); + bool is_err = (msg->type == MSG_TYPE_ERR); if (!priv_entry) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Header is missing"); - return FALSE; + return false; } - /* Generate Exported PDU tags for the packet info */ ws_buffer_clean(buf); - if (is_fd) - { - wtap_buffer_append_epdu_string(buf, EXP_PDU_TAG_DISSECTOR_NAME, "canfd"); - } - else - { - wtap_buffer_append_epdu_string(buf, EXP_PDU_TAG_DISSECTOR_NAME, "can-hostendian"); - } - wtap_buffer_append_epdu_end(buf); if (is_fd) { canfd_frame_t canfd_frame = {0}; - canfd_frame.can_id = (msg->id & (is_eff ? CAN_EFF_MASK : CAN_SFF_MASK)) | + canfd_frame.can_id = g_htonl((msg->id & (is_eff ? CAN_EFF_MASK : CAN_SFF_MASK)) | (is_eff ? CAN_EFF_FLAG : 0) | - (is_err ? CAN_ERR_FLAG : 0); - canfd_frame.flags = 0; + (is_err ? CAN_ERR_FLAG : 0)); + canfd_frame.flags = CANFD_FDF; canfd_frame.len = msg->data.length; memcpy(canfd_frame.data, @@ -96,17 +87,17 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf, MIN(msg->data.length, sizeof(canfd_frame.data))); ws_buffer_append(buf, - (guint8 *)&canfd_frame, + (uint8_t *)&canfd_frame, sizeof(canfd_frame)); } else { can_frame_t can_frame = {0}; - can_frame.can_id = (msg->id & (is_eff ? CAN_EFF_MASK : CAN_SFF_MASK)) | + can_frame.can_id = g_htonl((msg->id & (is_eff ? CAN_EFF_MASK : CAN_SFF_MASK)) | (is_rtr ? CAN_RTR_FLAG : 0) | (is_eff ? CAN_EFF_FLAG : 0) | - (is_err ? CAN_ERR_FLAG : 0); + (is_err ? CAN_ERR_FLAG : 0)); can_frame.can_dlc = msg->data.length; memcpy(can_frame.data, @@ -114,7 +105,7 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf, MIN(msg->data.length, sizeof(can_frame.data))); ws_buffer_append(buf, - (guint8 *)&can_frame, + (uint8_t *)&can_frame, sizeof(can_frame)); } @@ -132,12 +123,12 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf, secs = mktime(&tm); nsecs = msg->timestamp.micros * 1000u; - has_ts = TRUE; + has_ts = true; } else if (priv_entry->time_mode == TIME_MODE_ABSOLUTE) { struct tm tm; - guint32 micros; + uint32_t micros; tm.tm_year = priv_entry->start_date.year - 1900; tm.tm_mon = priv_entry->start_date.month - 1; @@ -161,7 +152,7 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf, } nsecs = micros * 1000u; - has_ts = TRUE; + has_ts = true; } rec->rec_type = REC_TYPE_PACKET; @@ -170,17 +161,17 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf, rec->ts.secs = secs; rec->ts.nsecs = nsecs; - rec->rec_header.packet_header.caplen = (guint32)ws_buffer_length(buf); - rec->rec_header.packet_header.len = (guint32)ws_buffer_length(buf); + rec->rec_header.packet_header.caplen = (uint32_t)ws_buffer_length(buf); + rec->rec_header.packet_header.len = (uint32_t)ws_buffer_length(buf); - return TRUE; + return true; } static log_entry_type_t busmaster_parse(FILE_T fh, busmaster_state_t *state, int *err, char **err_info) { - gboolean ok; - gint64 seek_off; + bool ok; + int64_t seek_off; busmaster_debug_printf("%s: Running busmaster file decoder\n", G_STRFUNC); @@ -251,7 +242,7 @@ busmaster_open(wtap *wth, int *err, char **err_info) wth->subtype_read = busmaster_read; wth->subtype_seek_read = busmaster_seek_read; wth->file_type_subtype = busmaster_file_type_subtype; - wth->file_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU; + wth->file_encap = WTAP_ENCAP_SOCKETCAN; wth->file_tsprec = WTAP_TSPREC_USEC; return WTAP_OPEN_MINE; @@ -267,7 +258,7 @@ busmaster_close(wtap *wth) } static busmaster_priv_t * -busmaster_find_priv_entry(void *priv, gint64 offset) +busmaster_find_priv_entry(void *priv, int64_t offset) { GSList *list; @@ -287,15 +278,15 @@ busmaster_find_priv_entry(void *priv, gint64 offset) return NULL; } -static gboolean -busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, - gint64 *data_offset) +static bool +busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, + int64_t *data_offset) { log_entry_type_t entry; busmaster_state_t state; busmaster_priv_t *priv_entry; - gboolean is_msg = FALSE; - gboolean is_ok = TRUE; + bool is_msg = false; + bool is_ok = true; while (!is_msg && is_ok) { @@ -308,7 +299,7 @@ busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in G_STRFUNC); *err = 0; *err_info = NULL; - return FALSE; + return false; } *data_offset = file_tell(wth->fh); @@ -331,7 +322,7 @@ busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Header is missing"); - return FALSE; + return false; } priv_entry->file_end_offset = *data_offset; if (entry == LOG_ENTRY_FOOTER) @@ -343,7 +334,7 @@ busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in { *err = WTAP_ERR_UNSUPPORTED; *err_info = g_strdup("Unsupported protocol type"); - return FALSE; + return false; } if (wth->priv) @@ -355,7 +346,7 @@ busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Footer is missing"); - return FALSE; + return false; } } @@ -369,7 +360,7 @@ busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in wth->priv = g_slist_append((GSList *)wth->priv, priv_entry); break; case LOG_ENTRY_MSG: - is_msg = TRUE; + is_msg = true; priv_entry = busmaster_find_priv_entry(wth->priv, *data_offset); is_ok = busmaster_gen_packet(rec, buf, priv_entry, &state.msg, err, err_info); break; @@ -377,7 +368,7 @@ busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in case LOG_ENTRY_ERROR: case LOG_ENTRY_NONE: default: - is_ok = FALSE; + is_ok = false; break; } } @@ -388,9 +379,9 @@ busmaster_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in return is_ok; } -static gboolean -busmaster_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +busmaster_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { busmaster_priv_t *priv_entry; busmaster_state_t state = {0}; @@ -404,11 +395,11 @@ busmaster_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, busmaster_debug_printf("%s: analyzing output\n", G_STRFUNC); *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Malformed header"); - return FALSE; + return false; } if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; state.header = *priv_entry; entry = busmaster_parse(wth->random_fh, &state, err, err_info); @@ -416,13 +407,13 @@ busmaster_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, busmaster_debug_printf("%s: analyzing output\n", G_STRFUNC); if (entry == LOG_ENTRY_ERROR || entry == LOG_ENTRY_NONE) - return FALSE; + return false; if (entry != LOG_ENTRY_MSG) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Failed to read a frame"); - return FALSE; + return false; } return busmaster_gen_packet(rec, buf, priv_entry, &state.msg, err, err_info); @@ -437,7 +428,7 @@ static const struct supported_block_type busmaster_blocks_supported[] = { static const struct file_type_subtype_info busmaster_info = { "BUSMASTER log file", "busmaster", "log", NULL, - FALSE, BLOCKS_SUPPORTED(busmaster_blocks_supported), + false, BLOCKS_SUPPORTED(busmaster_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/busmaster_parser.lemon b/wiretap/busmaster_parser.lemon index ce62aada..8c3e4c2c 100644 --- a/wiretap/busmaster_parser.lemon +++ b/wiretap/busmaster_parser.lemon @@ -16,6 +16,7 @@ #include <string.h> #include <wireshark.h> #include <wiretap/file_wrappers.h> +#include <wsutil/array.h> #include "busmaster_priv.h" extern void *BusmasterParserAlloc(void *(*mallocProc)(size_t)); @@ -62,7 +63,7 @@ DIAG_ON_LEMON() (void)yyminor; #ifdef BUSMASTER_DEBUG - const int n = sizeof(yyTokenName) / sizeof(yyTokenName[0]); + const int n = array_length(yyTokenName); busmaster_debug_printf("%s: got token: %s\n", G_STRFUNC, yyTokenName[yymajor]); for (int i = 0; i < n; ++i) { int a = yy_find_shift_action((YYCODETYPE)i, yypParser->yytos->stateno); @@ -97,15 +98,15 @@ DIAG_ON_LEMON() %type msg_time { msg_time_t } %type msg_type { msg_type_t } %type err_msg_type { msg_type_t } -%type msg_length { guint } -%type msg_id { guint32 } +%type msg_length { unsigned } +%type msg_id { uint32_t } %type ref_date { msg_date_t } %type ref_time { msg_time_t } %type start_time { msg_date_time_t } -%type byte { guint8 } +%type byte { uint8_t } %type data { msg_data_t } %type data0 { msg_data_t } %type data1 { msg_data_t } @@ -260,35 +261,35 @@ j1939_msg ::= msg_time(msg_time) INT msg_id(msg_id) INT J1939_MSG_TYPE INT INT I ref_date(R) ::= INT(D) COLON INT(M) COLON INT(Y) . { - R.year = (guint)Y.v0; - R.month = (guint)M.v0; - R.day = (guint)D.v0; + R.year = (unsigned)Y.v0; + R.month = (unsigned)M.v0; + R.day = (unsigned)D.v0; } ref_time(R) ::= INT(H) COLON INT(M) COLON INT(S) COLON INT(U) . { - R.hours = (guint)H.v0; - R.minutes = (guint)M.v0; - R.seconds = (guint)S.v0; - R.micros = (guint)U.v0 * 1000; + R.hours = (unsigned)H.v0; + R.minutes = (unsigned)M.v0; + R.seconds = (unsigned)S.v0; + R.micros = (unsigned)U.v0 * 1000; } msg_time(R) ::= MSG_TIME(M) . { - R.hours = (guint)M.v0; - R.minutes = (guint)M.v1; - R.seconds = (guint)M.v2; - R.micros = (guint)M.v3 * 100; + R.hours = (unsigned)M.v0; + R.minutes = (unsigned)M.v1; + R.seconds = (unsigned)M.v2; + R.micros = (unsigned)M.v3 * 100; } msg_id(R) ::= INT(V) . { - R = (guint)V.v0; + R = (unsigned)V.v0; } msg_length(R) ::= INT(V) . { - R = (guint)V.v0; + R = (unsigned)V.v0; } msg_type(R) ::= MSG_TYPE(V) . @@ -320,7 +321,7 @@ data(R) ::= data64(A) . { R = A; } byte(R) ::= INT(A) . { - R = (guint8)A.v0; + R = (uint8_t)A.v0; } data0(R) ::= . @@ -375,9 +376,9 @@ data64(R) ::= data32(A) data32(B) . { merge_msg_data(&R, &A, &B); } #include "busmaster_scanner_lex.h" #include "busmaster_parser.h" -gboolean +bool run_busmaster_parser(busmaster_state_t *state, - int *err, gchar **err_info) + int *err, char **err_info) { int lex_code; yyscan_t scanner; @@ -392,7 +393,7 @@ run_busmaster_parser(busmaster_state_t *state, { *err = errno; *err_info = g_strdup(g_strerror(errno)); - return FALSE; + return false; } parser = BusmasterParserAlloc(g_malloc); @@ -446,10 +447,10 @@ run_busmaster_parser(busmaster_state_t *state, else *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } - return TRUE; + return true; } } diff --git a/wiretap/busmaster_priv.h b/wiretap/busmaster_priv.h index 4c9cad67..633e4cf1 100644 --- a/wiretap/busmaster_priv.h +++ b/wiretap/busmaster_priv.h @@ -61,16 +61,16 @@ typedef enum { } msg_type_t; typedef struct { - guint year; - guint month; - guint day; + unsigned year; + unsigned month; + unsigned day; } msg_date_t; typedef struct { - guint hours; - guint minutes; - guint seconds; - guint micros; + unsigned hours; + unsigned minutes; + unsigned seconds; + unsigned micros; } msg_time_t; typedef struct { @@ -79,27 +79,27 @@ typedef struct { } msg_date_time_t; typedef struct { - guint length; - guint8 data[CANFD_MAX_DLEN]; + unsigned length; + uint8_t data[CANFD_MAX_DLEN]; } msg_data_t; typedef struct { msg_time_t timestamp; msg_type_t type; - guint32 id; + uint32_t id; msg_data_t data; } msg_t; typedef struct { - gint64 v0; - gint64 v1; - gint64 v2; - gint64 v3; + int64_t v0; + int64_t v1; + int64_t v2; + int64_t v3; } token_t; typedef struct { - gint64 file_start_offset; - gint64 file_end_offset; + int64_t file_start_offset; + int64_t file_end_offset; protocol_type_t protocol; data_mode_t data_mode; time_mode_t time_mode; @@ -109,11 +109,11 @@ typedef struct { typedef struct { FILE_T fh; - gint64 file_bytes_read; + int64_t file_bytes_read; - gchar *parse_error; + char *parse_error; int err; - gchar *err_info; + char *err_info; token_t token; @@ -122,9 +122,9 @@ typedef struct { msg_t msg; } busmaster_state_t; -gboolean +bool run_busmaster_parser(busmaster_state_t *state, - int *err, gchar **err_info); + int *err, char **err_info); #ifdef BUSMASTER_DEBUG #include <stdio.h> diff --git a/wiretap/camins.c b/wiretap/camins.c index 27d26111..bd3c8d79 100644 --- a/wiretap/camins.c +++ b/wiretap/camins.c @@ -52,14 +52,13 @@ */ #include "config.h" +#include "camins.h" #include <glib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "camins.h" - #define TRANS_CAM_HOST 0x20 #define TRANS_READ_SIZE_LOW 0x22 @@ -78,7 +77,7 @@ /* a timestamp consists of a 2-bit position, followed by an 11-bit value. */ #define TS_VALUE_SHIFT 11 #define TS_POS_MASK (0x3 << TS_VALUE_SHIFT) -#define TS_VALUE_MASK G_GUINT64_CONSTANT((1 << TS_VALUE_SHIFT) - 1) +#define TS_VALUE_MASK (UINT64_C((1 << TS_VALUE_SHIFT) - 1)) typedef enum { SIZE_HAVE_NONE, @@ -123,12 +122,12 @@ void register_camins(void); static wtap_open_return_val detect_camins_file(FILE_T fh) { int err; - gchar *err_info; - guint8 block[2]; - guint8 search_block = 0; - guint8 gap_count = 0; - guint32 valid_pairs = 0, invalid_pairs = 0; - guint64 read_bytes = 0; + char *err_info; + uint8_t block[2]; + uint8_t search_block = 0; + uint8_t gap_count = 0; + uint32_t valid_pairs = 0, invalid_pairs = 0; + uint64_t read_bytes = 0; while (wtap_read_bytes(fh, block, sizeof(block), &err, &err_info)) { if (search_block != 0) { @@ -193,10 +192,10 @@ static wtap_open_return_val detect_camins_file(FILE_T fh) /* update the current time counter with infos from a timestamp block */ -static void process_timestamp(guint16 timestamp, guint64 *time_us) +static void process_timestamp(uint16_t timestamp, uint64_t *time_us) { - guint8 pos, shift; - guint64 val; + uint8_t pos, shift; + uint64_t val; if (!time_us) return; @@ -216,25 +215,25 @@ static void process_timestamp(guint16 timestamp, guint64 *time_us) to retrieve the data if requested by the caller, we increment the time counter as we walk through the file */ -static gboolean +static bool find_next_pkt_info(FILE_T fh, - guint8 *dat_trans_type, /* transaction type used for the data bytes */ - guint16 *dat_len, /* the number of data bytes in the packet */ - guint64 *time_us, - int *err, gchar **err_info) + uint8_t *dat_trans_type, /* transaction type used for the data bytes */ + uint16_t *dat_len, /* the number of data bytes in the packet */ + uint64_t *time_us, + int *err, char **err_info) { - guint8 block[2]; + uint8_t block[2]; size_read_t size_stat; if (!dat_trans_type || !dat_len) - return FALSE; + return false; RESET_STAT_VALS; do { if (!wtap_read_bytes_or_eof(fh, block, sizeof(block), err, err_info)) { RESET_STAT_VALS; - return FALSE; + return false; } /* our strategy is to continue reading until we have a high and a @@ -277,19 +276,19 @@ find_next_pkt_info(FILE_T fh, } } while (size_stat != SIZE_HAVE_ALL); - return TRUE; + return true; } /* buffer allocated by the caller, must be long enough to hold dat_len bytes, ... */ -static gint -read_packet_data(FILE_T fh, guint8 dat_trans_type, guint8 *buf, guint16 dat_len, - guint64 *time_us, int *err, gchar **err_info) +static int +read_packet_data(FILE_T fh, uint8_t dat_trans_type, uint8_t *buf, uint16_t dat_len, + uint64_t *time_us, int *err, char **err_info) { - guint8 *p; - guint8 block[2]; - guint16 bytes_count = 0; + uint8_t *p; + uint8_t block[2]; + uint16_t bytes_count = 0; if (!buf) return -1; @@ -313,7 +312,7 @@ read_packet_data(FILE_T fh, guint8 dat_trans_type, guint8 *buf, guint16 dat_len, else if (IS_TRANS_SIZE(block[1])) { /* go back before the size transaction block the next packet should be able to pick up this block */ - if (-1 == file_seek(fh, -(gint64)sizeof(block), SEEK_CUR, err)) + if (-1 == file_seek(fh, -(int64_t)sizeof(block), SEEK_CUR, err)) return -1; break; } @@ -325,9 +324,9 @@ read_packet_data(FILE_T fh, guint8 dat_trans_type, guint8 *buf, guint16 dat_len, /* create a DVB-CI pseudo header return its length or -1 for error */ -static gint -create_pseudo_hdr(guint8 *buf, guint8 dat_trans_type, guint16 dat_len, - gchar **err_info) +static int +create_pseudo_hdr(uint8_t *buf, uint8_t dat_trans_type, uint16_t dat_len, + char **err_info) { buf[0] = DVB_CI_PSEUDO_HDR_VER; @@ -347,18 +346,18 @@ create_pseudo_hdr(guint8 *buf, guint8 dat_trans_type, guint16 dat_len, } -static gboolean +static bool camins_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, - guint64 *time_us, int *err, gchar **err_info) + uint64_t *time_us, int *err, char **err_info) { - guint8 dat_trans_type; - guint16 dat_len; - guint8 *p; - gint offset, bytes_read; + uint8_t dat_trans_type; + uint16_t dat_len; + uint8_t *p; + int offset, bytes_read; if (!find_next_pkt_info( fh, &dat_trans_type, &dat_len, time_us, err, err_info)) - return FALSE; + return false; /* * The maximum value of length is 65535, which, even after * DVB_CI_PSEUDO_HDR_LEN is added to it, is less than @@ -374,7 +373,7 @@ camins_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, find_next_pkt_info() */ *err = WTAP_ERR_INTERNAL; /* create_pseudo_hdr() set err_info appropriately */ - return FALSE; + return false; } bytes_read = read_packet_data(fh, dat_trans_type, @@ -382,7 +381,7 @@ camins_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, /* 0<=bytes_read<=dat_len is very likely a corrupted packet we let the dissector handle this */ if (bytes_read < 0) - return FALSE; + return false; offset += bytes_read; rec->rec_type = REC_TYPE_PACKET; @@ -397,33 +396,33 @@ camins_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, rec->rec_header.packet_header.caplen = offset; rec->rec_header.packet_header.len = offset; - return TRUE; + return true; } -static gboolean +static bool camins_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); - return camins_read_packet(wth->fh, rec, buf, (guint64 *)(wth->priv), + return camins_read_packet(wth->fh, rec, buf, (uint64_t *)(wth->priv), err, err_info); } -static gboolean -camins_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +static bool +camins_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err)) - return FALSE; + return false; return camins_read_packet(wth->random_fh, rec, buf, NULL, err, err_info); } -wtap_open_return_val camins_open(wtap *wth, int *err, gchar **err_info _U_) +wtap_open_return_val camins_open(wtap *wth, int *err, char **err_info _U_) { wtap_open_return_val status; @@ -443,7 +442,7 @@ wtap_open_return_val camins_open(wtap *wth, int *err, gchar **err_info _U_) /* wth->priv stores a pointer to the global time counter. we update it as we go through the file sequentially. */ - wth->priv = g_new0(guint64, 1); + wth->priv = g_new0(uint64_t, 1); wth->subtype_read = camins_read; wth->subtype_seek_read = camins_seek_read; @@ -471,7 +470,7 @@ static const struct supported_block_type camins_blocks_supported[] = { static const struct file_type_subtype_info camins_info = { "CAM Inspector file", "camins", "camins", NULL, - FALSE, BLOCKS_SUPPORTED(camins_blocks_supported), + false, BLOCKS_SUPPORTED(camins_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/camins.h b/wiretap/camins.h index 090dd30c..31ea82f4 100644 --- a/wiretap/camins.h +++ b/wiretap/camins.h @@ -16,6 +16,6 @@ #include <glib.h> #include <wiretap/wtap.h> -wtap_open_return_val camins_open(wtap *wth, int *err, gchar **err_info _U_); +wtap_open_return_val camins_open(wtap *wth, int *err, char **err_info _U_); #endif /* _CAMINS_H */ diff --git a/wiretap/candump.c b/wiretap/candump.c index 15a0ca16..80412fac 100644 --- a/wiretap/candump.c +++ b/wiretap/candump.c @@ -10,21 +10,22 @@ */ #include <config.h> +#include "candump.h" + #include <wtap-int.h> #include <file_wrappers.h> #include <wsutil/exported_pdu_tlvs.h> #include <string.h> #include <inttypes.h> #include <errno.h> -#include "candump.h" #include "candump_priv.h" -static gboolean candump_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, - gint64 *data_offset); -static gboolean candump_seek_read(wtap *wth, gint64 seek_off, +static bool candump_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, + int64_t *data_offset); +static bool candump_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + int *err, char **err_info); static int candump_file_type_subtype = -1; @@ -34,21 +35,12 @@ void register_candump(void); * This is written by the candump utility on Linux. */ -static gboolean -candump_write_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg, int *err, - gchar **err_info) +static bool +candump_gen_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg, int *err, + char **err_info) { /* Generate Exported PDU tags for the packet info */ ws_buffer_clean(buf); - if (msg->is_fd) - { - wtap_buffer_append_epdu_string(buf, EXP_PDU_TAG_DISSECTOR_NAME, "canfd"); - } - else - { - wtap_buffer_append_epdu_string(buf, EXP_PDU_TAG_DISSECTOR_NAME, "can-hostendian"); - } - wtap_buffer_append_epdu_end(buf); if (msg->is_fd) { @@ -63,15 +55,15 @@ candump_write_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg, int *err, *err_info = ws_strdup_printf("candump: File has %u-byte CAN FD packet, bigger than maximum of %u", msg->data.length, CANFD_MAX_DLEN); } - return FALSE; + return false; } - canfd_frame.can_id = msg->id; - canfd_frame.flags = msg->flags; + canfd_frame.can_id = g_htonl(msg->id); + canfd_frame.flags = msg->flags | CANFD_FDF; canfd_frame.len = msg->data.length; memcpy(canfd_frame.data, msg->data.data, msg->data.length); - ws_buffer_append(buf, (guint8 *)&canfd_frame, sizeof(canfd_frame)); + ws_buffer_append(buf, (uint8_t *)&canfd_frame, sizeof(canfd_frame)); } else { @@ -86,14 +78,14 @@ candump_write_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg, int *err, *err_info = ws_strdup_printf("candump: File has %u-byte CAN packet, bigger than maximum of %u", msg->data.length, CAN_MAX_DLEN); } - return FALSE; + return false; } - can_frame.can_id = msg->id; + can_frame.can_id = g_htonl(msg->id); can_frame.can_dlc = msg->data.length; memcpy(can_frame.data, msg->data.data, msg->data.length); - ws_buffer_append(buf, (guint8 *)&can_frame, sizeof(can_frame)); + ws_buffer_append(buf, (uint8_t *)&can_frame, sizeof(can_frame)); } rec->rec_type = REC_TYPE_PACKET; @@ -102,18 +94,18 @@ candump_write_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg, int *err, rec->ts = msg->ts; rec->tsprec = WTAP_TSPREC_USEC; - rec->rec_header.packet_header.caplen = (guint32)ws_buffer_length(buf); - rec->rec_header.packet_header.len = (guint32)ws_buffer_length(buf); + rec->rec_header.packet_header.caplen = (uint32_t)ws_buffer_length(buf); + rec->rec_header.packet_header.len = (uint32_t)ws_buffer_length(buf); - return TRUE; + return true; } -static gboolean -candump_parse(FILE_T fh, msg_t *msg, gint64 *offset, int *err, char **err_info) +static bool +candump_parse(FILE_T fh, msg_t *msg, int64_t *offset, int *err, char **err_info) { candump_state_t state = {0}; - gboolean ok; - gint64 seek_off; + bool ok; + int64_t seek_off; #ifdef CANDUMP_DEBUG candump_debug_printf("%s: Trying candump file decoder\n", G_STRFUNC); @@ -124,7 +116,7 @@ candump_parse(FILE_T fh, msg_t *msg, gint64 *offset, int *err, char **err_info) do { if (file_eof(fh)) - return FALSE; + return false; seek_off = file_tell(fh); #ifdef CANDUMP_DEBUG @@ -139,13 +131,13 @@ candump_parse(FILE_T fh, msg_t *msg, gint64 *offset, int *err, char **err_info) g_free(*err_info); *err = errno; *err_info = g_strdup(g_strerror(errno)); - return FALSE; + return false; } } while (ok && !state.is_msg_valid); if (!ok) - return FALSE; + return false; #ifdef CANDUMP_DEBUG candump_debug_printf("%s: Success\n", G_STRFUNC); @@ -157,7 +149,7 @@ candump_parse(FILE_T fh, msg_t *msg, gint64 *offset, int *err, char **err_info) if (msg) *msg = state.msg; - return TRUE; + return true; } wtap_open_return_val @@ -187,7 +179,7 @@ candump_open(wtap *wth, int *err, char **err_info) wth->priv = NULL; wth->file_type_subtype = candump_file_type_subtype; - wth->file_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU; + wth->file_encap = WTAP_ENCAP_SOCKETCAN; wth->file_tsprec = WTAP_TSPREC_USEC; wth->subtype_read = candump_read; wth->subtype_seek_read = candump_seek_read; @@ -195,9 +187,9 @@ candump_open(wtap *wth, int *err, char **err_info) return WTAP_OPEN_MINE; } -static gboolean -candump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, - gint64 *data_offset) +static bool +candump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, + int64_t *data_offset) { msg_t msg; @@ -206,18 +198,18 @@ candump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, #endif if (!candump_parse(wth->fh, &msg, data_offset, err, err_info)) - return FALSE; + return false; #ifdef CANDUMP_DEBUG candump_debug_printf("%s: Stopped at offset %" PRIi64 "\n", G_STRFUNC, file_tell(wth->fh)); #endif - return candump_write_packet(rec, buf, &msg, err, err_info); + return candump_gen_packet(rec, buf, &msg, err, err_info); } -static gboolean -candump_seek_read(wtap *wth , gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +candump_seek_read(wtap *wth , int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { msg_t msg; @@ -230,13 +222,13 @@ candump_seek_read(wtap *wth , gint64 seek_off, wtap_rec *rec, *err = errno; *err_info = g_strdup(g_strerror(errno)); - return FALSE; + return false; } if (!candump_parse(wth->random_fh, &msg, NULL, err, err_info)) - return FALSE; + return false; - return candump_write_packet(rec, buf, &msg, err, err_info); + return candump_gen_packet(rec, buf, &msg, err, err_info); } static const struct supported_block_type candump_blocks_supported[] = { @@ -248,7 +240,7 @@ static const struct supported_block_type candump_blocks_supported[] = { static const struct file_type_subtype_info candump_info = { "Linux candump file", "candump", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(candump_blocks_supported), + false, BLOCKS_SUPPORTED(candump_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/candump_parser.lemon b/wiretap/candump_parser.lemon index 149c3a7d..039da94e 100644 --- a/wiretap/candump_parser.lemon +++ b/wiretap/candump_parser.lemon @@ -17,6 +17,7 @@ #include <assert.h> #include <string.h> #include <wiretap/file_wrappers.h> +#include <wsutil/array.h> #include "candump_priv.h" extern void *CandumpParserAlloc(void *(*mallocProc)(size_t)); @@ -62,7 +63,7 @@ DIAG_ON_LEMON() (void)yyminor; #ifdef CANDUMP_DEBUG - const int n = sizeof(yyTokenName) / sizeof(yyTokenName[0]); + const int n = array_length(yyTokenName); candump_debug_printf("%s: got token: %s\n", G_STRFUNC, yyTokenName[yymajor]); for (int i = 0; i < n; ++i) { int a = yy_find_shift_action((YYCODETYPE)i, yypParser->yytos->stateno); @@ -91,10 +92,10 @@ DIAG_ON_LEMON() %type msg { msg_t } %type timestamp { nstime_t } -%type id { guint32 } -%type flags { guint8 } +%type id { uint32_t } +%type flags { uint8_t } -%type byte { guint8 } +%type byte { uint8_t } %type data_max_8 { msg_data_t } %type data_max_64 { msg_data_t } %type data0 { msg_data_t } @@ -123,7 +124,7 @@ line ::= maybe_spaces msg(M) . #endif state->msg = M; - state->is_msg_valid = TRUE; + state->is_msg_valid = true; } line ::= maybe_spaces . @@ -139,9 +140,9 @@ maybe_spaces ::= . msg(M) ::= timestamp(T) SPACE ifname SPACE id(I) RTR(R) . { M.ts = T; - M.is_fd = FALSE; + M.is_fd = false; M.id = I | CAN_RTR_FLAG; - M.data.length = (guint8)R.v0; + M.data.length = (uint8_t)R.v0; memset(M.data.data, 0, sizeof(M.data.data)); } @@ -149,7 +150,7 @@ msg(M) ::= timestamp(T) SPACE ifname SPACE id(I) RTR(R) . msg(M) ::= timestamp(T) SPACE ifname SPACE id(I) data_max_8(D) . { M.ts = T; - M.is_fd = FALSE; + M.is_fd = false; M.id = I; M.data = D; } @@ -157,7 +158,7 @@ msg(M) ::= timestamp(T) SPACE ifname SPACE id(I) data_max_8(D) . msg(M) ::= timestamp(T) SPACE ifname SPACE id(I) flags(F) data_max_64(D) . { M.ts = T; - M.is_fd = TRUE; + M.is_fd = true; M.id = I; M.flags = F; M.data = D; @@ -182,12 +183,12 @@ any ::= BYTE . id(R) ::= STD_ID(A) . { - R = (guint32)A.v0; + R = (uint32_t)A.v0; } id(R) ::= EXT_ID(A) . { - R = (guint32)A.v0; + R = (uint32_t)A.v0; if (!(R & CAN_ERR_FLAG)) R |= CAN_EFF_FLAG; @@ -195,7 +196,7 @@ id(R) ::= EXT_ID(A) . flags(R) ::= FLAGS(A) . { - R = (guint8)A.v0; + R = (uint8_t)A.v0; } data_max_8 ::= data0 . @@ -219,7 +220,7 @@ data_max_64 ::= data64 . byte(R) ::= BYTE(A) . { - R = (guint8)A.v0; + R = (uint8_t)A.v0; } data0(R) ::= . @@ -274,8 +275,8 @@ data64(R) ::= data32(A) data32(B) . { merge_msg_data(&R, &A, &B); } #include "candump_scanner_lex.h" #include "candump_parser.h" -gboolean -run_candump_parser(candump_state_t *state, int *err, gchar **err_info) +bool +run_candump_parser(candump_state_t *state, int *err, char **err_info) { int lex_code; yyscan_t scanner; @@ -290,7 +291,7 @@ run_candump_parser(candump_state_t *state, int *err, gchar **err_info) *err = errno; *err_info = g_strdup(g_strerror(errno)); - return FALSE; + return false; } parser = CandumpParserAlloc(g_malloc); @@ -346,10 +347,10 @@ run_candump_parser(candump_state_t *state, int *err, gchar **err_info) else *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } - return TRUE; + return true; } } diff --git a/wiretap/candump_priv.h b/wiretap/candump_priv.h index 417a44d4..1e5ba977 100644 --- a/wiretap/candump_priv.h +++ b/wiretap/candump_priv.h @@ -20,21 +20,21 @@ //#define CANDUMP_DEBUG typedef struct { - guint8 length; - guint8 data[CANFD_MAX_DLEN]; + uint8_t length; + uint8_t data[CANFD_MAX_DLEN]; } msg_data_t; typedef struct { nstime_t ts; - guint32 id; - gboolean is_fd; - guint8 flags; + uint32_t id; + bool is_fd; + uint8_t flags; msg_data_t data; } msg_t; typedef struct { - gint64 v0; - gint64 v1; + int64_t v0; + int64_t v1; } token_t; typedef struct { @@ -43,21 +43,21 @@ typedef struct { } candump_priv_t; typedef struct { - gboolean is_msg_valid; + bool is_msg_valid; msg_t msg; FILE_T fh; - guint64 file_bytes_read; + uint64_t file_bytes_read; int err; - gchar *err_info; - gchar *parse_error; + char *err_info; + char *parse_error; token_t token; } candump_state_t; -gboolean -run_candump_parser(candump_state_t *state, int *err, gchar **err_info); +bool +run_candump_parser(candump_state_t *state, int *err, char **err_info); #ifdef CANDUMP_DEBUG #include <stdio.h> diff --git a/wiretap/capsa.c b/wiretap/capsa.c index 6083e38f..31057d10 100644 --- a/wiretap/capsa.c +++ b/wiretap/capsa.c @@ -7,10 +7,11 @@ */ #include "config.h" +#include "capsa.h" + #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "capsa.h" #include <wsutil/ws_assert.h> /* @@ -69,61 +70,61 @@ static const char capsa_magic[] = { /* Capsa (format indicator 1) record header. */ struct capsarec_hdr { - guint32 unknown1; /* low-order 32 bits of a number? */ - guint32 unknown2; /* 0x00 0x00 0x00 0x00 */ - guint32 timestamplo; /* low-order 32 bits of the time stamp, in microseconds since January 1, 1970, 00:00:00 UTC */ - guint32 timestamphi; /* high-order 32 bits of the time stamp, in microseconds since January 1, 1970, 00:00:00 UTC */ - guint16 rec_len; /* length of record */ - guint16 incl_len; /* number of octets captured in file */ - guint16 orig_len; /* actual length of packet */ - guint16 unknown5; /* 0x00 0x00 */ - guint8 count1; /* count1*4 bytes after unknown8 */ - guint8 count2; /* count2*4 bytes after that */ - guint16 unknown7; /* 0x01 0x10 */ - guint32 unknown8; /* 0x00 0x00 0x00 0x00 or random numbers */ + uint32_t unknown1; /* low-order 32 bits of a number? */ + uint32_t unknown2; /* 0x00 0x00 0x00 0x00 */ + uint32_t timestamplo; /* low-order 32 bits of the time stamp, in microseconds since January 1, 1970, 00:00:00 UTC */ + uint32_t timestamphi; /* high-order 32 bits of the time stamp, in microseconds since January 1, 1970, 00:00:00 UTC */ + uint16_t rec_len; /* length of record */ + uint16_t incl_len; /* number of octets captured in file */ + uint16_t orig_len; /* actual length of packet */ + uint16_t unknown5; /* 0x00 0x00 */ + uint8_t count1; /* count1*4 bytes after unknown8 */ + uint8_t count2; /* count2*4 bytes after that */ + uint16_t unknown7; /* 0x01 0x10 */ + uint32_t unknown8; /* 0x00 0x00 0x00 0x00 or random numbers */ }; /* Packet Builder (format indicator 2) record header. */ struct pbrec_hdr { - guint16 rec_len; /* length of record */ - guint16 incl_len; /* number of octets captured in file */ - guint16 orig_len; /* actual length of packet */ - guint16 unknown1; - guint16 unknown2; - guint16 unknown3; - guint32 unknown4; - guint32 timestamplo; /* low-order 32 bits of the time stamp, in microseconds since January 1, 1970, 00:00:00 UTC */ - guint32 timestamphi; /* high-order 32 bits of the time stamp, in microseconds since January 1, 1970, 00:00:00 UTC */ - guint32 unknown5; - guint32 unknown6; + uint16_t rec_len; /* length of record */ + uint16_t incl_len; /* number of octets captured in file */ + uint16_t orig_len; /* actual length of packet */ + uint16_t unknown1; + uint16_t unknown2; + uint16_t unknown3; + uint32_t unknown4; + uint32_t timestamplo; /* low-order 32 bits of the time stamp, in microseconds since January 1, 1970, 00:00:00 UTC */ + uint32_t timestamphi; /* high-order 32 bits of the time stamp, in microseconds since January 1, 1970, 00:00:00 UTC */ + uint32_t unknown5; + uint32_t unknown6; }; typedef struct { - guint16 format_indicator; - guint32 number_of_frames; - guint32 frame_count; - gint64 base_offset; - guint32 record_offsets[N_RECORDS_PER_GROUP]; + uint16_t format_indicator; + uint32_t number_of_frames; + uint32_t frame_count; + int64_t base_offset; + uint32_t record_offsets[N_RECORDS_PER_GROUP]; } capsa_t; -static gboolean capsa_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean capsa_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool capsa_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool capsa_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); + Buffer *buf, int *err, char **err_info); static int capsa_file_type_subtype = -1; static int packet_builder_file_type_subtype = -1; void register_capsa(void); -wtap_open_return_val capsa_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val capsa_open(wtap *wth, int *err, char **err_info) { char magic[sizeof capsa_magic]; - guint16 format_indicator; + uint16_t format_indicator; int file_type_subtype; - guint32 number_of_frames; + uint32_t number_of_frames; capsa_t *capsa; /* Read in the string that should be at the start of a Capsa file */ @@ -231,11 +232,11 @@ wtap_open_return_val capsa_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean capsa_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool capsa_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { capsa_t *capsa = (capsa_t *)wth->priv; - guint32 frame_within_block; + uint32_t frame_within_block; int padbytes; if (capsa->frame_count == capsa->number_of_frames) { @@ -243,7 +244,7 @@ static gboolean capsa_read(wtap *wth, wtap_rec *rec, Buffer *buf, * No more frames left. Return an EOF. */ *err = 0; - return FALSE; + return false; } frame_within_block = capsa->frame_count % N_RECORDS_PER_GROUP; if (frame_within_block == 0) { @@ -254,72 +255,72 @@ static gboolean capsa_read(wtap *wth, wtap_rec *rec, Buffer *buf, */ capsa->base_offset = file_tell(wth->fh); if (!wtap_read_bytes(wth->fh, NULL, 1, err, err_info)) - return FALSE; + return false; /* * Now read the record offsets. */ if (!wtap_read_bytes(wth->fh, &capsa->record_offsets, sizeof capsa->record_offsets, err, err_info)) - return FALSE; + return false; /* * And finish processing all 805 bytes by skipping * the last 4 bytes. */ if (!wtap_read_bytes(wth->fh, NULL, 4, err, err_info)) - return FALSE; + return false; } *data_offset = capsa->base_offset + GUINT32_FROM_LE(capsa->record_offsets[frame_within_block]); if (!file_seek(wth->fh, *data_offset, SEEK_SET, err)) - return FALSE; + return false; padbytes = capsa_read_packet(wth, wth->fh, rec, buf, err, err_info); if (padbytes == -1) - return FALSE; + return false; /* * Skip over the padding, if any. */ if (padbytes != 0) { if (!wtap_read_bytes(wth->fh, NULL, padbytes, err, err_info)) - return FALSE; + return false; } capsa->frame_count++; - return TRUE; + return true; } -static gboolean -capsa_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +capsa_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (capsa_read_packet(wth, wth->random_fh, rec, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } static int capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { capsa_t *capsa = (capsa_t *)wth->priv; struct capsarec_hdr capsarec_hdr; struct pbrec_hdr pbrec_hdr; - guint32 rec_size; - guint32 packet_size; - guint32 orig_size; - guint32 header_size; - guint64 timestamp; + uint32_t rec_size; + uint32_t packet_size; + uint32_t orig_size; + uint32_t header_size; + uint64_t timestamp; /* Read record header. */ switch (capsa->format_indicator) { @@ -332,7 +333,7 @@ capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, orig_size = GUINT16_FROM_LE(capsarec_hdr.orig_len); packet_size = GUINT16_FROM_LE(capsarec_hdr.incl_len); header_size = sizeof capsarec_hdr; - timestamp = (((guint64)GUINT32_FROM_LE(capsarec_hdr.timestamphi))<<32) + GUINT32_FROM_LE(capsarec_hdr.timestamplo); + timestamp = (((uint64_t)GUINT32_FROM_LE(capsarec_hdr.timestamphi))<<32) + GUINT32_FROM_LE(capsarec_hdr.timestamplo); /* * OK, the rest of this is variable-length. @@ -355,7 +356,7 @@ capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, orig_size = GUINT16_FROM_LE(pbrec_hdr.orig_len); packet_size = GUINT16_FROM_LE(pbrec_hdr.incl_len); header_size = sizeof pbrec_hdr; - timestamp = (((guint64)GUINT32_FROM_LE(pbrec_hdr.timestamphi))<<32) + GUINT32_FROM_LE(pbrec_hdr.timestamplo); + timestamp = (((uint64_t)GUINT32_FROM_LE(pbrec_hdr.timestamphi))<<32) + GUINT32_FROM_LE(pbrec_hdr.timestamplo); /* * XXX - from the results of some conversions between * Capsa format and pcap by Colasoft Packet Builder, @@ -444,7 +445,7 @@ static const struct supported_block_type capsa_blocks_supported[] = { static const struct file_type_subtype_info capsa_info = { "Colasoft Capsa format", "capsa", "cscpkt", NULL, - FALSE, BLOCKS_SUPPORTED(capsa_blocks_supported), + false, BLOCKS_SUPPORTED(capsa_blocks_supported), NULL, NULL, NULL }; @@ -457,7 +458,7 @@ static const struct supported_block_type packet_builder_blocks_supported[] = { static const struct file_type_subtype_info packet_builder_info = { "Colasoft Packet Builder format", "colasoft-pb", "cscpkt", NULL, - FALSE, BLOCKS_SUPPORTED(packet_builder_blocks_supported), + false, BLOCKS_SUPPORTED(packet_builder_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/capsa.h b/wiretap/capsa.h index 2ec42577..30c7acf3 100644 --- a/wiretap/capsa.h +++ b/wiretap/capsa.h @@ -13,6 +13,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val capsa_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val capsa_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c index c7f1dde3..94e05511 100644 --- a/wiretap/catapult_dct2000.c +++ b/wiretap/catapult_dct2000.c @@ -7,6 +7,8 @@ */ #include "config.h" +#include "catapult_dct2000.h" + #include <errno.h> #include <string.h> #include <stdlib.h> @@ -16,8 +18,6 @@ #include "wtap-int.h" #include "file_wrappers.h" -#include "catapult_dct2000.h" - #define MAX_FIRST_LINE_LENGTH 150 #define MAX_TIMESTAMP_LINE_LENGTH 50 #define MAX_LINE_LENGTH 131072 @@ -45,8 +45,8 @@ typedef enum packet_direction_t /* - Whether or not " l " appears after timestamp */ typedef struct { - gchar *before_time; - gboolean has_l; + char *before_time; + bool has_l; } line_prefix_info_t; @@ -56,7 +56,7 @@ typedef struct dct2000_file_externals { /* Remember the time at the start of capture */ time_t start_secs; - guint32 start_usecs; + uint32_t start_usecs; /* * The following information is needed only for dumping. @@ -67,12 +67,12 @@ typedef struct dct2000_file_externals */ /* Buffer to hold first line, including magic and format number */ - gchar firstline[MAX_FIRST_LINE_LENGTH]; - gint firstline_length; + char firstline[MAX_FIRST_LINE_LENGTH]; + int firstline_length; /* Buffer to hold second line with formatted file creation data/time */ - gchar secondline[MAX_TIMESTAMP_LINE_LENGTH]; - gint secondline_length; + char secondline[MAX_TIMESTAMP_LINE_LENGTH]; + int secondline_length; /* Hash table to store text prefix data part of displayed packets. Records (file offset -> line_prefix_info_t) @@ -81,70 +81,70 @@ typedef struct dct2000_file_externals } dct2000_file_externals_t; /* 'Magic number' at start of Catapult DCT2000 .out files. */ -static const gchar catapult_dct2000_magic[] = "Session Transcript"; +static const char catapult_dct2000_magic[] = "Session Transcript"; /************************************************************/ /* Functions called from wiretap core */ -static gboolean catapult_dct2000_read(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, - gint64 *data_offset); -static gboolean catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, +static bool catapult_dct2000_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, + int64_t *data_offset); +static bool catapult_dct2000_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info); + char **err_info); static void catapult_dct2000_close(wtap *wth); -static gboolean catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); +static bool catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); /************************************************************/ /* Private helper functions */ -static gboolean read_new_line(FILE_T fh, gint *length, - gchar *buf, size_t bufsize, int *err, - gchar **err_info); -static gboolean parse_line(char *linebuff, gint line_length, - gint *seconds, gint *useconds, +static bool read_new_line(FILE_T fh, int *length, + char *buf, size_t bufsize, int *err, + char **err_info); +static bool parse_line(char *linebuff, int line_length, + int *seconds, int *useconds, long *before_time_offset, long *after_time_offset, long *data_offset, - gint *data_chars, + int *data_chars, packet_direction_t *direction, - int *encap, int *is_comment, int *is_sprint, - gchar *aal_header_chars, - gchar *context_name, guint8 *context_portp, - gchar *protocol_name, gchar *variant_name, - gchar *outhdr_name); -static gboolean process_parsed_line(wtap *wth, - dct2000_file_externals_t *file_externals, + int *encap, bool *is_comment, bool *is_sprint, + char *aal_header_chars, + char *context_name, uint8_t *context_portp, + char *protocol_name, char *variant_name, + char *outhdr_name); +static bool process_parsed_line(wtap *wth, + const dct2000_file_externals_t *file_externals, wtap_rec *rec, - Buffer *buf, gint64 file_offset, + Buffer *buf, int64_t file_offset, char *linebuff, long dollar_offset, int seconds, int useconds, - gchar *timestamp_string, + char *timestamp_string, packet_direction_t direction, int encap, - gchar *context_name, guint8 context_port, - gchar *protocol_name, gchar *variant_name, - gchar *outhdr_name, gchar *aal_header_chars, - gboolean is_comment, int data_chars, - int *err, gchar **err_info); -static guint8 hex_from_char(gchar c); + char *context_name, uint8_t context_port, + char *protocol_name, char *variant_name, + char *outhdr_name, char *aal_header_chars, + bool is_comment, int data_chars, + int *err, char **err_info); +static uint8_t hex_from_char(char c); static void prepare_hex_byte_from_chars_table(void); -static guint8 hex_byte_from_chars(gchar *c); -static gchar char_from_hex(guint8 hex); +static uint8_t hex_byte_from_chars(char *c); +static char char_from_hex(uint8_t hex); static void set_aal_info(union wtap_pseudo_header *pseudo_header, packet_direction_t direction, - gchar *aal_header_chars); + char *aal_header_chars); static void set_isdn_info(union wtap_pseudo_header *pseudo_header, packet_direction_t direction); static void set_ppp_info(union wtap_pseudo_header *pseudo_header, packet_direction_t direction); -static gint packet_offset_equal(gconstpointer v, gconstpointer v2); -static guint packet_offset_hash_func(gconstpointer v); +static int packet_offset_equal(const void *v, const void *v2); +static unsigned packet_offset_hash_func(const void *v); -static gboolean get_file_time_stamp(gchar *linebuff, time_t *secs, guint32 *usecs); -static gboolean free_line_prefix_info(gpointer key, gpointer value, gpointer user_data); +static bool get_file_time_stamp(const char *linebuff, time_t *secs, uint32_t *usecs); +static gboolean free_line_prefix_info(void *key, void *value, void *user_data); static int dct2000_file_type_subtype = -1; @@ -155,14 +155,14 @@ void register_dct2000(void); /* Open file (for reading) */ /********************************************/ wtap_open_return_val -catapult_dct2000_open(wtap *wth, int *err, gchar **err_info) +catapult_dct2000_open(wtap *wth, int *err, char **err_info) { time_t timestamp; - guint32 usecs; - gint firstline_length = 0; + uint32_t usecs; + int firstline_length = 0; dct2000_file_externals_t *file_externals; - static gchar linebuff[MAX_LINE_LENGTH]; - static gboolean hex_byte_table_values_set = FALSE; + static char linebuff[MAX_LINE_LENGTH]; + static bool hex_byte_table_values_set = false; /* Clear errno before reading from the file */ errno = 0; @@ -194,7 +194,7 @@ catapult_dct2000_open(wtap *wth, int *err, gchar **err_info) /* Make sure table is ready for use */ if (!hex_byte_table_values_set) { prepare_hex_byte_from_chars_table(); - hex_byte_table_values_set = TRUE; + hex_byte_table_values_set = true; } /*********************************************************************/ @@ -332,11 +332,11 @@ static void write_timestamp_string(char *timestamp_string, int secs, int tenthou /**************************************************/ /* Read packet function. */ /* Look for and read the next usable packet */ -/* - return TRUE and details if found */ +/* - return true and details if found */ /**************************************************/ -static gboolean +static bool catapult_dct2000_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) + int *err, char **err_info, int64_t *data_offset) { long dollar_offset, before_time_offset, after_time_offset; packet_direction_t direction; @@ -349,16 +349,16 @@ catapult_dct2000_read(wtap *wth, wtap_rec *rec, Buffer *buf, /* Search for a line containing a usable packet */ while (1) { int line_length, seconds, useconds, data_chars; - int is_comment = FALSE; - int is_sprint = FALSE; - gint64 this_offset; - static gchar linebuff[MAX_LINE_LENGTH+1]; - gchar aal_header_chars[AAL_HEADER_CHARS]; - gchar context_name[MAX_CONTEXT_NAME]; - guint8 context_port = 0; - gchar protocol_name[MAX_PROTOCOL_NAME+1]; - gchar variant_name[MAX_VARIANT_DIGITS+1]; - gchar outhdr_name[MAX_OUTHDR_NAME+1]; + bool is_comment = false; + bool is_sprint = false; + int64_t this_offset; + static char linebuff[MAX_LINE_LENGTH+1]; + char aal_header_chars[AAL_HEADER_CHARS]; + char context_name[MAX_CONTEXT_NAME]; + uint8_t context_port = 0; + char protocol_name[MAX_PROTOCOL_NAME+1]; + char variant_name[MAX_VARIANT_DIGITS+1]; + char outhdr_name[MAX_OUTHDR_NAME+1]; /* Get starting offset of the line we're about to read */ this_offset = file_tell(wth->fh); @@ -367,7 +367,7 @@ catapult_dct2000_read(wtap *wth, wtap_rec *rec, Buffer *buf, if (!read_new_line(wth->fh, &line_length, linebuff, sizeof linebuff, err, err_info)) { if (*err != 0) { - return FALSE; /* error */ + return false; /* error */ } /* No more lines can be read, so quit. */ break; @@ -382,7 +382,7 @@ catapult_dct2000_read(wtap *wth, wtap_rec *rec, Buffer *buf, context_name, &context_port, protocol_name, variant_name, outhdr_name)) { line_prefix_info_t *line_prefix_info; - gint64 *pkey = NULL; + int64_t *pkey = NULL; char timestamp_string[MAX_TIMESTAMP_LEN+1]; write_timestamp_string(timestamp_string, seconds, useconds/100); @@ -402,13 +402,13 @@ catapult_dct2000_read(wtap *wth, wtap_rec *rec, Buffer *buf, outhdr_name, aal_header_chars, is_comment, data_chars, err, err_info)) - return FALSE; + return false; /* Store the packet prefix in the hash table */ line_prefix_info = g_new(line_prefix_info_t,1); /* Create and use buffer for contents before time */ - line_prefix_info->before_time = (gchar *)g_malloc(before_time_offset+1); + line_prefix_info->before_time = (char *)g_malloc(before_time_offset+1); memcpy(line_prefix_info->before_time, linebuff, before_time_offset); line_prefix_info->before_time[before_time_offset] = '\0'; @@ -417,39 +417,39 @@ catapult_dct2000_read(wtap *wth, wtap_rec *rec, Buffer *buf, (strncmp(linebuff+after_time_offset, " l ", 3) == 0); /* Add packet entry into table */ - pkey = (gint64 *)g_malloc(sizeof(*pkey)); + pkey = (int64_t *)g_malloc(sizeof(*pkey)); *pkey = this_offset; g_hash_table_insert(file_externals->packet_prefix_table, pkey, line_prefix_info); /* OK, we have packet details to return */ - return TRUE; + return true; } } /* No packet details to return... */ - return FALSE; + return false; } /**************************************************/ /* Read & seek function. */ /**************************************************/ -static gboolean -catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, +static bool +catapult_dct2000_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { int length; long dollar_offset, before_time_offset, after_time_offset; - static gchar linebuff[MAX_LINE_LENGTH+1]; - gchar aal_header_chars[AAL_HEADER_CHARS]; - gchar context_name[MAX_CONTEXT_NAME]; - guint8 context_port = 0; - gchar protocol_name[MAX_PROTOCOL_NAME+1]; - gchar variant_name[MAX_VARIANT_DIGITS+1]; - gchar outhdr_name[MAX_OUTHDR_NAME+1]; - int is_comment = FALSE; - int is_sprint = FALSE; + static char linebuff[MAX_LINE_LENGTH+1]; + char aal_header_chars[AAL_HEADER_CHARS]; + char context_name[MAX_CONTEXT_NAME]; + uint8_t context_port = 0; + char protocol_name[MAX_PROTOCOL_NAME+1]; + char variant_name[MAX_VARIANT_DIGITS+1]; + char outhdr_name[MAX_OUTHDR_NAME+1]; + bool is_comment = false; + bool is_sprint = false; packet_direction_t direction; int encap; int seconds, useconds, data_chars; @@ -463,13 +463,13 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, /* Seek to beginning of packet */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return FALSE; + return false; } /* Re-read whole line (this really should succeed) */ if (!read_new_line(wth->random_fh, &length, linebuff, sizeof linebuff, err, err_info)) { - return FALSE; + return false; } /* Try to parse this line again (should succeed as re-reading...) */ @@ -495,11 +495,11 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, outhdr_name, aal_header_chars, is_comment, data_chars, err, err_info)) { - return FALSE; + return false; } *err = errno = 0; - return TRUE; + return true; } /* If get here, must have failed */ @@ -507,7 +507,7 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, *err_info = ws_strdup_printf("catapult dct2000: seek_read failed to read/parse " "line at position %" PRId64, seek_off); - return FALSE; + return false; } @@ -536,7 +536,7 @@ catapult_dct2000_close(wtap *wth) /***************************/ typedef struct { - gboolean first_packet_written; + bool first_packet_written; nstime_t start_time; } dct2000_dump_t; @@ -544,13 +544,13 @@ typedef struct { /* The file that we are writing to has been opened. */ /* Set other dump callbacks. */ /*****************************************************/ -static gboolean -catapult_dct2000_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) +static bool +catapult_dct2000_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { /* Fill in other dump callbacks */ wdh->subtype_write = catapult_dct2000_dump; - return TRUE; + return true; } /*********************************************************/ @@ -576,16 +576,16 @@ catapult_dct2000_dump_can_write_encap(int encap) /* Write a single packet out to the file */ /*****************************************/ -static gboolean +static bool catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; - guint32 n; + uint32_t n; line_prefix_info_t *prefix = NULL; - gchar time_string[MAX_TIMESTAMP_LEN]; - gboolean is_comment; - gboolean is_sprint = FALSE; + char time_string[MAX_TIMESTAMP_LEN]; + bool is_comment; + bool is_sprint = false; dct2000_dump_t *dct2000; int consecutive_slashes=0; char *p_c; @@ -599,7 +599,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -609,7 +609,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } dct2000 = (dct2000_dump_t *)wdh->priv; @@ -618,10 +618,10 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, /* Write out saved first line */ if (!wtap_dump_file_write(wdh, file_externals->firstline, file_externals->firstline_length, err)) { - return FALSE; + return false; } if (!wtap_dump_file_write(wdh, "\n", 1, err)) { - return FALSE; + return false; } /* Also write out saved second line with timestamp corresponding to the @@ -629,10 +629,10 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (!wtap_dump_file_write(wdh, file_externals->secondline, file_externals->secondline_length, err)) { - return FALSE; + return false; } if (!wtap_dump_file_write(wdh, "\n", 1, err)) { - return FALSE; + return false; } /* Allocate the dct2000-specific dump structure */ @@ -645,7 +645,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, (file_externals->start_usecs * 1000); /* Set flag so don't write header out again */ - dct2000->first_packet_written = TRUE; + dct2000->first_packet_written = true; } @@ -659,7 +659,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, /* Write out text before timestamp */ if (!wtap_dump_file_write(wdh, prefix->before_time, strlen(prefix->before_time), err)) { - return FALSE; + return false; } /* Can infer from prefix if this is a comment (whose payload is displayed differently) */ @@ -688,13 +688,13 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, /* Write out the calculated timestamp */ if (!wtap_dump_file_write(wdh, time_string, strlen(time_string), err)) { - return FALSE; + return false; } /* Write out text between timestamp and start of hex data */ if (prefix->has_l) { if (!wtap_dump_file_write(wdh, " l ", 3, err)) { - return FALSE; + return false; } } @@ -734,35 +734,35 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, /**************************************/ /* Remainder is encapsulated protocol */ if (!wtap_dump_file_write(wdh, is_sprint ? " " : "$", 1, err)) { - return FALSE; + return false; } if (!is_comment) { /* Each binary byte is written out as 2 hex string chars */ for (; n < rec->rec_header.packet_header.len; n++) { - gchar c[2]; - c[0] = char_from_hex((guint8)(pd[n] >> 4)); - c[1] = char_from_hex((guint8)(pd[n] & 0x0f)); + char c[2]; + c[0] = char_from_hex((uint8_t)(pd[n] >> 4)); + c[1] = char_from_hex((uint8_t)(pd[n] & 0x0f)); /* Write both hex chars of byte together */ if (!wtap_dump_file_write(wdh, c, 2, err)) { - return FALSE; + return false; } } } else { /* Comment */ if (!wtap_dump_file_write(wdh, pd+n, rec->rec_header.packet_header.len-n, err)) { - return FALSE; + return false; } } /* End the line */ if (!wtap_dump_file_write(wdh, "\n", 1, err)) { - return FALSE; + return false; } - return TRUE; + return true; } @@ -774,23 +774,23 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec, /* Read a new line from the file, starting at offset. */ /* - writes data to its argument linebuff */ /* - on return 'offset' will point to the next position to read from */ -/* - return TRUE if this read is successful */ +/* - return true if this read is successful */ /**********************************************************************/ -static gboolean -read_new_line(FILE_T fh, gint *length, - gchar *linebuff, size_t linebuffsize, int *err, gchar **err_info) +static bool +read_new_line(FILE_T fh, int *length, + char *linebuff, size_t linebuffsize, int *err, char **err_info) { /* Read in a line */ - gint64 pos_before = file_tell(fh); + int64_t pos_before = file_tell(fh); if (file_gets(linebuff, (int)linebuffsize - 1, fh) == NULL) { /* No characters found, or error */ *err = file_error(fh, err_info); - return FALSE; + return false; } /* Set length (avoiding strlen()) and offset.. */ - *length = (gint)(file_tell(fh) - pos_before); + *length = (int)(file_tell(fh) - pos_before); /* ...but don't want to include newline in line length */ if (*length > 0 && linebuff[*length-1] == '\n') { @@ -803,7 +803,7 @@ read_new_line(FILE_T fh, gint *length, *length = *length - 1; } - return TRUE; + return true; } @@ -812,19 +812,19 @@ read_new_line(FILE_T fh, gint *length, /* - context, port and direction of packet */ /* - timestamp */ /* - data position and length */ -/* Return TRUE if this packet looks valid and can be displayed */ +/* Return true if this packet looks valid and can be displayed */ /**********************************************************************/ -static gboolean -parse_line(gchar *linebuff, gint line_length, - gint *seconds, gint *useconds, +static bool +parse_line(char *linebuff, int line_length, + int *seconds, int *useconds, long *before_time_offset, long *after_time_offset, - long *data_offset, gint *data_chars, + long *data_offset, int *data_chars, packet_direction_t *direction, - int *encap, int *is_comment, int *is_sprint, - gchar *aal_header_chars, - gchar *context_name, guint8 *context_portp, - gchar *protocol_name, gchar *variant_name, - gchar *outhdr_name) + int *encap, bool *is_comment, bool *is_sprint, + char *aal_header_chars, + char *context_name, uint8_t *context_portp, + char *protocol_name, char *variant_name, + char *outhdr_name) { int n = 0; int port_digits; @@ -838,11 +838,11 @@ parse_line(gchar *linebuff, gint line_length, int seconds_chars; char subsecond_decimals_buff[MAX_SUBSECOND_DECIMALS+1]; int subsecond_decimals_chars; - int skip_first_byte = FALSE; - gboolean atm_header_present = FALSE; + bool skip_first_byte = false; + bool atm_header_present = false; - *is_comment = FALSE; - *is_sprint = FALSE; + *is_comment = false; + *is_sprint = false; /* Read context name until find '.' */ for (n=0; (n < MAX_CONTEXT_NAME) && (n+1 < line_length) && (linebuff[n] != '.'); n++) { @@ -851,21 +851,21 @@ parse_line(gchar *linebuff, gint line_length, /* If not a comment (/////), not a valid line */ if (strncmp(linebuff+n, "/////", 5) != 0) { - return FALSE; + return false; } /* There is no variant, outhdr, etc. Set protocol to be a comment */ (void) g_strlcpy(protocol_name, "comment", MAX_PROTOCOL_NAME); - *is_comment = TRUE; + *is_comment = true; break; } if (!g_ascii_isalnum(linebuff[n]) && (linebuff[n] != '_') && (linebuff[n] != '-')) { - return FALSE; + return false; } context_name[n] = linebuff[n]; } if (n == MAX_CONTEXT_NAME || (n+1 >= line_length)) { - return FALSE; + return false; } /* Reset strings (that won't be set by comments) */ @@ -876,7 +876,7 @@ parse_line(gchar *linebuff, gint line_length, if (!(*is_comment)) { /* '.' must follow context name */ if (linebuff[n] != '.') { - return FALSE; + return false; } context_name[n] = '\0'; /* Skip it */ @@ -888,18 +888,18 @@ parse_line(gchar *linebuff, gint line_length, n++, port_digits++) { if (!g_ascii_isdigit(linebuff[n])) { - return FALSE; + return false; } port_number_string[port_digits] = linebuff[n]; } if (port_digits > MAX_PORT_DIGITS || (n+1 >= line_length)) { - return FALSE; + return false; } /* Slash char must follow port number */ if (linebuff[n] != '/') { - return FALSE; + return false; } port_number_string[port_digits] = '\0'; if (port_digits == 1) { @@ -910,7 +910,7 @@ parse_line(gchar *linebuff, gint line_length, whether what follows the number is anything other than a '\0'. */ if (!ws_strtou8(port_number_string, NULL, context_portp)) { - return FALSE; + return false; } } /* Skip it */ @@ -922,19 +922,19 @@ parse_line(gchar *linebuff, gint line_length, n++, protocol_chars++) { if (!g_ascii_isalnum(linebuff[n]) && (linebuff[n] != '_') && (linebuff[n] != '.')) { - return FALSE; + return false; } protocol_name[protocol_chars] = linebuff[n]; } if (protocol_chars == MAX_PROTOCOL_NAME || n >= line_length) { /* If doesn't fit, fail rather than truncate */ - return FALSE; + return false; } protocol_name[protocol_chars] = '\0'; /* Slash char must follow protocol name */ if (linebuff[n] != '/') { - return FALSE; + return false; } /* Skip it */ n++; @@ -946,12 +946,12 @@ parse_line(gchar *linebuff, gint line_length, n++, variant_digits++) { if (!g_ascii_isdigit(linebuff[n])) { - return FALSE; + return false; } variant_name[variant_digits] = linebuff[n]; } if (variant_digits > MAX_VARIANT_DIGITS || (n+1 >= line_length)) { - return FALSE; + return false; } if (variant_digits > 0) { @@ -961,7 +961,7 @@ parse_line(gchar *linebuff, gint line_length, } else { if (!ws_strtoi32(variant_name, NULL, &variant)) { - return FALSE; + return false; } } } @@ -982,12 +982,12 @@ parse_line(gchar *linebuff, gint line_length, n++, outhdr_chars++) { if (!g_ascii_isdigit(linebuff[n]) && (linebuff[n] != ',')) { - return FALSE; + return false; } outhdr_name[outhdr_chars] = linebuff[n]; } if (outhdr_chars > MAX_OUTHDR_NAME || (n+1 >= line_length)) { - return FALSE; + return false; } /* Terminate (possibly empty) string */ outhdr_name[outhdr_chars] = '\0'; @@ -1019,13 +1019,13 @@ parse_line(gchar *linebuff, gint line_length, else { /* FP over AAL0 or AAL2 */ *encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; - atm_header_present = TRUE; + atm_header_present = true; } } else if (strcmp(protocol_name, "fpiur_r5") == 0) { /* FP (IuR) over AAL2 */ *encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; - atm_header_present = TRUE; + atm_header_present = true; } else @@ -1035,7 +1035,7 @@ parse_line(gchar *linebuff, gint line_length, else if (strcmp(protocol_name, "isdn_l3") == 0) { /* TODO: find out what this byte means... */ - skip_first_byte = TRUE; + skip_first_byte = true; *encap = WTAP_ENCAP_ISDN; } else @@ -1084,7 +1084,7 @@ parse_line(gchar *linebuff, gint line_length, /* Skip it */ n++; if (n+1 >= line_length) { - return FALSE; + return false; } /* Read consecutive hex chars into atm header buffer */ @@ -1102,7 +1102,7 @@ parse_line(gchar *linebuff, gint line_length, } if (header_chars_seen != AAL_HEADER_CHARS || n >= line_length) { - return FALSE; + return false; } } @@ -1138,7 +1138,7 @@ parse_line(gchar *linebuff, gint line_length, *direction = received; } else { - return FALSE; + return false; } /* Skip it */ n++; @@ -1156,12 +1156,12 @@ parse_line(gchar *linebuff, gint line_length, for (; ((linebuff[n] != 't') || (linebuff[n+1] != 'm')) && (n+1 < line_length); n++); if (n >= line_length) { - return FALSE; + return false; } for (; (n < line_length) && !g_ascii_isdigit(linebuff[n]); n++); if (n >= line_length) { - return FALSE; + return false; } *before_time_offset = n; @@ -1175,13 +1175,13 @@ parse_line(gchar *linebuff, gint line_length, if (!g_ascii_isdigit(linebuff[n])) { /* Found a non-digit before decimal point. Fail */ - return FALSE; + return false; } seconds_buff[seconds_chars] = linebuff[n]; } if (seconds_chars > MAX_SECONDS_CHARS || n >= line_length) { /* Didn't fit in buffer. Fail rather than use truncated */ - return FALSE; + return false; } /* Convert found value into number */ @@ -1196,7 +1196,7 @@ parse_line(gchar *linebuff, gint line_length, /* The decimal point must follow the last of the seconds digits */ if (linebuff[n] != '.') { - return FALSE; + return false; } /* Skip it */ n++; @@ -1209,13 +1209,13 @@ parse_line(gchar *linebuff, gint line_length, n++, subsecond_decimals_chars++) { if (!g_ascii_isdigit(linebuff[n])) { - return FALSE; + return false; } subsecond_decimals_buff[subsecond_decimals_chars] = linebuff[n]; } if (subsecond_decimals_chars != MAX_SUBSECOND_DECIMALS || n >= line_length) { /* There should be exactly 4 subsecond digits - give up if not */ - return FALSE; + return false; } /* Convert found value into microseconds */ subsecond_decimals_buff[subsecond_decimals_chars] = '\0'; @@ -1227,7 +1227,7 @@ parse_line(gchar *linebuff, gint line_length, /* Space character must follow end of timestamp */ if (linebuff[n] != ' ') { - return FALSE; + return false; } *after_time_offset = n++; @@ -1236,7 +1236,7 @@ parse_line(gchar *linebuff, gint line_length, a sprint line (no '$') */ if (*is_comment) { if (strncmp(linebuff+n, "l $", 3) != 0) { - *is_sprint = TRUE; + *is_sprint = true; (void) g_strlcpy(protocol_name, "sprint", MAX_PROTOCOL_NAME); } } @@ -1245,7 +1245,7 @@ parse_line(gchar *linebuff, gint line_length, /* Now skip ahead to find start of data (marked by '$') */ for (; (linebuff[n] != '$') && (linebuff[n] != '\'') && (n+1 < line_length); n++); if ((linebuff[n] == '\'') || (n+1 >= line_length)) { - return FALSE; + return false; } /* Skip it */ n++; @@ -1263,29 +1263,29 @@ parse_line(gchar *linebuff, gint line_length, *data_chars -= 2; } - return TRUE; + return true; } /***********************************/ /* Process results of parse_line() */ /***********************************/ -static gboolean -process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, +static bool +process_parsed_line(wtap *wth, const dct2000_file_externals_t *file_externals, wtap_rec *rec, - Buffer *buf, gint64 file_offset, + Buffer *buf, int64_t file_offset, char *linebuff, long dollar_offset, - int seconds, int useconds, gchar *timestamp_string, + int seconds, int useconds, char *timestamp_string, packet_direction_t direction, int encap, - gchar *context_name, guint8 context_port, - gchar *protocol_name, gchar *variant_name, - gchar *outhdr_name, gchar *aal_header_chars, - gboolean is_comment, int data_chars, - int *err, gchar **err_info) + char *context_name, uint8_t context_port, + char *protocol_name, char *variant_name, + char *outhdr_name, char *aal_header_chars, + bool is_comment, int data_chars, + int *err, char **err_info) { int n; int stub_offset = 0; - gsize length; - guint8 *frame_buffer; + size_t length; + uint8_t *frame_buffer; rec->rec_type = REC_TYPE_PACKET; rec->block = wtap_block_create(WTAP_BLOCK_PACKET); @@ -1306,12 +1306,12 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, * Calculate the length of the stub info and the packet data. * The packet data length is half bytestring length. */ - rec->rec_header.packet_header.caplen = (guint)strlen(context_name)+1 + /* Context name */ + rec->rec_header.packet_header.caplen = (unsigned)strlen(context_name)+1 + /* Context name */ 1 + /* port */ - (guint)strlen(timestamp_string)+1 + /* timestamp */ - (guint)strlen(variant_name)+1 + /* variant */ - (guint)strlen(outhdr_name)+1 + /* outhdr */ - (guint)strlen(protocol_name)+1 + /* Protocol name */ + (unsigned)strlen(timestamp_string)+1 + /* timestamp */ + (unsigned)strlen(variant_name)+1 + /* variant */ + (unsigned)strlen(outhdr_name)+1 + /* outhdr */ + (unsigned)strlen(protocol_name)+1 + /* Protocol name */ 1 + /* direction */ 1 + /* encap */ (is_comment ? data_chars : (data_chars/2)); @@ -1324,7 +1324,7 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("catapult dct2000: File has %u-byte packet, bigger than maximum of %u", rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen; @@ -1353,7 +1353,7 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, stub_offset += (int)(length + 1); /* Protocol variant number (as terminated string) */ - length = g_strlcpy((gchar*)&frame_buffer[stub_offset], variant_name, MAX_VARIANT_DIGITS+1); + length = g_strlcpy((char*)&frame_buffer[stub_offset], variant_name, MAX_VARIANT_DIGITS+1); stub_offset += (int)(length + 1); /* Outhdr (terminated string) */ @@ -1364,7 +1364,7 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, frame_buffer[stub_offset++] = direction; /* Encap */ - frame_buffer[stub_offset++] = (guint8)encap; + frame_buffer[stub_offset++] = (uint8_t)encap; if (!is_comment) { /***********************************************************/ @@ -1403,7 +1403,7 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, break; } - return TRUE; + return true; } /*********************************************/ @@ -1412,7 +1412,7 @@ process_parsed_line(wtap *wth, dct2000_file_externals_t *file_externals, static void set_aal_info(union wtap_pseudo_header *pseudo_header, packet_direction_t direction, - gchar *aal_header_chars) + char *aal_header_chars) { /* 'aal_head_chars' has this format (for AAL2 at least): Global Flow Control (4 bits) | VPI (8 bits) | VCI (16 bits) | @@ -1497,8 +1497,8 @@ set_ppp_info(union wtap_pseudo_header *pseudo_header, /********************************************************/ /* Return hex nibble equivalent of hex string character */ /********************************************************/ -static guint8 -hex_from_char(gchar c) +static uint8_t +hex_from_char(char c) { if ((c >= '0') && (c <= '9')) { return c - '0'; @@ -1514,16 +1514,16 @@ hex_from_char(gchar c) -/* Table allowing fast lookup from a pair of ascii hex characters to a guint8 */ -static guint8 s_tableValues[256][256]; +/* Table allowing fast lookup from a pair of ascii hex characters to a uint8_t */ +static uint8_t s_tableValues[256][256]; /* Prepare table values so ready so don't need to check inside hex_byte_from_chars() */ static void prepare_hex_byte_from_chars_table(void) { - guchar hex_char_array[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f' }; + const unsigned char hex_char_array[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f' }; - gint i, j; + int i, j; for (i=0; i < 16; i++) { for (j=0; j < 16; j++) { s_tableValues[hex_char_array[i]][hex_char_array[j]] = i*16 + j; @@ -1532,7 +1532,7 @@ static void prepare_hex_byte_from_chars_table(void) } /* Extract and return a byte value from 2 ascii hex chars, starting from the given pointer */ -static guint8 hex_byte_from_chars(gchar *c) +static uint8_t hex_byte_from_chars(char *c) { /* Return value from quick table lookup */ return s_tableValues[(unsigned char)c[0]][(unsigned char)c[1]]; @@ -1543,8 +1543,8 @@ static guint8 hex_byte_from_chars(gchar *c) /********************************************************/ /* Return character corresponding to hex nibble value */ /********************************************************/ -static gchar -char_from_hex(guint8 hex) +static char +char_from_hex(uint8_t hex) { static const char hex_lookup[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; @@ -1559,32 +1559,32 @@ char_from_hex(guint8 hex) /***********************************************/ /* Equality test for packet prefix hash tables */ /***********************************************/ -static gint -packet_offset_equal(gconstpointer v, gconstpointer v2) +static int +packet_offset_equal(const void *v, const void *v2) { - /* Dereferenced pointers must have same gint64 offset value */ - return (*(const gint64*)v == *(const gint64*)v2); + /* Dereferenced pointers must have same int64_t offset value */ + return (*(const int64_t*)v == *(const int64_t*)v2); } /********************************************/ /* Hash function for packet-prefix hash table */ /********************************************/ -static guint -packet_offset_hash_func(gconstpointer v) +static unsigned +packet_offset_hash_func(const void *v) { - /* Use low-order bits of gint64 offset value */ - return (guint)(*(const gint64*)v); + /* Use low-order bits of int64_t offset value */ + return (unsigned)(*(const int64_t*)v); } /************************************************************************/ /* Parse year, month, day, hour, minute, seconds out of formatted line. */ /* Set secs and usecs as output */ -/* Return FALSE if no valid time can be read */ +/* Return false if no valid time can be read */ /************************************************************************/ -static gboolean -get_file_time_stamp(gchar *linebuff, time_t *secs, guint32 *usecs) +static bool +get_file_time_stamp(const char *linebuff, time_t *secs, uint32_t *usecs) { struct tm tm; #define MAX_MONTH_LETTERS 9 @@ -1595,7 +1595,7 @@ get_file_time_stamp(gchar *linebuff, time_t *secs, guint32 *usecs) /* If line longer than expected, file is probably not correctly formatted */ if (strlen(linebuff) > MAX_TIMESTAMP_LINE_LENGTH) { - return FALSE; + return false; } /********************************************************/ @@ -1604,7 +1604,7 @@ get_file_time_stamp(gchar *linebuff, time_t *secs, guint32 *usecs) month, &day, &year, &hour, &minute, &second, usecs); if (scan_found != 7) { /* Give up if not all found */ - return FALSE; + return false; } if (strcmp(month, "January" ) == 0) tm.tm_mon = 0; @@ -1621,7 +1621,7 @@ get_file_time_stamp(gchar *linebuff, time_t *secs, guint32 *usecs) else if (strcmp(month, "December" ) == 0) tm.tm_mon = 11; else { /* Give up if not found a properly-formatted date */ - return FALSE; + return false; } /******************************************************/ @@ -1639,13 +1639,13 @@ get_file_time_stamp(gchar *linebuff, time_t *secs, guint32 *usecs) /* Multiply 4 digits given to get micro-seconds */ *usecs = *usecs * 100; - return TRUE; + return true; } /* Free the data allocated inside a line_prefix_info_t */ static gboolean -free_line_prefix_info(gpointer key, gpointer value, - gpointer user_data _U_) +free_line_prefix_info(void *key, void *value, + void *user_data _U_) { line_prefix_info_t *info = (line_prefix_info_t*)value; @@ -1659,7 +1659,7 @@ free_line_prefix_info(gpointer key, gpointer value, g_free(info); /* Item will always be removed from table */ - return TRUE; + return true; } static const struct supported_block_type dct2000_blocks_supported[] = { @@ -1671,7 +1671,7 @@ static const struct supported_block_type dct2000_blocks_supported[] = { static const struct file_type_subtype_info dct2000_info = { "Catapult DCT2000 trace (.out format)", "dct2000", "out", NULL, - FALSE, BLOCKS_SUPPORTED(dct2000_blocks_supported), + false, BLOCKS_SUPPORTED(dct2000_blocks_supported), catapult_dct2000_dump_can_write_encap, catapult_dct2000_dump_open, NULL }; diff --git a/wiretap/catapult_dct2000.h b/wiretap/catapult_dct2000.h index 61b8ebb7..30a45827 100644 --- a/wiretap/catapult_dct2000.h +++ b/wiretap/catapult_dct2000.h @@ -11,8 +11,9 @@ #include <glib.h> #include "ws_symbol_export.h" +#include "wtap.h" -wtap_open_return_val catapult_dct2000_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val catapult_dct2000_open(wtap *wth, int *err, char **err_info); #define DCT2000_ENCAP_UNHANDLED 0 #define DCT2000_ENCAP_SSCOP 101 diff --git a/wiretap/cllog.c b/wiretap/cllog.c new file mode 100644 index 00000000..3ca4b333 --- /dev/null +++ b/wiretap/cllog.c @@ -0,0 +1,1008 @@ +/* cllog.c + * + * Wiretap Library + * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +/* + * Reads log files from CLX000 CAN loggers from CSS Electronics: + * + * https://canlogger.csselectronics.com/clx000-docs/cl1000/log/index.html + * https://canlogger.csselectronics.com/clx000-docs/cl2000/log/index.html + * + * Based on the cCLLog.c, cCLLog.h, and wtap-cllog.c source files from + * the WS_v2.4-Plugin_v7.1.zip version of the CSS Electronics plugin at + * + * https://canlogger.csselectronics.com/downloads.php?q=wireshark + * + * with the files combined into one source file, modernized to + * fit into an up-to-date version of Wireshark, and cleaned up + * not to, for example, do seeks by rewinding and reading to + * get to the seek target. + * + * It could probably use some further cleanup. + */ + +#include "config.h" + +#include <stdio.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> + +#include <wsutil/str_util.h> +#include <wsutil/strtoi.h> + +#include "wtap-int.h" +#include "file_wrappers.h" + +/*********************************************************************************************************************** + * Public definitions + **********************************************************************************************************************/ +#define MAX_LOG_LINE_FIELDS 7 /*( seqNo, timestamp, lost, SE, ID, length, data) */ +/*********************************************************************************************************************** + * Public type declarations + **********************************************************************************************************************/ +/* Time stamp structure type (sec since start + ms resolution) */ +typedef struct { time_t epoch; uint16_t ms; } cCLLog_timeStamp_t; + + /* Message type */ +typedef enum +{ + msg_rx_standard_e = 0, + msg_rx_extended_e = 1, + msg_tx_standard_e = 7, + msg_tx_extended_e = 8, +} cCLLog_messageType_t; + +/* Typedef CAN-bus message type */ +typedef struct +{ + cCLLog_timeStamp_t timestamp; + uint32_t lost; + cCLLog_messageType_t msgType; + uint32_t id; + uint8_t length; + uint8_t data[ 8 ]; +} cCLLog_message_t; + +/* Silent-mode*/ +typedef enum { silent_disabled_e = 0, silent_enabled_e } cCLLog_silentMode_t; + +/* Cyclic-mode*/ +typedef enum { cyclic_disabled_e = 0, cyclic_enabled_e } cCLLog_cyclicMode_t; + +/* Logger type */ +typedef enum { type_CL1000_e = 0, type_CL2000_e, type_CL3000_e } cCLLog_loggerType_t; + +typedef char * (*CLLog_gets_t)(char *s, int size, void *stream); +typedef int (*CLLog_rewind_t)(void *stream); + +typedef struct cLLog_private cCLLog_logFileInfo_t; + +/* Type used to parse a field in a log line */ +typedef bool (*parseFieldFunc_t)(cCLLog_logFileInfo_t *pInfo, char *pField, cCLLog_message_t *pLogEntry, int *err, char **err_info); + +/* Log file information */ +struct cLLog_private +{ + uint32_t firstLogRow; + cCLLog_loggerType_t loggerType; + char hwrev[5]; + char fwrev[5]; + char id[20]; + uint32_t sessionNo; + uint32_t splitNo; + cCLLog_timeStamp_t logStartTime; + char logStartTimeString[ 20 ]; + char separator; + uint8_t timeFormat; + char timeSeparator; + char timeSeparatorMs; + char dateSeparator; + char dateAndTimeSeparator; + uint32_t bitRate; + cCLLog_silentMode_t silentMode; + cCLLog_cyclicMode_t cyclicMode; + + parseFieldFunc_t parseFieldFunc[ MAX_LOG_LINE_FIELDS ]; + + /* First log time stamp as relative offset */ + cCLLog_timeStamp_t firstTimeStampAbs; +}; + +/*********************************************************************************************************************** + * Private definitions + **********************************************************************************************************************/ +#define HEADER_LINE_PARSE_MAPPING_LENGTH array_length(headerLineParseMapping) +#define MAX_LOG_LINE_LENGTH 200 +#define TIME_STAMP_STRING_MAX_LENGTH ( sizeof( "YYYY/MM/DDThh:mm:ss.kkk" ) ) +#define TIME_STAMP_STRING_STRIPPED_MAX_LENGTH ( sizeof( "YYYYMMDDhhmmsskkk" ) ) + +/*********************************************************************************************************************** + * Private type definitions + **********************************************************************************************************************/ +/* Function type to parse a single log file line */ +typedef bool (*parseFunc_t)(cCLLog_logFileInfo_t *pInfo, char *pLine, int *err, char **err_info); + +/* Structure of the header parse mapping. A match string is paired with a parse function */ +typedef struct +{ + const char *pMatchString; + parseFunc_t parseFunc; +} headerLineParseMapping_t; + +/*********************************************************************************************************************** + * Private function declarations + **********************************************************************************************************************/ +static bool parseColumnHeaderFields( cCLLog_logFileInfo_t *pInfo, char *pColLine ); +static uint8_t stripTimeStamp( const cCLLog_logFileInfo_t *pInfo, char *pTimeStampString ); + +/* Parse header lines functions */ +static bool parseLogFileHeaderLine_type(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_hwrev(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_fwrev(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_id(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_sessionNo(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_splitNo(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_time(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_valueSeparator(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_timeFormat(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_timeSeparator(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_timeSeparatorMs(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_dateSeparator(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_timeAndDateSeparator(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_bitRate(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_silentMode(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +static bool parseLogFileHeaderLine_cyclicMode(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info); +/*********************************************************************************************************************** + * Private variable definitions + **********************************************************************************************************************/ + +/* Array of header line match strings and associated parse functions */ +static const headerLineParseMapping_t headerLineParseMapping[] = +{ + { .pMatchString = "Logger type: ", .parseFunc = parseLogFileHeaderLine_type}, + { .pMatchString = "HW rev: ", .parseFunc = parseLogFileHeaderLine_hwrev }, + { .pMatchString = "FW rev: ", .parseFunc = parseLogFileHeaderLine_fwrev }, + { .pMatchString = "Logger ID: ", .parseFunc = parseLogFileHeaderLine_id}, + { .pMatchString = "Session No.: ", .parseFunc = parseLogFileHeaderLine_sessionNo}, + { .pMatchString = "Split No.: ", .parseFunc = parseLogFileHeaderLine_splitNo}, + { .pMatchString = "Time: ", .parseFunc = parseLogFileHeaderLine_time}, + { .pMatchString = "Value separator: ", .parseFunc = parseLogFileHeaderLine_valueSeparator}, + { .pMatchString = "Time format: ", .parseFunc = parseLogFileHeaderLine_timeFormat}, + { .pMatchString = "Time separator: ", .parseFunc = parseLogFileHeaderLine_timeSeparator}, + { .pMatchString = "Time separator ms: ", .parseFunc = parseLogFileHeaderLine_timeSeparatorMs}, + { .pMatchString = "Date separator: ", .parseFunc = parseLogFileHeaderLine_dateSeparator}, + { .pMatchString = "Time and date separator: ", .parseFunc = parseLogFileHeaderLine_timeAndDateSeparator}, + { .pMatchString = "Bit-rate: ", .parseFunc = parseLogFileHeaderLine_bitRate}, + { .pMatchString = "Silent mode: ", .parseFunc = parseLogFileHeaderLine_silentMode}, + { .pMatchString = "Cyclic mode: ", .parseFunc = parseLogFileHeaderLine_cyclicMode}, +}; + +/* + * Do a string copy to a buffer of a specified length. + * If the string will fit, return true. + * If the string won't fit, return false. + */ +static bool +checked_strcpy(char *dest, size_t destlen, const char *src) +{ + size_t srclen; + + srclen = strlen(src) + 1; // count the trailing '\0' + if (srclen > destlen) + return false; + memcpy(dest, src, srclen); + return true; +} + +/* TODO: Does not support separators set to numbers (will remove part of the time stamp also */ +/* TODO: Does not support time stamps without ms, as given in the header */ +/* TODO: Alot of copying slows down the parsing */ +static bool parseFieldTS(cCLLog_logFileInfo_t *pInfo, char *pField, cCLLog_message_t *pLogEntry, int *err, char **err_info) +{ + struct tm tm; + int ms; + + /* Copy the string to not modify the original */ + char timeStampCopy[TIME_STAMP_STRING_MAX_LENGTH]; + if (!checked_strcpy(timeStampCopy, sizeof timeStampCopy, pField)) + { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: time stamp is too long"); + return false; + } + + /* Copy the header time stamp string to not modify the original */ + char timeStampHeaderCopy[TIME_STAMP_STRING_MAX_LENGTH]; + if (!checked_strcpy(timeStampHeaderCopy, sizeof timeStampHeaderCopy, pInfo->logStartTimeString)) + { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: header time stamp too long"); + return false; + } + + /* Strip the delimiters from the time strings */ + uint8_t msgTimeStrippedLen = stripTimeStamp(pInfo, timeStampCopy); + if (msgTimeStrippedLen > TIME_STAMP_STRING_STRIPPED_MAX_LENGTH - 1) { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: time stamp incorrectly formatted"); + return false; + } + + uint8_t headerTimeStrippedLen = stripTimeStamp(pInfo, timeStampHeaderCopy); + if (headerTimeStrippedLen > TIME_STAMP_STRING_STRIPPED_MAX_LENGTH - 1) { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: header time stamp incorrectly formatted"); + return false; + } + + /* Set time string (YYYYMMDDhhmmsskkk) to the epoch */ + char timeStampStringFull[TIME_STAMP_STRING_STRIPPED_MAX_LENGTH] = "19700101000000000"; + + /* Copy the header time to the template */ + memcpy(timeStampStringFull, timeStampHeaderCopy, headerTimeStrippedLen); + + /* Copy the stripped timestamp into the full template */ + memcpy(&timeStampStringFull[TIME_STAMP_STRING_STRIPPED_MAX_LENGTH - 1 - msgTimeStrippedLen], timeStampCopy, msgTimeStrippedLen); + timeStampStringFull[TIME_STAMP_STRING_STRIPPED_MAX_LENGTH - 1] = '\0'; + + memset(&tm, 0, sizeof tm); + + /* YYYYMMDDThhmmss */ + sscanf(timeStampStringFull, "%4u%2u%2u%2u%2u%2u%3d", + &tm.tm_year, + &tm.tm_mon, + &tm.tm_mday, + &tm.tm_hour, + &tm.tm_min, + &tm.tm_sec, + &ms + ); + tm.tm_mon -= 1; + tm.tm_year -= 1900; + + /* To Epoch (mktime converts to epoch from local (!!!) timezone) */ + pLogEntry->timestamp.epoch = mktime(&tm); + pLogEntry->timestamp.ms = ms; + + /* Is first time stamp ? */ + if (pInfo->firstTimeStampAbs.epoch == 0 && pInfo->firstTimeStampAbs.ms == 0) + { + pInfo->firstTimeStampAbs.epoch = pLogEntry->timestamp.epoch; + pInfo->firstTimeStampAbs.ms = pLogEntry->timestamp.ms; + } + + return true; +} + +static bool parseFieldLost(cCLLog_logFileInfo_t *pInfo _U_, char *pField, cCLLog_message_t *pLogEntry, int *err, char **err_info) +{ + uint32_t lost; + + if (!ws_strtou32(pField, NULL, &lost)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup_printf("cllog: lost packet count value is not valid"); + return false; + } + pLogEntry->lost = lost; + return true; +} + +static bool parseFieldMsgType(cCLLog_logFileInfo_t *pInfo _U_, char *pField, cCLLog_message_t *pLogEntry, int *err, char **err_info) +{ + switch (pField[0]) + { + case '0': + pLogEntry->msgType = msg_rx_standard_e; + return true; + case '1': + pLogEntry->msgType = msg_rx_extended_e; + return true; + case '8': + pLogEntry->msgType = msg_tx_standard_e; + return true; + case '9': + pLogEntry->msgType = msg_tx_extended_e; + return true; + default: + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: unknown message type"); + return false; + } +} + +static bool parseFieldID(cCLLog_logFileInfo_t *pInfo _U_, char *pField, cCLLog_message_t *pLogEntry, int *err, char **err_info) +{ + uint32_t id; + + if (!ws_hexstrtou32(pField, NULL, &id)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup_printf("cllog: ID value is not valid"); + return false; + } + pLogEntry->id = id; + return true; +} + +static bool parseFieldLength(cCLLog_logFileInfo_t *pInfo _U_, char *pField, cCLLog_message_t *pLogEntry, int *err, char **err_info) +{ + uint32_t length; + + if (!ws_strtou32(pField, NULL, &length)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup_printf("cllog: length value is not valid"); + return false; + } + pLogEntry->length = length; + return true; +} + +static bool parseFieldData(cCLLog_logFileInfo_t *pInfo _U_, char *pField, cCLLog_message_t *pLogEntry, int *err, char **err_info) +{ + char *pFieldStart = pField; + + /* Set data length in case length field is not set explicitly in the log file */ + pLogEntry->length = 0; + + /* Loop all data bytes */ + for (unsigned int dataByte = 0; dataByte < 8; dataByte++) + { + int hexdigit; + uint8_t data; + + if (*pFieldStart == '\n' || *pFieldStart == '\r') + { + break; + } + + hexdigit = ws_xton(*pFieldStart); + if (hexdigit < 0) { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup_printf("cllog: packet byte value is not valid"); + return false; + } + data = (uint8_t)hexdigit << 4U; + pFieldStart++; + hexdigit = ws_xton(*pFieldStart); + if (hexdigit < 0) { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: packet byte value is not valid"); + return false; + } + data = data | (uint8_t)hexdigit; + pFieldStart++; + pLogEntry->data[dataByte] = data; + + pLogEntry->length++; + } + return true; +} + +static bool parseLogLine(cCLLog_logFileInfo_t *pInfo, char *pLine, cCLLog_message_t *pLogEntry, int *err, char **err_info) +{ + char *pFieldStart = pLine; + + /* Loop all fields in log line */ + for (unsigned int fieldNo = 0, finalField = 0; fieldNo < MAX_LOG_LINE_FIELDS && finalField == 0; fieldNo++) + { + /* Find field end by separator */ + char *pFieldEnd = strchr(pFieldStart, pInfo->separator); + + /* If final field, then EOL marks the end of the field */ + if (pFieldEnd == NULL) + { + pFieldEnd = strchr(pFieldStart, '\n'); + finalField = 1; + } + + /* Replace separator with string termination */ + *pFieldEnd = '\0'; + + /* Is parse function assigned to field? */ + if (pInfo->parseFieldFunc[fieldNo] != NULL) + { + /* Parse field */ + if (!pInfo->parseFieldFunc[fieldNo](pInfo, pFieldStart, pLogEntry, err, err_info)) + { + return false; + } + } + + /* Skip over the separator */ + pFieldStart = pFieldEnd + 1; + } + return true; +} + +/*********************************************************************************************************************** + * parseColumnHeaderFields + * + * Parse the column fields and determine which fields are present and the position of the fields + * + * @param[ in ] pInfo Pointer to the CLLog object + * @param[ in ] pColLine The column line + **********************************************************************************************************************/ +static bool parseColumnHeaderFields( cCLLog_logFileInfo_t *pInfo, char *pColLine ) +{ + bool resultFlag = false; + + /* Initialise field start */ + char *pFieldStart = pColLine; + + /* Loop all fields in line */ + for ( uint8_t fieldNo = 0, finalField = 0 ; fieldNo < MAX_LOG_LINE_FIELDS && finalField == 0 ; fieldNo++ ) + { + /* Find field end */ + char *pFieldEnd = strchr( pFieldStart, pInfo->separator ); + + /* If final field, then EOL marks the end of the field */ + if( pFieldEnd == NULL ) + { + pFieldEnd = strchr( pFieldStart, '\n' ); + finalField = 1; + } + + /* Replace separator with string termination */ + *pFieldEnd = '\0'; + + /* Set field number */ + if( strcmp( pFieldStart, "Timestamp" ) == 0 ) { pInfo->parseFieldFunc[ fieldNo ] = parseFieldTS; resultFlag = true; } + if( strcmp( pFieldStart, "Lost" ) == 0 ) { pInfo->parseFieldFunc[ fieldNo ] = parseFieldLost; resultFlag = true; } + if( strcmp( pFieldStart, "Type" ) == 0 ) { pInfo->parseFieldFunc[ fieldNo ] = parseFieldMsgType; resultFlag = true; } + if( strcmp( pFieldStart, "ID" ) == 0 ) { pInfo->parseFieldFunc[ fieldNo ] = parseFieldID; resultFlag = true; } + if( strcmp( pFieldStart, "Length" ) == 0 ) { pInfo->parseFieldFunc[ fieldNo ] = parseFieldLength; resultFlag = true; } + if( strcmp( pFieldStart, "Data" ) == 0 ) { pInfo->parseFieldFunc[ fieldNo ] = parseFieldData; resultFlag = true; } + + /* Set start of next field to end of previous + 1 */ + pFieldStart = pFieldEnd + 1; + } + + return resultFlag; +} + +/*********************************************************************************************************************** + * stripTimeStamp + * + * Strips a time stamp string for any delimiters + **********************************************************************************************************************/ +static uint8_t stripTimeStamp( const cCLLog_logFileInfo_t *pInfo, char *pTimeStampString ) +{ + uint8_t strippedLength = 0U; + + /* Char by char, strip the delimiters from the time stamp string */ + size_t timeStampStringLen = strlen( pTimeStampString ); + for (size_t i = 0U; i < timeStampStringLen; i++ ) + { + /* Get char */ + char charTmp = pTimeStampString[i]; + + /* If delimiter, skip */ + if( charTmp == pInfo->separator ){ continue; } + if( charTmp == pInfo->timeSeparator ){ continue; } + if( charTmp == pInfo->timeSeparatorMs ){ continue; } + if( charTmp == pInfo->dateSeparator ){ continue; } + if( charTmp == pInfo->dateAndTimeSeparator ){ continue; } + + /* Not a delimiter, keep char */ + pTimeStampString[ strippedLength++ ] = charTmp; + } + pTimeStampString[ strippedLength ] = '\0'; + + return strippedLength; +} + +static bool parseString(const char *pFieldValue, char *valuep, size_t valueSize, char *fieldName, int *err, char **err_info) +{ + if (!checked_strcpy(valuep, valueSize, pFieldValue)) + { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("cllog: %s is too long", + fieldName); + return false; + } + return true; +} + +static bool parseUnsigned(const char *pFieldValue, uint32_t *valuep, char *fieldName, int *err, char **err_info) +{ + uint32_t value; + + if (!ws_strtou32(pFieldValue, NULL, &value)) { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("cllog: %s value is not valid", + fieldName); + return false; + } + *valuep = value; + return true; +} + +static bool parseSeparator(const char *pFieldValue, char *separatorp, char *fieldName, int *err, char **err_info) +{ + char separator = '\0'; + + /* Separator field is if set e.g. ";" - that is 3 chars. Else it is "" */ + if (strlen( pFieldValue) == 3) + { + if (pFieldValue[0] != '"' || !g_ascii_isprint(pFieldValue[1]) || + pFieldValue[2] != '"') + { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("cllog: %s separator is not valid", + fieldName); + return false; + } + separator = pFieldValue[1]; + } + *separatorp = separator; + return true; +} + +static bool parseBoolean(const char *pFieldValue, bool *value, char *fieldName, int *err, char **err_info) +{ + if (strcmp(pFieldValue, "true") == 0) + { + *value = true; + } + else if (strcmp(pFieldValue, "false") == 0) + { + *value = false; + } + else + { + *err = WTAP_ERR_BAD_FILE; + *err_info = ws_strdup_printf("cllog: %s value is not valid", + fieldName); + return false; + } + return true; +} + +static bool parseLogFileHeaderLine_type(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + if (strcmp(pFieldValue, "CANLogger1000") == 0 ) + { + pInfo->loggerType = type_CL1000_e; + } + else if (strcmp(pFieldValue, "CANLogger2000") == 0) + { + pInfo->loggerType = type_CL2000_e; + } + else if (strcmp(pFieldValue, "CANLogger3000") == 0 ) + { + pInfo->loggerType = type_CL3000_e; + } + else + { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: logger type value is not valid"); + return false; + } + return true; +} + +static bool parseLogFileHeaderLine_hwrev(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseString(pFieldValue, pInfo->hwrev, sizeof pInfo->hwrev, "hardware revision", err, err_info); +} + +static bool parseLogFileHeaderLine_fwrev(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseString(pFieldValue, pInfo->fwrev, sizeof pInfo->fwrev, "firmware revision", err, err_info); +} + +static bool parseLogFileHeaderLine_id(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseString(pFieldValue, pInfo->id, sizeof pInfo->id, "ID", err, err_info); +} + +static bool parseLogFileHeaderLine_sessionNo(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseUnsigned(pFieldValue, &pInfo->sessionNo, "session number", err, err_info); +} + +static bool parseLogFileHeaderLine_splitNo(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseUnsigned(pFieldValue, &pInfo->splitNo, "split number", err, err_info); +} + +static bool parseLogFileHeaderLine_time(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + struct tm tm; + + memset(&tm, 0, sizeof tm); + /* YYYYMMDDThhmmss */ + sscanf(pFieldValue, + "%4u%2u%2uT%2u%2u%2u", + &tm.tm_year, + &tm.tm_mon, + &tm.tm_mday, + &tm.tm_hour, + &tm.tm_min, + &tm.tm_sec); + tm.tm_mon -= 1; + tm.tm_year -= 1900; + + /* To Epoch ( mktime converts to epoch from local (!!!) timezone )*/ + pInfo->logStartTime.epoch = mktime(&tm); + pInfo->logStartTime.ms = 0; + + if (!checked_strcpy(pInfo->logStartTimeString, sizeof pInfo->logStartTimeString, pFieldValue)) + { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: time is too long"); + return false; + } + return true; +} + +static bool parseLogFileHeaderLine_valueSeparator(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseSeparator(pFieldValue, &pInfo->separator, "value", err, err_info); +} + +static bool parseLogFileHeaderLine_timeFormat(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + uint32_t format; + + if (!ws_strtou32(pFieldValue, NULL, &format)) + { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: time format value is not valid"); + return false; + } + if (format > 6) + { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup("cllog: time format value is not valid"); + return false; + } + pInfo->timeFormat = (uint8_t)format; + return true; +} + +static bool parseLogFileHeaderLine_timeSeparator(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseSeparator(pFieldValue, &pInfo->timeSeparator, "time", err, err_info); +} + +static bool parseLogFileHeaderLine_timeSeparatorMs(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseSeparator(pFieldValue, &pInfo->timeSeparatorMs, "time millisecond", err, err_info); +} + +static bool parseLogFileHeaderLine_dateSeparator(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseSeparator(pFieldValue, &pInfo->dateSeparator, "date", err, err_info); +} + +static bool parseLogFileHeaderLine_timeAndDateSeparator(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseSeparator(pFieldValue, &pInfo->dateAndTimeSeparator, "date and time", err, err_info); +} + +static bool parseLogFileHeaderLine_bitRate(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + return parseUnsigned(pFieldValue, &pInfo->bitRate, "bit rate", err, err_info); +} + +static bool parseLogFileHeaderLine_silentMode(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + bool silentMode; + + if (!parseBoolean(pFieldValue, &silentMode, "silent mode", err, err_info)) + { + return false; + } + + if (silentMode) + { + pInfo->silentMode = silent_enabled_e; + } + else + { + pInfo->silentMode = silent_disabled_e; + } + return true; +} + +static bool parseLogFileHeaderLine_cyclicMode(cCLLog_logFileInfo_t *pInfo, char *pFieldValue, int *err, char **err_info) +{ + bool cyclicMode; + + if (!parseBoolean(pFieldValue, &cyclicMode, "silent mode", err, err_info)) + { + return false; + } + + if (cyclicMode) + { + pInfo->cyclicMode = cyclic_enabled_e; + } + else + { + pInfo->cyclicMode = cyclic_disabled_e; + } + return true; +} + +/* + + c:\development\wireshark\plugins\wimaxmacphy\cCLLog.c(248): warning C4 + 477: 'sscanf' : format string '%i' requires an argument of type 'int *', + but variadic argument 1 has type 'uint8_t *' + c:\development\wireshark\plugins\wimaxmacphy\cCLLog.c(274): warning C4 + 477: 'sscanf' : format string '%i' requires an argument of type 'int *', + but variadic argument 1 has type 'uint8_t *' + c:\development\wireshark\plugins\wimaxmacphy\cCLLog.c(288): warning C4 + 477: 'sscanf' : format string '%2x' requires an argument of type 'unsign + ed int *', but variadic argument 1 has type 'uint8_t * + + +*/ + +#include "cllog.h" + +static int cllog_file_type_subtype = -1; + +#define CAN_EFF_MASK 0x1FFFFFFF /* extended frame format (EFF) */ +#define CAN_SFF_MASK 0x000007FF /* standard frame format (SFF) */ + +static bool +cllog_read_common(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, char **err_info _U_) +{ + cCLLog_logFileInfo_t *clLog = (cCLLog_logFileInfo_t *) wth->priv; + char line[MAX_LOG_LINE_LENGTH]; + cCLLog_message_t logEntry; + uint8_t *can_data; + + /* Read a line */ + if (file_gets(line, sizeof(line), fh) == NULL) + { + /* EOF or error. */ + *err = file_error(wth->fh, err_info); + return false; + } + + /* Default the log entry structure */ + memset(&logEntry, 0, sizeof(logEntry)); + + /* Parse the line */ + if (!parseLogLine(clLog, line, &logEntry, err, err_info)) + { + return false; + } + + rec->rec_type = REC_TYPE_PACKET; + rec->block = wtap_block_create(WTAP_BLOCK_PACKET); + rec->presence_flags = WTAP_HAS_TS; + + rec->ts.secs = logEntry.timestamp.epoch; + rec->ts.nsecs = logEntry.timestamp.ms * 1000U * 1000U; + + rec->rec_header.packet_header.caplen = 8 + logEntry.length; + rec->rec_header.packet_header.len = 8 + logEntry.length; + + if (logEntry.msgType == msg_tx_standard_e || logEntry.msgType == msg_tx_extended_e) + { + wtap_block_add_uint32_option(rec->block, OPT_PKT_FLAGS, PACK_FLAGS_DIRECTION_OUTBOUND); + } + else if (logEntry.msgType == msg_rx_standard_e || logEntry.msgType == msg_rx_extended_e) + { + wtap_block_add_uint32_option(rec->block, OPT_PKT_FLAGS, PACK_FLAGS_DIRECTION_INBOUND); + } + + ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); + can_data = ws_buffer_start_ptr(buf); + + can_data[0] = (logEntry.id >> 24); + can_data[1] = (logEntry.id >> 16); + can_data[2] = (logEntry.id >> 8); + can_data[3] = (logEntry.id >> 0); + can_data[4] = logEntry.length; + can_data[5] = 0; + can_data[6] = 0; + can_data[7] = 0; + + if (logEntry.msgType == msg_tx_extended_e || logEntry.msgType == msg_rx_extended_e || (logEntry.id & CAN_EFF_MASK) > CAN_SFF_MASK) + can_data[0] |= 0x80; + + memcpy(&can_data[8], logEntry.data, logEntry.length); + return true; +} + +static bool +cllog_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, int64_t *data_offset) +{ + *data_offset = file_tell(wth->fh); + + return cllog_read_common(wth, wth->fh, rec, buf, err, err_info); +} + +static bool +cllog_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) +{ + if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) + return false; + + return cllog_read_common(wth, wth->random_fh, rec, buf, err, err_info); +} + +wtap_open_return_val +cllog_open(wtap *wth, int *err, char **err_info _U_) +{ + cCLLog_logFileInfo_t *clLog; + char line[ MAX_LOG_LINE_LENGTH ]; + + clLog = g_new0(cCLLog_logFileInfo_t, 1); + + /* Initialize the header information */ + clLog->loggerType = 0; + clLog->hwrev[0] = '\0'; + clLog->fwrev[0] = '\0'; + clLog->id[0] = '\0'; + clLog->sessionNo = 0; + clLog->splitNo = 0; + clLog->logStartTime.epoch = 0; + clLog->logStartTime.ms = 0; + clLog->logStartTimeString[0] = '\0'; + clLog->separator = '\0'; + clLog->timeFormat = 0; + clLog->timeSeparator = '\0'; + clLog->timeSeparatorMs = '\0'; + clLog->dateSeparator = '\0'; + clLog->dateAndTimeSeparator = '\0'; + clLog->bitRate = 0; + clLog->silentMode = 0; + clLog->cyclicMode = 0; + + /* Set parse function pointers */ + memset(clLog->parseFieldFunc, 0, sizeof( clLog->parseFieldFunc)); + + /* + * We're at the beginning of the file; read each line and + * parse it. + */ + while (file_gets(line, sizeof(line), wth->fh) != NULL) + { + char *linep; + + if (*err != 0) + { + if (*err == WTAP_ERR_SHORT_READ) + { + /* Incomplete header, so not ours. */ + g_free(clLog); + return WTAP_OPEN_NOT_MINE; + } + else + { + /* I/O error. */ + g_free(clLog); + return WTAP_OPEN_ERROR; + } + } + + linep = line; + + /* Break on end of header */ + if (linep[0] != '#') + { + break; + } + + /* + * Skip the comment character and white space following it. + */ + linep++; + while (*linep == ' ' || *linep == '\t') + linep++; + + if (*linep == '\0') + { + /* + * Skip over empty comment lines. + * XXX - should we treat that as an indication of an + * invalid file? + */ + continue; + } + + /* + * Look for the handler for this particular header line. + */ + for (unsigned int i = 0U; i < HEADER_LINE_PARSE_MAPPING_LENGTH; i++) + { + const headerLineParseMapping_t *pHeaderMapping = &headerLineParseMapping[i]; + size_t matchStringLen = strlen(pHeaderMapping->pMatchString); + + if (strncmp(linep, pHeaderMapping->pMatchString, matchStringLen) == 0 && + pHeaderMapping->parseFunc != NULL) + { + /* + * This matches this header value. + * Skip past the tag. + */ + linep += matchStringLen; + + /* Replace any newline chars with end of line */ + for (char *pChar = linep; ; pChar++) + { + if (*pChar == '\n' || *pChar == '\r' || *pChar == '\0') + { + *pChar = '\0'; + break; + } + } + + /* + * Call the handler. + */ + if (!pHeaderMapping->parseFunc(clLog, linep, err, err_info)) + { + /* + * XXX - should this file be rejected as not + * one of ours? Given the line looks like + * a comment that begins with a valid header + * field tag, it may be likely to be one of + * ours. + */ + g_free(clLog); + return WTAP_OPEN_ERROR; + } + } + } + } + + /* + * We've read the first line after the header, so it's the column + * header line. Parse it. + */ + if (!parseColumnHeaderFields(clLog, line)) + { + g_free(clLog); + return WTAP_OPEN_NOT_MINE; + } + + wth->priv = clLog; + + wth->file_type_subtype = cllog_file_type_subtype; + wth->file_encap = WTAP_ENCAP_SOCKETCAN; + wth->snapshot_length = 0; + + wth->subtype_read = cllog_read; + wth->subtype_seek_read = cllog_seek_read; + wth->file_tsprec = WTAP_TSPREC_MSEC; + + return WTAP_OPEN_MINE; +} + +/* Options for packet blocks. */ +static const struct supported_option_type packet_block_options_supported[] = { + { OPT_PKT_FLAGS, ONE_OPTION_SUPPORTED }, +}; + +static const struct supported_block_type cllog_blocks_supported[] = { + /* + * We support packet blocks, with only the flags option supported. + */ + { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, OPTION_TYPES_SUPPORTED(packet_block_options_supported) } +}; + +static const struct file_type_subtype_info cllog_info = { + "CSS Electronics CLX000 CAN log", "cllog", "txt", NULL, + false, BLOCKS_SUPPORTED(cllog_blocks_supported), + NULL, NULL, NULL +}; + +void +register_canlogger(void) +{ + cllog_file_type_subtype = wtap_register_file_type_subtype(&cllog_info); +} diff --git a/wiretap/cllog.h b/wiretap/cllog.h new file mode 100644 index 00000000..0bbbf9ae --- /dev/null +++ b/wiretap/cllog.h @@ -0,0 +1,17 @@ +/** @file + * + * Wiretap Library + * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __CLLOG_H__ +#define __CLLOG_H__ + +#include <glib.h> +#include "wtap.h" + +wtap_open_return_val cllog_open(wtap *wth, int *err, char **err_info); + +#endif diff --git a/wiretap/commview.c b/wiretap/commview.c index 71f9ced2..61c76008 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -23,13 +23,13 @@ */ #include "config.h" +#include "commview.h" #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "commview.h" #include <wsutil/802_11-utils.h> @@ -42,25 +42,25 @@ #define MEDIUM_TOKEN_RING 2 typedef struct commview_ncf_header { - guint16 data_len; - guint16 source_data_len; - guint8 version; - guint16 year; - guint8 month; - guint8 day; - guint8 hours; - guint8 minutes; - guint8 seconds; - guint32 usecs; - guint8 flags; /* Bit-field positions defined below */ - guint8 signal_level_percent; - guint8 rate; - guint8 band; - guint8 channel; - guint8 direction; /* Or for WiFi, high order byte of + uint16_t data_len; + uint16_t source_data_len; + uint8_t version; + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hours; + uint8_t minutes; + uint8_t seconds; + uint32_t usecs; + uint8_t flags; /* Bit-field positions defined below */ + uint8_t signal_level_percent; + uint8_t rate; + uint8_t band; + uint8_t channel; + uint8_t direction; /* Or for WiFi, high order byte of * packet rate. */ - gint8 signal_level_dbm; /* WiFi-only */ - gint8 noise_level_dbm; /* WiFi-only */ + int8_t signal_level_dbm; /* WiFi-only */ + int8_t noise_level_dbm; /* WiFi-only */ } commview_ncf_header_t; #define COMMVIEW_NCF_HEADER_SIZE 24 @@ -82,15 +82,15 @@ typedef struct commview_ncf_header { #define BAND_11N_5GHZ 0x40 #define BAND_11N_2_4GHZ 0x80 -static gboolean commview_ncf_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean commview_ncf_seek_read(wtap *wth, gint64 seek_off, +static bool commview_ncf_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool commview_ncf_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); -static gboolean commview_ncf_read_header(commview_ncf_header_t *cv_hdr, FILE_T fh, - int *err, gchar **err_info); -static gboolean commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); + Buffer *buf, int *err, char **err_info); +static bool commview_ncf_read_header(commview_ncf_header_t *cv_hdr, FILE_T fh, + int *err, char **err_info); +static bool commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); static int commview_ncf_file_type_subtype = -1; static int commview_ncfx_file_type_subtype = -1; @@ -98,7 +98,7 @@ static int commview_ncfx_file_type_subtype = -1; void register_commview(void); wtap_open_return_val -commview_ncf_open(wtap *wth, int *err, gchar **err_info) +commview_ncf_open(wtap *wth, int *err, char **err_info) { commview_ncf_header_t cv_hdr; @@ -140,14 +140,14 @@ commview_ncf_open(wtap *wth, int *err, gchar **err_info) static int commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { commview_ncf_header_t cv_hdr; struct tm tm; - guint frequency; + unsigned frequency; if(!commview_ncf_read_header(&cv_hdr, fh, err, err_info)) - return FALSE; + return false; /* * The maximum value of cv_hdr.data_len is 65535, which is less * than WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to @@ -165,58 +165,58 @@ commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO; memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = -1; /* Unknown */ - rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = false; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = false; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; switch (cv_hdr.band) { case BAND_11A: rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_channel_type = FALSE; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_channel_type = false; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type = PHDR_802_11A_TURBO_TYPE_NORMAL; - frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE); + frequency = ieee80211_chan_to_mhz(cv_hdr.channel, false); break; case BAND_11B: rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE; - frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE); + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = false; + frequency = ieee80211_chan_to_mhz(cv_hdr.channel, true); break; case BAND_11G: rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.mode = PHDR_802_11G_MODE_NORMAL; - frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE); + frequency = ieee80211_chan_to_mhz(cv_hdr.channel, true); break; case BAND_11A_TURBO: rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type = PHDR_802_11A_TURBO_TYPE_TURBO; - frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE); + frequency = ieee80211_chan_to_mhz(cv_hdr.channel, false); break; case BAND_SUPERG: rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.mode = PHDR_802_11G_MODE_SUPER_G; - frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE); + frequency = ieee80211_chan_to_mhz(cv_hdr.channel, true); break; case BAND_11N_5GHZ: rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N; - frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE); + frequency = ieee80211_chan_to_mhz(cv_hdr.channel, false); break; case BAND_11N_2_4GHZ: rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N; - frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE); + frequency = ieee80211_chan_to_mhz(cv_hdr.channel, true); break; case BAND_PUBLIC_SAFETY: @@ -233,17 +233,17 @@ commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, break; } if (frequency != 0) { - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency = frequency; } - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = cv_hdr.channel; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate = cv_hdr.rate | (cv_hdr.direction << 8); - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = cv_hdr.signal_level_percent; /* @@ -258,11 +258,11 @@ commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, */ if (cv_hdr.signal_level_dbm != 0) { rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_dbm = -cv_hdr.signal_level_dbm; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm = true; } if (cv_hdr.noise_level_dbm != 0) { rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_dbm = -cv_hdr.noise_level_dbm; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm = true; } if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy == PHDR_802_11_PHY_UNKNOWN) { /* @@ -273,7 +273,7 @@ commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, if (RATE_IS_DSSS(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate)) { /* 11b */ rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = false; } else if (RATE_IS_OFDM(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate)) { /* 11a or 11g, depending on the band. */ if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency) { @@ -290,7 +290,7 @@ commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, if (RATE_IS_DSSS(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate)) { /* DSSS, so 11b. */ rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = false; } } break; @@ -303,7 +303,7 @@ commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("commview: unsupported encap for NCF: %u", cv_hdr.flags & FLAGS_MEDIUM); - return FALSE; + return false; } tm.tm_year = cv_hdr.year - 1900; @@ -327,65 +327,65 @@ commview_ncf_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, return wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info); } -static gboolean +static bool commview_ncf_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return commview_ncf_read_packet(wth->fh, rec, buf, err, err_info); } -static gboolean -commview_ncf_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +commview_ncf_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return commview_ncf_read_packet(wth->random_fh, rec, buf, err, err_info); } -static gboolean +static bool commview_ncf_read_header(commview_ncf_header_t *cv_hdr, FILE_T fh, int *err, - gchar **err_info) + char **err_info) { if (!wtap_read_bytes_or_eof(fh, &cv_hdr->data_len, 2, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->source_data_len, 2, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->version, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->year, 2, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->month, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->day, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->hours, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->minutes, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->seconds, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->usecs, 4, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->flags, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->signal_level_percent, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->rate, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->band, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->channel, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->direction, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->signal_level_dbm, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->noise_level_dbm, 1, err, err_info)) - return FALSE; + return false; /* Convert multi-byte values from little endian to host endian format */ cv_hdr->data_len = GUINT16_FROM_LE(cv_hdr->data_len); @@ -393,7 +393,7 @@ commview_ncf_read_header(commview_ncf_header_t *cv_hdr, FILE_T fh, int *err, cv_hdr->year = GUINT16_FROM_LE(cv_hdr->year); cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs); - return TRUE; + return true; } /* Returns 0 if we can write out the specified encapsulation type @@ -415,22 +415,22 @@ commview_ncf_dump_can_write_encap(int encap) } } -/* Returns TRUE on success, FALSE on failure; +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -commview_ncf_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) +static bool +commview_ncf_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { wdh->subtype_write = commview_ncf_dump; /* There is no file header to write out */ - return TRUE; + return true; } /* Write a record for a packet to a dump file. - * Returns TRUE on success, FALSE on failure. */ -static gboolean -commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, - int *err, gchar **err_info _U_) + * Returns true on success, false on failure. */ +static bool +commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, const uint8_t *pd, + int *err, char **err_info _U_) { commview_ncf_header_t cv_hdr = {0}; struct tm *tm; @@ -438,7 +438,7 @@ commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* Don't write out anything bigger than we can read. @@ -446,11 +446,11 @@ commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, * imposes a hard limit.) */ if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } - cv_hdr.data_len = GUINT16_TO_LE((guint16)rec->rec_header.packet_header.caplen); - cv_hdr.source_data_len = GUINT16_TO_LE((guint16)rec->rec_header.packet_header.caplen); + cv_hdr.data_len = GUINT16_TO_LE((uint16_t)rec->rec_header.packet_header.caplen); + cv_hdr.source_data_len = GUINT16_TO_LE((uint16_t)rec->rec_header.packet_header.caplen); cv_hdr.version = 0; tm = localtime(&rec->ts.secs); @@ -563,11 +563,11 @@ commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, 0; cv_hdr.rate = rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate ? - (guint8)(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate & 0xFF) : + (uint8_t)(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate & 0xFF) : 0; cv_hdr.direction = rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate ? - (guint8)((rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate >> 8) & 0xFF) : + (uint8_t)((rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate >> 8) & 0xFF) : 0; cv_hdr.signal_level_percent = rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent ? @@ -589,88 +589,88 @@ commview_ncf_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, default : *err = WTAP_ERR_UNWRITABLE_ENCAP; - return FALSE; + return false; } if (!wtap_dump_file_write(wdh, &cv_hdr.data_len, 2, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.source_data_len, 2, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.version, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.year, 2, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.month, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.day, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.hours, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.minutes, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.seconds, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.usecs, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.flags, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_percent, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.rate, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.band, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.channel, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.direction, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_dbm, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.noise_level_dbm, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; - return TRUE; + return false; + return true; } typedef struct commview_ncfx_header { - guint32 data_len; - guint16 year; - guint8 month; - guint8 day; - guint8 hours; - guint8 minutes; - guint8 seconds; - guint32 usecs; - guint8 medium_type; - guint8 decryption_flag; - guint8 direction; - guint8 reserved1; - guint8 reserved2; + uint32_t data_len; + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hours; + uint8_t minutes; + uint8_t seconds; + uint32_t usecs; + uint8_t medium_type; + uint8_t decryption_flag; + uint8_t direction; + uint8_t reserved1; + uint8_t reserved2; } commview_ncfx_header_t; #define COMMVIEW_NCFX_HEADER_SIZE 20 typedef struct commview_ncfx_rf_header { - guint16 header_len; /* includes extension headers */ - guint16 status_modulation; - guint16 frequency_band; - guint16 channel; - guint8 noise_level_dbm; /* abs(noise in dBm) */ - guint8 signal_level_dbm; /* abs(signal in dBm) */ - guint8 signal_level_percent; - guint8 reserved; - guint32 phy_rate; /* in 100Kbps units */ - guint32 extensions_present; + uint16_t header_len; /* includes extension headers */ + uint16_t status_modulation; + uint16_t frequency_band; + uint16_t channel; + uint8_t noise_level_dbm; /* abs(noise in dBm) */ + uint8_t signal_level_dbm; /* abs(signal in dBm) */ + uint8_t signal_level_percent; + uint8_t reserved; + uint32_t phy_rate; /* in 100Kbps units */ + uint32_t extensions_present; } commview_ncfx_rf_header_t; #define COMMVIEW_NCFX_RF_HEADER_SIZE 20 typedef struct commview_ncfx_mcs_header { - guint8 mcs_index; - guint8 n_streams; - guint8 channel_width; - guint8 guard_interval; + uint8_t mcs_index; + uint8_t n_streams; + uint8_t channel_width; + uint8_t guard_interval; } commview_ncfx_mcs_header_t; #define COMMVIEW_NCFX_MCS_HEADER_SIZE 4 @@ -692,21 +692,21 @@ typedef struct commview_ncfx_mcs_header { /* Presence bits */ #define PRESENCE_MCS_HEADER 0x00000001 /* type 0, bit 0 */ -static gboolean commview_ncfx_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean commview_ncfx_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean commview_ncfx_read_header(commview_ncfx_header_t *cv_hdr, - FILE_T fh, int *err, gchar **err_info); -static gboolean commview_ncfx_read_rf_header(commview_ncfx_rf_header_t *cv_rf_hdr, - FILE_T fh, int *err, gchar **err_info); -static gboolean commview_ncfx_read_mcs_header(commview_ncfx_mcs_header_t *cv_mcs_hdr, - FILE_T fh, int *err, gchar **err_info); -static gboolean commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); +static bool commview_ncfx_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool commview_ncfx_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool commview_ncfx_read_header(commview_ncfx_header_t *cv_hdr, + FILE_T fh, int *err, char **err_info); +static bool commview_ncfx_read_rf_header(commview_ncfx_rf_header_t *cv_rf_hdr, + FILE_T fh, int *err, char **err_info); +static bool commview_ncfx_read_mcs_header(commview_ncfx_mcs_header_t *cv_mcs_hdr, + FILE_T fh, int *err, char **err_info); +static bool commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); wtap_open_return_val -commview_ncfx_open(wtap *wth, int *err, gchar **err_info) +commview_ncfx_open(wtap *wth, int *err, char **err_info) { commview_ncfx_header_t cv_hdr; @@ -762,17 +762,17 @@ commview_ncfx_open(wtap *wth, int *err, gchar **err_info) static int commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { commview_ncfx_header_t cv_hdr; - guint32 length_remaining; + uint32_t length_remaining; struct tm tm; commview_ncfx_rf_header_t cv_rf_hdr; - guint frequency; + unsigned frequency; commview_ncfx_mcs_header_t cv_mcs_hdr; if (!commview_ncfx_read_header(&cv_hdr, fh, err, err_info)) - return FALSE; + return false; /* Amount of data remaining in the record, after the header */ length_remaining = cv_hdr.data_len - COMMVIEW_NCFX_HEADER_SIZE; @@ -789,7 +789,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; /* No FCS */ rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = (cv_hdr.decryption_flag == 0x01); - rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = false; /* * Make sure we have enough data left for the RF header. @@ -798,7 +798,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("commview: RF header goes past the NCFX data length %u", cv_hdr.data_len); - return FALSE; + return false; } length_remaining -= COMMVIEW_NCFX_RF_HEADER_SIZE; @@ -806,7 +806,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, * Read the RF header. */ if (!commview_ncfx_read_rf_header(&cv_rf_hdr, fh, err, err_info)) - return FALSE; + return false; if (cv_rf_hdr.status_modulation & STATUS_MODULATION_HE_PHY) rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11AX; else if (cv_rf_hdr.status_modulation & STATUS_MODULATION_VHT_PHY) @@ -822,7 +822,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, switch (cv_rf_hdr.frequency_band) { case BAND_5GHZ: - frequency = ieee80211_chan_to_mhz(cv_rf_hdr.channel, FALSE); + frequency = ieee80211_chan_to_mhz(cv_rf_hdr.channel, false); if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy == PHDR_802_11_PHY_UNKNOWN) { /* * None of the modulation bits were set, so @@ -833,7 +833,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, break; case BAND_2_4GHZ: - frequency = ieee80211_chan_to_mhz(cv_rf_hdr.channel, TRUE); + frequency = ieee80211_chan_to_mhz(cv_rf_hdr.channel, true); if (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy == PHDR_802_11_PHY_UNKNOWN) { /* * None of the modulation bits were set, so @@ -859,10 +859,10 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, break; } if (frequency != 0) { - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_frequency = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.frequency = frequency; } - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = cv_rf_hdr.channel; /* @@ -871,11 +871,11 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, * pseudo_header.ieee_802_11.data_rate is in units of 500 * Kbits/s. */ - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate = cv_rf_hdr.phy_rate/5; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = cv_rf_hdr.signal_level_percent; /* @@ -887,11 +887,11 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, */ if (cv_rf_hdr.signal_level_dbm != 0) { rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_dbm = -cv_rf_hdr.signal_level_dbm; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_dbm = true; } if (cv_rf_hdr.noise_level_dbm != 0) { rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_dbm = -cv_rf_hdr.noise_level_dbm; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_dbm = true; } if (cv_rf_hdr.extensions_present & PRESENCE_MCS_HEADER) { @@ -903,7 +903,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("commview: MCS header goes past the NCFX data length %u", cv_hdr.data_len); - return FALSE; + return false; } length_remaining -= COMMVIEW_NCFX_MCS_HEADER_SIZE; @@ -912,22 +912,22 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, */ if (!commview_ncfx_read_mcs_header(&cv_mcs_hdr, fh, err, err_info)) - return FALSE; + return false; switch (rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy) { case PHDR_802_11_PHY_11N: - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_mcs_index = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_mcs_index = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.mcs_index = cv_mcs_hdr.mcs_index; /* number of STBC streams? */ switch (cv_mcs_hdr.channel_width) { case 0x00: - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_bandwidth = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_bandwidth = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.bandwidth = PHDR_802_11_BANDWIDTH_20_MHZ; break; case 0x01: - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_bandwidth = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.has_bandwidth = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11n.bandwidth = PHDR_802_11_BANDWIDTH_40_MHZ; break; @@ -947,17 +947,17 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, switch (cv_mcs_hdr.channel_width) { case 0x00: - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.bandwidth = PHDR_802_11_BANDWIDTH_20_MHZ; break; case 0x01: - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.bandwidth = PHDR_802_11_BANDWIDTH_40_MHZ; break; case 0x02: - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.has_bandwidth = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ac.bandwidth = PHDR_802_11_BANDWIDTH_80_MHZ; break; @@ -968,7 +968,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, break; case PHDR_802_11_PHY_11AX: - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ax.has_mcs_index = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ax.has_mcs_index = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ax.mcs = cv_mcs_hdr.mcs_index; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11ax.nsts = cv_mcs_hdr.n_streams; /* Bandwidth stuff? */ @@ -985,7 +985,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("commview: unsupported encap for NCFX: %u", cv_hdr.medium_type); - return FALSE; + return false; } tm.tm_year = cv_hdr.year - 1900; @@ -1008,7 +1008,7 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("commview: File has %u-byte packet, bigger than maximum of %u", length_remaining, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } rec->rec_header.packet_header.len = length_remaining; @@ -1020,31 +1020,31 @@ commview_ncfx_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, return wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info); } -static gboolean +static bool commview_ncfx_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return commview_ncfx_read_packet(wth->fh, rec, buf, err, err_info); } -static gboolean -commview_ncfx_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +commview_ncfx_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return commview_ncfx_read_packet(wth->random_fh, rec, buf, err, err_info); } -static gboolean +static bool commview_ncfx_read_header(commview_ncfx_header_t *cv_hdr, FILE_T fh, int *err, - gchar **err_info) + char **err_info) { if (!wtap_read_bytes_or_eof(fh, &cv_hdr->data_len, 4, err, err_info)) - return FALSE; + return false; /* Convert data length from little endian to host endian format */ cv_hdr->data_len = GUINT32_FROM_LE(cv_hdr->data_len); @@ -1055,69 +1055,69 @@ commview_ncfx_read_header(commview_ncfx_header_t *cv_hdr, FILE_T fh, int *err, *err_info = ws_strdup_printf("commview: NCFX data length %u < %u", cv_hdr->data_len, COMMVIEW_NCFX_HEADER_SIZE); - return FALSE; + return false; } if (!wtap_read_bytes(fh, &cv_hdr->year, 2, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->month, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->day, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->hours, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->minutes, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->seconds, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->usecs, 4, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->medium_type, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->decryption_flag, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->direction, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->reserved1, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_hdr->reserved2, 1, err, err_info)) - return FALSE; + return false; /* Convert multi-byte values from little endian to host endian format */ cv_hdr->year = GUINT16_FROM_LE(cv_hdr->year); cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs); - return TRUE; + return true; } -static gboolean +static bool commview_ncfx_read_rf_header(commview_ncfx_rf_header_t *cv_rf_hdr, FILE_T fh, - int *err, gchar **err_info) + int *err, char **err_info) { if (!wtap_read_bytes(fh, &cv_rf_hdr->header_len, 2, err, err_info)) - return FALSE; + return false; /* Convert header length from little endian to host endian format */ cv_rf_hdr->header_len = GUINT16_FROM_LE(cv_rf_hdr->header_len); if (!wtap_read_bytes(fh, &cv_rf_hdr->status_modulation, 2, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_rf_hdr->frequency_band, 2, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_rf_hdr->channel, 2, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_rf_hdr->noise_level_dbm, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_rf_hdr->signal_level_dbm, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_rf_hdr->signal_level_percent, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_rf_hdr->reserved, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_rf_hdr->phy_rate, 4, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_rf_hdr->extensions_present, 4, err, err_info)) - return FALSE; + return false; /* Convert remaining multi-byte values from little endian to host endian format */ cv_rf_hdr->status_modulation = GUINT16_FROM_LE(cv_rf_hdr->status_modulation); @@ -1126,23 +1126,23 @@ commview_ncfx_read_rf_header(commview_ncfx_rf_header_t *cv_rf_hdr, FILE_T fh, cv_rf_hdr->phy_rate = GUINT32_FROM_LE(cv_rf_hdr->phy_rate); cv_rf_hdr->extensions_present = GUINT32_FROM_LE(cv_rf_hdr->extensions_present); - return TRUE; + return true; } -static gboolean +static bool commview_ncfx_read_mcs_header(commview_ncfx_mcs_header_t *cv_mcs_hdr, FILE_T fh, - int *err, gchar **err_info) + int *err, char **err_info) { if (!wtap_read_bytes(fh, &cv_mcs_hdr->mcs_index, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_mcs_hdr->n_streams, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_mcs_hdr->channel_width, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &cv_mcs_hdr->guard_interval, 1, err, err_info)) - return FALSE; + return false; - return TRUE; + return true; } /* Returns 0 if we can write out the specified encapsulation type @@ -1163,22 +1163,22 @@ commview_ncfx_dump_can_write_encap(int encap) } } -/* Returns TRUE on success, FALSE on failure; +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -commview_ncfx_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) +static bool +commview_ncfx_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { wdh->subtype_write = commview_ncfx_dump; /* There is no file header to write out */ - return TRUE; + return true; } /* Write a record for a packet to a dump file. - * Returns TRUE on success, FALSE on failure. */ -static gboolean -commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, - int *err, gchar **err_info _U_) + * Returns true on success, false on failure. */ +static bool +commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec, const uint8_t *pd, + int *err, char **err_info _U_) { commview_ncfx_header_t cv_hdr = {0}; struct tm *tm; @@ -1186,7 +1186,7 @@ commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* Don't write out anything bigger than we can read. @@ -1194,10 +1194,10 @@ commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, * imposes a hard limit.) */ if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } - cv_hdr.data_len = GUINT32_TO_LE((guint32)rec->rec_header.packet_header.caplen); + cv_hdr.data_len = GUINT32_TO_LE((uint32_t)rec->rec_header.packet_header.caplen); tm = localtime(&rec->ts.secs); if (tm != NULL) { @@ -1294,49 +1294,49 @@ commview_ncfx_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, cv_hdr.reserved = 0; cv_hdr.phy_rate = rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate ? - (guint32)(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate & 0xFF) : + (uint32_t)(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate & 0xFF) : 0; #endif break; default : *err = WTAP_ERR_UNWRITABLE_ENCAP; - return FALSE; + return false; } if (!wtap_dump_file_write(wdh, &cv_hdr.data_len, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.year, 2, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.month, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.day, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.hours, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.minutes, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.seconds, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.usecs, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.medium_type, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.decryption_flag, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.direction, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.reserved1, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &cv_hdr.reserved2, 1, err)) - return FALSE; + return false; /* XXX - RF and MCS headers */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; - return TRUE; + return true; } static const struct supported_block_type commview_blocks_supported[] = { @@ -1348,13 +1348,13 @@ static const struct supported_block_type commview_blocks_supported[] = { static const struct file_type_subtype_info commview_ncf_info = { "TamoSoft CommView NCF", "commview-ncf", "ncf", NULL, - FALSE, BLOCKS_SUPPORTED(commview_blocks_supported), + false, BLOCKS_SUPPORTED(commview_blocks_supported), commview_ncf_dump_can_write_encap, commview_ncf_dump_open, NULL }; static const struct file_type_subtype_info commview_ncfx_info = { "TamoSoft CommView NCFX", "commview-ncfx", "ncfx", NULL, - FALSE, BLOCKS_SUPPORTED(commview_blocks_supported), + false, BLOCKS_SUPPORTED(commview_blocks_supported), commview_ncfx_dump_can_write_encap, commview_ncfx_dump_open, NULL }; diff --git a/wiretap/commview.h b/wiretap/commview.h index 59efd7c6..90bc4c0b 100644 --- a/wiretap/commview.h +++ b/wiretap/commview.h @@ -11,10 +11,11 @@ #define __COMMVIEW_H__ #include <glib.h> #include "ws_symbol_export.h" +#include "wtap.h" -wtap_open_return_val commview_ncf_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val commview_ncf_open(wtap *wth, int *err, char **err_info); -wtap_open_return_val commview_ncfx_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val commview_ncfx_open(wtap *wth, int *err, char **err_info); #endif /* __COMMVIEW_H__ */ diff --git a/wiretap/cosine.c b/wiretap/cosine.c index f9adc43c..f6be9455 100644 --- a/wiretap/cosine.c +++ b/wiretap/cosine.c @@ -10,8 +10,8 @@ */ #include "config.h" -#include "wtap-int.h" #include "cosine.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <stdlib.h> @@ -145,26 +145,26 @@ #define COSINE_HEADER_LINES_TO_CHECK 200 #define COSINE_LINE_LENGTH 240 -static gboolean empty_line(const gchar *line); -static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info, +static bool empty_line(const char *line); +static int64_t cosine_seek_next_packet(wtap *wth, int *err, char **err_info, char *hdr); -static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info); -static gboolean cosine_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean cosine_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static int parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, - char *line, int *err, gchar **err_info); -static int parse_single_hex_dump_line(char* rec, guint8 *buf, - guint byte_offset); +static bool cosine_check_file_type(wtap *wth, int *err, char **err_info); +static bool cosine_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool cosine_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, + char *line, int *err, char **err_info); +static int parse_single_hex_dump_line(char* rec, uint8_t *buf, + unsigned byte_offset); static int cosine_file_type_subtype = -1; void register_cosine(void); -/* Returns TRUE if the line appears to be an empty line. Otherwise it - returns FALSE. */ -static gboolean empty_line(const gchar *line) +/* Returns true if the line appears to be an empty line. Otherwise it + returns false. */ +static bool empty_line(const char *line) { while (*line) { if (g_ascii_isspace(*line)) { @@ -175,19 +175,19 @@ static gboolean empty_line(const gchar *line) } } if (*line == '\0') - return TRUE; + return true; else - return FALSE; + return false; } /* Seeks to the beginning of the next packet, and returns the byte offset. Copy the header line to hdr. Returns -1 on failure, and sets "*err" to the error and sets "*err_info" to null or an additional error string. */ -static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info, +static int64_t cosine_seek_next_packet(wtap *wth, int *err, char **err_info, char *hdr) { - gint64 cur_off; + int64_t cur_off; char buf[COSINE_LINE_LENGTH]; while (1) { @@ -213,15 +213,15 @@ static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info, /* Look through the first part of a file to see if this is * a CoSine L2 debug output. * - * 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 cosine_check_file_type(wtap *wth, int *err, gchar **err_info) +static bool cosine_check_file_type(wtap *wth, int *err, char **err_info) { char buf[COSINE_LINE_LENGTH]; - gsize reclen; - guint line; + size_t reclen; + unsigned line; buf[COSINE_LINE_LENGTH-1] = '\0'; @@ -229,7 +229,7 @@ static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info) if (file_gets(buf, COSINE_LINE_LENGTH, wth->fh) == NULL) { /* EOF or error. */ *err = file_error(wth->fh, err_info); - return FALSE; + return false; } reclen = strlen(buf); @@ -239,15 +239,15 @@ static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info) if (strstr(buf, COSINE_HDR_MAGIC_STR1) || strstr(buf, COSINE_HDR_MAGIC_STR2)) { - return TRUE; + return true; } } *err = 0; - return FALSE; + return false; } -wtap_open_return_val cosine_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val cosine_open(wtap *wth, int *err, char **err_info) { /* Look for CoSine header */ if (!cosine_check_file_type(wth, err, err_info)) { @@ -278,16 +278,16 @@ wtap_open_return_val cosine_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean cosine_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool cosine_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { - gint64 offset; + int64_t offset; char line[COSINE_LINE_LENGTH]; /* Find the next packet */ offset = cosine_seek_next_packet(wth, err, err_info, line); if (offset < 0) - return FALSE; + return false; *data_offset = offset; /* Parse the header and convert the ASCII hex dump to binary data */ @@ -295,21 +295,21 @@ static gboolean cosine_read(wtap *wth, wtap_rec *rec, Buffer *buf, } /* Used to read packets in random-access fashion */ -static gboolean -cosine_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +cosine_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { char line[COSINE_LINE_LENGTH]; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (file_gets(line, COSINE_LINE_LENGTH, wth->random_fh) == NULL) { *err = file_error(wth->random_fh, err_info); if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } /* Parse the header and convert the ASCII hex dump to binary data */ @@ -322,18 +322,18 @@ cosine_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, 2002-5-10,20:1:31.4: l2-tx (FR:3/7/1:1), Length:18, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0] 2) output to PE without date and time l2-tx (FR:3/7/1:1), Length:18, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0] */ -static gboolean +static bool parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, - char *line, int *err, gchar **err_info) + char *line, int *err, char **err_info) { union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; int num_items_scanned; int yy, mm, dd, hr, min, sec, csec, pkt_len; int pro, off, pri, rm, error; - guint code1, code2; + unsigned code1, code2; char if_name[COSINE_MAX_IF_NAME_LEN] = "", direction[6] = ""; struct tm tm; - guint8 *pd; + uint8_t *pd; int i, hex_lines, n, caplen = 0; if (sscanf(line, "%4d-%2d-%2d,%2d:%2d:%2d.%9d:", @@ -349,7 +349,7 @@ parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, if (num_items_scanned != 17) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("cosine: purported control blade line doesn't have code values"); - return FALSE; + return false; } } else { /* appears to be output to PE */ @@ -362,24 +362,24 @@ parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, if (num_items_scanned != 10) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("cosine: header line is neither control blade nor PE output"); - return FALSE; + return false; } yy = mm = dd = hr = min = sec = csec = 0; } if (pkt_len < 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("cosine: 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("cosine: 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; @@ -444,7 +444,7 @@ parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } if (empty_line(line)) { break; @@ -452,12 +452,12 @@ parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, if ((n = parse_single_hex_dump_line(line, pd, i*16)) == -1) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("cosine: hex dump line doesn't have 16 numbers"); - return FALSE; + return false; } caplen += n; } rec->rec_header.packet_header.caplen = caplen; - return TRUE; + return true; } /* Take a string representing one line from a hex dump and converts @@ -466,7 +466,7 @@ parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, * * Returns number of bytes successfully read, -1 if bad. */ static int -parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset) +parse_single_hex_dump_line(char* rec, uint8_t *buf, unsigned byte_offset) { int num_items_scanned, i; unsigned int bytes[16]; @@ -483,7 +483,7 @@ parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset) num_items_scanned = 16; for (i=0; i<num_items_scanned; i++) { - buf[byte_offset + i] = (guint8)bytes[i]; + buf[byte_offset + i] = (uint8_t)bytes[i]; } return num_items_scanned; @@ -498,7 +498,7 @@ static const struct supported_block_type cosine_blocks_supported[] = { static const struct file_type_subtype_info cosine_info = { "CoSine IPSX L2 capture", "cosine", "txt", NULL, - FALSE, BLOCKS_SUPPORTED(cosine_blocks_supported), + false, BLOCKS_SUPPORTED(cosine_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/cosine.h b/wiretap/cosine.h index 6afa467a..83bac77c 100644 --- a/wiretap/cosine.h +++ b/wiretap/cosine.h @@ -16,6 +16,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val cosine_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val cosine_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/csids.c b/wiretap/csids.c index 584ef6e3..48da19ba 100644 --- a/wiretap/csids.c +++ b/wiretap/csids.c @@ -7,8 +7,8 @@ */ #include "config.h" -#include "wtap-int.h" #include "csids.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <stdlib.h> @@ -27,27 +27,27 @@ */ typedef struct { - gboolean byteswapped; + bool byteswapped; } csids_t; -static gboolean csids_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean csids_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean csids_read_packet(FILE_T fh, csids_t *csids, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool csids_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool csids_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool csids_read_packet(FILE_T fh, csids_t *csids, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); struct csids_header { - guint32 seconds; /* seconds since epoch */ - guint16 zeropad; /* 2 byte zero'ed pads */ - guint16 caplen; /* the capture length */ + uint32_t seconds; /* seconds since epoch */ + uint16_t zeropad; /* 2 byte zero'ed pads */ + uint16_t caplen; /* the capture length */ }; static int csids_file_type_subtype = -1; void register_csids(void); -wtap_open_return_val csids_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val csids_open(wtap *wth, int *err, char **err_info) { /* There is no file header. There is only a header for each packet * so we read a packet header and compare the caplen with iplen. They @@ -59,7 +59,7 @@ wtap_open_return_val csids_open(wtap *wth, int *err, gchar **err_info) int tmp,iplen; - gboolean byteswap = FALSE; + bool byteswap = false; struct csids_header hdr; csids_t *csids; @@ -100,13 +100,13 @@ wtap_open_return_val csids_open(wtap *wth, int *err, gchar **err_info) iplen = GUINT16_SWAP_LE_BE(iplen); if( iplen <= hdr.caplen ) { /* we know this format */ - byteswap = TRUE; + byteswap = true; } else { /* don't know this one */ return WTAP_OPEN_NOT_MINE; } } else { - byteswap = FALSE; + byteswap = false; } /* no file header. So reset the fh to 0 so we can read the first packet */ @@ -135,8 +135,8 @@ wtap_open_return_val csids_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean csids_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool csids_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { csids_t *csids = (csids_t *)wth->priv; @@ -146,36 +146,36 @@ static gboolean csids_read(wtap *wth, wtap_rec *rec, Buffer *buf, } /* Used to read packets in random-access fashion */ -static gboolean +static bool csids_seek_read(wtap *wth, - gint64 seek_off, + int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info) + char **err_info) { csids_t *csids = (csids_t *)wth->priv; if( file_seek( wth->random_fh, seek_off, SEEK_SET, err ) == -1 ) - return FALSE; + return false; if( !csids_read_packet( wth->random_fh, csids, rec, buf, err, err_info ) ) { if( *err == 0 ) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool csids_read_packet(FILE_T fh, csids_t *csids, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { struct csids_header hdr; - guint8 *pd; + uint8_t *pd; if( !wtap_read_bytes_or_eof( fh, &hdr, sizeof( struct csids_header), err, err_info ) ) - return FALSE; + return false; hdr.seconds = pntoh32(&hdr.seconds); hdr.caplen = pntoh16(&hdr.caplen); /* @@ -193,7 +193,7 @@ csids_read_packet(FILE_T fh, csids_t *csids, wtap_rec *rec, rec->ts.nsecs = 0; if( !wtap_read_packet_bytes( fh, buf, rec->rec_header.packet_header.caplen, err, err_info ) ) - return FALSE; + return false; pd = ws_buffer_start_ptr( buf ); if( csids->byteswapped ) { @@ -207,7 +207,7 @@ csids_read_packet(FILE_T fh, csids_t *csids, wtap_rec *rec, } } - return TRUE; + return true; } static const struct supported_block_type csids_blocks_supported[] = { @@ -219,7 +219,7 @@ static const struct supported_block_type csids_blocks_supported[] = { static const struct file_type_subtype_info csids_info = { "CSIDS IPLog", "csids", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(csids_blocks_supported), + false, BLOCKS_SUPPORTED(csids_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/csids.h b/wiretap/csids.h index 64ea4aa6..dcc34bd7 100644 --- a/wiretap/csids.h +++ b/wiretap/csids.h @@ -13,6 +13,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val csids_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val csids_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c index 67ae4444..61310f48 100644 --- a/wiretap/daintree-sna.c +++ b/wiretap/daintree-sna.c @@ -32,17 +32,17 @@ */ #include "config.h" +#include "daintree-sna.h" #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "daintree-sna.h" typedef struct daintree_sna_header { - guint32 len; - guint64 ts; + uint32_t len; + uint64_t ts; } daintree_sna_header_t; #define DAINTREE_SNA_HEADER_SIZE 2 @@ -57,21 +57,21 @@ static const char daintree_magic_text[] = "#Format="; #define COMMENT_LINE daintree_magic_text[0] -static gboolean daintree_sna_read(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); +static bool daintree_sna_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, int64_t *data_offset); -static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool daintree_sna_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); -static gboolean daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); +static bool daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info); static int daintree_sna_file_type_subtype = -1; void register_daintree_sna(void); /* Open a file and determine if it's a Daintree file */ -wtap_open_return_val daintree_sna_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val daintree_sna_open(wtap *wth, int *err, char **err_info) { char readLine[DAINTREE_MAX_LINE_SIZE]; @@ -120,9 +120,9 @@ wtap_open_return_val daintree_sna_open(wtap *wth, int *err, gchar **err_info) /* Read the capture file sequentially * Wireshark scans the file with sequential reads during preview and initial display. */ -static gboolean +static bool daintree_sna_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); @@ -132,12 +132,12 @@ daintree_sna_read(wtap *wth, wtap_rec *rec, Buffer *buf, /* Read the capture file randomly * Wireshark opens the capture file for random access when displaying user-selected packets */ -static gboolean -daintree_sna_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +daintree_sna_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* parse that line and the following packet data */ return daintree_sna_read_packet(wth->random_fh, rec, buf, err, @@ -148,24 +148,24 @@ daintree_sna_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, * Then convert packet data from ASCII hex string to binary in place, * sanity-check its length against what we assume is the packet length field, * and copy it into a Buffer. */ -static gboolean +static bool daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { - guint64 seconds; + uint64_t seconds; int useconds; char readLine[DAINTREE_MAX_LINE_SIZE]; char readData[READDATA_BUF_SIZE]; - guchar *str = (guchar *)readData; - guint bytes; - guint8 *p; + unsigned char *str = (unsigned char *)readData; + unsigned bytes; + uint8_t *p; /* we've only seen file header lines starting with '#', but * if others appear in the file, they are tossed */ do { if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, fh) == NULL) { *err = file_error(fh, err_info); - return FALSE; /* all done */ + return false; /* all done */ } } while (readLine[0] == COMMENT_LINE); @@ -177,7 +177,7 @@ daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, &seconds, &useconds, &rec->rec_header.packet_header.len, readData) != 4) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("daintree_sna: invalid read record"); - return FALSE; + return false; } /* Daintree doesn't store the FCS, but pads end of packet with 0xffff, which we toss */ @@ -185,7 +185,7 @@ daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("daintree_sna: packet length <= %u bytes, no frame data present", FCS_LENGTH); - return FALSE; + return false; } rec->rec_header.packet_header.len -= FCS_LENGTH; @@ -199,13 +199,13 @@ daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, */ p = str; /* overlay source buffer */ bytes = 0; - /* convert hex string to guint8 */ + /* convert hex string to uint8_t */ while(*str) { /* most significant nibble */ if (!g_ascii_isxdigit(*str)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("daintree_sna: non-hex digit in hex data"); - return FALSE; + return false; } if(g_ascii_isdigit(*str)) { *p = (*str - '0') << 4; @@ -218,7 +218,7 @@ daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, if (!g_ascii_isxdigit(*str)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("daintree_sna: non-hex digit in hex data"); - return FALSE; + return false; } if(g_ascii_isdigit(*str)) { *p += *str - '0'; @@ -237,21 +237,21 @@ daintree_sna_read_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("daintree_sna: Only %u bytes of packet data", bytes); - return FALSE; + return false; } bytes -= FCS_LENGTH; if (bytes > rec->rec_header.packet_header.len) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("daintree_sna: capture length (%u) > packet length (%u)", bytes, rec->rec_header.packet_header.len); - return FALSE; + return false; } rec->rec_header.packet_header.caplen = bytes; ws_buffer_assure_space(buf, bytes); memcpy(ws_buffer_start_ptr(buf), readData, bytes); - return TRUE; + return true; } static const struct supported_block_type daintree_sna_blocks_supported[] = { @@ -263,7 +263,7 @@ static const struct supported_block_type daintree_sna_blocks_supported[] = { static const struct file_type_subtype_info daintree_sna_info = { "Daintree SNA", "dsna", "dcf", NULL, - FALSE, BLOCKS_SUPPORTED(daintree_sna_blocks_supported), + false, BLOCKS_SUPPORTED(daintree_sna_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/daintree-sna.h b/wiretap/daintree-sna.h index 95567c1f..a5fa16bf 100644 --- a/wiretap/daintree-sna.h +++ b/wiretap/daintree-sna.h @@ -13,7 +13,7 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val daintree_sna_open(wtap *wth, int *err, gchar **err_info _U_); +wtap_open_return_val daintree_sna_open(wtap *wth, int *err, char **err_info _U_); #endif /* __DAINTREE_SNA_H__ */ diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c index 4147b039..2ee92eb5 100644 --- a/wiretap/dbs-etherwatch.c +++ b/wiretap/dbs-etherwatch.c @@ -7,8 +7,8 @@ */ #include "config.h" -#include "wtap-int.h" #include "dbs-etherwatch.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <stdlib.h> @@ -56,13 +56,13 @@ Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17 static const char dbs_etherwatch_hdr_magic[] = { 'E', 'T', 'H', 'E', 'R', 'W', 'A', 'T', 'C', 'H', ' '}; #define DBS_ETHERWATCH_HDR_MAGIC_SIZE \ - (sizeof dbs_etherwatch_hdr_magic / sizeof dbs_etherwatch_hdr_magic[0]) + array_length(dbs_etherwatch_hdr_magic) /* Magic text for start of packet */ static const char dbs_etherwatch_rec_magic[] = {'F', 'r', 'o', 'm', ' '}; #define DBS_ETHERWATCH_REC_MAGIC_SIZE \ - (sizeof dbs_etherwatch_rec_magic / sizeof dbs_etherwatch_rec_magic[0]) + array_length(dbs_etherwatch_rec_magic) /* * Default packet size - maximum normal Ethernet packet size, without an @@ -70,15 +70,15 @@ static const char dbs_etherwatch_rec_magic[] = */ #define DBS_ETHERWATCH_MAX_ETHERNET_PACKET_LEN 1514 -static gboolean dbs_etherwatch_read(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); -static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, - Buffer* buf, int *err, gchar **err_info); -static guint parse_single_hex_dump_line(char* rec, guint8 *buf, +static bool dbs_etherwatch_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, int64_t *data_offset); +static bool dbs_etherwatch_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, + Buffer* buf, int *err, char **err_info); +static unsigned parse_single_hex_dump_line(char* rec, uint8_t *buf, int byte_offset); -static guint parse_hex_dump(char* dump, guint8 *buf, char separator, char end); +static unsigned parse_hex_dump(char* dump, uint8_t *buf, char separator, char end); static int dbs_etherwatch_file_type_subtype = -1; @@ -87,12 +87,12 @@ void register_dbs_etherwatch(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 dbs_etherwatch_seek_next_packet(wtap *wth, int *err, - gchar **err_info) +static int64_t dbs_etherwatch_seek_next_packet(wtap *wth, int *err, + char **err_info) { int byte; unsigned int level = 0; - gint64 cur_off; + int64_t cur_off; while ((byte = file_getc(wth->fh)) != EOF) { if (byte == dbs_etherwatch_rec_magic[level]) { @@ -122,16 +122,16 @@ static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err, /* Look through the first part of a file to see if this is * a DBS Ethertrace text 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 error string. */ -static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err, - gchar **err_info) +static bool dbs_etherwatch_check_file_type(wtap *wth, int *err, + char **err_info) { char buf[DBS_ETHERWATCH_LINE_LENGTH]; int line, byte; - gsize reclen; + size_t reclen; unsigned int i, level; buf[DBS_ETHERWATCH_LINE_LENGTH-1] = 0; @@ -140,7 +140,7 @@ static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err, if (file_gets(buf, DBS_ETHERWATCH_LINE_LENGTH, wth->fh) == NULL) { /* EOF or error. */ *err = file_error(wth->fh, err_info); - return FALSE; + return false; } reclen = strlen(buf); @@ -154,7 +154,7 @@ static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err, level++; if (level >= DBS_ETHERWATCH_HDR_MAGIC_SIZE) { - return TRUE; + return true; } } else @@ -162,11 +162,11 @@ static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err, } } *err = 0; - return FALSE; + return false; } -wtap_open_return_val dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val dbs_etherwatch_open(wtap *wth, int *err, char **err_info) { /* Look for DBS ETHERWATCH header */ if (!dbs_etherwatch_check_file_type(wth, err, err_info)) { @@ -194,15 +194,15 @@ wtap_open_return_val dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean dbs_etherwatch_read(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) +static bool dbs_etherwatch_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 = dbs_etherwatch_seek_next_packet(wth, err, err_info); if (offset < 1) - return FALSE; + return false; *data_offset = offset; /* Parse the packet */ @@ -210,12 +210,12 @@ static gboolean dbs_etherwatch_read(wtap *wth, wtap_rec *rec, } /* Used to read packets in random-access fashion */ -static gboolean -dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +dbs_etherwatch_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) - return FALSE; + return false; return parse_dbs_etherwatch_packet(wth->random_fh, rec, buf, err, err_info); @@ -265,19 +265,19 @@ unnumbered. Unnumbered has length 1, numbered 2. */ #define CTL_UNNUMB_MASK 0x03 #define CTL_UNNUMB_VALUE 0x03 -static gboolean +static bool parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, - int *err, gchar **err_info) + int *err, char **err_info) { - guint8 *pd; + uint8_t *pd; char line[DBS_ETHERWATCH_LINE_LENGTH]; int num_items_scanned; int eth_hdr_len, pkt_len, csec; int length_pos, length_from, length; struct tm tm; char mon[4] = "xxx"; - gchar *p; - static const gchar months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"; + char *p; + static const char months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"; int count, line_count; /* Make sure we have enough room for a regular Ethernet packet */ @@ -295,7 +295,7 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } /* Get the destination address */ @@ -303,14 +303,14 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, if(!p) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: destination address not found"); - return FALSE; + return false; } p += strlen(DEST_MAC_PREFIX); if(parse_hex_dump(p, &pd[eth_hdr_len], HEX_HDR_SPR, HEX_HDR_END) != MAC_ADDR_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: destination address not valid"); - return FALSE; + return false; } eth_hdr_len += MAC_ADDR_LENGTH; @@ -328,7 +328,7 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, HEX_HDR_END) != MAC_ADDR_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: source address not valid"); - return FALSE; + return false; } eth_hdr_len += MAC_ADDR_LENGTH; @@ -338,14 +338,14 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } /* Check the lines is as least as long as the length position */ if(strlen(line) < LENGTH_POS) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: line too short"); - return FALSE; + return false; } num_items_scanned = sscanf(line + LENGTH_POS, @@ -358,13 +358,13 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, if (num_items_scanned != 8) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: header line not valid"); - return FALSE; + return false; } if (pkt_len < 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: packet header has a negative packet length"); - return FALSE; + return false; } /* Determine whether it is Ethernet II or IEEE 802 */ @@ -376,7 +376,7 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, HEX_HDR_END) != PROTOCOL_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: Ethernet II protocol value not valid"); - return FALSE; + return false; } eth_hdr_len += PROTOCOL_LENGTH; } else { @@ -392,7 +392,7 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, HEX_HDR_END) != SAP_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: 802.2 DSAP+SSAP value not valid"); - return FALSE; + return false; } eth_hdr_len += SAP_LENGTH; /* Get the (first part of the) control field */ @@ -400,7 +400,7 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, HEX_HDR_END) != CTL_UNNUMB_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: 802.2 control field first part not valid"); - return FALSE; + return false; } /* Determine whether the control is numbered, and thus longer */ if((pd[eth_hdr_len] & CTL_UNNUMB_MASK) != CTL_UNNUMB_VALUE) { @@ -410,7 +410,7 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, HEX_HDR_SPR) != CTL_NUMB_LENGTH - CTL_UNNUMB_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: 802.2 control field second part value not valid"); - return FALSE; + return false; } eth_hdr_len += CTL_NUMB_LENGTH; } else { @@ -424,7 +424,7 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, HEX_PID_END) != PID_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: 802.2 PID value not valid"); - return FALSE; + return false; } eth_hdr_len += PID_LENGTH; } @@ -458,7 +458,7 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dbs_etherwatch: File has %u-byte packet, bigger than maximum of %u", rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } /* Make sure we have enough room, even for an oversized Ethernet packet */ @@ -478,22 +478,22 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } if (!(line_count = parse_single_hex_dump_line(line, &pd[eth_hdr_len + count], count))) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: packet data value not valid"); - return FALSE; + return false; } count += line_count; if (count > pkt_len) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: packet data value has too many bytes"); - return FALSE; + return false; } } - return TRUE; + return true; } /* Parse a hex dump line */ @@ -533,8 +533,8 @@ parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, * * Returns length parsed if a good hex dump, 0 if bad. */ -static guint -parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset) { +static unsigned +parse_single_hex_dump_line(char* rec, uint8_t *buf, int byte_offset) { int pos, i; int value; @@ -596,8 +596,8 @@ parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset) { } /* Parse a hex dump */ -static guint -parse_hex_dump(char* dump, guint8 *buf, char separator, char end) { +static unsigned +parse_hex_dump(char* dump, uint8_t *buf, char separator, char end) { int pos, count; /* Parse the hex dump */ @@ -640,7 +640,7 @@ static const struct supported_block_type dbs_etherwatch_blocks_supported[] = { static const struct file_type_subtype_info dbs_etherwatch_info = { "DBS Etherwatch (VMS)", "etherwatch", "txt", NULL, - FALSE, BLOCKS_SUPPORTED(dbs_etherwatch_blocks_supported), + false, BLOCKS_SUPPORTED(dbs_etherwatch_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/dbs-etherwatch.h b/wiretap/dbs-etherwatch.h index 0ea83c6e..534cb1d0 100644 --- a/wiretap/dbs-etherwatch.h +++ b/wiretap/dbs-etherwatch.h @@ -13,6 +13,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val dbs_etherwatch_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c index 1476247d..6d41b7cf 100644 --- a/wiretap/dct3trace.c +++ b/wiretap/dct3trace.c @@ -13,8 +13,8 @@ */ #include "config.h" -#include "wtap-int.h" #include "dct3trace.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <stdlib.h> @@ -60,10 +60,10 @@ static const char dct3trace_magic_end[] = "</dump>"; #define MAX_PACKET_LEN 23 -static gboolean dct3trace_read(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); -static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool dct3trace_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, int64_t *data_offset); +static bool dct3trace_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int dct3trace_file_type_subtype = -1; @@ -87,9 +87,9 @@ hc2b(unsigned char hex) } static int -hex2bin(guint8 *out, guint8 *out_end, char *in) +hex2bin(uint8_t *out, uint8_t *out_end, char *in) { - guint8 *out_start = out; + uint8_t *out_start = out; int is_low = 0; int c; @@ -121,8 +121,8 @@ hex2bin(guint8 *out, guint8 *out_end, char *in) return (int)(out - out_start); } -static gboolean -xml_get_int(int *val, const char *str, const char *pattern, int *err, gchar **err_info) +static bool +xml_get_int(int *val, const char *str, const char *pattern, int *err, char **err_info) { const char *ptr, *endptr; char *start, *end; @@ -132,7 +132,7 @@ xml_get_int(int *val, const char *str, const char *pattern, int *err, gchar **er if (ptr == NULL) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dct3trace: %s not found", pattern); - return FALSE; + return false; } /* * XXX - should we just skip past the pattern and check for ="? @@ -141,7 +141,7 @@ xml_get_int(int *val, const char *str, const char *pattern, int *err, gchar **er if (start == NULL) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dct3trace: opening quote for %s not found", pattern); - return FALSE; + return false; } start++; /* @@ -152,12 +152,12 @@ xml_get_int(int *val, const char *str, const char *pattern, int *err, gchar **er if (end == NULL) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dct3trace: closing quote for %s not found", pattern); - return FALSE; + return false; } if (end - start > 31) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dct3trace: %s value is too long", pattern); - return FALSE; + return false; } memcpy(buf, start, end - start); @@ -175,18 +175,18 @@ xml_get_int(int *val, const char *str, const char *pattern, int *err, gchar **er *err_info = ws_strdup_printf("dct3trace: %s value is too large, maximum is %d", pattern, *val); } else *err_info = ws_strdup_printf("dct3trace: %s value \"%s\" not a number", pattern, buf); - return FALSE; + return false; } if (*endptr != '\0') { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dct3trace: %s value \"%s\" not a number", pattern, buf); - return FALSE; + return false; } - return TRUE; + return true; } -wtap_open_return_val dct3trace_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val dct3trace_open(wtap *wth, int *err, char **err_info) { char line1[64], line2[64]; @@ -226,12 +226,12 @@ wtap_open_return_val dct3trace_open(wtap *wth, int *err, gchar **err_info) } -static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool dct3trace_get_packet(FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { char line[1024]; - guint8 databuf[MAX_PACKET_LEN], *bufp; - gboolean have_data = FALSE; + uint8_t databuf[MAX_PACKET_LEN], *bufp; + bool have_data = false; int len = 0; bufp = &databuf[0]; @@ -241,7 +241,7 @@ static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, { /* Return on end of file </dump> */ *err = 0; - return FALSE; + return false; } else if( memcmp(dct3trace_magic_record_end, line, strlen(dct3trace_magic_record_end)) == 0 ) { @@ -263,14 +263,14 @@ static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); memcpy( ws_buffer_start_ptr(buf), databuf, rec->rec_header.packet_header.caplen ); - return TRUE; + return true; } else { /* If not got any data return error */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dct3trace: record without data"); - return FALSE; + return false; } } else if( memcmp(dct3trace_magic_record_start, line, strlen(dct3trace_magic_record_start)) == 0 ) @@ -281,25 +281,25 @@ static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, rec->rec_header.packet_header.pseudo_header.gsm_um.uplink = !strstr(line, "direction=\"down\""); if (!xml_get_int(&channel, line, "logicalchannel", err, err_info)) - return FALSE; + return false; /* Parse downlink only fields */ if( !rec->rec_header.packet_header.pseudo_header.gsm_um.uplink ) { if (!xml_get_int(&tmp, line, "physicalchannel", err, err_info)) - return FALSE; + return false; rec->rec_header.packet_header.pseudo_header.gsm_um.arfcn = tmp; if (!xml_get_int(&tmp, line, "sequence", err, err_info)) - return FALSE; + return false; rec->rec_header.packet_header.pseudo_header.gsm_um.tdma_frame = tmp; if (!xml_get_int(&tmp, line, "bsic", err, err_info)) - return FALSE; + return false; rec->rec_header.packet_header.pseudo_header.gsm_um.bsic = tmp; if (!xml_get_int(&tmp, line, "error", err, err_info)) - return FALSE; + return false; rec->rec_header.packet_header.pseudo_header.gsm_um.error = tmp; if (!xml_get_int(&tmp, line, "timeshift", err, err_info)) - return FALSE; + return false; rec->rec_header.packet_header.pseudo_header.gsm_um.timeshift = tmp; } @@ -317,13 +317,13 @@ static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, ptr = strstr(line, "data=\""); if( ptr ) { - have_data = TRUE; /* If has data... */ + have_data = true; /* If has data... */ len = hex2bin(bufp, &databuf[MAX_PACKET_LEN], ptr+6); if (len == -1) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dct3trace: record length %d too long", rec->rec_header.packet_header.caplen); - return FALSE; + return false; } } } @@ -339,7 +339,7 @@ static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, continue; } - have_data = TRUE; + have_data = true; /* * We know we have no data already, so we know @@ -363,7 +363,7 @@ static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dct3trace: record length %d too long", rec->rec_header.packet_header.caplen); - return FALSE; + return false; } len += data_len; @@ -377,13 +377,13 @@ static gboolean dct3trace_get_packet(FILE_T fh, wtap_rec *rec, { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean dct3trace_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool dct3trace_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); @@ -392,12 +392,12 @@ static gboolean dct3trace_read(wtap *wth, wtap_rec *rec, Buffer *buf, /* Used to read packets in random-access fashion */ -static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool dct3trace_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return FALSE; + return false; } return dct3trace_get_packet(wth->random_fh, rec, buf, err, err_info); @@ -412,7 +412,7 @@ static const struct supported_block_type dct3trace_blocks_supported[] = { static const struct file_type_subtype_info dct3trace_info = { "Gammu DCT3 trace", "dct3trace", "xml", NULL, - FALSE, BLOCKS_SUPPORTED(dct3trace_blocks_supported), + false, BLOCKS_SUPPORTED(dct3trace_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/dct3trace.h b/wiretap/dct3trace.h index 297b88bf..41e87024 100644 --- a/wiretap/dct3trace.h +++ b/wiretap/dct3trace.h @@ -12,6 +12,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val dct3trace_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val dct3trace_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/dpa400.c b/wiretap/dpa400.c index 671dbdff..f5ca01fa 100644 --- a/wiretap/dpa400.c +++ b/wiretap/dpa400.c @@ -7,12 +7,12 @@ */ #include "config.h" +#include "dpa400.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "dpa400.h" enum { DPA400_DATA = 0x00, @@ -24,35 +24,35 @@ enum { }; struct dpa400_header { - guint8 t0; - guint8 sb0; - guint8 t1; - guint8 sb1; - guint8 t2; - guint8 sb2; + uint8_t t0; + uint8_t sb0; + uint8_t t1; + uint8_t sb1; + uint8_t t2; + uint8_t sb2; }; static int dpa400_file_type_subtype = -1; void register_dpa400(void); -static gboolean dpa400_read_header(FILE_T fh, struct dpa400_header *hdr, int *err, gchar **err_info) +static bool dpa400_read_header(FILE_T fh, struct dpa400_header *hdr, int *err, char **err_info) { if (!wtap_read_bytes_or_eof(fh, hdr, sizeof(struct dpa400_header), err, err_info)) - return FALSE; + return false; if (hdr->sb0 || hdr->sb1 || hdr->sb2) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dpa400: malformed packet header"); - return FALSE; + return false; } - return TRUE; + return true; } static void get_ts(struct dpa400_header *hdr, nstime_t *ts) { - guint32 val; + uint32_t val; val = (hdr->t0 | (hdr->t1 << 8) | ((hdr->t2 & 0x7f) << 16)) << 5; @@ -62,33 +62,33 @@ static void get_ts(struct dpa400_header *hdr, nstime_t *ts) static void get_ts_overflow(nstime_t *ts) { - guint32 val = 0x7fffff << 5; + uint32_t val = 0x7fffff << 5; ts->secs = val / 1000000; ts->nsecs = (val % 1000000) * 1000; } -static guint8 get_from(struct dpa400_header *hdr) +static uint8_t get_from(struct dpa400_header *hdr) { return hdr->t2 & 0x80; } -static gboolean dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { - guint8 chunk[2]; - guint32 ctr = 0; + uint8_t chunk[2]; + uint32_t ctr = 0; if (!wth || !rec || !buf) - return FALSE; + return false; if (!wtap_read_bytes_or_eof(fh, chunk, sizeof(chunk), err, err_info)) - return FALSE; + return false; if (chunk[1] != 1) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dpa400: malformed packet framing"); - return FALSE; + return false; } ws_buffer_clean(buf); @@ -101,7 +101,7 @@ static gboolean dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, struct dpa400_header hdr; if (!dpa400_read_header(fh, &hdr, err, err_info)) - return FALSE; + return false; get_ts(&hdr, &rec->ts); @@ -118,17 +118,17 @@ static gboolean dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, struct dpa400_header hdr; if (!dpa400_read_header(fh, &hdr, err, err_info)) - return FALSE; + return false; get_ts(&hdr, &rec->ts); if (!wtap_read_bytes_or_eof(fh, chunk, sizeof(chunk), err, err_info)) - return FALSE; + return false; if (chunk[1]) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dpa400: malformed packet"); - return FALSE; + return false; } ws_buffer_append(buf, &chunk[0], 1); @@ -144,10 +144,10 @@ static gboolean dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, case DPA400_DATA: { struct dpa400_header hdr; - guint8 from_source; + uint8_t from_source; if (!dpa400_read_header(fh, &hdr, err, err_info)) - return FALSE; + return false; get_ts(&hdr, &rec->ts); @@ -157,7 +157,7 @@ static gboolean dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, while (1) { if (!wtap_read_bytes_or_eof(fh, chunk, sizeof(chunk), err, err_info)) - return FALSE; + return false; if (chunk[1]) break; @@ -166,7 +166,7 @@ static gboolean dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dpa400: File has data record bigger than maximum of %u", WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } ws_buffer_append(buf, &chunk[0], 1); @@ -194,30 +194,30 @@ static gboolean dpa400_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, default: *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("dpa400: unknown packet type %02x", chunk[0]); - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean dpa400_seek_read(wtap *wth,gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +static bool dpa400_seek_read(wtap *wth,int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return dpa400_read_packet(wth, wth->random_fh, rec, buf, err, err_info); } -static gboolean dpa400_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool dpa400_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return dpa400_read_packet(wth, wth->fh, rec, buf, err, err_info); } -wtap_open_return_val dpa400_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val dpa400_open(wtap *wth, int *err, char **err_info) { char magic[4]; const char dpa_magic[] = { 'D', 'B', 'F', 'R' }; @@ -259,7 +259,7 @@ static const struct supported_block_type dpa400_blocks_supported[] = { static const struct file_type_subtype_info dpa400_info = { "Unigraf DPA-400 capture", "dpa400", "bin", NULL, - FALSE, BLOCKS_SUPPORTED(dpa400_blocks_supported), + false, BLOCKS_SUPPORTED(dpa400_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/dpa400.h b/wiretap/dpa400.h index 2e78cf29..8cf50da8 100644 --- a/wiretap/dpa400.h +++ b/wiretap/dpa400.h @@ -12,7 +12,7 @@ #include "wtap.h" -wtap_open_return_val dpa400_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val dpa400_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/ems.c b/wiretap/ems.c new file mode 100644 index 00000000..cf3380b3 --- /dev/null +++ b/wiretap/ems.c @@ -0,0 +1,295 @@ +/* ems.c + * + * File format support for EGNOS Message Server files + * Copyright (c) 2023 by Timo Warns <timo.warns@gmail.com> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "config.h" + +#define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP + +#include "ems.h" + +#include <stdio.h> + +#include "wtap-int.h" +#include "file_wrappers.h" + +#include <wsutil/buffer.h> +#include <wsutil/nstime.h> +#include <wsutil/strtoi.h> +#include <wsutil/wslog.h> + +static bool ems_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char + **err_info, int64_t *data_offset); +static bool ems_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer + *buf, int *err, char **err_info); + +#define MAX_EMS_LINE_LEN 256 +#define EMS_MSG_SIZE 40 + +typedef struct ems_msg_s { + unsigned int prn; + unsigned int year; + unsigned int month; + unsigned int day; + unsigned int hour; + unsigned int minute; + unsigned int second; + unsigned int mt; + char sbas_msg[64]; +} ems_msg_t; + +static int ems_file_type_subtype = -1; + +/** + * Gets one character and returns in case of error. + * Without error, peeks at next character and returns it. + */ +static int get_and_peek(FILE_T fh) { + int c; + + c = file_getc(fh); + + if (c < 0) { + return c; + } + + return file_peekc(fh); +} + +/** + * Peeks / returns next relevant character. + * Skips whitespace at the beginning of a line, comment lines, and empty + * lines. + */ +static int peek_relevant_character(FILE_T fh) { + int c; + + while (true) { + c = file_peekc(fh); + + if (c < 0) { + return c; + } + + // ignore whitespace at the beginning of a line + else if (g_ascii_isspace(c)) { + ws_debug("ignoring whitespace at the beginning of line"); + do { + c = get_and_peek(fh); + if (c < 0) { + return c; + } + } while (g_ascii_isspace(c)); + + continue; + } + + // ignore comment and empty lines + else if (c == '\r' || c == '\n' || c == '#') { + ws_debug("ignoring comment or empty line"); + do { + c = get_and_peek(fh); + if (c < 0) { + return c; + } + } while (c != '\n'); + + continue; + } + + // return current character for further inspection + else { + return c; + } + } +} + +/** + * Parses EMS line to ems_msg struct. + * Return false on error, true otherwise. + */ +static bool parse_ems_line(FILE_T fh, ems_msg_t* ems_msg) { + char line[MAX_EMS_LINE_LEN]; + int i; + + if (!file_gets(line, array_length(line), fh)) { + return false; + } + + i = sscanf(line, "%03u %02u %02u %02u %02u %02u %02u %u %64c", + &ems_msg->prn, + &ems_msg->year, + &ems_msg->month, + &ems_msg->day, + &ems_msg->hour, + &ems_msg->minute, + &ems_msg->second, + &ems_msg->mt, + ems_msg->sbas_msg); + if (9 != i) { + return false; + } + + if (ems_msg->prn > 255 || + ems_msg->year > 255 || + ems_msg->month > 12 || + ems_msg->day > 31 || + ems_msg->hour > 23 || + ems_msg->minute > 59 || + ems_msg->second > 59 || + ems_msg->mt > 255) { + return false; + } + + return true; +} + +wtap_open_return_val ems_open(wtap *wth, int *err, char **err_info) { + int c; + ems_msg_t msg; + + ws_debug("opening file"); + + // skip irrelevant characters + c = peek_relevant_character(wth->fh); + if (c < 0) { + if (file_eof(wth->fh)) { + return WTAP_OPEN_NOT_MINE; + } + *err = file_error(wth->fh, err_info); + return WTAP_OPEN_ERROR; + } + + // EMS nav msg lines start with a digit (first digit of PRN). + // Check whether current line starts with a digit. + if (!g_ascii_isdigit(c)) { + return WTAP_OPEN_NOT_MINE; + } + + // Check whether the current line matches the EMS format + if (parse_ems_line(wth->fh, &msg)) { + /* return to the beginning of the file */ + if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) { + *err = file_error(wth->fh, err_info); + return WTAP_OPEN_ERROR; + } + + wth->file_encap = WTAP_ENCAP_EMS; + wth->snapshot_length = 0; + wth->file_tsprec = WTAP_TSPREC_SEC; + wth->subtype_read = ems_read; + wth->subtype_seek_read = ems_seek_read; + wth->file_type_subtype = ems_file_type_subtype; + + return WTAP_OPEN_MINE; + } + + return WTAP_OPEN_NOT_MINE; +} + +static bool ems_read_message(FILE_T fh, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { + + int c; + ems_msg_t msg; + + // skip irrelevant characters + c = peek_relevant_character(fh); + if (c < 0) { + *err = file_error(fh, err_info); + return false; + } + + // parse line with EMS message + if (parse_ems_line(fh, &msg)) { + char ts[NSTIME_ISO8601_BUFSIZE + 1]; + + ws_buffer_assure_space(buf, EMS_MSG_SIZE); + + ws_buffer_end_ptr(buf)[0] = msg.prn; + ws_buffer_end_ptr(buf)[1] = msg.year; + ws_buffer_end_ptr(buf)[2] = msg.month; + ws_buffer_end_ptr(buf)[3] = msg.day; + ws_buffer_end_ptr(buf)[4] = msg.hour; + ws_buffer_end_ptr(buf)[5] = msg.minute; + ws_buffer_end_ptr(buf)[6] = msg.second; + ws_buffer_end_ptr(buf)[7] = msg.mt; + + int i; + for (i = 0; i < 32; i++) { + uint8_t v; + char s[3] = {msg.sbas_msg[i*2], msg.sbas_msg[i*2+1], 0}; + if (!ws_hexstrtou8(s, NULL, &v)) { + return false; + } + ws_buffer_end_ptr(buf)[8 + i] = v; + } + + ws_buffer_increase_length(buf, EMS_MSG_SIZE); + + rec->rec_type = REC_TYPE_PACKET; + rec->block = wtap_block_create(WTAP_BLOCK_PACKET); + rec->presence_flags = WTAP_HAS_TS; + rec->rec_header.packet_header.len = EMS_MSG_SIZE; + rec->rec_header.packet_header.caplen = EMS_MSG_SIZE; + + // use EMS timestamp as packet timestamp + snprintf(ts, sizeof(ts), "%04u-%02u-%02uT%02u:%02u:%02uZ", msg.year + + 2000, msg.month, msg.day, msg.hour, msg.minute, msg.second); + iso8601_to_nstime(&rec->ts, ts, ISO8601_DATETIME); + + return true; + } + + return false; +} + +static bool ems_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char + **err_info, int64_t *offset) { + + *offset = file_tell(wth->fh); + ws_debug("reading at offset %" PRId64, *offset); + + if (!ems_read_message(wth->fh, rec, buf, err, err_info)) { + return false; + } + + return true; +} + +static bool ems_seek_read(wtap *wth, int64_t offset, wtap_rec *rec, Buffer + *buf, int *err, char **err_info) { + + if (file_seek(wth->random_fh, offset, SEEK_SET, err) == -1) { + *err = file_error(wth->fh, err_info); + return false; + } + + if (!ems_read_message(wth->random_fh, rec, buf, err, err_info)) { + return false; + } + + return true; +} + +static const struct supported_block_type ems_blocks_supported[] = { + { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED } +}; + +static const struct file_type_subtype_info ems_info = { + "EGNOS Message Server File Format", "ems", "ems", "ems", + false, BLOCKS_SUPPORTED(ems_blocks_supported), + NULL, NULL, NULL +}; + +void register_ems(void) +{ + ems_file_type_subtype = wtap_register_file_type_subtype(&ems_info); + + wtap_register_backwards_compatibility_lua_name("EMS", + ems_file_type_subtype); +} diff --git a/wiretap/ems.h b/wiretap/ems.h new file mode 100644 index 00000000..9cb74926 --- /dev/null +++ b/wiretap/ems.h @@ -0,0 +1,18 @@ +/** @file + * + * EMS file format decoder for the Wiretap library. + * + * Copyright (c) 2023 by Timo Warns <timo.warns@gmail.com> + * + * Wiretap Library + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __W_EMS_H__ +#define __W_EMS_H__ + +#include "wtap.h" + +wtap_open_return_val ems_open(wtap *wth, int *err, char **err_info); + +#endif diff --git a/wiretap/erf-common.h b/wiretap/erf-common.h index d70bf2a2..04dfe355 100644 --- a/wiretap/erf-common.h +++ b/wiretap/erf-common.h @@ -23,7 +23,7 @@ typedef struct erf_private erf_t; erf_t* erf_priv_create(void); erf_t* erf_priv_free(erf_t* erf_priv); -int erf_populate_interface_from_header(erf_t* erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); +int erf_populate_interface_from_header(erf_t* erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, int *err, char **err_info); #endif /* __W_ERF_COMMON_H__ */ diff --git a/wiretap/erf.c b/wiretap/erf.c index c4770ff3..3f24002c 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -29,6 +29,7 @@ */ #include "config.h" +#include "erf.h" #include <stdlib.h> #include <string.h> @@ -41,53 +42,52 @@ #include "wtap-int.h" #include "file_wrappers.h" -#include "erf.h" #include "erf_record.h" #include "erf-common.h" struct erf_anchor_mapping { - guint64 host_id; - guint64 anchor_id; - guint64 gen_time; - gchar *comment; + uint64_t host_id; + uint64_t anchor_id; + uint64_t gen_time; + char *comment; }; -static const guint erf_header_size = (guint)sizeof(erf_header_t); -static const guint erf_mc_header_size = (guint)sizeof(erf_mc_header_t); -static const guint erf_eth_hdr_size = (guint)sizeof(erf_eth_header_t); +static const unsigned erf_header_size = (unsigned)sizeof(erf_header_t); +static const unsigned erf_mc_header_size = (unsigned)sizeof(erf_mc_header_t); +static const unsigned erf_eth_hdr_size = (unsigned)sizeof(erf_eth_header_t); -static gboolean erf_read_header(wtap *wth, FILE_T fh, +static bool erf_read_header(wtap *wth, FILE_T fh, wtap_rec *rec, erf_header_t *erf_header, int *err, - gchar **err_info, - guint32 *bytes_read, - guint32 *packet_size, + char **err_info, + uint32_t *bytes_read, + uint32_t *packet_size, GPtrArray *anchor_mappings_to_update); -static gboolean erf_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean erf_seek_read(wtap *wth, gint64 seek_off, +static bool erf_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool erf_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + int *err, char **err_info); static void erf_close(wtap *wth); -static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, Buffer *buf, guint32 packet_size, GPtrArray *anchor_mappings_to_update, int *err, gchar **err_info); -static int erf_update_anchors_from_header(erf_t *erf_priv, wtap_rec *rec, union wtap_pseudo_header *pseudo_header, guint64 host_id, GPtrArray *anchor_mappings_to_update); -static int erf_get_source_from_header(union wtap_pseudo_header *pseudo_header, guint64 *host_id, guint8 *source_id); -static int erf_populate_interface(erf_t* erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, guint64 host_id, guint8 source_id, guint8 if_num, int *err, gchar **err_info); +static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, Buffer *buf, uint32_t packet_size, GPtrArray *anchor_mappings_to_update, int *err, char **err_info); +static int erf_update_anchors_from_header(erf_t *erf_priv, wtap_rec *rec, union wtap_pseudo_header *pseudo_header, uint64_t host_id, GPtrArray *anchor_mappings_to_update); +static int erf_get_source_from_header(union wtap_pseudo_header *pseudo_header, uint64_t *host_id, uint8_t *source_id); +static int erf_populate_interface(erf_t* erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, uint64_t host_id, uint8_t source_id, uint8_t if_num, int *err, char **err_info); typedef struct { - gboolean write_next_extra_meta; - gboolean last_meta_periodic; - guint64 host_id; - guint64 implicit_host_id; - guint64 prev_frame_ts; - guint8 prev_erf_type; - guint64 gen_time; + bool write_next_extra_meta; + bool last_meta_periodic; + uint64_t host_id; + uint64_t implicit_host_id; + uint64_t prev_frame_ts; + uint8_t prev_erf_type; + uint64_t gen_time; time_t first_frame_time_sec; time_t prev_inserted_time_sec; - gchar* user_comment_ptr; + char* user_comment_ptr; GPtrArray* periodic_sections; GArray *periodic_extra_ehdrs; GRand *rand; @@ -95,12 +95,12 @@ typedef struct { static erf_dump_t* erf_dump_priv_create(void); static void erf_dump_priv_free(erf_dump_t *dump_priv); -static gboolean erf_dump_priv_compare_capture_comment(wtap_dumper *wdh, erf_dump_t *dump_priv,const union wtap_pseudo_header *pseudo_header, const guint8 *pd); -static gboolean erf_comment_to_sections(wtap_dumper *wdh, guint16 section_type, guint16 section_id, gchar *comment, GPtrArray *sections); -static gboolean erf_wtap_info_to_sections(wtap_dumper *wdh, GPtrArray *sections); -static gboolean get_user_comment_string(wtap_dumper *wdh, gchar** user_comment_ptr); +static bool erf_dump_priv_compare_capture_comment(wtap_dumper *wdh, erf_dump_t *dump_priv,const union wtap_pseudo_header *pseudo_header, const uint8_t *pd); +static bool erf_comment_to_sections(wtap_dumper *wdh, uint16_t section_type, uint16_t section_id, char *comment, GPtrArray *sections); +static bool erf_wtap_info_to_sections(wtap_dumper *wdh, GPtrArray *sections); +static bool get_user_comment_string(wtap_dumper *wdh, char** user_comment_ptr); -static gboolean erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, guint64 timestamp, GPtrArray *sections, GArray *extra_ehdrs, int *err); +static bool erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, uint64_t timestamp, GPtrArray *sections, GArray *extra_ehdrs, int *err); static const struct { int erf_encap_value; @@ -116,85 +116,85 @@ static const struct { { 99, WTAP_ENCAP_ERF }, /*this type added so WTAP_ENCAP_ERF will work and then be treated at ERF->ERF*/ }; -#define NUM_ERF_ENCAPS (sizeof erf_to_wtap_map / sizeof erf_to_wtap_map[0]) +#define NUM_ERF_ENCAPS array_length(erf_to_wtap_map) #define ERF_META_TAG_HEADERLEN 4 -#define ERF_META_TAG_TOTAL_ALIGNED_LENGTH(taglength) ((((guint32)taglength + 0x3U) & ~0x3U) + ERF_META_TAG_HEADERLEN) -#define ERF_META_TAG_ALIGNED_LENGTH(taglength) ((((guint32)taglength + 0x3U) & ~0x3U)) +#define ERF_META_TAG_TOTAL_ALIGNED_LENGTH(taglength) ((((uint32_t)taglength + 0x3U) & ~0x3U) + ERF_META_TAG_HEADERLEN) +#define ERF_META_TAG_ALIGNED_LENGTH(taglength) ((((uint32_t)taglength + 0x3U) & ~0x3U)) #define ERF_PADDING_TO_8(len) ((8 - len % 8) % 8) struct erf_if_info { int if_index; - gchar *name; - gchar *descr; + char *name; + char *descr; int stream_num; struct { - guint filter:1; - guint fcs_len:1; - guint snaplen:1; + unsigned filter:1; + unsigned fcs_len:1; + unsigned snaplen:1; } set_flags; }; struct erf_if_mapping { - guint64 host_id; - guint8 source_id; - struct erf_if_info interfaces[4]; + uint64_t host_id; + uint8_t source_id; + struct erf_if_info interfaces[ERF_MAX_INTERFACES]; - gchar *module_filter_str; + char *module_filter_str; /*here because we could have captures from multiple hosts in the file*/ - gchar *capture_filter_str; - gint8 module_fcs_len; - guint32 module_snaplen; + char *capture_filter_str; + int8_t module_fcs_len; + uint32_t module_snaplen; int interface_metadata; - guint64 interface_gentime; - guint64 module_gentime; + uint64_t interface_gentime; + uint64_t module_gentime; }; struct erf_meta_section { - guint16 type; - guint16 section_id; - guint16 section_length; + uint16_t type; + uint16_t section_id; + uint16_t section_length; GPtrArray *tags; }; struct erf_meta_tag { - guint16 type; - guint16 length; - guint8 *value; + uint16_t type; + uint16_t length; + uint8_t *value; }; struct erf_meta_read_state { - guint8 *tag_ptr; - guint32 remaining_len; + uint8_t *tag_ptr; + uint32_t remaining_len; struct erf_if_mapping *if_map; - guint16 sectiontype; - guint16 sectionid; - guint16 parentsectiontype; - guint16 parentsectionid; + uint16_t sectiontype; + uint16_t sectionid; + uint16_t parentsectiontype; + uint16_t parentsectionid; - guint64 gen_time; + uint64_t gen_time; int interface_metadata; }; -static gboolean erf_wtap_blocks_to_erf_sections(wtap_block_t block, GPtrArray *sections, guint16 section_type, guint16 section_id, wtap_block_foreach_func func); +static bool erf_wtap_blocks_to_erf_sections(wtap_block_t block, GPtrArray *sections, uint16_t section_type, uint16_t section_id, wtap_block_foreach_func func); -static guint32 erf_meta_read_tag(struct erf_meta_tag*, guint8*, guint32); +static uint32_t erf_meta_read_tag(struct erf_meta_tag*, uint8_t*, uint32_t); static int erf_file_type_subtype = -1; void register_erf(void); -static guint erf_anchor_mapping_hash(gconstpointer key) { +static unsigned erf_anchor_mapping_hash(const void *key) { const struct erf_anchor_mapping *anchor_map = (const struct erf_anchor_mapping*) key; - return ((guint32)anchor_map->host_id ^ (guint32)anchor_map->anchor_id); + return ((uint32_t)anchor_map->host_id ^ (uint32_t)anchor_map->anchor_id); } -static gboolean erf_anchor_mapping_equal(gconstpointer a, gconstpointer b) { +static gboolean erf_anchor_mapping_equal(const void *a, const void *b) { const struct erf_anchor_mapping *anchor_map_a = (const struct erf_anchor_mapping*) a ; const struct erf_anchor_mapping *anchor_map_b = (const struct erf_anchor_mapping*) b ; @@ -202,7 +202,7 @@ static gboolean erf_anchor_mapping_equal(gconstpointer a, gconstpointer b) { (anchor_map_a->anchor_id & ERF_EXT_HDR_TYPE_ANCHOR_ID) == (anchor_map_b->anchor_id & ERF_EXT_HDR_TYPE_ANCHOR_ID); } -static void erf_anchor_mapping_destroy(gpointer key) { +static void erf_anchor_mapping_destroy(void *key) { struct erf_anchor_mapping *anchor_map = (struct erf_anchor_mapping*) key; if(anchor_map->comment != NULL) { @@ -213,7 +213,7 @@ static void erf_anchor_mapping_destroy(gpointer key) { anchor_map = NULL; } -static gboolean erf_if_mapping_equal(gconstpointer a, gconstpointer b) +static gboolean erf_if_mapping_equal(const void *a, const void *b) { const struct erf_if_mapping *if_map_a = (const struct erf_if_mapping*) a; const struct erf_if_mapping *if_map_b = (const struct erf_if_mapping*) b; @@ -221,19 +221,19 @@ static gboolean erf_if_mapping_equal(gconstpointer a, gconstpointer b) return if_map_a->source_id == if_map_b->source_id && if_map_a->host_id == if_map_b->host_id; } -static guint erf_if_mapping_hash(gconstpointer key) +static unsigned erf_if_mapping_hash(const void *key) { const struct erf_if_mapping *if_map = (const struct erf_if_mapping*) key; - return (((guint) if_map->host_id) << 16) | if_map->source_id; + return (((unsigned) if_map->host_id) << 16) | if_map->source_id; } -static void erf_if_mapping_destroy(gpointer key) +static void erf_if_mapping_destroy(void *key) { int i = 0; struct erf_if_mapping *if_map = (struct erf_if_mapping*) key; - for (i = 0; i < 4; i++) { + for (i = 0; i < ERF_MAX_INTERFACES; i++) { g_free(if_map->interfaces[i].name); g_free(if_map->interfaces[i].descr); } @@ -242,7 +242,7 @@ static void erf_if_mapping_destroy(gpointer key) g_free(if_map); } -static struct erf_if_mapping* erf_if_mapping_create(guint64 host_id, guint8 source_id) +static struct erf_if_mapping* erf_if_mapping_create(uint64_t host_id, uint8_t source_id) { int i = 0; struct erf_if_mapping *if_map = NULL; @@ -252,13 +252,13 @@ static struct erf_if_mapping* erf_if_mapping_create(guint64 host_id, guint8 sour if_map->host_id = host_id; if_map->source_id = source_id; - for (i = 0; i < 4; i++) { + for (i = 0; i < ERF_MAX_INTERFACES; i++) { if_map->interfaces[i].if_index = -1; if_map->interfaces[i].stream_num = -1; } if_map->module_fcs_len = -1; - if_map->module_snaplen = (guint32) -1; + if_map->module_snaplen = (uint32_t) -1; /* everything else 0 by g_malloc0*/ return if_map; @@ -294,10 +294,10 @@ erf_t* erf_priv_free(erf_t* erf_priv) static void erf_dump_priv_free(erf_dump_t *dump_priv) { if(dump_priv) { if(dump_priv->periodic_sections) { - g_ptr_array_free(dump_priv->periodic_sections, TRUE); + g_ptr_array_free(dump_priv->periodic_sections, true); } if(dump_priv->periodic_extra_ehdrs) { - g_array_free(dump_priv->periodic_extra_ehdrs, TRUE); + g_array_free(dump_priv->periodic_extra_ehdrs, true); } if(dump_priv->user_comment_ptr) { g_free(dump_priv->user_comment_ptr); @@ -310,16 +310,16 @@ static void erf_dump_priv_free(erf_dump_t *dump_priv) { } -static void erf_meta_section_free(gpointer data) { +static void erf_meta_section_free(void *data) { struct erf_meta_section *section_ptr = (struct erf_meta_section*) data; if (section_ptr) { - g_ptr_array_free(section_ptr->tags, TRUE); + g_ptr_array_free(section_ptr->tags, true); section_ptr->tags = NULL; } g_free(section_ptr); } -static void erf_meta_tag_free(gpointer data) { +static void erf_meta_tag_free(void *data) { struct erf_meta_tag *tag_ptr = (struct erf_meta_tag*) data; if (tag_ptr) { g_free(tag_ptr->value); @@ -329,9 +329,9 @@ static void erf_meta_tag_free(gpointer data) { } -static gboolean erf_dump_finish(struct wtap_dumper *wdh, int *err, gchar **err_info _U_) { +static bool erf_dump_finish(struct wtap_dumper *wdh, int *err, char **err_info _U_) { erf_dump_t *dump_priv = (erf_dump_t*)wdh->priv; - gboolean ret = TRUE; + bool ret = true; /* Write final metadata record. There are some corner cases where we should * do this (file <1 second, last record was ERF_TYPE_META with an out of date @@ -350,7 +350,7 @@ static gboolean erf_dump_finish(struct wtap_dumper *wdh, int *err, gchar **err_i } } - if (!erf_write_meta_record(wdh, dump_priv, dump_priv->prev_frame_ts, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) ret = FALSE; + if (!erf_write_meta_record(wdh, dump_priv, dump_priv->prev_frame_ts, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) ret = false; } /* Clean up */ @@ -363,26 +363,26 @@ static gboolean erf_dump_finish(struct wtap_dumper *wdh, int *err, gchar **err_i } static void -erf_free_data(gpointer data, gpointer user_data _U_) +erf_free_data(void *data, void *user_data _U_) { g_free(data); } -extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info) +extern wtap_open_return_val erf_open(wtap *wth, int *err, char **err_info) { int i, n, records_for_erf_check = RECORDS_FOR_ERF_CHECK; int valid_prev = 0; char *s; erf_timestamp_t prevts,ts; erf_header_t header; - guint32 mc_hdr; + uint32_t mc_hdr; struct erf_eth_hdr eth_hdr; - guint32 packet_size; - guint16 rlen; - guint64 erf_ext_header; - guint erf_ext_header_size = (guint)sizeof(erf_ext_header); - guint8 type; + uint32_t packet_size; + uint16_t rlen; + uint64_t erf_ext_header; + unsigned erf_ext_header_size = (unsigned)sizeof(erf_ext_header); + uint8_t type; prevts = 0; @@ -571,11 +571,11 @@ extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean erf_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool erf_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { erf_header_t erf_header; - guint32 packet_size, bytes_read; + uint32_t packet_size, bytes_read; GPtrArray *anchor_mappings_to_update; *data_offset = file_tell(wth->fh); @@ -586,13 +586,13 @@ static gboolean erf_read(wtap *wth, wtap_rec *rec, Buffer *buf, if (!erf_read_header(wth, wth->fh, rec, &erf_header, err, err_info, &bytes_read, &packet_size, anchor_mappings_to_update)) { - g_ptr_array_free(anchor_mappings_to_update, TRUE); - return FALSE; + g_ptr_array_free(anchor_mappings_to_update, true); + return false; } if (!wtap_read_packet_bytes(wth->fh, buf, packet_size, err, err_info)) { - g_ptr_array_free(anchor_mappings_to_update, TRUE); - return FALSE; + g_ptr_array_free(anchor_mappings_to_update, true); + return false; } /* @@ -603,48 +603,48 @@ static gboolean erf_read(wtap *wth, wtap_rec *rec, Buffer *buf, if ((erf_header.type & 0x7F) == ERF_TYPE_META && packet_size > 0) { if (populate_summary_info((erf_t*) wth->priv, wth, &rec->rec_header.packet_header.pseudo_header, buf, packet_size, anchor_mappings_to_update, err, err_info) < 0) { - g_ptr_array_free(anchor_mappings_to_update, TRUE); - return FALSE; + g_ptr_array_free(anchor_mappings_to_update, true); + return false; } } } while ( erf_header.type == ERF_TYPE_PAD ); - g_ptr_array_free(anchor_mappings_to_update, TRUE); + g_ptr_array_free(anchor_mappings_to_update, true); - return TRUE; + return true; } -static gboolean erf_seek_read(wtap *wth, gint64 seek_off, +static bool erf_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { erf_header_t erf_header; - guint32 packet_size; + uint32_t packet_size; GPtrArray *anchor_mappings_to_update; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; anchor_mappings_to_update = g_ptr_array_new_with_free_func(erf_anchor_mapping_destroy); do { if (!erf_read_header(wth, wth->random_fh, rec, &erf_header, err, err_info, NULL, &packet_size, anchor_mappings_to_update)) { - g_ptr_array_free(anchor_mappings_to_update, TRUE); - return FALSE; + g_ptr_array_free(anchor_mappings_to_update, true); + return false; } } while ( erf_header.type == ERF_TYPE_PAD ); - g_ptr_array_free(anchor_mappings_to_update, TRUE); + g_ptr_array_free(anchor_mappings_to_update, true); return wtap_read_packet_bytes(wth->random_fh, buf, packet_size, err, err_info); } static struct erf_anchor_mapping* erf_find_anchor_mapping(erf_t *priv, - guint64 host_id, - guint64 anchor_id) + uint64_t host_id, + uint64_t anchor_id) { struct erf_anchor_mapping mapping = { host_id, @@ -661,41 +661,41 @@ static struct erf_anchor_mapping* erf_find_anchor_mapping(erf_t *priv, } -static gboolean erf_read_header(wtap *wth, FILE_T fh, +static bool erf_read_header(wtap *wth, FILE_T fh, wtap_rec *rec, erf_header_t *erf_header, int *err, - gchar **err_info, - guint32 *bytes_read, - guint32 *packet_size, + char **err_info, + uint32_t *bytes_read, + uint32_t *packet_size, GPtrArray *anchor_mappings_to_update) { union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; - guint8 erf_exhdr[8]; - guint64 erf_exhdr_sw; - guint8 type = 0; - guint32 mc_hdr; - guint32 aal2_hdr; + uint8_t erf_exhdr[8]; + uint64_t erf_exhdr_sw; + uint8_t type = 0; + uint32_t mc_hdr; + uint32_t aal2_hdr; struct wtap_erf_eth_hdr eth_hdr; - guint32 skiplen = 0; + uint32_t skiplen = 0; int i = 0; - int max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr); + int max = array_length(pseudo_header->erf.ehdr_list); erf_t *priv = (erf_t*)wth->priv; int interface_id; - guint64 host_id = ERF_META_HOST_ID_IMPLICIT; - guint8 source_id = 0; - guint8 if_num = 0; - gboolean host_id_found = FALSE; + uint64_t host_id = ERF_META_HOST_ID_IMPLICIT; + uint8_t source_id = 0; + uint8_t if_num = 0; + bool host_id_found = false; if (!wtap_read_bytes_or_eof(fh, erf_header, sizeof(*erf_header), err, err_info)) { - return FALSE; + return false; } if (bytes_read != NULL) { *bytes_read = sizeof(*erf_header); } - *packet_size = g_ntohs(erf_header->rlen) - (guint32)sizeof(*erf_header); + *packet_size = g_ntohs(erf_header->rlen) - (uint32_t)sizeof(*erf_header); if (*packet_size > WTAP_MAX_PACKET_SIZE_STANDARD) { /* @@ -705,7 +705,7 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("erf: File has %u-byte packet, bigger than maximum of %u", *packet_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } if (*packet_size == 0) { @@ -714,12 +714,12 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("erf: File has 0 byte packet"); - return FALSE; + return false; } } { - guint64 ts = pletoh64(&erf_header->ts); + uint64_t ts = pletoh64(&erf_header->ts); /*if ((erf_header->type & 0x7f) != ERF_TYPE_META || wth->file_type_subtype != file_type_subtype_erf) {*/ rec->rec_type = REC_TYPE_PACKET; @@ -755,7 +755,7 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, rec->ts.secs += 1; } - if_num = erf_header->flags & 0x03; + if_num = erf_interface_id_from_flags(erf_header->flags); } /* Copy the ERF pseudo header */ @@ -772,11 +772,11 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, while (type & 0x80){ if (!wtap_read_bytes(fh, &erf_exhdr, sizeof(erf_exhdr), err, err_info)) - return FALSE; + return false; if (bytes_read != NULL) - *bytes_read += (guint32)sizeof(erf_exhdr); - *packet_size -= (guint32)sizeof(erf_exhdr); - skiplen += (guint32)sizeof(erf_exhdr); + *bytes_read += (uint32_t)sizeof(erf_exhdr); + *packet_size -= (uint32_t)sizeof(erf_exhdr); + skiplen += (uint32_t)sizeof(erf_exhdr); erf_exhdr_sw = pntoh64(erf_exhdr); if (i < max) memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw)); @@ -791,7 +791,7 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, if (!host_id_found) host_id = erf_exhdr_sw & ERF_EHDR_HOST_ID_MASK; - host_id_found = TRUE; + host_id_found = true; /* Fall through */ case ERF_EXT_HDR_TYPE_FLOW_ID: /* Source ID is present in both Flow ID and Host ID extension headers */ @@ -807,9 +807,9 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, interface_id = erf_populate_interface((erf_t*) wth->priv, wth, pseudo_header, host_id, source_id, if_num, err, err_info); if (interface_id < 0) { - return FALSE; + return false; } - rec->rec_header.packet_header.interface_id = (guint) interface_id; + rec->rec_header.packet_header.interface_id = (unsigned) interface_id; /* Try to find comment links using Anchor ID. Done here after we found the first Host ID and have updated the implicit Host ID. */ erf_update_anchors_from_header(priv, rec, pseudo_header, host_id, anchor_mappings_to_update); @@ -828,7 +828,7 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, rec->rec_header.packet_header.len = g_htons(erf_header->wlen); rec->rec_header.packet_header.caplen = g_htons(erf_header->wlen); } - return TRUE; + return true; #endif break; case ERF_TYPE_PAD: @@ -845,11 +845,11 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, case ERF_TYPE_DSM_COLOR_ETH: case ERF_TYPE_COLOR_HASH_ETH: if (!wtap_read_bytes(fh, ð_hdr, sizeof(eth_hdr), err, err_info)) - return FALSE; + return false; if (bytes_read != NULL) - *bytes_read += (guint32)sizeof(eth_hdr); - *packet_size -= (guint32)sizeof(eth_hdr); - skiplen += (guint32)sizeof(eth_hdr); + *bytes_read += (uint32_t)sizeof(eth_hdr); + *packet_size -= (uint32_t)sizeof(eth_hdr); + skiplen += (uint32_t)sizeof(eth_hdr); pseudo_header->erf.subhdr.eth_hdr = eth_hdr; break; @@ -861,21 +861,21 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, case ERF_TYPE_MC_AAL2: case ERF_TYPE_COLOR_MC_HDLC_POS: if (!wtap_read_bytes(fh, &mc_hdr, sizeof(mc_hdr), err, err_info)) - return FALSE; + return false; if (bytes_read != NULL) - *bytes_read += (guint32)sizeof(mc_hdr); - *packet_size -= (guint32)sizeof(mc_hdr); - skiplen += (guint32)sizeof(mc_hdr); + *bytes_read += (uint32_t)sizeof(mc_hdr); + *packet_size -= (uint32_t)sizeof(mc_hdr); + skiplen += (uint32_t)sizeof(mc_hdr); pseudo_header->erf.subhdr.mc_hdr = g_ntohl(mc_hdr); break; case ERF_TYPE_AAL2: if (!wtap_read_bytes(fh, &aal2_hdr, sizeof(aal2_hdr), err, err_info)) - return FALSE; + return false; if (bytes_read != NULL) - *bytes_read += (guint32)sizeof(aal2_hdr); - *packet_size -= (guint32)sizeof(aal2_hdr); - skiplen += (guint32)sizeof(aal2_hdr); + *bytes_read += (uint32_t)sizeof(aal2_hdr); + *packet_size -= (uint32_t)sizeof(aal2_hdr); + skiplen += (uint32_t)sizeof(aal2_hdr); pseudo_header->erf.subhdr.aal2_hdr = g_ntohl(aal2_hdr); break; @@ -890,7 +890,7 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, { rec->rec_header.packet_header.len = g_ntohs(erf_header->wlen); rec->rec_header.packet_header.caplen = MIN( g_ntohs(erf_header->wlen), - g_ntohs(erf_header->rlen) - (guint32)sizeof(*erf_header) - skiplen ); + g_ntohs(erf_header->rlen) - (uint32_t)sizeof(*erf_header) - skiplen ); } if (*packet_size > WTAP_MAX_PACKET_SIZE_STANDARD) { @@ -901,10 +901,10 @@ static gboolean erf_read_header(wtap *wth, FILE_T fh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("erf: File has %u-byte packet, bigger than maximum of %u", *packet_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } - return TRUE; + return true; } static int wtap_wtap_encap_to_erf_encap(int encap) @@ -917,15 +917,15 @@ static int wtap_wtap_encap_to_erf_encap(int encap) return -1; } -static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header, int * err) +static bool erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header, int * err) { - guint8 erf_hdr[sizeof(struct erf_mc_phdr)]; - guint8 erf_subhdr[sizeof(union erf_subhdr)]; - guint8 ehdr[8*MAX_ERF_EHDR]; + uint8_t erf_hdr[sizeof(struct erf_mc_phdr)]; + uint8_t erf_subhdr[sizeof(union erf_subhdr)]; + uint8_t ehdr[8*MAX_ERF_EHDR]; size_t size = 0; size_t subhdr_size = 0; int i = 0; - guint8 has_more = 0; + uint8_t has_more = 0; switch(encap){ case WTAP_ENCAP_ERF: @@ -965,11 +965,11 @@ static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pse } break; default: - return FALSE; + return false; } if (!wtap_dump_file_write(wdh, erf_hdr, size, err)) - return FALSE; + return false; /*write out up to MAX_ERF_EHDR extension headers*/ has_more = pseudo_header->erf.phdr.type & 0x80; @@ -981,18 +981,18 @@ static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pse i++; }while(has_more && i < MAX_ERF_EHDR); if (!wtap_dump_file_write(wdh, ehdr, 8*i, err)) - return FALSE; + return false; } if(!wtap_dump_file_write(wdh, erf_subhdr, subhdr_size, err)) - return FALSE; + return false; - return TRUE; + return true; } static void erf_dump_priv_init_gen_time(erf_dump_t *dump_priv) { - gint64 real_time; + int64_t real_time; real_time = g_get_real_time(); /* Convert TimeVal to ERF timestamp */ @@ -1000,8 +1000,8 @@ static void erf_dump_priv_init_gen_time(erf_dump_t *dump_priv) { } -static gboolean erf_write_wtap_option_to_capture_tag(wtap_block_t block _U_, - guint option_id, +static bool erf_write_wtap_option_to_capture_tag(wtap_block_t block _U_, + unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data) { @@ -1014,13 +1014,13 @@ static gboolean erf_write_wtap_option_to_capture_tag(wtap_block_t block _U_, switch(option_id) { case OPT_SHB_USERAPPL: tag_ptr->type = ERF_META_TAG_app_name; - tag_ptr->value = (guint8*)g_strdup(optval->stringval); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(optval->stringval); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); break; case OPT_COMMENT: tag_ptr->type = ERF_META_TAG_comment; - tag_ptr->value = (guint8*)g_strdup(optval->stringval); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(optval->stringval); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); break; default: erf_meta_tag_free(tag_ptr); @@ -1031,11 +1031,11 @@ static gboolean erf_write_wtap_option_to_capture_tag(wtap_block_t block _U_, if (tag_ptr) g_ptr_array_add(section_ptr->tags, tag_ptr); - return TRUE; /* we always succeed */ + return true; /* we always succeed */ } -static gboolean erf_write_wtap_option_to_host_tag(wtap_block_t block _U_, - guint option_id, +static bool erf_write_wtap_option_to_host_tag(wtap_block_t block _U_, + unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data) { @@ -1048,13 +1048,13 @@ static gboolean erf_write_wtap_option_to_host_tag(wtap_block_t block _U_, switch(option_id) { case OPT_SHB_HARDWARE: tag_ptr->type = ERF_META_TAG_cpu; - tag_ptr->value = (guint8*)g_strdup(optval->stringval); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(optval->stringval); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); break; case OPT_SHB_OS: tag_ptr->type = ERF_META_TAG_os; - tag_ptr->value = (guint8*)g_strdup(optval->stringval); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(optval->stringval); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); break; default: erf_meta_tag_free(tag_ptr); @@ -1065,11 +1065,11 @@ static gboolean erf_write_wtap_option_to_host_tag(wtap_block_t block _U_, if (tag_ptr) g_ptr_array_add(section_ptr->tags, tag_ptr); - return TRUE; /* we always succeed */ + return true; /* we always succeed */ } -static gboolean erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_, - guint option_id, +static bool erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_, + unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data) { @@ -1082,47 +1082,47 @@ static gboolean erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_, switch(option_id) { case OPT_COMMENT: tag_ptr->type = ERF_META_TAG_comment; - tag_ptr->value = (guint8*)g_strdup(optval->stringval); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(optval->stringval); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); break; case OPT_IDB_NAME: tag_ptr->type = ERF_META_TAG_name; - tag_ptr->value = (guint8*)g_strdup(optval->stringval); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(optval->stringval); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); break; case OPT_IDB_DESCRIPTION: tag_ptr->type = ERF_META_TAG_descr; - tag_ptr->value = (guint8*)g_strdup(optval->stringval); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(optval->stringval); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); break; case OPT_IDB_OS: tag_ptr->type = ERF_META_TAG_os; - tag_ptr->value = (guint8*)g_strdup(optval->stringval); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(optval->stringval); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); break; case OPT_IDB_TSOFFSET: tag_ptr->type = ERF_META_TAG_ts_offset; tag_ptr->length = 8; - tag_ptr->value = (guint8*)g_malloc(sizeof(optval->uint64val)); + tag_ptr->value = (uint8_t*)g_malloc(sizeof(optval->uint64val)); /* convert to relative ERF timestamp */ phtolell(tag_ptr->value, optval->uint64val << 32); break; case OPT_IDB_SPEED: tag_ptr->type = ERF_META_TAG_if_speed; tag_ptr->length = 8; - tag_ptr->value = (guint8*)g_malloc(sizeof(optval->uint64val)); + tag_ptr->value = (uint8_t*)g_malloc(sizeof(optval->uint64val)); phtonll(tag_ptr->value, optval->uint64val); break; case OPT_IDB_IP4ADDR: tag_ptr->type = ERF_META_TAG_if_ipv4; tag_ptr->length = 4; - tag_ptr->value = (guint8*)g_malloc(sizeof(optval->ipv4val)); + tag_ptr->value = (uint8_t*)g_malloc(sizeof(optval->ipv4val)); memcpy(tag_ptr->value, &optval->ipv4val, sizeof(optval->ipv4val)); break; case OPT_IDB_IP6ADDR: tag_ptr->type = ERF_META_TAG_if_ipv6; tag_ptr->length = 16; - tag_ptr->value = (guint8*)g_malloc(sizeof(optval->ipv6val)); + tag_ptr->value = (uint8_t*)g_malloc(sizeof(optval->ipv6val)); memcpy(tag_ptr->value, &optval->ipv6val, sizeof(optval->ipv6val)); break; case OPT_IDB_FILTER: @@ -1132,23 +1132,23 @@ static gboolean erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_, tag_ptr->type = 0xF800; if(filter->type == if_filter_pcap) { tag_ptr->type = ERF_META_TAG_filter; - tag_ptr->value = (guint8*)g_strdup(filter->data.filter_str); - tag_ptr->length = (guint16)strlen((char*)tag_ptr->value); + tag_ptr->value = (uint8_t*)g_strdup(filter->data.filter_str); + tag_ptr->length = (uint16_t)strlen((char*)tag_ptr->value); } } break; case OPT_IDB_FCSLEN: tag_ptr->type = ERF_META_TAG_fcs_len; tag_ptr->length = 4; - tag_ptr->value = (guint8*)g_malloc(tag_ptr->length); - phtonl(tag_ptr->value, (guint32)optval->uint8val); + tag_ptr->value = (uint8_t*)g_malloc(tag_ptr->length); + phtonl(tag_ptr->value, (uint32_t)optval->uint8val); break; /* TODO: Don't know what to do with these yet */ case OPT_IDB_EUIADDR: #if 0 tag_ptr->type = ERF_META_TAG_if_eui; tag_ptr->length = 8; - tag_ptr->value = (guint8*)g_malloc(sizeof(optval->eui64val)); + tag_ptr->value = (uint8_t*)g_malloc(sizeof(optval->eui64val)); memcpy(tag_ptr->value, &optval->euival, sizeof(optval->eui64val)); break; #endif @@ -1158,7 +1158,7 @@ static gboolean erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_, tag_ptr->length = 6; /*value same format as pcapng (6-byte canonical, padded by write * function automatically to 32-bit boundary)*/ - tag_ptr->value = (guint8*)g_malloc(sizeof(optval->macval)); + tag_ptr->value = (uint8_t*)g_malloc(sizeof(optval->macval)); memcpy(tag_ptr->value, &optval->macval, sizeof(optval->macval)); break; #endif @@ -1174,11 +1174,11 @@ static gboolean erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_, if (tag_ptr) g_ptr_array_add(section_ptr->tags, tag_ptr); - return TRUE; /* we always succeed */ + return true; /* we always succeed */ } static void erf_populate_section_length_by_tags(struct erf_meta_section *section_ptr) { - guint i = 0; + unsigned i = 0; struct erf_meta_tag *tag_ptr; section_ptr->section_length = 8; @@ -1197,12 +1197,12 @@ static void erf_populate_section_length_by_tags(struct erf_meta_section *section * @param section_id Section ID to assign * @param func a wtap_block_foreach_func call back function to specify * what needs to be done on the block - * @return TRUE if success, FALSE if failed + * @return true if success, false if failed */ -static gboolean erf_wtap_blocks_to_erf_sections(wtap_block_t block, GPtrArray *sections, guint16 section_type, guint16 section_id, wtap_block_foreach_func func) { +static bool erf_wtap_blocks_to_erf_sections(wtap_block_t block, GPtrArray *sections, uint16_t section_type, uint16_t section_id, wtap_block_foreach_func func) { if(!block || !sections || !func) { - return FALSE; + return false; } struct erf_meta_section *section_ptr; @@ -1216,58 +1216,58 @@ static gboolean erf_wtap_blocks_to_erf_sections(wtap_block_t block, GPtrArray *s erf_populate_section_length_by_tags(section_ptr); g_ptr_array_add(sections, section_ptr); - return TRUE; + return true; } -static gboolean erf_meta_write_tag(wtap_dumper *wdh, struct erf_meta_tag *tag_ptr, int *err) { +static bool erf_meta_write_tag(wtap_dumper *wdh, struct erf_meta_tag *tag_ptr, int *err) { - guint16 data[2]; - guint pad = 0; + uint16_t data[2]; + unsigned pad = 0; /* we only need to pad up to 32 bits*/ - guint32 padbuf = 0; + uint32_t padbuf = 0; pad = ERF_META_TAG_ALIGNED_LENGTH(tag_ptr->length) - tag_ptr->length; data[0] = g_htons(tag_ptr->type); data[1] = g_htons(tag_ptr->length); - if(!wtap_dump_file_write(wdh, data, sizeof(data), err)) return FALSE; + if(!wtap_dump_file_write(wdh, data, sizeof(data), err)) return false; - if(!wtap_dump_file_write(wdh, tag_ptr->value, tag_ptr->length, err)) return FALSE; + if(!wtap_dump_file_write(wdh, tag_ptr->value, tag_ptr->length, err)) return false; if(pad) { - if(!wtap_dump_file_write(wdh, &padbuf, pad, err)) return FALSE; + if(!wtap_dump_file_write(wdh, &padbuf, pad, err)) return false; } - return TRUE; + return true; } -static gboolean erf_meta_write_section(wtap_dumper *wdh, struct erf_meta_section *section_ptr, int *err) { +static bool erf_meta_write_section(wtap_dumper *wdh, struct erf_meta_section *section_ptr, int *err) { struct erf_meta_tag *tag_ptr; - guint i; - guint16 data[4]; + unsigned i; + uint16_t data[4]; data[0] = g_htons(section_ptr->type); data[1] = g_htons(4); /*section header length*/ data[2] = g_htons(section_ptr->section_id); data[3] = g_htons(section_ptr->section_length); - if(!wtap_dump_file_write(wdh, data, sizeof(data), err)) return FALSE; + if(!wtap_dump_file_write(wdh, data, sizeof(data), err)) return false; for(i = 0; i < section_ptr->tags->len; i++) { tag_ptr = (struct erf_meta_tag*)g_ptr_array_index(section_ptr->tags, i); - if(!erf_meta_write_tag(wdh, tag_ptr, err)) return FALSE; + if(!erf_meta_write_tag(wdh, tag_ptr, err)) return false; } - return TRUE; + return true; } -static gboolean erf_wtap_info_to_sections(wtap_dumper *wdh, GPtrArray *sections) { +static bool erf_wtap_info_to_sections(wtap_dumper *wdh, GPtrArray *sections) { wtap_block_t block; - guint i = 0; + unsigned i = 0; block = g_array_index(wdh->shb_hdrs, wtap_block_t, 0); erf_wtap_blocks_to_erf_sections(block, sections, ERF_META_SECTION_CAPTURE, 0, erf_write_wtap_option_to_capture_tag); @@ -1279,17 +1279,17 @@ static gboolean erf_wtap_info_to_sections(wtap_dumper *wdh, GPtrArray *sections) * function as need more metadata records. Just dump them all out for now. */ for(i = 0; i < wdh->interface_data->len; i++) { block = g_array_index(wdh->interface_data, wtap_block_t, i); - erf_wtap_blocks_to_erf_sections(block, sections, ERF_META_SECTION_INTERFACE, (gint16)i+1, erf_write_wtap_option_to_interface_tag); + erf_wtap_blocks_to_erf_sections(block, sections, ERF_META_SECTION_INTERFACE, (int16_t)i+1, erf_write_wtap_option_to_interface_tag); } - return TRUE; + return true; } -static gboolean erf_comment_to_sections(wtap_dumper *wdh _U_, guint16 section_type, guint16 section_id, gchar *comment, GPtrArray *sections){ +static bool erf_comment_to_sections(wtap_dumper *wdh _U_, uint16_t section_type, uint16_t section_id, char *comment, GPtrArray *sections){ struct erf_meta_section *section_ptr; struct erf_meta_tag *comment_tag_ptr = NULL; struct erf_meta_tag *user_tag_ptr = NULL; - const gchar *user = NULL; + const char *user = NULL; /* Generate the section */ section_ptr = g_new(struct erf_meta_section, 1); @@ -1303,8 +1303,8 @@ static gboolean erf_comment_to_sections(wtap_dumper *wdh _U_, guint16 section_ty /* XXX: if the comment has been cleared write the empty string (which * conveniently is all a zero length tag which means the value is * invalidated) */ - comment_tag_ptr->value = (guint8*)g_strdup(comment ? comment : ""); - comment_tag_ptr->length = (guint16)strlen((char*)comment_tag_ptr->value); + comment_tag_ptr->value = (uint8_t*)g_strdup(comment ? comment : ""); + comment_tag_ptr->length = (uint16_t)strlen((char*)comment_tag_ptr->value); g_ptr_array_add(section_ptr->tags, comment_tag_ptr); user = g_get_user_name(); @@ -1312,8 +1312,8 @@ static gboolean erf_comment_to_sections(wtap_dumper *wdh _U_, guint16 section_ty /* Generate username tag */ user_tag_ptr = g_new(struct erf_meta_tag, 1); user_tag_ptr->type = ERF_META_TAG_user; - user_tag_ptr->value = (guint8*)g_strdup(user); - user_tag_ptr->length = (guint16)strlen((char*)user_tag_ptr->value); + user_tag_ptr->value = (uint8_t*)g_strdup(user); + user_tag_ptr->length = (uint16_t)strlen((char*)user_tag_ptr->value); g_ptr_array_add(section_ptr->tags, user_tag_ptr); } @@ -1321,37 +1321,37 @@ static gboolean erf_comment_to_sections(wtap_dumper *wdh _U_, guint16 section_ty g_ptr_array_add(sections, section_ptr); - return TRUE; + return true; } -static guint64 erf_get_random_anchor_id(erf_dump_t *dump_priv) { - return (((guint64)g_rand_int(dump_priv->rand) << 32) | (guint64)g_rand_int(dump_priv->rand)) >> 16; +static uint64_t erf_get_random_anchor_id(erf_dump_t *dump_priv) { + return (((uint64_t)g_rand_int(dump_priv->rand) << 32) | (uint64_t)g_rand_int(dump_priv->rand)) >> 16; } -static guint64 erf_metaid_ext_hdr(guint8 exthdr_type, guint64 id, guint8 srcid_flags) { - guint64 ext_hdr; +static uint64_t erf_metaid_ext_hdr(uint8_t exthdr_type, uint64_t id, uint8_t srcid_flags) { + uint64_t ext_hdr; ext_hdr = id & ERF_EHDR_HOST_ID_MASK; - ext_hdr |= ((guint64)srcid_flags) << 48; - ext_hdr |= ((guint64)exthdr_type) << 56; + ext_hdr |= ((uint64_t)srcid_flags) << 48; + ext_hdr |= ((uint64_t)exthdr_type) << 56; return ext_hdr; } #define erf_host_id_ext_hdr(host_id, source_id) erf_metaid_ext_hdr(ERF_EXT_HDR_TYPE_HOST_ID, host_id, source_id) #define erf_anchor_id_ext_hdr(anchor_id, flags) erf_metaid_ext_hdr(ERF_EXT_HDR_TYPE_ANCHOR_ID, anchor_id, flags) -static inline gboolean erf_add_ext_hdr_to_list(guint64 ext_hdr, guint64 comparison_mask, GArray *extra_ehdrs) { +static inline bool erf_add_ext_hdr_to_list(uint64_t ext_hdr, uint64_t comparison_mask, GArray *extra_ehdrs) { /* check for existing Host ID in set and add */ - guint i = 0; + unsigned i = 0; struct erf_ehdr ehdr_tmp; struct erf_ehdr *ehdr_ptr = NULL; if (!extra_ehdrs) - return FALSE; + return false; ext_hdr = ext_hdr & ~ERF_EHDR_MORE_EXTHDR_MASK; if (comparison_mask == 0) - comparison_mask = G_MAXUINT64; + comparison_mask = UINT64_MAX; comparison_mask &= ~ERF_EHDR_MORE_EXTHDR_MASK; @@ -1359,7 +1359,7 @@ static inline gboolean erf_add_ext_hdr_to_list(guint64 ext_hdr, guint64 comparis ehdr_ptr = &g_array_index(extra_ehdrs, struct erf_ehdr, i); /* Check if we already have this Host ID extension header */ if (ext_hdr == (ehdr_ptr->ehdr & comparison_mask)) { - return TRUE; + return true; } } @@ -1371,14 +1371,14 @@ static inline gboolean erf_add_ext_hdr_to_list(guint64 ext_hdr, guint64 comparis ehdr_tmp.ehdr = ext_hdr; /*more flag already cleared above*/ g_array_append_val(extra_ehdrs, ehdr_tmp); - return TRUE; + return true; } -static inline gboolean erf_append_ext_hdr_to_list(guint64 ext_hdr, GArray *extra_ehdrs) { +static inline bool erf_append_ext_hdr_to_list(uint64_t ext_hdr, GArray *extra_ehdrs) { struct erf_ehdr ehdr_tmp; if (!extra_ehdrs) - return FALSE; + return false; ehdr_tmp.ehdr = ext_hdr & ~ERF_EHDR_MORE_EXTHDR_MASK; @@ -1389,28 +1389,28 @@ static inline gboolean erf_append_ext_hdr_to_list(guint64 ext_hdr, GArray *extra g_array_append_val(extra_ehdrs, ehdr_tmp); - return TRUE; + return true; } -static gboolean erf_update_host_id_ext_hdrs_list(erf_dump_t *dump_priv, const union wtap_pseudo_header *pseudo_header, GArray *extra_ehdrs) { - guint8 type; - guint8 erf_type; +static bool erf_update_host_id_ext_hdrs_list(erf_dump_t *dump_priv, const union wtap_pseudo_header *pseudo_header, GArray *extra_ehdrs) { + uint8_t type; + uint8_t erf_type; int has_more; - guint64 hdr; + uint64_t hdr; int i = 0; - guint8 source_id = 0; - guint64 host_id = 0; - gboolean host_id_found = FALSE; + uint8_t source_id = 0; + uint64_t host_id = 0; + bool host_id_found = false; if (!extra_ehdrs) - return FALSE; + return false; erf_type = pseudo_header->erf.phdr.type & 0x7f; has_more = pseudo_header->erf.phdr.type & 0x80; while (has_more && i < MAX_ERF_EHDR) { hdr = pseudo_header->erf.ehdr_list[i].ehdr; - type = (guint8) (hdr >> 56); + type = (uint8_t) (hdr >> 56); switch (type & 0x7f) { case ERF_EXT_HDR_TYPE_HOST_ID: @@ -1419,7 +1419,7 @@ static gboolean erf_update_host_id_ext_hdrs_list(erf_dump_t *dump_priv, const un /* Don't add the wireshark Host ID Source ID 0 twice since we already add it to metadata records */ if (host_id != dump_priv->host_id || source_id != 0) - if (!erf_add_ext_hdr_to_list(hdr, 0, extra_ehdrs)) return FALSE; + if (!erf_add_ext_hdr_to_list(hdr, 0, extra_ehdrs)) return false; if (!host_id_found) { /* XXX: Take the opportunity to update the implicit Host ID if we @@ -1432,7 +1432,7 @@ static gboolean erf_update_host_id_ext_hdrs_list(erf_dump_t *dump_priv, const un } } - host_id_found = TRUE; + host_id_found = true; break; case ERF_EXT_HDR_TYPE_FLOW_ID: if (source_id == 0) /* If no Host ID extension header use the first Source ID only */ @@ -1446,13 +1446,13 @@ static gboolean erf_update_host_id_ext_hdrs_list(erf_dump_t *dump_priv, const un /* Add Source ID with implicit Host ID if not found */ if (!host_id_found) { - guint64 implicit_host_id = dump_priv->implicit_host_id == ERF_META_HOST_ID_IMPLICIT ? 0 : dump_priv->implicit_host_id; + uint64_t implicit_host_id = dump_priv->implicit_host_id == ERF_META_HOST_ID_IMPLICIT ? 0 : dump_priv->implicit_host_id; /* Don't add the wireshark Host ID Source ID 0 twice since we already add it to metadata records */ if (implicit_host_id != dump_priv->host_id || source_id != 0) - if (!erf_add_ext_hdr_to_list(erf_host_id_ext_hdr(implicit_host_id, source_id), 0, extra_ehdrs)) return FALSE; + if (!erf_add_ext_hdr_to_list(erf_host_id_ext_hdr(implicit_host_id, source_id), 0, extra_ehdrs)) return false; } - return TRUE; + return true; } /** @@ -1465,28 +1465,28 @@ static gboolean erf_update_host_id_ext_hdrs_list(erf_dump_t *dump_priv, const un * @param rec record metadata from which to get user comment * @param mutable_hdr pseudo_header to update with Anchor ID for comment record * @param err the error value - * @return A gboolean value to indicate whether the dump was successful + * @return A bool value to indicate whether the dump was successful */ -static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t *dump_priv, const wtap_rec *rec, union wtap_pseudo_header *mutable_hdr, int *err) { +static bool erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t *dump_priv, const wtap_rec *rec, union wtap_pseudo_header *mutable_hdr, int *err) { GArray *meta_ehdrs; GPtrArray* sections = NULL; - guint8 has_more; - guint8 i = 0; - guint8 ext_hdr_count = 0; - guint8 j = 0; - guint64 host_id_src_hdr = ERF_META_HOST_ID_IMPLICIT; - guint64 host_id_own_hdr = erf_host_id_ext_hdr(dump_priv->host_id, 0); - guint64 flow_id_hdr = 0; - guint64 anchor_id_hdr = 0; - gboolean found_host_id = FALSE; - gboolean found_own_host_id = FALSE; - gboolean found_flow_id = FALSE; - gint new_ext_hdrs = 0; - guint8 insert_idx = 0; - guint8 source_id = 0; - gboolean ret = FALSE; - guint64 implicit_host_id = dump_priv->implicit_host_id == ERF_META_HOST_ID_IMPLICIT ? 0 : dump_priv->implicit_host_id; - gchar *pkt_comment; + uint8_t has_more; + uint8_t i = 0; + uint8_t ext_hdr_count = 0; + uint8_t j = 0; + uint64_t host_id_src_hdr = ERF_META_HOST_ID_IMPLICIT; + uint64_t host_id_own_hdr = erf_host_id_ext_hdr(dump_priv->host_id, 0); + uint64_t flow_id_hdr = 0; + uint64_t anchor_id_hdr = 0; + bool found_host_id = false; + bool found_own_host_id = false; + bool found_flow_id = false; + int new_ext_hdrs = 0; + uint8_t insert_idx = 0; + uint8_t source_id = 0; + bool ret = false; + uint64_t implicit_host_id = dump_priv->implicit_host_id == ERF_META_HOST_ID_IMPLICIT ? 0 : dump_priv->implicit_host_id; + char *pkt_comment; /* @@ -1514,8 +1514,8 @@ static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t * has_more = mutable_hdr->erf.phdr.type & 0x80; while (has_more && (i < MAX_ERF_EHDR)) { - guint64 hdr = mutable_hdr->erf.ehdr_list[i].ehdr; - guint8 type = (guint8) (hdr >> 56); + uint64_t hdr = mutable_hdr->erf.ehdr_list[i].ehdr; + uint8_t type = (uint8_t) (hdr >> 56); switch (type & 0x7f) { case ERF_EXT_HDR_TYPE_HOST_ID: @@ -1525,25 +1525,25 @@ static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t * insert_idx = i; if ((hdr & ERF_EHDR_HOST_ID_MASK) == dump_priv->host_id){ - found_own_host_id = TRUE; + found_own_host_id = true; } if (!found_host_id) host_id_src_hdr = hdr; - found_host_id = TRUE; + found_host_id = true; break; case ERF_EXT_HDR_TYPE_FLOW_ID: /*XXX: we only use this when making the implicit host id explicit, * otherwise we'd need to check the one in Host ID header too*/ if (source_id == 0) - source_id = (guint8)(hdr >> 48); + source_id = (uint8_t)(hdr >> 48); if (!found_flow_id) flow_id_hdr = hdr; - found_flow_id = TRUE; + found_flow_id = true; break; } @@ -1558,7 +1558,7 @@ static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t * /* Don't need to add our own Host ID twice if it is the same as the implicit*/ if (!found_host_id && implicit_host_id == dump_priv->host_id) { - found_own_host_id = TRUE; + found_own_host_id = true; } /* @@ -1570,7 +1570,7 @@ static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t * || mutable_hdr->erf.phdr.rlen + new_ext_hdrs * 8 > 65535) { /* Not enough extension header slots to add Anchor ID */ *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } mutable_hdr->erf.phdr.rlen += new_ext_hdrs * 8; @@ -1621,7 +1621,7 @@ static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t * * Now construct the metadata Anchor record with the same Anchor ID */ - meta_ehdrs = g_array_new(FALSE, FALSE, sizeof(struct erf_ehdr)); + meta_ehdrs = g_array_new(false, false, sizeof(struct erf_ehdr)); /* We need up to 4 extension headers on the Provenance metadata record */ /*Required*/ @@ -1661,24 +1661,24 @@ static gboolean erf_write_anchor_meta_update_phdr(wtap_dumper *wdh, erf_dump_t * /* Write the metadata record, but not the packet record as what we do depends * on the WTAP_ENCAP */ ret = erf_write_meta_record(wdh, dump_priv, mutable_hdr->erf.phdr.ts, sections, meta_ehdrs, err); - g_ptr_array_free(sections, TRUE); - g_array_free(meta_ehdrs, TRUE); + g_ptr_array_free(sections, true); + g_array_free(meta_ehdrs, true); return ret; } -static gboolean erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, guint64 timestamp, GPtrArray *sections, GArray *extra_ehdrs, int *err) { +static bool erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, uint64_t timestamp, GPtrArray *sections, GArray *extra_ehdrs, int *err) { union wtap_pseudo_header other_header; struct erf_meta_tag gen_time_tag; struct erf_meta_section *section_ptr; - guint total_wlen = 0; - guint total_rlen = 0; - gint64 alignbytes = 0; - guint i; - guint num_extra_ehdrs = 0; + unsigned total_wlen = 0; + unsigned total_rlen = 0; + int64_t alignbytes = 0; + unsigned i; + unsigned num_extra_ehdrs = 0; if(!sections || sections->len <= 0) - return FALSE; + return false; for(i = 0; i < sections->len; i++) { section_ptr = (struct erf_meta_section*)g_ptr_array_index(sections, i); @@ -1687,7 +1687,7 @@ static gboolean erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, g gen_time_tag.type = ERF_META_TAG_gen_time; gen_time_tag.length = 8U; - gen_time_tag.value = (guint8*)&dump_priv->gen_time; + gen_time_tag.value = (uint8_t*)&dump_priv->gen_time; total_wlen += gen_time_tag.length + 4; total_rlen = total_wlen + 24; /* 24 is the header + extension header length */ @@ -1706,15 +1706,15 @@ static gboolean erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, g if(total_rlen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } other_header.erf.phdr.ts = timestamp; other_header.erf.phdr.type = ERF_TYPE_META | 0x80; other_header.erf.phdr.flags = 0x04; /* Varying record length */ other_header.erf.phdr.lctr = 0; - other_header.erf.phdr.wlen = (guint16)total_wlen; - other_header.erf.phdr.rlen = (guint16)total_rlen; + other_header.erf.phdr.wlen = (uint16_t)total_wlen; + other_header.erf.phdr.rlen = (uint16_t)total_rlen; /*Add our Host ID in Host ID extension header indicating we generated this * record. Source ID 0 to avoid affecting implicit Host ID. */ other_header.erf.ehdr_list[0].ehdr = erf_host_id_ext_hdr(dump_priv->host_id, 0); @@ -1729,7 +1729,7 @@ static gboolean erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, g /* Make sure we always write out rlen, regardless of what happens */ alignbytes = wdh->bytes_dumped + other_header.erf.phdr.rlen; - if(!erf_write_phdr(wdh, WTAP_ENCAP_ERF, &other_header, err)) return FALSE; + if(!erf_write_phdr(wdh, WTAP_ENCAP_ERF, &other_header, err)) return false; /* Generation time */ erf_meta_write_tag(wdh, &gen_time_tag, err); @@ -1741,13 +1741,13 @@ static gboolean erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, g } while(wdh->bytes_dumped < alignbytes){ - if(!wtap_dump_file_write(wdh, "", 1, err)) return FALSE; + if(!wtap_dump_file_write(wdh, "", 1, err)) return false; } /* We wrote new packets, reloading is required */ - wdh->needs_reload = TRUE; + wdh->needs_reload = true; - return TRUE; + return true; } @@ -1755,8 +1755,8 @@ static erf_dump_t *erf_dump_priv_create(void) { erf_dump_t *dump_priv; dump_priv = g_new(erf_dump_t, 1); - dump_priv->write_next_extra_meta = FALSE; - dump_priv->last_meta_periodic = FALSE; + dump_priv->write_next_extra_meta = false; + dump_priv->last_meta_periodic = false; dump_priv->gen_time = 0; dump_priv->host_id = ERF_WS_DEFAULT_HOST_ID; dump_priv->implicit_host_id = ERF_META_HOST_ID_IMPLICIT; @@ -1766,36 +1766,36 @@ static erf_dump_t *erf_dump_priv_create(void) { dump_priv->prev_erf_type = 0; dump_priv->user_comment_ptr = NULL; dump_priv->periodic_sections = NULL; - dump_priv->periodic_extra_ehdrs = g_array_new(FALSE, FALSE, sizeof(struct erf_ehdr)); + dump_priv->periodic_extra_ehdrs = g_array_new(false, false, sizeof(struct erf_ehdr)); dump_priv->rand = g_rand_new(); return dump_priv; } -static gboolean erf_dump( +static bool erf_dump( wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, + const uint8_t *pd, int *err, - gchar **err_info _U_) + char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; union wtap_pseudo_header other_phdr; int erf_type; - gint64 alignbytes = 0; - guint padbytes = 0; + int64_t alignbytes = 0; + unsigned padbytes = 0; int round_down = 0; - gboolean must_add_crc = FALSE; - guint32 crc32 = 0x00000000; + bool must_add_crc = false; + uint32_t crc32 = 0x00000000; erf_dump_t *dump_priv = (erf_dump_t*)wdh->priv; /* Host ID extension header with Host ID 0 (unknown). For now use Source ID 1. */ /* TODO: How to know if record was captured by this Wireshark? */ - guint64 non_erf_host_id_ehdr = erf_host_id_ext_hdr(0, 1); + uint64_t non_erf_host_id_ehdr = erf_host_id_ext_hdr(0, 1); /* Don't write anything bigger than we're willing to read. */ if(rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } if(!dump_priv->gen_time) { @@ -1818,7 +1818,7 @@ static gboolean erf_dump( * support later. */ if (rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_ERF) { - unsigned int total_rlen;; + unsigned int total_rlen; unsigned int total_wlen; /* Non-ERF encapsulation; generate ERF metadata */ @@ -1829,20 +1829,20 @@ static gboolean erf_dump( /* We can only convert packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } erf_type = wtap_wtap_encap_to_erf_encap(rec->rec_header.packet_header.pkt_encap); if (erf_type == -1) { *err = WTAP_ERR_UNWRITABLE_ENCAP; - return FALSE; + return false; } /* Generate a fake header in other_phdr using data that we know*/ memset(&other_phdr, 0, sizeof(union wtap_pseudo_header)); /* Convert time erf timestamp format*/ - other_phdr.erf.phdr.ts = ((guint64) rec->ts.secs << 32) + (((guint64) rec->ts.nsecs <<32) / 1000 / 1000 / 1000); - other_phdr.erf.phdr.type = (guint8)erf_type; + other_phdr.erf.phdr.ts = ((uint64_t) rec->ts.secs << 32) + (((uint64_t) rec->ts.nsecs <<32) / 1000 / 1000 / 1000); + other_phdr.erf.phdr.type = (uint8_t)erf_type; /* Support up to 4 interfaces */ /* TODO: use multiple Source IDs and metadata records to support >4 interfaces */ other_phdr.erf.phdr.flags = rec->rec_header.packet_header.interface_id % ERF_MAX_INTERFACES; @@ -1863,7 +1863,7 @@ static gboolean erf_dump( crc32 = crc32_ccitt_seed(pd, rec->rec_header.packet_header.caplen, 0xFFFFFFFF); total_rlen += 4; /*4 bytes for added checksum*/ total_wlen += 4; - must_add_crc = TRUE; + must_add_crc = true; } } break; @@ -1873,7 +1873,7 @@ static gboolean erf_dump( crc32 = crc32_ccitt_seed(pd, rec->rec_header.packet_header.caplen, 0xFFFFFFFF); total_rlen += 4; /*4 bytes for added checksum*/ total_wlen += 4; - must_add_crc = TRUE; /* XXX - these never have an FCS? */ + must_add_crc = true; /* XXX - these never have an FCS? */ } break; default: @@ -1893,20 +1893,20 @@ static gboolean erf_dump( total_rlen += padbytes; } - if (total_rlen > G_MAXUINT16 || total_wlen > G_MAXUINT16) { + if (total_rlen > UINT16_MAX || total_wlen > UINT16_MAX) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } - other_phdr.erf.phdr.rlen = (guint16)total_rlen; - other_phdr.erf.phdr.wlen = (guint16)total_wlen; + other_phdr.erf.phdr.rlen = (uint16_t)total_rlen; + other_phdr.erf.phdr.wlen = (uint16_t)total_wlen; pseudo_header = &other_phdr; } else if (rec->presence_flags & WTAP_HAS_TS) { // Update timestamp if changed. time_t secs; int nsecs; - guint64 ts = pseudo_header->erf.phdr.ts; + uint64_t ts = pseudo_header->erf.phdr.ts; secs = (long) (ts >> 32); ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000); @@ -1919,7 +1919,7 @@ static gboolean erf_dump( if (secs != rec->ts.secs || nsecs != rec->ts.nsecs) { other_phdr = *pseudo_header; - other_phdr.erf.phdr.ts = ((guint64) rec->ts.secs << 32) + (((guint64) rec->ts.nsecs <<32) / 1000 / 1000 / 1000); + other_phdr.erf.phdr.ts = ((uint64_t) rec->ts.secs << 32) + (((uint64_t) rec->ts.nsecs <<32) / 1000 / 1000 / 1000); pseudo_header = &other_phdr; } } @@ -1952,7 +1952,7 @@ static gboolean erf_dump( erf_comment_to_sections(wdh, ERF_META_SECTION_CAPTURE, 0, dump_priv->user_comment_ptr, dump_priv->periodic_sections); } - if (!erf_write_meta_record(wdh, dump_priv, dump_priv->prev_frame_ts, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) return FALSE; + if (!erf_write_meta_record(wdh, dump_priv, dump_priv->prev_frame_ts, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) return false; dump_priv->prev_inserted_time_sec = rec->ts.secs; /*TODO: clear accumulated existing extension headers here?*/ } @@ -1963,7 +1963,7 @@ static gboolean erf_dump( * trust the Wireshark representation since we massage the fields on * read. */ /* restart searching for next meta record to update capture comment at */ - dump_priv->write_next_extra_meta = FALSE; + dump_priv->write_next_extra_meta = false; } else if (rec->ts.secs > dump_priv->first_frame_time_sec + 1 && dump_priv->prev_inserted_time_sec != rec->ts.secs) { /* For compatibility, don't insert metadata for older ERF files with no changed metadata */ @@ -1981,7 +1981,7 @@ static gboolean erf_dump( /* At second boundaries insert either the updated comment (if we've seen some metadata records * already) or the full metadata */ if (dump_priv->periodic_sections) { - if (!erf_write_meta_record(wdh, dump_priv, (guint64)(rec->ts.secs) << 32, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) return FALSE; + if (!erf_write_meta_record(wdh, dump_priv, (uint64_t)(rec->ts.secs) << 32, dump_priv->periodic_sections, dump_priv->periodic_extra_ehdrs, err)) return false; dump_priv->prev_inserted_time_sec = rec->ts.secs; } } @@ -1997,25 +1997,25 @@ static gboolean erf_dump( * modified)? */ if(rec->block_was_modified) { memmove(&other_phdr, pseudo_header, sizeof(union wtap_pseudo_header)); - if(!erf_write_anchor_meta_update_phdr(wdh, dump_priv, rec, &other_phdr, err)) return FALSE; + if(!erf_write_anchor_meta_update_phdr(wdh, dump_priv, rec, &other_phdr, err)) return false; pseudo_header = &other_phdr; } } else { /* Always write the comment if non-ERF */ - if(!erf_write_anchor_meta_update_phdr(wdh, dump_priv, rec, &other_phdr, err)) return FALSE; + if(!erf_write_anchor_meta_update_phdr(wdh, dump_priv, rec, &other_phdr, err)) return false; } } /* Make sure we always write out rlen, regardless of what happens */ alignbytes = wdh->bytes_dumped + pseudo_header->erf.phdr.rlen; - if(!erf_write_phdr(wdh, WTAP_ENCAP_ERF, pseudo_header, err)) return FALSE; + if(!erf_write_phdr(wdh, WTAP_ENCAP_ERF, pseudo_header, err)) return false; - if(!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen - round_down, err)) return FALSE; + if(!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen - round_down, err)) return false; /*add the 4 byte CRC if necessary*/ if(must_add_crc){ - if(!wtap_dump_file_write(wdh, &crc32, 4, err)) return FALSE; + if(!wtap_dump_file_write(wdh, &crc32, 4, err)) return false; } /*XXX: In the case of ENCAP_ERF, this pads the record to its original length, which is fine in most @@ -2025,13 +2025,13 @@ static gboolean erf_dump( * written out anyway and fixing properly would require major refactor.*/ /*records should be 8byte aligned, so we add padding to our calculated rlen */ while(wdh->bytes_dumped < alignbytes){ - if(!wtap_dump_file_write(wdh, "", 1, err)) return FALSE; + if(!wtap_dump_file_write(wdh, "", 1, err)) return false; } dump_priv->prev_erf_type = pseudo_header->erf.phdr.type & 0x7FU; dump_priv->prev_frame_ts = pseudo_header->erf.phdr.ts; - return TRUE; + return true; } static int erf_dump_can_write_encap(int encap) @@ -2046,11 +2046,11 @@ static int erf_dump_can_write_encap(int encap) return 0; } -static int erf_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) +static bool erf_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { erf_dump_t *dump_priv; - gchar *s; - guint64 host_id; + char *s; + uint64_t host_id; char *first_shb_comment = NULL; dump_priv = erf_dump_priv_create(); @@ -2066,7 +2066,7 @@ static int erf_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) /* XXX: If we have a capture comment or a non-ERF file assume we need to * write metadata unless we see existing metadata in the first second. */ if (dump_priv->user_comment_ptr || wdh->file_encap != WTAP_ENCAP_ERF) - dump_priv->write_next_extra_meta = TRUE; + dump_priv->write_next_extra_meta = true; /* Read Host ID from environment variable */ /* TODO: generate one from MAC address? */ @@ -2077,16 +2077,16 @@ static int erf_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) } } - return TRUE; + return true; } -static int erf_get_source_from_header(union wtap_pseudo_header *pseudo_header, guint64 *host_id, guint8 *source_id) +static int erf_get_source_from_header(union wtap_pseudo_header *pseudo_header, uint64_t *host_id, uint8_t *source_id) { - guint8 type; - guint8 has_more; - guint64 hdr; + uint8_t type; + uint8_t has_more; + uint64_t hdr; int i = 0; - gboolean host_id_found = FALSE; + bool host_id_found = false; if (!pseudo_header || !host_id || !source_id) return -1; @@ -2098,7 +2098,7 @@ static int erf_get_source_from_header(union wtap_pseudo_header *pseudo_header, g while (has_more && (i < MAX_ERF_EHDR)) { hdr = pseudo_header->erf.ehdr_list[i].ehdr; - type = (guint8) (hdr >> 56); + type = (uint8_t) (hdr >> 56); /* * XXX: Only want first Source ID and Host ID, and want to preserve HID n SID 0 (see @@ -2109,7 +2109,7 @@ static int erf_get_source_from_header(union wtap_pseudo_header *pseudo_header, g if (!host_id_found) *host_id = hdr & ERF_EHDR_HOST_ID_MASK; - host_id_found = TRUE; + host_id_found = true; /* Fall through */ case ERF_EXT_HDR_TYPE_FLOW_ID: if (*source_id == 0) @@ -2127,23 +2127,23 @@ static int erf_get_source_from_header(union wtap_pseudo_header *pseudo_header, g return 0; } -int erf_populate_interface_from_header(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) +int erf_populate_interface_from_header(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, int *err, char **err_info) { - guint64 host_id; - guint8 source_id; - guint8 if_num; + uint64_t host_id; + uint8_t source_id; + uint8_t if_num; if (!pseudo_header) return -1; - if_num = pseudo_header->erf.phdr.flags & 0x03; + if_num = (pseudo_header->erf.phdr.flags & 0x03) | ((pseudo_header->erf.phdr.flags & 0x40)>>4); erf_get_source_from_header(pseudo_header, &host_id, &source_id); return erf_populate_interface(erf_priv, wth, pseudo_header, host_id, source_id, if_num, err, err_info); } -static struct erf_if_mapping* erf_find_interface_mapping(erf_t *erf_priv, guint64 host_id, guint8 source_id) +static struct erf_if_mapping* erf_find_interface_mapping(erf_t *erf_priv, uint64_t host_id, uint8_t source_id) { struct erf_if_mapping if_map_lookup; @@ -2157,7 +2157,7 @@ static struct erf_if_mapping* erf_find_interface_mapping(erf_t *erf_priv, guint6 return (struct erf_if_mapping*) g_hash_table_lookup(erf_priv->if_map, &if_map_lookup); } -static void erf_set_interface_descr(wtap_block_t block, guint option_id, guint64 host_id, guint8 source_id, guint8 if_num, const gchar *descr) +static void erf_set_interface_descr(wtap_block_t block, unsigned option_id, uint64_t host_id, uint8_t source_id, uint8_t if_num, const char *descr) { /* Source XXX,*/ char sourceid_buf[16]; @@ -2187,16 +2187,16 @@ static void erf_set_interface_descr(wtap_block_t block, guint option_id, guint64 } } -static int erf_update_anchors_from_header(erf_t *erf_priv, wtap_rec *rec, union wtap_pseudo_header *pseudo_header, guint64 host_id, GPtrArray *anchor_mappings_to_update) +static int erf_update_anchors_from_header(erf_t *erf_priv, wtap_rec *rec, union wtap_pseudo_header *pseudo_header, uint64_t host_id, GPtrArray *anchor_mappings_to_update) { - guint8 type; - guint8 has_more; - guint64 hdr; - guint64 comment_gen_time = 0; - guint64 host_id_current; - guint64 anchor_id_current = 0; + uint8_t type; + uint8_t has_more; + uint64_t hdr; + uint64_t comment_gen_time = 0; + uint64_t host_id_current; + uint64_t anchor_id_current = 0; int i = 0; - gchar *comment = NULL; + char *comment = NULL; if (!rec || !pseudo_header) return -1; @@ -2209,7 +2209,7 @@ static int erf_update_anchors_from_header(erf_t *erf_priv, wtap_rec *rec, union while (has_more && (i < MAX_ERF_EHDR)) { hdr = pseudo_header->erf.ehdr_list[i].ehdr; - type = (guint8) (hdr >> 56); + type = (uint8_t) (hdr >> 56); switch (type & 0x7f) { case ERF_EXT_HDR_TYPE_HOST_ID: @@ -2272,10 +2272,10 @@ static int erf_update_anchors_from_header(erf_t *erf_priv, wtap_rec *rec, union /** * @brief Update the implicit Host ID and Anchor Mapping information */ -static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 implicit_host_id) +static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, uint64_t implicit_host_id) { GHashTableIter iter; - gpointer iter_value; + void *iter_value; GList* implicit_list = NULL; GList* item = NULL; wtap_block_t int_data; @@ -2284,7 +2284,7 @@ static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 impli struct erf_if_info* if_info = NULL; struct erf_anchor_mapping* anchor_mapping = NULL; struct erf_anchor_mapping* anchor_mapping_other = NULL; - gchar *oldstr = NULL; + char *oldstr = NULL; char portstr_buf[16]; int i; @@ -2333,7 +2333,7 @@ static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 impli * Needs a wtap_block_copy() that supports overwriting and/or expose * custom option copy and do with wtap_block_foreach_option(). */ - for (i = 0; i < 4; i++) { + for (i = 0; i < ERF_MAX_INTERFACES; i++) { if_info = &if_map->interfaces[i]; if (if_info->if_index >= 0) { @@ -2350,8 +2350,8 @@ static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 impli if_info->descr = g_strconcat(oldstr ? oldstr : portstr_buf, " [unmatched implicit]", NULL); g_free(oldstr); - erf_set_interface_descr(int_data, OPT_IDB_NAME, implicit_host_id, if_map->source_id, (guint8) i, if_info->name); - erf_set_interface_descr(int_data, OPT_IDB_DESCRIPTION, implicit_host_id, if_map->source_id, (guint8) i, if_info->descr); + erf_set_interface_descr(int_data, OPT_IDB_NAME, implicit_host_id, if_map->source_id, (uint8_t) i, if_info->name); + erf_set_interface_descr(int_data, OPT_IDB_DESCRIPTION, implicit_host_id, if_map->source_id, (uint8_t) i, if_info->descr); } } } @@ -2364,14 +2364,14 @@ static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 impli do { if_map = (struct erf_if_mapping*) item->data; - for (i = 0; i < 4; i++) { + for (i = 0; i < ERF_MAX_INTERFACES; i++) { if_info = &if_map->interfaces[i]; if (if_info->if_index >= 0) { /* XXX: this is a pointer! */ int_data = g_array_index(wth->interface_data, wtap_block_t, if_info->if_index); - erf_set_interface_descr(int_data, OPT_IDB_NAME, implicit_host_id, if_map->source_id, (guint8) i, if_info->name); - erf_set_interface_descr(int_data, OPT_IDB_DESCRIPTION, implicit_host_id, if_map->source_id, (guint8) i, if_info->descr); + erf_set_interface_descr(int_data, OPT_IDB_NAME, implicit_host_id, if_map->source_id, (uint8_t) i, if_info->name); + erf_set_interface_descr(int_data, OPT_IDB_DESCRIPTION, implicit_host_id, if_map->source_id, (uint8_t) i, if_info->descr); } } @@ -2431,7 +2431,7 @@ static int erf_update_implicit_host_id(erf_t *erf_priv, wtap *wth, guint64 impli return 0; } -static int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, guint64 host_id, guint8 source_id, guint8 if_num, int *err, gchar **err_info) +static int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, uint64_t host_id, uint8_t source_id, uint8_t if_num, int *err, char **err_info) { wtap_block_t int_data; wtapng_if_descr_mandatory_t* int_data_mand; @@ -2452,10 +2452,10 @@ static int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_ *err_info = ws_strdup_printf("erf: erf_populate_interface called with erf_priv NULL"); return -1; } - if (if_num > 3) { + if (if_num > ERF_MAX_INTERFACES-1) { *err = WTAP_ERR_INTERNAL; - *err_info = ws_strdup_printf("erf: erf_populate_interface called with if_num %u > 3", - if_num); + *err_info = ws_strdup_printf("erf: erf_populate_interface called with if_num %u > %u", + if_num, ERF_MAX_INTERFACES-1); return -1; } @@ -2519,11 +2519,11 @@ static int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_ return if_map->interfaces[if_num].if_index; } -static guint32 erf_meta_read_tag(struct erf_meta_tag* tag, guint8 *tag_ptr, guint32 remaining_len) +static uint32_t erf_meta_read_tag(struct erf_meta_tag* tag, uint8_t *tag_ptr, uint32_t remaining_len) { - guint16 tagtype; - guint16 taglength; - guint32 tagtotallength; + uint16_t tagtype; + uint16_t taglength; + uint32_t tagtotallength; if (!tag_ptr || !tag || remaining_len < ERF_META_TAG_HEADERLEN) return 0; @@ -2547,19 +2547,19 @@ static guint32 erf_meta_read_tag(struct erf_meta_tag* tag, guint8 *tag_ptr, guin return tagtotallength; } -static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header _U_, struct erf_meta_read_state *state, int *err, gchar **err_info) +static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header _U_, struct erf_meta_read_state *state, int *err, char **err_info) { struct erf_meta_tag tag = {0, 0, NULL}; wtap_block_t shb_hdr; char* tmp; - gchar* app_name = NULL; - gchar* app_version = NULL; - gchar* model = NULL; - gchar* descr = NULL; - gchar* cpu = NULL; - gchar* modelcpu = NULL; - guint32 tagtotallength; + char* app_name = NULL; + char* app_version = NULL; + char* model = NULL; + char* descr = NULL; + char* cpu = NULL; + char* modelcpu = NULL; + uint32_t tagtotallength; if (!wth) { *err = WTAP_ERR_INTERNAL; @@ -2597,7 +2597,7 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse switch (tag.type) { case ERF_META_TAG_comment: { - gchar *existing_comment = NULL; + char *existing_comment = NULL; /*XXX: hack to make changing capture comment work since Wireshark only * displays one. For now just overwrite the comment as we won't * pick up all of them yet due to the gen_time check above */ @@ -2620,32 +2620,32 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse switch (tag.type) { case ERF_META_TAG_model: g_free(model); - model = g_strndup((gchar*) tag.value, tag.length); + model = g_strndup((char*) tag.value, tag.length); break; case ERF_META_TAG_cpu: g_free(cpu); - cpu = g_strndup((gchar*) tag.value, tag.length); + cpu = g_strndup((char*) tag.value, tag.length); break; case ERF_META_TAG_descr: g_free(descr); - descr = g_strndup((gchar*) tag.value, tag.length); + descr = g_strndup((char*) tag.value, tag.length); break; case ERF_META_TAG_os: wtap_block_set_string_option_value(shb_hdr, OPT_SHB_OS, tag.value, tag.length); break; case ERF_META_TAG_app_name: g_free(app_name); - app_name = g_strndup((gchar*) tag.value, tag.length); + app_name = g_strndup((char*) tag.value, tag.length); break; case ERF_META_TAG_app_version: g_free(app_version); - app_version = g_strndup((gchar*) tag.value, tag.length); + app_version = g_strndup((char*) tag.value, tag.length); break; /* TODO: dag_version? */ /* TODO: could concatenate comment(s)? */ case ERF_META_TAG_filter: g_free(state->if_map->capture_filter_str); - state->if_map->capture_filter_str = g_strndup((gchar*) tag.value, tag.length); + state->if_map->capture_filter_str = g_strndup((char*) tag.value, tag.length); break; default: break; @@ -2721,11 +2721,11 @@ static int populate_capture_host_info(erf_t *erf_priv, wtap *wth, union wtap_pse return 1; } -static int populate_module_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseudo_header *pseudo_header _U_, struct erf_meta_read_state *state, int *err, gchar **err_info) +static int populate_module_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseudo_header *pseudo_header _U_, struct erf_meta_read_state *state, int *err, char **err_info) { struct erf_meta_tag tag = {0, 0, NULL}; - guint32 tagtotallength; + uint32_t tagtotallength; if (!wth) { *err = WTAP_ERR_INTERNAL; @@ -2746,7 +2746,7 @@ static int populate_module_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud switch (tag.type) { case ERF_META_TAG_fcs_len: if (tag.length >= 4) { - state->if_map->module_fcs_len = (gint8) pntoh32(tag.value); + state->if_map->module_fcs_len = (int8_t) pntoh32(tag.value); } break; case ERF_META_TAG_snaplen: @@ -2757,7 +2757,7 @@ static int populate_module_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud break; case ERF_META_TAG_filter: g_free(state->if_map->module_filter_str); - state->if_map->module_filter_str = g_strndup((gchar*) tag.value, tag.length); + state->if_map->module_filter_str = g_strndup((char*) tag.value, tag.length); break; } @@ -2770,15 +2770,15 @@ static int populate_module_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud return 1; } -static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, struct erf_meta_read_state *state, int *err, gchar **err_info) +static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, struct erf_meta_read_state *state, int *err, char **err_info) { struct erf_meta_tag tag = {0, 0, NULL}; - guint32 tagtotallength; + uint32_t tagtotallength; int interface_index = -1; wtap_block_t int_data = NULL; wtapng_if_descr_mandatory_t* int_data_mand = NULL; if_filter_opt_t if_filter; - guint32 if_num = 0; + uint32_t if_num = 0; struct erf_if_info* if_info = NULL; if (!wth) { @@ -2808,14 +2808,14 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo * Get or create the interface (there can be multiple interfaces in * a Provenance record). */ - if (if_num < 4) { /* Note: -1u > 4*/ + if (if_num < ERF_MAX_INTERFACES) { /* Note: -1u > ERF_MAX_INTERFACES */ if_info = &state->if_map->interfaces[if_num]; interface_index = if_info->if_index; /* Check if the interface information is still uninitialized */ if (interface_index == -1) { - guint8 *tag_ptr_tmp = state->tag_ptr; - guint32 remaining_len_tmp = state->remaining_len; + uint8_t *tag_ptr_tmp = state->tag_ptr; + uint32_t remaining_len_tmp = state->remaining_len; /* First iterate tags, checking we aren't looking at a timing port */ /* @@ -2834,7 +2834,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo } } else if (tag.type == ERF_META_TAG_stream_num) { if (tag.length >= 4) { - if_info->stream_num = (gint32) pntoh32(tag.value); + if_info->stream_num = (int32_t) pntoh32(tag.value); } } @@ -2844,7 +2844,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo /* If the interface is valid but uninitialized, create it */ if (interface_index == -1) { - interface_index = erf_populate_interface(erf_priv, wth, pseudo_header, state->if_map->host_id, state->if_map->source_id, (guint8) if_num, err, err_info); + interface_index = erf_populate_interface(erf_priv, wth, pseudo_header, state->if_map->host_id, state->if_map->source_id, (uint8_t) if_num, err, err_info); if (interface_index == -1) { return -1; } @@ -2867,7 +2867,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo /* * Bail if already have interface metadata or no interface to associate with. - * We also don't support metadata for >4 interfaces per Host + Source + * We also don't support metadata for >ERF_MAX_INTERFACES interfaces per Host + Source * as we only use interface ID. */ if (!int_data) @@ -2881,23 +2881,23 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo case ERF_META_TAG_name: /* TODO: fall back to module "dev_name Port N"? */ if (!if_info->name) { - if_info->name = g_strndup((gchar*) tag.value, tag.length); - erf_set_interface_descr(int_data, OPT_IDB_NAME, state->if_map->host_id, state->if_map->source_id, (guint8) if_num, if_info->name); + if_info->name = g_strndup((char*) tag.value, tag.length); + erf_set_interface_descr(int_data, OPT_IDB_NAME, state->if_map->host_id, state->if_map->source_id, (uint8_t) if_num, if_info->name); /* If we have no description, also copy to wtap if_description */ if (!if_info->descr) { - erf_set_interface_descr(int_data, OPT_IDB_DESCRIPTION, state->if_map->host_id, state->if_map->source_id, (guint8) if_num, if_info->name); + erf_set_interface_descr(int_data, OPT_IDB_DESCRIPTION, state->if_map->host_id, state->if_map->source_id, (uint8_t) if_num, if_info->name); } } break; case ERF_META_TAG_descr: if (!if_info->descr) { - if_info->descr = g_strndup((gchar*) tag.value, tag.length); - erf_set_interface_descr(int_data, OPT_IDB_DESCRIPTION, state->if_map->host_id, state->if_map->source_id, (guint8) if_num, if_info->descr); + if_info->descr = g_strndup((char*) tag.value, tag.length); + erf_set_interface_descr(int_data, OPT_IDB_DESCRIPTION, state->if_map->host_id, state->if_map->source_id, (uint8_t) if_num, if_info->descr); /* If we have no name, also copy to wtap if_name */ if (!if_info->name) { - erf_set_interface_descr(int_data, OPT_IDB_NAME, state->if_map->host_id, state->if_map->source_id, (guint8) if_num, if_info->descr); + erf_set_interface_descr(int_data, OPT_IDB_NAME, state->if_map->host_id, state->if_map->source_id, (uint8_t) if_num, if_info->descr); } } break; @@ -2909,13 +2909,13 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo /* * XXX: We ignore this as Section ID must match the ERF ifid and * that is all we care about/have space for at the moment. if_num - * is only really useful with >4 interfaces. + * is only really useful with >ERF_MAX_INTERFACES interfaces. */ /* TODO: might want to put this number in description */ break; case ERF_META_TAG_fcs_len: if (tag.length >= 4) { - wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (guint8) pntoh32(tag.value)); + wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (uint8_t) pntoh32(tag.value)); if_info->set_flags.fcs_len = 1; } break; @@ -2931,7 +2931,7 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo break; case ERF_META_TAG_filter: if_filter.type = if_filter_pcap; - if_filter.data.filter_str = g_strndup((gchar*) tag.value, tag.length); + if_filter.data.filter_str = g_strndup((char*) tag.value, tag.length); wtap_block_add_if_filter_option(int_data, OPT_IDB_FILTER, &if_filter); g_free(if_filter.data.filter_str); if_info->set_flags.filter = 1; @@ -2973,11 +2973,11 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo } if (state->if_map->module_fcs_len != -1 && !if_info->set_flags.fcs_len) { - wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (guint8) state->if_map->module_fcs_len); + wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (uint8_t) state->if_map->module_fcs_len); if_info->set_flags.fcs_len = 1; } - if (state->if_map->module_snaplen != (guint32) -1 && !if_info->set_flags.snaplen) { + if (state->if_map->module_snaplen != (uint32_t) -1 && !if_info->set_flags.snaplen) { int_data_mand->snap_len = pntoh32(tag.value); if_info->set_flags.snaplen = 1; } @@ -2987,18 +2987,18 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo return 1; } -static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseudo_header *pseudo_header, struct erf_meta_read_state *state, int *err, gchar **err_info) +static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseudo_header *pseudo_header, struct erf_meta_read_state *state, int *err, char **err_info) { struct erf_meta_tag tag = {0, 0, NULL}; - guint32 tagtotallength; + uint32_t tagtotallength; int interface_index = -1; wtap_block_t int_data = NULL; wtapng_if_descr_mandatory_t* int_data_mand = NULL; if_filter_opt_t if_filter; - guint32 if_num = 0; - gint32 stream_num = -1; - guint8 *tag_ptr_tmp; - guint32 remaining_len_tmp; + uint32_t if_num = 0; + int32_t stream_num = -1; + uint8_t *tag_ptr_tmp; + uint32_t remaining_len_tmp; struct erf_if_info* if_info = NULL; if (!wth) { @@ -3040,7 +3040,7 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud while ((tagtotallength = erf_meta_read_tag(&tag, tag_ptr_tmp, remaining_len_tmp)) && !ERF_META_IS_SECTION(tag.type)) { if (tag.type == ERF_META_TAG_stream_num) { if (tag.length >= 4) { - stream_num = (gint32) pntoh32(tag.value); + stream_num = (int32_t) pntoh32(tag.value); } } @@ -3050,7 +3050,7 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud } /* Otherwise assume the stream applies to all interfaces in the record */ - for (if_num = 0; if_num < 4; if_num++) { + for (if_num = 0; if_num < ERF_MAX_INTERFACES; if_num++) { tag_ptr_tmp = state->tag_ptr; remaining_len_tmp = state->remaining_len; if_info = &state->if_map->interfaces[if_num]; @@ -3083,22 +3083,22 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud case ERF_META_TAG_fcs_len: if (tag.length >= 4) { /* Use the largest fcslen of matching streams */ - gint8 fcs_len = (gint8) pntoh32(tag.value); - guint8 old_fcs_len = 0; + int8_t fcs_len = (int8_t) pntoh32(tag.value); + uint8_t old_fcs_len = 0; switch (wtap_block_get_uint8_option_value(int_data, OPT_IDB_FCSLEN, &old_fcs_len)) { case WTAP_OPTTYPE_SUCCESS: /* We already have an FCS length option; update it. */ if (fcs_len > old_fcs_len || !if_info->set_flags.fcs_len) { - wtap_block_set_uint8_option_value(int_data, OPT_IDB_FCSLEN, (guint8) pntoh32(tag.value)); + wtap_block_set_uint8_option_value(int_data, OPT_IDB_FCSLEN, (uint8_t) pntoh32(tag.value)); if_info->set_flags.fcs_len = 1; } break; case WTAP_OPTTYPE_NOT_FOUND: /* We don't have an FCS length option; add it. */ - wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (guint8) pntoh32(tag.value)); + wtap_block_add_uint8_option(int_data, OPT_IDB_FCSLEN, (uint8_t) pntoh32(tag.value)); if_info->set_flags.fcs_len = 1; break; @@ -3111,7 +3111,7 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud case ERF_META_TAG_snaplen: if (tag.length >= 4) { /* Use the largest snaplen of matching streams */ - guint32 snaplen = pntoh32(tag.value); + uint32_t snaplen = pntoh32(tag.value); if (snaplen > int_data_mand->snap_len || !if_info->set_flags.snaplen) { int_data_mand->snap_len = pntoh32(tag.value); @@ -3123,7 +3123,7 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud /* Override only if not set */ if (!if_info->set_flags.filter) { if_filter.type = if_filter_pcap; - if_filter.data.filter_str = g_strndup((gchar*) tag.value, tag.length); + if_filter.data.filter_str = g_strndup((char*) tag.value, tag.length); wtap_block_add_if_filter_option(int_data, OPT_IDB_FILTER, &if_filter); g_free(if_filter.data.filter_str); if_info->set_flags.filter = 1; @@ -3143,11 +3143,11 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud return 1; } -static int populate_anchor_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, struct erf_meta_read_state *state, GPtrArray *anchor_mappings_to_update, int *err, gchar **err_info) { +static int populate_anchor_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, struct erf_meta_read_state *state, GPtrArray *anchor_mappings_to_update, int *err, char **err_info) { struct erf_meta_tag tag = {0, 0, NULL}; - guint32 tagtotallength; - gchar *comment_ptr = NULL; - guint i = 0; + uint32_t tagtotallength; + char *comment_ptr = NULL; + unsigned i = 0; if (!wth) { *err = WTAP_ERR_INTERNAL; @@ -3173,7 +3173,7 @@ static int populate_anchor_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_he switch(tag.type) { case ERF_META_TAG_comment: if(!comment_ptr) { - comment_ptr = g_strndup((gchar*)tag.value, tag.length); + comment_ptr = g_strndup((char*)tag.value, tag.length); } break; default: @@ -3220,17 +3220,17 @@ static int populate_anchor_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_he } /* Populates the capture and interface information for display on the Capture File Properties */ -static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, Buffer *buf, guint32 packet_size, GPtrArray *anchor_mappings_to_update, int *err, gchar **err_info) +static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, Buffer *buf, uint32_t packet_size, GPtrArray *anchor_mappings_to_update, int *err, char **err_info) { struct erf_meta_read_state state = {0}; struct erf_meta_read_state *state_post = NULL; - guint64 host_id; - guint8 source_id; + uint64_t host_id; + uint8_t source_id; GList *post_list = NULL; GList *item = NULL; struct erf_meta_tag tag = {0, 0, NULL}; - guint32 tagtotallength; + uint32_t tagtotallength; if (!wth) { *err = WTAP_ERR_INTERNAL; @@ -3310,7 +3310,7 @@ static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_h * Currently we only particularly care about updating the capture comment * and a few counters anyway. */ - if ((state.if_map->interface_metadata & 0x03) + if ((state.if_map->interface_metadata & 0xff) && state.gen_time < erf_priv->host_gentime && state.gen_time < erf_priv->capture_gentime && (!anchor_mappings_to_update || !anchor_mappings_to_update->len)) { return 0; @@ -3459,7 +3459,7 @@ static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_h return 0; } -static gboolean get_user_comment_string(wtap_dumper *wdh, gchar** user_comment_ptr) { +static bool get_user_comment_string(wtap_dumper *wdh, char** user_comment_ptr) { wtap_block_t wtap_block; wtap_opttype_return_val ret; @@ -3472,20 +3472,20 @@ static gboolean get_user_comment_string(wtap_dumper *wdh, gchar** user_comment_p if(wtap_block != NULL) { ret = wtap_block_get_nth_string_option_value(wtap_block, OPT_COMMENT, 0, user_comment_ptr); if(ret != WTAP_OPTTYPE_SUCCESS) { - return FALSE; + return false; } } - return TRUE; + return true; } -static gboolean erf_dump_priv_compare_capture_comment(wtap_dumper *wdh _U_, erf_dump_t *dump_priv, const union wtap_pseudo_header *pseudo_header, const guint8 *pd){ +static bool erf_dump_priv_compare_capture_comment(wtap_dumper *wdh _U_, erf_dump_t *dump_priv, const union wtap_pseudo_header *pseudo_header, const uint8_t *pd){ struct erf_meta_read_state state = {0}; struct erf_meta_tag tag = {0, 0, NULL}; - guint32 tagtotallength; - gboolean found_capture_section = FALSE; - gboolean found_normal_section = FALSE; - gchar* comment_ptr = NULL; + uint32_t tagtotallength; + bool found_capture_section = false; + bool found_normal_section = false; + char* comment_ptr = NULL; state.remaining_len = pseudo_header->erf.phdr.wlen; memcpy(&(state.tag_ptr), &pd, sizeof(pd)); @@ -3501,11 +3501,11 @@ static gboolean erf_dump_priv_compare_capture_comment(wtap_dumper *wdh _U_, erf_ /* Skip sections that don't apply to the general set of records */ if (!(state.sectionid & 0x8000)) { - found_normal_section = TRUE; + found_normal_section = true; if(tag.type == ERF_META_SECTION_CAPTURE) { /* Found the Capture Section */ - found_capture_section = TRUE; + found_capture_section = true; } } } else { @@ -3531,15 +3531,15 @@ static gboolean erf_dump_priv_compare_capture_comment(wtap_dumper *wdh _U_, erf_ /* Also treat "" in ERF as equivalent to NULL as that is how we clear the comment on write. */ /* Comments are different, we should write extra metadata record at the end of the list */ - dump_priv->write_next_extra_meta = TRUE; + dump_priv->write_next_extra_meta = true; g_free(comment_ptr); - return TRUE; + return true; } else { /* We have a capture comment but there is no change, we don't * need to insert the 'changed' comment. This most likely happened * because we were looking at list of periodic records and got up to the * one where the comment was last set. */ - dump_priv->write_next_extra_meta = FALSE; + dump_priv->write_next_extra_meta = false; } /* Otherwise no effect on whether we need to write extra metadata record */ } @@ -3611,7 +3611,7 @@ static const struct supported_block_type erf_blocks_supported[] = { static const struct file_type_subtype_info erf_info = { "Endace ERF capture", "erf", "erf", NULL, - FALSE, BLOCKS_SUPPORTED(erf_blocks_supported), + false, BLOCKS_SUPPORTED(erf_blocks_supported), erf_dump_can_write_encap, erf_dump_open, NULL }; diff --git a/wiretap/erf.h b/wiretap/erf.h index 62e2144d..c2d14373 100644 --- a/wiretap/erf.h +++ b/wiretap/erf.h @@ -21,7 +21,7 @@ #define ERF_POPULATE_ALREADY_POPULATED 0 #define ERF_POPULATE_FAILED -1 -#define ERF_MAX_INTERFACES 4 +#define ERF_MAX_INTERFACES 8 /* * Private data for ERF files and LINKTYPE_ERF packets in pcap and pcapng. @@ -29,9 +29,9 @@ struct erf_private { GHashTable* if_map; GHashTable* anchor_map; - guint64 implicit_host_id; - guint64 capture_gentime; - guint64 host_gentime; + uint64_t implicit_host_id; + uint64_t capture_gentime; + uint64_t host_gentime; }; #define MIN_RECORDS_FOR_ERF_CHECK 3 @@ -40,7 +40,7 @@ struct erf_private { /*Configurable through ERF_HOST_ID environment variable */ #define ERF_WS_DEFAULT_HOST_ID 0 -wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val erf_open(wtap *wth, int *err, char **err_info); #endif /* __W_ERF_H__ */ diff --git a/wiretap/erf_record.h b/wiretap/erf_record.h index 81e35a0f..238efe80 100644 --- a/wiretap/erf_record.h +++ b/wiretap/erf_record.h @@ -87,21 +87,39 @@ #define ERF_EXT_HDR_TYPE_ANCHOR_ID 18 #define ERF_EXT_HDR_TYPE_ENTROPY 19 +/* ERF Header */ +#define ERF_HDR_TYPE_MASK 0x7f +#define ERF_HDR_EHDR_MASK 0x80 +#define ERF_HDR_FLAGS_MASK 0xff +#define ERF_HDR_CAP_MASK 0x43 +#define ERF_HDR_CAP_LO_MASK 0x03 +#define ERF_HDR_CAP_HI_MASK 0x40 +#define ERF_HDR_VLEN_MASK 0x04 +#define ERF_HDR_TRUNC_MASK 0x08 +#define ERF_HDR_RXE_MASK 0x10 +#define ERF_HDR_DSE_MASK 0x20 +#define ERF_HDR_RES_MASK 0x80 + +/* + * Calculate 3-bit ERF InterfaceID value from ERF Header flags byte + */ +#define erf_interface_id_from_flags(flags) ((((uint8_t)flags) & ERF_HDR_CAP_HI_MASK >> 4 ) | (((uint8_t)flags) & ERF_HDR_CAP_LO_MASK)) + /* Host ID and Anchor ID*/ -#define ERF_EHDR_HOST_ID_MASK G_GUINT64_CONSTANT(0xffffffffffff) -#define ERF_EHDR_ANCHOR_ID_MASK G_GUINT64_CONSTANT(0xffffffffffff) -#define ERF_EHDR_MORE_EXTHDR_MASK G_GUINT64_CONSTANT(0x8000000000000000) -#define ERF_EHDR_ANCHOR_ID_DEFINITION_MASK G_GUINT64_CONSTANT(0x80000000000000) +#define ERF_EHDR_HOST_ID_MASK UINT64_C(0xffffffffffff) +#define ERF_EHDR_ANCHOR_ID_MASK UINT64_C(0xffffffffffff) +#define ERF_EHDR_MORE_EXTHDR_MASK UINT64_C(0x8000000000000000) +#define ERF_EHDR_ANCHOR_ID_DEFINITION_MASK UINT64_C(0x80000000000000) -#define ERF_EHDR_FLOW_ID_STACK_TYPE_MASK G_GUINT64_CONSTANT(0xff00000000) -#define ERF_EHDR_FLOW_ID_SOURCE_ID_MASK G_GUINT64_CONSTANT(0xff000000000000) +#define ERF_EHDR_FLOW_ID_STACK_TYPE_MASK UINT64_C(0xff00000000) +#define ERF_EHDR_FLOW_ID_SOURCE_ID_MASK UINT64_C(0xff000000000000) /* ERF Provenance metadata */ #define ERF_META_SECTION_MASK 0xFF00 #define ERF_META_IS_SECTION(type) (type > 0 && (type & ERF_META_SECTION_MASK) == ERF_META_SECTION_MASK) -#define ERF_META_HOST_ID_IMPLICIT G_MAXUINT64 -#define ERF_ANCHOR_ID_IS_DEFINITION(anchor_id) ((guint64)anchor_id & ERF_EHDR_ANCHOR_ID_DEFINITION_MASK) -#define ERF_EHDR_SET_MORE_EXTHDR(ext_hdr) ((guint64)ext_hdr | ERF_EHDR_MORE_EXTHDR_MASK) +#define ERF_META_HOST_ID_IMPLICIT UINT64_MAX +#define ERF_ANCHOR_ID_IS_DEFINITION(anchor_id) ((uint64_t)anchor_id & ERF_EHDR_ANCHOR_ID_DEFINITION_MASK) +#define ERF_EHDR_SET_MORE_EXTHDR(ext_hdr) ((uint64_t)ext_hdr | ERF_EHDR_MORE_EXTHDR_MASK) #define ERF_META_SECTION_CAPTURE 0xFF00 #define ERF_META_SECTION_HOST 0xFF01 @@ -383,28 +401,28 @@ * The timestamp is 64bit unsigned fixed point little-endian value with * 32 bits for second and 32 bits for fraction. */ -typedef guint64 erf_timestamp_t; +typedef uint64_t erf_timestamp_t; typedef struct erf_record { erf_timestamp_t ts; - guint8 type; - guint8 flags; - guint16 rlen; - guint16 lctr; - guint16 wlen; + uint8_t type; + uint8_t flags; + uint16_t rlen; + uint16_t lctr; + uint16_t wlen; } erf_header_t; typedef struct erf_mc_hdr { - guint32 mc; + uint32_t mc; } erf_mc_header_t; typedef struct erf_aal2_hdr { - guint32 aal2; + uint32_t aal2; } erf_aal2_header_t; typedef struct erf_eth_hdr { - guint8 offset; - guint8 pad; + uint8_t offset; + uint8_t pad; } erf_eth_header_t; union erf_subhdr { diff --git a/wiretap/eri_enb_log.c b/wiretap/eri_enb_log.c index 20abcd7a..a4f02ce0 100644 --- a/wiretap/eri_enb_log.c +++ b/wiretap/eri_enb_log.c @@ -22,19 +22,19 @@ void register_eri_enb_log(void); #define MAX_LINE_LENGTH 131072 -static gboolean eri_enb_log_get_packet(FILE_T fh, wtap_rec* rec, - Buffer* buf, int* err _U_, gchar** err_info _U_) +static bool eri_enb_log_get_packet(FILE_T fh, wtap_rec* rec, + Buffer* buf, int* err _U_, char** err_info _U_) { static char line[MAX_LINE_LENGTH]; /* Read in a line */ - gint64 pos_before = file_tell(fh); + int64_t pos_before = file_tell(fh); while (file_gets(line, sizeof(line), fh) != NULL) { nstime_t packet_time; - gint length; + int length; /* Set length (avoiding strlen()) and offset.. */ - length = (gint)(file_tell(fh) - pos_before); + length = (int)(file_tell(fh) - pos_before); /* ...but don't want to include newline in line length */ if (length > 0 && line[length - 1] == '\n') { @@ -68,15 +68,15 @@ static gboolean eri_enb_log_get_packet(FILE_T fh, wtap_rec* rec, ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); memcpy(ws_buffer_start_ptr(buf), line, rec->rec_header.packet_header.caplen); - return TRUE; + return true; } - return FALSE; + return false; } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean eri_enb_log_read(wtap* wth, wtap_rec* rec, Buffer* buf, - int* err, gchar** err_info, gint64* data_offset) +static bool eri_enb_log_read(wtap* wth, wtap_rec* rec, Buffer* buf, + int* err, char** err_info, int64_t* data_offset) { *data_offset = file_tell(wth->fh); @@ -84,19 +84,19 @@ static gboolean eri_enb_log_read(wtap* wth, wtap_rec* rec, Buffer* buf, } /* Used to read packets in random-access fashion */ -static gboolean eri_enb_log_seek_read(wtap* wth, gint64 seek_off, - wtap_rec* rec, Buffer* buf, int* err, gchar** err_info) +static bool eri_enb_log_seek_read(wtap* wth, int64_t seek_off, + wtap_rec* rec, Buffer* buf, int* err, char** err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return FALSE; + return false; } return eri_enb_log_get_packet(wth->random_fh, rec, buf, err, err_info); } wtap_open_return_val -eri_enb_log_open(wtap *wth, int *err, gchar **err_info) +eri_enb_log_open(wtap *wth, int *err, char **err_info) { char line1[64]; @@ -138,7 +138,7 @@ static const struct supported_block_type eri_enb_log_blocks_supported[] = { static const struct file_type_subtype_info eri_enb_log_info = { "Ericsson eNode-B raw log", "eri_enb_log", "eri_enb_log", NULL, - FALSE, BLOCKS_SUPPORTED(eri_enb_log_blocks_supported), + false, BLOCKS_SUPPORTED(eri_enb_log_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/eri_enb_log.h b/wiretap/eri_enb_log.h index 53c0ef36..0213210e 100644 --- a/wiretap/eri_enb_log.h +++ b/wiretap/eri_enb_log.h @@ -11,6 +11,6 @@ #include "wtap.h" -wtap_open_return_val eri_enb_log_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val eri_enb_log_open(wtap *wth, int *err, char **err_info); #endif /* __W_ERI_ENB_LOG_H__*/ diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c index 4d22d6b7..7c832806 100644 --- a/wiretap/eyesdn.c +++ b/wiretap/eyesdn.c @@ -7,8 +7,8 @@ */ #include "config.h" -#include "wtap-int.h" #include "eyesdn.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <stdlib.h> @@ -42,7 +42,7 @@ void register_eyesdn(void); */ -static gboolean esc_read(FILE_T fh, guint8 *buf, int len, int *err, gchar **err_info) +static bool esc_read(FILE_T fh, uint8_t *buf, int len, int *err, char **err_info) { int i; int value; @@ -54,13 +54,13 @@ static gboolean esc_read(FILE_T fh, guint8 *buf, int len, int *err, gchar **err_ *err=file_error(fh, err_info); if(*err==0) *err=WTAP_ERR_SHORT_READ; - return FALSE; + return false; } if(value==0xff) { /* error !!, read into next frame */ *err=WTAP_ERR_BAD_FILE; *err_info=g_strdup("eyesdn: No flag character seen in frame"); - return FALSE; + return false; } if(value==0xfe) { /* we need to escape */ @@ -70,14 +70,14 @@ static gboolean esc_read(FILE_T fh, guint8 *buf, int len, int *err, gchar **err_ *err=file_error(fh, err_info); if(*err==0) *err=WTAP_ERR_SHORT_READ; - return FALSE; + return false; } value+=2; } buf[i]=value; } - return TRUE; + return true; } /* Magic text to check for eyesdn-ness of file */ @@ -88,20 +88,20 @@ static const unsigned char eyesdn_hdr_magic[] = /* Size of a record header */ #define EYESDN_HDR_LENGTH 12 -static gboolean eyesdn_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static int read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer* buf, - int *err, gchar **err_info); +static bool eyesdn_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool eyesdn_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer* buf, + int *err, char **err_info); /* 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 eyesdn_seek_next_packet(wtap *wth, int *err, gchar **err_info) +static int64_t eyesdn_seek_next_packet(wtap *wth, int *err, char **err_info) { int byte; - gint64 cur_off; + int64_t cur_off; while ((byte = file_getc(wth->fh)) != EOF) { if (byte == 0xff) { @@ -119,7 +119,7 @@ static gint64 eyesdn_seek_next_packet(wtap *wth, int *err, gchar **err_info) return -1; } -wtap_open_return_val eyesdn_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val eyesdn_open(wtap *wth, int *err, char **err_info) { char magic[EYESDN_HDR_MAGIC_SIZE]; @@ -143,15 +143,15 @@ wtap_open_return_val eyesdn_open(wtap *wth, int *err, gchar **err_info) } /* Find the next record and parse it; called from wtap_read(). */ -static gboolean eyesdn_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool eyesdn_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 record */ offset = eyesdn_seek_next_packet(wth, err, err_info); if (offset < 1) - return FALSE; + return false; *data_offset = offset; /* Parse the record */ @@ -159,35 +159,35 @@ static gboolean eyesdn_read(wtap *wth, wtap_rec *rec, Buffer *buf, } /* Used to read packets in random-access fashion */ -static gboolean -eyesdn_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +eyesdn_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return read_eyesdn_rec(wth->random_fh, rec, buf, err, err_info); } /* Parses a record. */ -static gboolean +static bool read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info) + char **err_info) { union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; - guint8 hdr[EYESDN_HDR_LENGTH]; + uint8_t hdr[EYESDN_HDR_LENGTH]; time_t secs; int usecs; - guint pkt_len; - guint8 channel, direction; - guint8 *pd; + unsigned pkt_len; + uint8_t channel, direction; + uint8_t *pd; /* Our file pointer should be at the summary information header * for a packet. Read in that header and extract the useful * information. */ if (!esc_read(fh, hdr, EYESDN_HDR_LENGTH, err, err_info)) - return FALSE; + return false; /* extract information from header */ usecs = pntoh24(&hdr[0]); @@ -232,21 +232,21 @@ read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, case EYESDN_ENCAP_ATM: { /* ATM cells */ #define CELL_LEN 53 unsigned char cell[CELL_LEN]; - gint64 cur_off; + int64_t cur_off; if(pkt_len != CELL_LEN) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf( "eyesdn: ATM cell has a length != 53 (%u)", pkt_len); - return FALSE; + return false; } cur_off = file_tell(fh); if (!esc_read(fh, cell, CELL_LEN, err, err_info)) - return FALSE; + return false; if (file_seek(fh, cur_off, SEEK_SET, err) == -1) - return FALSE; + return false; rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; pseudo_header->atm.flags=ATM_RAW_CELL; pseudo_header->atm.aal=AAL_UNKNOWN; @@ -294,7 +294,7 @@ read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("eyesdn: File has %u-byte packet, bigger than maximum of %u", pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -310,17 +310,17 @@ read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, pd = ws_buffer_start_ptr(buf); if (!esc_read(fh, pd, pkt_len, err, err_info)) - return FALSE; - return TRUE; + return false; + return true; } -static gboolean -esc_write(wtap_dumper *wdh, const guint8 *buf, int len, int *err) +static bool +esc_write(wtap_dumper *wdh, const uint8_t *buf, int len, int *err) { int i; - guint8 byte; - static const guint8 esc = 0xfe; + uint8_t byte; + static const uint8_t esc = 0xfe; for(i=0; i<len; i++) { byte=buf[i]; @@ -329,28 +329,28 @@ esc_write(wtap_dumper *wdh, const guint8 *buf, int len, int *err) * Escape the frame delimiter and escape byte. */ if (!wtap_dump_file_write(wdh, &esc, sizeof esc, err)) - return FALSE; + return false; byte-=2; } if (!wtap_dump_file_write(wdh, &byte, sizeof byte, err)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean eyesdn_dump(wtap_dumper *wdh, +static bool eyesdn_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); + const uint8_t *pd, int *err, char **err_info); -static gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool eyesdn_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { wdh->subtype_write=eyesdn_dump; if (!wtap_dump_file_write(wdh, eyesdn_hdr_magic, EYESDN_HDR_MAGIC_SIZE, err)) - return FALSE; + return false; *err=0; - return TRUE; + return true; } static int eyesdn_dump_can_write_encap(int encap) @@ -372,14 +372,14 @@ static int eyesdn_dump_can_write_encap(int encap) } /* Write a record for a packet to a dump file. - * Returns TRUE on success, FALSE on failure. */ -static gboolean eyesdn_dump(wtap_dumper *wdh, + * Returns true on success, false on failure. */ +static bool eyesdn_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { - static const guint8 start_flag = 0xff; + static const uint8_t start_flag = 0xff; const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; - guint8 buf[EYESDN_HDR_LENGTH]; + uint8_t buf[EYESDN_HDR_LENGTH]; int usecs; time_t secs; int channel; @@ -390,7 +390,7 @@ static gboolean eyesdn_dump(wtap_dumper *wdh, /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* Don't write out anything bigger than we can read. @@ -398,7 +398,7 @@ static gboolean eyesdn_dump(wtap_dumper *wdh, * imposes a hard limit.) */ if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } usecs=rec->ts.nsecs/1000; @@ -450,29 +450,29 @@ static gboolean eyesdn_dump(wtap_dumper *wdh, default: *err=WTAP_ERR_UNWRITABLE_ENCAP; - return FALSE; + return false; } phton24(&buf[0], usecs); - buf[3] = (guint8)0; - buf[4] = (guint8)(0xff & (secs >> 24)); - buf[5] = (guint8)(0xff & (secs >> 16)); - buf[6] = (guint8)(0xff & (secs >> 8)); - buf[7] = (guint8)(0xff & (secs >> 0)); + buf[3] = (uint8_t)0; + buf[4] = (uint8_t)(0xff & (secs >> 24)); + buf[5] = (uint8_t)(0xff & (secs >> 16)); + buf[6] = (uint8_t)(0xff & (secs >> 8)); + buf[7] = (uint8_t)(0xff & (secs >> 0)); - buf[8] = (guint8) channel; - buf[9] = (guint8) (origin?1:0) + (protocol << 1); + buf[8] = (uint8_t) channel; + buf[9] = (uint8_t) (origin?1:0) + (protocol << 1); phtons(&buf[10], size); /* start flag */ if (!wtap_dump_file_write(wdh, &start_flag, sizeof start_flag, err)) - return FALSE; + return false; if (!esc_write(wdh, buf, 12, err)) - return FALSE; + return false; if (!esc_write(wdh, pd, size, err)) - return FALSE; - return TRUE; + return false; + return true; } static const struct supported_block_type eyesdn_blocks_supported[] = { @@ -484,7 +484,7 @@ static const struct supported_block_type eyesdn_blocks_supported[] = { static const struct file_type_subtype_info eyesdn_info = { "EyeSDN USB S0/E1 ISDN trace format", "eyesdn", "trc", NULL, - FALSE, BLOCKS_SUPPORTED(eyesdn_blocks_supported), + false, BLOCKS_SUPPORTED(eyesdn_blocks_supported), eyesdn_dump_can_write_encap, eyesdn_dump_open, NULL }; diff --git a/wiretap/eyesdn.h b/wiretap/eyesdn.h index 28dfec82..b92c2f57 100644 --- a/wiretap/eyesdn.h +++ b/wiretap/eyesdn.h @@ -14,7 +14,7 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val eyesdn_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val eyesdn_open(wtap *wth, int *err, char **err_info); enum EyeSDN_TYPES { EYESDN_ENCAP_ISDN=0, diff --git a/wiretap/file_access.c b/wiretap/file_access.c index ca4d2f69..c3fbc5a6 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -8,6 +8,7 @@ #include "config.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP +#include "wtap-int.h" #include <string.h> #include <stdlib.h> @@ -20,9 +21,7 @@ #include <wsutil/plugins.h> #endif #include <wsutil/ws_assert.h> -#include <wsutil/wslog.h> -#include "wtap-int.h" #include "wtap_modules.h" #include "file_wrappers.h" #include "required_file_handlers.h" @@ -89,18 +88,19 @@ #include "log3gpp.h" #include "candump.h" #include "busmaster.h" +#include "cllog.h" #include "blf.h" #include "eri_enb_log.h" #include "autosar_dlt.h" #include "rtpdump.h" - +#include "ems.h" /* * Add an extension, and all compressed versions thereof if requested, * to a GSList of extensions. */ static GSList * -add_extensions(GSList *extensions, const gchar *extension, +add_extensions(GSList *extensions, const char *extension, GSList *compression_type_extensions) { /* @@ -139,49 +139,50 @@ add_extensions(GSList *extensions, const gchar *extension, * must also be added open_info_base[] below. */ static const struct file_extension_info file_type_extensions_base[] = { - { "Wireshark/tcpdump/... - pcap", TRUE, "pcap;cap;dmp" }, - { "Wireshark/... - pcapng", TRUE, "pcapng;ntar;scap" }, - { "Network Monitor, Surveyor, NetScaler", TRUE, "cap" }, - { "Sun snoop", TRUE, "snoop" }, - { "InfoVista 5View capture", TRUE, "5vw" }, - { "Sniffer (DOS)", TRUE, "cap;enc;trc;fdc;syc" }, - { "Cinco NetXRay, Sniffer (Windows)", TRUE, "cap;caz" }, - { "Endace ERF capture", TRUE, "erf" }, - { "EyeSDN USB S0/E1 ISDN trace format", TRUE, "trc" }, - { "HP-UX nettl trace", TRUE, "trc0;trc1" }, - { "Viavi Observer", TRUE, "bfr" }, - { "Colasoft Capsa", TRUE, "cscpkt" }, - { "Novell LANalyzer", TRUE, "tr1" }, - { "Tektronix K12xx 32-bit .rf5 format", TRUE, "rf5" }, - { "Savvius *Peek", TRUE, "pkt;tpc;apc;wpz" }, - { "Catapult DCT2000 trace (.out format)", TRUE, "out" }, - { "Micropross mplog", TRUE, "mplog" }, - { "TamoSoft CommView NCF", TRUE, "ncf" }, - { "TamoSoft CommView NCFX", TRUE, "ncfx" }, - { "Symbian OS btsnoop", TRUE, "log" }, - { "XML files (including Gammu DCT3 traces)", TRUE, "xml" }, - { "macOS PacketLogger", TRUE, "pklg" }, - { "Daintree SNA", TRUE, "dcf" }, - { "IPFIX File Format", TRUE, "pfx;ipfix" }, - { "Aethra .aps file", TRUE, "aps" }, - { "MPEG2 transport stream", TRUE, "mp2t;ts;mpg" }, - { "Ixia IxVeriWave .vwr Raw 802.11 Capture", TRUE, "vwr" }, - { "CAM Inspector file", TRUE, "camins" }, - { "BLF file", TRUE, "blf" }, - { "AUTOSAR DLT file", TRUE, "dlt" }, - { "MPEG files", FALSE, "mpeg;mpg;mp3" }, - { "Transport-Neutral Encapsulation Format", FALSE, "tnef" }, - { "JPEG/JFIF files", FALSE, "jpg;jpeg;jfif" }, - { "JavaScript Object Notation file", FALSE, "json" }, - { "MP4 file", FALSE, "mp4" }, - { "RTPDump file", FALSE, "rtp;rtpdump" }, + { "Wireshark/tcpdump/... - pcap", true, "pcap;cap;dmp" }, + { "Wireshark/... - pcapng", true, "pcapng;scap;ntar" }, + { "Network Monitor, Surveyor, NetScaler", true, "cap" }, + { "Sun snoop", true, "snoop" }, + { "InfoVista 5View capture", true, "5vw" }, + { "Sniffer (DOS)", true, "cap;enc;trc;fdc;syc" }, + { "Cinco NetXRay, Sniffer (Windows)", true, "cap;caz" }, + { "Endace ERF capture", true, "erf" }, + { "EyeSDN USB S0/E1 ISDN trace format", true, "trc" }, + { "HP-UX nettl trace", true, "trc0;trc1" }, + { "Viavi Observer", true, "bfr" }, + { "Colasoft Capsa", true, "cscpkt" }, + { "Novell LANalyzer", true, "tr1" }, + { "Tektronix K12xx 32-bit .rf5 format", true, "rf5" }, + { "Savvius *Peek", true, "pkt;tpc;apc;wpz" }, + { "Catapult DCT2000 trace (.out format)", true, "out" }, + { "Micropross mplog", true, "mplog" }, + { "TamoSoft CommView NCF", true, "ncf" }, + { "TamoSoft CommView NCFX", true, "ncfx" }, + { "Symbian OS btsnoop", true, "log" }, + { "XML files (including Gammu DCT3 traces)", true, "xml" }, + { "macOS PacketLogger", true, "pklg" }, + { "Daintree SNA", true, "dcf" }, + { "IPFIX File Format", true, "pfx;ipfix" }, + { "Aethra .aps file", true, "aps" }, + { "MPEG2 transport stream", true, "mp2t;ts;m2ts;mpg" }, + { "Ixia IxVeriWave .vwr Raw 802.11 Capture", true, "vwr" }, + { "CAM Inspector file", true, "camins" }, + { "BLF file", true, "blf" }, + { "AUTOSAR DLT file", true, "dlt" }, + { "MPEG files", false, "mpeg;mpg;mp3" }, + { "Transport-Neutral Encapsulation Format", false, "tnef" }, + { "JPEG/JFIF files", false, "jpg;jpeg;jfif" }, + { "JavaScript Object Notation file", false, "json" }, + { "MP4 file", false, "mp4" }, + { "RTPDump file", false, "rtp;rtpdump" }, + { "EMS file", false, "ems" }, }; -#define N_FILE_TYPE_EXTENSIONS (sizeof file_type_extensions_base / sizeof file_type_extensions_base[0]) +#define N_FILE_TYPE_EXTENSIONS array_length(file_type_extensions_base) -static const struct file_extension_info* file_type_extensions = NULL; +static const struct file_extension_info* file_type_extensions; -static GArray* file_type_extensions_arr = NULL; +static GArray* file_type_extensions_arr; /* initialize the extensions array if it has not been initialized yet */ static void @@ -190,7 +191,7 @@ init_file_type_extensions(void) if (file_type_extensions_arr) return; - file_type_extensions_arr = g_array_new(FALSE,TRUE,sizeof(struct file_extension_info)); + file_type_extensions_arr = g_array_new(false,true,sizeof(struct file_extension_info)); g_array_append_vals(file_type_extensions_arr,file_type_extensions_base,N_FILE_TYPE_EXTENSIONS); @@ -223,7 +224,7 @@ static GSList * add_extensions_for_file_extensions_type(int extension_type, GSList *extensions, GSList *compression_type_extensions) { - gchar **extensions_set, **extensionp, *extension; + char **extensions_set, **extensionp, *extension; /* * Split the extension-list string into a set of extensions. @@ -256,7 +257,7 @@ add_extensions_for_file_extensions_type(int extension_type, GSList *extensions, * with g_free(). */ GSList * -wtap_get_file_extension_type_extensions(guint extension_type) +wtap_get_file_extension_type_extensions(unsigned extension_type) { GSList *extensions, *compression_type_extensions; @@ -406,12 +407,16 @@ static const struct open_info open_info_base[] = { { "Android Logcat Text formats", OPEN_INFO_HEURISTIC, logcat_text_open, "txt", NULL, NULL }, { "Candump log", OPEN_INFO_HEURISTIC, candump_open, NULL, NULL, NULL }, { "Busmaster log", OPEN_INFO_HEURISTIC, busmaster_open, NULL, NULL, NULL }, + { "CSS Electronics CLX000 CAN log", OPEN_INFO_MAGIC, cllog_open, "txt", NULL, NULL }, { "Ericsson eNode-B raw log", OPEN_INFO_MAGIC, eri_enb_log_open, NULL, NULL, NULL }, { "Systemd Journal", OPEN_INFO_HEURISTIC, systemd_journal_open, "log;jnl;journal", NULL, NULL }, /* ASCII trace files from Telnet sessions. */ { "Lucent/Ascend access server trace", OPEN_INFO_HEURISTIC, ascend_open, "txt", NULL, NULL }, { "Toshiba Compact ISDN Router snoop", OPEN_INFO_HEURISTIC, toshiba_open, "txt", NULL, NULL }, + + { "EGNOS Message Server (EMS) file", OPEN_INFO_HEURISTIC, ems_open, "ems", NULL, NULL }, + /* Extremely weak heuristics - put them at the end. */ { "Ixia IxVeriWave .vwr Raw Capture", OPEN_INFO_HEURISTIC, vwr_open, "vwr", NULL, NULL }, { "CAM Inspector file", OPEN_INFO_HEURISTIC, camins_open, "camins", NULL, NULL }, @@ -426,20 +431,20 @@ static const struct open_info open_info_base[] = { * for anything else, because the size of the actual array will change if * Lua scripts register a new file reader. */ -#define N_OPEN_INFO_ROUTINES ((sizeof open_info_base / sizeof open_info_base[0])) +#define N_OPEN_INFO_ROUTINES array_length(open_info_base) -static GArray *open_info_arr = NULL; +static GArray *open_info_arr; /* this always points to the top of the created array */ -struct open_info *open_routines = NULL; +struct open_info *open_routines; /* this points to the first OPEN_INFO_HEURISTIC type in the array */ -static guint heuristic_open_routine_idx = 0; +static unsigned heuristic_open_routine_idx; static void set_heuristic_routine(void) { - guint i; + unsigned i; ws_assert(open_info_arr != NULL); for (i = 0; i < open_info_arr->len; i++) { @@ -463,7 +468,7 @@ init_open_routines(void) if (open_info_arr) return; - open_info_arr = g_array_new(TRUE,TRUE,sizeof(struct open_info)); + open_info_arr = g_array_new(true,true,sizeof(struct open_info)); g_array_append_vals(open_info_arr, open_info_base, N_OPEN_INFO_ROUTINES); @@ -500,7 +505,7 @@ init_open_routines(void) * wtap_has_open_info() first. */ void -wtap_register_open_info(struct open_info *oi, const gboolean first_routine) +wtap_register_open_info(struct open_info *oi, const bool first_routine) { if (!oi || !oi->name) { ws_error("No open_info name given to register"); @@ -536,9 +541,9 @@ wtap_register_open_info(struct open_info *oi, const gboolean first_routine) * that condition more gracefully, call wtap_has_open_info() first. */ void -wtap_deregister_open_info(const gchar *name) +wtap_deregister_open_info(const char *name) { - guint i; + unsigned i; if (!name) { ws_error("Missing open_info name to de-register"); @@ -559,27 +564,27 @@ wtap_deregister_open_info(const gchar *name) /* Determines if a open routine short name already exists */ -gboolean -wtap_has_open_info(const gchar *name) +bool +wtap_has_open_info(const char *name) { - guint i; + unsigned i; if (!name) { ws_error("No name given to wtap_has_open_info!"); - return FALSE; + return false; } for (i = 0; i < open_info_arr->len; i++) { if (open_routines[i].name && strcmp(open_routines[i].name, name) == 0) { - return TRUE; + return true; } } - return FALSE; + return false; } -gboolean +bool wtap_uses_lua_filehandler(const wtap* wth) { if (wth && wth->wslua_data != NULL) { @@ -587,10 +592,10 @@ wtap_uses_lua_filehandler(const wtap* wth) * Currently, wslua_data is set if and only if using a Lua * file handler. */ - return TRUE; + return true; } - return FALSE; + return false; } /* @@ -637,10 +642,10 @@ open_info_name_to_type(const char *name) static char * get_file_extension(const char *pathname) { - gchar *filename; - gchar **components; + char *filename; + char **components; size_t ncomponents; - gchar *extensionp; + char *extensionp; /* * Is the pathname empty? @@ -736,16 +741,16 @@ get_file_extension(const char *pathname) /* * Check if file extension is used in this heuristic */ -static gboolean +static bool heuristic_uses_extension(unsigned int i, const char *extension) { - gchar **extensionp; + char **extensionp; /* * Does this file type *have* any extensions? */ if (open_routines[i].extensions == NULL) - return FALSE; /* no */ + return false; /* no */ /* * Check each of them against the specified extension. @@ -753,15 +758,130 @@ heuristic_uses_extension(unsigned int i, const char *extension) for (extensionp = open_routines[i].extensions_set; *extensionp != NULL; extensionp++) { if (strcmp(extension, *extensionp) == 0) { - return TRUE; /* it's one of them */ + return true; /* it's one of them */ + } + } + + return false; /* it's not one of them */ +} + +/* + * Attempt to open the file corresponding to "wth" using the file format + * handler in "candidate". + * + * Returns WTAP_OPEN_MINE upon success, WTAP_OPEN_NOT_MINE if the file is not + * in a suitable format for "candidate", or WTAP_OPEN_ERROR if a failure + * occurred while reading the input. + */ +static int +try_one_open(wtap *wth, const struct open_info *candidate, int *err, char **err_info) +{ + /* Seek back to the beginning of the file; the open routine for the + * previous file type may have left the file position somewhere other + * than the beginning, and the open routine for this file type will + * probably want to start reading at the beginning. + * + * Initialize the data offset while we're at it. + */ + if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) { + /* Error - give up */ + return WTAP_OPEN_ERROR; + } + + /* Set wth with wslua data if any - this is how we pass the data to the + * file reader, kinda like the priv member but not free'd later. + * It's ok for this to copy a NULL. + */ + wth->wslua_data = candidate->wslua_data; + + return candidate->open_routine(wth, err, err_info); +} + +/* + * Attempt to open the file corresponding to "wth". If "type" is supplied + * (i.e. other than WTAP_TYPE_AUTO), that will be the only type attempted. + * Otherwise, heuristic detection of the file format will be performed, + * possibly guided by the extension part of "filename". + * + * Returns WTAP_OPEN_MINE upon success, WTAP_OPEN_NOT_MINE if it was not + * possible to determine a suitable format for the file, or WTAP_OPEN_ERROR if + * a failure occurred while reading the input. + */ +static int +try_open(wtap *wth, unsigned int type, int *err, char **err_info) +{ + int result = WTAP_OPEN_NOT_MINE; + unsigned i; + char *extension; + + /* 'type' is 1-based. */ + if (type != WTAP_TYPE_AUTO && type <= open_info_arr->len) { + /* Try only the specified type. */ + return try_one_open(wth, &open_routines[type - 1], err, err_info); + } + + /* First, all file types that support magic numbers. */ + for (i = 0; i < heuristic_open_routine_idx && result == WTAP_OPEN_NOT_MINE; i++) { + result = try_one_open(wth, &open_routines[i], err, err_info); + } + + if (result != WTAP_OPEN_NOT_MINE) { + return result; + } + + /* Does this file's name have an extension? */ + extension = get_file_extension(wth->pathname); + if (extension != NULL) { + unsigned pass; + + /* + * Yes, the filename has an extension. + * + * The heuristic types fall into one of three categories, which + * we attempt in order by scanning for each category in turn. + * + * First pass selects the heuristic types that list this file's + * extension, as these are most likely to be the correct choice + * for this file. + * + * Second pass selects heuristic types which have no + * extensions. We try those before the ones that have + * extensions that *don't* match this file's extension, on the + * theory that files of those types generally have one of the + * type's extensions, and, as this file *doesn't* have one of + * those extensions, it's probably *not* one of those files. + * + * Third pass selects heuristic types which support extensions + * but where none of them matches this file's extension. + * + * We need only continue searching until we find a match or an + * error occurs. + */ + + for (pass = 0; pass < 3 && result == WTAP_OPEN_NOT_MINE; pass++) { + for (i = heuristic_open_routine_idx; i < open_info_arr->len && result == WTAP_OPEN_NOT_MINE; i++) { + if ( (pass == 0 && heuristic_uses_extension(i, extension)) + || (pass == 1 && open_routines[i].extensions == NULL) + || (pass == 2 && open_routines[i].extensions != NULL + && !heuristic_uses_extension(i, extension))) { + result = try_one_open(wth, &open_routines[i], err, err_info); + } + } + } + + g_free(extension); + } else { + /* No extension. Try all the heuristic types in order. */ + for (i = heuristic_open_routine_idx; i < open_info_arr->len && result == WTAP_OPEN_NOT_MINE; i++) { + result = try_one_open(wth, &open_routines[i], err, err_info); } } - return FALSE; /* it's not one of them */ + return result; } /* Opens a file and prepares a wtap struct. - * If "do_random" is TRUE, it opens the file twice; the second open + * If "do_random" is true, it opens the file twice; the second open * allows the application to do random-access I/O without moving * the seek offset for sequential I/O, which is used by Wireshark * so that it can do sequential I/O to a capture file that's being @@ -770,15 +890,13 @@ heuristic_uses_extension(unsigned int i, const char *extension) */ wtap * wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_info, - gboolean do_random) + bool do_random) { int fd; ws_statb64 statb; - gboolean ispipe = FALSE; + bool ispipe = false; wtap *wth; - unsigned int i; - gboolean use_stdin = FALSE; - gchar *extension; + bool use_stdin = false; wtap_block_t shb; *err = 0; @@ -786,7 +904,7 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_ /* open standard input if filename is '-' */ if (strcmp(filename, "-") == 0) - use_stdin = TRUE; + use_stdin = true; /* First, make sure the file is valid */ if (use_stdin) { @@ -816,7 +934,7 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_ *err = WTAP_ERR_RANDOM_OPEN_PIPE; return NULL; } - ispipe = TRUE; + ispipe = true; } else if (S_ISDIR(statb.st_mode)) { /* * Return different errors for "this is a directory" @@ -900,7 +1018,7 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_ wth->pathname = g_strdup(filename); wth->priv = NULL; wth->wslua_data = NULL; - wth->shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + wth->shb_hdrs = g_array_new(false, false, sizeof(wtap_block_t)); shb = wtap_block_create(WTAP_BLOCK_SECTION); if (shb) g_array_append_val(wth->shb_hdrs, shb); @@ -908,274 +1026,42 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_ /* Initialize the array containing a list of interfaces. pcapng_open and * erf_open needs this (and libpcap_open for ERF encapsulation types). * Always initing it here saves checking for a NULL ptr later. */ - wth->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + wth->interface_data = g_array_new(false, false, sizeof(wtap_block_t)); /* * Next interface data that wtap_get_next_interface_description() * will return. */ wth->next_interface_data = 0; + wth->shb_iface_to_global = g_array_new(false, false, sizeof(unsigned)); + g_array_append_val(wth->shb_iface_to_global, wth->interface_data->len); + if (wth->random_fh) { wth->fast_seek = g_ptr_array_new(); - file_set_random_access(wth->fh, FALSE, wth->fast_seek); - file_set_random_access(wth->random_fh, TRUE, wth->fast_seek); - } - - /* 'type' is 1 greater than the array index */ - if (type != WTAP_TYPE_AUTO && type <= open_info_arr->len) { - int result; - - if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) { - /* I/O error - give up */ - wtap_close(wth); - return NULL; - } - - /* Set wth with wslua data if any - this is how we pass the data - * to the file reader, kinda like the priv member but not free'd later. - * It's ok for this to copy a NULL. - */ - wth->wslua_data = open_routines[type - 1].wslua_data; - - result = (*open_routines[type - 1].open_routine)(wth, err, err_info); - - switch (result) { - case WTAP_OPEN_ERROR: - /* Error - give up */ - wtap_close(wth); - return NULL; - - case WTAP_OPEN_NOT_MINE: - /* No error, but not that type of file */ - goto fail; - - case WTAP_OPEN_MINE: - /* We found the file type */ - goto success; - } - } - - /* Try all file types that support magic numbers */ - for (i = 0; i < heuristic_open_routine_idx; i++) { - /* Seek back to the beginning of the file; the open routine - * for the previous file type may have left the file - * position somewhere other than the beginning, and the - * open routine for this file type will probably want - * to start reading at the beginning. - * - * Initialize the data offset while we're at it. - */ - if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) { - /* Error - give up */ - wtap_close(wth); - return NULL; - } - - /* Set wth with wslua data if any - this is how we pass the data - * to the file reader, kinda like the priv member but not free'd later. - * It's ok for this to copy a NULL. - */ - wth->wslua_data = open_routines[i].wslua_data; - - switch ((*open_routines[i].open_routine)(wth, err, err_info)) { - - case WTAP_OPEN_ERROR: - /* Error - give up */ - wtap_close(wth); - return NULL; - - case WTAP_OPEN_NOT_MINE: - /* No error, but not that type of file */ - break; - - case WTAP_OPEN_MINE: - /* We found the file type */ - goto success; - } + file_set_random_access(wth->fh, false, wth->fast_seek); + file_set_random_access(wth->random_fh, true, wth->fast_seek); } + /* Find a file format handler which can read the file. */ + switch (try_open(wth, type, err, err_info)) { + case WTAP_OPEN_NOT_MINE: + /* Well, it's not one of the types of file we know about. */ + *err = WTAP_ERR_FILE_UNKNOWN_FORMAT; + /* FALLTHROUGH */ - /* Does this file's name have an extension? */ - extension = get_file_extension(filename); - if (extension != NULL) { - /* Yes - try the heuristic types that use that extension first. */ - for (i = heuristic_open_routine_idx; i < open_info_arr->len; i++) { - /* Does this type use that extension? */ - if (heuristic_uses_extension(i, extension)) { - /* Yes. */ - if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) { - /* Error - give up */ - g_free(extension); - wtap_close(wth); - return NULL; - } - - /* Set wth with wslua data if any - this is how we pass the data - * to the file reader, kind of like priv but not free'd later. - */ - wth->wslua_data = open_routines[i].wslua_data; - - switch ((*open_routines[i].open_routine)(wth, - err, err_info)) { - - case WTAP_OPEN_ERROR: - /* Error - give up */ - g_free(extension); - wtap_close(wth); - return NULL; - - case WTAP_OPEN_NOT_MINE: - /* No error, but not that type of file */ - break; - - case WTAP_OPEN_MINE: - /* We found the file type */ - g_free(extension); - goto success; - } - } - } - - /* - * Now try the heuristic types that have no extensions - * to check; we try those before the ones that have - * extensions that *don't* match this file's extension, - * on the theory that files of those types generally - * have one of the type's extensions, and, as this file - * *doesn't* have one of those extensions, it's probably - * *not* one of those files. - */ - for (i = heuristic_open_routine_idx; i < open_info_arr->len; i++) { - /* Does this type have any extensions? */ - if (open_routines[i].extensions == NULL) { - /* No. */ - if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) { - /* Error - give up */ - g_free(extension); - wtap_close(wth); - return NULL; - } - - /* Set wth with wslua data if any - this is how we pass the data - * to the file reader, kind of like priv but not free'd later. - */ - wth->wslua_data = open_routines[i].wslua_data; - - switch ((*open_routines[i].open_routine)(wth, - err, err_info)) { - - case WTAP_OPEN_ERROR: - /* Error - give up */ - g_free(extension); - wtap_close(wth); - return NULL; - - case WTAP_OPEN_NOT_MINE: - /* No error, but not that type of file */ - break; - - case WTAP_OPEN_MINE: - /* We found the file type */ - g_free(extension); - goto success; - } - } - } - - /* - * Now try the ones that have extensions where none of - * them matches this file's extensions. - */ - for (i = heuristic_open_routine_idx; i < open_info_arr->len; i++) { - /* - * Does this type have extensions and is this file's - * extension one of them? - */ - if (open_routines[i].extensions != NULL && - !heuristic_uses_extension(i, extension)) { - /* Yes and no. */ - if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) { - /* Error - give up */ - g_free(extension); - wtap_close(wth); - return NULL; - } - - /* Set wth with wslua data if any - this is how we pass the data - * to the file reader, kind of like priv but not free'd later. - */ - wth->wslua_data = open_routines[i].wslua_data; - - switch ((*open_routines[i].open_routine)(wth, - err, err_info)) { - - case WTAP_OPEN_ERROR: - /* Error - give up */ - g_free(extension); - wtap_close(wth); - return NULL; - - case WTAP_OPEN_NOT_MINE: - /* No error, but not that type of file */ - break; - - case WTAP_OPEN_MINE: - /* We found the file type */ - g_free(extension); - goto success; - } - } - } - g_free(extension); - } else { - /* No - try all the heuristics types in order. */ - for (i = heuristic_open_routine_idx; i < open_info_arr->len; i++) { - - if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) { - /* Error - give up */ - wtap_close(wth); - return NULL; - } - - /* Set wth with wslua data if any - this is how we pass the data - * to the file reader, kind of like priv but not free'd later. - */ - wth->wslua_data = open_routines[i].wslua_data; - - switch ((*open_routines[i].open_routine)(wth, err, err_info)) { - - case WTAP_OPEN_ERROR: - /* Error - give up */ - wtap_close(wth); - return NULL; - - case WTAP_OPEN_NOT_MINE: - /* No error, but not that type of file */ - break; - - case WTAP_OPEN_MINE: - /* We found the file type */ - goto success; - } - } + case WTAP_OPEN_ERROR: + wtap_close(wth); + wth = NULL; } -fail: - - /* Well, it's not one of the types of file we know about. */ - wtap_close(wth); - *err = WTAP_ERR_FILE_UNKNOWN_FORMAT; - return NULL; - -success: return wth; } /* * Given the pathname of the file we just closed with wtap_fdclose(), attempt * to reopen that file and assign the new file descriptor(s) to the sequential - * stream and, if do_random is TRUE, to the random stream. Used on Windows + * stream and, if do_random is true, to the random stream. Used on Windows * after the rename of a file we had open was done or if the rename of a * file on top of a file we had open failed. * @@ -1184,7 +1070,7 @@ success: * random stream is open, so this refuses to open pipes, and only * reopens the random stream. */ -gboolean +bool wtap_fdreopen(wtap *wth, const char *filename, int *err) { ws_statb64 statb; @@ -1198,20 +1084,20 @@ wtap_fdreopen(wtap *wth, const char *filename, int *err) */ if (strcmp(filename, "-") == 0) { *err = WTAP_ERR_RANDOM_OPEN_STDIN; - return FALSE; + return false; } /* First, make sure the file is valid */ if (ws_stat64(filename, &statb) < 0) { *err = errno; - return FALSE; + return false; } if (S_ISFIFO(statb.st_mode)) { /* * Opens of FIFOs are not allowed; see above. */ *err = WTAP_ERR_RANDOM_OPEN_PIPE; - return FALSE; + return false; } else if (S_ISDIR(statb.st_mode)) { /* * Return different errors for "this is a directory" @@ -1219,23 +1105,23 @@ wtap_fdreopen(wtap *wth, const char *filename, int *err) * the user can get a potentially more helpful error. */ *err = EISDIR; - return FALSE; + return false; } else if (! S_ISREG(statb.st_mode)) { *err = WTAP_ERR_NOT_REGULAR_FILE; - return FALSE; + return false; } /* Open the file */ errno = WTAP_ERR_CANT_OPEN; if (!file_fdreopen(wth->random_fh, filename)) { *err = errno; - return FALSE; + return false; } if (strcmp(filename, wth->pathname) != 0) { g_free(wth->pathname); wth->pathname = g_strdup(filename); } - return TRUE; + return true; } /* Table of the file types and subtypes for which we have support. */ @@ -1253,7 +1139,7 @@ static const struct file_type_subtype_info* file_type_subtype_table; /* * Number of elements in the table for builtin file types/subtypes. */ -static guint wtap_num_builtin_file_types_subtypes; +static unsigned wtap_num_builtin_file_types_subtypes; /* * Required builtin types. @@ -1288,7 +1174,7 @@ wtap_init_file_type_subtypes(void) * Add on 7 more for pcapng, pcap, nanosecond pcap, and the * extra modified flavors of pcap. */ - file_type_subtype_table_arr = g_array_sized_new(FALSE, TRUE, + file_type_subtype_table_arr = g_array_sized_new(false, true, sizeof(struct file_type_subtype_info), wtap_module_count*2 + 7); file_type_subtype_table = (const struct file_type_subtype_info*)(void *)file_type_subtype_table_arr->data; @@ -1314,7 +1200,7 @@ wtap_init_file_type_subtypes(void) register_pcap(); /* Now register the ones found by the build process */ - for (guint i = 0; i < wtap_module_count; i++) + for (unsigned i = 0; i < wtap_module_count; i++) wtap_module_reg[i].cb_func(); /* Update the number of builtin entries. */ @@ -1329,7 +1215,7 @@ int wtap_register_file_type_subtype(const struct file_type_subtype_info* fi) { struct file_type_subtype_info* finfo; - guint file_type_subtype; + unsigned file_type_subtype; /* * Check for required fields (description and name). @@ -1382,7 +1268,7 @@ wtap_register_file_type_subtype(const struct file_type_subtype_info* fi) */ *finfo = *fi; - return (gint)file_type_subtype; + return (int)file_type_subtype; } } @@ -1411,7 +1297,7 @@ wtap_deregister_file_type_subtype(const int subtype) ws_error("invalid file type to de-register"); return; } - if ((guint)subtype < wtap_num_builtin_file_types_subtypes) { + if ((unsigned)subtype < wtap_num_builtin_file_types_subtypes) { ws_error("built-in file types cannot be de-registered"); return; } @@ -1428,7 +1314,7 @@ wtap_deregister_file_type_subtype(const int subtype) finfo->name = NULL; finfo->default_file_extension = NULL; finfo->additional_file_extensions = NULL; - finfo->writing_must_seek = FALSE; + finfo->writing_must_seek = false; finfo->num_supported_blocks = 0; finfo->supported_blocks = NULL; finfo->can_write_encap = NULL; @@ -1450,12 +1336,12 @@ wtap_dump_required_file_encap_type(const GArray *file_encaps) encap = WTAP_ENCAP_PER_PACKET; if (file_encaps->len == 1) { /* OK, use the one-and-only encapsulation type. */ - encap = g_array_index(file_encaps, gint, 0); + encap = g_array_index(file_encaps, int, 0); } return encap; } -gboolean +bool wtap_dump_can_write_encap(int file_type_subtype, int encap) { int result = 0; @@ -1463,7 +1349,7 @@ wtap_dump_can_write_encap(int file_type_subtype, int encap) if (file_type_subtype < 0 || file_type_subtype >= (int)file_type_subtype_table_arr->len || file_type_subtype_table[file_type_subtype].can_write_encap == NULL) - return FALSE; + return false; result = (*file_type_subtype_table[file_type_subtype].can_write_encap)(encap); @@ -1478,29 +1364,29 @@ wtap_dump_can_write_encap(int file_type_subtype, int encap) } if (result != 0) - return FALSE; + return false; } - return TRUE; + return true; } /* - * Return TRUE if a capture with a given GArray of encapsulation types + * Return true if a capture with a given GArray of encapsulation types * and a given bitset of comment types can be written in a specified - * format, and FALSE if it can't. + * format, and false if it can't. */ -static gboolean +static bool wtap_dump_can_write_format(int ft, const GArray *file_encaps, - guint32 required_comment_types) + uint32_t required_comment_types) { - guint i; + unsigned i; /* * Can we write in this format? */ if (!wtap_dump_can_open(ft)) { /* No. */ - return FALSE; + return false; } /* @@ -1511,21 +1397,21 @@ wtap_dump_can_write_format(int ft, const GArray *file_encaps, if (wtap_file_type_subtype_supports_option(ft, WTAP_BLOCK_SECTION, OPT_COMMENT) == OPTION_NOT_SUPPORTED) { /* Not section comments. */ - return FALSE; + return false; } } if (required_comment_types & WTAP_COMMENT_PER_INTERFACE) { if (wtap_file_type_subtype_supports_option(ft, WTAP_BLOCK_IF_ID_AND_INFO, OPT_COMMENT) == OPTION_NOT_SUPPORTED) { /* Not interface comments. */ - return FALSE; + return false; } } if (required_comment_types & WTAP_COMMENT_PER_PACKET) { if (wtap_file_type_subtype_supports_option(ft, WTAP_BLOCK_PACKET, OPT_COMMENT) == OPTION_NOT_SUPPORTED) { /* Not packet comments. */ - return FALSE; + return false; } } @@ -1535,7 +1421,7 @@ wtap_dump_can_write_format(int ft, const GArray *file_encaps, */ if (!wtap_dump_can_write_encap(ft, wtap_dump_required_file_encap_type(file_encaps))) { /* No. */ - return FALSE; + return false; } /* @@ -1545,20 +1431,20 @@ wtap_dump_can_write_format(int ft, const GArray *file_encaps, if (!wtap_dump_can_write_encap(ft, g_array_index(file_encaps, int, i))) { /* No - one of them isn't. */ - return FALSE; + return false; } } /* Yes - we're OK. */ - return TRUE; + return true; } /* - * Return TRUE if we can write a file with the given GArray of + * Return true if we can write a file with the given GArray of * encapsulation types and the given bitmask of comment types. */ -gboolean -wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types) +bool +wtap_dump_can_write(const GArray *file_encaps, uint32_t required_comment_types) { int ft; @@ -1569,19 +1455,19 @@ wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types) */ if (wtap_dump_can_write_format(ft, file_encaps, required_comment_types)) { /* OK, we can write it out in this type. */ - return TRUE; + return true; } } /* No, we couldn't save it in any format. */ - return FALSE; + return false; } /* * Sort by file type/subtype name. */ static int -compare_file_type_subtypes_by_name(gconstpointer a, gconstpointer b) +compare_file_type_subtypes_by_name(const void *a, const void *b) { int file_type_subtype_a = *(const int *)a; int file_type_subtype_b = *(const int *)b; @@ -1594,7 +1480,7 @@ compare_file_type_subtypes_by_name(gconstpointer a, gconstpointer b) * Sort by file type/subtype description. */ static int -compare_file_type_subtypes_by_description(gconstpointer a, gconstpointer b) +compare_file_type_subtypes_by_description(const void *a, const void *b) { int file_type_subtype_a = *(const int *)a; int file_type_subtype_b = *(const int *)b; @@ -1610,7 +1496,7 @@ compare_file_type_subtypes_by_description(gconstpointer a, gconstpointer b) */ GArray * wtap_get_savable_file_types_subtypes_for_file(int file_type_subtype, - const GArray *file_encaps, guint32 required_comment_types, + const GArray *file_encaps, uint32_t required_comment_types, ft_sort_order sort_order) { GArray *savable_file_types_subtypes; @@ -1676,7 +1562,7 @@ wtap_get_savable_file_types_subtypes_for_file(int file_type_subtype, } /* Allocate the array. */ - savable_file_types_subtypes = g_array_new(FALSE, FALSE, + savable_file_types_subtypes = g_array_new(false, false, sizeof (int)); /* @@ -1732,7 +1618,7 @@ wtap_get_writable_file_types_subtypes(ft_sort_order sort_order) * XXX - that's overkill; just scan the table to find all the * writable types and count them. */ - writable_file_types_subtypes = g_array_sized_new(FALSE, FALSE, + writable_file_types_subtypes = g_array_sized_new(false, false, sizeof (int), file_type_subtype_table_arr->len); /* @@ -1831,7 +1717,7 @@ wtap_name_to_file_type_subtype(const char *name) * Is this name a backwards-compatibility name? */ new_name = (char *)g_hash_table_lookup(type_subtype_name_map, - (gpointer)name); + (void *)name); if (new_name != NULL) { /* * Yes, and new_name is the name to which it should @@ -1932,7 +1818,7 @@ wtap_file_type_subtype_supports_block(int file_type_subtype, */ option_support_t wtap_file_type_subtype_supports_option(int file_type_subtype, - wtap_block_type_t type, guint option) + wtap_block_type_t type, unsigned option) { size_t num_supported_blocks; const struct supported_block_type *supported_blocks; @@ -1996,8 +1882,8 @@ static GSList * add_extensions_for_file_type_subtype(int file_type_subtype, GSList *extensions, GSList *compression_type_extensions) { - gchar **extensions_set, **extensionp; - gchar *extension; + char **extensions_set, **extensionp; + char *extension; if (file_type_subtype < 0 || file_type_subtype >= (int)file_type_subtype_table_arr->len) { @@ -2052,7 +1938,7 @@ add_extensions_for_file_type_subtype(int file_type_subtype, GSList *extensions, /* Return a list of file extensions that are used by the specified file * type/subtype. * - * If include_compressed is TRUE, the list will include compressed + * If include_compressed is true, the list will include compressed * extensions, e.g. not just "pcap" but also "pcap.gz" if we can read * gzipped files. * @@ -2060,7 +1946,7 @@ add_extensions_for_file_type_subtype(int file_type_subtype, GSList *extensions, * with g_free(). */ GSList * -wtap_get_file_extensions_list(int file_type_subtype, gboolean include_compressed) +wtap_get_file_extensions_list(int file_type_subtype, bool include_compressed) { GSList *extensions, *compression_type_extensions; @@ -2223,47 +2109,47 @@ wtap_default_file_extension(int file_type_subtype) /* * Return whether we know how to write the specified file type. */ -gboolean +bool wtap_dump_can_open(int file_type_subtype) { if (file_type_subtype < 0 || file_type_subtype >= (int)file_type_subtype_table_arr->len || file_type_subtype_table[file_type_subtype].dump_open == NULL) - return FALSE; + return false; - return TRUE; + return true; } /* * Return whether we know how to write a compressed file of the specified * file type. */ -#ifdef HAVE_ZLIB -gboolean +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) || defined (HAVE_LZ4FRAME_H) +bool wtap_dump_can_compress(int file_type_subtype) { /* * If this is an unknown file type, or if we have to * seek when writing out a file with this file type, - * return FALSE. + * return false. */ if (file_type_subtype < 0 || file_type_subtype >= (int)file_type_subtype_table_arr->len || file_type_subtype_table[file_type_subtype].writing_must_seek) - return FALSE; + return false; - return TRUE; + return true; } #else -gboolean +bool wtap_dump_can_compress(int file_type_subtype _U_) { - return FALSE; + return false; } #endif -static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int *err, - gchar **err_info); +static bool wtap_dump_open_finish(wtap_dumper *wdh, int *err, + char **err_info); static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename); static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd); @@ -2288,7 +2174,7 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t if (!wtap_dump_can_open(file_type_subtype)) { /* Invalid type, or type we don't know how to write. */ *err = WTAP_ERR_UNWRITABLE_FILE_TYPE; - return FALSE; + return false; } /* OK, we know how to write that file type/subtype; can we write @@ -2338,7 +2224,8 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t wdh->file_encap = params->encap; wdh->compression_type = compression_type; wdh->wslua_data = NULL; - wdh->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + wdh->shb_iface_to_global = params->shb_iface_to_global; + wdh->interface_data = g_array_new(false, false, sizeof(wtap_block_t)); /* Set Section Header Block data */ wdh->shb_hdrs = params->shb_hdrs; @@ -2347,7 +2234,7 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t /* Set Interface Description Block data */ if (interfaces && interfaces->len) { if (!params->dont_copy_idbs) { /* XXX */ - guint itf_count; + unsigned itf_count; /* Note: this memory is owned by wtap_dumper and will become * invalid after wtap_dump_close. */ @@ -2383,14 +2270,14 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t wdh->dsbs_initial = params->dsbs_initial; wdh->dsbs_growing = params->dsbs_growing; /* Set Sysdig meta events */ - wdh->sysdig_mev_growing = params->sysdig_mev_growing; + wdh->mevs_growing = params->mevs_growing; return wdh; } wtap_dumper * wtap_dump_open(const char *filename, int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, - int *err, gchar **err_info) + int *err, char **err_info) { wtap_dumper *wdh; WFILE_T fh; @@ -2429,7 +2316,7 @@ wtap_dump_open(const char *filename, int file_type_subtype, wtap_dumper * wtap_dump_open_tempfile(const char *tmpdir, char **filenamep, const char *pfx, int file_type_subtype, wtap_compression_type compression_type, - const wtap_dump_params *params, int *err, gchar **err_info) + const wtap_dump_params *params, int *err, char **err_info) { int fd; const char *ext; @@ -2490,7 +2377,7 @@ wtap_dump_open_tempfile(const char *tmpdir, char **filenamep, const char *pfx, wtap_dumper * wtap_dump_fdopen(int fd, int file_type_subtype, wtap_compression_type compression_type, - const wtap_dump_params *params, int *err, gchar **err_info) + const wtap_dump_params *params, int *err, char **err_info) { wtap_dumper *wdh; WFILE_T fh; @@ -2525,7 +2412,7 @@ wtap_dump_fdopen(int fd, int file_type_subtype, wtap_compression_type compressio wtap_dumper * wtap_dump_open_stdout(int file_type_subtype, wtap_compression_type compression_type, - const wtap_dump_params *params, int *err, gchar **err_info) + const wtap_dump_params *params, int *err, char **err_info) { int new_fd; wtap_dumper *wdh; @@ -2566,31 +2453,31 @@ wtap_dump_open_stdout(int file_type_subtype, wtap_compression_type compression_t return wdh; } -static gboolean -wtap_dump_open_finish(wtap_dumper *wdh, int *err, gchar **err_info) +static bool +wtap_dump_open_finish(wtap_dumper *wdh, int *err, char **err_info) { int fd; - gboolean cant_seek; + bool cant_seek; /* Can we do a seek on the file descriptor? If not, note that fact. */ if (wdh->compression_type != WTAP_UNCOMPRESSED) { - cant_seek = TRUE; + cant_seek = true; } else { fd = ws_fileno((FILE *)wdh->fh); if (ws_lseek64(fd, 1, SEEK_CUR) == (off_t) -1) - cant_seek = TRUE; + cant_seek = true; else { /* Undo the seek. */ ws_lseek64(fd, 0, SEEK_SET); - cant_seek = FALSE; + cant_seek = false; } } /* If this file type requires seeking, and we can't seek, fail. */ if (file_type_subtype_table[wdh->file_type_subtype].writing_must_seek && cant_seek) { *err = WTAP_ERR_CANT_WRITE_TO_PIPE; - return FALSE; + return false; } /* Set wdh with wslua data if any - this is how we pass the data @@ -2602,68 +2489,77 @@ wtap_dump_open_finish(wtap_dumper *wdh, int *err, gchar **err_info) /* Now try to open the file for writing. */ if (!(*file_type_subtype_table[wdh->file_type_subtype].dump_open)(wdh, err, err_info)) { - return FALSE; + return false; } - return TRUE; /* success! */ + return true; /* success! */ } -gboolean +bool wtap_dump_add_idb(wtap_dumper *wdh, wtap_block_t idb, int *err, - gchar **err_info) + char **err_info) { if (wdh->subtype_add_idb == NULL) { /* Not supported. */ *err = WTAP_ERR_UNWRITABLE_REC_TYPE; *err_info = g_strdup("Adding IDBs isn't supported by this file type"); - return FALSE; + return false; } *err = 0; *err_info = NULL; return (wdh->subtype_add_idb)(wdh, idb, err, err_info); } -gboolean +bool wtap_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info) + const uint8_t *pd, int *err, char **err_info) { *err = 0; *err_info = NULL; return (wdh->subtype_write)(wdh, rec, pd, err, err_info); } -gboolean +bool wtap_dump_flush(wtap_dumper *wdh, int *err) { -#ifdef HAVE_ZLIB - if (wdh->compression_type == WTAP_GZIP_COMPRESSED) { + switch (wdh->compression_type) { +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) + case WTAP_GZIP_COMPRESSED: if (gzwfile_flush((GZWFILE_T)wdh->fh) == -1) { *err = gzwfile_geterr((GZWFILE_T)wdh->fh); - return FALSE; + return false; } - } else + break; #endif - { +#ifdef HAVE_LZ4FRAME_H + case WTAP_LZ4_COMPRESSED: + if (lz4wfile_flush((LZ4WFILE_T)wdh->fh) == -1) { + *err = lz4wfile_geterr((LZ4WFILE_T)wdh->fh); + return false; + } + break; +#endif /* HAVE_LZ4FRAME_H */ + default: if (fflush((FILE *)wdh->fh) == EOF) { *err = errno; - return FALSE; + return false; } } - return TRUE; + return true; } -gboolean -wtap_dump_close(wtap_dumper *wdh, gboolean *needs_reload, - int *err, gchar **err_info) +bool +wtap_dump_close(wtap_dumper *wdh, bool *needs_reload, + int *err, char **err_info) { - gboolean ret = TRUE; + bool ret = true; *err = 0; *err_info = NULL; if (wdh->subtype_finish != NULL) { /* There's a finish routine for this dump stream. */ if (!(wdh->subtype_finish)(wdh, err, err_info)) - ret = FALSE; + ret = false; } errno = WTAP_ERR_CANT_CLOSE; if (wtap_dump_file_close(wdh) == EOF) { @@ -2674,7 +2570,7 @@ wtap_dump_close(wtap_dumper *wdh, gboolean *needs_reload, if (err != NULL) *err = errno; } - ret = FALSE; + ret = false; } if (needs_reload != NULL) *needs_reload = wdh->needs_reload; @@ -2691,19 +2587,19 @@ wtap_dump_file_type_subtype(wtap_dumper *wdh) return wdh->file_type_subtype; } -gint64 +int64_t wtap_get_bytes_dumped(wtap_dumper *wdh) { return wdh->bytes_dumped; } void -wtap_set_bytes_dumped(wtap_dumper *wdh, gint64 bytes_dumped) +wtap_set_bytes_dumped(wtap_dumper *wdh, int64_t bytes_dumped) { wdh->bytes_dumped = bytes_dumped; } -gboolean +bool wtap_addrinfo_list_empty(addrinfo_lists_t *addrinfo_lists) { return (addrinfo_lists == NULL) || @@ -2711,15 +2607,15 @@ wtap_addrinfo_list_empty(addrinfo_lists_t *addrinfo_lists) (addrinfo_lists->ipv6_addr_list == NULL)); } -gboolean +bool wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists) { if (!wdh || wdh->file_type_subtype < 0 || wdh->file_type_subtype >= (int)file_type_subtype_table_arr->len || wtap_file_type_subtype_supports_block(wdh->file_type_subtype, WTAP_BLOCK_NAME_RESOLUTION) == BLOCK_NOT_SUPPORTED) - return FALSE; + return false; wdh->addrinfo_lists = addrinfo_lists; - return TRUE; + return true; } void @@ -2760,71 +2656,82 @@ void wtap_dump_discard_sysdig_meta_events(wtap_dumper *wdh) { /* As above for DSBs. */ - if (wdh->sysdig_mev_growing) { + if (wdh->mevs_growing) { /* * Pretend we've written all of them. */ - wdh->sysdig_mev_growing_written = wdh->sysdig_mev_growing->len; + wdh->mevs_growing_written = wdh->mevs_growing->len; } } /* internally open a file for writing (compressed or not) */ -#ifdef HAVE_ZLIB static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename) { - if (wdh->compression_type == WTAP_GZIP_COMPRESSED) { + switch (wdh->compression_type) { +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) + case WTAP_GZIP_COMPRESSED: return gzwfile_open(filename); - } else { +#endif /* defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) */ +#ifdef HAVE_LZ4FRAME_H + case WTAP_LZ4_COMPRESSED: + return lz4wfile_open(filename); +#endif /* HAVE_LZ4FRAME_H */ + default: return ws_fopen(filename, "wb"); } } -#else -static WFILE_T -wtap_dump_file_open(wtap_dumper *wdh _U_, const char *filename) -{ - return ws_fopen(filename, "wb"); -} -#endif /* internally open a file for writing (compressed or not) */ -#ifdef HAVE_ZLIB static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd) { - if (wdh->compression_type == WTAP_GZIP_COMPRESSED) { + switch (wdh->compression_type) { +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) + case WTAP_GZIP_COMPRESSED: return gzwfile_fdopen(fd); - } else { +#endif /* defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) */ +#ifdef HAVE_LZ4FRAME_H + case WTAP_LZ4_COMPRESSED: + return lz4wfile_fdopen(fd); +#endif /* HAVE_LZ4FRAME_H */ + default: return ws_fdopen(fd, "wb"); } } -#else -static WFILE_T -wtap_dump_file_fdopen(wtap_dumper *wdh _U_, int fd) -{ - return ws_fdopen(fd, "wb"); -} -#endif /* internally writing raw bytes (compressed or not). Updates wdh->bytes_dumped on success */ -gboolean +bool wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize, int *err) { size_t nwritten; -#ifdef HAVE_ZLIB - if (wdh->compression_type == WTAP_GZIP_COMPRESSED) { + switch (wdh->compression_type) { +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) + case WTAP_GZIP_COMPRESSED: nwritten = gzwfile_write((GZWFILE_T)wdh->fh, buf, (unsigned int) bufsize); /* * gzwfile_write() returns 0 on error. */ if (nwritten == 0) { *err = gzwfile_geterr((GZWFILE_T)wdh->fh); - return FALSE; + return false; } - } else + break; #endif - { +#ifdef HAVE_LZ4FRAME_H + case WTAP_LZ4_COMPRESSED: + nwritten = lz4wfile_write((LZ4WFILE_T)wdh->fh, buf, bufsize); + /* + * lz4wfile_write() returns 0 on error. + */ + if (nwritten == 0) { + *err = lz4wfile_geterr((LZ4WFILE_T)wdh->fh); + return false; + } + break; +#endif /* HAVE_LZ4FRAME_H */ + default: errno = WTAP_ERR_CANT_WRITE; nwritten = fwrite(buf, 1, bufsize, (FILE *)wdh->fh); /* @@ -2836,29 +2743,35 @@ wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize, int *err *err = errno; else *err = WTAP_ERR_SHORT_WRITE; - return FALSE; + return false; } } wdh->bytes_dumped += bufsize; - return TRUE; + return true; } /* internally close a file for writing (compressed or not) */ static int wtap_dump_file_close(wtap_dumper *wdh) { -#ifdef HAVE_ZLIB - if (wdh->compression_type == WTAP_GZIP_COMPRESSED) + switch (wdh->compression_type) { +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) + case WTAP_GZIP_COMPRESSED: return gzwfile_close((GZWFILE_T)wdh->fh); - else #endif +#ifdef HAVE_LZ4FRAME_H + case WTAP_LZ4_COMPRESSED: + return lz4wfile_close((LZ4WFILE_T)wdh->fh); +#endif /* HAVE_LZ4FRAME_H */ + default: return fclose((FILE *)wdh->fh); + } } -gint64 -wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err) +int64_t +wtap_dump_file_seek(wtap_dumper *wdh, int64_t offset, int whence, int *err) { -#ifdef HAVE_ZLIB +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) || defined (HAVE_LZ4FRAME_H) if (wdh->compression_type != WTAP_UNCOMPRESSED) { *err = WTAP_ERR_CANT_SEEK_COMPRESSED; return -1; @@ -2875,11 +2788,11 @@ wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err) } } -gint64 +int64_t wtap_dump_file_tell(wtap_dumper *wdh, int *err) { - gint64 rval; -#ifdef HAVE_ZLIB + int64_t rval; +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) || defined (HAVE_LZ4FRAME_H) if (wdh->compression_type != WTAP_UNCOMPRESSED) { *err = WTAP_ERR_CANT_SEEK_COMPRESSED; return -1; @@ -2899,7 +2812,7 @@ wtap_dump_file_tell(wtap_dumper *wdh, int *err) void cleanup_open_routines(void) { - guint i; + unsigned i; struct open_info *i_open; if (open_routines != NULL && open_info_arr) { @@ -2908,7 +2821,7 @@ cleanup_open_routines(void) g_strfreev(i_open->extensions_set); } - g_array_free(open_info_arr, TRUE); + g_array_free(open_info_arr, true); open_info_arr = NULL; } } @@ -2929,6 +2842,7 @@ cleanup_open_routines(void) static GArray *backwards_compatibility_lua_names; void +// NOLINTNEXTLINE(misc-no-recursion) wtap_register_backwards_compatibility_lua_name(const char *name, int ft) { struct backwards_compatibiliity_lua_name entry; @@ -2938,8 +2852,8 @@ wtap_register_backwards_compatibility_lua_name(const char *name, int ft) * Use the same size as we do for the file type/subtype table. */ if (backwards_compatibility_lua_names == NULL) { - backwards_compatibility_lua_names = g_array_sized_new(FALSE, - TRUE, sizeof(struct backwards_compatibiliity_lua_name), + backwards_compatibility_lua_names = g_array_sized_new(false, + true, sizeof(struct backwards_compatibiliity_lua_name), wtap_module_count*2); /* diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index 67979a5b..f0c42b84 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -15,6 +15,9 @@ */ #include "config.h" + +#define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP + #include "file_wrappers.h" #include <assert.h> @@ -24,14 +27,25 @@ #include <wsutil/file_util.h> -#ifdef HAVE_ZLIB +#if defined(HAVE_ZLIB) && !defined(HAVE_ZLIBNG) +#define USE_ZLIB_OR_ZLIBNG #define ZLIB_CONST +#define ZLIB_PREFIX(x) x #include <zlib.h> -#endif /* HAVE_ZLIB */ +typedef z_stream zlib_stream; +#endif /* defined(HAVE_ZLIB) && !defined(HAVE_ZLIBNG) */ + +#ifdef HAVE_ZLIBNG +#define USE_ZLIB_OR_ZLIBNG +#define HAVE_INFLATEPRIME 1 +#define ZLIB_PREFIX(x) zng_ ## x +#include <zlib-ng.h> +typedef zng_stream zlib_stream; +#endif /* HAVE_ZLIBNG */ #ifdef HAVE_ZSTD #include <zstd.h> -#endif +#endif /* HAVE_ZSTD */ #ifdef HAVE_LZ4 #include <lz4.h> @@ -39,24 +53,11 @@ #if LZ4_VERSION_NUMBER >= 10703 #define USE_LZ4 #include <lz4frame.h> -#endif -#endif - -/* - * See RFC 1952: - * - * https://tools.ietf.org/html/rfc1952 - * - * for a description of the gzip file format. - * - * Some other compressed file formats we might want to support: - * - * XZ format: https://tukaani.org/xz/ - * - * Bzip2 format: https://www.sourceware.org/bzip2/ - * - * Lzip format: https://www.nongnu.org/lzip/ - */ +#ifndef LZ4F_BLOCK_HEADER_SIZE /* Added in LZ4_VERSION_NUMBER 10902 */ +#define LZ4F_BLOCK_HEADER_SIZE 4 +#endif /* LZ4F_BLOCK_HEADER_SIZE */ +#endif /* LZ4_VERSION_NUMBER >= 10703 */ +#endif /* HAVE_LZ4 */ /* * List of compression types supported. @@ -65,22 +66,58 @@ static struct compression_type { wtap_compression_type type; const char *extension; const char *description; + const char *name; + const bool can_write_compressed; } compression_types[] = { -#ifdef HAVE_ZLIB - { WTAP_GZIP_COMPRESSED, "gz", "gzip compressed" }, -#endif +#ifdef USE_ZLIB_OR_ZLIBNG + { WTAP_GZIP_COMPRESSED, "gz", "gzip compressed", "gzip", true }, +#endif /* USE_ZLIB_OR_ZLIBNG */ #ifdef HAVE_ZSTD - { WTAP_ZSTD_COMPRESSED, "zst", "zstd compressed" }, -#endif + { WTAP_ZSTD_COMPRESSED, "zst", "zstd compressed", "zstd", false }, +#endif /* HAVE_ZSTD */ #ifdef USE_LZ4 - { WTAP_LZ4_COMPRESSED, "lz4", "lz4 compressed" }, -#endif - { WTAP_UNCOMPRESSED, NULL, NULL } + { WTAP_LZ4_COMPRESSED, "lz4", "lz4 compressed", "lz4", true }, +#endif /* USE_LZ4 */ + { WTAP_UNCOMPRESSED, NULL, NULL, "none", true }, + { WTAP_UNKNOWN_COMPRESSION, NULL, NULL, NULL, false }, }; static wtap_compression_type file_get_compression_type(FILE_T stream); wtap_compression_type +wtap_name_to_compression_type(const char *name) +{ + for (struct compression_type *p = compression_types; + p->type != WTAP_UNKNOWN_COMPRESSION; p++) { + if (!g_strcmp0(name, p->name)) + return p->type; + } + return WTAP_UNKNOWN_COMPRESSION; +} + +wtap_compression_type +wtap_extension_to_compression_type(const char *ext) +{ + for (struct compression_type *p = compression_types; + p->type != WTAP_UNKNOWN_COMPRESSION; p++) { + if (!g_strcmp0(ext, p->extension)) + return p->type; + } + return WTAP_UNKNOWN_COMPRESSION; +} + +bool +wtap_can_write_compression_type(wtap_compression_type compression_type) +{ + for (struct compression_type *p = compression_types; p->type != WTAP_UNKNOWN_COMPRESSION; p++) { + if (compression_type == p->type) + return p->can_write_compressed; + } + + return false; +} + +wtap_compression_type wtap_get_compression_type(wtap *wth) { return file_get_compression_type((wth->fh == NULL) ? wth->random_fh : wth->fh); @@ -117,13 +154,30 @@ wtap_get_all_compression_type_extensions_list(void) for (struct compression_type *p = compression_types; p->type != WTAP_UNCOMPRESSED; p++) - extensions = g_slist_prepend(extensions, (gpointer)p->extension); + extensions = g_slist_prepend(extensions, (void *)p->extension); return extensions; } +GSList * +wtap_get_all_output_compression_type_names_list(void) +{ + GSList *names; + + names = NULL; /* empty list, to start with */ + + for (struct compression_type *p = compression_types; + p->type != WTAP_UNCOMPRESSED; p++) { + if (p->can_write_compressed) + names = g_slist_prepend(names, (void *)p->name); + } + + return names; +} + /* #define GZBUFSIZE 8192 */ #define GZBUFSIZE 4096 +#define LZ4BUFSIZE 4194304 // 4MiB, maximum block size /* values for wtap_reader compression */ typedef enum { @@ -148,11 +202,11 @@ typedef enum { * imposes a limit on the buffer size when we're reading a * gzipped file. * - * Thus, we use guint for the buffer sizes, offsets, amount available + * Thus, we use unsigned for the buffer sizes, offsets, amount available * from the buffer, etc. * * If we want an even bigger buffer for uncompressed data, or for - * some other form of compression, then the guint-sized values should + * some other form of compression, then the unsigned-sized values should * be in structure values used only for reading gzipped files, and * other values should be used for uncompressed data or data * compressed using other algorithms (e.g., in a union). @@ -160,53 +214,61 @@ typedef enum { #define MAX_READ_BUF_SIZE (1U << 30) struct wtap_reader_buf { - guint8 *buf; /* buffer */ - guint8 *next; /* next byte to deliver from buffer */ - guint avail; /* number of bytes available to deliver at next */ + uint8_t *buf; /* buffer */ + uint8_t *next; /* next byte to deliver from buffer */ + unsigned avail; /* number of bytes available to deliver at next */ }; struct wtap_reader { int fd; /* file descriptor */ - gint64 raw_pos; /* current position in file (just to not call lseek()) */ - gint64 pos; /* current position in uncompressed data */ - guint size; /* buffer size */ + int64_t raw_pos; /* current position in file (just to not call lseek()) */ + int64_t pos; /* current position in uncompressed data */ + unsigned size; /* buffer size */ struct wtap_reader_buf in; /* input buffer, containing compressed data */ struct wtap_reader_buf out; /* output buffer, containing uncompressed data */ - gboolean eof; /* TRUE if end of input file reached */ - gint64 start; /* where the gzip data started, for rewinding */ - gint64 raw; /* where the raw data started, for seeking */ + bool eof; /* true if end of input file reached */ + int64_t start; /* where the gzip data started, for rewinding */ + int64_t raw; /* where the raw data started, for seeking */ compression_t compression; /* type of compression, if any */ compression_t last_compression; /* last known compression type */ - gboolean is_compressed; /* FALSE if completely uncompressed, TRUE otherwise */ + bool is_compressed; /* false if completely uncompressed, true otherwise */ /* seek request */ - gint64 skip; /* amount to skip (already rewound if backwards) */ - gboolean seek_pending; /* TRUE if seek request pending */ + int64_t skip; /* amount to skip (already rewound if backwards) */ + bool seek_pending; /* true if seek request pending */ /* error information */ int err; /* error code */ const char *err_info; /* additional error information string for some errors */ -#ifdef HAVE_ZLIB + /* + * Decompression stream information. + * + * XXX - should this be a union? + */ +#ifdef USE_ZLIB_OR_ZLIBNG /* zlib inflate stream */ - z_stream strm; /* stream structure in-place (not a pointer) */ - gboolean dont_check_crc; /* TRUE if we aren't supposed to check the CRC */ -#endif - /* fast seeking */ - GPtrArray *fast_seek; - void *fast_seek_cur; + zlib_stream strm; /* stream structure in-place (not a pointer) */ + bool dont_check_crc; /* true if we aren't supposed to check the CRC */ +#endif /* USE_ZLIB_OR_ZLIBNG */ #ifdef HAVE_ZSTD ZSTD_DCtx *zstd_dctx; -#endif +#endif /* HAVE_ZSTD */ #ifdef USE_LZ4 LZ4F_dctx *lz4_dctx; -#endif + LZ4F_frameInfo_t lz4_info; + unsigned char lz4_hdr[LZ4F_HEADER_SIZE_MAX]; +#endif /* USE_LZ4 */ + + /* fast seeking */ + GPtrArray *fast_seek; + void *fast_seek_cur; }; /* Current read offset within a buffer. */ -static guint +static unsigned offset_in_buffer(struct wtap_reader_buf *buf) { /* buf->next points to the next byte to read, and buf->buf points @@ -215,11 +277,11 @@ offset_in_buffer(struct wtap_reader_buf *buf) This will fit in an unsigned int, because it can't be bigger than the size of the buffer, which is an unsigned int. */ - return (guint)(buf->next - buf->buf); + return (unsigned)(buf->next - buf->buf); } /* Number of bytes of data that are in a buffer. */ -static guint +static unsigned bytes_in_buffer(struct wtap_reader_buf *buf) { /* buf->next + buf->avail points just past the last byte of data in @@ -227,9 +289,9 @@ bytes_in_buffer(struct wtap_reader_buf *buf) Thus, (buf->next + buf->avail) - buf->buf is the number of bytes of data in the buffer. - This will fit in an guint, because it can't be bigger - than the size of the buffer, which is a guint. */ - return (guint)((buf->next + buf->avail) - buf->buf); + This will fit in an unsigned, because it can't be bigger + than the size of the buffer, which is a unsigned. */ + return (unsigned)((buf->next + buf->avail) - buf->buf); } /* Reset a buffer, discarding all data in the buffer, so we read into @@ -244,7 +306,7 @@ buf_reset(struct wtap_reader_buf *buf) static int buf_read(FILE_T state, struct wtap_reader_buf *buf) { - guint space_left, to_read; + unsigned space_left, to_read; unsigned char *read_ptr; ssize_t ret; @@ -273,9 +335,9 @@ buf_read(FILE_T state, struct wtap_reader_buf *buf) return -1; } if (ret == 0) - state->eof = TRUE; + state->eof = true; state->raw_pos += ret; - buf->avail += (guint)ret; + buf->avail += (unsigned)ret; return 0; } @@ -292,23 +354,33 @@ fill_in_buffer(FILE_T state) } #define ZLIB_WINSIZE 32768 +#define LZ4_WINSIZE 65536 struct fast_seek_point { - gint64 out; /* corresponding offset in uncompressed data */ - gint64 in; /* offset in input file of first full byte */ + int64_t out; /* corresponding offset in uncompressed data */ + int64_t in; /* offset in input file of first full byte */ compression_t compression; union { struct { #ifdef HAVE_INFLATEPRIME int bits; /* number of bits (1-7) from byte at in - 1, or 0 */ -#endif +#endif /* HAVE_INFLATEPRIME */ unsigned char window[ZLIB_WINSIZE]; /* preceding 32K of uncompressed data */ /* be gentle with Z_STREAM_END, 8 bytes more... Another solution would be to comment checks out */ - guint32 adler; - guint32 total_out; + uint32_t adler; + uint32_t total_out; } zlib; +#ifdef USE_LZ4 + struct { + LZ4F_frameInfo_t lz4_info; + unsigned char lz4_hdr[LZ4F_HEADER_SIZE_MAX]; +#if 0 + unsigned char window[LZ4_WINSIZE]; /* preceding 64K of uncompressed data */ +#endif + } lz4; +#endif } data; }; @@ -318,13 +390,13 @@ struct zlib_cur_seek_point { unsigned int have; }; -#define SPAN G_GINT64_CONSTANT(1048576) +#define SPAN INT64_C(1048576) static struct fast_seek_point * -fast_seek_find(FILE_T file, gint64 pos) +fast_seek_find(FILE_T file, int64_t pos) { struct fast_seek_point *smallest = NULL; struct fast_seek_point *item; - guint low, i, max; + unsigned low, i, max; if (!file->fast_seek) return NULL; @@ -346,42 +418,101 @@ fast_seek_find(FILE_T file, gint64 pos) } static void -fast_seek_header(FILE_T file, gint64 in_pos, gint64 out_pos, +fast_seek_header(FILE_T file, int64_t in_pos, int64_t out_pos, compression_t compression) { struct fast_seek_point *item = NULL; + if (!file->fast_seek) { + return; + } + if (file->fast_seek->len != 0) item = (struct fast_seek_point *)file->fast_seek->pdata[file->fast_seek->len - 1]; + /* fast_seek_header always adds a fast seek point, even if less than + * SPAN from the last one. That is because it used for new streams + * (including concatenated streams) where the compression type + * or, for LZ4, compression options, may change. + */ if (!item || item->out < out_pos) { struct fast_seek_point *val = g_new(struct fast_seek_point,1); val->in = in_pos; val->out = out_pos; val->compression = compression; +#ifdef USE_LZ4 + if (compression == LZ4) { + val->data.lz4.lz4_info = file->lz4_info; + memcpy(val->data.lz4.lz4_hdr, file->lz4_hdr, LZ4F_HEADER_SIZE_MAX); + } +#endif /* USE_LZ4 */ g_ptr_array_add(file->fast_seek, val); } } static void -fast_seek_reset( -#ifdef HAVE_ZLIB - FILE_T state) -#else - FILE_T state _U_) -#endif +fast_seek_reset(FILE_T state) { -#ifdef HAVE_ZLIB - if (state->compression == ZLIB && state->fast_seek_cur != NULL) { - struct zlib_cur_seek_point *cur = (struct zlib_cur_seek_point *) state->fast_seek_cur; + switch (state->compression) { + + case UNKNOWN: + break; - cur->have = 0; + case UNCOMPRESSED: + /* Nothing to do */ + break; + + case ZLIB: +#ifdef USE_ZLIB_OR_ZLIBNG + if (state->fast_seek_cur != NULL) { + struct zlib_cur_seek_point *cur = (struct zlib_cur_seek_point *) state->fast_seek_cur; + + cur->have = 0; + } +#else + /* This "cannot happen" */ + ws_assert_not_reached(); +#endif /* USE_ZLIB_OR_ZLIBNG */ + break; + + case GZIP_AFTER_HEADER: + break; + + case ZSTD: +#ifdef HAVE_ZSTD + /* Anything to do? */ +#else + /* This "cannot happen" */ + ws_assert_not_reached(); +#endif /* HAVE_ZSTD */ + break; + + case LZ4: +#ifdef HAVE_LZ4 + /* Anything to do? */ +#else + /* This "cannot happen" */ + ws_assert_not_reached(); +#endif /* HAVE_LZ4 */ + break; + + /* Add other compression types here */ + + default: + /* This "cannot happen" */ + ws_assert_not_reached(); + break; } -#endif } -#ifdef HAVE_ZLIB +static bool +uncompressed_fill_out_buffer(FILE_T state) +{ + if (buf_read(state, &state->out) < 0) + return false; + return true; +} /* Get next byte from input, or -1 if end or error. * @@ -399,10 +530,18 @@ fast_seek_reset( (state->in.avail == 0 ? -1 : \ (state->in.avail--, *(state->in.next)++))) + +/* + * Gzipped files, using compression from zlib or zlib-ng. + * + * https://tools.ietf.org/html/rfc1952 (RFC 1952) + */ +#ifdef USE_ZLIB_OR_ZLIBNG + /* Get a one-byte integer and return 0 on success and the value in *ret. Otherwise -1 is returned, state->err is set, and *ret is not modified. */ static int -gz_next1(FILE_T state, guint8 *ret) +gz_next1(FILE_T state, uint8_t *ret) { int ch; @@ -423,9 +562,9 @@ gz_next1(FILE_T state, guint8 *ret) in *ret. Otherwise -1 is returned, state->err is set, and *ret is not modified. */ static int -gz_next2(FILE_T state, guint16 *ret) +gz_next2(FILE_T state, uint16_t *ret) { - guint16 val; + uint16_t val; int ch; val = GZ_GETC(); @@ -438,7 +577,7 @@ gz_next2(FILE_T state, guint16 *ret) } return -1; } - val += (guint16)ch << 8; + val += (uint16_t)ch << 8; *ret = val; return 0; } @@ -447,14 +586,14 @@ gz_next2(FILE_T state, guint16 *ret) in *ret. Otherwise -1 is returned, state->err is set, and *ret is not modified. */ static int -gz_next4(FILE_T state, guint32 *ret) +gz_next4(FILE_T state, uint32_t *ret) { - guint32 val; + uint32_t val; int ch; val = GZ_GETC(); val += (unsigned)GZ_GETC() << 8; - val += (guint32)GZ_GETC() << 16; + val += (uint32_t)GZ_GETC() << 16; ch = GZ_GETC(); if (ch == -1) { if (state->err == 0) { @@ -464,7 +603,7 @@ gz_next4(FILE_T state, guint32 *ret) } return -1; } - val += (guint32)ch << 24; + val += (uint32_t)ch << 24; *ret = val; return 0; } @@ -511,7 +650,7 @@ gz_skipzstr(FILE_T state) } static void -zlib_fast_seek_add(FILE_T file, struct zlib_cur_seek_point *point, int bits, gint64 in_pos, gint64 out_pos) +zlib_fast_seek_add(FILE_T file, struct zlib_cur_seek_point *point, int bits, int64_t in_pos, int64_t out_pos) { /* it's for sure after gzip header, so file->fast_seek->len != 0 */ struct fast_seek_point *item = (struct fast_seek_point *)file->fast_seek->pdata[file->fast_seek->len - 1]; @@ -519,7 +658,7 @@ zlib_fast_seek_add(FILE_T file, struct zlib_cur_seek_point *point, int bits, gin #ifndef HAVE_INFLATEPRIME if (bits) return; -#endif +#endif /* HAVE_INFLATEPRIME */ /* Glib has got Balanced Binary Trees (GTree) but I couldn't find a way to do quick search for nearest (and smaller) value to seek (It's what fast_seek_find() do) * Inserting value in middle of sorted array is expensive, so we want to add only in the end. @@ -532,7 +671,7 @@ zlib_fast_seek_add(FILE_T file, struct zlib_cur_seek_point *point, int bits, gin val->compression = ZLIB; #ifdef HAVE_INFLATEPRIME val->data.zlib.bits = bits; -#endif +#endif /* HAVE_INFLATEPRIME */ if (point->pos != 0) { unsigned int left = ZLIB_WINSIZE - point->pos; @@ -554,18 +693,27 @@ zlib_fast_seek_add(FILE_T file, struct zlib_cur_seek_point *point, int bits, gin * * The same applies to strm.total_out. */ - val->data.zlib.adler = (guint32) file->strm.adler; - val->data.zlib.total_out = (guint32) file->strm.total_out; + val->data.zlib.adler = (uint32_t) file->strm.adler; + val->data.zlib.total_out = (uint32_t) file->strm.total_out; g_ptr_array_add(file->fast_seek, val); } } -static void /* gz_decomp */ -zlib_read(FILE_T state, unsigned char *buf, unsigned int count) +/* + * Based on what gz_decomp() in zlib does. + */ +static void +zlib_fill_out_buffer(FILE_T state) { int ret = 0; /* XXX */ - guint32 crc, len; + uint32_t crc, len; +#ifdef HAVE_ZLIBNG + zng_streamp strm = &(state->strm); +#else /* HAVE_ZLIBNG */ z_streamp strm = &(state->strm); +#endif /* HAVE_ZLIBNG */ + unsigned char *buf = state->out.buf; + unsigned int count = state->size << 1; unsigned char *buf2 = buf; unsigned int count2 = count; @@ -589,18 +737,18 @@ zlib_read(FILE_T state, unsigned char *buf, unsigned int count) strm->next_in = state->in.next; /* decompress and handle errors */ #ifdef Z_BLOCK - ret = inflate(strm, Z_BLOCK); -#else - ret = inflate(strm, Z_NO_FLUSH); -#endif + ret = ZLIB_PREFIX(inflate)(strm, Z_BLOCK); +#else /* Z_BLOCK */ + ret = ZLIB_PREFIX(inflate)(strm, Z_NO_FLUSH); +#endif /* Z_BLOCK */ state->in.avail = strm->avail_in; #ifdef z_const DIAG_OFF(cast-qual) state->in.next = (unsigned char *)strm->next_in; DIAG_ON(cast-qual) -#else +#else /* z_const */ state->in.next = strm->next_in; -#endif +#endif /* z_const */ if (ret == Z_STREAM_ERROR) { state->err = WTAP_ERR_DECOMPRESS; state->err_info = strm->msg; @@ -626,14 +774,14 @@ DIAG_ON(cast-qual) * XXX - Z_BUF_ERROR? */ - strm->adler = crc32(strm->adler, buf2, count2 - strm->avail_out); + strm->adler = ZLIB_PREFIX(crc32)(strm->adler, buf2, count2 - strm->avail_out); #ifdef Z_BLOCK if (state->fast_seek_cur != NULL) { struct zlib_cur_seek_point *cur = (struct zlib_cur_seek_point *) state->fast_seek_cur; unsigned int ready = count2 - strm->avail_out; if (ready < ZLIB_WINSIZE) { - guint left = ZLIB_WINSIZE - cur->pos; + unsigned left = ZLIB_WINSIZE - cur->pos; if (ready >= left) { memcpy(cur->window + cur->pos, buf2, left); @@ -660,7 +808,7 @@ DIAG_ON(cast-qual) if (cur->have >= ZLIB_WINSIZE && ret != Z_STREAM_END && (strm->data_type & 128) && !(strm->data_type & 64)) zlib_fast_seek_add(state, cur, (strm->data_type & 7), state->raw_pos - strm->avail_in, state->pos + (count - strm->avail_out)); } -#endif +#endif /* Z_BLOCK */ buf2 = (buf2 + count2 - strm->avail_out); count2 = strm->avail_out; @@ -692,22 +840,21 @@ DIAG_ON(cast-qual) state->fast_seek_cur = NULL; } } -#endif +#endif /* USE_ZLIB_OR_ZLIBNG */ +/* + * Check for a gzip header. + * + * Based on the gzip-specific stuff gz_head() from zlib does. + */ static int -gz_head(FILE_T state) +check_for_zlib_compression(FILE_T state) { - guint already_read; - - /* get some data in the input buffer */ - if (state->in.avail == 0) { - if (fill_in_buffer(state) == -1) - return -1; - if (state->in.avail == 0) - return 0; - } - - /* look for the gzip magic header bytes 31 and 139 */ + /* + * Look for the gzip header. The first two bytes are 31 and 139, + * and if we find it, return success if we support gzip and an + * error if we don't. + */ if (state->in.next[0] == 31) { state->in.avail--; state->in.next++; @@ -729,11 +876,11 @@ gz_head(FILE_T state) * and 139 in the second byte of the file. For now, in * those cases, you lose. */ -#ifdef HAVE_ZLIB - guint8 cm; - guint8 flags; - guint16 len; - guint16 hcrc; +#ifdef USE_ZLIB_OR_ZLIBNG + uint8_t cm; + uint8_t flags; + uint16_t len; + uint16_t hcrc; state->in.avail--; state->in.next++; @@ -815,10 +962,10 @@ gz_head(FILE_T state) } /* set up for decompression */ - inflateReset(&(state->strm)); - state->strm.adler = crc32(0L, Z_NULL, 0); + ZLIB_PREFIX(inflateReset)(&(state->strm)); + state->strm.adler = ZLIB_PREFIX(crc32)(0L, Z_NULL, 0); state->compression = ZLIB; - state->is_compressed = TRUE; + state->is_compressed = true; #ifdef Z_BLOCK if (state->fast_seek) { struct zlib_cur_seek_point *cur = g_new(struct zlib_cur_seek_point,1); @@ -829,12 +976,12 @@ gz_head(FILE_T state) fast_seek_header(state, state->raw_pos - state->in.avail, state->pos, GZIP_AFTER_HEADER); } #endif /* Z_BLOCK */ - return 0; -#else /* HAVE_ZLIB */ + return 1; +#else /* USE_ZLIB_OR_ZLIBNG */ state->err = WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED; state->err_info = "reading gzip-compressed files isn't supported"; return -1; -#endif /* HAVE_ZLIB */ +#endif /* USE_ZLIB_OR_ZLIBNG */ } /* @@ -856,14 +1003,60 @@ gz_head(FILE_T state) state->in.next--; } } -#ifdef HAVE_LIBXZ - /* { 0xFD, '7', 'z', 'X', 'Z', 0x00 } */ - /* FD 37 7A 58 5A 00 */ -#endif + return 0; +} + +/* + * Zstandard compression. + * + * https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md + */ +#ifdef HAVE_ZSTD +static bool +zstd_fill_out_buffer(FILE_T state) +{ + ws_assert(state->out.avail == 0); + + if (state->in.avail == 0 && fill_in_buffer(state) == -1) + return false; + + ZSTD_outBuffer output = {state->out.buf, state->size << 1, 0}; + ZSTD_inBuffer input = {state->in.next, state->in.avail, 0}; + const size_t ret = ZSTD_decompressStream(state->zstd_dctx, &output, &input); + if (ZSTD_isError(ret)) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = ZSTD_getErrorName(ret); + return false; + } + + state->in.next = state->in.next + input.pos; + state->in.avail -= (unsigned)input.pos; + + state->out.next = output.dst; + state->out.avail = (unsigned)output.pos; + + if (ret == 0) { + state->last_compression = state->compression; + state->compression = UNKNOWN; + } + return true; +} +#endif /* HAVE_ZSTD */ + +/* + * Check for a Zstandard header. + */ +static int +check_for_zstd_compression(FILE_T state) +{ + /* + * Look for the Zstandard header, and, if we find it, return + * success if we support Zstandard and an error if we don't. + */ if (state->in.avail >= 4 - && state->in.buf[0] == 0x28 && state->in.buf[1] == 0xb5 - && state->in.buf[2] == 0x2f && state->in.buf[3] == 0xfd) { + && state->in.next[0] == 0x28 && state->in.next[1] == 0xb5 + && state->in.next[2] == 0x2f && state->in.next[3] == 0xfd) { #ifdef HAVE_ZSTD const size_t ret = ZSTD_initDStream(state->zstd_dctx); if (ZSTD_isError(ret)) { @@ -872,23 +1065,290 @@ gz_head(FILE_T state) return -1; } + fast_seek_header(state, state->raw_pos - state->in.avail, state->pos, ZSTD); state->compression = ZSTD; - state->is_compressed = TRUE; - return 0; -#else + state->is_compressed = true; + return 1; +#else /* HAVE_ZSTD */ state->err = WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED; state->err_info = "reading zstd-compressed files isn't supported"; return -1; +#endif /* HAVE_ZSTD */ + } + return 0; +} + +/* + * lz4 compression. + * + * https://github.com/lz4/lz4/blob/dev/doc/lz4_Frame_format.md + */ +#ifdef USE_LZ4 +static void +lz4_fast_seek_add(FILE_T file, struct zlib_cur_seek_point *point _U_, int64_t in_pos, int64_t out_pos) +{ + if (!file->fast_seek) { + return; + } + + struct fast_seek_point *item = NULL; + + if (file->fast_seek->len != 0) + item = (struct fast_seek_point *)file->fast_seek->pdata[file->fast_seek->len - 1]; + + /* As of Glib 2.68 GTree has g_tree_upper_bound, or we could use a + * wmem_tree. However, since our initial read is usually sequential + * only adding seek points at the end of the ptr array is fast and fine. + */ + + /* don't bother adding jump points between very small blocks (min SPAN) */ + if (!item || item->out + SPAN < out_pos) { + struct fast_seek_point *val = g_new(struct fast_seek_point,1); + val->in = in_pos; + val->out = out_pos; + val->compression = LZ4; +#if 0 + if (point->pos != 0) { + unsigned int left = LZ4_WINSIZE - point->pos; + + memcpy(val->data.zlib.window, point->window + point->pos, left); + memcpy(val->data.zlib.window + left, point->window, point->pos); + } else + memcpy(val->data.zlib.window, point->window, ZZ4_WINSIZE); #endif + + val->data.lz4.lz4_info = file->lz4_info; + memcpy(val->data.lz4.lz4_hdr, file->lz4_hdr, LZ4F_HEADER_SIZE_MAX); + g_ptr_array_add(file->fast_seek, val); + } +} + +static bool +lz4_fill_out_buffer(FILE_T state) +{ + ws_assert(state->out.avail == 0); + + if (state->in.avail == 0 && fill_in_buffer(state) == -1) + return false; + + /* + * We should be at the start of a block. First, determine the size of + * the block. We tell LZ4F_decompress that there's no room to put + * the decompressed block; this will make it read the block size + * header and stop, returning the size of the block (plus next + * header) as hint of how much input to hand next. + */ + + size_t outBufSize = 0; // Zero so we don't actually consume the block + size_t inBufSize; + + size_t compressedSize = 0; + + do { + /* get more input for decompress() */ + if (state->in.avail == 0 && fill_in_buffer(state) == -1) + break; + if (state->eof) { + state->err = WTAP_ERR_SHORT_READ; + state->err_info = NULL; + break; + } + + inBufSize = state->in.avail; + compressedSize = LZ4F_decompress(state->lz4_dctx, state->out.buf, &outBufSize, state->in.next, &inBufSize, NULL); + + if (LZ4F_isError(compressedSize)) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = LZ4F_getErrorName(compressedSize); + return false; + } + + state->in.next += inBufSize; + state->in.avail -= inBufSize; + + if (compressedSize == 0) { + /* End of Frame */ + state->last_compression = state->compression; + state->compression = UNKNOWN; + return true; + } + + ws_assert(outBufSize == 0); + + } while (compressedSize < LZ4F_BLOCK_HEADER_SIZE); + + /* + * We don't want to add a fast seek point for the end of frame, + * especially if there's another frame or other stream after it, + * which would have the same out position. So add it after the + * reading the block size - but point to where the block size + * is so that we'll fast seek to the block size again. + */ + if (state->lz4_info.blockMode == LZ4F_blockIndependent) { + /* + * XXX - If state->lz4_info.blockMode == LZ4F_blockLinked, it doesn't + * seem like the LZ4 Frame API can handle this, we would need to use + * the low level Block API and pass the last 64KiB window of data to + * LZ4_setStreamDecode and use LZ4_decompress_safe_continue (similar + * to gzip). So for now we can't do fast seek with it (we do add one + * header at the frame beginning so that concatenated frames and other + * decompression streams work.) + */ + lz4_fast_seek_add(state, NULL, state->raw_pos - state->in.avail - LZ4F_BLOCK_HEADER_SIZE, state->pos); + } + + // Now actually read the entire next block - but not the next header + compressedSize -= LZ4F_BLOCK_HEADER_SIZE; + state->out.next = state->out.buf; + + if (compressedSize > state->size) { + /* + * What is this? Either bogus, or some new variant of LZ4 Frames with + * a larger block size we don't support. We could have a buffer + * overrun if we try to process it. + * + * TODO - We could realloc here. + */ + state->err = WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED; + state->err_info = "lz4 compressed block size too large"; + return false; + } + + size_t ret; + do { + /* get more input for decompress() */ + if (state->in.avail == 0 && fill_in_buffer(state) == -1) + break; + if (state->eof) { + state->err = WTAP_ERR_SHORT_READ; + state->err_info = NULL; + break; + } + + outBufSize = (state->size << 1) - offset_in_buffer(&state->out); + inBufSize = MIN(state->in.avail, compressedSize); + ret = LZ4F_decompress(state->lz4_dctx, state->out.next, &outBufSize, state->in.next, &inBufSize, NULL); + + if (LZ4F_isError(ret)) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = LZ4F_getErrorName(ret); + return false; + } + state->in.next += inBufSize; + state->in.avail -= inBufSize; + compressedSize -= inBufSize; + + state->out.next += outBufSize; + state->out.avail += outBufSize; + } while (compressedSize != 0); + + state->out.next = state->out.buf; + +#if 0 + /* This is an alternative implementation using the lower-level + * LZ4 Block API. Doing something like this might be necessary + * to handle linked blocks, because the Frame API doesn't have + * a method to reset the dictionary / window. + */ + int outBufSize = state->size << 1; + uint32_t compressedSize; + if (gz_next4(state, &compressedSize) == -1) { + return false; + } + if (compressedSize == 0) { + /* EndMark */ + if (state->lz4_info.contentChecksumFlag) { + uint32_t xxHash; + if (gz_next4(state, &xxHash) == -1) { + return false; + } + /* XXX - check hash? */ + } + state->last_compression = state->compression; + state->compression = UNKNOWN; + return true; + } + bool uncompressed = compressedSize >> 31; + compressedSize &= 0x7FFFFFFF; + if (compressedSize > state->size) { + // TODO - we could realloc here + state->err = WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED; + state->err_info = "lz4 compressed block size too large"; + return false; } + /* + * We have to read an entire block as we're using the low-level + * Block API instead of the LZ4 Frame API. + */ + if (compressedSize > (unsigned)state->in.avail) { + memmove(state->in.buf, state->in.next, state->in.avail); + state->in.next = state->in.buf; + while ((unsigned)state->in.avail < compressedSize) { + if (state->eof) { + state->err = WTAP_ERR_SHORT_READ; + state->err_info = NULL; + return false; + } + if (fill_in_buffer(state) == -1) { + return false; + } + } + } + + int decompressedSize; + if (uncompressed) { + memcpy(state->out.buf, state->in.buf, compressedSize); + decompressedSize = compressedSize; + } else { + decompressedSize = LZ4_decompress_safe(state->in.next, state->out.buf, compressedSize, outBufSize); + //const size_t ret = LZ4F_decompress(state->lz4_dctx, state->out.buf, &outBufSize, state->in.next, &inBufSize, NULL); + if (LZ4F_isError(decompressedSize)) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = LZ4F_getErrorName(decompressedSize); + return false; + } + } + + /* + * We assume LZ4F_decompress() will not set inBufSize to a + * value > state->in.avail. + */ + state->in.next += compressedSize; + state->in.avail -= compressedSize; + + state->out.next = state->out.buf; + state->out.avail = (unsigned)decompressedSize; + + if (state->lz4_info.blockChecksumFlag == LZ4F_blockChecksumEnabled) { + uint32_t xxHash; + if (gz_next4(state, &xxHash) == -1) { + return false; + } + /* XXX - check hash? */ + } +#endif + return true; +} +#endif /* USE_LZ4 */ + +/* + * Check for an lz4 header. + */ +static int +check_for_lz4_compression(FILE_T state) +{ + /* + * Look for the lz4 header, and, if we find it, return success + * if we support lz4 and an error if we don't. + */ if (state->in.avail >= 4 - && state->in.buf[0] == 0x04 && state->in.buf[1] == 0x22 - && state->in.buf[2] == 0x4d && state->in.buf[3] == 0x18) { + && state->in.next[0] == 0x04 && state->in.next[1] == 0x22 + && state->in.next[2] == 0x4d && state->in.next[3] == 0x18) { #ifdef USE_LZ4 #if LZ4_VERSION_NUMBER >= 10800 LZ4F_resetDecompressionContext(state->lz4_dctx); -#else +#else /* LZ4_VERSION_NUMBER >= 10800 */ LZ4F_freeDecompressionContext(state->lz4_dctx); const LZ4F_errorCode_t ret = LZ4F_createDecompressionContext(&state->lz4_dctx, LZ4F_VERSION); if (LZ4F_isError(ret)) { @@ -896,19 +1356,157 @@ gz_head(FILE_T state) state->err_info = LZ4F_getErrorName(ret); return -1; } -#endif +#endif /* LZ4_VERSION_NUMBER >= 10800 */ + size_t headerSize = LZ4F_HEADER_SIZE_MAX; +#if LZ4_VERSION_NUMBER >= 10903 + /* + * In 1.9.3+ we can handle a silly edge case of a tiny valid + * frame at the end of a file that is smaller than the maximum + * header size. (lz4frame.h added the function in 1.9.0, but + * only for the static library; it wasn't exported until 1.9.3) + */ + while (state->in.avail < LZ4F_MIN_SIZE_TO_KNOW_HEADER_LENGTH) { + if (fill_in_buffer(state) == -1) { + return -1; + } + if (state->eof) { + state->err = WTAP_ERR_SHORT_READ; + state->err_info = NULL; + return 0; + } + } + headerSize = LZ4F_headerSize(state->in.next, state->in.avail); + if (LZ4F_isError(headerSize)) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = LZ4F_getErrorName(headerSize); + return -1; + } +#endif /* LZ4_VERSION_NUMBER >= 10903 */ + while (state->in.avail < headerSize) { + if (fill_in_buffer(state) == -1) { + return -1; + } + if (state->eof) { + state->err = WTAP_ERR_SHORT_READ; + state->err_info = NULL; + return 0; + } + } + size_t inBufSize = state->in.avail; + memcpy(state->lz4_hdr, state->in.next, headerSize); + const LZ4F_errorCode_t err = LZ4F_getFrameInfo(state->lz4_dctx, &state->lz4_info, state->in.next, &inBufSize); + if (LZ4F_isError(err)) { + state->err = WTAP_ERR_DECOMPRESS; + state->err_info = LZ4F_getErrorName(err); + return -1; + } + + /* + * XXX - We could check state->lz4_info.blockSizeID here, and + * only realloc the buffers to a larger value if the max + * block size is bigger than state->size. Also we could fail + * on unknown values? + */ + state->in.avail -= inBufSize; + state->in.next += inBufSize; + + fast_seek_header(state, state->raw_pos - state->in.avail, state->pos, LZ4); state->compression = LZ4; - state->is_compressed = TRUE; - return 0; -#else + state->is_compressed = true; + return 1; +#else /* USE_LZ4 */ state->err = WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED; state->err_info = "reading lz4-compressed files isn't supported"; return -1; -#endif +#endif /* USE_LZ4 */ + } + return 0; +} + +typedef int (*compression_type_test)(FILE_T); + +static compression_type_test const compression_type_tests[] = { + check_for_zlib_compression, + check_for_zstd_compression, + check_for_lz4_compression, +}; + +/* + * Used when we haven't yet determined whether we have a compressed file + * and, if we do, what sort of compressed file it is. + * + * Based on the non-gzip-specific stuff that gz_head() from zlib does. + */ +static int +check_for_compression(FILE_T state) +{ + /* + * If this isn't the first frame / compressed stream, ensure that + * we're starting at the beginning of the buffer. This shouldn't + * get called much. + * + * This is to avoid edge cases where a previous frame finished but + * state->in.next is close to the end of the buffer so there isn't + * much room to put the start of the next frame. + * This also lets us put back bytes if things go wrong. + */ + if (state->in.next != state->in.buf) { + memmove(state->in.buf, state->in.next, state->in.avail); + state->in.next = state->in.buf; } + /* get some data in the input buffer */ + if (state->in.avail == 0) { + if (fill_in_buffer(state) == -1) + return -1; + if (state->in.avail == 0) + return 0; + } + + /* + * Check for the compression types we support. + */ + for (size_t i = 0; i < G_N_ELEMENTS(compression_type_tests); i++) { + int ret; + + ret = compression_type_tests[i](state); + if (ret == -1) + return -1; /* error */ + if (ret == 1) + return 0; /* found it */ + } + + /* + * Some other compressed file formats we might want to support: + * + * XZ format: + * https://tukaani.org/xz/ + * https://github.com/tukaani-project/xz + * https://github.com/tukaani-project/xz/blob/master/doc/xz-file-format.txt + * + * Bzip2 format: + * https://www.sourceware.org/bzip2/ + * https://gitlab.com/bzip2/bzip2/ + * https://github.com/dsnet/compress/blob/master/doc/bzip2-format.pdf + * (GitHub won't render it; download and open it) + * + * Lzip format: + * https://www.nongnu.org/lzip/ + */ + + /* + * We didn't see anything that looks like a header for any type of + * compressed file that we support, so just do uncompressed I/O. + * + * XXX - This fast seek data is for the case where a compressed stream + * ends and is followed by an uncompressed portion. It only works if + * the uncompressed portion is at the end, as we don't constantly scan + * for magic bytes in the middle of uncompressed data. (Concatenated + * compressed streams _do_ work, even streams of different compression types.) + */ if (state->fast_seek) - fast_seek_header(state, state->raw_pos - state->in.avail - state->out.avail, state->pos, UNCOMPRESSED); + fast_seek_header(state, state->raw_pos - state->in.avail, state->pos, UNCOMPRESSED); + /* doing raw i/o, save start of raw data for seeking, copy any leftover input to output -- this assumes that the output buffer is larger than @@ -917,10 +1515,9 @@ gz_head(FILE_T state) state->out.next = state->out.buf; /* not a compressed file -- copy everything we've read into the input buffer to the output buffer and fall to raw i/o */ - already_read = bytes_in_buffer(&state->in); - if (already_read != 0) { - memcpy(state->out.buf, state->in.buf, already_read); - state->out.avail = already_read; + if (state->in.avail) { + memcpy(state->out.buf, state->in.next, state->in.avail); + state->out.avail = state->in.avail; /* Now discard everything in the input buffer */ buf_reset(&state->in); @@ -929,98 +1526,77 @@ gz_head(FILE_T state) return 0; } -static int /* gz_make */ +/* + * Based on what gz_make() in zlib does. + */ +static int fill_out_buffer(FILE_T state) { - if (state->compression == UNKNOWN) { /* look for compression header */ - if (gz_head(state) == -1) + if (state->compression == UNKNOWN) { + /* + * We don't yet know whether the file is compressed, + * so check for a compressed-file header. + */ + if (check_for_compression(state) == -1) return -1; - if (state->out.avail != 0) /* got some data from gz_head() */ + if (state->out.avail != 0) /* got some data from check_for_compression() */ return 0; } - if (state->compression == UNCOMPRESSED) { /* straight copy */ - if (buf_read(state, &state->out) < 0) - return -1; - } -#ifdef HAVE_ZLIB - else if (state->compression == ZLIB) { /* decompress */ - zlib_read(state, state->out.buf, state->size << 1); - } -#endif -#ifdef HAVE_ZSTD - else if (state->compression == ZSTD) { - ws_assert(state->out.avail == 0); - if (state->in.avail == 0 && fill_in_buffer(state) == -1) - return -1; + /* + * We got no data from check_for_compression(), or we didn't call + * it as we already know the compression type, so read some more + * data. + */ + switch (state->compression) { - ZSTD_outBuffer output = {state->out.buf, state->size << 1, 0}; - ZSTD_inBuffer input = {state->in.next, state->in.avail, 0}; - const size_t ret = ZSTD_decompressStream(state->zstd_dctx, &output, &input); - if (ZSTD_isError(ret)) { - state->err = WTAP_ERR_DECOMPRESS; - state->err_info = ZSTD_getErrorName(ret); + case UNCOMPRESSED: + /* straight copy */ + if (!uncompressed_fill_out_buffer(state)) return -1; - } - - state->in.next = state->in.next + input.pos; - state->in.avail -= (guint)input.pos; + break; - state->out.next = output.dst; - state->out.avail = (guint)output.pos; - - if (ret == 0) { - state->last_compression = state->compression; - state->compression = UNKNOWN; - } - } -#endif -#ifdef USE_LZ4 - else if (state->compression == LZ4) { - ws_assert(state->out.avail == 0); +#ifdef USE_ZLIB_OR_ZLIBNG + case ZLIB: + /* zlib (gzip) decompress */ + zlib_fill_out_buffer(state); + break; +#endif /* USE_ZLIB_OR_ZLIBNG */ - if (state->in.avail == 0 && fill_in_buffer(state) == -1) +#ifdef HAVE_ZSTD + case ZSTD: + /* zstd decompress */ + if (!zstd_fill_out_buffer(state)) return -1; + break; +#endif /* HAVE_ZSTD */ - size_t outBufSize = state->size << 1; - size_t inBufSize = state->in.avail; - const size_t ret = LZ4F_decompress(state->lz4_dctx, state->out.buf, &outBufSize, state->in.next, &inBufSize, NULL); - if (LZ4F_isError(ret)) { - state->err = WTAP_ERR_DECOMPRESS; - state->err_info = LZ4F_getErrorName(ret); +#ifdef USE_LZ4 + case LZ4: + /* lz4 decompress */ + if (!lz4_fill_out_buffer(state)) return -1; - } - - /* - * We assume LZ4F_decompress() will not set inBufSize to a - * value > state->in.avail. - */ - state->in.next = state->in.next + inBufSize; - state->in.avail -= (guint)inBufSize; - - state->out.next = state->out.buf; - state->out.avail = (guint)outBufSize; + break; +#endif /* USE_LZ4 */ - if (ret == 0) { - state->last_compression = state->compression; - state->compression = UNKNOWN; - } + default: + /* Unknown compression type; keep reading */ + break; } -#endif return 0; } static int -gz_skip(FILE_T state, gint64 len) +gz_skip(FILE_T state, int64_t len) { - guint n; + unsigned n; /* skip over len bytes or reach end-of-file, whichever comes first */ while (len) if (state->out.avail != 0) { /* We have stuff in the output buffer; skip over it. */ - n = (gint64)state->out.avail > len ? (unsigned)len : state->out.avail; + n = (int64_t)state->out.avail > len ? (unsigned)len : state->out.avail; state->out.avail -= n; state->out.next += n; state->pos += n; @@ -1050,10 +1626,10 @@ static void gz_reset(FILE_T state) { buf_reset(&state->out); /* no output data available */ - state->eof = FALSE; /* not at end of file */ + state->eof = false; /* not at end of file */ state->compression = UNKNOWN; /* look for compression header */ - state->seek_pending = FALSE; /* no seek request pending */ + state->seek_pending = false; /* no seek request pending */ state->err = 0; /* clear error */ state->err_info = NULL; state->pos = 0; /* no uncompressed data yet */ @@ -1083,15 +1659,15 @@ file_fdopen(int fd) */ #ifdef _STATBUF_ST_BLKSIZE ws_statb64 st; -#endif +#endif /* _STATBUF_ST_BLKSIZE */ #ifdef HAVE_ZSTD size_t zstd_buf_size; -#endif - guint want = GZBUFSIZE; +#endif /* HAVE_ZSTD */ + unsigned want = GZBUFSIZE; FILE_T state; #ifdef USE_LZ4 size_t ret; -#endif +#endif /* USE_LZ4 */ if (fd == -1) return NULL; @@ -1108,7 +1684,7 @@ file_fdopen(int fd) state->fd = fd; /* we don't yet know whether it's compressed */ - state->is_compressed = FALSE; + state->is_compressed = false; state->last_compression = UNKNOWN; /* save the current position for rewinding (only if reading) */ @@ -1130,7 +1706,7 @@ file_fdopen(int fd) * Yes, st_blksize can be bigger than an int; apparently, * it's a long on LP64 Linux, for example. * - * If the value is too big to fit into a guint, + * If the value is too big to fit into a unsigned, * just use the maximum read buffer size. * * On top of that, the Single UNIX Speification says that @@ -1152,29 +1728,39 @@ file_fdopen(int fd) * (We only support 32-bit and 64-bit 2's-complement platforms.) */ if (st.st_blksize <= (long)MAX_READ_BUF_SIZE) - want = (guint)st.st_blksize; + want = (unsigned)st.st_blksize; else want = MAX_READ_BUF_SIZE; /* XXX, verify result? */ } -#endif +#endif /* _STATBUF_ST_BLKSIZE */ #ifdef HAVE_ZSTD /* we should have separate input and output buf sizes */ zstd_buf_size = ZSTD_DStreamInSize(); if (zstd_buf_size > want) { if (zstd_buf_size <= MAX_READ_BUF_SIZE) - want = (guint)zstd_buf_size; + want = (unsigned)zstd_buf_size; else want = MAX_READ_BUF_SIZE; } zstd_buf_size = ZSTD_DStreamOutSize(); if (zstd_buf_size > want) { if (zstd_buf_size <= MAX_READ_BUF_SIZE) - want = (guint)zstd_buf_size; + want = (unsigned)zstd_buf_size; else want = MAX_READ_BUF_SIZE; } -#endif +#endif /* HAVE_ZSTD */ +#ifdef USE_LZ4 + if (LZ4BUFSIZE > want) { + if (LZ4BUFSIZE <= MAX_READ_BUF_SIZE) { + want = LZ4BUFSIZE; + } else { + goto err; + } + } +#endif /* USE_LZ4 */ + /* allocate buffers */ state->in.buf = (unsigned char *)g_try_malloc(want); state->in.next = state->in.buf; @@ -1187,48 +1773,48 @@ file_fdopen(int fd) goto err; } -#ifdef HAVE_ZLIB +#ifdef USE_ZLIB_OR_ZLIBNG /* allocate inflate memory */ state->strm.zalloc = Z_NULL; state->strm.zfree = Z_NULL; state->strm.opaque = Z_NULL; state->strm.avail_in = 0; state->strm.next_in = Z_NULL; - if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */ + if (ZLIB_PREFIX(inflateInit2)(&(state->strm), -15) != Z_OK) { /* raw inflate */ goto err; } /* for now, assume we should check the crc */ - state->dont_check_crc = FALSE; -#endif + state->dont_check_crc = false; +#endif /* USE_ZLIB_OR_ZLIBNG */ #ifdef HAVE_ZSTD state->zstd_dctx = ZSTD_createDCtx(); if (state->zstd_dctx == NULL) { goto err; } -#endif +#endif /* HAVE_ZSTD */ #ifdef USE_LZ4 ret = LZ4F_createDecompressionContext(&state->lz4_dctx, LZ4F_VERSION); if (LZ4F_isError(ret)) { goto err; } -#endif +#endif /* USE_LZ4 */ /* return stream */ return state; err: -#ifdef HAVE_ZLIB - inflateEnd(&state->strm); -#endif +#ifdef USE_ZLIB_OR_ZLIBNG + ZLIB_PREFIX(inflateEnd)(&state->strm); +#endif /* USE_ZLIB_OR_ZLIBNG */ #ifdef HAVE_ZSTD ZSTD_freeDCtx(state->zstd_dctx); -#endif +#endif /* HAVE_ZSTD */ #ifdef USE_LZ4 LZ4F_freeDecompressionContext(state->lz4_dctx); -#endif +#endif /* USE_LZ4 */ g_free(state->out.buf); g_free(state->in.buf); g_free(state); @@ -1241,9 +1827,9 @@ file_open(const char *path) { int fd; FILE_T ft; -#ifdef HAVE_ZLIB +#ifdef USE_ZLIB_OR_ZLIBNG const char *suffixp; -#endif +#endif /* USE_ZLIB_OR_ZLIBNG */ /* open file and do correct filename conversions. @@ -1264,7 +1850,7 @@ file_open(const char *path) return NULL; } -#ifdef HAVE_ZLIB +#ifdef USE_ZLIB_OR_ZLIBNG /* * If this file's name ends in ".caz", it's probably a compressed * Windows Sniffer file. The compression is gzip, but if we @@ -1281,24 +1867,24 @@ file_open(const char *path) suffixp = strrchr(path, '.'); if (suffixp != NULL) { if (g_ascii_strcasecmp(suffixp, ".caz") == 0) - ft->dont_check_crc = TRUE; + ft->dont_check_crc = true; } -#endif +#endif /* USE_ZLIB_OR_ZLIBNG */ return ft; } void -file_set_random_access(FILE_T stream, gboolean random_flag _U_, GPtrArray *seek) +file_set_random_access(FILE_T stream, bool random_flag _U_, GPtrArray *seek) { stream->fast_seek = seek; } -gint64 -file_seek(FILE_T file, gint64 offset, int whence, int *err) +int64_t +file_seek(FILE_T file, int64_t offset, int whence, int *err) { struct fast_seek_point *here; - guint n; + unsigned n; if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) { ws_assert_not_reached(); @@ -1318,7 +1904,7 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) XXX - we don't actually use this yet, but, for uncompressed files, we could optimize it, if desired, by directly using ws_lseek64(). */ - if (gz_skip(file, G_MAXINT64) == -1) { + if (gz_skip(file, INT64_MAX) == -1) { *err = file->err; return -1; } @@ -1334,7 +1920,7 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) which we're skipping; update the offset to include that. */ offset += file->skip; } - file->seek_pending = FALSE; + file->seek_pending = false; /* * Are we moving at all? @@ -1370,7 +1956,7 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) * not at all likely to see files big enough to ever * see a negative offset that large. */ - guint adjustment = (unsigned)(-offset); + unsigned adjustment = (unsigned)(-offset); file->out.avail += adjustment; file->out.next -= adjustment; @@ -1389,9 +1975,9 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) * Yes. Adjust appropriately. * * offset is < an unsigned and thus fits in an unsigned, - * so we can cast it to guint safely. + * so we can cast it to unsigned safely. */ - file->out.avail -= (guint)offset; + file->out.avail -= (unsigned)offset; file->out.next += offset; file->pos += offset; return file->pos; @@ -1400,15 +1986,21 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) /* * We're not seeking within the buffer. Do we have "fast seek" data - * for the location to which we will be seeking, and is the offset - * outside the span for compressed files or is this an uncompressed - * file? + * for the location to which we will be seeking, and are we either + * seeking backwards or is the fast seek point past what is in the + * buffer? (We don't want to "fast seek" backwards to a point that + * we've already read and buffered if we're actually seeking forwards.) * - * XXX, profile + * It might in certain cases be faster to continue reading linearly + * foward rather than jump to the fast seek point if the distance + * to the fast seek point is small, but we might only be able to do that + * if the compression context doesn't change (which for LZ4 includes if + * we jump to a LZ4 with different options.) + * XXX - profile different buffer and SPAN sizes */ if ((here = fast_seek_find(file, file->pos + offset)) && - (offset < 0 || offset > SPAN || here->compression == UNCOMPRESSED)) { - gint64 off, off2; + (offset < 0 || here->out >= file->pos + file->out.avail)) { + int64_t off, off2; /* * Yes. Use that data to do the seek. @@ -1416,22 +2008,43 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) * has been called on this file, which should never be the case * for a pipe. */ -#ifdef HAVE_ZLIB - if (here->compression == ZLIB) { + switch (here->compression) { + +#ifdef USE_ZLIB_OR_ZLIBNG + case ZLIB: #ifdef HAVE_INFLATEPRIME off = here->in - (here->data.zlib.bits ? 1 : 0); -#else +#else /* HAVE_INFLATEPRIME */ off = here->in; -#endif +#endif /* HAVE_INFLATEPRIME */ off2 = here->out; - } else if (here->compression == GZIP_AFTER_HEADER) { + break; + + case GZIP_AFTER_HEADER: off = here->in; off2 = here->out; - } else -#endif - { + break; +#endif /* USE_ZLIB_OR_ZLIBNG */ + +#ifdef USE_LZ4 + case LZ4: + ws_debug("fast seek lz4"); + off = here->in; + off2 = here->out; + break; +#endif /* USE_LZ4 */ + + case UNCOMPRESSED: + /* In an uncompressed portion, seek directly to the offset */ off2 = (file->pos + offset); off = here->in + (off2 - here->out); + break; + + default: + /* Otherwise, seek to the fast seek point to do any needed setup. */ + off = here->in; + off2 = here->out; + break; } if (ws_lseek64(file->fd, off, SEEK_SET) == -1) { @@ -1442,17 +2055,18 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) file->raw_pos = off; buf_reset(&file->out); - file->eof = FALSE; - file->seek_pending = FALSE; + file->eof = false; + file->seek_pending = false; file->err = 0; file->err_info = NULL; buf_reset(&file->in); -#ifdef HAVE_ZLIB - if (here->compression == ZLIB) { - z_stream *strm = &file->strm; + switch (here->compression) { - inflateReset(strm); +#ifdef USE_ZLIB_OR_ZLIBNG + case ZLIB: { + zlib_stream*strm = &file->strm; + ZLIB_PREFIX(inflateReset)(strm); strm->adler = here->data.zlib.adler; strm->total_out = here->data.zlib.total_out; #ifdef HAVE_INFLATEPRIME @@ -1468,30 +2082,85 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) *err = state->err; return -1; } - (void)inflatePrime(strm, here->data.zlib.bits, ret >> (8 - here->data.zlib.bits)); + (void)ZLIB_PREFIX(inflatePrime)(strm, here->data.zlib.bits, ret >> (8 - here->data.zlib.bits)); } -#endif - (void)inflateSetDictionary(strm, here->data.zlib.window, ZLIB_WINSIZE); +#endif /* HAVE_INFLATEPRIME */ + (void)ZLIB_PREFIX(inflateSetDictionary)(strm, here->data.zlib.window, ZLIB_WINSIZE); file->compression = ZLIB; - } else if (here->compression == GZIP_AFTER_HEADER) { - z_stream *strm = &file->strm; + break; + } - inflateReset(strm); - strm->adler = crc32(0L, Z_NULL, 0); + case GZIP_AFTER_HEADER: { + zlib_stream* strm = &file->strm; + ZLIB_PREFIX(inflateReset)(strm); + strm->adler = ZLIB_PREFIX(crc32)(0L, Z_NULL, 0); file->compression = ZLIB; - } else -#endif + break; + } +#endif /* USE_ZLIB_OR_ZLIBNG */ + +#ifdef USE_LZ4 + case LZ4: + /* If the frame information seems to have changed (i.e., we fast + * seeked into a different frame that also has different flags + * and options), then reset the context and re-read it. + * Unfortunately the API doesn't provide a method to set the + * context options explicitly based on an already read + * LZ4F_frameInfo_t. + */ + if (memcmp(&file->lz4_info, &here->data.lz4.lz4_info, sizeof(LZ4F_frameInfo_t)) != 0) { +#if LZ4_VERSION_NUMBER >= 10800 + LZ4F_resetDecompressionContext(file->lz4_dctx); +#else /* LZ4_VERSION_NUMBER >= 10800 */ + LZ4F_freeDecompressionContext(file->lz4_dctx); + const LZ4F_errorCode_t ret = LZ4F_createDecompressionContext(&file->lz4_dctx, LZ4F_VERSION); + if (LZ4F_isError(ret)) { + file->err = WTAP_ERR_INTERNAL; + file->err_info = LZ4F_getErrorName(ret); + return -1; + } +#endif /* LZ4_VERSION_NUMBER >= 10800 */ + size_t hdr_size = LZ4F_HEADER_SIZE_MAX; + const LZ4F_errorCode_t frame_err = LZ4F_getFrameInfo(file->lz4_dctx, &file->lz4_info, here->data.lz4.lz4_hdr, &hdr_size); + if (LZ4F_isError(frame_err)) { + file->err = WTAP_ERR_DECOMPRESS; + file->err_info = LZ4F_getErrorName(frame_err); + return -1; + } + } + file->lz4_info = here->data.lz4.lz4_info; + file->compression = LZ4; + break; +#endif /* USE_LZ4 */ + +#ifdef HAVE_ZSTD + case ZSTD: + { + const size_t ret = ZSTD_initDStream(file->zstd_dctx); + if (ZSTD_isError(ret)) { + file->err = WTAP_ERR_DECOMPRESS; + file->err_info = ZSTD_getErrorName(ret); + return -1; + } + file->compression = ZSTD; + break; + } +#endif /* HAVE_ZSTD */ + + default: file->compression = here->compression; + break; + } offset = (file->pos + offset) - off2; file->pos = off2; - /* g_print("OK! %ld\n", offset); */ + ws_debug("Fast seek OK! %"PRId64, offset); if (offset) { /* Don't skip forward yet, wait until we want to read from the file; that way, if we do multiple seeks in a row, all involving forward skips, they will be combined. */ - file->seek_pending = TRUE; + file->seek_pending = true; file->skip = offset; } return file->pos + offset; @@ -1520,8 +2189,8 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) } file->raw_pos += (offset - file->out.avail); buf_reset(&file->out); - file->eof = FALSE; - file->seek_pending = FALSE; + file->eof = false; + file->seek_pending = false; file->err = 0; file->err_info = NULL; buf_reset(&file->in); @@ -1563,7 +2232,7 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) * * Skip what's in output buffer (one less gzgetc() check). */ - n = (gint64)file->out.avail > offset ? (unsigned)offset : file->out.avail; + n = (int64_t)file->out.avail > offset ? (unsigned)offset : file->out.avail; file->out.avail -= n; file->out.next += n; file->pos += n; @@ -1574,20 +2243,20 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) /* Don't skip forward yet, wait until we want to read from the file; that way, if we do multiple seeks in a row, all involving forward skips, they will be combined. */ - file->seek_pending = TRUE; + file->seek_pending = true; file->skip = offset; } return file->pos + offset; } -gint64 +int64_t file_tell(FILE_T stream) { /* return position */ return stream->pos + (stream->seek_pending ? stream->skip : 0); } -gint64 +int64_t file_tell_raw(FILE_T stream) { return stream->raw_pos; @@ -1604,7 +2273,7 @@ file_fstat(FILE_T stream, ws_statb64 *statb, int *err) return 0; } -gboolean +bool file_iscompressed(FILE_T stream) { return stream->is_compressed; @@ -1645,7 +2314,7 @@ file_get_compression_type(FILE_T stream) int file_read(void *buf, unsigned int len, FILE_T file) { - guint got, n; + unsigned got, n; /* if len is zero, avoid unnecessary operations */ if (len == 0) @@ -1653,7 +2322,7 @@ file_read(void *buf, unsigned int len, FILE_T file) /* process a skip request */ if (file->seek_pending) { - file->seek_pending = FALSE; + file->seek_pending = false; if (gz_skip(file, file->skip) == -1) return -1; } @@ -1722,7 +2391,7 @@ file_peekc(FILE_T file) /* process a skip request */ if (file->seek_pending) { - file->seek_pending = FALSE; + file->seek_pending = false; if (gz_skip(file, file->skip) == -1) return -1; } @@ -1778,7 +2447,7 @@ file_getc(FILE_T file) char * file_getsp(char *buf, int len, FILE_T file) { - guint left, n; + unsigned left, n; char *str; unsigned char *eol; @@ -1792,7 +2461,7 @@ file_getsp(char *buf, int len, FILE_T file) /* process a skip request */ if (file->seek_pending) { - file->seek_pending = FALSE; + file->seek_pending = false; if (gz_skip(file, file->skip) == -1) return NULL; } @@ -1864,7 +2533,7 @@ file_eof(FILE_T file) * I/O stream. Also returns an error string for some errors. */ int -file_error(FILE_T fh, gchar **err_info) +file_error(FILE_T fh, char **err_info) { if (fh->err!=0 && err_info) { /* g_strdup() returns NULL for NULL argument */ @@ -1879,7 +2548,7 @@ file_clearerr(FILE_T stream) /* clear error and end-of-file */ stream->err = 0; stream->err_info = NULL; - stream->eof = FALSE; + stream->eof = false; } void @@ -1890,15 +2559,15 @@ file_fdclose(FILE_T file) file->fd = -1; } -gboolean +bool file_fdreopen(FILE_T file, const char *path) { int fd; if ((fd = ws_open(path, O_RDONLY|O_BINARY, 0000)) == -1) - return FALSE; + return false; file->fd = fd; - return TRUE; + return true; } void @@ -1908,15 +2577,15 @@ file_close(FILE_T file) /* free memory and close file */ if (file->size) { -#ifdef HAVE_ZLIB - inflateEnd(&(file->strm)); -#endif +#ifdef USE_ZLIB_OR_ZLIBNG + ZLIB_PREFIX(inflateEnd)(&(file->strm)); +#endif /* USE_ZLIB_OR_ZLIBNG */ #ifdef HAVE_ZSTD ZSTD_freeDCtx(file->zstd_dctx); -#endif +#endif /* HAVE_ZSTD */ #ifdef USE_LZ4 LZ4F_freeDecompressionContext(file->lz4_dctx); -#endif +#endif /* USE_LZ4 */ g_free(file->out.buf); g_free(file->in.buf); } @@ -1933,13 +2602,13 @@ file_close(FILE_T file) ws_close(fd); } -#ifdef HAVE_ZLIB +#ifdef USE_ZLIB_OR_ZLIBNG /* internal gzip file state data structure for writing */ struct wtap_writer { int fd; /* file descriptor */ - gint64 pos; /* current position in uncompressed data */ - guint size; /* buffer size, zero if not allocated yet */ - guint want; /* requested buffer size, default is GZBUFSIZE */ + int64_t pos; /* current position in uncompressed data */ + unsigned size; /* buffer size, zero if not allocated yet */ + unsigned want; /* requested buffer size, default is GZBUFSIZE */ unsigned char *in; /* input buffer */ unsigned char *out; /* output buffer (double-sized when reading) */ unsigned char *next; /* next output data to deliver or write */ @@ -1948,7 +2617,7 @@ struct wtap_writer { int err; /* error code */ const char *err_info; /* additional error information string for some errors */ /* zlib deflate stream */ - z_stream strm; /* stream structure in-place (not a pointer) */ + zlib_stream strm; /* stream structure in-place (not a pointer) */ }; GZWFILE_T @@ -2003,7 +2672,11 @@ static int gz_init(GZWFILE_T state) { int ret; +#ifdef HAVE_ZLIBNG + zng_streamp strm = &(state->strm); +#else /* HAVE_ZLIBNG */ z_streamp strm = &(state->strm); +#endif /* HAVE_ZLIBNG */ /* allocate input and output buffers */ state->in = (unsigned char *)g_try_malloc(state->want); @@ -2019,7 +2692,7 @@ gz_init(GZWFILE_T state) strm->zalloc = Z_NULL; strm->zfree = Z_NULL; strm->opaque = Z_NULL; - ret = deflateInit2(strm, state->level, Z_DEFLATED, + ret = ZLIB_PREFIX(deflateInit2)(strm, state->level, Z_DEFLATED, 15 + 16, 8, state->strategy); if (ret != Z_OK) { g_free(state->out); @@ -2056,8 +2729,11 @@ gz_comp(GZWFILE_T state, int flush) int ret; ssize_t got; ptrdiff_t have; +#ifdef HAVE_ZLIBNG + zng_streamp strm = &(state->strm); +#else /* HAVE_ZLIBNG */ z_streamp strm = &(state->strm); - +#endif /* HAVE_ZLIBNG */ /* allocate memory if this is the first time through */ if (state->size == 0 && gz_init(state) == -1) return -1; @@ -2090,7 +2766,7 @@ gz_comp(GZWFILE_T state, int flush) /* compress */ have = strm->avail_out; - ret = deflate(strm, flush); + ret = ZLIB_PREFIX(deflate)(strm, flush); if (ret == Z_STREAM_ERROR) { /* This "shouldn't happen". */ state->err = WTAP_ERR_INTERNAL; @@ -2102,7 +2778,7 @@ gz_comp(GZWFILE_T state, int flush) /* if that completed a deflate stream, allow another to start */ if (flush == Z_FINISH) - deflateReset(strm); + ZLIB_PREFIX(deflateReset)(strm); /* all done, no errors */ return 0; @@ -2112,11 +2788,15 @@ gz_comp(GZWFILE_T state, int flush) failure or on an attempt to write 0 bytes (in which case state->err is Z_OK); return the number of bytes written on success. */ unsigned -gzwfile_write(GZWFILE_T state, const void *buf, guint len) +gzwfile_write(GZWFILE_T state, const void *buf, unsigned len) { - guint put = len; - guint n; + unsigned put = len; + unsigned n; +#ifdef HAVE_ZLIBNG + zng_streamp strm; +#else /* HAVE_ZLIBNG */ z_streamp strm; +#endif /* HAVE_ZLIBNG */ strm = &(state->strm); @@ -2145,9 +2825,9 @@ gzwfile_write(GZWFILE_T state, const void *buf, guint len) DIAG_OFF(cast-qual) memcpy((Bytef *)strm->next_in + strm->avail_in, buf, n); DIAG_ON(cast-qual) -#else +#else /* z_const */ memcpy(strm->next_in + strm->avail_in, buf, n); -#endif +#endif /* z_const */ strm->avail_in += n; state->pos += n; buf = (const char *)buf + n; @@ -2165,11 +2845,11 @@ DIAG_ON(cast-qual) strm->avail_in = len; #ifdef z_const strm->next_in = (z_const Bytef *)buf; -#else +#else /* z_const */ DIAG_OFF(cast-qual) strm->next_in = (Bytef *)buf; DIAG_ON(cast-qual) -#endif +#endif /* z_const */ state->pos += len; if (gz_comp(state, Z_NO_FLUSH) == -1) return 0; @@ -2205,7 +2885,7 @@ gzwfile_close(GZWFILE_T state) /* flush, free memory, and close file */ if (gz_comp(state, Z_FINISH) == -1) ret = state->err; - (void)deflateEnd(&(state->strm)); + (void)ZLIB_PREFIX(deflateEnd)(&(state->strm)); g_free(state->out); g_free(state->in); state->err = Z_OK; @@ -2220,8 +2900,242 @@ gzwfile_geterr(GZWFILE_T state) { return state->err; } -#endif +#endif /* USE_ZLIB_OR_ZLIBNG */ + +#ifdef USE_LZ4 +/* internal lz4 file state data structure for writing */ +struct lz4_writer { + int fd; /* file descriptor */ + int64_t pos; /* current position in uncompressed data */ + int64_t pos_out; + size_t size_out; /* buffer size, zero if not allocated yet */ + size_t want; /* requested buffer size, default is LZ4BUFSIZE */ + size_t want_out; /* requested output buffer size, determined from want */ + unsigned char *out; /* output buffer, containing uncompressed data */ + int err; /* error code */ + const char *err_info; /* additional error information string for some errors */ + LZ4F_preferences_t lz4_prefs; + LZ4F_cctx *lz4_cctx; +}; + +LZ4WFILE_T +lz4wfile_open(const char *path) +{ + int fd; + LZ4WFILE_T state; + int save_errno; + + fd = ws_open(path, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0666); + if (fd == -1) + return NULL; + state = lz4wfile_fdopen(fd); + if (state == NULL) { + save_errno = errno; + ws_close(fd); + errno = save_errno; + } + return state; +} + +LZ4WFILE_T +lz4wfile_fdopen(int fd) +{ + LZ4WFILE_T state; + + /* allocate wtap_writer structure to return */ + state = (LZ4WFILE_T)g_try_malloc(sizeof *state); + if (state == NULL) + return NULL; + state->fd = fd; + state->size_out = 0; /* no buffer allocated yet */ + state->want = LZ4BUFSIZE; /* max input size (a block) */ + state->want_out = LZ4F_compressBound(state->want, &state->lz4_prefs); + /* + * This size guarantees that we will always have enough room to + * write the result of LZ4F_compressUpdate (or Flush or End), + * so long as the output buffer is empty (i.e., we immediately + * write to the output file anything the compressor hands back + * instead of buffering.) + */ + + memset(&state->lz4_prefs, 0, sizeof(LZ4F_preferences_t)); + /* Use the same prefs as the lz4 command line utility defaults. */ + state->lz4_prefs.frameInfo.blockMode = LZ4F_blockIndependent; /* Allows fast seek */ + state->lz4_prefs.frameInfo.contentChecksumFlag = 1; + state->lz4_prefs.frameInfo.blockSizeID = LZ4F_max4MB; + /* XXX - What should we set state->lz4_prefs.compressionLevel to? + * The command line utility uses 1, recommends 9 as another option, and + * also there's 12 (max). + * + * We could provide an API call or perhaps two or three preset options. + */ + state->lz4_prefs.compressionLevel = 1; + + /* initialize stream */ + state->err = 0; /* clear error */ + state->err_info = NULL; /* clear additional error information */ + state->pos = 0; /* no uncompressed data yet */ + state->pos_out = 0; + + /* return stream */ + return state; +} + +/* Writes len bytes from the output buffer to the file. + * Return true on success; returns false and sets state->err on failure. + */ +static bool +lz4_write_out(LZ4WFILE_T state, size_t len) +{ + if (len > 0) { + ssize_t got = ws_write(state->fd, state->out, len); + if (got < 0) { + state->err = errno; + return false; + } + if ((unsigned)got != len) { + state->err = WTAP_ERR_SHORT_WRITE; + return false; + } + state->pos_out += got; + } + return true; +} + +/* Initialize state for writing an lz4 file. Mark initialization by setting + state->size to non-zero. Return -1, and set state->err and possibly + state->err_info, on failure; return 0 on success. */ +static int +lz4_init(LZ4WFILE_T state) +{ + LZ4F_errorCode_t ret; + + /* create Compression context */ + ret = LZ4F_createCompressionContext(&state->lz4_cctx, LZ4F_VERSION); + if (LZ4F_isError(ret)) { + state->err = WTAP_ERR_CANT_WRITE; // XXX - WTAP_ERR_COMPRESS? + state->err_info = LZ4F_getErrorName(ret); + return -1; + } + + /* allocate buffer */ + state->out = (unsigned char *)g_try_malloc(state->want_out); + if (state->out == NULL) { + g_free(state->out); + LZ4F_freeCompressionContext(state->lz4_cctx); + state->err = ENOMEM; + return -1; + } + + ret = LZ4F_compressBegin(state->lz4_cctx, state->out, state->want_out, &state->lz4_prefs); + if (LZ4F_isError(ret)) { + state->err = WTAP_ERR_CANT_WRITE; // XXX - WTAP_ERR_COMPRESS? + state->err_info = LZ4F_getErrorName(ret); + return -1; + } + if (!lz4_write_out(state, ret)) { + return -1; + } + + /* mark state as initialized */ + state->size_out = state->want_out; + + return 0; +} + +/* Write out len bytes from buf. Return 0, and set state->err, on + failure or on an attempt to write 0 bytes (in which case state->err + is 0); return the number of bytes written on success. */ +size_t +lz4wfile_write(LZ4WFILE_T state, const void *buf, size_t len) +{ + size_t to_write; + size_t put = len; + /* check that there's no error */ + if (state->err != 0) + return 0; + + /* if len is zero, avoid unnecessary operations */ + if (len == 0) + return 0; + + /* allocate memory if this is the first time through */ + if (state->size_out == 0 && lz4_init(state) == -1) + return 0; + + do { + to_write = MIN(len, state->want); + size_t bytesWritten = LZ4F_compressUpdate(state->lz4_cctx, state->out, state->size_out, + buf, to_write, NULL); + if (LZ4F_isError(bytesWritten)) { + state->err = WTAP_ERR_CANT_WRITE; // XXX - WTAP_ERR_COMPRESS? + state->err_info = LZ4F_getErrorName(bytesWritten); + return 0; + } + if (!lz4_write_out(state, bytesWritten)) { + return 0; + } + state->pos += to_write; + len -= to_write; + } while (len); + + /* input was all buffered or compressed */ + return put; +} + +/* Flush out what we've written so far. Returns -1, and sets state->err, + on failure; returns 0 on success. */ +int +lz4wfile_flush(LZ4WFILE_T state) +{ + size_t bytesWritten; + /* check that there's no error */ + if (state->err != 0) + return -1; + + bytesWritten = LZ4F_flush(state->lz4_cctx, state->out, state->size_out, NULL); + if (LZ4F_isError(bytesWritten)) { + // Should never happen if size_out >= LZ4F_compressBound(0, prefsPtr) + state->err = WTAP_ERR_INTERNAL; + return -1; + } + if (!lz4_write_out(state, bytesWritten)) { + return -1; + } + return 0; +} + +/* Flush out all data written, and close the file. Returns a Wiretap + error on failure; returns 0 on success. */ +int +lz4wfile_close(LZ4WFILE_T state) +{ + int ret = 0; + + /* flush, free memory, and close file */ + size_t bytesWritten = LZ4F_compressEnd(state->lz4_cctx, state->out, state->size_out, NULL); + if (LZ4F_isError(bytesWritten)) { + // Should never happen if size_out >= LZ4F_compressBound(0, prefsPtr) + ret = WTAP_ERR_INTERNAL; + } + if (!lz4_write_out(state, bytesWritten)) { + ret = state->err; + } + g_free(state->out); + LZ4F_freeCompressionContext(state->lz4_cctx); + if (ws_close(state->fd) == -1 && ret == 0) + ret = errno; + g_free(state); + return ret; +} + +int +lz4wfile_geterr(LZ4WFILE_T state) +{ + return state->err; +} +#endif /* USE_LZ4 */ /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/wiretap/file_wrappers.h b/wiretap/file_wrappers.h index 4c644f32..2ba12eb2 100644 --- a/wiretap/file_wrappers.h +++ b/wiretap/file_wrappers.h @@ -15,33 +15,44 @@ extern FILE_T file_open(const char *path); extern FILE_T file_fdopen(int fildes); -extern void file_set_random_access(FILE_T stream, gboolean random_flag, GPtrArray *seek); -WS_DLL_PUBLIC gint64 file_seek(FILE_T stream, gint64 offset, int whence, int *err); -WS_DLL_PUBLIC gint64 file_tell(FILE_T stream); -extern gint64 file_tell_raw(FILE_T stream); +extern void file_set_random_access(FILE_T stream, bool random_flag, GPtrArray *seek); +WS_DLL_PUBLIC int64_t file_seek(FILE_T stream, int64_t offset, int whence, int *err); +WS_DLL_PUBLIC int64_t file_tell(FILE_T stream); +extern int64_t file_tell_raw(FILE_T stream); extern int file_fstat(FILE_T stream, ws_statb64 *statb, int *err); -WS_DLL_PUBLIC gboolean file_iscompressed(FILE_T stream); +WS_DLL_PUBLIC bool file_iscompressed(FILE_T stream); WS_DLL_PUBLIC int file_read(void *buf, unsigned int count, FILE_T file); WS_DLL_PUBLIC int file_peekc(FILE_T stream); WS_DLL_PUBLIC int file_getc(FILE_T stream); WS_DLL_PUBLIC char *file_gets(char *buf, int len, FILE_T stream); WS_DLL_PUBLIC char *file_getsp(char *buf, int len, FILE_T stream); WS_DLL_PUBLIC int file_eof(FILE_T stream); -WS_DLL_PUBLIC int file_error(FILE_T fh, gchar **err_info); +WS_DLL_PUBLIC int file_error(FILE_T fh, char **err_info); extern void file_clearerr(FILE_T stream); extern void file_fdclose(FILE_T file); -extern int file_fdreopen(FILE_T file, const char *path); +extern bool file_fdreopen(FILE_T file, const char *path); extern void file_close(FILE_T file); -#ifdef HAVE_ZLIB +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) typedef struct wtap_writer *GZWFILE_T; extern GZWFILE_T gzwfile_open(const char *path); extern GZWFILE_T gzwfile_fdopen(int fd); -extern guint gzwfile_write(GZWFILE_T state, const void *buf, guint len); +extern unsigned gzwfile_write(GZWFILE_T state, const void *buf, unsigned len); extern int gzwfile_flush(GZWFILE_T state); extern int gzwfile_close(GZWFILE_T state); extern int gzwfile_geterr(GZWFILE_T state); #endif /* HAVE_ZLIB */ +#ifdef HAVE_LZ4 +typedef struct lz4_writer *LZ4WFILE_T; + +extern LZ4WFILE_T lz4wfile_open(const char *path); +extern LZ4WFILE_T lz4wfile_fdopen(int fd); +extern size_t lz4wfile_write(LZ4WFILE_T state, const void *buf, size_t len); +extern int lz4wfile_flush(LZ4WFILE_T state); +extern int lz4wfile_close(LZ4WFILE_T state); +extern int lz4wfile_geterr(LZ4WFILE_T state); +#endif + #endif /* __FILE_H__ */ diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c index 2755a86c..d2f63e8f 100644 --- a/wiretap/hcidump.c +++ b/wiretap/hcidump.c @@ -6,33 +6,33 @@ */ #include "config.h" +#include "hcidump.h" #include "wtap-int.h" #include "file_wrappers.h" -#include "hcidump.h" static int hcidump_file_type_subtype = -1; void register_hcidump(void); struct dump_hdr { - guint16 len; - guint8 in; - guint8 pad; - guint32 ts_sec; - guint32 ts_usec; + uint16_t len; + uint8_t in; + uint8_t pad; + uint32_t ts_sec; + uint32_t ts_usec; }; #define DUMP_HDR_SIZE (sizeof(struct dump_hdr)) -static gboolean hcidump_read_packet(FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool hcidump_read_packet(FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { struct dump_hdr dh; - guint packet_size; + unsigned packet_size; if (!wtap_read_bytes_or_eof(fh, &dh, DUMP_HDR_SIZE, err, err_info)) - return FALSE; + return false; packet_size = GUINT16_FROM_LE(dh.len); if (packet_size > WTAP_MAX_PACKET_SIZE_STANDARD) { @@ -43,7 +43,7 @@ static gboolean hcidump_read_packet(FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("hcidump: File has %u-byte packet, bigger than maximum of %u", packet_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -54,32 +54,32 @@ static gboolean hcidump_read_packet(FILE_T fh, wtap_rec *rec, rec->rec_header.packet_header.caplen = packet_size; rec->rec_header.packet_header.len = packet_size; - rec->rec_header.packet_header.pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE); + rec->rec_header.packet_header.pseudo_header.p2p.sent = (dh.in ? false : true); return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static gboolean hcidump_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool hcidump_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return hcidump_read_packet(wth->fh, rec, buf, err, err_info); } -static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool hcidump_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return hcidump_read_packet(wth->random_fh, rec, buf, err, err_info); } -wtap_open_return_val hcidump_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val hcidump_open(wtap *wth, int *err, char **err_info) { struct dump_hdr dh; - guint8 type; + uint8_t type; if (!wtap_read_bytes(wth->fh, &dh, DUMP_HDR_SIZE, err, err_info)) { if (*err != WTAP_ERR_SHORT_READ) @@ -131,7 +131,7 @@ static const struct supported_block_type hcidummp_blocks_supported[] = { static const struct file_type_subtype_info hcidump_info = { "Bluetooth HCI dump", "hcidump", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(hcidummp_blocks_supported), + false, BLOCKS_SUPPORTED(hcidummp_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/hcidump.h b/wiretap/hcidump.h index b5685ed8..3cf14fe6 100644 --- a/wiretap/hcidump.h +++ b/wiretap/hcidump.h @@ -13,6 +13,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val hcidump_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val hcidump_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/i4b_trace.h b/wiretap/i4b_trace.h index 6b377be7..4b048db9 100644 --- a/wiretap/i4b_trace.h +++ b/wiretap/i4b_trace.h @@ -15,20 +15,20 @@ * structure of the header at the beginning of every trace mbuf *---------------------------------------------------------------------------*/ typedef struct { - guint32 length; /* length of the following mbuf */ - guint32 unit; /* controller unit number */ - guint32 type; /* type of channel */ + uint32_t length; /* length of the following mbuf */ + uint32_t unit; /* controller unit number */ + uint32_t type; /* type of channel */ #define TRC_CH_I 0 /* Layer 1 INFO's */ #define TRC_CH_D 1 /* D channel */ #define TRC_CH_B1 2 /* B1 channel */ #define TRC_CH_B2 3 /* B2 channel */ - gint32 dir; /* direction */ + int32_t dir; /* direction */ #define FROM_TE 0 /* user -> network */ #define FROM_NT 1 /* network -> user */ - guint32 trunc; /* # of truncated bytes (frame > MCLBYTES) */ - guint32 count; /* frame count for this unit/type */ - guint32 ts_sec; /* timestamp seconds */ - guint32 ts_usec; /* timestamp microseconds */ + uint32_t trunc; /* # of truncated bytes (frame > MCLBYTES) */ + uint32_t count; /* frame count for this unit/type */ + uint32_t ts_sec; /* timestamp seconds */ + uint32_t ts_usec; /* timestamp microseconds */ } i4b_trace_hdr_t; #define INFO0 0 /* layer 1 */ @@ -55,10 +55,10 @@ typedef struct { #define TRACE_B_RX 0x10 /* trace B channel on */ typedef struct { - gint32 rxunit; /* unit # for rx frames */ - gint32 rxflags; /* d and/or b channel */ - gint32 txunit; /* unit # for tx frames */ - gint32 txflags; /* d and/or b channel */ + int32_t rxunit; /* unit # for rx frames */ + int32_t rxflags; /* d and/or b channel */ + int32_t txunit; /* unit # for tx frames */ + int32_t txflags; /* d and/or b channel */ } i4b_trace_setupa_t; #define I4B_TRC_SETA _IOW('T', 2, i4b_trace_setupa_t) /* set analyze mode */ diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index 1b15972b..c3c79ea8 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -7,24 +7,24 @@ */ #include "config.h" +#include "i4btrace.h" #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" #include "i4b_trace.h" -#include "i4btrace.h" typedef struct { - gboolean byte_swapped; + bool byte_swapped; } i4btrace_t; -static gboolean i4btrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *offset); -static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static int i4b_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); +static bool i4btrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *offset); +static bool i4btrace_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool i4b_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info); static int i4btrace_file_type_subtype = -1; @@ -62,10 +62,10 @@ void register_i4btrace(void); */ #define PACKETS_TO_CHECK 5 -wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val i4btrace_open(wtap *wth, int *err, char **err_info) { i4b_trace_hdr_t hdr; - gboolean byte_swapped = FALSE; + bool byte_swapped = false; i4btrace_t *i4btrace; /* I4B trace files have no magic in the header... Sigh */ @@ -92,7 +92,7 @@ wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info) * It looks valid byte-swapped, so assume it's a * trace written in the opposite byte order. */ - byte_swapped = TRUE; + byte_swapped = true; } /* @@ -100,7 +100,7 @@ wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info) * a short read, we don't fail, so that we can report * the file as a truncated I4B file. */ - if (!wtap_read_bytes(wth->fh, NULL, hdr.length - (guint32)sizeof(hdr), + if (!wtap_read_bytes(wth->fh, NULL, hdr.length - (uint32_t)sizeof(hdr), err, err_info)) { if (*err != WTAP_ERR_SHORT_READ) return WTAP_OPEN_ERROR; @@ -140,7 +140,7 @@ wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info) * we can report the file as a truncated I4B file. */ if (!wtap_read_bytes(wth->fh, NULL, - hdr.length - (guint32)sizeof(hdr), err, err_info)) { + hdr.length - (uint32_t)sizeof(hdr), err, err_info)) { if (*err != WTAP_ERR_SHORT_READ) return WTAP_OPEN_ERROR; @@ -181,20 +181,20 @@ wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean i4btrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool i4btrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return i4b_read_rec(wth, wth->fh, rec, buf, err, err_info); } -static gboolean -i4btrace_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +i4btrace_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (!i4b_read_rec(wth, wth->random_fh, rec, buf, err, err_info)) { /* Read error or EOF */ @@ -202,21 +202,21 @@ i4btrace_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, /* EOF means "short read" in random-access mode */ *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool i4b_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { i4btrace_t *i4btrace = (i4btrace_t *)wth->priv; i4b_trace_hdr_t hdr; - guint32 length; + uint32_t length; if (!wtap_read_bytes_or_eof(fh, &hdr, sizeof hdr, err, err_info)) - return FALSE; + return false; if (i4btrace->byte_swapped) { /* @@ -229,9 +229,9 @@ i4b_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; /* record length < header! */ *err_info = ws_strdup_printf("i4btrace: record length %u < header length %lu", hdr.length, (unsigned long)sizeof(hdr)); - return FALSE; + return false; } - length = hdr.length - (guint32)sizeof(hdr); + length = hdr.length - (uint32_t)sizeof(hdr); if (length > WTAP_MAX_PACKET_SIZE_STANDARD) { /* * Probably a corrupt capture file; don't blow up trying @@ -240,7 +240,7 @@ i4b_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("i4btrace: File has %u-byte packet, bigger than maximum of %u", length, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -306,7 +306,7 @@ static const struct supported_block_type i4btrace_blocks_supported[] = { static const struct file_type_subtype_info i4btrace_info = { "I4B ISDN trace", "i4btrace", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(i4btrace_blocks_supported), + false, BLOCKS_SUPPORTED(i4btrace_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/i4btrace.h b/wiretap/i4btrace.h index 455f0a65..92104e58 100644 --- a/wiretap/i4btrace.h +++ b/wiretap/i4btrace.h @@ -14,6 +14,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val i4btrace_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/introspection-enums.c b/wiretap/introspection-enums.c index 5ebd7b81..f2fb07b7 100644 --- a/wiretap/introspection-enums.c +++ b/wiretap/introspection-enums.c @@ -17,7 +17,7 @@ #define ENUM(arg) { #arg, arg } -static ws_enum_t all_enums[] = { +static ws_enum_t const all_enums[] = { ENUM(AAL_1), ENUM(AAL_2), ENUM(AAL_3_4), @@ -126,7 +126,6 @@ static ws_enum_t all_enums[] = { ENUM(PHDR_802_11A_TURBO_TYPE_TURBO), ENUM(PHDR_802_11G_MODE_NORMAL), ENUM(PHDR_802_11G_MODE_SUPER_G), - ENUM(PHDR_802_11_0_LENGTH_PSDU_S1G_NDP), ENUM(PHDR_802_11_0_LENGTH_PSDU_VENDOR_SPECIFIC), ENUM(PHDR_802_11_A_MPDU_DELIM_CRC_ERROR), ENUM(PHDR_802_11_BANDWIDTH_160_MHZ), @@ -291,12 +290,14 @@ static ws_enum_t all_enums[] = { ENUM(WTAP_ENCAP_CISCO_IOS), ENUM(WTAP_ENCAP_COSINE), ENUM(WTAP_ENCAP_DBUS), + ENUM(WTAP_ENCAP_DECT_NR), ENUM(WTAP_ENCAP_DOCSIS), ENUM(WTAP_ENCAP_DOCSIS31_XRA31), ENUM(WTAP_ENCAP_DPAUXMON), ENUM(WTAP_ENCAP_DPNSS), ENUM(WTAP_ENCAP_DVBCI), ENUM(WTAP_ENCAP_EBHSCR), + ENUM(WTAP_ENCAP_EMS), ENUM(WTAP_ENCAP_ENC), ENUM(WTAP_ENCAP_EPON), ENUM(WTAP_ENCAP_ERF), diff --git a/wiretap/introspection.c b/wiretap/introspection.c index 032eee8e..44a342f9 100644 --- a/wiretap/introspection.c +++ b/wiretap/introspection.c @@ -11,6 +11,7 @@ #include "introspection.h" #include <string.h> #include <stdlib.h> +#include <wsutil/array.h> #include "introspection-enums.c" @@ -22,7 +23,7 @@ const ws_enum_t *wtap_inspect_enums(void) size_t wtap_inspect_enums_count(void) { /* Exclude null terminator */ - return sizeof(all_enums)/sizeof(ws_enum_t) - 1; + return array_length(all_enums) - 1; } const ws_enum_t *wtap_inspect_enums_bsearch(const char *needle) diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c index 2dff3849..0c1dafb3 100644 --- a/wiretap/ipfix.c +++ b/wiretap/ipfix.c @@ -49,42 +49,42 @@ #include "config.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP +#include "ipfix.h" #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "ipfix.h" #include <wsutil/strtoi.h> #include <wsutil/wslog.h> #define RECORDS_FOR_IPFIX_CHECK 20 -static gboolean +static bool ipfix_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset); -static gboolean -ipfix_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); + char **err_info, int64_t *data_offset); +static bool +ipfix_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); #define IPFIX_VERSION 10 /* ipfix: message header */ typedef struct ipfix_message_header_s { - guint16 version; - guint16 message_length; - guint32 export_time_secs; - guint32 sequence_number; - guint32 observation_id; /* might be 0 for none */ + uint16_t version; + uint16_t message_length; + uint32_t export_time_secs; + uint32_t sequence_number; + uint32_t observation_id; /* might be 0 for none */ /* x bytes msg_body */ } ipfix_message_header_t; #define IPFIX_MSG_HDR_SIZE 16 /* ipfix: common Set header for every Set type */ typedef struct ipfix_set_header_s { - guint16 set_type; - guint16 set_length; + uint16_t set_type; + uint16_t set_length; /* x bytes set_body */ } ipfix_set_header_t; #define IPFIX_SET_HDR_SIZE 4 @@ -96,13 +96,13 @@ void register_ipfix(void); /* Read IPFIX message header from file. Return true on success. Set *err to * 0 on EOF, any other value for "real" errors (EOF is ok, since return - * value is still FALSE) + * value is still false) */ -static gboolean -ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err, gchar **err_info) +static bool +ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err, char **err_info) { if (!wtap_read_bytes_or_eof(fh, pfx_hdr, IPFIX_MSG_HDR_SIZE, err, err_info)) - return FALSE; + return false; /* fix endianness, because IPFIX files are always big-endian */ pfx_hdr->version = g_ntohs(pfx_hdr->version); @@ -116,37 +116,37 @@ ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err, /* Not an ipfix file. */ *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("ipfix: wrong version %d", pfx_hdr->version); - return FALSE; + return false; } if (pfx_hdr->message_length < 16) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("ipfix: message length %u is too short", pfx_hdr->message_length); - return FALSE; + return false; } /* go back to before header */ if (file_seek(fh, 0 - IPFIX_MSG_HDR_SIZE, SEEK_CUR, err) == -1) { ws_debug("couldn't go back in file before header"); - return FALSE; + return false; } - return TRUE; + return true; } /* Read IPFIX message header from file and fill in the struct wtap_rec * for the packet, and, if that succeeds, read the packet data. * Return true on success. Set *err to 0 on EOF, any other value for "real" - * errors (EOF is ok, since return value is still FALSE). + * errors (EOF is ok, since return value is still false). */ -static gboolean -ipfix_read_message(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +ipfix_read_message(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { ipfix_message_header_t msg_hdr; if (!ipfix_read_message_header(&msg_hdr, fh, err, err_info)) - return FALSE; + return false; /* * The maximum value of msg_hdr.message_length is 65535, which is * less than WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need @@ -171,11 +171,11 @@ ipfix_read_message(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_ * WTAP_OPEN_ERROR on bad error like file system */ wtap_open_return_val -ipfix_open(wtap *wth, int *err, gchar **err_info) +ipfix_open(wtap *wth, int *err, char **err_info) { - gint i, n, records_for_ipfix_check = RECORDS_FOR_IPFIX_CHECK; - gchar *s; - guint16 checked_len = 0; + int i, n, records_for_ipfix_check = RECORDS_FOR_IPFIX_CHECK; + char *s; + uint16_t checked_len; ipfix_message_header_t msg_hdr; ipfix_set_header_t set_hdr; @@ -285,9 +285,9 @@ ipfix_open(wtap *wth, int *err, gchar **err_info) /* classic wtap: read packet */ -static gboolean +static bool ipfix_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); ws_debug("offset is initially %" PRId64, *data_offset); @@ -295,23 +295,23 @@ ipfix_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, if (!ipfix_read_message(wth->fh, rec, buf, err, err_info)) { ws_debug("couldn't read message header with code: %d\n, and error '%s'", *err, *err_info); - return FALSE; + return false; } - return TRUE; + return true; } /* classic wtap: seek to file position and read packet */ -static gboolean -ipfix_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +ipfix_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { /* seek to the right file position */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { ws_debug("couldn't read message header with code: %d\n, and error '%s'", *err, *err_info); - return FALSE; /* Seek error */ + return false; /* Seek error */ } ws_debug("reading at offset %" PRIu64, seek_off); @@ -320,9 +320,9 @@ ipfix_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, ws_debug("couldn't read message header"); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } static const struct supported_block_type ipfix_blocks_supported[] = { @@ -334,7 +334,7 @@ static const struct supported_block_type ipfix_blocks_supported[] = { static const struct file_type_subtype_info ipfix_info = { "IPFIX File Format", "ipfix", "pfx", "ipfix", - FALSE, BLOCKS_SUPPORTED(ipfix_blocks_supported), + false, BLOCKS_SUPPORTED(ipfix_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/ipfix.h b/wiretap/ipfix.h index 7f7bfe95..160c7d81 100644 --- a/wiretap/ipfix.h +++ b/wiretap/ipfix.h @@ -13,6 +13,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val ipfix_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val ipfix_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c index 2b4e9d63..f031eb7c 100644 --- a/wiretap/iptrace.c +++ b/wiretap/iptrace.c @@ -7,19 +7,20 @@ * */ #include "config.h" +#include "iptrace.h" + #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" #include "atm.h" -#include "iptrace.h" /* * Private per-wtap_t data needed to read a file. */ typedef struct { GHashTable *interface_ids; /* map name/description/link-layer type to interface ID */ - guint num_interface_ids; /* Number of interface IDs assigned */ + unsigned num_interface_ids; /* Number of interface IDs assigned */ } iptrace_t; #define IPTRACE_IFT_HF 0x3d /* Support for PERCS IP-HFI*/ @@ -27,18 +28,18 @@ typedef struct { static void iptrace_close(wtap *wth); -static gboolean iptrace_read_1_0(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); -static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool iptrace_read_1_0(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, int64_t *data_offset); +static bool iptrace_seek_read_1_0(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); -static gboolean iptrace_read_2_0(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); -static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool iptrace_read_2_0(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, int64_t *data_offset); +static bool iptrace_seek_read_2_0(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); -static gboolean iptrace_read_rec_data(FILE_T fh, Buffer *buf, - wtap_rec *rec, int *err, gchar **err_info); +static bool iptrace_read_rec_data(FILE_T fh, Buffer *buf, + wtap_rec *rec, int *err, char **err_info); static void fill_in_pseudo_header(int encap, union wtap_pseudo_header *pseudo_header, const char *pkt_text); static int wtap_encap_ift(unsigned int ift); @@ -56,8 +57,8 @@ static int wtap_encap_ift(unsigned int ift); typedef struct { char prefix[PREFIX_SIZE+1]; - guint8 unit; - guint8 if_type; + uint8_t unit; + uint8_t if_type; } if_info; static int iptrace_1_0_file_type_subtype = -1; @@ -65,24 +66,24 @@ static int iptrace_2_0_file_type_subtype = -1; void register_iptrace(void); -static gboolean destroy_if_info(gpointer key, gpointer value _U_, - gpointer user_data _U_) +static gboolean destroy_if_info(void *key, void *value _U_, + void *user_data _U_) { if_info *info = (if_info *)key; g_free(info); - return TRUE; + return true; } -static guint if_info_hash(gconstpointer info_arg) +static unsigned if_info_hash(const void *info_arg) { if_info *info = (if_info *)info_arg; return g_str_hash(info->prefix) + info->unit + info->if_type; } -static gboolean if_info_equal(gconstpointer info1_arg, gconstpointer info2_arg) +static gboolean if_info_equal(const void *info1_arg, const void *info2_arg) { if_info *info1 = (if_info *)info1_arg; if_info *info2 = (if_info *)info2_arg; @@ -92,7 +93,7 @@ static gboolean if_info_equal(gconstpointer info1_arg, gconstpointer info2_arg) info1->if_type == info2->if_type; } -wtap_open_return_val iptrace_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val iptrace_open(wtap *wth, int *err, char **err_info) { char version_string[VERSION_STRING_SIZE+1]; iptrace_t *iptrace; @@ -139,12 +140,12 @@ static void iptrace_close(wtap *wth) g_hash_table_destroy(iptrace->interface_ids); } -static void add_new_if_info(iptrace_t *iptrace, if_info *info, gpointer *result) +static void add_new_if_info(iptrace_t *iptrace, if_info *info, void * *result) { if_info *new_info = g_new(if_info, 1); *new_info = *info; *result = GUINT_TO_POINTER(iptrace->num_interface_ids); - g_hash_table_insert(iptrace->interface_ids, (gpointer)new_info, *result); + g_hash_table_insert(iptrace->interface_ids, (void *)new_info, *result); iptrace->num_interface_ids++; } @@ -191,22 +192,22 @@ static void add_new_if_info(iptrace_t *iptrace, if_info *info, gpointer *result) #define IPTRACE_1_0_PINFO_SIZE 22 /* packet information */ -static gboolean +static bool iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { iptrace_t *iptrace = (iptrace_t *)wth->priv; - guint8 header[IPTRACE_1_0_PHDR_SIZE]; - guint32 record_length; - guint8 pkt_info[IPTRACE_1_0_PINFO_SIZE]; + uint8_t header[IPTRACE_1_0_PHDR_SIZE]; + uint32_t record_length; + uint8_t pkt_info[IPTRACE_1_0_PINFO_SIZE]; if_info info; - guint32 packet_size; - gpointer result; + uint32_t packet_size; + void *result; if (!wtap_read_bytes_or_eof(fh, header, IPTRACE_1_0_PHDR_SIZE, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } /* Get the record length */ @@ -219,7 +220,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("iptrace: file has a %u-byte record, too small to have even a packet information header", record_length); - return FALSE; + return false; } /* @@ -228,7 +229,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, if (!wtap_read_bytes(fh, pkt_info, IPTRACE_1_0_PINFO_SIZE, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } /* @@ -242,7 +243,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_UNSUPPORTED; *err_info = ws_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported", info.if_type); - return FALSE; + return false; } /* Get the packet data size */ @@ -265,7 +266,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("iptrace: file has a %u-byte record, too small to have even a packet meta-data header", record_length); - return FALSE; + return false; } packet_size -= 3; @@ -273,7 +274,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, * Skip the padding. */ if (!wtap_read_bytes(fh, NULL, 3, err, err_info)) - return FALSE; + return false; } if (packet_size > WTAP_MAX_PACKET_SIZE_STANDARD) { /* @@ -283,7 +284,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("iptrace: File has %u-byte packet, bigger than maximum of %u", packet_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -305,7 +306,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, /* Get the packet data */ if (!iptrace_read_rec_data(fh, buf, rec, err, err_info)) - return FALSE; + return false; /* * No errors - get the interface ID. @@ -322,7 +323,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, * interface type. */ if (!g_hash_table_lookup_extended(iptrace->interface_ids, - (gconstpointer)&info, NULL, &result)) { + (const void *)&info, NULL, &result)) { wtap_block_t int_data; wtapng_if_descr_mandatory_t *int_data_mand; @@ -352,19 +353,19 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, wtap_add_idb(wth, int_data); } rec->rec_header.packet_header.interface_id = GPOINTER_TO_UINT(result); - return TRUE; + return true; } /* Read the next packet */ -static gboolean iptrace_read_1_0(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) +static bool iptrace_read_1_0(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); /* Read the packet */ if (!iptrace_read_rec_1_0(wth, wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } /* If the per-file encapsulation isn't known, set it to this @@ -380,23 +381,23 @@ static gboolean iptrace_read_1_0(wtap *wth, wtap_rec *rec, wth->file_encap = WTAP_ENCAP_PER_PACKET; } - return TRUE; + return true; } -static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool iptrace_seek_read_1_0(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read the packet */ if (!iptrace_read_rec_1_0(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } /*********************************************************** @@ -445,22 +446,22 @@ static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, #define IPTRACE_2_0_PINFO_SIZE 32 /* packet information */ -static gboolean +static bool iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { iptrace_t *iptrace = (iptrace_t *)wth->priv; - guint8 header[IPTRACE_2_0_PHDR_SIZE]; - guint32 record_length; - guint8 pkt_info[IPTRACE_2_0_PINFO_SIZE]; + uint8_t header[IPTRACE_2_0_PHDR_SIZE]; + uint32_t record_length; + uint8_t pkt_info[IPTRACE_2_0_PINFO_SIZE]; if_info info; - guint32 packet_size; - gpointer result; + uint32_t packet_size; + void *result; if (!wtap_read_bytes_or_eof(fh, header, IPTRACE_2_0_PHDR_SIZE, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } /* Get the record length */ @@ -473,7 +474,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("iptrace: file has a %u-byte record, too small to have even a packet information header", record_length); - return FALSE; + return false; } /* @@ -482,7 +483,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, if (!wtap_read_bytes(fh, pkt_info, IPTRACE_2_0_PINFO_SIZE, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } /* @@ -513,7 +514,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_UNSUPPORTED; *err_info = ws_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported", info.if_type); - return FALSE; + return false; } #endif @@ -537,7 +538,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("iptrace: file has a %u-byte record, too small to have even a packet meta-data header", record_length); - return FALSE; + return false; } packet_size -= 3; @@ -545,7 +546,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, * Skip the padding. */ if (!wtap_read_bytes(fh, NULL, 3, err, err_info)) - return FALSE; + return false; } if (packet_size > WTAP_MAX_PACKET_SIZE_STANDARD) { /* @@ -555,7 +556,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("iptrace: File has %u-byte packet, bigger than maximum of %u", packet_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -577,7 +578,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, /* Get the packet data */ if (!iptrace_read_rec_data(fh, buf, rec, err, err_info)) - return FALSE; + return false; /* * No errors - get the interface ID. @@ -594,7 +595,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, * interface type. */ if (!g_hash_table_lookup_extended(iptrace->interface_ids, - (gconstpointer)&info, NULL, &result)) { + (const void *)&info, NULL, &result)) { wtap_block_t int_data; wtapng_if_descr_mandatory_t *int_data_mand; @@ -624,19 +625,19 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, wtap_add_idb(wth, int_data); } rec->rec_header.packet_header.interface_id = GPOINTER_TO_UINT(result); - return TRUE; + return true; } /* Read the next packet */ -static gboolean iptrace_read_2_0(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) +static bool iptrace_read_2_0(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); /* Read the packet */ if (!iptrace_read_rec_2_0(wth, wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } /* If the per-file encapsulation isn't known, set it to this @@ -652,31 +653,31 @@ static gboolean iptrace_read_2_0(wtap *wth, wtap_rec *rec, wth->file_encap = WTAP_ENCAP_PER_PACKET; } - return TRUE; + return true; } -static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool iptrace_seek_read_2_0(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read the packet */ if (!iptrace_read_rec_2_0(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool iptrace_read_rec_data(FILE_T fh, Buffer *buf, wtap_rec *rec, - int *err, gchar **err_info) + int *err, char **err_info) { if (!wtap_read_packet_bytes(fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) - return FALSE; + return false; if (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_ATM_PDUS) { /* @@ -686,7 +687,7 @@ iptrace_read_rec_data(FILE_T fh, Buffer *buf, wtap_rec *rec, atm_guess_traffic_type(rec, ws_buffer_start_ptr(buf)); } - return TRUE; + return true; } /* @@ -800,7 +801,7 @@ wtap_encap_ift(unsigned int ift) /* 0x24 */ WTAP_ENCAP_UNKNOWN, /* IFT_ARCNETPLUS */ /* 0x25 */ WTAP_ENCAP_ATM_PDUS, /* IFT_ATM */ }; - #define NUM_IFT_ENCAPS (sizeof ift_encap / sizeof ift_encap[0]) + #define NUM_IFT_ENCAPS array_length(ift_encap) if (ift < NUM_IFT_ENCAPS) { return ift_encap[ift]; @@ -810,7 +811,6 @@ wtap_encap_ift(unsigned int ift) /* Infiniband*/ case IPTRACE_IFT_IB: return WTAP_ENCAP_INFINIBAND; - break; /* Host Fabric Interface */ case IPTRACE_IFT_HF: @@ -824,7 +824,6 @@ wtap_encap_ift(unsigned int ift) have to figure out which field in the iptrace file encodes it. */ return WTAP_ENCAP_RAW_IP; - break; default: return WTAP_ENCAP_UNKNOWN; @@ -855,7 +854,7 @@ static const struct supported_block_type iptrace_1_0_blocks_supported[] = { static const struct file_type_subtype_info iptrace_1_0_info = { "AIX iptrace 1.0", "iptrace_1", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(iptrace_1_0_blocks_supported), + false, BLOCKS_SUPPORTED(iptrace_1_0_blocks_supported), NULL, NULL, NULL }; @@ -876,7 +875,7 @@ static const struct supported_block_type iptrace_2_0_blocks_supported[] = { static const struct file_type_subtype_info iptrace_2_0_info = { "AIX iptrace 2.0", "iptrace_2", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(iptrace_2_0_blocks_supported), + false, BLOCKS_SUPPORTED(iptrace_2_0_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/iptrace.h b/wiretap/iptrace.h index 1328ea33..549c10d9 100644 --- a/wiretap/iptrace.h +++ b/wiretap/iptrace.h @@ -13,6 +13,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val iptrace_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val iptrace_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/iseries.c b/wiretap/iseries.c index 180ed01a..aa78744e 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -137,8 +137,8 @@ Number S/R Length Timer MAC Address MAC Address */ #include "config.h" -#include "wtap-int.h" #include "iseries.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <stdlib.h> @@ -174,24 +174,24 @@ static const char iseries_hdr_magic_le_ucs_2[] = { }; typedef struct { - gboolean have_date; /* TRUE if we found a capture start date */ + bool have_date; /* true if we found a capture start date */ int year, month, day; /* The start date */ int format; /* Trace format type */ } iseries_t; -static gboolean iseries_read (wtap * wth, wtap_rec *rec, Buffer *buf, - int *err, gchar ** err_info, gint64 *data_offset); -static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, +static bool iseries_read (wtap * wth, wtap_rec *rec, Buffer *buf, + int *err, char ** err_info, int64_t *data_offset); +static bool iseries_seek_read (wtap * wth, int64_t seek_off, wtap_rec *rec, - Buffer * buf, int *err, gchar ** err_info); -static gboolean iseries_check_file_type (wtap * wth, int *err, gchar **err_info, + Buffer * buf, int *err, char ** err_info); +static bool iseries_check_file_type (wtap * wth, int *err, char **err_info, int format); -static gint64 iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info); -static gboolean iseries_parse_packet (wtap * wth, FILE_T fh, +static int64_t iseries_seek_next_packet (wtap * wth, int *err, char **err_info); +static bool iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, - Buffer * buf, int *err, gchar ** err_info); -static int iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes); -static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf, + Buffer * buf, int *err, char ** err_info); +static int iseries_UNICODE_to_ASCII (uint8_t * buf, unsigned bytes); +static bool iseries_parse_hex_string (const char * ascii, uint8_t * buf, size_t len); static int iseries_file_type_subtype = -1; @@ -204,9 +204,9 @@ void register_iseries(void); * rather than file_gets(), if we're reading a UCS-2 file. */ wtap_open_return_val -iseries_open (wtap * wth, int *err, gchar ** err_info) +iseries_open (wtap * wth, int *err, char ** err_info) { - gint offset; + int offset; char magic[ISERIES_LINE_LENGTH]; /* @@ -327,18 +327,18 @@ iseries_open (wtap * wth, int *err, gchar ** err_info) * contents of this trace by checking the header page for * requisite requirements and additional information. */ -static gboolean -iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) +static bool +iseries_check_file_type (wtap * wth, int *err, char **err_info, int format) { - gboolean is_iseries = FALSE; - guint line; + bool is_iseries = false; + unsigned line; int num_items_scanned; char buf[ISERIES_LINE_LENGTH], protocol[9]; iseries_t *iseries; /* Save trace format for passing between packets */ iseries = g_new(iseries_t, 1); - iseries->have_date = FALSE; + iseries->have_date = false; iseries->format = format; for (line = 0; line < ISERIES_HDR_LINES_TO_CHECK; line++) @@ -358,7 +358,7 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) */ if (iseries->format == ISERIES_FORMAT_UNICODE) { - iseries_UNICODE_to_ASCII ((guint8 *)buf, ISERIES_LINE_LENGTH); + iseries_UNICODE_to_ASCII ((uint8_t *)buf, ISERIES_LINE_LENGTH); } ascii_strup_inplace (buf); num_items_scanned = sscanf (buf, @@ -369,7 +369,7 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) if (memcmp (protocol, "ETHERNET", 8) == 0) { *err = 0; - is_iseries = TRUE; + is_iseries = true; } } @@ -383,7 +383,7 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) &iseries->year); if (num_items_scanned == 3) { - iseries->have_date = TRUE; + iseries->have_date = true; } } @@ -398,18 +398,18 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) /* * Find the next packet and parse it; called from wtap_read(). */ -static gboolean +static bool iseries_read (wtap * wth, wtap_rec *rec, Buffer *buf, int *err, - gchar ** err_info, gint64 *data_offset) + char ** err_info, int64_t *data_offset) { - gint64 offset; + int64_t offset; /* * Locate the next packet */ offset = iseries_seek_next_packet (wth, err, err_info); if (offset < 0) - return FALSE; + return false; *data_offset = offset; /* @@ -424,13 +424,13 @@ iseries_read (wtap * wth, wtap_rec *rec, Buffer *buf, int *err, * *err to 0, and, on failure, sets *err to the error and *err_info * to null or an additional error string. */ -static gint64 -iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info) +static int64_t +iseries_seek_next_packet (wtap * wth, int *err, char **err_info) { iseries_t *iseries = (iseries_t *)wth->priv; char buf[ISERIES_LINE_LENGTH],type[5]; int line, num_items_scanned; - gint64 cur_off; + int64_t cur_off; long buflen; for (line = 0; line < ISERIES_MAX_TRACE_LEN; line++) @@ -446,7 +446,7 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info) if (iseries->format == ISERIES_FORMAT_UNICODE) { /* buflen is #bytes to 1st 0x0A */ - buflen = iseries_UNICODE_to_ASCII ((guint8 *) buf, ISERIES_LINE_LENGTH); + buflen = iseries_UNICODE_to_ASCII ((uint8_t *) buf, ISERIES_LINE_LENGTH); } else { @@ -490,14 +490,14 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info) /* * Read packets in random-access fashion */ -static gboolean -iseries_seek_read (wtap * wth, gint64 seek_off, wtap_rec *rec, - Buffer * buf, int *err, gchar ** err_info) +static bool +iseries_seek_read (wtap * wth, int64_t seek_off, wtap_rec *rec, + Buffer * buf, int *err, char ** err_info) { /* seek to packet location */ if (file_seek (wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) - return FALSE; + return false; /* * Parse the packet and extract the various fields @@ -508,12 +508,12 @@ iseries_seek_read (wtap * wth, gint64 seek_off, wtap_rec *rec, static int append_hex_digits(char *ascii_buf, int ascii_offset, int max_offset, - char *data, int *err, gchar **err_info) + char *data, int *err, char **err_info) { int in_offset, out_offset; int c; unsigned int i; - gboolean overflow = FALSE; + bool overflow = false; in_offset = 0; out_offset = ascii_offset; @@ -554,7 +554,7 @@ append_hex_digits(char *ascii_buf, int ascii_offset, int max_offset, return ascii_offset; /* pretend we appended nothing */ } if (out_offset >= max_offset) - overflow = TRUE; + overflow = true; else { ascii_buf[out_offset] = c; @@ -587,8 +587,8 @@ done: } /* return the multiplier for nanoseconds */ -static guint32 -csec_multiplier(guint32 csec) +static uint32_t +csec_multiplier(uint32_t csec) { if (csec < 10) return 100000000; if (csec < 100) return 10000000; @@ -602,17 +602,17 @@ csec_multiplier(guint32 csec) } /* Parses a packet. */ -static gboolean +static bool iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { iseries_t *iseries = (iseries_t *)wth->priv; - gint64 cur_off; - gboolean isValid, isCurrentPacket; + int64_t cur_off; + bool isValid, isCurrentPacket; int num_items_scanned, line, pktline, buflen; int pkt_len, pktnum, hr, min, sec; char direction[2], destmac[13], srcmac[13], type[5]; - guint32 csec; + uint32_t csec; char data[ISERIES_LINE_LENGTH * 2]; int offset; char *ascii_buf; @@ -624,18 +624,18 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, * situations and the header lines output at each page throw and ensure we * read both the captured and packet lengths. */ - isValid = FALSE; + isValid = false; for (line = 1; line < ISERIES_PKT_LINES_TO_CHECK; line++) { if (file_gets (data, ISERIES_LINE_LENGTH, fh) == NULL) { *err = file_error (fh, err_info); - return FALSE; + return false; } /* Convert UNICODE data to ASCII */ if (iseries->format == ISERIES_FORMAT_UNICODE) { - iseries_UNICODE_to_ASCII ((guint8 *)data, ISERIES_LINE_LENGTH); + iseries_UNICODE_to_ASCII ((uint8_t *)data, ISERIES_LINE_LENGTH); } ascii_strup_inplace (data); num_items_scanned = @@ -650,49 +650,49 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a negative packet number"); - return FALSE; + return false; } if (pkt_len < 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a negative packet length"); - return FALSE; + return false; } if (hr < 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a negative hour in the time stamp"); - return FALSE; + return false; } if (hr > 23) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a hour in the time stamp greater than 23"); - return FALSE; + return false; } if (min < 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a negative minute in the time stamp"); - return FALSE; + return false; } if (min > 59) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a minute in the time stamp greater than 59"); - return FALSE; + return false; } if (sec < 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a negative second in the time stamp"); - return FALSE; + return false; } /* @@ -703,32 +703,32 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a second in the time stamp greater than 60"); - return FALSE; + return false; } if (strlen(destmac) != 12) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a destination MAC address shorter than 6 bytes"); - return FALSE; + return false; } if (strlen(srcmac) != 12) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has a source MAC address shorter than 6 bytes"); - return FALSE; + return false; } if (strlen(type) != 4) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header has an Ethernet type/length field than 2 bytes"); - return FALSE; + return false; } /* OK! We found the packet header line */ - isValid = TRUE; + isValid = true; /* * XXX - The Capture length returned by the iSeries trace doesn't * seem to include the Ethernet header, so we add its length here. @@ -736,7 +736,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, * Check the length first, just in case it's *so* big that, after * adding the Ethernet header length, it overflows. */ - if ((guint)pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD - 14) + if ((unsigned)pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD - 14) { /* * Probably a corrupt capture file; don't blow up trying @@ -747,9 +747,9 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, */ *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("iseries: File has %" PRIu64 "-byte packet, bigger than maximum of %u", - (guint64)pkt_len + 14, + (uint64_t)pkt_len + 14, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } pkt_len += 14; break; @@ -763,7 +763,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header isn't valid"); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -824,7 +824,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, /* * Start reading packet contents */ - isCurrentPacket = TRUE; + isCurrentPacket = true; /* loop through packet lines and breakout when the next packet header is read */ pktline = 0; @@ -846,7 +846,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, /* Convert UNICODE data to ASCII and determine line length */ if (iseries->format == ISERIES_FORMAT_UNICODE) { - buflen = iseries_UNICODE_to_ASCII ((guint8 *)data, ISERIES_LINE_LENGTH); + buflen = iseries_UNICODE_to_ASCII ((uint8_t *)data, ISERIES_LINE_LENGTH); } else { @@ -887,7 +887,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, if (ascii_offset == -1) { /* Bad line. */ - return FALSE; + return false; } continue; } @@ -909,7 +909,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, if (ascii_offset == -1) { /* Bad line. */ - return FALSE; + return false; } continue; } @@ -932,14 +932,14 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, if (ascii_offset == -1) { /* Bad line. */ - return FALSE; + return false; } continue; } /* * If we see the identifier for the next packet then rewind and set - * isCurrentPacket FALSE + * isCurrentPacket false */ ascii_strup_inplace (data); /* If packet header found return the offset */ @@ -948,7 +948,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, "%*[ \n\t]ETHV2%*[ .:\n\t]TYPE%*[ .:\n\t]%4s",type); if ((num_items_scanned == 1) && pktline > 1) { - isCurrentPacket = FALSE; + isCurrentPacket = false; cur_off = file_tell( fh); if (cur_off == -1) { @@ -971,7 +971,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, * XXX - this can happen for IPv6 packets if the next header isn't the * last header. */ - rec->rec_header.packet_header.caplen = ((guint32) ascii_offset)/2; + rec->rec_header.packet_header.caplen = ((uint32_t) ascii_offset)/2; /* Make sure we have enough room for the packet. */ ws_buffer_assure_space (buf, rec->rec_header.packet_header.caplen); @@ -981,11 +981,11 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec, /* free buffer allocs and return */ *err = 0; g_free (ascii_buf); - return TRUE; + return true; errxit: g_free (ascii_buf); - return FALSE; + return false; } /* @@ -994,10 +994,10 @@ errxit: * XXX - This may be possible with iconv or similar */ static int -iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes) +iseries_UNICODE_to_ASCII (uint8_t * buf, unsigned bytes) { - guint i; - guint8 *bufptr; + unsigned i; + uint8_t *bufptr; bufptr = buf; @@ -1025,13 +1025,13 @@ iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes) * Simple routine to convert an ASCII hex string to binary data * Requires ASCII hex data and buffer to populate with binary data */ -static gboolean -iseries_parse_hex_string (const char * ascii, guint8 * buf, size_t len) +static bool +iseries_parse_hex_string (const char * ascii, uint8_t * buf, size_t len) { size_t i; int byte; - gint hexvalue; - guint8 bytevalue; + int hexvalue; + uint8_t bytevalue; byte = 0; for (i = 0; i < len; i++) @@ -1039,18 +1039,18 @@ iseries_parse_hex_string (const char * ascii, guint8 * buf, size_t len) hexvalue = g_ascii_xdigit_value(ascii[i]); i++; if (hexvalue == -1) - return FALSE; /* not a valid hex digit */ - bytevalue = (guint8)(hexvalue << 4); + return false; /* not a valid hex digit */ + bytevalue = (uint8_t)(hexvalue << 4); if (i >= len) - return FALSE; /* only one hex digit of the byte is present */ + return false; /* only one hex digit of the byte is present */ hexvalue = g_ascii_xdigit_value(ascii[i]); if (hexvalue == -1) - return FALSE; /* not a valid hex digit */ - bytevalue |= (guint8) hexvalue; + return false; /* not a valid hex digit */ + bytevalue |= (uint8_t) hexvalue; buf[byte] = bytevalue; byte++; } - return TRUE; + return true; } static const struct supported_block_type iseries_blocks_supported[] = { @@ -1062,7 +1062,7 @@ static const struct supported_block_type iseries_blocks_supported[] = { static const struct file_type_subtype_info iseries_info = { "IBM iSeries comm. trace (ASCII)", "iseries_ascii", "txt", NULL, - FALSE, BLOCKS_SUPPORTED(iseries_blocks_supported), + false, BLOCKS_SUPPORTED(iseries_blocks_supported), NULL, NULL, NULL }; @@ -1075,7 +1075,7 @@ static const struct supported_block_type iseries_unicode_blocks_supported[] = { static const struct file_type_subtype_info iseries_unicode_info = { "IBM iSeries comm. trace (Unicode)", "iseries_unicode", "txt", NULL, - FALSE, BLOCKS_SUPPORTED(iseries_unicode_blocks_supported), + false, BLOCKS_SUPPORTED(iseries_unicode_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/iseries.h b/wiretap/iseries.h index a75e4905..1e00fd69 100644 --- a/wiretap/iseries.h +++ b/wiretap/iseries.h @@ -12,6 +12,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val iseries_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val iseries_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/json.c b/wiretap/json.c index e2213e95..3ffa8599 100644 --- a/wiretap/json.c +++ b/wiretap/json.c @@ -6,13 +6,13 @@ */ #include "config.h" +#include "json.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "json.h" #include <wsutil/wsjson.h> /* Maximum size of json file. */ @@ -22,14 +22,14 @@ static int json_file_type_subtype = -1; void register_json(void); -wtap_open_return_val json_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val json_open(wtap *wth, int *err, char **err_info) { - guint8* filebuf; + uint8_t* filebuf; int bytes_read; /* XXX checking the full file contents might be a bit expensive, maybe * resort to simpler heuristics like '{' or '[' (with some other chars)? */ - filebuf = (guint8*)g_malloc0(MAX_FILE_SIZE); + filebuf = (uint8_t*)g_malloc0(MAX_FILE_SIZE); if (!filebuf) return WTAP_OPEN_ERROR; @@ -46,7 +46,7 @@ wtap_open_return_val json_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_NOT_MINE; } - if (json_validate(filebuf, bytes_read) == FALSE) { + if (json_validate(filebuf, bytes_read) == false) { g_free(filebuf); return WTAP_OPEN_NOT_MINE; } @@ -78,7 +78,7 @@ static const struct supported_block_type json_blocks_supported[] = { static const struct file_type_subtype_info json_info = { "JavaScript Object Notation", "json", "json", NULL, - FALSE, BLOCKS_SUPPORTED(json_blocks_supported), + false, BLOCKS_SUPPORTED(json_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/json.h b/wiretap/json.h index cbca4fcf..a7b3c7fe 100644 --- a/wiretap/json.h +++ b/wiretap/json.h @@ -13,7 +13,7 @@ #include "wtap.h" -wtap_open_return_val json_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val json_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/k12.c b/wiretap/k12.c index f03e859d..79e758db 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -12,12 +12,13 @@ */ #include "config.h" +#include "k12.h" + #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "k12.h" #include <wsutil/str_util.h> #include <wsutil/glib-compat.h> @@ -46,10 +47,10 @@ void register_k12(void); #include <stdarg.h> #include <wsutil/file_util.h> -FILE* dbg_out = NULL; -char* env_file = NULL; +FILE* dbg_out; +char* env_file; -static unsigned int debug_level = 0; +static unsigned int debug_level; void k12_fprintf(const char* fmt, ...) { va_list ap; @@ -66,7 +67,7 @@ void k12_fprintf(const char* fmt, ...) { fprintf(dbg_out,"\n"); \ } } while(0) -void k12_hex_ascii_dump(guint level, gint64 offset, const char* label, const unsigned char* b, unsigned int len) { +void k12_hex_ascii_dump(unsigned level, int64_t offset, const char* label, const unsigned char* b, unsigned int len) { static const char* c2t[] = { "00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f", "10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f", @@ -111,8 +112,8 @@ void k12_hex_ascii_dump(guint level, gint64 offset, const char* label, const uns #define K12_HEX_ASCII_DUMP(x,a,b,c,d) k12_hex_ascii_dump(x,a,b,c,d) -void k12_ascii_dump(guint level, guint8 *buf, guint32 len, guint32 buf_offset) { - guint32 i; +void k12_ascii_dump(unsigned level, uint8_t *buf, uint32_t len, uint32_t buf_offset) { + uint32_t i; if (debug_level < level) return; @@ -185,7 +186,7 @@ void k12_ascii_dump(guint level, guint8 *buf, guint32 len, guint32 buf_offset) { /* * We use the first 8 bytes of the file header as a magic number. */ -static const guint8 k12_file_magic[] = { 0x00, 0x00, 0x02, 0x00 ,0x12, 0x05, 0x00, 0x10 }; +static const uint8_t k12_file_magic[] = { 0x00, 0x00, 0x02, 0x00 ,0x12, 0x05, 0x00, 0x10 }; #define K12_FILE_HDR_LEN 512 @@ -201,25 +202,25 @@ static const guint8 k12_file_magic[] = { 0x00, 0x00, 0x02, 0x00 ,0x12, 0x05, 0x0 #define K12_FILE_BLOB_LEN 16 typedef struct { - guint32 file_len; - guint32 num_of_records; /* XXX: not sure about this */ + uint32_t file_len; + uint32_t num_of_records; /* XXX: not sure about this */ - GHashTable* src_by_id; /* k12_srcdsc_recs by input */ - GHashTable* src_by_name; /* k12_srcdsc_recs by stack_name */ + GHashTable* src_by_id; /* k12_srcdsc_recs by input */ + GHashTable* src_by_name; /* k12_srcdsc_recs by stack_name */ - guint8 *seq_read_buff; /* read buffer for sequential reading */ - guint seq_read_buff_len; /* length of that buffer */ - guint8 *rand_read_buff; /* read buffer for random reading */ - guint rand_read_buff_len; /* length of that buffer */ + uint8_t *seq_read_buff; /* read buffer for sequential reading */ + unsigned seq_read_buff_len; /* length of that buffer */ + uint8_t *rand_read_buff; /* read buffer for random reading */ + unsigned rand_read_buff_len; /* length of that buffer */ - Buffer extra_info; /* Buffer to hold per packet extra information */ + Buffer extra_info; /* Buffer to hold per packet extra information */ } k12_t; typedef struct _k12_src_desc_t { - guint32 input; - guint32 input_type; - gchar* input_name; - gchar* stack_file; + uint32_t input; + uint32_t input_type; + char* input_name; + char* stack_file; k12_input_info_t input_info; } k12_src_desc_t; @@ -410,15 +411,15 @@ typedef struct _k12_src_desc_t { * * XXX: works at most with 8191 bytes per record */ -static gint get_record(k12_t *file_data, FILE_T fh, gint64 file_offset, - gboolean is_random, int *err, gchar **err_info) { - guint8 *buffer = is_random ? file_data->rand_read_buff : file_data->seq_read_buff; - guint buffer_len = is_random ? file_data->rand_read_buff_len : file_data->seq_read_buff_len; - guint total_read = 0; - guint left; - guint8* writep; +static int get_record(k12_t *file_data, FILE_T fh, int64_t file_offset, + bool is_random, int *err, char **err_info) { + uint8_t *buffer = is_random ? file_data->rand_read_buff : file_data->seq_read_buff; + unsigned buffer_len = is_random ? file_data->rand_read_buff_len : file_data->seq_read_buff_len; + unsigned total_read = 0; + unsigned left; + uint8_t* writep; #ifdef DEBUG_K12 - guint actual_len; + unsigned actual_len; #endif /* @@ -428,13 +429,13 @@ static gint get_record(k12_t *file_data, FILE_T fh, gint64 file_offset, * relative to the file header is a multiple of 8192, the * 16-byte blob is there. */ - guint junky_offset = 8192 - (gint) ( (file_offset - K12_FILE_HDR_LEN) % 8192 ); + unsigned junky_offset = 8192 - (int) ( (file_offset - K12_FILE_HDR_LEN) % 8192 ); K12_DBG(6,("get_record: ENTER: junky_offset=%" PRId64 ", file_offset=%" PRId64,junky_offset,file_offset)); /* no buffer is given, lets create it */ if (buffer == NULL) { - buffer = (guint8*)g_malloc(8192); + buffer = (uint8_t*)g_malloc(8192); buffer_len = 8192; if (is_random) { file_data->rand_read_buff = buffer; @@ -497,7 +498,7 @@ static gint get_record(k12_t *file_data, FILE_T fh, gint64 file_offset, * looping. */ while (left > buffer_len) { - buffer = (guint8*)g_realloc(buffer,buffer_len*=2); + buffer = (uint8_t*)g_realloc(buffer,buffer_len*=2); if (is_random) { file_data->rand_read_buff = buffer; file_data->rand_read_buff_len = buffer_len; @@ -551,30 +552,30 @@ static gint get_record(k12_t *file_data, FILE_T fh, gint64 file_offset, return total_read; } -static gboolean +static bool memiszero(const void *ptr, size_t count) { - const guint8 *p = (const guint8 *)ptr; + const uint8_t *p = (const uint8_t *)ptr; while (count != 0) { if (*p != 0) - return FALSE; + return false; p++; count--; } - return TRUE; + return true; } -static gboolean -process_packet_data(wtap_rec *rec, Buffer *target, guint8 *buffer, - guint record_len, k12_t *k12, int *err, gchar **err_info) +static bool +process_packet_data(wtap_rec *rec, Buffer *target, uint8_t *buffer, + unsigned record_len, k12_t *k12, int *err, char **err_info) { - guint32 type; - guint buffer_offset; - guint64 ts; - guint32 length; - guint32 extra_len; - guint32 src_id; + uint32_t type; + unsigned buffer_offset; + uint64_t ts; + uint32_t length; + uint32_t extra_len; + uint32_t src_id; k12_src_desc_t* src_desc; type = pntoh32(buffer + K12_RECORD_TYPE); @@ -583,7 +584,7 @@ process_packet_data(wtap_rec *rec, Buffer *target, guint8 *buffer, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("k12: Frame data offset %u > record length %u", buffer_offset, record_len); - return FALSE; + return false; } length = pntoh32(buffer + K12_RECORD_FRAME_LEN) & 0x00001FFF; @@ -591,7 +592,7 @@ process_packet_data(wtap_rec *rec, Buffer *target, guint8 *buffer, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("k12: Frame length %u > record frame data %u", length, record_len - buffer_offset); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -601,7 +602,7 @@ process_packet_data(wtap_rec *rec, Buffer *target, guint8 *buffer, ts = pntoh64(buffer + K12_PACKET_TIMESTAMP); rec->ts.secs = (time_t) ((ts / 2000000) + 631152000); - rec->ts.nsecs = (guint32) ( (ts % 2000000) * 500 ); + rec->ts.nsecs = (uint32_t) ( (ts % 2000000) * 500 ); rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen = length; @@ -613,7 +614,7 @@ process_packet_data(wtap_rec *rec, Buffer *target, guint8 *buffer, ws_buffer_assure_space(&(k12->extra_info), extra_len); memcpy(ws_buffer_start_ptr(&(k12->extra_info)), buffer + buffer_offset + length, extra_len); - rec->rec_header.packet_header.pseudo_header.k12.extra_info = (guint8*)ws_buffer_start_ptr(&(k12->extra_info)); + rec->rec_header.packet_header.pseudo_header.k12.extra_info = (uint8_t*)ws_buffer_start_ptr(&(k12->extra_info)); rec->rec_header.packet_header.pseudo_header.k12.extra_length = extra_len; src_id = pntoh32(buffer + K12_RECORD_SRC_ID); @@ -660,17 +661,17 @@ process_packet_data(wtap_rec *rec, Buffer *target, guint8 *buffer, rec->rec_header.packet_header.pseudo_header.k12.input = src_id; rec->rec_header.packet_header.pseudo_header.k12.stuff = k12; - return TRUE; + return true; } -static gboolean k12_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { +static bool k12_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, int64_t *data_offset) { k12_t *k12 = (k12_t *)wth->priv; k12_src_desc_t* src_desc; - guint8* buffer; - gint64 offset; - gint len; - guint32 type; - guint32 src_id; + uint8_t* buffer; + int64_t offset; + int len; + uint32_t type; + uint32_t src_id; offset = file_tell(wth->fh); @@ -679,27 +680,27 @@ static gboolean k12_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar if ( k12->num_of_records == 0 ) { /* No more records */ *err = 0; - return FALSE; + return false; } K12_DBG(5,("k12_read: offset=%i",offset)); *data_offset = offset; - len = get_record(k12, wth->fh, offset, FALSE, err, err_info); + len = get_record(k12, wth->fh, offset, false, err, err_info); if (len < 0) { /* read error */ - return FALSE; + return false; } else if (len == 0) { /* EOF */ *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } else if (len < K12_RECORD_SRC_ID + 4) { /* Record not large enough to contain a src ID */ *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("k12: Data record length %d too short", len); - return FALSE; + return false; } k12->num_of_records--; @@ -726,37 +727,37 @@ static gboolean k12_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar } while ( ((type & K12_MASK_PACKET) != K12_REC_PACKET && (type & K12_MASK_PACKET) != K12_REC_D0020) || !src_id || !src_desc ); - return process_packet_data(rec, buf, buffer, (guint)len, k12, err, err_info); + return process_packet_data(rec, buf, buffer, (unsigned)len, k12, err, err_info); } -static gboolean k12_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { +static bool k12_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { k12_t *k12 = (k12_t *)wth->priv; - guint8* buffer; - gint len; - gboolean status; + uint8_t* buffer; + int len; + bool status; K12_DBG(5,("k12_seek_read: ENTER")); if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { K12_DBG(5,("k12_seek_read: SEEK ERROR")); - return FALSE; + return false; } - len = get_record(k12, wth->random_fh, seek_off, TRUE, err, err_info); + len = get_record(k12, wth->random_fh, seek_off, true, err, err_info); if (len < 0) { K12_DBG(5,("k12_seek_read: READ ERROR")); - return FALSE; + return false; } else if (len < K12_RECORD_SRC_ID + 4) { /* Record not large enough to contain a src ID */ K12_DBG(5,("k12_seek_read: SHORT READ")); *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } buffer = k12->rand_read_buff; - status = process_packet_data(rec, buf, buffer, (guint)len, k12, err, err_info); + status = process_packet_data(rec, buf, buffer, (unsigned)len, k12, err, err_info); K12_DBG(5,("k12_seek_read: DONE OK")); @@ -781,14 +782,14 @@ static k12_t* new_k12_file_data(void) { return fd; } -static gboolean destroy_srcdsc(gpointer k _U_, gpointer v, gpointer p _U_) { +static gboolean destroy_srcdsc(void *k _U_, void *v, void *p _U_) { k12_src_desc_t* rec = (k12_src_desc_t*)v; g_free(rec->input_name); g_free(rec->stack_file); g_free(rec); - return TRUE; + return true; } static void destroy_k12_file_data(k12_t* fd) { @@ -813,23 +814,23 @@ static void k12_close(wtap *wth) { } -wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) { +wtap_open_return_val k12_open(wtap *wth, int *err, char **err_info) { k12_src_desc_t* rec; - guint8 header_buffer[K12_FILE_HDR_LEN]; - guint8* read_buffer; - guint32 type; + uint8_t header_buffer[K12_FILE_HDR_LEN]; + uint8_t* read_buffer; + uint32_t type; long offset; long len; - guint port_type; - guint32 rec_len; - guint32 hwpart_len; - guint32 name_len; - guint32 stack_len; - guint i; + unsigned port_type; + uint32_t rec_len; + uint32_t hwpart_len; + uint32_t name_len; + uint32_t stack_len; + unsigned i; k12_t* file_data; #ifdef DEBUG_K12 - gchar* env_level = getenv("K12_DEBUG_LEVEL"); + char* env_level = getenv("K12_DEBUG_LEVEL"); env_file = getenv("K12_DEBUG_FILENAME"); if ( env_file ) { dbg_out = ws_fopen(env_file,"w"); @@ -905,7 +906,7 @@ wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) { return WTAP_OPEN_ERROR; } - len = get_record(file_data, wth->fh, offset, FALSE, err, err_info); + len = get_record(file_data, wth->fh, offset, false, err, err_info); if ( len < 0 ) { K12_DBG(1,("k12_open: BAD HEADER RECORD",len)); @@ -1063,8 +1064,8 @@ wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) { g_free(rec); return WTAP_OPEN_ERROR; } - rec->input_name = (gchar *)g_memdup2(read_buffer + K12_SRCDESC_HWPART + hwpart_len, name_len); - rec->stack_file = (gchar *)g_memdup2(read_buffer + K12_SRCDESC_HWPART + hwpart_len + name_len, stack_len); + rec->input_name = (char *)g_memdup2(read_buffer + K12_SRCDESC_HWPART + hwpart_len, name_len); + rec->stack_file = (char *)g_memdup2(read_buffer + K12_SRCDESC_HWPART + hwpart_len + name_len, stack_len); ascii_strdown_inplace (rec->stack_file); @@ -1108,9 +1109,9 @@ wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) { } typedef struct { - guint32 file_len; - guint32 num_of_records; - guint32 file_offset; + uint32_t file_len; + uint32_t num_of_records; + uint32_t file_offset; } k12_dump_t; static int k12_dump_can_write_encap(int encap) { @@ -1124,79 +1125,79 @@ static int k12_dump_can_write_encap(int encap) { return 0; } -static const gchar dumpy_junk[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; +static const char dumpy_junk[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; -static gboolean k12_dump_record(wtap_dumper *wdh, guint32 len, guint8* buffer, int *err_p) { +static bool k12_dump_record(wtap_dumper *wdh, uint32_t len, uint8_t* buffer, int *err_p) { k12_dump_t *k12 = (k12_dump_t *)wdh->priv; - guint32 junky_offset = (8192 - ( (k12->file_offset - K12_FILE_HDR_LEN) % 8192 )) % 8192; + uint32_t junky_offset = (8192 - ( (k12->file_offset - K12_FILE_HDR_LEN) % 8192 )) % 8192; if (len > junky_offset) { if (junky_offset) { if (! wtap_dump_file_write(wdh, buffer, junky_offset, err_p)) - return FALSE; + return false; } if (! wtap_dump_file_write(wdh, dumpy_junk, K12_FILE_BLOB_LEN, err_p)) - return FALSE; + return false; if (! wtap_dump_file_write(wdh, buffer+junky_offset, len - junky_offset, err_p)) - return FALSE; + return false; k12->file_offset += len + K12_FILE_BLOB_LEN; k12->file_len += len + K12_FILE_BLOB_LEN; } else { if (! wtap_dump_file_write(wdh, buffer, len, err_p)) - return FALSE; + return false; k12->file_offset += len; k12->file_len += len; } k12->num_of_records++; - return TRUE; + return true; } -static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) { +static void k12_dump_src_setting(void *k _U_, void *v, void *p) { k12_src_desc_t* src_desc = (k12_src_desc_t*)v; wtap_dumper *wdh = (wtap_dumper *)p; - guint32 len; - guint offset; - guint i; + uint32_t len; + unsigned offset; + unsigned i; int errxxx; /* dummy */ union { - guint8 buffer[8192]; + uint8_t buffer[8192]; struct { - guint32 len; - guint32 type; - guint32 unk32_1; - guint32 input; + uint32_t len; + uint32_t type; + uint32_t unk32_1; + uint32_t input; - guint16 unk32_2; - guint16 color; - guint32 unk32_3; - guint32 unk32_4; - guint16 unk16_1; - guint16 hwpart_len; + uint16_t unk32_2; + uint16_t color; + uint32_t unk32_3; + uint32_t unk32_4; + uint16_t unk16_1; + uint16_t hwpart_len; - guint16 name_len; - guint16 stack_len; + uint16_t name_len; + uint16_t stack_len; struct { - guint32 type; + uint32_t type; union { struct { - guint32 unk32; - guint8 mask[32]; + uint32_t unk32; + uint8_t mask[32]; } ds0mask; struct { - guint8 unk_data[16]; - guint16 vp; - guint16 vc; + uint8_t unk_data[16]; + uint16_t vp; + uint16_t vc; } atm; - guint32 unk; + uint32_t unk; } desc; } extra; } record; @@ -1218,8 +1219,8 @@ static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) { } obj.record.unk16_1 = g_htons(0x0000); - obj.record.name_len = (guint16) strlen(src_desc->input_name) + 1; - obj.record.stack_len = (guint16) strlen(src_desc->stack_file) + 1; + obj.record.name_len = (uint16_t) strlen(src_desc->input_name) + 1; + obj.record.stack_len = (uint16_t) strlen(src_desc->stack_file) + 1; obj.record.extra.type = g_htonl(src_desc->input_type); @@ -1262,31 +1263,31 @@ static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) { k12_dump_record(wdh,len,obj.buffer, &errxxx); /* fwrite errs ignored: see k12_dump below */ } -static gboolean k12_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) { +static bool k12_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; k12_dump_t *k12 = (k12_dump_t *)wdh->priv; - guint32 len; + uint32_t len; union { - guint8 buffer[8192]; + uint8_t buffer[8192]; struct { - guint32 len; - guint32 type; - guint32 frame_len; - guint32 input; + uint32_t len; + uint32_t type; + uint32_t frame_len; + uint32_t input; - guint32 datum_1; - guint32 datum_2; - guint64 ts; + uint32_t datum_1; + uint32_t datum_2; + uint64_t ts; - guint8 frame[0x1fc0]; + uint8_t frame[0x1fc0]; } record; } obj; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -1295,7 +1296,7 @@ static gboolean k12_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } if (k12->num_of_records == 0) { @@ -1318,75 +1319,75 @@ static gboolean k12_dump(wtap_dumper *wdh, const wtap_rec *rec, obj.record.frame_len = g_htonl(rec->rec_header.packet_header.caplen); obj.record.input = g_htonl(pseudo_header->k12.input); - obj.record.ts = GUINT64_TO_BE((((guint64)rec->ts.secs - 631152000) * 2000000) + (rec->ts.nsecs / 1000 * 2)); + obj.record.ts = GUINT64_TO_BE((((uint64_t)rec->ts.secs - 631152000) * 2000000) + (rec->ts.nsecs / 1000 * 2)); memcpy(obj.record.frame,pd,rec->rec_header.packet_header.caplen); return k12_dump_record(wdh,len,obj.buffer, err); } -static const guint8 k12_eof[] = {0xff,0xff}; +static const uint8_t k12_eof[] = {0xff,0xff}; -static gboolean k12_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info _U_) { +static bool k12_dump_finish(wtap_dumper *wdh, int *err, char **err_info _U_) { k12_dump_t *k12 = (k12_dump_t *)wdh->priv; union { - guint8 b[sizeof(guint32)]; - guint32 u; + uint8_t b[sizeof(uint32_t)]; + uint32_t u; } d; if (! wtap_dump_file_write(wdh, k12_eof, 2, err)) - return FALSE; + return false; k12->file_len += 2; if (wtap_dump_file_seek(wdh, K12_FILE_HDR_FILE_SIZE, SEEK_SET, err) == -1) - return FALSE; + return false; d.u = g_htonl(k12->file_len); if (! wtap_dump_file_write(wdh, d.b, 4, err)) - return FALSE; + return false; if (wtap_dump_file_seek(wdh, K12_FILE_HDR_PAGE_SIZE, SEEK_SET, err) == -1) - return FALSE; + return false; d.u = g_htonl(8192); if (! wtap_dump_file_write(wdh, d.b, 4, err)) - return FALSE; + return false; if (wtap_dump_file_seek(wdh, K12_FILE_HDR_RECORD_COUNT_1, SEEK_SET, err) == -1) - return FALSE; + return false; d.u = g_htonl(k12->num_of_records); if (! wtap_dump_file_write(wdh, d.b, 4, err)) - return FALSE; + return false; if (wtap_dump_file_seek(wdh, K12_FILE_HDR_RECORD_COUNT_2, SEEK_SET, err) == -1) - return FALSE; + return false; d.u = g_htonl(k12->num_of_records); if (! wtap_dump_file_write(wdh, d.b, 4, err)) - return FALSE; + return false; /* Prevent the above calls to wtap_dump_file_write() from * double-counting the header length */ wdh->bytes_dumped = k12->file_len; - return TRUE; + return true; } -static gboolean k12_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) { +static bool k12_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { k12_dump_t *k12; if ( ! wtap_dump_file_write(wdh, k12_file_magic, 8, err)) { - return FALSE; + return false; } if (wtap_dump_file_seek(wdh, K12_FILE_HDR_LEN, SEEK_SET, err) == -1) - return FALSE; + return false; wdh->bytes_dumped = K12_FILE_HDR_LEN; wdh->subtype_write = k12_dump; @@ -1398,7 +1399,7 @@ static gboolean k12_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) k12->num_of_records = 0; k12->file_offset = K12_FILE_HDR_LEN; - return TRUE; + return true; } static const struct supported_block_type k12_blocks_supported[] = { @@ -1410,7 +1411,7 @@ static const struct supported_block_type k12_blocks_supported[] = { static const struct file_type_subtype_info k12_info = { "Tektronix K12xx 32-bit .rf5 format", "rf5", "rf5", NULL, - TRUE, BLOCKS_SUPPORTED(k12_blocks_supported), + true, BLOCKS_SUPPORTED(k12_blocks_supported), k12_dump_can_write_encap, k12_dump_open, NULL }; diff --git a/wiretap/k12.h b/wiretap/k12.h index b0d7fa2f..30884396 100644 --- a/wiretap/k12.h +++ b/wiretap/k12.h @@ -12,8 +12,8 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info); -wtap_open_return_val k12text_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val k12_open(wtap *wth, int *err, char **err_info); +wtap_open_return_val k12text_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/k12text.l b/wiretap/k12text.l index 7ba4587c..fc61251d 100644 --- a/wiretap/k12text.l +++ b/wiretap/k12text.l @@ -114,33 +114,33 @@ DIAG_OFF_FLEX() typedef struct { FILE_T fh; int err; - gchar *err_info; + char *err_info; int start_state; - guint g_h; - guint g_m; - guint g_s; - guint g_ms; - guint g_ns; - gint g_encap; - guint8 *bb; - guint ii; - gboolean is_k12text; - gboolean at_eof; - guint junk_chars; - gchar* error_str; - guint64 file_bytes_read; - gboolean ok_frame; + unsigned g_h; + unsigned g_m; + unsigned g_s; + unsigned g_ms; + unsigned g_ns; + int g_encap; + uint8_t *bb; + unsigned ii; + bool is_k12text; + bool at_eof; + unsigned junk_chars; + char* error_str; + uint64_t file_bytes_read; + bool ok_frame; } k12text_state_t; #define KERROR(text) do { yyextra->error_str = g_strdup(text); yyterminate(); } while(0) -#define SET_HOURS(text) yyextra->g_h = (guint) strtoul(text,NULL,10) -#define SET_MINUTES(text) yyextra->g_m = (guint) strtoul(text,NULL,10) -#define SET_SECONDS(text) yyextra->g_s = (guint) strtoul(text,NULL,10) -#define SET_MS(text) yyextra->g_ms = (guint) strtoul(text,NULL,10) -#define SET_NS(text) yyextra->g_ns = (guint) strtoul(text,NULL,10) -#define ADD_BYTE(text) do {if (yyextra->ii >= WTAP_MAX_PACKET_SIZE_STANDARD) {KERROR("frame too large");} yyextra->bb[yyextra->ii++] = (guint8)strtoul(text,NULL,16); } while(0) -#define FINALIZE_FRAME() do { yyextra->ok_frame = TRUE; } while (0) +#define SET_HOURS(text) yyextra->g_h = (unsigned) strtoul(text,NULL,10) +#define SET_MINUTES(text) yyextra->g_m = (unsigned) strtoul(text,NULL,10) +#define SET_SECONDS(text) yyextra->g_s = (unsigned) strtoul(text,NULL,10) +#define SET_MS(text) yyextra->g_ms = (unsigned) strtoul(text,NULL,10) +#define SET_NS(text) yyextra->g_ns = (unsigned) strtoul(text,NULL,10) +#define ADD_BYTE(text) do {if (yyextra->ii >= WTAP_MAX_PACKET_SIZE_STANDARD) {KERROR("frame too large");} yyextra->bb[yyextra->ii++] = (uint8_t)strtoul(text,NULL,16); } while(0) +#define FINALIZE_FRAME() do { yyextra->ok_frame = true; } while (0) /*~ #define ECHO*/ #define YY_USER_ACTION yyextra->file_bytes_read += yyleng; #define YY_USER_INIT { \ @@ -176,7 +176,7 @@ typedef struct { * each call to k12text_read(), since the lexer undoubtedly did some * amount of look-ahead when processing the previous frame. */ - gint64 next_frame_offset; + int64_t next_frame_offset; } k12text_t; /* @@ -214,9 +214,9 @@ hdlc HDLC %START MAGIC NEXT_FRAME HOURS MINUTES M2S SECONDS S2M MS M2N NS ENCAP STARTBYTES BYTE %% -<MAGIC>{start_timestamp} { yyextra->is_k12text = TRUE; yyterminate(); } +<MAGIC>{start_timestamp} { yyextra->is_k12text = true; yyterminate(); } -<MAGIC>. { if (++ yyextra->junk_chars > MAX_JUNK) { yyextra->is_k12text = FALSE; yyterminate(); } } +<MAGIC>. { if (++ yyextra->junk_chars > MAX_JUNK) { yyextra->is_k12text = false; yyterminate(); } } <NEXT_FRAME>{start_timestamp} {BEGIN(HOURS); } <HOURS>{oneormoredigits} { SET_HOURS(yytext); BEGIN(MINUTES); } @@ -238,7 +238,7 @@ hdlc HDLC <BYTE>{end_bytes} { FINALIZE_FRAME(); yyterminate(); } . { if (++yyextra->junk_chars > MAX_JUNK) { KERROR("too much junk"); } } -<<EOF>> { yyextra->at_eof = TRUE; yyterminate(); } +<<EOF>> { yyextra->at_eof = true; yyterminate(); } %% @@ -249,9 +249,9 @@ DIAG_ON_FLEX() /* Fill in pkthdr */ -static gboolean +static bool k12text_set_headers(wtap_rec *rec, k12text_state_t *state, - int *err, gchar **err_info) + int *err, char **err_info) { rec->rec_type = REC_TYPE_PACKET; rec->block = wtap_block_create(WTAP_BLOCK_PACKET); @@ -278,19 +278,19 @@ k12text_set_headers(wtap_rec *rec, k12text_state_t *state, /* pseudo_header for these types. */ *err = WTAP_ERR_UNSUPPORTED; *err_info = g_strdup("k12text: MTP2 packets not yet supported"); - return FALSE; + return false; case WTAP_ENCAP_ATM_PDUS: /* not (yet) supported */ /* XXX: I don't know how to fill in the */ /* pseudo_header for these types. */ *err = WTAP_ERR_UNSUPPORTED; *err_info = g_strdup("k12text: SSCOP packets not yet supported"); - return FALSE; + return false; default: *err = WTAP_ERR_UNSUPPORTED; *err_info = g_strdup("k12text: unknown encapsulation type"); - return FALSE; + return false; } - return TRUE; + return true; } /* Note: k12text_reset is called each time data is to be processed from */ @@ -300,9 +300,9 @@ k12text_set_headers(wtap_rec *rec, k12text_state_t *state, /* used even when multiple files are open simultaneously (as for */ /* a file merge). */ -static gboolean +static bool k12text_run_scanner(k12text_state_t *state, FILE_T fh, int start_state, - int *err, gchar **err_info) + int *err, char **err_info) { yyscan_t scanner = NULL; @@ -310,7 +310,7 @@ k12text_run_scanner(k12text_state_t *state, FILE_T fh, int start_state, /* errno is set if this fails */ *err = errno; *err_info = NULL; - return FALSE; + return false; } state->fh = fh; state->err = 0; @@ -318,9 +318,9 @@ k12text_run_scanner(k12text_state_t *state, FILE_T fh, int start_state, state->start_state = start_state; state->g_encap = WTAP_ENCAP_UNKNOWN; - state->ok_frame = FALSE; - state->is_k12text = FALSE; - state->at_eof = FALSE; + state->ok_frame = false; + state->is_k12text = false; + state->at_eof = false; state->junk_chars = 0; state->error_str = NULL; state->file_bytes_read=0; @@ -340,13 +340,13 @@ k12text_run_scanner(k12text_state_t *state, FILE_T fh, int start_state, /* I/O error. */ *err = state->err; *err_info = state->err_info; - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean -k12text_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char ** err_info, gint64 *data_offset) +static bool +k12text_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char ** err_info, int64_t *data_offset) { k12text_t *k12text = (k12text_t *)wth->priv; k12text_state_t state; @@ -361,16 +361,16 @@ k12text_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char ** err_info, */ if ( file_seek(wth->fh, k12text->next_frame_offset, SEEK_SET, err) == -1) { - return FALSE; + return false; } - state.bb = (guint8*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); + state.bb = (uint8_t*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); if (!k12text_run_scanner(&state, wth->fh, NEXT_FRAME, err, err_info)) { g_free(state.bb); - return FALSE; + return false; } - if (state.ok_frame == FALSE) { + if (state.ok_frame == false) { if (state.at_eof) { *err = 0; *err_info = NULL; @@ -379,7 +379,7 @@ k12text_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char ** err_info, *err_info = state.error_str; } g_free(state.bb); - return FALSE; + return false; } *data_offset = k12text->next_frame_offset; /* file position for beginning of this frame */ @@ -387,31 +387,31 @@ k12text_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char ** err_info, if (!k12text_set_headers(rec, &state, err, err_info)) { g_free(state.bb); - return FALSE; + return false; } ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); memcpy(ws_buffer_start_ptr(buf), state.bb, rec->rec_header.packet_header.caplen); g_free(state.bb); - return TRUE; + return true; } -static gboolean -k12text_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) +static bool +k12text_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { k12text_state_t state; if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return FALSE; + return false; } - state.bb = (guint8*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); + state.bb = (uint8_t*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); if (!k12text_run_scanner(&state, wth->random_fh, NEXT_FRAME, err, err_info)) { g_free(state.bb); - return FALSE; + return false; } - if (state.ok_frame == FALSE) { + if (state.ok_frame == false) { *err = WTAP_ERR_BAD_FILE; if (state.at_eof) { /* What happened ? The desired frame was previously read without a problem */ @@ -420,27 +420,27 @@ k12text_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *e *err_info = state.error_str; } g_free(state.bb); - return FALSE; + return false; } if (!k12text_set_headers(rec, &state, err, err_info)) { g_free(state.bb); - return FALSE; + return false; } ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen); memcpy(ws_buffer_start_ptr(buf), state.bb, rec->rec_header.packet_header.caplen); g_free(state.bb); - return TRUE; + return true; } wtap_open_return_val -k12text_open(wtap *wth, int *err, gchar **err_info) +k12text_open(wtap *wth, int *err, char **err_info) { k12text_t *k12text; k12text_state_t state; - state.bb = (guint8*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); + state.bb = (uint8_t*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); if (!k12text_run_scanner(&state, wth->fh, MAGIC, err, err_info)) { g_free(state.bb); return WTAP_OPEN_ERROR; @@ -483,25 +483,25 @@ static const struct { int e; const char* s; } encaps[] = { { 0, NULL } }; -static gboolean +static bool k12text_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) { + const uint8_t *pd, int *err, char **err_info _U_) { #define K12BUF_SIZE 196808 char *buf; size_t left = K12BUF_SIZE; size_t wl; char *p; const char* str_enc; - guint i; - guint ns; - guint ms; - gboolean ret; + unsigned i; + unsigned ns; + unsigned ms; + bool ret; struct tm *tmp; /* Don't write anything bigger than we're willing to read. */ if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } str_enc = NULL; @@ -516,7 +516,7 @@ k12text_dump(wtap_dumper *wdh, const wtap_rec *rec, * That encapsulation type is not supported. Fail. */ *err = WTAP_ERR_UNWRITABLE_ENCAP; - return FALSE; + return false; } buf = (char *)g_malloc(K12BUF_SIZE); @@ -554,12 +554,12 @@ k12text_dump(wtap_dumper *wdh, const wtap_rec *rec, } -static gboolean -k12text_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) +static bool +k12text_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { wdh->subtype_write = k12text_dump; - return TRUE; + return true; } static int @@ -587,7 +587,7 @@ static const struct supported_block_type k12text_blocks_supported[] = { static const struct file_type_subtype_info k12text_info = { "K12 text file", "k12text", "txt", NULL, - FALSE, BLOCKS_SUPPORTED(k12text_blocks_supported), + false, BLOCKS_SUPPORTED(k12text_blocks_supported), k12text_dump_can_write_encap, k12text_dump_open, NULL }; diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c index 642db819..97b19b05 100644 --- a/wiretap/lanalyzer.c +++ b/wiretap/lanalyzer.c @@ -9,12 +9,12 @@ #include "config.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP +#include "lanalyzer.h" #include <stdlib.h> #include <errno.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "lanalyzer.h" /* The LANalyzer format is documented (at least in part) in Novell document TID022037, which can be found at, among other places: @@ -25,8 +25,8 @@ /* Record header format */ typedef struct { - guint8 record_type[2]; - guint8 record_length[2]; + uint8_t record_type[2]; + uint8_t record_length[2]; } LA_RecordHeader; #define LA_RecordHeaderSize 4 @@ -49,8 +49,8 @@ typedef struct { #define LA_ProFileLimit (1024 * 1024 * 32) -typedef guint8 Eadr[6]; -typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */ +typedef uint8_t Eadr[6]; +typedef uint16_t TimeStamp[3]; /* 0.5 microseconds since start of trace */ /* * These records have only 2-byte alignment for 4-byte quantities, @@ -60,19 +60,19 @@ typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */ /* * typedef struct { - * guint8 day; - * guint8 mon; - * gint16 year; + * uint8_t day; + * uint8_t mon; + * int16_t year; * } Date; */ /* * typedef struct { - * guint8 second; - * guint8 minute; - * guint8 hour; - * guint8 day; - * gint16 reserved; + * uint8_t second; + * uint8_t minute; + * uint8_t hour; + * uint8_t day; + * int16_t reserved; * } Time; */ @@ -85,16 +85,16 @@ typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */ * Time timeopn; * Time timeclo; * Eadr statadr; - * gint16 mxseqno; - * gint16 slcoff; - * gint16 mxslc; - * gint32 totpktt; - * gint32 statrg; - * gint32 stptrg; - * gint32 mxpkta[36]; - * gint16 board_type; - * gint16 board_version; - * gint8 reserved[18]; + * int16_t mxseqno; + * int16_t slcoff; + * int16_t mxslc; + * int32_t totpktt; + * int32_t statrg; + * int32_t stptrg; + * int32_t mxpkta[36]; + * int16_t board_type; + * int16_t board_version; + * int8_t reserved[18]; * } Summary; */ @@ -102,8 +102,8 @@ typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */ /* * typedef struct { - * gint16 rid; - * gint16 rlen; + * int16_t rid; + * int16_t rlen; * Summary s; * } LA_SummaryRecord; */ @@ -118,10 +118,10 @@ typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */ /* * typedef struct { - * gint16 rid; - * gint16 rlen; - * gint16 seqno; - * gint32 totpktf; + * int16_t rid; + * int16_t rlen; + * int16_t seqno; + * int32_t totpktf; * } LA_SubfileSummaryRecord; */ @@ -132,13 +132,13 @@ typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */ /* * typedef struct { - * gint16 rid; - * gint16 rlen; - * gint16 idxsp; = LA_IndexSize - * gint16 idxct; - * gint8 idxgranu; - * gint8 idxvd; - * gint32 trcidx[LA_IndexSize + 2]; +2 undocumented but used by La 2.2 + * int16_t rid; + * int16_t rlen; + * int16_t idxsp; = LA_IndexSize + * int16_t idxct; + * int8_t idxgranu; + * int8_t idxvd; + * int32_t trcidx[LA_IndexSize + 2]; +2 undocumented but used by La 2.2 * } LA_IndexRecord; */ @@ -147,19 +147,19 @@ typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */ /* * typedef struct { - * guint16 rx_channels; - * guint16 rx_errors; - * gint16 rx_frm_len; - * gint16 rx_frm_sln; + * uint16_t rx_channels; + * uint16_t rx_errors; + * int16_t rx_frm_len; + * int16_t rx_frm_sln; * TimeStamp rx_time; - * guint32 pktno; - * gint16 prvlen; - * gint16 offset; - * gint16 tx_errs; - * gint16 rx_filters; - * gint8 unused[2]; - * gint16 hwcolls; - * gint16 hwcollschans; + * uint32_t pktno; + * int16_t prvlen; + * int16_t offset; + * int16_t tx_errs; + * int16_t rx_filters; + * int8_t unused[2]; + * int16_t hwcolls; + * int16_t hwcollschans; * Packetdata ....; * } LA_PacketRecord; */ @@ -167,14 +167,14 @@ typedef guint16 TimeStamp[3]; /* 0.5 microseconds since start of trace */ #define LA_PacketRecordSize 32 typedef struct { - gboolean init; + bool init; nstime_t start; - guint32 pkts; + uint32_t pkts; int encap; int lastlen; } LA_TmpInfo; -static const guint8 LA_HeaderRegularFake[] = { +static const uint8_t LA_HeaderRegularFake[] = { 0x01,0x10,0x4c,0x00,0x01,0x05,0x54,0x72,0x61,0x63,0x65,0x20,0x44,0x69,0x73,0x70, 0x6c,0x61,0x79,0x20,0x54,0x72,0x61,0x63,0x65,0x20,0x46,0x69,0x6c,0x65,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -182,7 +182,7 @@ static const guint8 LA_HeaderRegularFake[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; -static const guint8 LA_RxChannelNameFake[] = { +static const uint8_t LA_RxChannelNameFake[] = { 0x06,0x10,0x80,0x00,0x43,0x68,0x61,0x6e ,0x6e,0x65,0x6c,0x31,0x00,0x43,0x68,0x61, 0x6e,0x6e,0x65,0x6c,0x32,0x00,0x43,0x68 ,0x61,0x6e,0x6e,0x65,0x6c,0x33,0x00,0x43, 0x68,0x61,0x6e,0x6e,0x65,0x6c,0x34,0x00 ,0x43,0x68,0x61,0x6e,0x6e,0x65,0x6c,0x35, @@ -194,14 +194,14 @@ static const guint8 LA_RxChannelNameFake[] = { 0x00,0x00,0x00,0x00 }; -static const guint8 LA_TxChannelNameFake[] = { +static const uint8_t LA_TxChannelNameFake[] = { 0x0b,0x10,0x36,0x00 ,0x54,0x72,0x61,0x6e,0x73,0x31,0x00,0x00, 0x00,0x54,0x72,0x61,0x6e,0x73,0x32,0x00 ,0x00,0x00,0x54,0x72,0x61,0x6e,0x73,0x33, 0x00,0x00,0x00,0x54,0x72,0x61,0x6e,0x73 ,0x34,0x00,0x00,0x00,0x54,0x72,0x61,0x6e, 0x73,0x35,0x00,0x00,0x00,0x54,0x72,0x61 ,0x6e,0x73,0x36,0x00,0x00,0x00 }; -static const guint8 LA_RxTemplateNameFake[] = { +static const uint8_t LA_RxTemplateNameFake[] = { 0x35,0x10, 0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -215,14 +215,14 @@ static const guint8 LA_RxTemplateNameFake[] = { 0x00,0x00 }; -static const guint8 LA_TxTemplateNameFake[] = { +static const uint8_t LA_TxTemplateNameFake[] = { 0x36,0x10,0x36,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00 }; -static const guint8 LA_DisplayOptionsFake[] = { +static const uint8_t LA_DisplayOptionsFake[] = { 0x0a,0x10,0x0a,0x01, 0x00,0x00,0x01,0x00,0x01,0x02,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -243,13 +243,13 @@ static const guint8 LA_DisplayOptionsFake[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00 }; -static const guint8 LA_CyclicInformationFake[] = { +static const uint8_t LA_CyclicInformationFake[] = { 0x09,0x10,0x1a,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; -static const guint8 z64[64] = { +static const uint8_t z64[64] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -260,28 +260,28 @@ typedef struct { time_t start; } lanalyzer_t; -static gboolean lanalyzer_read(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info, gint64 *data_offset); -static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean lanalyzer_dump_finish(wtap_dumper *wdh, int *err, - gchar **err_info); +static bool lanalyzer_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err, char **err_info, int64_t *data_offset); +static bool lanalyzer_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool lanalyzer_dump_finish(wtap_dumper *wdh, int *err, + char **err_info); static int lanalyzer_file_type_subtype = -1; void register_lanalyzer(void); -wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val lanalyzer_open(wtap *wth, int *err, char **err_info) { LA_RecordHeader rec_header; char header_fixed[2]; char *comment; - gboolean found_summary; + bool found_summary; char summary[210]; - guint16 board_type, mxslc; - guint16 record_type, record_length; - guint8 cr_day, cr_month; - guint16 cr_year; + uint16_t board_type, mxslc; + uint16_t record_type, record_length; + uint8_t cr_day, cr_month; + uint16_t cr_year; struct tm tm; time_t start; int file_encap; @@ -341,7 +341,7 @@ wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info) * If we don't have a summary record, we don't know the link-layer * header type, so we can't read the file. */ - found_summary = FALSE; + found_summary = false; while (1) { if (!wtap_read_bytes_or_eof(wth->fh, &rec_header, LA_RecordHeaderSize, err, err_info)) { @@ -419,7 +419,7 @@ wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info) *err_info = ws_strdup_printf("lanalyzer: file has more than one summary record"); return WTAP_OPEN_ERROR; } - found_summary = TRUE; + found_summary = true; /* Skip the rest of the record */ record_length -= sizeof summary; @@ -481,25 +481,25 @@ done: #define DESCRIPTOR_LEN 32 -static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool lanalyzer_read_trace_record(wtap *wth, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { char LE_record_type[2]; char LE_record_length[2]; - guint16 record_type, record_length; + uint16_t record_type, record_length; int record_data_size; int packet_size; - gchar descriptor[DESCRIPTOR_LEN]; + char descriptor[DESCRIPTOR_LEN]; lanalyzer_t *lanalyzer; - guint16 time_low, time_med, time_high, true_size; - guint64 t; + uint16_t time_low, time_med, time_high, true_size; + uint64_t t; time_t tsecs; /* read the record type and length. */ if (!wtap_read_bytes_or_eof(fh, LE_record_type, 2, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, LE_record_length, 2, err, err_info)) - return FALSE; + return false; record_type = pletoh16(LE_record_type); record_length = pletoh16(LE_record_length); @@ -511,7 +511,7 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("lanalyzer: record type %u seen after trace summary record", record_type); - return FALSE; + return false; } if (record_length < DESCRIPTOR_LEN) { @@ -522,13 +522,13 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("lanalyzer: file has a %u-byte record, too small to have even a packet descriptor", record_length); - return FALSE; + return false; } record_data_size = record_length - DESCRIPTOR_LEN; /* Read the descriptor data */ if (!wtap_read_bytes(fh, descriptor, DESCRIPTOR_LEN, err, err_info)) - return FALSE; + return false; true_size = pletoh16(&descriptor[4]); packet_size = pletoh16(&descriptor[6]); @@ -548,7 +548,7 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("lanalyzer: Record length is less than packet size"); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -558,12 +558,12 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, time_low = pletoh16(&descriptor[8]); time_med = pletoh16(&descriptor[10]); time_high = pletoh16(&descriptor[12]); - t = (((guint64)time_low) << 0) + (((guint64)time_med) << 16) + - (((guint64)time_high) << 32); + t = (((uint64_t)time_low) << 0) + (((uint64_t)time_med) << 16) + + (((uint64_t)time_high) << 32); tsecs = (time_t) (t/2000000); lanalyzer = (lanalyzer_t *)wth->priv; rec->ts.secs = tsecs + lanalyzer->start; - rec->ts.nsecs = ((guint32) (t - tsecs*2000000)) * 500; + rec->ts.nsecs = ((uint32_t) (t - tsecs*2000000)) * 500; if (true_size - 4 >= packet_size) { /* @@ -590,8 +590,8 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, } /* Read the next packet */ -static gboolean lanalyzer_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool lanalyzer_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); @@ -600,27 +600,27 @@ static gboolean lanalyzer_read(wtap *wth, wtap_rec *rec, Buffer *buf, err_info); } -static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool lanalyzer_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read the record */ if (!lanalyzer_read_trace_record(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } /*--------------------------------------------------- - * Returns TRUE on success, FALSE on error + * Returns true on success, false on error * Write "cnt" bytes of zero with error control *---------------------------------------------------*/ -static gboolean s0write(wtap_dumper *wdh, size_t cnt, int *err) +static bool s0write(wtap_dumper *wdh, size_t cnt, int *err) { size_t snack; @@ -628,63 +628,63 @@ static gboolean s0write(wtap_dumper *wdh, size_t cnt, int *err) snack = cnt > 64 ? 64 : cnt; if (!wtap_dump_file_write(wdh, z64, snack, err)) - return FALSE; + return false; cnt -= snack; } - return TRUE; /* ok */ + return true; /* ok */ } /*--------------------------------------------------- - * Returns TRUE on success, FALSE on error + * Returns true on success, false on error * Write an 8-bit value *---------------------------------------------------*/ -static gboolean s8write(wtap_dumper *wdh, const guint8 s8, int *err) +static bool s8write(wtap_dumper *wdh, const uint8_t s8, int *err) { return wtap_dump_file_write(wdh, &s8, 1, err); } /*--------------------------------------------------- - * Returns TRUE on success, FALSE on error + * Returns true on success, false on error * Write a 16-bit value as little-endian *---------------------------------------------------*/ -static gboolean s16write(wtap_dumper *wdh, const guint16 s16, int *err) +static bool s16write(wtap_dumper *wdh, const uint16_t s16, int *err) { - guint16 s16_le = GUINT16_TO_LE(s16); + uint16_t s16_le = GUINT16_TO_LE(s16); return wtap_dump_file_write(wdh, &s16_le, 2, err); } /*--------------------------------------------------- - * Returns TRUE on success, FALSE on error + * Returns true on success, false on error * Write a 32-bit value as little-endian *---------------------------------------------------*/ -static gboolean s32write(wtap_dumper *wdh, const guint32 s32, int *err) +static bool s32write(wtap_dumper *wdh, const uint32_t s32, int *err) { - guint32 s32_le = GUINT32_TO_LE(s32); + uint32_t s32_le = GUINT32_TO_LE(s32); return wtap_dump_file_write(wdh, &s32_le, 4, err); } /*--------------------------------------------------- - * Returns TRUE on success, FALSE on error + * Returns true on success, false on error * Write a 48-bit value as little-endian *---------------------------------------------------*/ -static gboolean s48write(wtap_dumper *wdh, const guint64 s48, int *err) +static bool s48write(wtap_dumper *wdh, const uint64_t s48, int *err) { #if G_BYTE_ORDER == G_BIG_ENDIAN - guint16 s48_upper_le = GUINT16_SWAP_LE_BE((guint16) (s48 >> 32)); - guint32 s48_lower_le = GUINT32_SWAP_LE_BE((guint32) (s48 & 0xFFFFFFFF)); + uint16_t s48_upper_le = GUINT16_SWAP_LE_BE((uint16_t) (s48 >> 32)); + uint32_t s48_lower_le = GUINT32_SWAP_LE_BE((uint32_t) (s48 & 0xFFFFFFFF)); #else - guint16 s48_upper_le = (guint16) (s48 >> 32); - guint32 s48_lower_le = (guint32) (s48 & 0xFFFFFFFF); + uint16_t s48_upper_le = (uint16_t) (s48 >> 32); + uint32_t s48_lower_le = (uint32_t) (s48 & 0xFFFFFFFF); #endif return wtap_dump_file_write(wdh, &s48_lower_le, 4, err) && wtap_dump_file_write(wdh, &s48_upper_le, 2, err); } /*--------------------------------------------------- * Write a record for a packet to a dump file. - * Returns TRUE on success, FALSE on failure. + * Returns true on success, false on failure. *---------------------------------------------------*/ -static gboolean lanalyzer_dump(wtap_dumper *wdh, +static bool lanalyzer_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { - guint64 x; + uint64_t x; int len; LA_TmpInfo *itmp = (LA_TmpInfo*)(wdh->priv); @@ -694,7 +694,7 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -703,13 +703,13 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } if (wdh->bytes_dumped + thisSize > LA_ProFileLimit) { /* printf(" LA_ProFileLimit reached\n"); */ *err = EFBIG; - return FALSE; /* and don't forget the header */ + return false; /* and don't forget the header */ } len = rec->rec_header.packet_header.caplen + (rec->rec_header.packet_header.caplen ? LA_PacketRecordSize : 0); @@ -717,13 +717,13 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, /* len goes into a 16-bit field, so there's a hard limit of 65535. */ if (len > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } if (!s16write(wdh, 0x1005, err)) - return FALSE; - if (!s16write(wdh, (guint16)len, err)) - return FALSE; + return false; + if (!s16write(wdh, (uint16_t)len, err)) + return false; if (!itmp->init) { /* collect some information for the @@ -731,19 +731,19 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, */ itmp->start = rec->ts; itmp->pkts = 0; - itmp->init = TRUE; + itmp->init = true; itmp->encap = wdh->file_encap; itmp->lastlen = 0; } if (!s16write(wdh, 0x0001, err)) /* pr.rx_channels */ - return FALSE; + return false; if (!s16write(wdh, 0x0008, err)) /* pr.rx_errors */ - return FALSE; - if (!s16write(wdh, (guint16) (rec->rec_header.packet_header.len + 4), err)) /* pr.rx_frm_len */ - return FALSE; - if (!s16write(wdh, (guint16) rec->rec_header.packet_header.caplen, err)) /* pr.rx_frm_sln */ - return FALSE; + return false; + if (!s16write(wdh, (uint16_t) (rec->rec_header.packet_header.len + 4), err)) /* pr.rx_frm_len */ + return false; + if (!s16write(wdh, (uint16_t) rec->rec_header.packet_header.caplen, err)) /* pr.rx_frm_sln */ + return false; nstime_delta(&td, &rec->ts, &itmp->start); @@ -752,21 +752,21 @@ static gboolean lanalyzer_dump(wtap_dumper *wdh, x += td.secs * 2000000; /* seconds -> half-microseconds */ if (!s48write(wdh, x, err)) /* pr.rx_time[i] */ - return FALSE; + return false; if (!s32write(wdh, ++itmp->pkts, err)) /* pr.pktno */ - return FALSE; - if (!s16write(wdh, (guint16)itmp->lastlen, err)) /* pr.prlen */ - return FALSE; + return false; + if (!s16write(wdh, (uint16_t)itmp->lastlen, err)) /* pr.prlen */ + return false; itmp->lastlen = len; if (!s0write(wdh, 12, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; - return TRUE; + return true; } /*--------------------------------------------------- @@ -789,10 +789,10 @@ static int lanalyzer_dump_can_write_encap(int encap) } /*--------------------------------------------------- - * Returns TRUE on success, FALSE on failure; sets "*err" to an + * Returns true on success, false on failure; sets "*err" to an * error code on failure *---------------------------------------------------*/ -static gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool lanalyzer_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { int jump; void *tmp; @@ -800,10 +800,10 @@ static gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info tmp = g_malloc(sizeof(LA_TmpInfo)); if (!tmp) { *err = errno; - return FALSE; + return false; } - ((LA_TmpInfo*)tmp)->init = FALSE; + ((LA_TmpInfo*)tmp)->init = false; wdh->priv = tmp; wdh->subtype_write = lanalyzer_dump; wdh->subtype_finish = lanalyzer_dump_finish; @@ -824,151 +824,151 @@ static gboolean lanalyzer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info + LA_IndexRecordSize; if (wtap_dump_file_seek(wdh, jump, SEEK_SET, err) == -1) - return FALSE; + return false; wdh->bytes_dumped = jump; - return TRUE; + return true; } /*--------------------------------------------------- * *---------------------------------------------------*/ -static gboolean lanalyzer_dump_header(wtap_dumper *wdh, int *err) +static bool lanalyzer_dump_header(wtap_dumper *wdh, int *err) { LA_TmpInfo *itmp = (LA_TmpInfo*)(wdh->priv); - guint16 board_type = itmp->encap == WTAP_ENCAP_TOKEN_RING + uint16_t board_type = itmp->encap == WTAP_ENCAP_TOKEN_RING ? BOARD_325TR /* LANalyzer Board Type */ : BOARD_325; /* LANalyzer Board Type */ struct tm *fT; fT = localtime(&itmp->start.secs); if (fT == NULL) - return FALSE; + return false; if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &LA_HeaderRegularFake, sizeof LA_HeaderRegularFake, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &LA_RxChannelNameFake, sizeof LA_RxChannelNameFake, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &LA_TxChannelNameFake, sizeof LA_TxChannelNameFake, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &LA_RxTemplateNameFake, sizeof LA_RxTemplateNameFake, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &LA_TxTemplateNameFake, sizeof LA_TxTemplateNameFake, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &LA_DisplayOptionsFake, sizeof LA_DisplayOptionsFake, err)) - return FALSE; + return false; /*-----------------------------------------------------------------*/ if (!s16write(wdh, RT_Summary, err)) /* rid */ - return FALSE; + return false; if (!s16write(wdh, SummarySize, err)) /* rlen */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.datcre.day */ - return FALSE; - if (!s8write(wdh, (guint8) (fT->tm_mon+1), err)) /* s.datcre.mon */ - return FALSE; - if (!s16write(wdh, (guint16) (fT->tm_year + 1900), err)) /* s.datcre.year */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.datclo.day */ - return FALSE; - if (!s8write(wdh, (guint8) (fT->tm_mon+1), err)) /* s.datclo.mon */ - return FALSE; - if (!s16write(wdh, (guint16) (fT->tm_year + 1900), err)) /* s.datclo.year */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_sec, err)) /* s.timeopn.second */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_min, err)) /* s.timeopn.minute */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_hour, err)) /* s.timeopn.hour */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.timeopn.mday */ - return FALSE; + return false; + if (!s8write(wdh, (uint8_t) fT->tm_mday, err)) /* s.datcre.day */ + return false; + if (!s8write(wdh, (uint8_t) (fT->tm_mon+1), err)) /* s.datcre.mon */ + return false; + if (!s16write(wdh, (uint16_t) (fT->tm_year + 1900), err)) /* s.datcre.year */ + return false; + if (!s8write(wdh, (uint8_t) fT->tm_mday, err)) /* s.datclo.day */ + return false; + if (!s8write(wdh, (uint8_t) (fT->tm_mon+1), err)) /* s.datclo.mon */ + return false; + if (!s16write(wdh, (uint16_t) (fT->tm_year + 1900), err)) /* s.datclo.year */ + return false; + if (!s8write(wdh, (uint8_t) fT->tm_sec, err)) /* s.timeopn.second */ + return false; + if (!s8write(wdh, (uint8_t) fT->tm_min, err)) /* s.timeopn.minute */ + return false; + if (!s8write(wdh, (uint8_t) fT->tm_hour, err)) /* s.timeopn.hour */ + return false; + if (!s8write(wdh, (uint8_t) fT->tm_mday, err)) /* s.timeopn.mday */ + return false; if (!s0write(wdh, 2, err)) - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_sec, err)) /* s.timeclo.second */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_min, err)) /* s.timeclo.minute */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_hour, err)) /* s.timeclo.hour */ - return FALSE; - if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.timeclo.mday */ - return FALSE; + return false; + if (!s8write(wdh, (uint8_t) fT->tm_sec, err)) /* s.timeclo.second */ + return false; + if (!s8write(wdh, (uint8_t) fT->tm_min, err)) /* s.timeclo.minute */ + return false; + if (!s8write(wdh, (uint8_t) fT->tm_hour, err)) /* s.timeclo.hour */ + return false; + if (!s8write(wdh, (uint8_t) fT->tm_mday, err)) /* s.timeclo.mday */ + return false; if (!s0write(wdh, 2, err)) - return FALSE; + return false; if (!s0write(wdh, 6, err)) /* EAddr == 0 */ - return FALSE; + return false; if (!s16write(wdh, 1, err)) /* s.mxseqno */ - return FALSE; + return false; if (!s16write(wdh, 0, err)) /* s.slcoffo */ - return FALSE; + return false; if (!s16write(wdh, 1514, err)) /* s.mxslc */ - return FALSE; + return false; if (!s32write(wdh, itmp->pkts, err)) /* s.totpktt */ - return FALSE; + return false; /* * statrg == 0; ? -1 * stptrg == 0; ? -1 * s.mxpkta[0]=0 */ if (!s0write(wdh, 12, err)) - return FALSE; + return false; if (!s32write(wdh, itmp->pkts, err)) /* sr.s.mxpkta[1] */ - return FALSE; + return false; if (!s0write(wdh, 34*4, err)) /* s.mxpkta[2-33]=0 */ - return FALSE; + return false; if (!s16write(wdh, board_type, err)) - return FALSE; + return false; if (!s0write(wdh, 20, err)) /* board_version == 0 */ - return FALSE; + return false; /*-----------------------------------------------------------------*/ if (!s16write(wdh, RT_SubfileSummary, err)) /* ssr.rid */ - return FALSE; + return false; if (!s16write(wdh, LA_SubfileSummaryRecordSize-4, err)) /* ssr.rlen */ - return FALSE; + return false; if (!s16write(wdh, 1, err)) /* ssr.seqno */ - return FALSE; + return false; if (!s32write(wdh, itmp->pkts, err)) /* ssr.totpkts */ - return FALSE; + return false; /*-----------------------------------------------------------------*/ if (!wtap_dump_file_write(wdh, &LA_CyclicInformationFake, sizeof LA_CyclicInformationFake, err)) - return FALSE; + return false; /*-----------------------------------------------------------------*/ if (!s16write(wdh, RT_Index, err)) /* rid */ - return FALSE; + return false; if (!s16write(wdh, LA_IndexRecordSize -4, err)) /* rlen */ - return FALSE; + return false; if (!s16write(wdh, LA_IndexSize, err)) /* idxsp */ - return FALSE; + return false; if (!s0write(wdh, LA_IndexRecordSize - 6, err)) - return FALSE; + return false; - return TRUE; + return true; } /*--------------------------------------------------- * Finish writing to a dump file. - * Returns TRUE on success, FALSE on failure. + * Returns true on success, false on failure. *---------------------------------------------------*/ -static gboolean lanalyzer_dump_finish(wtap_dumper *wdh, int *err, - gchar **err_info _U_) +static bool lanalyzer_dump_finish(wtap_dumper *wdh, int *err, + char **err_info _U_) { /* bytes_dumped already accounts for the size of the header, * but lanalyzer_dump_header() (via wtap_dump_file_write()) * will keep incrementing it. */ - gint64 saved_bytes_dumped = wdh->bytes_dumped; + int64_t saved_bytes_dumped = wdh->bytes_dumped; lanalyzer_dump_header(wdh,err); wdh->bytes_dumped = saved_bytes_dumped; - return *err ? FALSE : TRUE; + return *err ? false : true; } static const struct supported_block_type lanalyzer_blocks_supported[] = { @@ -980,7 +980,7 @@ static const struct supported_block_type lanalyzer_blocks_supported[] = { static const struct file_type_subtype_info lanalyzer_info = { "Novell LANalyzer","lanalyzer", "tr1", NULL, - TRUE, BLOCKS_SUPPORTED(lanalyzer_blocks_supported), + true, BLOCKS_SUPPORTED(lanalyzer_blocks_supported), lanalyzer_dump_can_write_encap, lanalyzer_dump_open, NULL }; diff --git a/wiretap/lanalyzer.h b/wiretap/lanalyzer.h index ffae61de..cfb474d4 100644 --- a/wiretap/lanalyzer.h +++ b/wiretap/lanalyzer.h @@ -12,6 +12,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val lanalyzer_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index f3538078..a231dc63 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -7,6 +7,7 @@ */ #include "config.h" +#include "libpcap.h" #include <stdlib.h> #include <string.h> @@ -15,7 +16,6 @@ #include "required_file_handlers.h" #include "pcap-common.h" #include "pcap-encap.h" -#include "libpcap.h" #include "erf-common.h" #include <wsutil/ws_assert.h> @@ -49,43 +49,43 @@ typedef enum { } pcap_variant_t; typedef struct { - gboolean byte_swapped; + bool byte_swapped; swapped_type_t lengths_swapped; - guint16 version_major; - guint16 version_minor; + uint16_t version_major; + uint16_t version_minor; pcap_variant_t variant; int fcs_len; void *encap_priv; } libpcap_t; /* Try to read the first few records of the capture file. */ -static gboolean libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, - size_t n_variants, int *err, gchar **err_info); -static int libpcap_try(wtap *wth, int *err, gchar **err_info); -static int libpcap_try_record(wtap *wth, int *err, gchar **err_info); - -static gboolean libpcap_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean libpcap_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean libpcap_read_packet(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info, +static bool libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, + size_t n_variants, int *err, char **err_info); +static int libpcap_try(wtap *wth, int *err, char **err_info); +static int libpcap_try_record(wtap *wth, int *err, char **err_info); + +static bool libpcap_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool libpcap_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool libpcap_read_packet(wtap *wth, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool libpcap_read_header(wtap *wth, FILE_T fh, int *err, char **err_info, struct pcaprec_ss990915_hdr *hdr); static void libpcap_close(wtap *wth); -static gboolean libpcap_dump_pcap(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gboolean libpcap_dump_pcap_nsec(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gboolean libpcap_dump_pcap_ss990417(wtap_dumper *wdh, - const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); -static gboolean libpcap_dump_pcap_ss990915(wtap_dumper *wdh, - const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); -static gboolean libpcap_dump_pcap_ss991029(wtap_dumper *wdh, - const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); -static gboolean libpcap_dump_pcap_nokia(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); +static bool libpcap_dump_pcap(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); +static bool libpcap_dump_pcap_nsec(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); +static bool libpcap_dump_pcap_ss990417(wtap_dumper *wdh, + const wtap_rec *rec, const uint8_t *pd, int *err, char **err_info); +static bool libpcap_dump_pcap_ss990915(wtap_dumper *wdh, + const wtap_rec *rec, const uint8_t *pd, int *err, char **err_info); +static bool libpcap_dump_pcap_ss991029(wtap_dumper *wdh, + const wtap_rec *rec, const uint8_t *pd, int *err, char **err_info); +static bool libpcap_dump_pcap_nokia(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); /* * Subfields of the field containing the link-layer header type. @@ -173,11 +173,11 @@ static const pcap_variant_t variants_modified[] = { }; #define N_VARIANTS_MODIFIED G_N_ELEMENTS(variants_modified) -wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val libpcap_open(wtap *wth, int *err, char **err_info) { - guint32 magic; + uint32_t magic; struct pcap_hdr hdr; - gboolean byte_swapped; + bool byte_swapped; pcap_variant_t variant; libpcap_t *libpcap; int skip_size = 0; @@ -197,7 +197,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) a program using either standard or ss990417 libpcap, or maybe it was written by AIX. That means we don't yet know the variant. */ - byte_swapped = FALSE; + byte_swapped = false; variant = PCAP_UNKNOWN; break; @@ -206,7 +206,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) and was running a program using either standard or ss990417 libpcap, or maybe it was written by AIX. That means we don't yet know the variant. */ - byte_swapped = TRUE; + byte_swapped = true; variant = PCAP_UNKNOWN; break; @@ -215,7 +215,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) /* Weird Ixia variant that has extra crud, written in our byte order. It's otherwise like standard pcap. */ skip_size = 1; - byte_swapped = FALSE; + byte_swapped = false; variant = PCAP; break; @@ -225,7 +225,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) byte order opposite to ours. It's otherwise like standard pcap. */ skip_size = 1; - byte_swapped = TRUE; + byte_swapped = true; variant = PCAP; break; @@ -234,7 +234,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) a program using either ss990915 or ss991029 libpcap. That means we don't yet know the variant; there's no obvious default, so default to "unknown". */ - byte_swapped = FALSE; + byte_swapped = false; variant = PCAP_UNKNOWN; break; @@ -244,7 +244,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) or ss991029 libpcap. That means we don't yet know the variant; there's no obvious default, so default to "unknown". */ - byte_swapped = TRUE; + byte_swapped = true; variant = PCAP_UNKNOWN; break; @@ -252,7 +252,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) /* Host that wrote it has our byte order, and was writing the file in a format similar to standard libpcap except that the time stamps have nanosecond resolution. */ - byte_swapped = FALSE; + byte_swapped = false; variant = PCAP_NSEC; break; @@ -261,7 +261,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) ours, and was writing the file in a format similar to standard libpcap except that the time stamps have nanosecond resolution. */ - byte_swapped = TRUE; + byte_swapped = true; variant = PCAP_NSEC; break; @@ -653,15 +653,15 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_MINE; } -static gboolean libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, - size_t n_variants, int *err, gchar **err_info) +static bool libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, + size_t n_variants, int *err, char **err_info) { libpcap_t *libpcap = (libpcap_t *)wth->priv; #define MAX_FIGURES_OF_MERIT \ MAX(N_VARIANTS_MODIFIED, N_VARIANTS_STANDARD) int figures_of_merit[MAX_FIGURES_OF_MERIT]; int best_variant; - gint64 first_packet_offset; + int64_t first_packet_offset; first_packet_offset = file_tell(wth->fh); for (size_t i = 0; i < n_variants; i++) { @@ -671,7 +671,7 @@ static gboolean libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, /* * Well, we couldn't even read it. Give up. */ - return FALSE; + return false; } if (figures_of_merit[i] == 0) { /* @@ -681,9 +681,9 @@ static gboolean libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, */ if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) { - return FALSE; + return false; } - return TRUE; + return true; } /* @@ -693,7 +693,7 @@ static gboolean libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, */ if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) { - return FALSE; + return false; } } @@ -713,7 +713,7 @@ static gboolean libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, best_variant = figures_of_merit[i]; } } - return TRUE; + return true; } /* @@ -722,7 +722,7 @@ static gboolean libpcap_try_variants(wtap *wth, const pcap_variant_t *variants, #define MAX_RECORDS_TO_TRY 3 /* Try to read the first MAX_RECORDS_TO_TRY records of the capture file. */ -static int libpcap_try(wtap *wth, int *err, gchar **err_info) +static int libpcap_try(wtap *wth, int *err, char **err_info) { int ret; int i; @@ -770,7 +770,7 @@ static int libpcap_try(wtap *wth, int *err, gchar **err_info) are wrong with the header; this is used by the heuristics that try to guess what type of file it is, with the type with the fewest problems being chosen. */ -static int libpcap_try_record(wtap *wth, int *err, gchar **err_info) +static int libpcap_try_record(wtap *wth, int *err, char **err_info) { /* * pcaprec_ss990915_hdr is the largest header type. @@ -842,7 +842,7 @@ static int libpcap_try_record(wtap *wth, int *err, gchar **err_info) * This is not a fatal error, and packets that have one * such packet probably have thousands. For discussion, * see - * https://www.wireshark.org/lists/wireshark-dev/201307/msg00076.html + * https://lists.wireshark.org/archives/wireshark-dev/201307/msg00076.html * and related messages. * * The packet contents will be copied to a Buffer, which @@ -894,43 +894,43 @@ static int libpcap_try_record(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean libpcap_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool libpcap_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return libpcap_read_packet(wth, wth->fh, rec, buf, err, err_info); } -static gboolean -libpcap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +libpcap_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (!libpcap_read_packet(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool libpcap_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { struct pcaprec_ss990915_hdr hdr; - guint packet_size; - guint orig_size; + unsigned packet_size; + unsigned orig_size; int phdr_len; libpcap_t *libpcap = (libpcap_t *)wth->priv; - gboolean is_nokia; + bool is_nokia; if (!libpcap_read_header(wth, fh, err, err_info, &hdr)) - return FALSE; + return false; if (hdr.hdr.incl_len > wtap_max_snaplen_for_encap(wth->file_encap)) { /* @@ -944,7 +944,7 @@ libpcap_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, hdr.hdr.incl_len, wtap_max_snaplen_for_encap(wth->file_encap)); } - return FALSE; + return false; } packet_size = hdr.hdr.incl_len; @@ -968,14 +968,14 @@ libpcap_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, * Skip the padding. */ if (!wtap_read_bytes(fh, NULL, 3, err, err_info)) - return FALSE; + return false; } is_nokia = (libpcap->variant == PCAP_NOKIA); phdr_len = pcap_process_pseudo_header(fh, is_nokia, wth->file_encap, packet_size, rec, err, err_info); if (phdr_len < 0) - return FALSE; /* error */ + return false; /* error */ /* * Don't count any pseudo-header as part of the packet. @@ -1000,9 +1000,9 @@ libpcap_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, /* Set interface ID for ERF format */ rec->presence_flags |= WTAP_HAS_INTERFACE_ID; if ((interface_id = erf_populate_interface_from_header((erf_t*) libpcap->encap_priv, wth, &rec->rec_header.packet_header.pseudo_header, err, err_info)) < 0) - return FALSE; + return false; - rec->rec_header.packet_header.interface_id = (guint) interface_id; + rec->rec_header.packet_header.interface_id = (unsigned) interface_id; } rec->rec_header.packet_header.caplen = packet_size; rec->rec_header.packet_header.len = orig_size; @@ -1011,21 +1011,22 @@ libpcap_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, * Read the packet data. */ if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) - return FALSE; /* failed */ + return false; /* failed */ pcap_read_post_process(is_nokia, wth->file_encap, rec, ws_buffer_start_ptr(buf), libpcap->byte_swapped, libpcap->fcs_len); - return TRUE; + return true; } /* Read the header of the next packet. - Return FALSE on an error, TRUE on success. */ -static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info, + Return false on an error, true on success. */ +static bool +libpcap_read_header(wtap *wth, FILE_T fh, int *err, char **err_info, struct pcaprec_ss990915_hdr *hdr) { int bytes_to_read; - guint32 temp; + uint32_t temp; libpcap_t *libpcap = (libpcap_t *)wth->priv; switch (libpcap->variant) { @@ -1054,7 +1055,7 @@ static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info, ws_assert_not_reached(); } if (!wtap_read_bytes_or_eof(fh, hdr, bytes_to_read, err, err_info)) - return FALSE; + return false; if (libpcap->byte_swapped) { /* Byte-swap the record header fields. */ @@ -1087,7 +1088,7 @@ static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info, break; } - return TRUE; + return true; } /* Returns 0 if we could write the specified encapsulation type, @@ -1104,13 +1105,13 @@ static int libpcap_dump_can_write_encap(int encap) return 0; } -static gboolean libpcap_dump_write_file_header(wtap_dumper *wdh, guint32 magic, +static bool libpcap_dump_write_file_header(wtap_dumper *wdh, uint32_t magic, int *err) { struct pcap_hdr file_hdr; if (!wtap_dump_file_write(wdh, &magic, sizeof magic, err)) - return FALSE; + return false; /* current "libpcap" format is 2.4 */ file_hdr.version_major = 2; @@ -1129,20 +1130,20 @@ static gboolean libpcap_dump_write_file_header(wtap_dumper *wdh, guint32 magic, * the snapshot length in the header file the maximum for the * link-layer type we'll be writing. */ - file_hdr.snaplen = (wdh->snaplen != 0) ? (guint)wdh->snaplen : + file_hdr.snaplen = (wdh->snaplen != 0) ? (unsigned)wdh->snaplen : wtap_max_snaplen_for_encap(wdh->file_encap); file_hdr.network = wtap_wtap_encap_to_pcap_encap(wdh->file_encap); if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err)) - return FALSE; + return false; - return TRUE; + return true; } /* Good old fashioned pcap. - Returns TRUE on success, FALSE on failure; sets "*err" to an error code on + Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -libpcap_dump_open_pcap(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool +libpcap_dump_open_pcap(wtap_dumper *wdh, int *err, char **err_info _U_) { /* This is a libpcap file */ wdh->subtype_write = libpcap_dump_pcap; @@ -1152,10 +1153,10 @@ libpcap_dump_open_pcap(wtap_dumper *wdh, int *err, gchar **err_info _U_) } /* Like classic pcap, but with nanosecond resolution. - Returns TRUE on success, FALSE on failure; sets "*err" to an error code on + Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -libpcap_dump_open_pcap_nsec(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool +libpcap_dump_open_pcap_nsec(wtap_dumper *wdh, int *err, char **err_info _U_) { /* This is a nanosecond-resolution libpcap file */ wdh->subtype_write = libpcap_dump_pcap_nsec; @@ -1165,11 +1166,11 @@ libpcap_dump_open_pcap_nsec(wtap_dumper *wdh, int *err, gchar **err_info _U_) } /* Modified, but with the old magic, sigh. - Returns TRUE on success, FALSE on failure; sets "*err" to an error code on + Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean +static bool libpcap_dump_open_pcap_ss990417(wtap_dumper *wdh, int *err, - gchar **err_info _U_) + char **err_info _U_) { /* This is a modified-by-patch-SS990417 libpcap file */ wdh->subtype_write = libpcap_dump_pcap_ss990417; @@ -1179,11 +1180,11 @@ libpcap_dump_open_pcap_ss990417(wtap_dumper *wdh, int *err, } /* New magic, extra crap. - Returns TRUE on success, FALSE on failure; sets "*err" to an error code on + Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean +static bool libpcap_dump_open_pcap_ss990915(wtap_dumper *wdh, int *err, - gchar **err_info _U_) + char **err_info _U_) { /* This is a modified-by-patch-SS990915 libpcap file */ wdh->subtype_write = libpcap_dump_pcap_ss990915; @@ -1193,11 +1194,11 @@ libpcap_dump_open_pcap_ss990915(wtap_dumper *wdh, int *err, } /* Same magic as SS990915, *different* extra crap, sigh. - Returns TRUE on success, FALSE on failure; sets "*err" to an error code on + Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean +static bool libpcap_dump_open_pcap_ss991029(wtap_dumper *wdh, int *err, - gchar **err_info _U_) + char **err_info _U_) { /* This is a modified-by-patch-SS991029 libpcap file */ wdh->subtype_write = libpcap_dump_pcap_ss991029; @@ -1225,10 +1226,10 @@ static void libpcap_close(wtap *wth) } /* Nokia libpcap of some sort. - Returns TRUE on success, FALSE on failure; sets "*err" to an error code on + Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -libpcap_dump_open_pcap_nokia(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool +libpcap_dump_open_pcap_nokia(wtap_dumper *wdh, int *err, char **err_info _U_) { /* This is a Nokia libpcap file */ wdh->subtype_write = libpcap_dump_pcap_nokia; @@ -1237,9 +1238,9 @@ libpcap_dump_open_pcap_nokia(wtap_dumper *wdh, int *err, gchar **err_info _U_) return libpcap_dump_write_file_header(wdh, PCAP_MAGIC, err); } -static gboolean +static bool libpcap_dump_write_packet(wtap_dumper *wdh, const wtap_rec *rec, - struct pcaprec_hdr *hdr, size_t hdr_size, const guint8 *pd, int *err) + struct pcaprec_hdr *hdr, size_t hdr_size, const uint8_t *pd, int *err) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; int phdrsize; @@ -1249,7 +1250,7 @@ libpcap_dump_write_packet(wtap_dumper *wdh, const wtap_rec *rec, /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -1258,38 +1259,38 @@ libpcap_dump_write_packet(wtap_dumper *wdh, const wtap_rec *rec, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* * Don't write anything we're not willing to read. * (The cast is to prevent an overflow.) */ - if ((guint64)rec->rec_header.packet_header.caplen + phdrsize > wtap_max_snaplen_for_encap(wdh->file_encap)) { + if ((uint64_t)rec->rec_header.packet_header.caplen + phdrsize > wtap_max_snaplen_for_encap(wdh->file_encap)) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } hdr->incl_len = rec->rec_header.packet_header.caplen + phdrsize; hdr->orig_len = rec->rec_header.packet_header.len + phdrsize; if (!wtap_dump_file_write(wdh, hdr, hdr_size, err)) - return FALSE; + return false; if (!pcap_write_phdr(wdh, wdh->file_encap, pseudo_header, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; - return TRUE; + return false; + return true; } /* Good old fashioned pcap. Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean -libpcap_dump_pcap(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, - int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool +libpcap_dump_pcap(wtap_dumper *wdh, const wtap_rec *rec, const uint8_t *pd, + int *err, char **err_info _U_) { struct pcaprec_hdr rec_hdr; @@ -1298,11 +1299,11 @@ libpcap_dump_pcap(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, * stamps as unsigned, but most of it probably handles * them as signed. */ - if (rec->ts.secs < 0 || rec->ts.secs > G_MAXINT32) { + if (rec->ts.secs < 0 || rec->ts.secs > INT32_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - rec_hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.ts_sec = (uint32_t) rec->ts.secs; rec_hdr.ts_usec = rec->ts.nsecs / 1000; return libpcap_dump_write_packet(wdh, rec, &rec_hdr, sizeof rec_hdr, pd, err); @@ -1310,10 +1311,10 @@ libpcap_dump_pcap(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, /* Like classic pcap, but with nanosecond resolution. Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean -libpcap_dump_pcap_nsec(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, - int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool +libpcap_dump_pcap_nsec(wtap_dumper *wdh, const wtap_rec *rec, const uint8_t *pd, + int *err, char **err_info _U_) { struct pcaprec_hdr rec_hdr; @@ -1322,11 +1323,11 @@ libpcap_dump_pcap_nsec(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, * stamps as unsigned, but most of it probably handles * them as signed. */ - if (rec->ts.secs < 0 || rec->ts.secs > G_MAXINT32) { + if (rec->ts.secs < 0 || rec->ts.secs > INT32_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - rec_hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.ts_sec = (uint32_t) rec->ts.secs; rec_hdr.ts_usec = rec->ts.nsecs; return libpcap_dump_write_packet(wdh, rec, &rec_hdr, sizeof rec_hdr, pd, err); @@ -1334,10 +1335,10 @@ libpcap_dump_pcap_nsec(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, /* Modified, but with the old magic, sigh. Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean + Returns true on success, false on failure. */ +static bool libpcap_dump_pcap_ss990417(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { struct pcaprec_modified_hdr rec_hdr; @@ -1346,11 +1347,11 @@ libpcap_dump_pcap_ss990417(wtap_dumper *wdh, const wtap_rec *rec, * stamps as unsigned, but most of it probably handles * them as signed. */ - if (rec->ts.secs < 0 || rec->ts.secs > G_MAXINT32) { + if (rec->ts.secs < 0 || rec->ts.secs > INT32_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_sec = (uint32_t) rec->ts.secs; rec_hdr.hdr.ts_usec = rec->ts.nsecs / 1000; /* XXX - what should we supply here? @@ -1380,10 +1381,10 @@ libpcap_dump_pcap_ss990417(wtap_dumper *wdh, const wtap_rec *rec, /* New magic, extra crap. Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean + Returns true on success, false on failure. */ +static bool libpcap_dump_pcap_ss990915(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { struct pcaprec_ss990915_hdr rec_hdr; @@ -1392,11 +1393,11 @@ libpcap_dump_pcap_ss990915(wtap_dumper *wdh, const wtap_rec *rec, * stamps as unsigned, but most of it probably handles * them as signed. */ - if (rec->ts.secs < 0 || rec->ts.secs > G_MAXINT32) { + if (rec->ts.secs < 0 || rec->ts.secs > INT32_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_sec = (uint32_t) rec->ts.secs; rec_hdr.hdr.ts_usec = rec->ts.nsecs / 1000; rec_hdr.ifindex = 0; rec_hdr.protocol = 0; @@ -1409,10 +1410,10 @@ libpcap_dump_pcap_ss990915(wtap_dumper *wdh, const wtap_rec *rec, /* Same magic as SS990915, *different* extra crap, sigh. Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean + Returns true on success, false on failure. */ +static bool libpcap_dump_pcap_ss991029(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { struct pcaprec_modified_hdr rec_hdr; @@ -1421,11 +1422,11 @@ libpcap_dump_pcap_ss991029(wtap_dumper *wdh, const wtap_rec *rec, * stamps as unsigned, but most of it probably handles * them as signed. */ - if (rec->ts.secs < 0 || rec->ts.secs > G_MAXINT32) { + if (rec->ts.secs < 0 || rec->ts.secs > INT32_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_sec = (uint32_t) rec->ts.secs; rec_hdr.hdr.ts_usec = rec->ts.nsecs / 1000; /* XXX - what should we supply here? @@ -1455,10 +1456,10 @@ libpcap_dump_pcap_ss991029(wtap_dumper *wdh, const wtap_rec *rec, /* Nokia libpcap of some sort. Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean + Returns true on success, false on failure. */ +static bool libpcap_dump_pcap_nokia(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { struct pcaprec_nokia_hdr rec_hdr; const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; @@ -1468,11 +1469,11 @@ libpcap_dump_pcap_nokia(wtap_dumper *wdh, const wtap_rec *rec, * stamps as unsigned, but most of it probably handles * them as signed. */ - if (rec->ts.secs < 0 || rec->ts.secs > G_MAXINT32) { + if (rec->ts.secs < 0 || rec->ts.secs > INT32_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - rec_hdr.hdr.ts_sec = (guint32) rec->ts.secs; + rec_hdr.hdr.ts_sec = (uint32_t) rec->ts.secs; rec_hdr.hdr.ts_usec = rec->ts.nsecs / 1000; /* restore the "mysterious stuff" that came with the packet */ memcpy(rec_hdr.stuff, pseudo_header->nokia.stuff, 4); @@ -1490,43 +1491,43 @@ static const struct supported_block_type pcap_blocks_supported[] = { static const struct file_type_subtype_info pcap_info = { /* Gianluca Varenni suggests that we add "deprecated" to the description. */ "Wireshark/tcpdump/... - pcap", "pcap", "pcap", "cap;dmp", - FALSE, BLOCKS_SUPPORTED(pcap_blocks_supported), + false, BLOCKS_SUPPORTED(pcap_blocks_supported), libpcap_dump_can_write_encap, libpcap_dump_open_pcap, NULL }; static const struct file_type_subtype_info pcap_nsec_info = { "Wireshark/tcpdump/... - nanosecond pcap", "nsecpcap", "pcap", "cap;dmp", - FALSE, BLOCKS_SUPPORTED(pcap_blocks_supported), + false, BLOCKS_SUPPORTED(pcap_blocks_supported), libpcap_dump_can_write_encap, libpcap_dump_open_pcap_nsec, NULL }; static const struct file_type_subtype_info pcap_aix_info = { "AIX tcpdump - pcap", "aixpcap", "pcap", "cap;dmp", - FALSE, BLOCKS_SUPPORTED(pcap_blocks_supported), + false, BLOCKS_SUPPORTED(pcap_blocks_supported), NULL, NULL, NULL }; static const struct file_type_subtype_info pcap_ss990417_info = { "RedHat 6.1 tcpdump - pcap", "rh6_1pcap", "pcap", "cap;dmp", - FALSE, BLOCKS_SUPPORTED(pcap_blocks_supported), + false, BLOCKS_SUPPORTED(pcap_blocks_supported), libpcap_dump_can_write_encap, libpcap_dump_open_pcap_ss990417, NULL }; static const struct file_type_subtype_info pcap_ss990915_info = { "SuSE 6.3 tcpdump - pcap", "suse6_3pcap", "pcap", "cap;dmp", - FALSE, BLOCKS_SUPPORTED(pcap_blocks_supported), + false, BLOCKS_SUPPORTED(pcap_blocks_supported), libpcap_dump_can_write_encap, libpcap_dump_open_pcap_ss990915, NULL }; static const struct file_type_subtype_info pcap_ss991029_info = { "Modified tcpdump - pcap", "modpcap", "pcap", "cap;dmp", - FALSE, BLOCKS_SUPPORTED(pcap_blocks_supported), + false, BLOCKS_SUPPORTED(pcap_blocks_supported), libpcap_dump_can_write_encap, libpcap_dump_open_pcap_ss991029, NULL }; static const struct file_type_subtype_info pcap_nokia_info = { "Nokia tcpdump - pcap", "nokiapcap", "pcap", "cap;dmp", - FALSE, BLOCKS_SUPPORTED(pcap_blocks_supported), + false, BLOCKS_SUPPORTED(pcap_blocks_supported), libpcap_dump_can_write_encap, libpcap_dump_open_pcap_nokia, NULL }; diff --git a/wiretap/libpcap.h b/wiretap/libpcap.h index 4042ec7c..53eeb497 100644 --- a/wiretap/libpcap.h +++ b/wiretap/libpcap.h @@ -50,52 +50,52 @@ /* "libpcap" file header (minus magic number). */ struct pcap_hdr { - guint16 version_major; /* major version number */ - guint16 version_minor; /* minor version number */ - gint32 thiszone; /* GMT to local correction */ - guint32 sigfigs; /* accuracy of timestamps */ - guint32 snaplen; /* max length of captured packets, in octets */ - guint32 network; /* data link type */ + uint16_t version_major; /* major version number */ + uint16_t version_minor; /* minor version number */ + int32_t thiszone; /* GMT to local correction */ + uint32_t sigfigs; /* accuracy of timestamps */ + uint32_t snaplen; /* max length of captured packets, in octets */ + uint32_t network; /* data link type */ }; /* "libpcap" record header. */ struct pcaprec_hdr { - guint32 ts_sec; /* timestamp seconds */ - guint32 ts_usec; /* timestamp microseconds (nsecs for PCAP_NSEC_MAGIC) */ - guint32 incl_len; /* number of octets of packet saved in file */ - guint32 orig_len; /* actual length of packet */ + uint32_t ts_sec; /* timestamp seconds */ + uint32_t ts_usec; /* timestamp microseconds (nsecs for PCAP_NSEC_MAGIC) */ + uint32_t incl_len; /* number of octets of packet saved in file */ + uint32_t orig_len; /* actual length of packet */ }; /* "libpcap" record header for Alexey's patched version. */ struct pcaprec_modified_hdr { struct pcaprec_hdr hdr; /* the regular header */ - guint32 ifindex; /* index, in *capturing* machine's list of + uint32_t ifindex; /* index, in *capturing* machine's list of interfaces, of the interface on which this packet came in. */ - guint16 protocol; /* Ethernet packet type */ - guint8 pkt_type; /* broadcast/multicast/etc. indication */ - guint8 pad; /* pad to a 4-byte boundary */ + uint16_t protocol; /* Ethernet packet type */ + uint8_t pkt_type; /* broadcast/multicast/etc. indication */ + uint8_t pad; /* pad to a 4-byte boundary */ }; /* "libpcap" record header for Alexey's patched version in its ss990915 incarnation; this version shows up in SuSE Linux 6.3. */ struct pcaprec_ss990915_hdr { struct pcaprec_hdr hdr; /* the regular header */ - guint32 ifindex; /* index, in *capturing* machine's list of + uint32_t ifindex; /* index, in *capturing* machine's list of interfaces, of the interface on which this packet came in. */ - guint16 protocol; /* Ethernet packet type */ - guint8 pkt_type; /* broadcast/multicast/etc. indication */ - guint8 cpu1, cpu2; /* SMP debugging gunk? */ - guint8 pad[3]; /* pad to a 4-byte boundary */ + uint16_t protocol; /* Ethernet packet type */ + uint8_t pkt_type; /* broadcast/multicast/etc. indication */ + uint8_t cpu1, cpu2; /* SMP debugging gunk? */ + uint8_t pad[3]; /* pad to a 4-byte boundary */ }; /* "libpcap" record header for version used on some Nokia boxes (firewalls?) */ struct pcaprec_nokia_hdr { struct pcaprec_hdr hdr; /* the regular header */ - guint8 stuff[4]; /* mysterious stuff */ + uint8_t stuff[4]; /* mysterious stuff */ }; -wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val libpcap_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/log3gpp.c b/wiretap/log3gpp.c index 6fb21f6f..21efe850 100644 --- a/wiretap/log3gpp.c +++ b/wiretap/log3gpp.c @@ -11,6 +11,7 @@ */ #include "config.h" +#include "log3gpp.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP @@ -21,8 +22,6 @@ #include "wtap-int.h" #include "file_wrappers.h" -#include "log3gpp.h" - #define MAX_FIRST_LINE_LENGTH 200 #define MAX_TIMESTAMP_LINE_LENGTH 100 #define MAX_LINE_LENGTH 65536 @@ -41,51 +40,51 @@ typedef enum packet_direction_t typedef struct { time_t start_secs; - guint32 start_usecs; + uint32_t start_usecs; } log3gpp_t; -gint first_packet_offset; -gchar firstline[MAX_FIRST_LINE_LENGTH]; -gchar secondline[MAX_TIMESTAMP_LINE_LENGTH]; -gint secondline_length = 0; +int first_packet_offset; +char firstline[MAX_FIRST_LINE_LENGTH]; +char secondline[MAX_TIMESTAMP_LINE_LENGTH]; +int secondline_length; /***********************************************************/ /* Transient data used for parsing */ /* 'Magic number' at start of 3gpp log files. */ -static const gchar log3gpp_magic[] = "3GPP protocols transcript"; +static const char log3gpp_magic[] = "3GPP protocols transcript"; /* Protocol name of the packet that the packet was captured at */ -static gchar protocol_name[MAX_PROTOCOL_NAME+1]; +static char protocol_name[MAX_PROTOCOL_NAME+1]; /* Optional string parameter giving info required for the protocol dissector */ -static gchar protocol_parameters[MAX_PROTOCOL_PAR_STRING+1]; +static char protocol_parameters[MAX_PROTOCOL_PAR_STRING+1]; /************************************************************/ /* Functions called from wiretap core */ -static gboolean log3gpp_read( wtap* wth, wtap_rec* rec, Buffer* buf, - int* err, gchar** err_info, gint64* data_offset); -static gboolean log3gpp_seek_read(struct wtap *wth, gint64 seek_off, +static bool log3gpp_read( wtap* wth, wtap_rec* rec, Buffer* buf, + int* err, char** err_info, int64_t* data_offset); +static bool log3gpp_seek_read(struct wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + int *err, char **err_info); /************************************************************/ /* Private helper functions */ -static gboolean read_new_line(FILE_T fh, gint* length, - gchar* buf, size_t bufsize, int* err, - gchar** err_info); +static bool read_new_line(FILE_T fh, int* length, + char* buf, size_t bufsize, int* err, + char** err_info); -static gboolean parse_line(char* linebuff, gint line_length, gint *seconds, gint *useconds, +static bool parse_line(char* linebuff, int line_length, int *seconds, int *useconds, long *data_offset, - gint *data_chars, + int *data_chars, packet_direction_t *direction, - gboolean *is_text_data); -static int write_stub_header(guchar *frame_buffer, char *timestamp_string, + bool *is_text_data); +static int write_stub_header(unsigned char *frame_buffer, char *timestamp_string, packet_direction_t direction); -static guchar hex_from_char(gchar c); -/*not used static gchar char_from_hex(guchar hex);*/ +static unsigned char hex_from_char(char c); +/*not used static char char_from_hex(unsigned char hex);*/ -static gboolean get_file_time_stamp(gchar* linebuff, time_t *secs, guint32 *usecs); +static bool get_file_time_stamp(const char* linebuff, time_t *secs, uint32_t *usecs); static int log3gpp_file_type_subtype = -1; @@ -107,15 +106,15 @@ static void log3gpp_close(wtap* wth) /* Open file (for reading) */ /********************************************/ wtap_open_return_val -log3gpp_open(wtap *wth, int *err, gchar **err_info _U_) +log3gpp_open(wtap *wth, int *err, char **err_info _U_) { time_t timestamp; - guint32 usecs; + uint32_t usecs; log3gpp_t *log3gpp; wtap_open_return_val retval; /* Buffer to hold a single text line read from the file */ - static gchar linebuff[MAX_LINE_LENGTH]; - gint firstline_length = 0; + static char linebuff[MAX_LINE_LENGTH]; + int firstline_length = 0; /* Clear errno before reading from the file */ errno = 0; @@ -212,28 +211,28 @@ log3gpp_open(wtap *wth, int *err, gchar **err_info _U_) /**************************************************/ /* Read packet function. */ /* Look for and read the next usable packet */ -/* - return TRUE and details if found */ +/* - return true and details if found */ /**************************************************/ -gboolean log3gpp_read(wtap* wth, wtap_rec* rec, Buffer* buf, - int* err, gchar** err_info, gint64* data_offset) +bool log3gpp_read(wtap* wth, wtap_rec* rec, Buffer* buf, + int* err, char** err_info, int64_t* data_offset) { - gint64 offset = file_tell(wth->fh); - static gchar linebuff[MAX_LINE_LENGTH + 1]; + int64_t offset = file_tell(wth->fh); + static char linebuff[MAX_LINE_LENGTH + 1]; long dollar_offset; packet_direction_t direction; - gboolean is_text_data; + bool is_text_data; log3gpp_t *log3gpp = (log3gpp_t *)wth->priv; /* Search for a line containing a usable packet */ while (1) { int line_length, seconds, useconds, data_chars; - gint64 this_offset = offset; + int64_t this_offset = offset; /* Are looking for first packet after 2nd line */ if (file_tell(wth->fh) == 0) { - this_offset += (gint64)first_packet_offset +1+1; + this_offset += (int64_t)first_packet_offset +1+1; } /* Clear errno before reading from the file */ @@ -243,7 +242,7 @@ gboolean log3gpp_read(wtap* wth, wtap_rec* rec, Buffer* buf, if (!read_new_line(wth->fh, &line_length, linebuff, sizeof linebuff, err, err_info)) { if (*err != 0) { - return FALSE; /* error */ + return false; /* error */ } /* No more lines can be read, so quit. */ break; @@ -256,11 +255,11 @@ gboolean log3gpp_read(wtap* wth, wtap_rec* rec, Buffer* buf, &direction, &is_text_data)) { - guchar *frame_buffer; + unsigned char *frame_buffer; int n; int stub_offset = 0; char timestamp_string[MAX_TIMESTAMP_LEN+1]; - /*not used gint64 *pkey = NULL;*/ + /*not used int64_t *pkey = NULL;*/ snprintf(timestamp_string, 32, "%d.%04d", seconds, useconds/100); @@ -310,7 +309,7 @@ gboolean log3gpp_read(wtap* wth, wtap_rec* rec, Buffer* buf, hex_from_char(linebuff[dollar_offset+n+1]); } *err = errno = 0; - return TRUE; + return true; } else { @@ -335,33 +334,33 @@ gboolean log3gpp_read(wtap* wth, wtap_rec* rec, Buffer* buf, memcpy(&frame_buffer[stub_offset],&linebuff[dollar_offset],data_chars); frame_buffer[stub_offset+data_chars-1]= '\0'; *err = errno = 0; - return TRUE; + return true; } } } /* No packet details to return... */ *err = errno; - return FALSE; + return false; } /**************************************************/ /* Read & seek function. */ /**************************************************/ -static gboolean -log3gpp_seek_read(wtap *wth, gint64 seek_off, +static bool +log3gpp_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec _U_ , Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { long dollar_offset; - static gchar linebuff[MAX_LINE_LENGTH + 1]; + static char linebuff[MAX_LINE_LENGTH + 1]; packet_direction_t direction; int seconds, useconds, data_chars; - gboolean is_text_data; + bool is_text_data; log3gpp_t* log3gpp = (log3gpp_t*)wth->priv; int length = 0; - guchar *frame_buffer; + unsigned char *frame_buffer; /* Reset errno */ *err = errno = 0; @@ -369,13 +368,13 @@ log3gpp_seek_read(wtap *wth, gint64 seek_off, /* Seek to beginning of packet */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return FALSE; + return false; } /* Re-read whole line (this really should succeed) */ if (!read_new_line(wth->random_fh, &length, linebuff, sizeof linebuff, err, err_info)) { - return FALSE; + return false; } /* Try to parse this line again (should succeed as re-reading...) */ @@ -426,7 +425,7 @@ log3gpp_seek_read(wtap *wth, gint64 seek_off, hex_from_char(linebuff[dollar_offset+n+1]); } *err = errno = 0; - return TRUE; + return true; } else { @@ -434,7 +433,7 @@ log3gpp_seek_read(wtap *wth, gint64 seek_off, memcpy(&frame_buffer[stub_offset],&linebuff[dollar_offset],data_chars); frame_buffer[stub_offset+data_chars-1] = '\0'; *err = errno = 0; - return TRUE; + return true; } } @@ -443,7 +442,7 @@ log3gpp_seek_read(wtap *wth, gint64 seek_off, *err_info = ws_strdup_printf("prot 3gpp: seek_read failed to read/parse " "line at position %" PRId64, seek_off); - return FALSE; + return false; } /****************************/ @@ -454,23 +453,23 @@ log3gpp_seek_read(wtap *wth, gint64 seek_off, /* Read a new line from the file, starting at offset. */ /* - writes data to static var linebuff */ /* - on return 'offset' will point to the next position to read from */ -/* - return TRUE if this read is successful */ +/* - return true if this read is successful */ /**********************************************************************/ -static gboolean -read_new_line(FILE_T fh, gint* length, - gchar* linebuff, size_t linebuffsize, int* err, gchar** err_info) +static bool +read_new_line(FILE_T fh, int* length, + char* linebuff, size_t linebuffsize, int* err, char** err_info) { /* Read in a line */ - gint64 pos_before = file_tell(fh); + int64_t pos_before = file_tell(fh); if (file_gets(linebuff, (int)linebuffsize - 1, fh) == NULL) { /* No characters found, or error */ *err = file_error(fh, err_info); - return FALSE; + return false; } /* Set length (avoiding strlen()) and offset.. */ - *length = (gint)(file_tell(fh) - pos_before); + *length = (int)(file_tell(fh) - pos_before); /* ...but don't want to include newline in line length */ if (*length > 0 && linebuff[*length - 1] == '\n') { @@ -483,7 +482,7 @@ read_new_line(FILE_T fh, gint* length, *length = *length - 1; } - return TRUE; + return true; } @@ -491,12 +490,12 @@ read_new_line(FILE_T fh, gint* length, /* Parse a line from buffer, by identifying: */ /* - timestamp */ /* - data position and length */ -/* Return TRUE if this packet looks valid and can be displayed */ +/* Return true if this packet looks valid and can be displayed */ /**********************************************************************/ -gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *useconds, - long *data_offset, gint *data_chars, +bool parse_line(char* linebuff, int line_length, int *seconds, int *useconds, + long *data_offset, int *data_chars, packet_direction_t *direction, - gboolean *is_text_data) + bool *is_text_data) { int n = 0; int protocol_chars = 0; @@ -510,10 +509,10 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec /* Find and read the timestamp */ /*********************************************************************/ /* Now scan to the next digit, which should be the start of the timestamp */ - for (; !g_ascii_isdigit((guchar)linebuff[n]) && (n < line_length); n++); + for (; !g_ascii_isdigit((unsigned char)linebuff[n]) && (n < line_length); n++); if (n >= line_length) { - return FALSE; + return false; } /* Seconds */ @@ -523,17 +522,17 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec (n < line_length); n++, seconds_chars++) { - if (!g_ascii_isdigit((guchar)linebuff[n])) + if (!g_ascii_isdigit((unsigned char)linebuff[n])) { /* Found a non-digit before decimal point. Fail */ - return FALSE; + return false; } seconds_buff[seconds_chars] = linebuff[n]; } if (seconds_chars > MAX_SECONDS_CHARS || n >= line_length) { /* Didn't fit in buffer. Fail rather than use truncated */ - return FALSE; + return false; } /* Convert found value into number */ @@ -550,7 +549,7 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec /* The decimal point must follow the last of the seconds digits */ if (linebuff[n] != '.') { - return FALSE; + return false; } /* Skip it */ n++; @@ -560,9 +559,9 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec (linebuff[n] != ' ') && (subsecond_decimals_chars < MAX_SUBSECOND_DECIMALS) && (n < line_length); n++, subsecond_decimals_chars++) { - if (!g_ascii_isdigit((guchar)linebuff[n])) + if (!g_ascii_isdigit((unsigned char)linebuff[n])) { - return FALSE; + return false; } subsecond_decimals_buff[subsecond_decimals_chars] = linebuff[n]; } @@ -570,7 +569,7 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec if (subsecond_decimals_chars > MAX_SUBSECOND_DECIMALS || n >= line_length) { /* More numbers than expected - give up */ - return FALSE; + return false; } /* Convert found value into microseconds */ @@ -586,7 +585,7 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec /* Space character must follow end of timestamp */ if (linebuff[n] != ' ') { - return FALSE; + return false; } n++; @@ -597,32 +596,32 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec (linebuff[n] != ' ') && (protocol_chars < MAX_PROTOCOL_NAME) && (n < line_length); n++, protocol_chars++) { - if (!g_ascii_isalnum((guchar)linebuff[n]) && linebuff[n] != '_' && linebuff[n] != '.' && linebuff[n] != '-') + if (!g_ascii_isalnum((unsigned char)linebuff[n]) && linebuff[n] != '_' && linebuff[n] != '.' && linebuff[n] != '-') { - return FALSE; + return false; } protocol_name[protocol_chars] = linebuff[n]; } if (protocol_chars == MAX_PROTOCOL_NAME || n >= line_length) { /* If doesn't fit, fail rather than truncate */ - return FALSE; + return false; } protocol_name[protocol_chars] = '\0'; /* Space char must follow protocol name */ if (linebuff[n] != ' ') { - return FALSE; + return false; } /* Skip it */ n++; /* Scan ahead to the next space */ - for (; (!g_ascii_isalnum((guchar)linebuff[n])) && (n < line_length); n++); + for (; (!g_ascii_isalnum((unsigned char)linebuff[n])) && (n < line_length); n++); if (n >= line_length) { - return FALSE; + return false; } @@ -631,7 +630,7 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec *direction = uplink; *data_offset = n; *data_chars = line_length - n; - *is_text_data = TRUE; + *is_text_data = true; } else { @@ -646,7 +645,7 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec } else { - return FALSE; + return false; } n++; @@ -660,7 +659,7 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec if (prot_option_chars == MAX_PROTOCOL_PAR_STRING || n >= line_length) { /* If doesn't fit, fail rather than truncate */ - return FALSE; + return false; } /* Skip it */ @@ -672,15 +671,15 @@ gboolean parse_line(gchar* linebuff, gint line_length, gint *seconds, gint *usec /* Set number of chars that comprise the hex string protocol data */ *data_chars = line_length - n; - *is_text_data = FALSE; + *is_text_data = false; } - return TRUE; + return true; } /*****************************************************************/ /* Write the stub info to the data buffer while reading a packet */ /*****************************************************************/ -int write_stub_header(guchar *frame_buffer, char *timestamp_string, +int write_stub_header(unsigned char *frame_buffer, char *timestamp_string, packet_direction_t direction) { int stub_offset = 0; @@ -707,7 +706,7 @@ int write_stub_header(guchar *frame_buffer, char *timestamp_string, /********************************************************/ /* Return hex nibble equivalent of hex string character */ /********************************************************/ -guchar hex_from_char(gchar c) +unsigned char hex_from_char(char c) { if ((c >= '0') && (c <= '9')) { @@ -731,7 +730,7 @@ guchar hex_from_char(gchar c) /********************************************************/ /* Return character corresponding to hex nibble value */ /********************************************************/ -/*gchar char_from_hex(guchar hex) +/*char char_from_hex(unsigned char hex) { static char hex_lookup[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; @@ -747,9 +746,9 @@ guchar hex_from_char(gchar c) /************************************************************************/ /* Parse year, month, day, hour, minute, seconds out of formatted line. */ /* Set secs and usecs as output */ -/* Return FALSE if no valid time can be read */ +/* Return false if no valid time can be read */ /************************************************************************/ -gboolean get_file_time_stamp(gchar* linebuff, time_t *secs, guint32 *usecs) +bool get_file_time_stamp(const char* linebuff, time_t *secs, uint32_t *usecs) { int n; struct tm tm; @@ -762,7 +761,7 @@ gboolean get_file_time_stamp(gchar* linebuff, time_t *secs, guint32 *usecs) /* If line longer than expected, file is probably not correctly formatted */ if (strlen(linebuff) > MAX_TIMESTAMP_LINE_LENGTH) { - return FALSE; + return false; } /**************************************************************/ @@ -788,7 +787,7 @@ gboolean get_file_time_stamp(gchar* linebuff, time_t *secs, guint32 *usecs) else { /* Give up if not found a properly-formatted date */ - return FALSE; + return false; } /* Skip space char */ n++; @@ -800,7 +799,7 @@ gboolean get_file_time_stamp(gchar* linebuff, time_t *secs, guint32 *usecs) if (scan_found != 6) { /* Give up if not all found */ - return FALSE; + return false; } /******************************************************/ @@ -818,7 +817,7 @@ gboolean get_file_time_stamp(gchar* linebuff, time_t *secs, guint32 *usecs) /* Multiply 4 digits given to get micro-seconds */ *usecs = *usecs * 100; - return TRUE; + return true; } static const struct supported_block_type log3gpp_blocks_supported[] = { @@ -830,7 +829,7 @@ static const struct supported_block_type log3gpp_blocks_supported[] = { static const struct file_type_subtype_info log3gpp_info = { "3GPP Log", "3gpp_log", "*.log", NULL, - TRUE, BLOCKS_SUPPORTED(log3gpp_blocks_supported), + true, BLOCKS_SUPPORTED(log3gpp_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/log3gpp.h b/wiretap/log3gpp.h index ff3b3ca8..e5e02e5b 100644 --- a/wiretap/log3gpp.h +++ b/wiretap/log3gpp.h @@ -11,6 +11,6 @@ #include <wtap.h> -wtap_open_return_val log3gpp_open(wtap* wth, int* err, gchar** err_info); +wtap_open_return_val log3gpp_open(wtap* wth, int* err, char** err_info); #endif /* __LOG_3GPP_H__ */ diff --git a/wiretap/logcat.c b/wiretap/logcat.c index fc4eb87b..78ff336d 100644 --- a/wiretap/logcat.c +++ b/wiretap/logcat.c @@ -6,23 +6,22 @@ */ #include "config.h" +#include "logcat.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "logcat.h" - static int logcat_file_type_subtype = -1; void register_logcat(void); /* Returns '?' for invalid priorities */ -static gchar get_priority(const guint8 priority) { - static gchar priorities[] = "??VDIWEFS"; +static char get_priority(const uint8_t priority) { + static char priorities[] = "??VDIWEFS"; - if (priority >= (guint8) sizeof(priorities)) + if (priority >= (uint8_t) sizeof(priorities)) return '?'; return priorities[priority]; @@ -34,23 +33,23 @@ static gchar get_priority(const guint8 priority) { * -2 if we get an EOF at the beginning; * -1 on an I/O error; * 0 if the record doesn't appear to be valid; - * 1-{max gint} as a version number if we got a valid record. + * 1-{max int} as a version number if we got a valid record. */ -static gint detect_version(FILE_T fh, int *err, gchar **err_info) +static int detect_version(FILE_T fh, int *err, char **err_info) { - guint16 payload_length; - guint16 hdr_size; - guint16 read_sofar; - guint16 entry_len; - gint version; + uint16_t payload_length; + uint16_t hdr_size; + uint16_t read_sofar; + uint16_t entry_len; + int version; struct logger_entry *log_entry; struct logger_entry_v2 *log_entry_v2; - guint8 *buffer; - guint16 tmp; - guint8 *msg_payload; - guint8 *msg_part; - guint8 *msg_end; - guint16 msg_len; + uint8_t *buffer; + uint16_t tmp; + uint8_t *msg_payload; + uint8_t *msg_part; + uint8_t *msg_end; + uint16_t msg_len; /* 16-bit payload length */ if (!wtap_read_bytes_or_eof(fh, &tmp, 2, err, err_info)) { @@ -83,7 +82,7 @@ static gint detect_version(FILE_T fh, int *err, gchar **err_info) read_sofar = 4; /* ensure buffer is large enough for all versions */ - buffer = (guint8 *) g_malloc(sizeof(*log_entry_v2) + payload_length); + buffer = (uint8_t *) g_malloc(sizeof(*log_entry_v2) + payload_length); log_entry_v2 = (struct logger_entry_v2 *)(void *) buffer; log_entry = (struct logger_entry *)(void *) buffer; @@ -91,11 +90,11 @@ static gint detect_version(FILE_T fh, int *err, gchar **err_info) * version is in use. First assume the smallest msg. */ for (version = 1; version <= 2; ++version) { if (version == 1) { - msg_payload = (guint8 *) (log_entry + 1); + msg_payload = (uint8_t *) (log_entry + 1); entry_len = sizeof(*log_entry) + payload_length; } else if (version == 2) { /* v2 is 4 bytes longer */ - msg_payload = (guint8 *) (log_entry_v2 + 1); + msg_payload = (uint8_t *) (log_entry_v2 + 1); entry_len = sizeof(*log_entry_v2) + payload_length; if (hdr_size != sizeof(*log_entry_v2)) continue; @@ -116,14 +115,14 @@ static gint detect_version(FILE_T fh, int *err, gchar **err_info) continue; /* Is there a terminating '\0' for the tag? */ - msg_part = (guint8 *) memchr(msg_payload, '\0', payload_length - 1); + msg_part = (uint8_t *) memchr(msg_payload, '\0', payload_length - 1); if (msg_part == NULL) continue; /* if msg is '\0'-terminated, is it equal to the payload len? */ ++msg_part; - msg_len = (guint16)(payload_length - (msg_part - msg_payload)); - msg_end = (guint8 *) memchr(msg_part, '\0', msg_len); + msg_len = (uint16_t)(payload_length - (msg_part - msg_payload)); + msg_end = (uint8_t *) memchr(msg_part, '\0', msg_len); /* is the end of the buffer (-1) equal to the end of msg? */ if (msg_end && (msg_payload + payload_length - 1 != msg_end)) continue; @@ -137,19 +136,19 @@ static gint detect_version(FILE_T fh, int *err, gchar **err_info) return 0; } -gint logcat_exported_pdu_length(const guint8 *pd) { - const guint16 *tag; - const guint16 *tag_length; - gint length = 0; +int logcat_exported_pdu_length(const uint8_t *pd) { + const uint16_t *tag; + const uint16_t *tag_length; + int length = 0; - tag = (const guint16 *)(const void *) pd; + tag = (const uint16_t *)(const void *) pd; while(GINT16_FROM_BE(*tag)) { - tag_length = (const guint16 *)(const void *) (pd + 2); + tag_length = (const uint16_t *)(const void *) (pd + 2); length += 2 + 2 + GINT16_FROM_BE(*tag_length); pd += 2 + 2 + GINT16_FROM_BE(*tag_length); - tag = (const guint16 *)(const void *) pd; + tag = (const uint16_t *)(const void *) pd; } length += 2 + 2; @@ -157,26 +156,26 @@ gint logcat_exported_pdu_length(const guint8 *pd) { return length; } -static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { - gint packet_size; - guint16 payload_length; - guint tmp[2]; - guint8 *pd; + int packet_size; + uint16_t payload_length; + unsigned tmp[2]; + uint8_t *pd; struct logger_entry *log_entry; if (!wtap_read_bytes_or_eof(fh, &tmp, 2, err, err_info)) { - return FALSE; + return false; } payload_length = pletoh16(tmp); if (logcat->version == 1) { - packet_size = (gint)sizeof(struct logger_entry) + payload_length; + packet_size = (int)sizeof(struct logger_entry) + payload_length; } else if (logcat->version == 2) { - packet_size = (gint)sizeof(struct logger_entry_v2) + payload_length; + packet_size = (int)sizeof(struct logger_entry_v2) + payload_length; } else { - return FALSE; + return false; } /* * The maximum value of payload_length is 65535, which, even after @@ -194,7 +193,7 @@ static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh, /* Read the rest of the packet. */ if (!wtap_read_bytes(fh, pd + 2, packet_size - 2, err, err_info)) { - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -207,11 +206,11 @@ static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh, rec->rec_header.packet_header.pseudo_header.logcat.version = logcat->version; - return TRUE; + return true; } -static gboolean logcat_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool logcat_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); @@ -219,26 +218,26 @@ static gboolean logcat_read(wtap *wth, wtap_rec *rec, Buffer *buf, rec, buf, err, err_info); } -static gboolean logcat_seek_read(wtap *wth, gint64 seek_off, +static bool logcat_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, SEEK_SET, err) == -1) - return FALSE; + return false; if (!logcat_read_packet((struct logcat_phdr *) wth->priv, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -wtap_open_return_val logcat_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val logcat_open(wtap *wth, int *err, char **err_info) { - gint version; - gint tmp_version; + int version; + int tmp_version; struct logcat_phdr *logcat; /* check first 3 packets (or 2 or 1 if EOF) versions to check file format is correct */ @@ -316,16 +315,16 @@ static int logcat_dump_can_write_encap(int encap) return 0; } -static gboolean logcat_binary_dump(wtap_dumper *wdh, +static bool logcat_binary_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { int caplen; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -334,14 +333,14 @@ static gboolean logcat_binary_dump(wtap_dumper *wdh, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } caplen = rec->rec_header.packet_header.caplen; /* Skip EXPORTED_PDU*/ if (wdh->file_encap == WTAP_ENCAP_WIRESHARK_UPPER_PDU) { - gint skipped_length; + int skipped_length; skipped_length = logcat_exported_pdu_length(pd); pd += skipped_length; @@ -349,17 +348,17 @@ static gboolean logcat_binary_dump(wtap_dumper *wdh, } if (!wtap_dump_file_write(wdh, pd, caplen, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err _U_, - gchar **err_info _U_) +static bool logcat_binary_dump_open(wtap_dumper *wdh, int *err _U_, + char **err_info _U_) { wdh->subtype_write = logcat_binary_dump; - return TRUE; + return true; } static const struct supported_block_type logcat_blocks_supported[] = { @@ -371,7 +370,7 @@ static const struct supported_block_type logcat_blocks_supported[] = { static const struct file_type_subtype_info logcat_info = { "Android Logcat Binary format", "logcat", "logcat", NULL, - FALSE, BLOCKS_SUPPORTED(logcat_blocks_supported), + false, BLOCKS_SUPPORTED(logcat_blocks_supported), logcat_dump_can_write_encap, logcat_binary_dump_open, NULL }; diff --git a/wiretap/logcat.h b/wiretap/logcat.h index 29ea6d61..25cbb90a 100644 --- a/wiretap/logcat.h +++ b/wiretap/logcat.h @@ -21,33 +21,33 @@ #define LOGGER_ENTRY_MAX_PAYLOAD 4076 struct logger_entry { - guint16 len; /* length of the payload */ - guint16 __pad; /* no matter what, we get 2 bytes of padding */ - gint32 pid; /* generating process's pid */ - gint32 tid; /* generating process's tid */ - gint32 sec; /* seconds since Epoch */ - gint32 nsec; /* nanoseconds */ + uint16_t len; /* length of the payload */ + uint16_t __pad; /* no matter what, we get 2 bytes of padding */ + int32_t pid; /* generating process's pid */ + int32_t tid; /* generating process's tid */ + int32_t sec; /* seconds since Epoch */ + int32_t nsec; /* nanoseconds */ /* char msg[0]; *//* the entry's payload */ }; struct logger_entry_v2 { - guint16 len; /* length of the payload */ - guint16 hdr_size; /* sizeof(struct logger_entry_v2) */ - gint32 pid; /* generating process's pid */ - gint32 tid; /* generating process's tid */ - gint32 sec; /* seconds since Epoch */ - gint32 nsec; /* nanoseconds */ + uint16_t len; /* length of the payload */ + uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */ + int32_t pid; /* generating process's pid */ + int32_t tid; /* generating process's tid */ + int32_t sec; /* seconds since Epoch */ + int32_t nsec; /* nanoseconds */ union { /* v1: not present */ - guint32 euid; /* v2: effective UID of logger */ - guint32 lid; /* v3: log id of the payload */ + uint32_t euid; /* v2: effective UID of logger */ + uint32_t lid; /* v3: log id of the payload */ } id; /* char msg[0]; *//* the entry's payload */ }; -wtap_open_return_val logcat_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val logcat_open(wtap *wth, int *err, char **err_info); -gint logcat_exported_pdu_length(const guint8 *pd); +int logcat_exported_pdu_length(const uint8_t *pd); #endif /* diff --git a/wiretap/logcat_text.c b/wiretap/logcat_text.c index ced74396..5d6f307c 100644 --- a/wiretap/logcat_text.c +++ b/wiretap/logcat_text.c @@ -7,13 +7,13 @@ */ #include "config.h" +#include "logcat_text.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "logcat_text.h" #include "logcat.h" struct dumper_t { @@ -31,24 +31,24 @@ static int logcat_text_long_file_type_subtype = -1; void register_logcat_text(void); /* Returns '?' for invalid priorities */ -static gchar get_priority(const guint8 priority) { - static gchar priorities[] = "??VDIWEFS"; +static char get_priority(const uint8_t priority) { + static char priorities[] = "??VDIWEFS"; - if (priority >= (guint8) sizeof(priorities)) + if (priority >= (uint8_t) sizeof(priorities)) return '?'; return priorities[priority]; } -static gint buffered_detect_version(const guint8 *pd) +static int buffered_detect_version(const uint8_t *pd) { const struct logger_entry *log_entry; const struct logger_entry_v2 *log_entry_v2; - gint version; - const guint8 *msg_payload = NULL; - guint8 *msg_part; - guint8 *msg_end; - guint16 msg_len; + int version; + const uint8_t *msg_payload = NULL; + uint8_t *msg_part; + uint8_t *msg_end; + uint16_t msg_len; log_entry = (const struct logger_entry *)(const void *) pd; log_entry_v2 = (const struct logger_entry_v2 *)(const void *) pd; @@ -65,10 +65,10 @@ static gint buffered_detect_version(const guint8 *pd) * version is in use. First assume the smallest msg. */ for (version = 1; version <= 2; ++version) { if (version == 1) { - msg_payload = (const guint8 *) (log_entry + 1); + msg_payload = (const uint8_t *) (log_entry + 1); } else if (version == 2) { /* v2 is 4 bytes longer */ - msg_payload = (const guint8 *) (log_entry_v2 + 1); + msg_payload = (const uint8_t *) (log_entry_v2 + 1); if (log_entry_v2->hdr_size != sizeof(*log_entry_v2)) continue; } @@ -78,14 +78,14 @@ static gint buffered_detect_version(const guint8 *pd) continue; /* Is there a terminating '\0' for the tag? */ - msg_part = (guint8 *) memchr(msg_payload, '\0', log_entry->len - 1); + msg_part = (uint8_t *) memchr(msg_payload, '\0', log_entry->len - 1); if (msg_part == NULL) continue; /* if msg is '\0'-terminated, is it equal to the payload len? */ ++msg_part; - msg_len = (guint16)(log_entry->len - (msg_part - msg_payload)); - msg_end = (guint8 *) memchr(msg_part, '\0', msg_len); + msg_len = (uint16_t)(log_entry->len - (msg_part - msg_payload)); + msg_end = (uint8_t *) memchr(msg_part, '\0', msg_len); /* is the end of the buffer (-1) equal to the end of msg? */ if (msg_end && (msg_payload + log_entry->len - 1 != msg_end)) continue; @@ -96,11 +96,11 @@ static gint buffered_detect_version(const guint8 *pd) return -1; } -static gchar *logcat_log(const struct dumper_t *dumper, guint32 seconds, - gint milliseconds, gint pid, gint tid, gchar priority, const gchar *tag, - const gchar *log) +static char *logcat_log(const struct dumper_t *dumper, uint32_t seconds, + int milliseconds, int pid, int tid, char priority, const char *tag, + const char *log) { - gchar time_buffer[15]; + char time_buffer[15]; time_t datetime; struct tm *tm; @@ -160,8 +160,8 @@ static gchar *logcat_log(const struct dumper_t *dumper, guint32 seconds, } -static void get_time(gchar *string, wtap_rec *rec) { - gint ms; +static void get_time(char *string, wtap_rec *rec) { + int ms; struct tm date; time_t seconds; @@ -181,30 +181,30 @@ static void get_time(gchar *string, wtap_rec *rec) { } } -static gboolean logcat_text_read_packet(FILE_T fh, wtap_rec *rec, - Buffer *buf, gint file_type) { - gint8 *pd; - gchar *cbuff; - gchar *ret = NULL; +static bool logcat_text_read_packet(FILE_T fh, wtap_rec *rec, + Buffer *buf, int file_type) { + int8_t *pd; + char *cbuff; + char *ret = NULL; - cbuff = (gchar*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); + cbuff = (char*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); do { ret = file_gets(cbuff, WTAP_MAX_PACKET_SIZE_STANDARD, fh); } while (NULL != ret && 3 > strlen(cbuff) && !file_eof(fh)); if (NULL == ret || 3 > strlen(cbuff)) { g_free(cbuff); - return FALSE; + return false; } if (logcat_text_long_file_type_subtype == file_type && !g_regex_match_simple(SPECIAL_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW), G_REGEX_MATCH_NOTEMPTY)) { - gint64 file_off = 0; - gchar *lbuff; + int64_t file_off = 0; + char *lbuff; int err; - gchar *ret2 = NULL; + char *ret2 = NULL; - lbuff = (gchar*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); + lbuff = (char*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); file_off = file_tell(fh); ret2 = file_gets(lbuff,WTAP_MAX_PACKET_SIZE_STANDARD, fh); while (NULL != ret2 && 2 < strlen(lbuff) && !file_eof(fh)) { @@ -216,7 +216,7 @@ static gboolean logcat_text_read_packet(FILE_T fh, wtap_rec *rec, if(NULL == ret2 || 2 < strlen(lbuff)) { g_free(cbuff); g_free(lbuff); - return FALSE; + return false; } file_seek(fh,file_off,SEEK_SET,&err); @@ -225,7 +225,7 @@ static gboolean logcat_text_read_packet(FILE_T fh, wtap_rec *rec, rec->rec_type = REC_TYPE_PACKET; rec->block = wtap_block_create(WTAP_BLOCK_PACKET); - rec->rec_header.packet_header.caplen = (guint32)strlen(cbuff); + rec->rec_header.packet_header.caplen = (uint32_t)strlen(cbuff); rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen; ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen + 1); @@ -246,38 +246,38 @@ static gboolean logcat_text_read_packet(FILE_T fh, wtap_rec *rec, } memcpy(pd, cbuff, rec->rec_header.packet_header.caplen + 1); g_free(cbuff); - return TRUE; + return true; } -static gboolean logcat_text_read(wtap *wth, wtap_rec *rec, - Buffer *buf, int *err _U_ , gchar **err_info _U_, gint64 *data_offset) { +static bool logcat_text_read(wtap *wth, wtap_rec *rec, + Buffer *buf, int *err _U_ , char **err_info _U_, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return logcat_text_read_packet(wth->fh, rec, buf, wth->file_type_subtype); } -static gboolean logcat_text_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info _U_) { +static bool logcat_text_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info _U_) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (!logcat_text_read_packet(wth->random_fh, rec, buf, wth->file_type_subtype)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -wtap_open_return_val logcat_text_open(wtap *wth, int *err, gchar **err_info _U_) { - gchar *cbuff; - gchar *ret = NULL; +wtap_open_return_val logcat_text_open(wtap *wth, int *err, char **err_info _U_) { + char *cbuff; + char *ret = NULL; if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) return WTAP_OPEN_ERROR; - cbuff = (gchar*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); + cbuff = (char*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD); do { ret = file_gets(cbuff, WTAP_MAX_PACKET_SIZE_STANDARD, wth->fh); } while (NULL != ret && !file_eof(wth->fh) @@ -429,34 +429,34 @@ static int logcat_text_long_dump_can_write_encap(int encap) { } } -static gboolean logcat_text_dump_text(wtap_dumper *wdh, +static bool logcat_text_dump_text(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info) + const uint8_t *pd, int *err, char **err_info) { - gchar *buf; - gint length; - gchar priority; + char *buf; + int length; + char priority; const struct logger_entry *log_entry; const struct logger_entry_v2 *log_entry_v2; - gint payload_length; - const gchar *tag; - gint32 pid; - gint32 tid; - gint32 seconds; - gint32 milliseconds; - const guint8 *msg_payload = NULL; - const gchar *msg_begin; - gint msg_pre_skip; - gchar *log; - gchar *log_part; - gchar *log_next; - gint logcat_version; + int payload_length; + const char *tag; + int32_t pid; + int32_t tid; + int32_t seconds; + int32_t milliseconds; + const uint8_t *msg_payload = NULL; + const char *msg_begin; + int msg_pre_skip; + char *log; + char *log_part; + char *log_next; + int logcat_version; const struct dumper_t *dumper = (const struct dumper_t *) wdh->priv; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -465,26 +465,26 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } switch (wdh->file_encap) { case WTAP_ENCAP_WIRESHARK_UPPER_PDU: { - gint skipped_length; + int skipped_length; skipped_length = logcat_exported_pdu_length(pd); pd += skipped_length; - if (!wtap_dump_file_write(wdh, (const gchar*) pd, rec->rec_header.packet_header.caplen - skipped_length, err)) { - return FALSE; + if (!wtap_dump_file_write(wdh, (const char*) pd, rec->rec_header.packet_header.caplen - skipped_length, err)) { + return false; } } break; case WTAP_ENCAP_LOGCAT: /* Skip EXPORTED_PDU*/ if (wdh->file_encap == WTAP_ENCAP_WIRESHARK_UPPER_PDU) { - gint skipped_length; + int skipped_length; skipped_length = logcat_exported_pdu_length(pd); pd += skipped_length; @@ -507,24 +507,24 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, /* msg: <prio:1><tag:N>\0<msg:N>\0 with N >= 0, last \0 can be missing */ if (logcat_version == 1) { - msg_payload = (const guint8 *) (log_entry + 1); + msg_payload = (const uint8_t *) (log_entry + 1); priority = get_priority(msg_payload[0]); tag = msg_payload + 1; - msg_pre_skip = 1 + (gint) strlen(tag) + 1; + msg_pre_skip = 1 + (int) strlen(tag) + 1; msg_begin = msg_payload + msg_pre_skip; } else if (logcat_version == 2) { - msg_payload = (const guint8 *) (log_entry_v2 + 1); + msg_payload = (const uint8_t *) (log_entry_v2 + 1); priority = get_priority(msg_payload[0]); tag = msg_payload + 1; - msg_pre_skip = 1 + (gint) strlen(tag) + 1; + msg_pre_skip = 1 + (int) strlen(tag) + 1; msg_begin = msg_payload + msg_pre_skip; } else { *err = WTAP_ERR_UNWRITABLE_REC_DATA; *err_info = ws_strdup_printf("logcat: version %d isn't supported", logcat_version); - return FALSE; + return false; } /* copy the message part. If a nul byte was missing, it will be added. */ @@ -554,13 +554,13 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, buf = logcat_log(dumper, seconds, milliseconds, pid, tid, priority, tag, log_part); if (!buf) { g_free(log); - return FALSE; + return false; } - length = (guint32) strlen(buf); + length = (uint32_t) strlen(buf); if (!wtap_dump_file_write(wdh, buf, length, err)) { g_free(log); - return FALSE; + return false; } } while (log_next != NULL ); @@ -575,19 +575,19 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, case WTAP_ENCAP_LOGCAT_THREADTIME: case WTAP_ENCAP_LOGCAT_LONG: if (dumper->type == wdh->file_encap) { - if (!wtap_dump_file_write(wdh, (const gchar*) pd, rec->rec_header.packet_header.caplen, err)) { - return FALSE; + if (!wtap_dump_file_write(wdh, (const char*) pd, rec->rec_header.packet_header.caplen, err)) { + return false; } } else { *err = WTAP_ERR_UNWRITABLE_FILE_TYPE; - return FALSE; + return false; } } - return TRUE; + return true; } -static gboolean logcat_text_dump_open(wtap_dumper *wdh, guint dump_type) { +static bool logcat_text_dump_open(wtap_dumper *wdh, unsigned dump_type) { struct dumper_t *dumper; dumper = g_new(struct dumper_t, 1); @@ -596,34 +596,34 @@ static gboolean logcat_text_dump_open(wtap_dumper *wdh, guint dump_type) { wdh->priv = dumper; wdh->subtype_write = logcat_text_dump_text; - return TRUE; + return true; } -static gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) { +static bool logcat_text_brief_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_BRIEF); } -static gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) { +static bool logcat_text_process_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_PROCESS); } -static gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) { +static bool logcat_text_tag_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_TAG); } -static gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) { +static bool logcat_text_time_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_TIME); } -static gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) { +static bool logcat_text_thread_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_THREAD); } -static gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) { +static bool logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_THREADTIME); } -static gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) { +static bool logcat_text_long_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) { return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_LONG); } @@ -636,7 +636,7 @@ static const struct supported_block_type logcat_text_brief_blocks_supported[] = static const struct file_type_subtype_info logcat_text_brief_info = { "Android Logcat Brief text format", "logcat-brief", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(logcat_text_brief_blocks_supported), + false, BLOCKS_SUPPORTED(logcat_text_brief_blocks_supported), logcat_text_brief_dump_can_write_encap, logcat_text_brief_dump_open, NULL }; @@ -649,7 +649,7 @@ static const struct supported_block_type logcat_text_process_blocks_supported[] static const struct file_type_subtype_info logcat_text_process_info = { "Android Logcat Process text format", "logcat-process", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(logcat_text_process_blocks_supported), + false, BLOCKS_SUPPORTED(logcat_text_process_blocks_supported), logcat_text_process_dump_can_write_encap, logcat_text_process_dump_open, NULL }; @@ -662,7 +662,7 @@ static const struct supported_block_type logcat_text_tag_blocks_supported[] = { static const struct file_type_subtype_info logcat_text_tag_info = { "Android Logcat Tag text format", "logcat-tag", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(logcat_text_tag_blocks_supported), + false, BLOCKS_SUPPORTED(logcat_text_tag_blocks_supported), logcat_text_tag_dump_can_write_encap, logcat_text_tag_dump_open, NULL }; @@ -675,7 +675,7 @@ static const struct supported_block_type logcat_text_thread_blocks_supported[] = static const struct file_type_subtype_info logcat_text_thread_info = { "Android Logcat Thread text format", "logcat-thread", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(logcat_text_thread_blocks_supported), + false, BLOCKS_SUPPORTED(logcat_text_thread_blocks_supported), logcat_text_thread_dump_can_write_encap, logcat_text_thread_dump_open, NULL }; @@ -688,7 +688,7 @@ static const struct supported_block_type logcat_text_time_blocks_supported[] = { static const struct file_type_subtype_info logcat_text_time_info = { "Android Logcat Time text format", "logcat-time", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(logcat_text_time_blocks_supported), + false, BLOCKS_SUPPORTED(logcat_text_time_blocks_supported), logcat_text_time_dump_can_write_encap, logcat_text_time_dump_open, NULL }; @@ -701,7 +701,7 @@ static const struct supported_block_type logcat_text_threadtime_blocks_supported static const struct file_type_subtype_info logcat_text_threadtime_info = { "Android Logcat Threadtime text format", "logcat-threadtime", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(logcat_text_threadtime_blocks_supported), + false, BLOCKS_SUPPORTED(logcat_text_threadtime_blocks_supported), logcat_text_threadtime_dump_can_write_encap, logcat_text_threadtime_dump_open, NULL }; @@ -714,7 +714,7 @@ static const struct supported_block_type logcat_text_long_blocks_supported[] = { static const struct file_type_subtype_info logcat_text_long_info = { "Android Logcat Long text format", "logcat-long", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(logcat_text_long_blocks_supported), + false, BLOCKS_SUPPORTED(logcat_text_long_blocks_supported), logcat_text_long_dump_can_write_encap, logcat_text_long_dump_open, NULL }; diff --git a/wiretap/logcat_text.h b/wiretap/logcat_text.h index c8bd5026..ad8c8300 100644 --- a/wiretap/logcat_text.h +++ b/wiretap/logcat_text.h @@ -22,7 +22,7 @@ #define THREADTIME_STRING "(\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3}) +(\\d+) +(\\d+) ([IVDWEF]) (.*?): (.*)" #define LONG_STRING "\\[ (\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3}) +(\\d+): *(\\d+) ([IVDWEF])/(.+) ]\\R(.*)" -wtap_open_return_val logcat_text_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val logcat_text_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/merge.c b/wiretap/merge.c index 3c007dd6..86336013 100644 --- a/wiretap/merge.c +++ b/wiretap/merge.c @@ -15,6 +15,7 @@ #include "config.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP +#include "merge.h" #include <stdlib.h> #include <errno.h> @@ -32,7 +33,6 @@ #endif #include <string.h> -#include "merge.h" #include "wtap_opttypes.h" #include "wtap-int.h" @@ -84,7 +84,7 @@ cleanup_in_file(merge_in_file_t *in_file) wtap_close(in_file->wth); in_file->wth = NULL; - g_array_free(in_file->idb_index_map, TRUE); + g_array_free(in_file->idb_index_map, true); in_file->idb_index_map = NULL; wtap_rec_cleanup(&in_file->rec); @@ -92,7 +92,7 @@ cleanup_in_file(merge_in_file_t *in_file) } static void -add_idb_index_map(merge_in_file_t *in_file, const guint orig_index _U_, const guint found_index) +add_idb_index_map(merge_in_file_t *in_file, const unsigned orig_index _U_, const unsigned found_index) { ws_assert(in_file != NULL); ws_assert(in_file->idb_index_map != NULL); @@ -174,16 +174,16 @@ raise_limit(int resource, unsigned add) * @return The number of input files opened, which can be less than * the number requested if the limit of open file descriptors is reached. */ -static guint -merge_open_in_files(guint in_file_count, const char *const *in_file_names, +static unsigned +merge_open_in_files(unsigned in_file_count, const char *const *in_file_names, merge_in_file_t **out_files, merge_progress_callback_t* cb, - int *err, gchar **err_info, guint *err_fileno) + int *err, char **err_info, unsigned *err_fileno) { - guint i = 0; - guint j; + unsigned i = 0; + unsigned j; size_t files_size = in_file_count * sizeof(merge_in_file_t); merge_in_file_t *files; - gint64 size; + int64_t size; #ifndef _WIN32 bool try_raise_nofile = false; #endif @@ -193,7 +193,7 @@ merge_open_in_files(guint in_file_count, const char *const *in_file_names, while (i < in_file_count) { files[i].filename = in_file_names[i]; - files[i].wth = wtap_open_offline(in_file_names[i], WTAP_TYPE_AUTO, err, err_info, FALSE); + files[i].wth = wtap_open_offline(in_file_names[i], WTAP_TYPE_AUTO, err, err_info, false); files[i].state = RECORD_NOT_PRESENT; files[i].packet_num = 0; @@ -231,7 +231,7 @@ merge_open_in_files(guint in_file_count, const char *const *in_file_names, } size = wtap_file_size(files[i].wth, err); if (size == -1) { - for (j = 0; j != G_MAXUINT && j <= i; j++) + for (j = 0; j != UINT_MAX && j <= i; j++) cleanup_in_file(&files[j]); g_free(files); *err_fileno = i; @@ -240,7 +240,7 @@ merge_open_in_files(guint in_file_count, const char *const *in_file_names, wtap_rec_init(&files[i].rec); ws_buffer_init(&files[i].frame_buffer, 1514); files[i].size = size; - files[i].idb_index_map = g_array_new(FALSE, FALSE, sizeof(guint)); + files[i].idb_index_map = g_array_new(false, false, sizeof(unsigned)); i++; } @@ -305,22 +305,22 @@ merge_select_frame_type(const int file_type, int in_file_count, merge_in_file_t } /* - * returns TRUE if first argument is earlier than second + * returns true if first argument is earlier than second */ -static gboolean +static bool is_earlier(nstime_t *l, nstime_t *r) /* XXX, move to nstime.c */ { if (l->secs > r->secs) { /* left is later */ - return FALSE; + return false; } else if (l->secs < r->secs) { /* left is earlier */ - return TRUE; + return true; } else if (l->nsecs > r->nsecs) { /* tv_sec equal, l.usec later */ - return FALSE; + return false; } /* either one < two or one == two * either way, return one */ - return TRUE; + return true; } /** Read the next packet, in chronological order, from the set of files to @@ -345,7 +345,7 @@ is_earlier(nstime_t *l, nstime_t *r) /* XXX, move to nstime.c */ */ static merge_in_file_t * merge_read_packet(int in_file_count, merge_in_file_t in_files[], - int *err, gchar **err_info) + int *err, char **err_info) { int i; int ei = -1; @@ -360,7 +360,7 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[], * merge of those records, but you obviously *can't* get that. */ for (i = 0; i < in_file_count; i++) { - gint64 data_offset; + int64_t data_offset; if (in_files[i].state == RECORD_NOT_PRESENT) { /* @@ -442,10 +442,10 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[], */ static merge_in_file_t * merge_append_read_packet(int in_file_count, merge_in_file_t in_files[], - int *err, gchar **err_info) + int *err, char **err_info) { int i; - gint64 data_offset; + int64_t data_offset; /* * Find the first file not at EOF, and read the next packet from it. @@ -482,18 +482,17 @@ merge_append_read_packet(int in_file_count, merge_in_file_t in_files[], /* creates a section header block for the new output file */ static GArray* -create_shb_header(const merge_in_file_t *in_files, const guint in_file_count, - const gchar *app_name) +create_shb_header(const merge_in_file_t *in_files, const unsigned in_file_count, + const char *app_name) { GArray *shb_hdrs; wtap_block_t shb_hdr; GString *comment_gstr; GString *os_info_str; - guint i; - char* shb_comment = NULL; + unsigned i; wtapng_section_mandatory_t* shb_data; - gsize opt_len; - gchar *opt_str; + size_t opt_len; + char *opt_str; shb_hdrs = wtap_file_get_shb_for_new_file(in_files[0].wth); shb_hdr = g_array_index(shb_hdrs, wtap_block_t, 0); @@ -505,14 +504,7 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count, * * XXX - do we want some way to record which comments, hardware/OS/app * descriptions, IDBs, etc.? came from which files? - * - * XXX - fix this to handle multiple comments from a single file. */ - if (wtap_block_get_nth_string_option_value(shb_hdr, OPT_COMMENT, 0, &shb_comment) == WTAP_OPTTYPE_SUCCESS && - strlen(shb_comment) > 0) { - /* very lame way to save comments - does not save them from the other files */ - g_string_append_printf(comment_gstr, "%s \n",shb_comment); - } g_string_append_printf(comment_gstr, "File created by merging: \n"); @@ -526,10 +518,14 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count, shb_data = (wtapng_section_mandatory_t*)wtap_block_get_mandatory_data(shb_hdr); shb_data->section_length = -1; /* TODO: handle comments from each file being merged */ - opt_len = comment_gstr->len; + /* XXX: 65535 is the maximum size for an option (hence comment) in pcapng. + * Truncate it? Let wiretap/pcapng.c decide what to do? (Currently it + * writes nothing without reporting an error.) What if we support other + * output file formats later? + */ opt_str = g_string_free(comment_gstr, FALSE); - wtap_block_set_nth_string_option_value(shb_hdr, OPT_COMMENT, 0, opt_str, opt_len); /* section comment */ - g_free(opt_str); + /* XXX: We probably want to prepend (insert at index 0) instead? */ + wtap_block_add_string_option_owned(shb_hdr, OPT_COMMENT, opt_str); /* * XXX - and how do we preserve all the OPT_SHB_HARDWARE, OPT_SHB_OS, * and OPT_SHB_USERAPPL values from all the previous files? @@ -553,14 +549,14 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count, return shb_hdrs; } -static gboolean +static bool is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) { wtapng_if_descr_mandatory_t *idb1_mand, *idb2_mand; - gboolean have_idb1_value, have_idb2_value; - guint64 idb1_if_speed, idb2_if_speed; - guint8 idb1_if_tsresol, idb2_if_tsresol; - guint8 idb1_if_fcslen, idb2_if_fcslen; + bool have_idb1_value, have_idb2_value; + uint64_t idb1_if_speed, idb2_if_speed; + uint8_t idb1_if_tsresol, idb2_if_tsresol; + uint8_t idb1_if_fcslen, idb2_if_fcslen; char *idb1_opt_comment, *idb2_opt_comment; char *idb1_if_name, *idb2_if_name; char *idb1_if_description, *idb2_if_description; @@ -573,41 +569,41 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) ws_debug("merge::is_duplicate_idb() called"); ws_debug("idb1_mand->wtap_encap == idb2_mand->wtap_encap: %s", - (idb1_mand->wtap_encap == idb2_mand->wtap_encap) ? "TRUE":"FALSE"); + (idb1_mand->wtap_encap == idb2_mand->wtap_encap) ? "true":"false"); if (idb1_mand->wtap_encap != idb2_mand->wtap_encap) { /* Clearly not the same interface. */ - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } ws_debug("idb1_mand->time_units_per_second == idb2_mand->time_units_per_second: %s", - (idb1_mand->time_units_per_second == idb2_mand->time_units_per_second) ? "TRUE":"FALSE"); + (idb1_mand->time_units_per_second == idb2_mand->time_units_per_second) ? "true":"false"); if (idb1_mand->time_units_per_second != idb2_mand->time_units_per_second) { /* * Probably not the same interface, and we can't combine them * in any case. */ - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } ws_debug("idb1_mand->tsprecision == idb2_mand->tsprecision: %s", - (idb1_mand->tsprecision == idb2_mand->tsprecision) ? "TRUE":"FALSE"); + (idb1_mand->tsprecision == idb2_mand->tsprecision) ? "true":"false"); if (idb1_mand->tsprecision != idb2_mand->tsprecision) { /* * Probably not the same interface, and we can't combine them * in any case. */ - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } /* XXX: should snaplen not be compared? */ ws_debug("idb1_mand->snap_len == idb2_mand->snap_len: %s", - (idb1_mand->snap_len == idb2_mand->snap_len) ? "TRUE":"FALSE"); + (idb1_mand->snap_len == idb2_mand->snap_len) ? "true":"false"); if (idb1_mand->snap_len != idb2_mand->snap_len) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } /* XXX - what do to if we have only one value? */ @@ -615,10 +611,10 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) have_idb2_value = (wtap_block_get_uint64_option_value(idb2, OPT_IDB_SPEED, &idb2_if_speed) == WTAP_OPTTYPE_SUCCESS); if (have_idb1_value && have_idb2_value) { ws_debug("idb1_if_speed == idb2_if_speed: %s", - (idb1_if_speed == idb2_if_speed) ? "TRUE":"FALSE"); + (idb1_if_speed == idb2_if_speed) ? "true":"false"); if (idb1_if_speed != idb2_if_speed) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } } @@ -627,10 +623,10 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) have_idb2_value = (wtap_block_get_uint8_option_value(idb2, OPT_IDB_TSRESOL, &idb2_if_tsresol) == WTAP_OPTTYPE_SUCCESS); if (have_idb1_value && have_idb2_value) { ws_debug("idb1_if_tsresol == idb2_if_tsresol: %s", - (idb1_if_tsresol == idb2_if_tsresol) ? "TRUE":"FALSE"); + (idb1_if_tsresol == idb2_if_tsresol) ? "true":"false"); if (idb1_if_tsresol != idb2_if_tsresol) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } } @@ -639,10 +635,10 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) have_idb2_value = (wtap_block_get_uint8_option_value(idb2, OPT_IDB_FCSLEN, &idb2_if_fcslen) == WTAP_OPTTYPE_SUCCESS); if (have_idb1_value && have_idb2_value) { ws_debug("idb1_if_fcslen == idb2_if_fcslen: %s", - (idb1_if_fcslen == idb2_if_fcslen) ? "TRUE":"FALSE"); + (idb1_if_fcslen == idb2_if_fcslen) ? "true":"false"); if (idb1_if_fcslen == idb2_if_fcslen) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } } @@ -657,10 +653,10 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) have_idb2_value = (wtap_block_get_nth_string_option_value(idb2, OPT_COMMENT, 0, &idb2_opt_comment) == WTAP_OPTTYPE_SUCCESS); if (have_idb1_value && have_idb2_value) { ws_debug("g_strcmp0(idb1_opt_comment, idb2_opt_comment) == 0: %s", - (g_strcmp0(idb1_opt_comment, idb2_opt_comment) == 0) ? "TRUE":"FALSE"); + (g_strcmp0(idb1_opt_comment, idb2_opt_comment) == 0) ? "true":"false"); if (g_strcmp0(idb1_opt_comment, idb2_opt_comment) != 0) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } } @@ -669,10 +665,10 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) have_idb2_value = (wtap_block_get_string_option_value(idb2, OPT_IDB_NAME, &idb2_if_name) == WTAP_OPTTYPE_SUCCESS); if (have_idb1_value && have_idb2_value) { ws_debug("g_strcmp0(idb1_if_name, idb2_if_name) == 0: %s", - (g_strcmp0(idb1_if_name, idb2_if_name) == 0) ? "TRUE":"FALSE"); + (g_strcmp0(idb1_if_name, idb2_if_name) == 0) ? "true":"false"); if (g_strcmp0(idb1_if_name, idb2_if_name) != 0) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } } @@ -681,10 +677,10 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) have_idb2_value = (wtap_block_get_string_option_value(idb2, OPT_IDB_DESCRIPTION, &idb2_if_description) == WTAP_OPTTYPE_SUCCESS); if (have_idb1_value && have_idb2_value) { ws_debug("g_strcmp0(idb1_if_description, idb2_if_description) == 0: %s", - (g_strcmp0(idb1_if_description, idb2_if_description) == 0) ? "TRUE":"FALSE"); + (g_strcmp0(idb1_if_description, idb2_if_description) == 0) ? "true":"false"); if (g_strcmp0(idb1_if_description, idb2_if_description) != 0) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } } @@ -693,10 +689,10 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) have_idb2_value = (wtap_block_get_string_option_value(idb2, OPT_IDB_HARDWARE, &idb2_if_hardware) == WTAP_OPTTYPE_SUCCESS); if (have_idb1_value && have_idb2_value) { ws_debug("g_strcmp0(idb1_if_hardware, idb2_if_hardware) == 0: %s", - (g_strcmp0(idb1_if_hardware, idb2_if_hardware) == 0) ? "TRUE":"FALSE"); + (g_strcmp0(idb1_if_hardware, idb2_if_hardware) == 0) ? "true":"false"); if (g_strcmp0(idb1_if_hardware, idb2_if_hardware) != 0) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } } @@ -705,29 +701,29 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2) have_idb2_value = (wtap_block_get_string_option_value(idb2, OPT_IDB_OS, &idb2_if_os) == WTAP_OPTTYPE_SUCCESS); if (have_idb1_value && have_idb2_value) { ws_debug("g_strcmp0(idb1_if_os, idb2_if_os) == 0: %s", - (g_strcmp0(idb1_if_os, idb2_if_os) == 0) ? "TRUE":"FALSE"); + (g_strcmp0(idb1_if_os, idb2_if_os) == 0) ? "true":"false"); if (g_strcmp0(idb1_if_os, idb2_if_os) != 0) { - ws_debug("returning FALSE"); - return FALSE; + ws_debug("returning false"); + return false; } } /* does not compare filters nor interface statistics */ - ws_debug("returning TRUE"); - return TRUE; + ws_debug("returning true"); + return true; } /* * Returns true if all of the input files have duplicate IDBs to the other files. */ -static gboolean -all_idbs_are_duplicates(const merge_in_file_t *in_files, const guint in_file_count) +static bool +all_idbs_are_duplicates(const merge_in_file_t *in_files, const unsigned in_file_count) { wtapng_iface_descriptions_t *first_idb_list = NULL; wtapng_iface_descriptions_t *other_idb_list = NULL; - guint first_idb_list_size, other_idb_list_size; + unsigned first_idb_list_size, other_idb_list_size; wtap_block_t first_file_idb, other_file_idb; - guint i, j; + unsigned i, j; ws_assert(in_files != NULL); @@ -748,7 +744,7 @@ all_idbs_are_duplicates(const merge_in_file_t *in_files, const guint in_file_cou first_idb_list_size, other_idb_list_size); g_free(other_idb_list); g_free(first_idb_list); - return FALSE; + return false; } for (j = 0; j < other_idb_list_size; j++) { @@ -756,20 +752,20 @@ all_idbs_are_duplicates(const merge_in_file_t *in_files, const guint in_file_cou other_file_idb = g_array_index(other_idb_list->interface_data, wtap_block_t, j); if (!is_duplicate_idb(first_file_idb, other_file_idb)) { - ws_debug("IDBs at index %d do not match, returning FALSE", j); + ws_debug("IDBs at index %d do not match, returning false", j); g_free(other_idb_list); g_free(first_idb_list); - return FALSE; + return false; } } g_free(other_idb_list); } - ws_debug("returning TRUE"); + ws_debug("returning true"); g_free(first_idb_list); - return TRUE; + return true; } /* @@ -781,13 +777,13 @@ all_idbs_are_duplicates(const merge_in_file_t *in_files, const guint in_file_cou * considered a success. That means it will even match another IDB from its * own (same) input file. */ -static gboolean +static bool find_duplicate_idb(const wtap_block_t input_file_idb, const wtapng_iface_descriptions_t *merged_idb_list, - guint *found_index) + unsigned *found_index) { wtap_block_t merged_idb; - guint i; + unsigned i; ws_assert(input_file_idb != NULL); ws_assert(merged_idb_list != NULL); @@ -799,21 +795,21 @@ find_duplicate_idb(const wtap_block_t input_file_idb, if (is_duplicate_idb(input_file_idb, merged_idb)) { *found_index = i; - return TRUE; + return true; } } - return FALSE; + return false; } /* Adds IDB to merged file info. If pdh is not NULL, also tries to * add the IDB to the file (if the file type supports writing IDBs). - * returns TRUE on success + * returns true on success * (merged_idb_list->interface_data->len - 1 is the new index) */ -static gboolean +static bool add_idb_to_merged_file(wtapng_iface_descriptions_t *merged_idb_list, const wtap_block_t input_file_idb, wtap_dumper *pdh, - int *err, gchar **err_info) + int *err, char **err_info) { wtap_block_t idb; wtapng_if_descr_mandatory_t* idb_mand; @@ -832,28 +828,33 @@ add_idb_to_merged_file(wtapng_iface_descriptions_t *merged_idb_list, if (pdh != NULL) { if (wtap_file_type_subtype_supports_block(wtap_dump_file_type_subtype(pdh), WTAP_BLOCK_IF_ID_AND_INFO) != BLOCK_NOT_SUPPORTED) { if (!wtap_dump_add_idb(pdh, input_file_idb, err, err_info)) { - return FALSE; + return false; } } } g_array_append_val(merged_idb_list->interface_data, idb); - return TRUE; + return true; } /* * Create clone IDBs for the merge file for IDBs found in the middle of * input files while processing. */ -static gboolean -process_new_idbs(wtap_dumper *pdh, merge_in_file_t *in_files, const guint in_file_count, const idb_merge_mode mode, wtapng_iface_descriptions_t *merged_idb_list, int *err, gchar **err_info) +static bool +process_new_idbs(wtap_dumper *pdh, merge_in_file_t *in_files, const unsigned in_file_count, const idb_merge_mode mode, wtapng_iface_descriptions_t *merged_idb_list, int *err, char **err_info) { wtap_block_t input_file_idb; - guint itf_count, merged_index; - guint i; + unsigned itf_count, merged_index; + unsigned i; for (i = 0; i < in_file_count; i++) { + /* + * The number below is the global interface number within wth, + * not the number within the section. We will do both mappings + * in map_rec_interface_id(). + */ itf_count = in_files[i].wth->next_interface_data; while ((input_file_idb = wtap_get_next_interface_description(in_files[i].wth)) != NULL) { @@ -890,30 +891,30 @@ process_new_idbs(wtap_dumper *pdh, merge_in_file_t *in_files, const guint in_fil merged_index = merged_idb_list->interface_data->len - 1; add_idb_index_map(&in_files[i], itf_count, merged_index); } else { - return FALSE; + return false; } } itf_count = in_files[i].wth->next_interface_data; } } - return TRUE; + return true; } /* * Create clone IDBs for the merge file, based on the input files and mode. */ static wtapng_iface_descriptions_t * -generate_merged_idbs(merge_in_file_t *in_files, const guint in_file_count, idb_merge_mode * const mode) +generate_merged_idbs(merge_in_file_t *in_files, const unsigned in_file_count, idb_merge_mode * const mode) { wtapng_iface_descriptions_t *merged_idb_list = NULL; wtap_block_t input_file_idb; - guint itf_count, merged_index; - guint i; + unsigned itf_count, merged_index; + unsigned i; /* create new IDB info */ merged_idb_list = g_new(wtapng_iface_descriptions_t,1); - merged_idb_list->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + merged_idb_list->interface_data = g_array_new(false, false, sizeof(wtap_block_t)); if (*mode == IDB_MERGE_MODE_ALL_SAME && all_idbs_are_duplicates(in_files, in_file_count)) { ws_debug("mode ALL set and all IDBs are duplicates"); @@ -979,46 +980,60 @@ generate_merged_idbs(merge_in_file_t *in_files, const guint in_file_count, idb_m return merged_idb_list; } -static gboolean +static bool map_rec_interface_id(wtap_rec *rec, const merge_in_file_t *in_file) { - guint current_interface_id = 0; + unsigned current_interface_id = 0; ws_assert(rec != NULL); ws_assert(in_file != NULL); ws_assert(in_file->idb_index_map != NULL); if (rec->presence_flags & WTAP_HAS_INTERFACE_ID) { - current_interface_id = rec->rec_header.packet_header.interface_id; + unsigned section_num = (rec->presence_flags & WTAP_HAS_SECTION_NUMBER) ? rec->section_number : 0; + current_interface_id = wtap_file_get_shb_global_interface_id(in_file->wth, section_num, rec->rec_header.packet_header.interface_id); } if (current_interface_id >= in_file->idb_index_map->len) { /* this shouldn't happen, but in a malformed input file it could */ ws_debug("current_interface_id (%u) >= in_file->idb_index_map->len (%u) (ERROR?)", current_interface_id, in_file->idb_index_map->len); - return FALSE; + return false; } - rec->rec_header.packet_header.interface_id = g_array_index(in_file->idb_index_map, guint, current_interface_id); + rec->rec_header.packet_header.interface_id = g_array_index(in_file->idb_index_map, unsigned, current_interface_id); rec->presence_flags |= WTAP_HAS_INTERFACE_ID; - return TRUE; + return true; } +/** Return values from internal merge routines. */ +typedef enum { + MERGE_OK, + MERGE_USER_ABORTED, + /* below here are true errors */ + MERGE_ERR_CANT_OPEN_INFILE, + MERGE_ERR_CANT_OPEN_OUTFILE, + MERGE_ERR_CANT_READ_INFILE, + MERGE_ERR_BAD_PHDR_INTERFACE_ID, + MERGE_ERR_CANT_WRITE_OUTFILE, + MERGE_ERR_CANT_CLOSE_OUTFILE +} merge_result; + static merge_result merge_process_packets(wtap_dumper *pdh, const int file_type, - merge_in_file_t *in_files, const guint in_file_count, - const gboolean do_append, - const idb_merge_mode mode, guint snaplen, + merge_in_file_t *in_files, const unsigned in_file_count, + const bool do_append, + const idb_merge_mode mode, unsigned snaplen, merge_progress_callback_t* cb, wtapng_iface_descriptions_t *idb_inf, GArray *nrb_combined, GArray *dsb_combined, - int *err, gchar **err_info, guint *err_fileno, - guint32 *err_framenum) + int *err, char **err_info, unsigned *err_fileno, + uint32_t *err_framenum) { merge_result status = MERGE_OK; merge_in_file_t *in_file; int count = 0; - gboolean stop_flag = FALSE; + bool stop_flag = false; wtap_rec *rec, snap_rec; for (;;) { @@ -1040,8 +1055,24 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, if (*err != 0) { /* I/O error reading from in_file */ - status = MERGE_ERR_CANT_READ_INFILE; - break; + if (*err == WTAP_ERR_SHORT_READ) { + /* + * A truncated file is not a fatal error, just stop reading + * from that file, report it, and keep going. + * XXX - What about WTAP_ERR_BAD_FILE? Are there *any* + * read errors, as opposed to not being able to open the file + * or write a record, that make us want to abort the entire + * merge? + */ + report_cfile_read_failure(in_file->filename, *err, *err_info); + *err = 0; + g_free(*err_info); + *err_info = NULL; + continue; + } else { + status = MERGE_ERR_CANT_READ_INFILE; + break; + } } count++; @@ -1113,7 +1144,7 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, */ if (nrb_combined && in_file->wth->nrbs) { GArray *in_nrb = in_file->wth->nrbs; - for (guint i = in_file->nrbs_seen; i < in_nrb->len; i++) { + for (unsigned i = in_file->nrbs_seen; i < in_nrb->len; i++) { wtap_block_t wblock = g_array_index(in_nrb, wtap_block_t, i); g_array_append_val(nrb_combined, wblock); in_file->nrbs_seen++; @@ -1121,7 +1152,7 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, } if (dsb_combined && in_file->wth->dsbs) { GArray *in_dsb = in_file->wth->dsbs; - for (guint i = in_file->dsbs_seen; i < in_dsb->len; i++) { + for (unsigned i = in_file->dsbs_seen; i < in_dsb->len; i++) { wtap_block_t wblock = g_array_index(in_dsb, wtap_block_t, i); g_array_append_val(dsb_combined, wblock); in_file->dsbs_seen++; @@ -1148,11 +1179,11 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, } } if (nrb_combined) { - for (guint j = 0; j < in_file_count; j++) { + for (unsigned j = 0; j < in_file_count; j++) { in_file = &in_files[j]; GArray *in_nrb = in_file->wth->nrbs; if (in_nrb) { - for (guint i = in_file->nrbs_seen; i < in_nrb->len; i++) { + for (unsigned i = in_file->nrbs_seen; i < in_nrb->len; i++) { wtap_block_t wblock = g_array_index(in_nrb, wtap_block_t, i); g_array_append_val(nrb_combined, wblock); in_file->nrbs_seen++; @@ -1161,11 +1192,11 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, } } if (dsb_combined) { - for (guint j = 0; j < in_file_count; j++) { + for (unsigned j = 0; j < in_file_count; j++) { in_file = &in_files[j]; GArray *in_dsb = in_file->wth->dsbs; if (in_dsb) { - for (guint i = in_file->dsbs_seen; i < in_dsb->len; i++) { + for (unsigned i = in_file->dsbs_seen; i < in_dsb->len; i++) { wtap_block_t wblock = g_array_index(in_dsb, wtap_block_t, i); g_array_append_val(dsb_combined, wblock); in_file->dsbs_seen++; @@ -1185,7 +1216,7 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, * Don't overwrite the earlier error. */ int close_err = 0; - gchar *close_err_info = NULL; + char *close_err_info = NULL; (void)wtap_dump_close(pdh, NULL, &close_err, &close_err_info); g_free(close_err_info); } @@ -1200,7 +1231,7 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, *err_fileno = 0; *err_framenum = 0; } else { - *err_fileno = (guint)(in_file - in_files); + *err_fileno = (unsigned)(in_file - in_files); *err_framenum = in_file->packet_num; } @@ -1208,26 +1239,30 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, } static void -tempfile_free(gpointer data) { +tempfile_free(void *data) { char *filename = (char*)data; ws_unlink(filename); g_free(filename); } -static merge_result -merge_files_common(const gchar* out_filename, /* filename in normal output mode, +#define MAX_MERGE_FILES 10000 // Arbitrary +static bool +// NOLINTNEXTLINE(misc-no-recursion) +merge_files_common(const char* out_filename, /* filename in normal output mode, optional tempdir in tempfile mode (NULL for OS default) */ - gchar **out_filenamep, const char *pfx, /* tempfile mode */ + char **out_filenamep, const char *pfx, /* tempfile mode */ const int file_type, const char *const *in_filenames, - const guint in_file_count, const gboolean do_append, - idb_merge_mode mode, guint snaplen, - const gchar *app_name, merge_progress_callback_t* cb, - int *err, gchar **err_info, guint *err_fileno, - guint32 *err_framenum) + const unsigned in_file_count, const bool do_append, + idb_merge_mode mode, unsigned snaplen, + const char *app_name, merge_progress_callback_t* cb, wtap_compression_type compression_type) { merge_in_file_t *in_files = NULL; int frame_type = WTAP_ENCAP_PER_PACKET; unsigned open_file_count; + int err = 0; + char *err_info = NULL; + unsigned err_fileno = 0; + uint32_t err_framenum = 0; merge_result status = MERGE_OK; wtap_dumper *pdh; GArray *shb_hdrs = NULL; @@ -1238,14 +1273,11 @@ merge_files_common(const gchar* out_filename, /* filename in normal output mode, int dup_fd; ws_assert(in_file_count > 0); + ws_assert(in_file_count < MAX_MERGE_FILES); ws_assert(in_filenames != NULL); - ws_assert(err != NULL); - ws_assert(err_info != NULL); - ws_assert(err_fileno != NULL); - ws_assert(err_framenum != NULL); /* if a callback was given, it has to have a callback function ptr */ - ws_assert((cb != NULL) ? (cb->callback_func != NULL) : TRUE); + ws_assert((cb != NULL) ? (cb->callback_func != NULL) : true); ws_debug("merge_files: begin"); @@ -1258,15 +1290,16 @@ merge_files_common(const gchar* out_filename, /* filename in normal output mode, */ dup_fd = ws_dup(1); if (dup_fd == -1) { - return MERGE_ERR_CANT_OPEN_OUTFILE; + report_cfile_dump_open_failure(out_filename, errno, NULL, file_type); + return false; } /* open the input files */ - open_file_count = merge_open_in_files(in_file_count - total_file_count, &in_filenames[total_file_count], &in_files, cb, err, err_info, err_fileno); + open_file_count = merge_open_in_files(in_file_count - total_file_count, &in_filenames[total_file_count], &in_files, cb, &err, &err_info, &err_fileno); if (open_file_count == 0) { - ws_debug("merge_open_in_files() failed with err=%d", *err); - *err_framenum = 0; - return MERGE_ERR_CANT_OPEN_INFILE; + ws_debug("merge_open_in_files() failed with err=%d", err); + report_cfile_open_failure(in_filenames[err_fileno], err, err_info); + return false; } if (snaplen == 0) { @@ -1310,18 +1343,20 @@ merge_files_common(const gchar* out_filename, /* filename in normal output mode, idb_inf = generate_merged_idbs(in_files, open_file_count, &mode); ws_debug("IDB merge operation complete, got %u IDBs", idb_inf ? idb_inf->interface_data->len : 0); + /* We do our own mapping of interface numbers */ + params.shb_iface_to_global = NULL; /* XXX other blocks like ISB are now discarded. */ params.shb_hdrs = shb_hdrs; params.idb_inf = idb_inf; } if (wtap_file_type_subtype_supports_block(file_type, WTAP_BLOCK_NAME_RESOLUTION) != BLOCK_NOT_SUPPORTED) { - nrb_combined = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + nrb_combined = g_array_new(false, false, sizeof(wtap_block_t)); params.nrbs_growing = nrb_combined; } if (wtap_file_type_subtype_supports_block(file_type, WTAP_BLOCK_DECRYPTION_SECRETS) != BLOCK_NOT_SUPPORTED) { - dsb_combined = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + dsb_combined = g_array_new(false, false, sizeof(wtap_block_t)); params.dsbs_growing = dsb_combined; } ws_close(dup_fd); @@ -1336,21 +1371,21 @@ merge_files_common(const gchar* out_filename, /* filename in normal output mode, pdh = wtap_dump_open_tempfile(out_filenamep ? out_filename : NULL, &temp_filename, pfx ? pfx : "mergecap", file_type, - WTAP_UNCOMPRESSED, ¶ms, err, - err_info); + compression_type, ¶ms, &err, + &err_info); if (pdh) { g_ptr_array_add(temp_files, temp_filename); } } else if (out_filenamep) { pdh = wtap_dump_open_tempfile(out_filename, out_filenamep, pfx, file_type, - WTAP_UNCOMPRESSED, ¶ms, err, - err_info); + compression_type, ¶ms, &err, + &err_info); } else if (out_filename) { - pdh = wtap_dump_open(out_filename, file_type, WTAP_UNCOMPRESSED, - ¶ms, err, err_info); + pdh = wtap_dump_open(out_filename, file_type, compression_type, + ¶ms, &err, &err_info); } else { - pdh = wtap_dump_open_stdout(file_type, WTAP_UNCOMPRESSED, ¶ms, err, - err_info); + pdh = wtap_dump_open_stdout(file_type, compression_type, ¶ms, + &err, &err_info); } if (pdh == NULL) { merge_close_in_files(open_file_count, in_files); @@ -1358,16 +1393,16 @@ merge_files_common(const gchar* out_filename, /* filename in normal output mode, wtap_block_array_free(shb_hdrs); wtap_free_idb_info(idb_inf); if (nrb_combined) { - g_array_free(nrb_combined, TRUE); + g_array_free(nrb_combined, true); } if (dsb_combined) { - g_array_free(dsb_combined, TRUE); + g_array_free(dsb_combined, true); } if (temp_files) { - g_ptr_array_free(temp_files, TRUE); + g_ptr_array_free(temp_files, true); } - *err_framenum = 0; - return MERGE_ERR_CANT_OPEN_OUTFILE; + report_cfile_dump_open_failure(out_filename, err, err_info, file_type); + return false; } if (cb) @@ -1376,34 +1411,77 @@ merge_files_common(const gchar* out_filename, /* filename in normal output mode, status = merge_process_packets(pdh, file_type, in_files, open_file_count, do_append, mode, snaplen, cb, idb_inf, nrb_combined, dsb_combined, - err, err_info, - err_fileno, err_framenum); + &err, &err_info, + &err_fileno, &err_framenum); g_free(in_files); wtap_block_array_free(shb_hdrs); wtap_free_idb_info(idb_inf); if (nrb_combined) { - g_array_free(nrb_combined, TRUE); + g_array_free(nrb_combined, true); nrb_combined = NULL; } if (dsb_combined) { - g_array_free(dsb_combined, TRUE); + g_array_free(dsb_combined, true); dsb_combined = NULL; } } - if (temp_files != NULL) { - if (status == MERGE_OK) { - status = merge_files_common(out_filename, out_filenamep, pfx, - file_type, (const char**)temp_files->pdata, - temp_files->len, do_append, mode, snaplen, app_name, - cb, err, err_info, err_fileno, err_framenum); + if (status != MERGE_OK) { + /* + * Failed. Clean up and return false. + */ + switch (status) { + case MERGE_USER_ABORTED: + /* This isn't an error, so no need to report anything */ + break; + + case MERGE_ERR_CANT_OPEN_INFILE: + report_cfile_open_failure(in_filenames[err_fileno], err, err_info); + break; + + case MERGE_ERR_CANT_OPEN_OUTFILE: + report_cfile_dump_open_failure(out_filename, err, err_info, file_type); + break; + + case MERGE_ERR_CANT_READ_INFILE: + report_cfile_read_failure(in_filenames[err_fileno], err, err_info); + break; + + case MERGE_ERR_BAD_PHDR_INTERFACE_ID: + report_failure("Record %u of \"%s\" has an interface ID that does not match any IDB in its file.", + err_framenum, in_filenames[err_fileno]); + break; + + case MERGE_ERR_CANT_WRITE_OUTFILE: + report_cfile_write_failure(in_filenames[err_fileno], out_filename, + err, err_info, err_framenum, file_type); + break; + + case MERGE_ERR_CANT_CLOSE_OUTFILE: + report_cfile_close_failure(out_filename, err, err_info); + break; + + default: + report_failure("Unknown merge_files error %d", status); + break; } - g_ptr_array_free(temp_files, TRUE); + if (temp_files != NULL) + g_ptr_array_free(temp_files, true); + return false; } - return status; + if (temp_files != NULL) { + // We recurse here, but we're limited by MAX_MERGE_FILES + status = merge_files_common(out_filename, out_filenamep, pfx, + file_type, (const char**)temp_files->pdata, + temp_files->len, do_append, mode, snaplen, app_name, cb, compression_type); + /* If that failed, it has already reported an error */ + g_ptr_array_free(temp_files, true); + } + + return status == MERGE_OK; } /* @@ -1411,36 +1489,32 @@ merge_files_common(const gchar* out_filename, /* filename in normal output mode, * based on given input, and invokes callback during execution. Returns * MERGE_OK on success, or a MERGE_ERR_XXX on failure. */ -merge_result -merge_files(const gchar* out_filename, const int file_type, - const char *const *in_filenames, const guint in_file_count, - const gboolean do_append, const idb_merge_mode mode, - guint snaplen, const gchar *app_name, merge_progress_callback_t* cb, - int *err, gchar **err_info, guint *err_fileno, - guint32 *err_framenum) +bool +merge_files(const char* out_filename, const int file_type, + const char *const *in_filenames, const unsigned in_file_count, + const bool do_append, const idb_merge_mode mode, + unsigned snaplen, const char *app_name, merge_progress_callback_t* cb, const wtap_compression_type compression_type) { ws_assert(out_filename != NULL); ws_assert(in_file_count > 0); ws_assert(in_filenames != NULL); - ws_assert(err_info != NULL); /* #19402: ensure we aren't appending to one of our inputs */ if (do_append) { unsigned int i; for (i = 0; i < in_file_count; i++) { if (files_identical(out_filename, in_filenames[i])) { - *err_info = ws_strdup_printf("Output file %s is same as input file %s; " - "appending would create infinite loop", - out_filename, in_filenames[i]); - return MERGE_ERR_INVALID_OPTION; + report_failure("Output file %s is same as input file %s; " + "appending would create infinite loop", + out_filename, in_filenames[i]); + return false; } } } return merge_files_common(out_filename, NULL, NULL, file_type, in_filenames, in_file_count, - do_append, mode, snaplen, app_name, cb, err, - err_info, err_fileno, err_framenum); + do_append, mode, snaplen, app_name, cb, compression_type); } /* @@ -1448,14 +1522,12 @@ merge_files(const gchar* out_filename, const int file_type, * callback during execution. Returns MERGE_OK on success, or a MERGE_ERR_XXX * on failure. */ -merge_result -merge_files_to_tempfile(const char *tmpdir, gchar **out_filenamep, const char *pfx, +bool +merge_files_to_tempfile(const char *tmpdir, char **out_filenamep, const char *pfx, const int file_type, const char *const *in_filenames, - const guint in_file_count, const gboolean do_append, - const idb_merge_mode mode, guint snaplen, - const gchar *app_name, merge_progress_callback_t* cb, - int *err, gchar **err_info, guint *err_fileno, - guint32 *err_framenum) + const unsigned in_file_count, const bool do_append, + const idb_merge_mode mode, unsigned snaplen, + const char *app_name, merge_progress_callback_t* cb) { ws_assert(out_filenamep != NULL); @@ -1464,8 +1536,7 @@ merge_files_to_tempfile(const char *tmpdir, gchar **out_filenamep, const char *p return merge_files_common(tmpdir, out_filenamep, pfx, file_type, in_filenames, in_file_count, - do_append, mode, snaplen, app_name, cb, err, - err_info, err_fileno, err_framenum); + do_append, mode, snaplen, app_name, cb, WTAP_UNCOMPRESSED); } /* @@ -1473,18 +1544,16 @@ merge_files_to_tempfile(const char *tmpdir, gchar **out_filenamep, const char *p * callback during execution. Returns MERGE_OK on success, or a MERGE_ERR_XXX * on failure. */ -merge_result +bool merge_files_to_stdout(const int file_type, const char *const *in_filenames, - const guint in_file_count, const gboolean do_append, - const idb_merge_mode mode, guint snaplen, - const gchar *app_name, merge_progress_callback_t* cb, - int *err, gchar **err_info, guint *err_fileno, - guint32 *err_framenum) + const unsigned in_file_count, const bool do_append, + const idb_merge_mode mode, unsigned snaplen, + const char *app_name, merge_progress_callback_t* cb, + wtap_compression_type compression_type) { return merge_files_common(NULL, NULL, NULL, file_type, in_filenames, in_file_count, - do_append, mode, snaplen, app_name, cb, err, - err_info, err_fileno, err_framenum); + do_append, mode, snaplen, app_name, cb, compression_type); } /* diff --git a/wiretap/merge.h b/wiretap/merge.h index b069f3ff..dd5589ef 100644 --- a/wiretap/merge.h +++ b/wiretap/merge.h @@ -33,28 +33,13 @@ typedef struct merge_in_file_s { wtap_rec rec; Buffer frame_buffer; in_file_state_e state; - guint32 packet_num; /* current packet number */ - gint64 size; /* file size */ + uint32_t packet_num; /* current packet number */ + int64_t size; /* file size */ GArray *idb_index_map; /* used for mapping the old phdr interface_id values to new during merge */ - guint nrbs_seen; /* number of elements processed so far from wth->nrbs */ - guint dsbs_seen; /* number of elements processed so far from wth->dsbs */ + unsigned nrbs_seen; /* number of elements processed so far from wth->nrbs */ + unsigned dsbs_seen; /* number of elements processed so far from wth->dsbs */ } merge_in_file_t; -/** Return values from merge_files(). */ -typedef enum { - MERGE_OK, - MERGE_USER_ABORTED, - /* below here are true errors */ - MERGE_ERR_CANT_OPEN_INFILE, - MERGE_ERR_CANT_OPEN_OUTFILE, - MERGE_ERR_CANT_READ_INFILE, - MERGE_ERR_BAD_PHDR_INTERFACE_ID, - MERGE_ERR_CANT_WRITE_OUTFILE, - MERGE_ERR_CANT_CLOSE_OUTFILE, - MERGE_ERR_INVALID_OPTION -} merge_result; - - /** Merge events, used as an arg in the callback function - indicates when the callback was invoked. */ typedef enum { MERGE_EVENT_INPUT_FILES_OPENED, @@ -104,11 +89,11 @@ merge_idb_merge_mode_to_string(const int mode); * was invoked, the num is an int specific to the event, in_files is an array * of the created merge info, in_file_count is the size of the array, data is * whatever was passed in the data member of this struct. The callback_func - * routine's return value should be TRUE if merging should be aborted. + * routine's return value should be true if merging should be aborted. */ typedef struct { - gboolean (*callback_func)(merge_event event, int num, - const merge_in_file_t in_files[], const guint in_file_count, + bool (*callback_func)(merge_event event, int num, + const merge_in_file_t in_files[], const unsigned in_file_count, void *data); void *data; /**< private data to use for passing through to the callback function */ } merge_progress_callback_t; @@ -125,23 +110,15 @@ typedef struct { * @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files * @param app_name The application name performing the merge, used in SHB info * @param cb The callback information to use during execution - * @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed - * with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE, - * MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or - * MERGE_ERR_CANT_CLOSE_OUTFILE - * @param[out] err_info Additional information for some WTAP_ERR_XXX codes - * @param[out] err_fileno Set to the input file number which failed, if it - * failed - * @param[out] err_framenum Set to the input frame number if it failed - * @return the frame type + * @param compression_type The compresion type to use for the output + * @return true on success, false on failure */ -WS_DLL_PUBLIC merge_result -merge_files(const gchar* out_filename, const int file_type, - const char *const *in_filenames, const guint in_file_count, - const gboolean do_append, const idb_merge_mode mode, - guint snaplen, const gchar *app_name, merge_progress_callback_t* cb, - int *err, gchar **err_info, guint *err_fileno, - guint32 *err_framenum); +WS_DLL_PUBLIC bool +merge_files(const char* out_filename, const int file_type, + const char *const *in_filenames, const unsigned in_file_count, + const bool do_append, const idb_merge_mode mode, + unsigned snaplen, const char *app_name, merge_progress_callback_t* cb, + wtap_compression_type compression_type); /** Merge the given input files to a temporary file * @@ -157,24 +134,14 @@ merge_files(const gchar* out_filename, const int file_type, * @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files * @param app_name The application name performing the merge, used in SHB info * @param cb The callback information to use during execution - * @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed - * with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE, - * MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or - * MERGE_ERR_CANT_CLOSE_OUTFILE - * @param[out] err_info Additional information for some WTAP_ERR_XXX codes - * @param[out] err_fileno Set to the input file number which failed, if it - * failed - * @param[out] err_framenum Set to the input frame number if it failed - * @return the frame type + * @return true on success, false on failure */ -WS_DLL_PUBLIC merge_result -merge_files_to_tempfile(const char *tmpdir, gchar **out_filenamep, const char *pfx, +WS_DLL_PUBLIC bool +merge_files_to_tempfile(const char *tmpdir, char **out_filenamep, const char *pfx, const int file_type, const char *const *in_filenames, - const guint in_file_count, const gboolean do_append, - const idb_merge_mode mode, guint snaplen, - const gchar *app_name, merge_progress_callback_t* cb, - int *err, gchar **err_info, guint *err_fileno, - guint32 *err_framenum); + const unsigned in_file_count, const bool do_append, + const idb_merge_mode mode, unsigned snaplen, + const char *app_name, merge_progress_callback_t* cb); /** Merge the given input files to the standard output * @@ -186,23 +153,14 @@ merge_files_to_tempfile(const char *tmpdir, gchar **out_filenamep, const char *p * @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files * @param app_name The application name performing the merge, used in SHB info * @param cb The callback information to use during execution - * @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed - * with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE, - * MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or - * MERGE_ERR_CANT_CLOSE_OUTFILE - * @param[out] err_info Additional information for some WTAP_ERR_XXX codes - * @param[out] err_fileno Set to the input file number which failed, if it - * failed - * @param[out] err_framenum Set to the input frame number if it failed - * @return the frame type + * @return true on success, false on failure */ -WS_DLL_PUBLIC merge_result +WS_DLL_PUBLIC bool merge_files_to_stdout(const int file_type, const char *const *in_filenames, - const guint in_file_count, const gboolean do_append, - const idb_merge_mode mode, guint snaplen, - const gchar *app_name, merge_progress_callback_t* cb, - int *err, gchar **err_info, guint *err_fileno, - guint32 *err_framenum); + const unsigned in_file_count, const bool do_append, + const idb_merge_mode mode, unsigned snaplen, + const char *app_name, merge_progress_callback_t* cb, + wtap_compression_type compression_type); #ifdef __cplusplus } diff --git a/wiretap/mime_file.c b/wiretap/mime_file.c index a3cce0d1..c9aca57a 100644 --- a/wiretap/mime_file.c +++ b/wiretap/mime_file.c @@ -17,6 +17,7 @@ */ #include "config.h" +#include "mime_file.h" #include <sys/types.h> @@ -31,11 +32,10 @@ #include "wtap-int.h" #include "file_wrappers.h" #include <wsutil/buffer.h> -#include "mime_file.h" typedef struct { - const guint8 *magic; - guint magic_len; + const uint8_t *magic; + unsigned magic_len; } mime_files_t; /* @@ -51,31 +51,31 @@ typedef struct { * https://www.itu.int/rec/T-REC-T.871-201105-I/en * https://www.w3.org/Graphics/JPEG/jfif3.pdf */ -static const guint8 jpeg_jfif_magic[] = { 0xFF, 0xD8, /* SOF */ +static const uint8_t jpeg_jfif_magic[] = { 0xFF, 0xD8, /* SOF */ 0xFF /* start of the next marker */ }; /* <?xml */ -static const guint8 xml_magic[] = { '<', '?', 'x', 'm', 'l' }; -static const guint8 png_magic[] = { 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n' }; -static const guint8 gif87a_magic[] = { 'G', 'I', 'F', '8', '7', 'a'}; -static const guint8 gif89a_magic[] = { 'G', 'I', 'F', '8', '9', 'a'}; -static const guint8 elf_magic[] = { 0x7F, 'E', 'L', 'F'}; -static const guint8 tiff_le_magic[] = { 'I', 'I', 42, 0 }; -static const guint8 tiff_be_magic[] = { 'M', 'M', 0, 42 }; -static const guint8 btsnoop_magic[] = { 'b', 't', 's', 'n', 'o', 'o', 'p', 0}; -static const guint8 pcap_magic[] = { 0xA1, 0xB2, 0xC3, 0xD4 }; -static const guint8 pcap_swapped_magic[] = { 0xD4, 0xC3, 0xB2, 0xA1 }; -static const guint8 pcap_nsec_magic[] = { 0xA1, 0xB2, 0x3C, 0x4D }; -static const guint8 pcap_nsec_swapped_magic[] = { 0x4D, 0x3C, 0xB2, 0xA1 }; -static const guint8 pcapng_premagic[] = { 0x0A, 0x0D, 0x0D, 0x0A }; -static const guint8 blf_magic[] = { 'L', 'O', 'G', 'G' }; -static const guint8 autosar_dlt_magic[] = { 'D', 'L', 'T', 0x01 }; -static const guint8 rtpdump_magic[] = { '#', '!', 'r', 't', 'p', 'p', 'l', 'a', 'y', '1', '.', '0', ' ' }; +static const uint8_t xml_magic[] = { '<', '?', 'x', 'm', 'l' }; +static const uint8_t png_magic[] = { 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n' }; +static const uint8_t gif87a_magic[] = { 'G', 'I', 'F', '8', '7', 'a'}; +static const uint8_t gif89a_magic[] = { 'G', 'I', 'F', '8', '9', 'a'}; +static const uint8_t elf_magic[] = { 0x7F, 'E', 'L', 'F'}; +static const uint8_t tiff_le_magic[] = { 'I', 'I', 42, 0 }; +static const uint8_t tiff_be_magic[] = { 'M', 'M', 0, 42 }; +static const uint8_t btsnoop_magic[] = { 'b', 't', 's', 'n', 'o', 'o', 'p', 0}; +static const uint8_t pcap_magic[] = { 0xA1, 0xB2, 0xC3, 0xD4 }; +static const uint8_t pcap_swapped_magic[] = { 0xD4, 0xC3, 0xB2, 0xA1 }; +static const uint8_t pcap_nsec_magic[] = { 0xA1, 0xB2, 0x3C, 0x4D }; +static const uint8_t pcap_nsec_swapped_magic[] = { 0x4D, 0x3C, 0xB2, 0xA1 }; +static const uint8_t pcapng_premagic[] = { 0x0A, 0x0D, 0x0D, 0x0A }; +static const uint8_t blf_magic[] = { 'L', 'O', 'G', 'G' }; +static const uint8_t autosar_dlt_magic[] = { 'D', 'L', 'T', 0x01 }; +static const uint8_t rtpdump_magic[] = { '#', '!', 'r', 't', 'p', 'p', 'l', 'a', 'y', '1', '.', '0', ' ' }; /* File does not start with it */ -static const guint8 pcapng_xmagic[] = { 0x1A, 0x2B, 0x3C, 0x4D }; -static const guint8 pcapng_swapped_xmagic[] = { 0x4D, 0x3C, 0x2B, 0x1A }; +static const uint8_t pcapng_xmagic[] = { 0x1A, 0x2B, 0x3C, 0x4D }; +static const uint8_t pcapng_swapped_xmagic[] = { 0x4D, 0x3C, 0x2B, 0x1A }; static const mime_files_t magic_files[] = { { jpeg_jfif_magic, sizeof(jpeg_jfif_magic) }, @@ -97,27 +97,27 @@ static const mime_files_t magic_files[] = { { rtpdump_magic, sizeof(rtpdump_magic) }, }; -#define N_MAGIC_TYPES (sizeof(magic_files) / sizeof(magic_files[0])) +#define N_MAGIC_TYPES array_length(magic_files) static int mime_file_type_subtype = -1; void register_mime(void); wtap_open_return_val -mime_file_open(wtap *wth, int *err, gchar **err_info) +mime_file_open(wtap *wth, int *err, char **err_info) { char magic_buf[128]; /* increase buffer size when needed */ int bytes_read; - gboolean found_file; - /* guint file_ok; */ - guint i; + bool found_file; + /* unsigned file_ok; */ + unsigned i; - guint read_bytes = 12; + unsigned read_bytes = 12; for (i = 0; i < N_MAGIC_TYPES; i++) read_bytes = MAX(read_bytes, magic_files[i].magic_len); - read_bytes = (guint)MIN(read_bytes, sizeof(magic_buf)); + read_bytes = (unsigned)MIN(read_bytes, sizeof(magic_buf)); bytes_read = file_read(magic_buf, read_bytes, wth->fh); if (bytes_read < 0) { @@ -127,16 +127,16 @@ mime_file_open(wtap *wth, int *err, gchar **err_info) if (bytes_read == 0) return WTAP_OPEN_NOT_MINE; - found_file = FALSE; + found_file = false; for (i = 0; i < N_MAGIC_TYPES; i++) { - if ((guint) bytes_read >= magic_files[i].magic_len && !memcmp(magic_buf, magic_files[i].magic, MIN(magic_files[i].magic_len, (guint) bytes_read))) { + if ((unsigned) bytes_read >= magic_files[i].magic_len && !memcmp(magic_buf, magic_files[i].magic, MIN(magic_files[i].magic_len, (unsigned) bytes_read))) { if (!found_file) { if (magic_files[i].magic == pcapng_premagic) { if (memcmp(magic_buf + 8, pcapng_xmagic, sizeof(pcapng_xmagic)) && memcmp(magic_buf + 8, pcapng_swapped_xmagic, sizeof(pcapng_swapped_xmagic))) continue; } - found_file = TRUE; + found_file = true; } else return WTAP_OPEN_NOT_MINE; /* many files matched, bad file */ } @@ -169,7 +169,7 @@ static const struct supported_block_type mime_blocks_supported[] = { static const struct file_type_subtype_info mime_info = { "MIME File Format", "mime", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(mime_blocks_supported), + false, BLOCKS_SUPPORTED(mime_blocks_supported), NULL, NULL, NULL }; @@ -189,7 +189,7 @@ static const struct supported_block_type jpeg_jfif_blocks_supported[] = { static const struct file_type_subtype_info jpeg_jfif_info = { "JPEG/JFIF", "jpeg", "jpg", "jpeg;jfif", - FALSE, BLOCKS_SUPPORTED(jpeg_jfif_blocks_supported), + false, BLOCKS_SUPPORTED(jpeg_jfif_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/mime_file.h b/wiretap/mime_file.h index dd6820fb..392ea47d 100644 --- a/wiretap/mime_file.h +++ b/wiretap/mime_file.h @@ -12,6 +12,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val mime_file_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val mime_file_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c index a0f3f611..14189970 100644 --- a/wiretap/mp2t.c +++ b/wiretap/mp2t.c @@ -9,6 +9,7 @@ */ #include "config.h" +#include "mp2t.h" #include <sys/types.h> @@ -16,8 +17,6 @@ #include <unistd.h> #endif -#include "mp2t.h" - #include "wtap-int.h" #include <wsutil/buffer.h> #include "file_wrappers.h" @@ -39,22 +38,25 @@ typedef struct { - guint32 start_offset; - guint64 bitrate; + uint64_t bitrate; + uint32_t start_offset; + /* length of header data (e.g., TP_extra_header in BDAV m2ts files) before + * each packet) */ + uint8_t header_len; /* length of trailing data (e.g. FEC) that's appended after each packet */ - guint8 trailer_len; + uint8_t trailer_len; } mp2t_filetype_t; static int mp2t_file_type_subtype = -1; void register_mp2t(void); -static gboolean -mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset, +static bool +mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, int64_t offset, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info) + char **err_info) { - guint64 tmp; + uint64_t tmp; /* * MP2T_SIZE will always be less than WTAP_MAX_PACKET_SIZE_STANDARD, so @@ -62,7 +64,7 @@ mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset, */ ws_buffer_assure_space(buf, MP2T_SIZE); if (!wtap_read_bytes_or_eof(fh, ws_buffer_start_ptr(buf), MP2T_SIZE, err, err_info)) - return FALSE; + return false; rec->rec_type = REC_TYPE_PACKET; rec->block = wtap_block_create(WTAP_BLOCK_PACKET); @@ -84,49 +86,61 @@ mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset, * case our attempt to guess it from the PCRs of one of the programs * doesn't get the right answer. */ - tmp = ((guint64)(offset - mp2t->start_offset) * 8); /* offset, in bits */ + tmp = ((uint64_t)(offset - mp2t->start_offset) * 8); /* offset, in bits */ rec->ts.secs = (time_t)(tmp / mp2t->bitrate); rec->ts.nsecs = (int)((tmp % mp2t->bitrate) * 1000000000 / mp2t->bitrate); rec->rec_header.packet_header.caplen = MP2T_SIZE; rec->rec_header.packet_header.len = MP2T_SIZE; - return TRUE; + return true; } -static gboolean +static bool mp2t_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { mp2t_filetype_t *mp2t; mp2t = (mp2t_filetype_t*) wth->priv; + /* if there's a header, skip it and go to the start of the packet */ + /* XXX - Eventually we might want to process the header (and trailer?) in + * packet-mp2t.c, in which case we would read it in mp2t_read_packet and + * include header_len in the packet_header lengths. We'd probably want + * pseudo-header information to indicate it to packet-mp2t.c + */ + if (mp2t->header_len!=0) { + if (!wtap_read_bytes_or_eof(wth->fh, NULL, mp2t->header_len, err, err_info)) { + return false; + } + } + *data_offset = file_tell(wth->fh); if (!mp2t_read_packet(mp2t, wth->fh, *data_offset, rec, buf, err, err_info)) { - return FALSE; + return false; } /* if there's a trailer, skip it and go to the start of the next packet */ if (mp2t->trailer_len!=0) { if (!wtap_read_bytes(wth->fh, NULL, mp2t->trailer_len, err, err_info)) { - return FALSE; + return false; } } - return TRUE; + return true; } -static gboolean -mp2t_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +mp2t_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { mp2t_filetype_t *mp2t; if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err)) { - return FALSE; + return false; } mp2t = (mp2t_filetype_t*) wth->priv; @@ -135,16 +149,16 @@ mp2t_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -static guint64 -mp2t_read_pcr(guint8 *buffer) +static uint64_t +mp2t_read_pcr(uint8_t *buffer) { - guint64 base; - guint64 ext; + uint64_t base; + uint64_t ext; base = pntoh40(buffer); base >>= 7; @@ -155,22 +169,22 @@ mp2t_read_pcr(guint8 *buffer) return (base * 300 + ext); } -static gboolean -mp2t_find_next_pcr(wtap *wth, guint8 trailer_len, - int *err, gchar **err_info, guint32 *idx, guint64 *pcr, guint16 *pid) +static bool +mp2t_find_next_pcr(wtap *wth, uint8_t trailer_len, + int *err, char **err_info, uint32_t *idx, uint64_t *pcr, uint16_t *pid) { - guint8 buffer[MP2T_SIZE+TRAILER_LEN_MAX]; - gboolean found; - guint8 afc; - guint timeout = 0; + uint8_t buffer[MP2T_SIZE+TRAILER_LEN_MAX]; + bool found; + uint8_t afc; + unsigned timeout = 0; - found = FALSE; - while (FALSE == found && timeout++ < SYNC_STEPS * SYNC_STEPS) { + found = false; + while (false == found && timeout++ < SYNC_STEPS * SYNC_STEPS) { (*idx)++; if (!wtap_read_bytes_or_eof( wth->fh, buffer, MP2T_SIZE+trailer_len, err, err_info)) { /* Read error, short read, or EOF */ - return FALSE; + return false; } if (MP2T_SYNC_BYTE != buffer[0]) { @@ -196,21 +210,21 @@ mp2t_find_next_pcr(wtap *wth, guint8 trailer_len, /* We have a PCR value! */ *pcr = mp2t_read_pcr(&buffer[6]); *pid = 0x01ff & pntoh16(&buffer[1]); - found = TRUE; + found = true; } return found; } static wtap_open_return_val -mp2t_bits_per_second(wtap *wth, guint32 first, guint8 trailer_len, - guint64 *bitrate, int *err, gchar **err_info) +mp2t_bits_per_second(wtap *wth, uint32_t first, uint8_t trailer_len, + uint64_t *bitrate, int *err, char **err_info) { - guint32 pn1, pn2; - guint64 pcr1, pcr2; - guint16 pid1, pid2; - guint32 idx; - guint64 pcr_delta, bits_passed; + uint32_t pn1, pn2; + uint64_t pcr1, pcr2; + uint16_t pid1, pid2; + uint32_t idx; + uint64_t pcr_delta, bits_passed; /* Find the first PCR + PID. * Then find another PCR in that PID. @@ -267,10 +281,10 @@ mp2t_bits_per_second(wtap *wth, guint32 first, guint8 trailer_len, return WTAP_OPEN_NOT_MINE; } pcr_delta = pcr2 - pcr1; - /* cast one of the factors to guint64 - otherwise, the multiplication would use guint32 and could - overflow before the result is assigned to the guint64 bits_passed */ - bits_passed = (guint64)MP2T_SIZE * (pn2 - pn1) * 8; + /* cast one of the factors to uint64_t + otherwise, the multiplication would use uint32_t and could + overflow before the result is assigned to the uint64_t bits_passed */ + bits_passed = (uint64_t)MP2T_SIZE * (pn2 - pn1) * 8; *bitrate = ((MP2T_PCR_CLOCK * bits_passed) / pcr_delta); if (*bitrate == 0) { @@ -292,16 +306,17 @@ mp2t_bits_per_second(wtap *wth, guint32 first, guint8 trailer_len, } wtap_open_return_val -mp2t_open(wtap *wth, int *err, gchar **err_info) +mp2t_open(wtap *wth, int *err, char **err_info) { - guint8 buffer[MP2T_SIZE+TRAILER_LEN_MAX]; - guint8 trailer_len = 0; - guint sync_steps = 0; - guint i; - guint32 first = 0; + uint8_t buffer[MP2T_SIZE+TRAILER_LEN_MAX]; + uint8_t trailer_len = 0; + uint8_t header_len = 0; + unsigned sync_steps = 0; + unsigned i; + uint32_t first = 0; mp2t_filetype_t *mp2t; wtap_open_return_val status; - guint64 bitrate; + uint64_t bitrate; if (!wtap_read_bytes(wth->fh, buffer, MP2T_SIZE, err, err_info)) { @@ -328,39 +343,61 @@ found: /* read some packets and make sure they all start with a sync byte */ do { - if (!wtap_read_bytes(wth->fh, buffer, MP2T_SIZE+trailer_len, err, err_info)) { - if (*err != WTAP_ERR_SHORT_READ) - return WTAP_OPEN_ERROR; /* read error */ - if(sync_steps<2) return WTAP_OPEN_NOT_MINE; /* wrong file type - not an mpeg2 ts file */ - break; /* end of file, that's ok if we're still in sync */ - } - if (buffer[0] == MP2T_SYNC_BYTE) { - sync_steps++; - } - else { - /* no sync byte found, check if trailing data is appended - and we have to increase the packet size */ - - /* if we've already detected a trailer field, we must remain in sync - another mismatch means we have no mpeg2 ts file */ - if (trailer_len>0) - return WTAP_OPEN_NOT_MINE; - - /* check if a trailer is appended to the packet */ - for (i=0; i<TRAILER_LEN_MAX; i++) { - if (buffer[i] == MP2T_SYNC_BYTE) { - trailer_len = i; - if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) { - return WTAP_OPEN_ERROR; - } - sync_steps = 0; - break; - } - } - /* no sync byte found in the vicinity, this is no mpeg2 ts file */ - if (i==TRAILER_LEN_MAX) - return WTAP_OPEN_NOT_MINE; - } + if (!wtap_read_bytes(wth->fh, buffer, MP2T_SIZE+trailer_len, err, err_info)) { + if (*err != WTAP_ERR_SHORT_READ) + return WTAP_OPEN_ERROR; /* read error */ + if(sync_steps<2) return WTAP_OPEN_NOT_MINE; /* wrong file type - not an mpeg2 ts file */ + break; /* end of file, that's ok if we're still in sync */ + } + if (buffer[0] == MP2T_SYNC_BYTE) { + sync_steps++; + } + else { + /* no sync byte found, check if trailing data is appended + and we have to increase the packet size */ + + /* if we've already detected a trailer field, we must remain in sync + another mismatch means we have no mpeg2 ts file */ + if (trailer_len>0) { + /* check for header with spurious sync byte in header */ + if (first < trailer_len) { + first += 1; + trailer_len -= 1; + if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) { + return WTAP_OPEN_ERROR; + } + /* Shouldn't fail, we just read this */ + if (!wtap_read_bytes(wth->fh, buffer, MP2T_SIZE, err, err_info)) { + if (*err != WTAP_ERR_SHORT_READ) + return WTAP_OPEN_ERROR; + return WTAP_OPEN_NOT_MINE; + } + for (i = 0; i < trailer_len; i++) { + if (MP2T_SYNC_BYTE == buffer[i]) { + first += i; + trailer_len -= i; + goto found; + } + } + } + return WTAP_OPEN_NOT_MINE; + } + + /* check if a trailer is appended to the packet */ + for (i=0; i<TRAILER_LEN_MAX; i++) { + if (buffer[i] == MP2T_SYNC_BYTE) { + trailer_len = i; + if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) { + return WTAP_OPEN_ERROR; + } + sync_steps = 0; + break; + } + } + /* no sync byte found in the vicinity, this is no mpeg2 ts file */ + if (i==TRAILER_LEN_MAX) + return WTAP_OPEN_NOT_MINE; + } } while (sync_steps < SYNC_STEPS); if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) { @@ -374,6 +411,12 @@ found: return status; } + /* If the packet didn't start on a sync byte, the "trailer" might + * be a header. At least BDAV M2TS does this with a four byte header. */ + header_len = MIN(first, trailer_len); + first -= header_len; + trailer_len -= header_len; + if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) { return WTAP_OPEN_ERROR; } @@ -390,11 +433,69 @@ found: wth->priv = mp2t; mp2t->start_offset = first; mp2t->trailer_len = trailer_len; + mp2t->header_len = header_len; mp2t->bitrate = bitrate; return WTAP_OPEN_MINE; } +static int mp2t_dump_can_write_encap(int encap) +{ + /* Per-packet encapsulations aren't supported. */ + if (encap == WTAP_ENCAP_PER_PACKET) { + return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; + } + + /* This is the only encapsulation type we write. */ + if (encap != WTAP_ENCAP_MPEG_2_TS) { + return WTAP_ERR_UNWRITABLE_ENCAP; + } + + return 0; +} + +/* Write a record for a packet to a dump file. + Returns true on success, false on failure. */ +static bool mp2t_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info _U_) +{ + /* We can only write packet records. */ + if (rec->rec_type != REC_TYPE_PACKET) { + *err = WTAP_ERR_UNWRITABLE_REC_TYPE; + return false; + } + + /* + * Make sure this packet doesn't have a link-layer type that + * differs from the one for the file. + */ + if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { + *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; + return false; + } + + /* A MPEG-2 Transport Stream is just the packet bytes, with no header. + * The sync byte is supposed to identify where packets start. + * Note this drops existing headers and trailers currently, since we + * don't include them in the record. + */ + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) { + return false; + } + + return true; +} + +/* Returns true on success, false on failure; sets "*err" to an error code on + failure */ +static bool mp2t_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_) +{ + /* There is no header, so we just always return true. */ + wdh->subtype_write = mp2t_dump; + + return true; +} + static const struct supported_block_type mp2t_blocks_supported[] = { /* * We support packet blocks, with no comments or other options. @@ -403,9 +504,9 @@ static const struct supported_block_type mp2t_blocks_supported[] = { }; static const struct file_type_subtype_info mp2t_info = { - "MPEG2 transport stream", "mp2t", "mp2t", "ts;mpg", - FALSE, BLOCKS_SUPPORTED(mp2t_blocks_supported), - NULL, NULL, NULL + "MPEG2 transport stream", "mp2t", "mp2t", "ts;m2ts;mpg", + false, BLOCKS_SUPPORTED(mp2t_blocks_supported), + mp2t_dump_can_write_encap, mp2t_dump_open, NULL }; void register_mp2t(void) diff --git a/wiretap/mp2t.h b/wiretap/mp2t.h index 76bd7f49..0ccec8f4 100644 --- a/wiretap/mp2t.h +++ b/wiretap/mp2t.h @@ -14,6 +14,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val mp2t_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val mp2t_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/mp4.c b/wiretap/mp4.c index 36a43a71..40b08cf1 100644 --- a/wiretap/mp4.c +++ b/wiretap/mp4.c @@ -14,16 +14,16 @@ #include "file_wrappers.h" #include "wtap-int.h" -static const guint8 mp4_magic[] = { 'f', 't', 'y', 'p' }; -static const guint8 mp4_magic_sidx[] = { 's', 'i', 'd', 'x' }; -static const guint8 mp4_magic_styp[] = { 's', 't', 'y', 'p' }; +static const uint8_t mp4_magic[] = { 'f', 't', 'y', 'p' }; +static const uint8_t mp4_magic_sidx[] = { 's', 'i', 'd', 'x' }; +static const uint8_t mp4_magic_styp[] = { 's', 't', 'y', 'p' }; static int mp4_file_type_subtype = -1; void register_mp4(void); wtap_open_return_val -mp4_open(wtap *wth, int *err, gchar **err_info) +mp4_open(wtap *wth, int *err, char **err_info) { char magic_buf[8]; int bytes_read; @@ -67,7 +67,7 @@ static const struct supported_block_type mp4_blocks_supported[] = { static const struct file_type_subtype_info mp4_info = { "MP4 media", "mp4", "mp4", NULL, - FALSE, BLOCKS_SUPPORTED(mp4_blocks_supported), + false, BLOCKS_SUPPORTED(mp4_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/mp4.h b/wiretap/mp4.h index 5dbcd96f..e03f115b 100644 --- a/wiretap/mp4.h +++ b/wiretap/mp4.h @@ -11,6 +11,6 @@ #include "wtap.h" -wtap_open_return_val mp4_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val mp4_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c index c4219926..6eb9bfdf 100644 --- a/wiretap/mpeg.c +++ b/wiretap/mpeg.c @@ -18,6 +18,7 @@ */ #include "config.h" +#include "mpeg.h" #include <sys/types.h> @@ -25,7 +26,6 @@ #include <unistd.h> #endif -#include "mpeg.h" #include "wsutil/mpeg-audio.h" #include "wtap-int.h" @@ -41,7 +41,7 @@ typedef struct { nstime_t now; time_t t0; - gboolean is_audio; + bool is_audio; } mpeg_t; static int mpeg_file_type_subtype = -1; @@ -51,7 +51,7 @@ void register_mpeg(void); static int mpeg_resync(FILE_T fh, int *err) { - gint64 offset = file_tell(fh); + int64_t offset = file_tell(fh); int count = 0; int byte = file_getc(fh); @@ -72,14 +72,14 @@ mpeg_resync(FILE_T fh, int *err) #define SCRHZ 27000000 static unsigned int -mpeg_read_audio_packet(wtap *wth, FILE_T fh, gboolean is_random, int *err, gchar **err_info) +mpeg_read_audio_packet(wtap *wth, FILE_T fh, bool is_random, int *err, char **err_info) { mpeg_t *mpeg = (mpeg_t *)wth->priv; unsigned int packet_size; - guint32 n; + uint32_t n; if (!wtap_read_bytes_or_eof(fh, &n, sizeof n, err, err_info)) return 0; - if (file_seek(fh, -(gint64)(sizeof n), SEEK_CUR, err) == -1) + if (file_seek(fh, -(int64_t)(sizeof n), SEEK_CUR, err) == -1) return 0; n = g_ntohl(n); struct mpa mpa; @@ -101,7 +101,7 @@ mpeg_read_audio_packet(wtap *wth, FILE_T fh, gboolean is_random, int *err, gchar return 0; if (!wtap_read_bytes_or_eof(fh, &n, sizeof n, err, err_info)) return 0; - if (file_seek(fh, -(gint64)(6+sizeof(n)), SEEK_CUR, err) == -1) + if (file_seek(fh, -(int64_t)(6+sizeof(n)), SEEK_CUR, err) == -1) return 0; n = g_ntohl(n); @@ -115,15 +115,15 @@ mpeg_read_audio_packet(wtap *wth, FILE_T fh, gboolean is_random, int *err, gchar } static unsigned int -mpeg_read_pes_packet(wtap *wth, FILE_T fh, gboolean is_random, int *err, gchar **err_info) +mpeg_read_pes_packet(wtap *wth, FILE_T fh, bool is_random, int *err, char **err_info) { mpeg_t *mpeg = (mpeg_t *)wth->priv; unsigned int packet_size = 0; - guint32 n; + uint32_t n; while (1) { if (!wtap_read_bytes_or_eof(fh, &n, sizeof n, err, err_info)) return 0; - if (file_seek(fh, -(gint64)(sizeof n), SEEK_CUR, err) == -1) + if (file_seek(fh, -(int64_t)(sizeof n), SEEK_CUR, err) == -1) return 0; n = g_ntohl(n); if (PES_VALID(n)) { @@ -144,8 +144,8 @@ mpeg_read_pes_packet(wtap *wth, FILE_T fh, gboolean is_random, int *err, gchar * return 0; } - gint64 offset = file_tell(fh); - guint8 stream; + int64_t offset = file_tell(fh); + uint8_t stream; if (!wtap_read_bytes(fh, NULL, 3, err, err_info)) return 0; @@ -154,41 +154,41 @@ mpeg_read_pes_packet(wtap *wth, FILE_T fh, gboolean is_random, int *err, gchar * return 0; if (stream == 0xba) { - guint32 pack1; - guint32 pack0; - guint64 pack; - guint8 stuffing; + uint32_t pack1; + uint32_t pack0; + uint64_t pack; + uint8_t stuffing; if (!wtap_read_bytes(fh, &pack1, sizeof pack1, err, err_info)) return 0; if (!wtap_read_bytes(fh, &pack0, sizeof pack0, err, err_info)) return 0; - pack = (guint64)g_ntohl(pack1) << 32 | g_ntohl(pack0); + pack = (uint64_t)g_ntohl(pack1) << 32 | g_ntohl(pack0); switch (pack >> 62) { case 1: if (!wtap_read_bytes(fh, NULL, 1, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &stuffing, sizeof stuffing, err, err_info)) - return FALSE; + return false; stuffing &= 0x07; packet_size = 14 + stuffing; if (!is_random) { - guint64 bytes = pack >> 16; - guint64 ts_val = + uint64_t bytes = pack >> 16; + uint64_t ts_val = (bytes >> 43 & 0x0007) << 30 | (bytes >> 27 & 0x7fff) << 15 | (bytes >> 11 & 0x7fff) << 0; - guint ext = (guint)((bytes >> 1) & 0x1ff); - guint64 cr = 300 * ts_val + ext; - guint rem = (guint)(cr % SCRHZ); + unsigned ext = (unsigned)((bytes >> 1) & 0x1ff); + uint64_t cr = 300 * ts_val + ext; + unsigned rem = (unsigned)(cr % SCRHZ); mpeg->now.secs = mpeg->t0 + (time_t)(cr / SCRHZ); mpeg->now.nsecs - = (int)(G_GINT64_CONSTANT(1000000000) * rem / SCRHZ); + = (int)(INT64_C(1000000000) * rem / SCRHZ); } break; default: @@ -198,9 +198,9 @@ mpeg_read_pes_packet(wtap *wth, FILE_T fh, gboolean is_random, int *err, gchar * /* MPEG_program_end_code */ packet_size = 4; } else { - guint16 length; + uint16_t length; if (!wtap_read_bytes(fh, &length, sizeof length, err, err_info)) - return FALSE; + return false; length = g_ntohs(length); packet_size = 6 + length; } @@ -211,9 +211,9 @@ mpeg_read_pes_packet(wtap *wth, FILE_T fh, gboolean is_random, int *err, gchar * return packet_size; } -static gboolean +static bool mpeg_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, - gboolean is_random, int *err, gchar **err_info) + bool is_random, int *err, char **err_info) { mpeg_t *mpeg = (mpeg_t *)wth->priv; unsigned int packet_size; @@ -233,10 +233,10 @@ mpeg_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, } if (packet_size == 0) - return FALSE; + return false; if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) - return FALSE; + return false; rec->rec_type = REC_TYPE_PACKET; rec->block = wtap_block_create(WTAP_BLOCK_PACKET); @@ -250,47 +250,47 @@ mpeg_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, rec->rec_header.packet_header.caplen = packet_size; rec->rec_header.packet_header.len = packet_size; - return TRUE; + return true; } -static gboolean +static bool mpeg_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); - return mpeg_read_packet(wth, wth->fh, rec, buf, FALSE, err, err_info); + return mpeg_read_packet(wth, wth->fh, rec, buf, false, err, err_info); } -static gboolean -mpeg_seek_read(wtap *wth, gint64 seek_off, +static bool +mpeg_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, SEEK_SET, err) == -1) - return FALSE; + return false; - if (!mpeg_read_packet(wth, wth->random_fh, rec, buf, TRUE, err, + if (!mpeg_read_packet(wth, wth->random_fh, rec, buf, true, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } struct _mpeg_magic { size_t len; - const gchar* match; - gboolean is_audio; + const char* match; + bool is_audio; } magic[] = { - { 3, "TAG", TRUE }, /* ID3v1 */ + { 3, "TAG", true }, /* ID3v1 */ /* XXX: ID3v1 tags come at the end of MP3 files, so in practice the * untagged magic number is used instead. */ - { 3, "ID3", TRUE }, /* ID3v2 */ - { 3, "\0\0\1", FALSE }, /* MPEG PES */ - { 2, "\xff\xfb", TRUE }, /* MP3 (MPEG-1 Audio Layer 3, no CRC), taken from https://en.wikipedia.org/wiki/MP3#File_structure */ + { 3, "ID3", true }, /* ID3v2 */ + { 3, "\0\0\1", false }, /* MPEG PES */ + { 2, "\xff\xfb", true }, /* MP3 (MPEG-1 Audio Layer 3, no CRC), taken from https://en.wikipedia.org/wiki/MP3#File_structure */ #if 0 /* XXX: The value above is for MPEG-1 Audio Layer 3 with no CRC. * Only the first three nibbles are the guaranteed sync byte. @@ -303,19 +303,19 @@ struct _mpeg_magic { * The mpeg-audio dissector handles these, so wiretap should open * them. Including all of them might increase false positives though. */ - { 2, "\xff\xf2", TRUE }, /* MPEG-2 Audio Layer 3, CRC */ - { 2, "\xff\xf3", TRUE }, /* MPEG-2 Audio Layer 3, No CRC */ - { 2, "\xff\xf4", TRUE }, /* MPEG-2 Audio Layer 2, CRC */ - { 2, "\xff\xf5", TRUE }, /* MPEG-2 Audio Layer 2, No CRC */ - { 2, "\xff\xf6", TRUE }, /* MPEG-2 Audio Layer 1, CRC */ - { 2, "\xff\xf7", TRUE }, /* MPEG-2 Audio Layer 1, No CRC */ - { 2, "\xff\xfa", TRUE }, /* MPEG-1 Audio Layer 3, CRC */ - { 2, "\xff\xfc", TRUE }, /* MPEG-1 Audio Layer 2, CRC */ - { 2, "\xff\xfd", TRUE }, /* MPEG-1 Audio Layer 2, No CRC */ - { 2, "\xff\xfe", TRUE }, /* MPEG-1 Audio Layer 1, CRC */ - { 2, "\xff\xff", TRUE }, /* MPEG-1 Audio Layer 1, No CRC */ + { 2, "\xff\xf2", true }, /* MPEG-2 Audio Layer 3, CRC */ + { 2, "\xff\xf3", true }, /* MPEG-2 Audio Layer 3, No CRC */ + { 2, "\xff\xf4", true }, /* MPEG-2 Audio Layer 2, CRC */ + { 2, "\xff\xf5", true }, /* MPEG-2 Audio Layer 2, No CRC */ + { 2, "\xff\xf6", true }, /* MPEG-2 Audio Layer 1, CRC */ + { 2, "\xff\xf7", true }, /* MPEG-2 Audio Layer 1, No CRC */ + { 2, "\xff\xfa", true }, /* MPEG-1 Audio Layer 3, CRC */ + { 2, "\xff\xfc", true }, /* MPEG-1 Audio Layer 2, CRC */ + { 2, "\xff\xfd", true }, /* MPEG-1 Audio Layer 2, No CRC */ + { 2, "\xff\xfe", true }, /* MPEG-1 Audio Layer 1, CRC */ + { 2, "\xff\xff", true }, /* MPEG-1 Audio Layer 1, No CRC */ #endif - { 0, NULL, FALSE } + { 0, NULL, false } }; /* @@ -333,7 +333,7 @@ struct _mpeg_magic { * Untagged MPEG Audio files would still have to be heuristics, though. */ wtap_open_return_val -mpeg_open(wtap *wth, int *err, gchar **err_info) +mpeg_open(wtap *wth, int *err, char **err_info) { char magic_buf[16]; struct _mpeg_magic* m; @@ -385,7 +385,7 @@ static const struct supported_block_type mpeg_blocks_supported[] = { static const struct file_type_subtype_info mpeg_info = { "MPEG", "mpeg", "mpeg", "mpg;mp3", - FALSE, BLOCKS_SUPPORTED(mpeg_blocks_supported), + false, BLOCKS_SUPPORTED(mpeg_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/mpeg.h b/wiretap/mpeg.h index 5b1b220c..008c7a19 100644 --- a/wiretap/mpeg.h +++ b/wiretap/mpeg.h @@ -14,6 +14,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val mpeg_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val mpeg_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/mplog.c b/wiretap/mplog.c index e27400ad..2be8596a 100644 --- a/wiretap/mplog.c +++ b/wiretap/mplog.c @@ -35,13 +35,12 @@ */ #include "config.h" +#include "mplog.h" #include <string.h> #include <wtap-int.h> #include <file_wrappers.h> -#include "mplog.h" - /* the block types */ #define TYPE_PCD_PICC_A 0x70 #define TYPE_PICC_PCD_A 0x71 @@ -91,22 +90,22 @@ void register_mplog(void); - if two blocks of our packet's block type are more than 200us apart, we treat this as a packet boundary as described above */ -static gboolean mplog_read_packet(FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool mplog_read_packet(FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { - guint8 *p, *start_p; + uint8_t *p, *start_p; /* --- the last block of a known type --- */ - guint64 last_ctr = 0; + uint64_t last_ctr = 0; /* --- the current block --- */ - guint8 block[MPLOG_BLOCK_SIZE]; /* the entire block */ - guint8 data, type; /* its data and block type bytes */ - guint64 ctr; /* its timestamp counter */ + uint8_t block[MPLOG_BLOCK_SIZE]; /* the entire block */ + uint8_t data, type; /* its data and block type bytes */ + uint64_t ctr; /* its timestamp counter */ /* --- the packet we're assembling --- */ - gint pkt_bytes = 0; - guint8 pkt_type = TYPE_UNKNOWN; + int pkt_bytes = 0; + uint8_t pkt_type = TYPE_UNKNOWN; /* the timestamp of the packet's first block, this will become the packet's timestamp */ - guint64 pkt_ctr = 0; + uint64_t pkt_ctr = 0; ws_buffer_assure_space(buf, PKT_BUF_LEN); @@ -162,7 +161,7 @@ static gboolean mplog_read_packet(FILE_T fh, wtap_rec *rec, } while (pkt_bytes < ISO14443_MAX_PKT_LEN); if (pkt_type == TYPE_UNKNOWN) - return FALSE; + return false; start_p[0] = ISO14443_PSEUDO_HDR_VER; @@ -183,13 +182,13 @@ static gboolean mplog_read_packet(FILE_T fh, wtap_rec *rec, rec->rec_header.packet_header.caplen = ISO14443_PSEUDO_HDR_LEN + pkt_bytes; rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen; - return TRUE; + return true; } -static gboolean +static bool mplog_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); @@ -197,27 +196,27 @@ mplog_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, } -static gboolean -mplog_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +static bool +mplog_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err)) - return FALSE; + return false; if (!mplog_read_packet(wth->random_fh, rec, buf, err, err_info)) { /* Even if we got an immediate EOF, that's an error. */ if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -wtap_open_return_val mplog_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val mplog_open(wtap *wth, int *err, char **err_info) { - gboolean ok; - guint8 magic[6]; + bool ok; + uint8_t magic[6]; ok = wtap_read_bytes(wth->fh, magic, 6, err, err_info); if (!ok) { @@ -264,7 +263,7 @@ static const struct supported_block_type mplog_blocks_supported[] = { static const struct file_type_subtype_info mplog_info = { "Micropross mplog", "mplog", "mplog", NULL, - FALSE, BLOCKS_SUPPORTED(mplog_blocks_supported), + false, BLOCKS_SUPPORTED(mplog_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/mplog.h b/wiretap/mplog.h index 2a1ba18c..ea3cae4a 100644 --- a/wiretap/mplog.h +++ b/wiretap/mplog.h @@ -16,6 +16,6 @@ #include <glib.h> #include <wiretap/wtap.h> -wtap_open_return_val mplog_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val mplog_open(wtap *wth, int *err, char **err_info); #endif /* _MPLOG_H */ diff --git a/wiretap/netmon.c b/wiretap/netmon.c index 861b1f90..6adf5396 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -7,6 +7,8 @@ */ #include "config.h" +#include "netmon.h" + #include <errno.h> #include <string.h> #include <wsutil/unicode-utils.h> @@ -14,7 +16,6 @@ #include "file_wrappers.h" #include "atm.h" #include "pcap-encap.h" -#include "netmon.h" /* The file at * @@ -44,35 +45,35 @@ static const char netmon_2_x_magic[MAGIC_SIZE] = { /* Network Monitor file header (minus magic number). */ struct netmon_hdr { - guint8 ver_minor; /* minor version number */ - guint8 ver_major; /* major version number */ - guint16 network; /* network type */ - guint16 ts_year; /* year of capture start */ - guint16 ts_month; /* month of capture start (January = 1) */ - guint16 ts_dow; /* day of week of capture start (Sun = 0) */ - guint16 ts_day; /* day of month of capture start */ - guint16 ts_hour; /* hour of capture start */ - guint16 ts_min; /* minute of capture start */ - guint16 ts_sec; /* second of capture start */ - guint16 ts_msec; /* millisecond of capture start */ - guint32 frametableoffset; /* frame index table offset */ - guint32 frametablelength; /* frame index table size */ - guint32 userdataoffset; /* user data offset */ - guint32 userdatalength; /* user data size */ - guint32 commentdataoffset; /* comment data offset */ - guint32 commentdatalength; /* comment data size */ - guint32 processinfooffset; /* offset to process info structure */ - guint32 processinfocount; /* number of process info structures */ - guint32 networkinfooffset; /* offset to network info structure */ - guint32 networkinfolength; /* length of network info structure */ + uint8_t ver_minor; /* minor version number */ + uint8_t ver_major; /* major version number */ + uint16_t network; /* network type */ + uint16_t ts_year; /* year of capture start */ + uint16_t ts_month; /* month of capture start (January = 1) */ + uint16_t ts_dow; /* day of week of capture start (Sun = 0) */ + uint16_t ts_day; /* day of month of capture start */ + uint16_t ts_hour; /* hour of capture start */ + uint16_t ts_min; /* minute of capture start */ + uint16_t ts_sec; /* second of capture start */ + uint16_t ts_msec; /* millisecond of capture start */ + uint32_t frametableoffset; /* frame index table offset */ + uint32_t frametablelength; /* frame index table size */ + uint32_t userdataoffset; /* user data offset */ + uint32_t userdatalength; /* user data size */ + uint32_t commentdataoffset; /* comment data offset */ + uint32_t commentdatalength; /* comment data size */ + uint32_t processinfooffset; /* offset to process info structure */ + uint32_t processinfocount; /* number of process info structures */ + uint32_t networkinfooffset; /* offset to network info structure */ + uint32_t networkinfolength; /* length of network info structure */ }; /* Network Monitor 1.x record header; not defined in STRUCT.H, but deduced by * looking at capture files. */ struct netmonrec_1_x_hdr { - guint32 ts_delta; /* time stamp - msecs since start of capture */ - guint16 orig_len; /* actual length of packet */ - guint16 incl_len; /* number of octets captured in file */ + uint32_t ts_delta; /* time stamp - msecs since start of capture */ + uint16_t orig_len; /* actual length of packet */ + uint16_t incl_len; /* number of octets captured in file */ }; /* @@ -80,9 +81,9 @@ struct netmonrec_1_x_hdr { * help files. */ struct netmonrec_2_x_hdr { - guint64 ts_delta; /* time stamp - usecs since start of capture */ - guint32 orig_len; /* actual length of packet */ - guint32 incl_len; /* number of octets captured in file */ + uint64_t ts_delta; /* time stamp - usecs since start of capture */ + uint32_t orig_len; /* actual length of packet */ + uint32_t incl_len; /* number of octets captured in file */ }; /* @@ -94,49 +95,49 @@ struct netmonrec_2_x_hdr { * natural boundaries. */ struct netmonrec_2_1_trlr { - guint8 network[2]; /* network type for this packet */ + uint8_t network[2]; /* network type for this packet */ }; struct netmonrec_2_2_trlr { - guint8 network[2]; /* network type for this packet */ - guint8 process_info_index[4]; /* index into the process info table */ + uint8_t network[2]; /* network type for this packet */ + uint8_t process_info_index[4]; /* index into the process info table */ }; struct netmonrec_2_3_trlr { - guint8 network[2]; /* network type for this packet */ - guint8 process_info_index[4]; /* index into the process info table */ - guint8 utc_timestamp[8]; /* packet time stamp, as .1 us units since January 1, 1601, 00:00:00 UTC */ - guint8 timezone_index; /* index of time zone information */ + uint8_t network[2]; /* network type for this packet */ + uint8_t process_info_index[4]; /* index into the process info table */ + uint8_t utc_timestamp[8]; /* packet time stamp, as .1 us units since January 1, 1601, 00:00:00 UTC */ + uint8_t timezone_index; /* index of time zone information */ }; struct netmonrec_comment { - guint32 numFramePerComment; /* Currently, this is always set to 1. Each comment is attached to only one frame. */ - guint32 frameOffset; /* Offset in the capture file table that indicates the beginning of the frame. Key used to match comment with frame */ - guint8* title; /* Comment title */ - guint32 descLength; /* Number of bytes in the comment description. Must be at least zero. */ - guint8* description; /* Comment description */ + uint32_t numFramePerComment; /* Currently, this is always set to 1. Each comment is attached to only one frame. */ + uint32_t frameOffset; /* Offset in the capture file table that indicates the beginning of the frame. Key used to match comment with frame */ + uint8_t* title; /* Comment title */ + uint32_t descLength; /* Number of bytes in the comment description. Must be at least zero. */ + uint8_t* description; /* Comment description */ }; /* Just the first few fields of netmonrec_comment so it can be read sequentially from file */ struct netmonrec_comment_header { - guint32 numFramePerComment; - guint32 frameOffset; - guint32 titleLength; + uint32_t numFramePerComment; + uint32_t frameOffset; + uint32_t titleLength; }; union ip_address { - guint32 ipv4; + uint32_t ipv4; ws_in6_addr ipv6; }; struct netmonrec_process_info { - guint8* path; /* A Unicode string of length PathSize */ - guint32 iconSize; - guint8* iconData; - guint32 pid; - guint16 localPort; - guint16 remotePort; - gboolean isIPv6; + uint8_t* path; /* A Unicode string of length PathSize */ + uint32_t iconSize; + uint8_t* iconData; + uint32_t pid; + uint16_t localPort; + uint16_t remotePort; + bool isIPv6; union ip_address localAddr; union ip_address remoteAddr; }; @@ -145,22 +146,22 @@ struct netmonrec_process_info { * The link-layer header on ATM packets. */ struct netmon_atm_hdr { - guint8 dest[6]; /* "Destination address" - what is it? */ - guint8 src[6]; /* "Source address" - what is it? */ - guint16 vpi; /* VPI */ - guint16 vci; /* VCI */ + uint8_t dest[6]; /* "Destination address" - what is it? */ + uint8_t src[6]; /* "Source address" - what is it? */ + uint16_t vpi; /* VPI */ + uint16_t vci; /* VCI */ }; typedef struct { - time_t start_secs; - guint32 start_nsecs; - guint8 version_major; - guint8 version_minor; - guint32 *frame_table; - guint32 frame_table_size; + time_t start_secs; + uint32_t start_nsecs; + uint8_t version_major; + uint8_t version_minor; + uint32_t *frame_table; + uint32_t frame_table_size; GHashTable* comment_table; GHashTable* process_info_table; - guint current_frame; + unsigned current_frame; } netmon_t; /* @@ -202,7 +203,7 @@ static const int netmon_encap[] = { WTAP_ENCAP_UNKNOWN, /* NDIS Wireless WAN */ WTAP_ENCAP_UNKNOWN /* NDIS IrDA */ }; -#define NUM_NETMON_ENCAPS (sizeof netmon_encap / sizeof netmon_encap[0]) +#define NUM_NETMON_ENCAPS array_length(netmon_encap) /* * Special link-layer types. @@ -215,17 +216,17 @@ static const int netmon_encap[] = { #define NETMON_NET_DNS_CACHE 0xFFFE #define NETMON_NET_NETMON_FILTER 0xFFFF -static gboolean netmon_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean netmon_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean netmon_read_atm_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); +static bool netmon_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool netmon_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool netmon_read_atm_pseudoheader(FILE_T fh, + union wtap_pseudo_header *pseudo_header, int *err, char **err_info); static void netmon_close(wtap *wth); -static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err, - gchar **err_info); +static bool netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); +static bool netmon_dump_finish(wtap_dumper *wdh, int *err, + char **err_info); static int netmon_1_x_file_type_subtype = -1; static int netmon_2_x_file_type_subtype = -1; @@ -237,14 +238,14 @@ void register_netmon(void); * but is not guaranteed to be null-terminated (as it came from a file), * to a null-terminated UTF-8 string. */ -static guint8 * -utf_16_to_utf_8(const guint8 *in, guint32 length) +static uint8_t * +utf_16_to_utf_8(const uint8_t *in, uint32_t length) { - guint8 *result, *out; + uint8_t *result, *out; gunichar2 uchar2; gunichar uchar; size_t n_bytes; - guint32 i; + uint32_t i; /* * Get the length of the resulting UTF-8 string, and validate @@ -316,7 +317,7 @@ utf_16_to_utf_8(const guint8 *in, guint32 length) * Now allocate a buffer big enough for the UTF-8 string plus a * trailing NUL, and generate the string. */ - result = (guint8 *)g_malloc(n_bytes + 1); + result = (uint8_t *)g_malloc(n_bytes + 1); out = result; for (i = 0; i + 1 < length && (uchar2 = pletoh16(in + i)) != '\0'; @@ -389,7 +390,7 @@ utf_16_to_utf_8(const guint8 *in, guint32 length) } -static void netmonrec_comment_destroy(gpointer key) { +static void netmonrec_comment_destroy(void *key) { struct netmonrec_comment *comment = (struct netmonrec_comment*) key; g_free(comment->title); @@ -397,7 +398,7 @@ static void netmonrec_comment_destroy(gpointer key) { g_free(comment); } -static void netmonrec_process_info_destroy(gpointer key) { +static void netmonrec_process_info_destroy(void *key) { struct netmonrec_process_info *process_info = (struct netmonrec_process_info*) key; g_free(process_info->path); @@ -405,21 +406,21 @@ static void netmonrec_process_info_destroy(gpointer key) { g_free(process_info); } -wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val netmon_open(wtap *wth, int *err, char **err_info) { char magic[MAGIC_SIZE]; struct netmon_hdr hdr; int file_type; struct tm tm; - guint32 frame_table_offset; - guint32 frame_table_length; - guint32 frame_table_size; - guint32 *frame_table; - guint32 comment_table_offset, process_info_table_offset; - guint32 comment_table_size, process_info_table_count; + uint32_t frame_table_offset; + uint32_t frame_table_length; + uint32_t frame_table_size; + uint32_t *frame_table; + uint32_t comment_table_offset, process_info_table_offset; + uint32_t comment_table_size, process_info_table_count; GHashTable *comment_table, *process_info_table; struct netmonrec_comment* comment_rec; - gint64 file_size = wtap_file_size(wth, err); + int64_t file_size = wtap_file_size(wth, err); #if G_BYTE_ORDER == G_BIG_ENDIAN unsigned int i; #endif @@ -554,8 +555,8 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) * in it as the offsets of the frames. */ frame_table_length = pletoh32(&hdr.frametablelength); - frame_table_size = frame_table_length / (guint32)sizeof (guint32); - if ((frame_table_size * sizeof (guint32)) != frame_table_length) { + frame_table_size = frame_table_length / (uint32_t)sizeof (uint32_t); + if ((frame_table_size * sizeof (uint32_t)) != frame_table_length) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("netmon: frame table length is %u, which is not a multiple of the size of an entry", frame_table_length); @@ -659,7 +660,7 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) * large chunks of memory for the frame table */ - frame_table = (guint32 *)g_try_malloc(frame_table_length); + frame_table = (uint32_t *)g_try_malloc(frame_table_length); if (frame_table_length != 0 && frame_table == NULL) { *err = ENOMEM; /* we assume we're out of memory */ return WTAP_OPEN_ERROR; @@ -693,9 +694,9 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) while (comment_table_size > 16) { struct netmonrec_comment_header comment_header; - guint32 title_length; - guint32 desc_length; - guint8 *utf16_str; + uint32_t title_length; + uint32_t desc_length; + uint8_t *utf16_str; /* Read the first 12 bytes of the structure */ if (!wtap_read_bytes(wth->fh, &comment_header, 12, err, err_info)) { @@ -733,7 +734,7 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) * size is a count of octets, not octet pairs or * Unicode characters. */ - utf16_str = (guint8*)g_malloc(title_length); + utf16_str = (uint8_t*)g_malloc(title_length); if (!wtap_read_bytes(wth->fh, utf16_str, title_length, err, err_info)) { g_hash_table_destroy(comment_table); @@ -772,7 +773,7 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_ERROR; } - comment_rec->description = (guint8*)g_malloc(comment_rec->descLength); + comment_rec->description = (uint8_t*)g_malloc(comment_rec->descLength); /* Read the comment description */ if (!wtap_read_bytes(wth->fh, comment_rec->description, comment_rec->descLength, err, err_info)) { @@ -787,7 +788,7 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) } if ((process_info_table_offset > 0) && (process_info_table_count > 0)) { - guint16 version; + uint16_t version; /* Go to the process table offset */ if (file_seek(wth->fh, process_info_table_offset, SEEK_SET, err) == -1) { @@ -809,10 +810,10 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) while (process_info_table_count > 0) { struct netmonrec_process_info* process_info; - guint32 tmp32; - guint16 tmp16; - guint32 path_size; - guint8 *utf16_str; + uint32_t tmp32; + uint16_t tmp16; + uint32_t path_size; + uint8_t *utf16_str; process_info = g_new0(struct netmonrec_process_info, 1); @@ -840,7 +841,7 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) * size is a count of octets, not octet pairs or * Unicode characters. */ - utf16_str = (guint8*)g_malloc(path_size); + utf16_str = (uint8_t*)g_malloc(path_size); if (!wtap_read_bytes(wth->fh, utf16_str, path_size, err, err_info)) { g_free(process_info); @@ -913,7 +914,7 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) g_hash_table_destroy(process_info_table); return WTAP_OPEN_ERROR; } - process_info->isIPv6 = ((pletoh32(&tmp32) == 0) ? FALSE : TRUE); + process_info->isIPv6 = ((pletoh32(&tmp32) == 0) ? false : true); if (process_info->isIPv6) { if (!wtap_read_bytes(wth->fh, &process_info->localAddr.ipv6, 16, err, err_info)) { @@ -925,7 +926,7 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_ERROR; } } else { - guint8 ipbuffer[16]; + uint8_t ipbuffer[16]; if (!wtap_read_bytes(wth->fh, ipbuffer, 16, err, err_info)) { g_hash_table_destroy(process_info_table); return WTAP_OPEN_ERROR; @@ -1020,28 +1021,28 @@ typedef enum { static process_record_retval netmon_process_record(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { netmon_t *netmon = (netmon_t *)wth->priv; - int hdr_size = 0; + int hdr_size = 0; union { struct netmonrec_1_x_hdr hdr_1_x; struct netmonrec_2_x_hdr hdr_2_x; } hdr; - gint64 delta = 0; /* signed - frame times can be before the nominal start */ - gint64 t; - time_t secs; - int nsecs; - guint32 packet_size = 0; - guint32 orig_size = 0; - int trlr_size; + int64_t delta = 0; /* signed - frame times can be before the nominal start */ + int64_t t; + time_t secs; + int nsecs; + uint32_t packet_size = 0; + uint32_t orig_size = 0; + int trlr_size; union { struct netmonrec_2_1_trlr trlr_2_1; struct netmonrec_2_2_trlr trlr_2_2; struct netmonrec_2_3_trlr trlr_2_3; } trlr; - guint16 network; - int pkt_encap; + uint16_t network; + int pkt_encap; struct netmonrec_comment* comment_rec = NULL; /* Read record header. */ @@ -1111,8 +1112,8 @@ netmon_process_record(wtap *wth, FILE_T fh, wtap_rec *rec, /* * Don't count the pseudo-header as part of the packet. */ - orig_size -= (guint)sizeof (struct netmon_atm_hdr); - packet_size -= (guint)sizeof (struct netmon_atm_hdr); + orig_size -= (unsigned)sizeof (struct netmon_atm_hdr); + packet_size -= (unsigned)sizeof (struct netmon_atm_hdr); break; default: @@ -1125,14 +1126,14 @@ netmon_process_record(wtap *wth, FILE_T fh, wtap_rec *rec, /* * According to Paul Long, this offset is unsigned. * It's 32 bits, so the maximum value will fit in - * a gint64 such as delta, even after multiplying + * a int64_t such as delta, even after multiplying * it by 1000000. * - * pletoh32() returns a guint32; we cast it to gint64 + * pletoh32() returns a uint32_t; we cast it to int64_t * before multiplying, so that the product doesn't - * overflow a guint32. + * overflow a uint32_t. */ - delta = ((gint64)pletoh32(&hdr.hdr_1_x.ts_delta))*1000000; + delta = ((int64_t)pletoh32(&hdr.hdr_1_x.ts_delta))*1000000; break; case 2: @@ -1353,7 +1354,7 @@ netmon_process_record(wtap *wth, FILE_T fh, wtap_rec *rec, * contains a UTC per-packet time stamp; use * that instead of the start time and offset. */ - guint64 d; + uint64_t d; d = pletoh64(trlr.trlr_2_3.utc_timestamp); @@ -1430,17 +1431,17 @@ netmon_process_record(wtap *wth, FILE_T fh, wtap_rec *rec, } /* Read the next packet */ -static gboolean netmon_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool netmon_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { netmon_t *netmon = (netmon_t *)wth->priv; - gint64 rec_offset; + int64_t rec_offset; for (;;) { /* Have we reached the end of the packet data? */ if (netmon->current_frame >= netmon->frame_table_size) { *err = 0; /* it's just an EOF, not an error */ - return FALSE; + return false; } /* Seek to the beginning of the current record, if we're @@ -1456,7 +1457,7 @@ static gboolean netmon_read(wtap *wth, wtap_rec *rec, Buffer *buf, rec_offset = netmon->frame_table[netmon->current_frame]; if (file_tell(wth->fh) != rec_offset) { if (file_seek(wth->fh, rec_offset, SEEK_SET, err) == -1) - return FALSE; + return false; } netmon->current_frame++; @@ -1469,20 +1470,20 @@ static gboolean netmon_read(wtap *wth, wtap_rec *rec, Buffer *buf, continue; case SUCCESS: - return TRUE; + return true; case FAILURE: - return FALSE; + return false; } } } -static gboolean -netmon_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +netmon_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; switch (netmon_process_record(wth, wth->random_fh, rec, buf, err, err_info)) { @@ -1493,26 +1494,26 @@ netmon_seek_read(wtap *wth, gint64 seek_off, */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("netmon: saw metadata in netmon_seek_read"); - return FALSE; + return false; case SUCCESS: - return TRUE; + return true; case FAILURE: - return FALSE; + return false; } } -static gboolean +static bool netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - int *err, gchar **err_info) + int *err, char **err_info) { struct netmon_atm_hdr atm_phdr; - guint16 vpi, vci; + uint16_t vpi, vci; if (!wtap_read_bytes(fh, &atm_phdr, sizeof (struct netmon_atm_hdr), err, err_info)) - return FALSE; + return false; vpi = g_ntohs(atm_phdr.vpi); vci = g_ntohs(atm_phdr.vci); @@ -1528,7 +1529,7 @@ netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, pseudo_header->atm.aal5t_len = 0; pseudo_header->atm.aal5t_chksum = 0; - return TRUE; + return true; } /* Throw away the frame table used by the sequential I/O stream. */ @@ -1554,14 +1555,14 @@ netmon_close(wtap *wth) } typedef struct { - gboolean is_v2; - gboolean got_first_record_time; + bool is_v2; + bool got_first_record_time; nstime_t first_record_time; - guint32 frame_table_offset; - guint32 *frame_table; - guint frame_table_index; - guint frame_table_size; - gboolean no_more_room; /* TRUE if no more records can be written */ + uint32_t frame_table_offset; + uint32_t *frame_table; + unsigned frame_table_index; + unsigned frame_table_size; + bool no_more_room; /* true if no more records can be written */ } netmon_dump_t; static const int wtap_encap[] = { @@ -1580,7 +1581,7 @@ static const int wtap_encap[] = { -1, /* WTAP_ENCAP_LAPB -> unsupported*/ 4, /* WTAP_ENCAP_ATM_PDUS -> NDIS WAN (*NOT* ATM!) */ }; -#define NUM_WTAP_ENCAPS (sizeof wtap_encap / sizeof wtap_encap[0]) +#define NUM_WTAP_ENCAPS array_length(wtap_encap) /* Returns 0 if we could write the specified encapsulation type, an error indication otherwise. */ @@ -1611,10 +1612,10 @@ static int netmon_dump_can_write_encap_2_x(int encap) return 0; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean netmon_dump_open(wtap_dumper *wdh, gboolean is_v2, - int *err, gchar **err_info _U_) +static bool netmon_dump_open(wtap_dumper *wdh, bool is_v2, + int *err, char **err_info _U_) { netmon_dump_t *netmon; @@ -1623,7 +1624,7 @@ static gboolean netmon_dump_open(wtap_dumper *wdh, gboolean is_v2, the header when we've written out all the packets, we just skip over the header for now. */ if (wtap_dump_file_seek(wdh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1) - return FALSE; + return false; wdh->bytes_dumped = CAPTUREFILE_HEADER_SIZE; wdh->subtype_write = netmon_dump; @@ -1633,29 +1634,29 @@ static gboolean netmon_dump_open(wtap_dumper *wdh, gboolean is_v2, wdh->priv = (void *)netmon; netmon->is_v2 = is_v2; netmon->frame_table_offset = CAPTUREFILE_HEADER_SIZE; - netmon->got_first_record_time = FALSE; + netmon->got_first_record_time = false; netmon->frame_table = NULL; netmon->frame_table_index = 0; netmon->frame_table_size = 0; - netmon->no_more_room = FALSE; + netmon->no_more_room = false; - return TRUE; + return true; } -static gboolean netmon_dump_open_1_x(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool netmon_dump_open_1_x(wtap_dumper *wdh, int *err, char **err_info _U_) { - return netmon_dump_open(wdh, FALSE, err, err_info); + return netmon_dump_open(wdh, false, err, err_info); } -static gboolean netmon_dump_open_2_x(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool netmon_dump_open_2_x(wtap_dumper *wdh, int *err, char **err_info _U_) { - return netmon_dump_open(wdh, TRUE, err, err_info); + return netmon_dump_open(wdh, true, err, err_info); } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; netmon_dump_t *netmon = (netmon_dump_t *)wdh->priv; @@ -1667,20 +1668,20 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, size_t hdr_size; struct netmon_atm_hdr atm_hdr; int atm_hdrsize; - gint64 secs; - gint32 nsecs; + int64_t secs; + int32_t nsecs; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } if (netmon->is_v2) { /* Don't write anything we're not willing to read. */ if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } } else { /* @@ -1689,7 +1690,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* @@ -1698,7 +1699,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } } @@ -1713,7 +1714,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, * No. Fail. */ *err = WTAP_ERR_UNWRITABLE_ENCAP; - return FALSE; + return false; } /* @@ -1732,7 +1733,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, * handle. */ *err = EFBIG; - return FALSE; + return false; } /* @@ -1748,14 +1749,14 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, netmon->first_record_time.secs = rec->ts.secs; netmon->first_record_time.nsecs = (rec->ts.nsecs/1000000)*1000000; - netmon->got_first_record_time = TRUE; + netmon->got_first_record_time = true; } if (wdh->file_encap == WTAP_ENCAP_ATM_PDUS) atm_hdrsize = sizeof (struct netmon_atm_hdr); else atm_hdrsize = 0; - secs = (gint64)(rec->ts.secs - netmon->first_record_time.secs); + secs = (int64_t)(rec->ts.secs - netmon->first_record_time.secs); nsecs = rec->ts.nsecs - netmon->first_record_time.nsecs; while (nsecs < 0) { /* @@ -1803,7 +1804,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, rec_size = 0; if (!wtap_dump_file_write(wdh, hdrp, hdr_size, err)) - return FALSE; + return false; rec_size += hdr_size; if (wdh->file_encap == WTAP_ENCAP_ATM_PDUS) { @@ -1816,12 +1817,12 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, atm_hdr.vpi = g_htons(pseudo_header->atm.vpi); atm_hdr.vci = g_htons(pseudo_header->atm.vci); if (!wtap_dump_file_write(wdh, &atm_hdr, sizeof atm_hdr, err)) - return FALSE; + return false; rec_size += sizeof atm_hdr; } if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; rec_size += rec->rec_header.packet_header.caplen; if (wdh->file_encap == WTAP_ENCAP_PER_PACKET) { @@ -1830,7 +1831,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (!wtap_dump_file_write(wdh, &rec_2_x_trlr, sizeof rec_2_x_trlr, err)) - return FALSE; + return false; rec_size += sizeof rec_2_x_trlr; } @@ -1841,7 +1842,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, /* * Haven't yet allocated the buffer for the frame table. */ - netmon->frame_table = (guint32 *)g_malloc(1024 * sizeof *netmon->frame_table); + netmon->frame_table = (uint32_t *)g_malloc(1024 * sizeof *netmon->frame_table); netmon->frame_table_size = 1024; } else { /* @@ -1852,7 +1853,7 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, * Yes - double the size of the frame table. */ netmon->frame_table_size *= 2; - netmon->frame_table = (guint32 *)g_realloc(netmon->frame_table, + netmon->frame_table = (uint32_t *)g_realloc(netmon->frame_table, netmon->frame_table_size * sizeof *netmon->frame_table); } } @@ -1874,22 +1875,22 @@ static gboolean netmon_dump(wtap_dumper *wdh, const wtap_rec *rec, * Note: this also catches the unlikely possibility that * the record itself is > 2^32 - 1 bytes long. */ - if ((guint64)netmon->frame_table_offset + rec_size > G_MAXUINT32) { + if ((uint64_t)netmon->frame_table_offset + rec_size > UINT32_MAX) { /* * Yup, too big. */ - netmon->no_more_room = TRUE; + netmon->no_more_room = true; } netmon->frame_table_index++; - netmon->frame_table_offset += (guint32) rec_size; + netmon->frame_table_offset += (uint32_t) rec_size; - return TRUE; + return true; } /* Finish writing to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err, - gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool netmon_dump_finish(wtap_dumper *wdh, int *err, + char **err_info _U_) { netmon_dump_t *netmon = (netmon_dump_t *)wdh->priv; size_t n_to_write; @@ -1897,17 +1898,17 @@ static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err, const char *magicp; size_t magic_size; struct tm *tm; - gint64 saved_bytes_dumped; + int64_t saved_bytes_dumped; /* Write out the frame table. "netmon->frame_table_index" is the number of entries we've put into it. */ n_to_write = netmon->frame_table_index * sizeof *netmon->frame_table; if (!wtap_dump_file_write(wdh, netmon->frame_table, n_to_write, err)) - return FALSE; + return false; /* Now go fix up the file header. */ if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) - return FALSE; + return false; /* Save bytes_dumped since following calls to wtap_dump_file_write() * will still (mistakenly) increase it. */ @@ -1943,7 +1944,7 @@ static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err, file_hdr.ver_minor = 1; } if (!wtap_dump_file_write(wdh, magicp, magic_size, err)) - return FALSE; + return false; if (wdh->file_encap == WTAP_ENCAP_PER_PACKET) { /* @@ -1977,10 +1978,10 @@ static gboolean netmon_dump_finish(wtap_dumper *wdh, int *err, file_hdr.frametablelength = GUINT32_TO_LE(netmon->frame_table_index * sizeof *netmon->frame_table); if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err)) - return FALSE; + return false; wdh->bytes_dumped = saved_bytes_dumped; - return TRUE; + return true; } static const struct supported_block_type netmon_1_x_blocks_supported[] = { @@ -1992,7 +1993,7 @@ static const struct supported_block_type netmon_1_x_blocks_supported[] = { static const struct file_type_subtype_info netmon_1_x_info = { "Microsoft NetMon 1.x", "netmon1", "cap", NULL, - TRUE, BLOCKS_SUPPORTED(netmon_1_x_blocks_supported), + true, BLOCKS_SUPPORTED(netmon_1_x_blocks_supported), netmon_dump_can_write_encap_1_x, netmon_dump_open_1_x, NULL }; @@ -2005,7 +2006,7 @@ static const struct supported_block_type netmon_2_x_blocks_supported[] = { static const struct file_type_subtype_info netmon_2_x_info = { "Microsoft NetMon 2.x", "netmon2", "cap", NULL, - TRUE, BLOCKS_SUPPORTED(netmon_2_x_blocks_supported), + true, BLOCKS_SUPPORTED(netmon_2_x_blocks_supported), netmon_dump_can_write_encap_2_x, netmon_dump_open_2_x, NULL }; diff --git a/wiretap/netmon.h b/wiretap/netmon.h index 2146b35e..155222af 100644 --- a/wiretap/netmon.h +++ b/wiretap/netmon.h @@ -12,6 +12,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val netmon_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c index c1b229e0..e1f0dfe9 100644 --- a/wiretap/netscaler.c +++ b/wiretap/netscaler.c @@ -7,10 +7,11 @@ */ #include "config.h" +#include "netscaler.h" + #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "netscaler.h" #include <wsutil/ws_assert.h> /* Defines imported from netscaler code: nsperfrc.h */ @@ -82,22 +83,22 @@ typedef struct nspr_header_v10 { - guint8 ph_RecordType[2]; /* Record Type */ - guint8 ph_RecordSize[2]; /* Record Size including header */ + uint8_t ph_RecordType[2]; /* Record Type */ + uint8_t ph_RecordSize[2]; /* Record Size including header */ } nspr_header_v10_t; -#define nspr_header_v10_s ((guint32)sizeof(nspr_header_v10_t)) +#define nspr_header_v10_s ((uint32_t)sizeof(nspr_header_v10_t)) /* This is V20 short header (2 bytes long) to be included where needed */ #define NSPR_HEADER_V20(prefix) \ - guint8 prefix##_RecordType; /* Record Type */ \ - guint8 prefix##_RecordSize /* Record Size including header */ \ + uint8_t prefix##_RecordType; /* Record Type */ \ + uint8_t prefix##_RecordSize /* Record Size including header */ \ /* end of declaration */ /* This is new long header (3 bytes long) to be included where needed */ #define NSPR_HEADER3B_V20(prefix) \ - guint8 prefix##_RecordType; /* Record Type */ \ - guint8 prefix##_RecordSizeLow; /* Record Size including header */ \ - guint8 prefix##_RecordSizeHigh /* Record Size including header */ \ + uint8_t prefix##_RecordType; /* Record Type */ \ + uint8_t prefix##_RecordSizeLow; /* Record Size including header */ \ + uint8_t prefix##_RecordSizeHigh /* Record Size including header */ \ /* end of declaration */ #define NSPR_HEADER3B_V21 NSPR_HEADER3B_V20 #define NSPR_HEADER3B_V22 NSPR_HEADER3B_V20 @@ -108,7 +109,7 @@ typedef struct nspr_hd_v20 NSPR_HEADER3B_V20(phd); /* long performance header */ } nspr_hd_v20_t; -#define nspr_hd_v20_s ((guint32)sizeof(nspr_hd_v20_t)) +#define nspr_hd_v20_s ((uint32_t)sizeof(nspr_hd_v20_t)) /* @@ -121,23 +122,23 @@ typedef struct nspr_hd_v20 /* Performance Data Header with device number */ typedef struct nspr_headerdev_v10 { - guint8 ph_RecordType[2]; /* Record Type */ - guint8 ph_RecordSize[2]; /* Record Size including header */ - guint8 ph_DevNo[4]; /* Network Device (NIC/CONN) number */ + uint8_t ph_RecordType[2]; /* Record Type */ + uint8_t ph_RecordSize[2]; /* Record Size including header */ + uint8_t ph_DevNo[4]; /* Network Device (NIC/CONN) number */ } nspr_headerdev_v10_t; -#define nspr_headerdev_v10_s ((guint32)sizeof(nspr_headerdev_v10_t)) +#define nspr_headerdev_v10_s ((uint32_t)sizeof(nspr_headerdev_v10_t)) typedef struct nspr_hd_v10 { nspr_header_v10_t phd; /* performance header */ } nspr_hd_v10_t; -#define nspr_hd_v10_s ((guint32)sizeof(nspr_hd_v10_t)) +#define nspr_hd_v10_s ((uint32_t)sizeof(nspr_hd_v10_t)) typedef struct nspr_hdev_v10 { nspr_headerdev_v10_t phd; /* performance header */ } nspr_hdev_v10_t; -#define nspr_hdev_v10_s ((guint32)sizeof(nspr_hdev_v10_t)) +#define nspr_hdev_v10_s ((uint32_t)sizeof(nspr_hdev_v10_t)) /* if structure has defined phd as first field, it can use following names */ #define nsprRecordType phd.ph_RecordType @@ -151,60 +152,60 @@ typedef struct nspr_hdev_v10 typedef struct nspr_signature_v10 { nspr_header_v10_t phd; /* performance header */ - guint8 sig_EndianType; /* Endian Type for the data */ - guint8 sig_Reserved0; - guint8 sig_Reserved1[2]; - gchar sig_Signature[NSPR_SIGSIZE_V10]; /* Signature value */ + uint8_t sig_EndianType; /* Endian Type for the data */ + uint8_t sig_Reserved0; + uint8_t sig_Reserved1[2]; + char sig_Signature[NSPR_SIGSIZE_V10]; /* Signature value */ } nspr_signature_v10_t; -#define nspr_signature_v10_s ((guint32)sizeof(nspr_signature_v10_t)) +#define nspr_signature_v10_s ((uint32_t)sizeof(nspr_signature_v10_t)) /* NSPR_SIGNATURE_V20 structure */ #define NSPR_SIGSIZE_V20 sizeof(NSPR_SIGSTR_V20) /* signature value size in bytes */ typedef struct nspr_signature_v20 { NSPR_HEADER_V20(sig); /* short performance header */ - guint8 sig_EndianType; /* Endian Type for the data */ - gchar sig_Signature[NSPR_SIGSIZE_V20]; /* Signature value */ + uint8_t sig_EndianType; /* Endian Type for the data */ + char sig_Signature[NSPR_SIGSIZE_V20]; /* Signature value */ } nspr_signature_v20_t; -#define nspr_signature_v20_s ((guint32)sizeof(nspr_signature_v20_t)) +#define nspr_signature_v20_s ((uint32_t)sizeof(nspr_signature_v20_t)) /* NSPR_SIGNATURE_V30 structure */ #define NSPR_SIGSIZE_V30 sizeof(NSPR_SIGSTR_V30) /* signature value size in bytes */ typedef struct nspr_signature_v30 { NSPR_HEADER_V20(sig); /* short performance header */ - guint8 sig_EndianType; /* Endian Type for the data */ - gchar sig_Signature[NSPR_SIGSIZE_V30]; /* Signature value */ + uint8_t sig_EndianType; /* Endian Type for the data */ + char sig_Signature[NSPR_SIGSIZE_V30]; /* Signature value */ } nspr_signature_v30_t; -#define nspr_signature_v30_s ((guint32)sizeof(nspr_signature_v30_t)) +#define nspr_signature_v30_s ((uint32_t)sizeof(nspr_signature_v30_t)) #define NSPR_SIGSIZE_V35 sizeof(NSPR_SIGSTR_V35) /* signature value size in bytes */ typedef struct nspr_signature_v35 { NSPR_HEADER_V20(sig); /* short performance header */ - guint8 sig_EndianType; /* Endian Type for the data */ - gchar sig_Signature[NSPR_SIGSIZE_V35]; /* Signature value */ + uint8_t sig_EndianType; /* Endian Type for the data */ + char sig_Signature[NSPR_SIGSIZE_V35]; /* Signature value */ } nspr_signature_v35_t; -#define nspr_signature_v35_s ((guint32)sizeof(nspr_signature_v35_t)) +#define nspr_signature_v35_s ((uint32_t)sizeof(nspr_signature_v35_t)) /* NSPR_ABSTIME_V10 and NSPR_SYSTARTIME_V10 structure */ typedef struct nspr_abstime_v10 { nspr_header_v10_t phd; /* performance header */ - guint8 abs_RelTime[4]; /* relative time is ms from last time */ - guint8 abs_Time[4]; /* absolute time in seconds from 1970 */ + uint8_t abs_RelTime[4]; /* relative time is ms from last time */ + uint8_t abs_Time[4]; /* absolute time in seconds from 1970 */ } nspr_abstime_v10_t; -#define nspr_abstime_v10_s ((guint32)sizeof(nspr_abstime_v10_t)) +#define nspr_abstime_v10_s ((uint32_t)sizeof(nspr_abstime_v10_t)) /* NSPR_ABSTIME_V20 and NSPR_SYSTARTIME_V20 structure */ typedef struct nspr_abstime_v20 { NSPR_HEADER_V20(abs); /* short performance header */ - guint8 abs_RelTime[2]; /* relative time is ms from last time */ - guint8 abs_Time[4]; /* absolute time in seconds from 1970 */ + uint8_t abs_RelTime[2]; /* relative time is ms from last time */ + uint8_t abs_Time[4]; /* absolute time in seconds from 1970 */ } nspr_abstime_v20_t; -#define nspr_abstime_v20_s ((guint32)sizeof(nspr_abstime_v20_t)) +#define nspr_abstime_v20_s ((uint32_t)sizeof(nspr_abstime_v20_t)) @@ -212,287 +213,287 @@ typedef struct nspr_abstime_v20 typedef struct nspr_pktracefull_v10 { nspr_headerdev_v10_t phd; /* performance header */ - guint8 fp_RelTimeHr[4]; /* High resolution relative time */ + uint8_t fp_RelTimeHr[4]; /* High resolution relative time */ } nspr_pktracefull_v10_t; -#define nspr_pktracefull_v10_s ((guint32)(sizeof(nspr_pktracefull_v10_t))) +#define nspr_pktracefull_v10_s ((uint32_t)(sizeof(nspr_pktracefull_v10_t))) /* new full packet trace structure v20 */ typedef struct nspr_pktracefull_v20 { NSPR_HEADER3B_V20(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_RelTimeHr[4]; /* High resolution relative time */ + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_RelTimeHr[4]; /* High resolution relative time */ } nspr_pktracefull_v20_t; -#define nspr_pktracefull_v20_s ((guint32)(sizeof(nspr_pktracefull_v20_t))) +#define nspr_pktracefull_v20_s ((uint32_t)(sizeof(nspr_pktracefull_v20_t))) /* new full packet trace structure v21 */ typedef struct nspr_pktracefull_v21 { NSPR_HEADER3B_V21(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_RelTimeHr[4]; /* High resolution relative time */ - guint8 fp_PcbDevNo[4]; /* PCB devno */ - guint8 fp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_RelTimeHr[4]; /* High resolution relative time */ + uint8_t fp_PcbDevNo[4]; /* PCB devno */ + uint8_t fp_lPcbDevNo[4]; /* link PCB devno */ } nspr_pktracefull_v21_t; -#define nspr_pktracefull_v21_s ((guint32)(sizeof(nspr_pktracefull_v21_t))) +#define nspr_pktracefull_v21_s ((uint32_t)(sizeof(nspr_pktracefull_v21_t))) /* new full packet trace structure v22 */ typedef struct nspr_pktracefull_v22 { NSPR_HEADER3B_V22(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_RelTimeHr[4]; /* High resolution relative time */ - guint8 fp_PcbDevNo[4]; /* PCB devno */ - guint8 fp_lPcbDevNo[4]; /* link PCB devno */ - guint8 fp_VlanTag[2]; /* vlan tag */ + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_RelTimeHr[4]; /* High resolution relative time */ + uint8_t fp_PcbDevNo[4]; /* PCB devno */ + uint8_t fp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t fp_VlanTag[2]; /* vlan tag */ } nspr_pktracefull_v22_t; -#define nspr_pktracefull_v22_s ((guint32)(sizeof(nspr_pktracefull_v22_t))) +#define nspr_pktracefull_v22_s ((uint32_t)(sizeof(nspr_pktracefull_v22_t))) typedef struct nspr_pktracefull_v23 { NSPR_HEADER3B_V22(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_AbsTimeHr[8]; /* High resolution absolute time */ - guint8 fp_PcbDevNo[4]; /* PCB devno */ - guint8 fp_lPcbDevNo[4]; /* link PCB devno */ - guint8 fp_VlanTag[2]; /* vlan tag */ - guint8 fp_Coreid[2]; /* coreid of the packet */ + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_AbsTimeHr[8]; /* High resolution absolute time */ + uint8_t fp_PcbDevNo[4]; /* PCB devno */ + uint8_t fp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t fp_VlanTag[2]; /* vlan tag */ + uint8_t fp_Coreid[2]; /* coreid of the packet */ } nspr_pktracefull_v23_t; -#define nspr_pktracefull_v23_s ((guint32)(sizeof(nspr_pktracefull_v23_t))) +#define nspr_pktracefull_v23_s ((uint32_t)(sizeof(nspr_pktracefull_v23_t))) /* New full packet trace structure v24 for cluster tracing */ typedef struct nspr_pktracefull_v24 { NSPR_HEADER3B_V22(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_AbsTimeHr[8]; /* High resolution absolute time in nanosec */ - guint8 fp_PcbDevNo[4]; /* PCB devno */ - guint8 fp_lPcbDevNo[4]; /* link PCB devno */ - guint8 fp_VlanTag[2]; /* vlan tag */ - guint8 fp_Coreid[2]; /* coreid of the packet */ - guint8 fp_srcNodeId[2]; /* source node # */ - guint8 fp_destNodeId[2]; /* destination node # */ - guint8 fp_clFlags; /* cluster flags */ + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_AbsTimeHr[8]; /* High resolution absolute time in nanosec */ + uint8_t fp_PcbDevNo[4]; /* PCB devno */ + uint8_t fp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t fp_VlanTag[2]; /* vlan tag */ + uint8_t fp_Coreid[2]; /* coreid of the packet */ + uint8_t fp_srcNodeId[2]; /* source node # */ + uint8_t fp_destNodeId[2]; /* destination node # */ + uint8_t fp_clFlags; /* cluster flags */ } nspr_pktracefull_v24_t; -#define nspr_pktracefull_v24_s ((guint32)(sizeof(nspr_pktracefull_v24_t))) +#define nspr_pktracefull_v24_s ((uint32_t)(sizeof(nspr_pktracefull_v24_t))) /* New full packet trace structure v25 for vm info tracing */ typedef struct nspr_pktracefull_v25 { NSPR_HEADER3B_V22(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_AbsTimeHr[8]; /* High resolution absolute time in nanosec */ - guint8 fp_PcbDevNo[4]; /* PCB devno */ - guint8 fp_lPcbDevNo[4]; /* link PCB devno */ - guint8 fp_VlanTag[2]; /* vlan tag */ - guint8 fp_Coreid[2]; /* coreid of the packet */ - guint8 fp_srcNodeId[2]; /* source node # */ - guint8 fp_destNodeId[2]; /* destination node # */ - guint8 fp_clFlags; /* cluster flags */ - guint8 fp_src_vmname_len; /* vm src info */ - guint8 fp_dst_vmname_len; /* vm src info */ + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_AbsTimeHr[8]; /* High resolution absolute time in nanosec */ + uint8_t fp_PcbDevNo[4]; /* PCB devno */ + uint8_t fp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t fp_VlanTag[2]; /* vlan tag */ + uint8_t fp_Coreid[2]; /* coreid of the packet */ + uint8_t fp_srcNodeId[2]; /* source node # */ + uint8_t fp_destNodeId[2]; /* destination node # */ + uint8_t fp_clFlags; /* cluster flags */ + uint8_t fp_src_vmname_len; /* vm src info */ + uint8_t fp_dst_vmname_len; /* vm src info */ } nspr_pktracefull_v25_t; -#define nspr_pktracefull_v25_s ((guint32)(sizeof(nspr_pktracefull_v25_t))) +#define nspr_pktracefull_v25_s ((uint32_t)(sizeof(nspr_pktracefull_v25_t))) /* New full packet trace structure v26 for vm info tracing */ typedef struct nspr_pktracefull_v26 { NSPR_HEADER3B_V22(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_AbsTimeHr[8]; /* High resolution absolute time in nanosec */ - guint8 fp_PcbDevNo[4]; /* PCB devno */ - guint8 fp_lPcbDevNo[4]; /* link PCB devno */ - guint8 fp_VlanTag[2]; /* vlan tag */ - guint8 fp_Coreid[2]; /* coreid of the packet */ - guint8 fp_srcNodeId[2]; /* source node # */ - guint8 fp_destNodeId[2]; /* destination node # */ - guint8 fp_clFlags; /* cluster flags */ - guint8 fp_src_vmname_len; /* vm src info */ - guint8 fp_dst_vmname_len; /* vm src info */ - guint8 fp_reserved; - guint8 fp_ns_activity[4]; - guint8 fp_reserved_32[12]; /* Adding more field to reduce wireshark changes every time */ + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_AbsTimeHr[8]; /* High resolution absolute time in nanosec */ + uint8_t fp_PcbDevNo[4]; /* PCB devno */ + uint8_t fp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t fp_VlanTag[2]; /* vlan tag */ + uint8_t fp_Coreid[2]; /* coreid of the packet */ + uint8_t fp_srcNodeId[2]; /* source node # */ + uint8_t fp_destNodeId[2]; /* destination node # */ + uint8_t fp_clFlags; /* cluster flags */ + uint8_t fp_src_vmname_len; /* vm src info */ + uint8_t fp_dst_vmname_len; /* vm src info */ + uint8_t fp_reserved; + uint8_t fp_ns_activity[4]; + uint8_t fp_reserved_32[12]; /* Adding more field to reduce wireshark changes every time */ } nspr_pktracefull_v26_t; -#define nspr_pktracefull_v26_s ((guint32)(sizeof(nspr_pktracefull_v26_t))) +#define nspr_pktracefull_v26_s ((uint32_t)(sizeof(nspr_pktracefull_v26_t))) /* partial packet trace structure */ typedef struct nspr_pktracepart_v10 { nspr_headerdev_v10_t phd; /* performance header */ - guint8 pp_RelTimeHr[4]; /* High resolution relative time */ - guint8 pp_PktSizeOrg[2]; /* Original packet size */ - guint8 pp_PktOffset[2]; /* starting offset in packet */ + uint8_t pp_RelTimeHr[4]; /* High resolution relative time */ + uint8_t pp_PktSizeOrg[2]; /* Original packet size */ + uint8_t pp_PktOffset[2]; /* starting offset in packet */ } nspr_pktracepart_v10_t; -#define nspr_pktracepart_v10_s ((guint32)(sizeof(nspr_pktracepart_v10_t))) +#define nspr_pktracepart_v10_s ((uint32_t)(sizeof(nspr_pktracepart_v10_t))) /* new partial packet trace structure */ typedef struct nspr_pktracepart_v20 { NSPR_HEADER3B_V20(pp); /* long performance header */ - guint8 pp_DevNo; /* Network Device (NIC) number */ - guint8 pp_RelTimeHr[4]; /* High resolution relative time */ - guint8 pp_PktSizeOrg[2]; /* Original packet size */ - guint8 pp_PktOffset[2]; /* starting offset in packet */ + uint8_t pp_DevNo; /* Network Device (NIC) number */ + uint8_t pp_RelTimeHr[4]; /* High resolution relative time */ + uint8_t pp_PktSizeOrg[2]; /* Original packet size */ + uint8_t pp_PktOffset[2]; /* starting offset in packet */ } nspr_pktracepart_v20_t; -#define nspr_pktracepart_v20_s ((guint32)(sizeof(nspr_pktracepart_v20_t))) +#define nspr_pktracepart_v20_s ((uint32_t)(sizeof(nspr_pktracepart_v20_t))) /* new partial packet trace structure */ typedef struct nspr_pktracepart_v21 { NSPR_HEADER3B_V21(pp); /* long performance header */ - guint8 pp_DevNo; /* Network Device (NIC) number */ - guint8 pp_RelTimeHr[4]; /* High resolution relative time */ - guint8 pp_PktSizeOrg[2]; /* Original packet size */ - guint8 pp_PktOffset[2]; /* starting offset in packet */ - guint8 pp_PcbDevNo[4]; /* PCB devno */ - guint8 pp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t pp_DevNo; /* Network Device (NIC) number */ + uint8_t pp_RelTimeHr[4]; /* High resolution relative time */ + uint8_t pp_PktSizeOrg[2]; /* Original packet size */ + uint8_t pp_PktOffset[2]; /* starting offset in packet */ + uint8_t pp_PcbDevNo[4]; /* PCB devno */ + uint8_t pp_lPcbDevNo[4]; /* link PCB devno */ } nspr_pktracepart_v21_t; -#define nspr_pktracepart_v21_s ((guint32)(sizeof(nspr_pktracepart_v21_t))) +#define nspr_pktracepart_v21_s ((uint32_t)(sizeof(nspr_pktracepart_v21_t))) /* new partial packet trace structure v22 */ typedef struct nspr_pktracepart_v22 { NSPR_HEADER3B_V22(pp); /* long performance header */ - guint8 pp_DevNo; /* Network Device (NIC) number */ - guint8 pp_RelTimeHr[4]; /* High resolution relative time */ - guint8 pp_PktSizeOrg[2]; /* Original packet size */ - guint8 pp_PktOffset[2]; /* starting offset in packet */ - guint8 pp_PcbDevNo[4]; /* PCB devno */ - guint8 pp_lPcbDevNo[4]; /* link PCB devno */ - guint8 pp_VlanTag[2]; /* Vlan Tag */ + uint8_t pp_DevNo; /* Network Device (NIC) number */ + uint8_t pp_RelTimeHr[4]; /* High resolution relative time */ + uint8_t pp_PktSizeOrg[2]; /* Original packet size */ + uint8_t pp_PktOffset[2]; /* starting offset in packet */ + uint8_t pp_PcbDevNo[4]; /* PCB devno */ + uint8_t pp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t pp_VlanTag[2]; /* Vlan Tag */ } nspr_pktracepart_v22_t; -#define nspr_pktracepart_v22_s ((guint32)(sizeof(nspr_pktracepart_v22_t))) +#define nspr_pktracepart_v22_s ((uint32_t)(sizeof(nspr_pktracepart_v22_t))) typedef struct nspr_pktracepart_v23 { NSPR_HEADER3B_V22(pp); /* long performance header */ - guint8 pp_DevNo; /* Network Device (NIC) number */ - guint8 pp_AbsTimeHr[8]; /* High resolution absolute time */ - guint8 pp_PktSizeOrg[2]; /* Original packet size */ - guint8 pp_PktOffset[2]; /* starting offset in packet */ - guint8 pp_PcbDevNo[4]; /* PCB devno */ - guint8 pp_lPcbDevNo[4]; /* link PCB devno */ - guint8 pp_VlanTag[2]; /* vlan tag */ - guint8 pp_Coreid[2]; /* Coreid of the packet */ + uint8_t pp_DevNo; /* Network Device (NIC) number */ + uint8_t pp_AbsTimeHr[8]; /* High resolution absolute time */ + uint8_t pp_PktSizeOrg[2]; /* Original packet size */ + uint8_t pp_PktOffset[2]; /* starting offset in packet */ + uint8_t pp_PcbDevNo[4]; /* PCB devno */ + uint8_t pp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t pp_VlanTag[2]; /* vlan tag */ + uint8_t pp_Coreid[2]; /* Coreid of the packet */ } nspr_pktracepart_v23_t; -#define nspr_pktracepart_v23_s ((guint32)(sizeof(nspr_pktracepart_v23_t))) +#define nspr_pktracepart_v23_s ((uint32_t)(sizeof(nspr_pktracepart_v23_t))) /* New partial packet trace structure v24 for cluster tracing */ typedef struct nspr_pktracepart_v24 { NSPR_HEADER3B_V22(pp); /* long performance header */ - guint8 pp_DevNo; /* Network Device (NIC) number */ - guint8 pp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ - guint8 pp_PktSizeOrg[2]; /* Original packet size */ - guint8 pp_PktOffset[2]; /* starting offset in packet */ - guint8 pp_PcbDevNo[4]; /* PCB devno */ - guint8 pp_lPcbDevNo[4]; /* link PCB devno */ - guint8 pp_VlanTag[2]; /* vlan tag */ - guint8 pp_Coreid[2]; /* Coreid of the packet */ - guint8 pp_srcNodeId[2]; /* source node # */ - guint8 pp_destNodeId[2]; /* destination node # */ - guint8 pp_clFlags; /* cluster flags */ + uint8_t pp_DevNo; /* Network Device (NIC) number */ + uint8_t pp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ + uint8_t pp_PktSizeOrg[2]; /* Original packet size */ + uint8_t pp_PktOffset[2]; /* starting offset in packet */ + uint8_t pp_PcbDevNo[4]; /* PCB devno */ + uint8_t pp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t pp_VlanTag[2]; /* vlan tag */ + uint8_t pp_Coreid[2]; /* Coreid of the packet */ + uint8_t pp_srcNodeId[2]; /* source node # */ + uint8_t pp_destNodeId[2]; /* destination node # */ + uint8_t pp_clFlags; /* cluster flags */ } nspr_pktracepart_v24_t; -#define nspr_pktracepart_v24_s ((guint32)(sizeof(nspr_pktracepart_v24_t))) +#define nspr_pktracepart_v24_s ((uint32_t)(sizeof(nspr_pktracepart_v24_t))) /* New partial packet trace structure v25 for vm info tracing */ typedef struct nspr_pktracepart_v25 { NSPR_HEADER3B_V22(pp); /* long performance header */ - guint8 pp_DevNo; /* Network Device (NIC) number */ - guint8 pp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ - guint8 pp_PktSizeOrg[2]; /* Original packet size */ - guint8 pp_PktOffset[2]; /* starting offset in packet */ - guint8 pp_PcbDevNo[4]; /* PCB devno */ - guint8 pp_lPcbDevNo[4]; /* link PCB devno */ - guint8 pp_VlanTag[2]; /* vlan tag */ - guint8 pp_Coreid[2]; /* Coreid of the packet */ - guint8 pp_srcNodeId[2]; /* source node # */ - guint8 pp_destNodeId[2]; /* destination node # */ - guint8 pp_clFlags; /* cluster flags */ - guint8 pp_src_vmname_len; /* vm info */ - guint8 pp_dst_vmname_len; /* vm info */ + uint8_t pp_DevNo; /* Network Device (NIC) number */ + uint8_t pp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ + uint8_t pp_PktSizeOrg[2]; /* Original packet size */ + uint8_t pp_PktOffset[2]; /* starting offset in packet */ + uint8_t pp_PcbDevNo[4]; /* PCB devno */ + uint8_t pp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t pp_VlanTag[2]; /* vlan tag */ + uint8_t pp_Coreid[2]; /* Coreid of the packet */ + uint8_t pp_srcNodeId[2]; /* source node # */ + uint8_t pp_destNodeId[2]; /* destination node # */ + uint8_t pp_clFlags; /* cluster flags */ + uint8_t pp_src_vmname_len; /* vm info */ + uint8_t pp_dst_vmname_len; /* vm info */ } nspr_pktracepart_v25_t; -#define nspr_pktracepart_v25_s ((guint32)(sizeof(nspr_pktracepart_v25_t))) +#define nspr_pktracepart_v25_s ((uint32_t)(sizeof(nspr_pktracepart_v25_t))) /* New full packet trace structure v30 for multipage spanning data */ typedef struct nspr_pktracefull_v30 { NSPR_HEADER3B_V30(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ - guint8 fp_PcbDevNo[4]; /* PCB devno */ - guint8 fp_lPcbDevNo[4]; /* link PCB devno */ - guint8 fp_PktSizeOrg[2]; /* Original packet size */ - guint8 fp_VlanTag[2]; /* vlan tag */ - guint8 fp_Coreid[2]; /* coreid of the packet */ - guint8 fp_srcNodeId[2]; /* cluster nodeid of the packet */ - guint8 fp_destNodeId[2]; - guint8 fp_clFlags; - guint8 fp_src_vmname_len; - guint8 fp_dst_vmname_len; - guint8 fp_reserved[3]; - guint8 fp_ns_activity[4]; - guint8 fp_reserved_32[12]; + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ + uint8_t fp_PcbDevNo[4]; /* PCB devno */ + uint8_t fp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t fp_PktSizeOrg[2]; /* Original packet size */ + uint8_t fp_VlanTag[2]; /* vlan tag */ + uint8_t fp_Coreid[2]; /* coreid of the packet */ + uint8_t fp_srcNodeId[2]; /* cluster nodeid of the packet */ + uint8_t fp_destNodeId[2]; + uint8_t fp_clFlags; + uint8_t fp_src_vmname_len; + uint8_t fp_dst_vmname_len; + uint8_t fp_reserved[3]; + uint8_t fp_ns_activity[4]; + uint8_t fp_reserved_32[12]; } nspr_pktracefull_v30_t; -#define nspr_pktracefull_v30_s ((guint32)(sizeof(nspr_pktracefull_v30_t))) +#define nspr_pktracefull_v30_s ((uint32_t)(sizeof(nspr_pktracefull_v30_t))) /* New full packet trace structure v35 for multipage spanning data */ typedef struct nspr_pktracefull_v35 { NSPR_HEADER3B_V30(fp); /* long performance header */ - guint8 fp_DevNo; /* Network Device (NIC) number */ - guint8 fp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ - guint8 fp_PcbDevNo[4]; /* PCB devno */ - guint8 fp_lPcbDevNo[4]; /* link PCB devno */ - guint8 fp_PktSizeOrg[2]; /* Original packet size */ - guint8 fp_VlanTag[2]; /* vlan tag */ - guint8 fp_Coreid[2]; /* coreid of the packet */ - guint8 fp_headerlen[2]; - guint8 fp_errorcode; - guint8 fp_app; - guint8 fp_ns_activity[4]; - guint8 fp_nextrectype; + uint8_t fp_DevNo; /* Network Device (NIC) number */ + uint8_t fp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ + uint8_t fp_PcbDevNo[4]; /* PCB devno */ + uint8_t fp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t fp_PktSizeOrg[2]; /* Original packet size */ + uint8_t fp_VlanTag[2]; /* vlan tag */ + uint8_t fp_Coreid[2]; /* coreid of the packet */ + uint8_t fp_headerlen[2]; + uint8_t fp_errorcode; + uint8_t fp_app; + uint8_t fp_ns_activity[4]; + uint8_t fp_nextrectype; } nspr_pktracefull_v35_t; -#define nspr_pktracefull_v35_s ((guint32)(sizeof(nspr_pktracefull_v35_t))) +#define nspr_pktracefull_v35_s ((uint32_t)(sizeof(nspr_pktracefull_v35_t))) /* New partial packet trace structure v26 for vm info tracing */ typedef struct nspr_pktracepart_v26 { NSPR_HEADER3B_V22(pp); /* long performance header */ - guint8 pp_DevNo; /* Network Device (NIC) number */ - guint8 pp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ - guint8 pp_PktSizeOrg[2]; /* Original packet size */ - guint8 pp_PktOffset[2]; /* starting offset in packet */ - guint8 pp_PcbDevNo[4]; /* PCB devno */ - guint8 pp_lPcbDevNo[4]; /* link PCB devno */ - guint8 pp_VlanTag[2]; /* vlan tag */ - guint8 pp_Coreid[2]; /* Coreid of the packet */ - guint8 pp_srcNodeId[2]; /* source node # */ - guint8 pp_destNodeId[2]; /* destination node # */ - guint8 pp_clFlags; /* cluster flags */ - guint8 pp_src_vmname_len; /* vm info */ - guint8 pp_dst_vmname_len; /* vm info */ - guint8 pp_reserved; - guint8 pp_ns_activity[4]; - guint8 pp_reserved_32[12]; /* Adding more field to reduce wireshark changes every time */ + uint8_t pp_DevNo; /* Network Device (NIC) number */ + uint8_t pp_AbsTimeHr[8]; /*High resolution absolute time in nanosec*/ + uint8_t pp_PktSizeOrg[2]; /* Original packet size */ + uint8_t pp_PktOffset[2]; /* starting offset in packet */ + uint8_t pp_PcbDevNo[4]; /* PCB devno */ + uint8_t pp_lPcbDevNo[4]; /* link PCB devno */ + uint8_t pp_VlanTag[2]; /* vlan tag */ + uint8_t pp_Coreid[2]; /* Coreid of the packet */ + uint8_t pp_srcNodeId[2]; /* source node # */ + uint8_t pp_destNodeId[2]; /* destination node # */ + uint8_t pp_clFlags; /* cluster flags */ + uint8_t pp_src_vmname_len; /* vm info */ + uint8_t pp_dst_vmname_len; /* vm info */ + uint8_t pp_reserved; + uint8_t pp_ns_activity[4]; + uint8_t pp_reserved_32[12]; /* Adding more field to reduce wireshark changes every time */ } nspr_pktracepart_v26_t; -#define nspr_pktracepart_v26_s ((guint32)(sizeof(nspr_pktracepart_v26_t))) +#define nspr_pktracepart_v26_s ((uint32_t)(sizeof(nspr_pktracepart_v26_t))) #define __TNDO(rec,enumprefix,structname,hdrname)\ - static const guint8 enumprefix##_##hdrname##_offset = (guint8)sizeof(nspr_##structname##_t); + static const uint8_t enumprefix##_##hdrname##_offset = (uint8_t)sizeof(nspr_##structname##_t); #define __TNO(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ - static const guint8 enumprefix##_##hdrname##_offset = (guint8)GPOINTER_TO_INT(offsetof(nspr_##structname##_t,structprefix##_##structfieldname)); + static const uint8_t enumprefix##_##hdrname##_offset = (uint8_t)GPOINTER_TO_INT(offsetof(nspr_##structname##_t,structprefix##_##structfieldname)); #define __TNL(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ - static const guint8 enumprefix##_##hdrname##_len = (guint8)sizeof(((nspr_##structname##_t*)0)->structprefix##_##structfieldname); + static const uint8_t enumprefix##_##hdrname##_len = (uint8_t)sizeof(((nspr_##structname##_t*)0)->structprefix##_##structfieldname); #define __TNV1O(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ - static const guint8 enumprefix##_##hdrname##_offset = (guint8)GPOINTER_TO_INT(offsetof(nspr_##structname##_t,structfieldname)); + static const uint8_t enumprefix##_##hdrname##_offset = (uint8_t)GPOINTER_TO_INT(offsetof(nspr_##structname##_t,structfieldname)); #define __TNV1L(rec,enumprefix,structprefix,structname,hdrname,structfieldname) \ - static const guint8 enumprefix##_##hdrname##_len = (guint8)sizeof(((nspr_##structname##_t*)0)->structfieldname); + static const uint8_t enumprefix##_##hdrname##_len = (uint8_t)sizeof(((nspr_##structname##_t*)0)->structfieldname); #define TRACE_V10_REC_LEN_OFF(rec,enumprefix,structprefix,structname) \ __TNV1O(rec,enumprefix,structprefix,structname,dir,phd.ph_RecordType)\ @@ -581,26 +582,26 @@ typedef struct nspr_pktracepart_v26 #define ns_setrelativetime(nstrace, RelativeTimems) \ do { \ - guint32 rsec; \ + uint32_t rsec; \ (nstrace)->nspm_curtimemsec += RelativeTimems; \ - rsec = (guint32)((nstrace)->nspm_curtimemsec - (nstrace)->nspm_curtimelastmsec)/1000; \ + rsec = (uint32_t)((nstrace)->nspm_curtimemsec - (nstrace)->nspm_curtimelastmsec)/1000; \ (nstrace)->nspm_curtime += rsec; \ (nstrace)->nspm_curtimelastmsec += rsec * 1000; \ } while (0) typedef struct { - gchar *pnstrace_buf; - guint32 page_size; - gint64 xxx_offset; - guint32 nstrace_buf_offset; - guint32 nstrace_buflen; + char *pnstrace_buf; + uint32_t page_size; + int64_t xxx_offset; + uint32_t nstrace_buf_offset; + uint32_t nstrace_buflen; /* Performance Monitor Time variables */ - guint32 nspm_curtime; /* current time since 1970 */ - guint64 nspm_curtimemsec; /* current time in milliseconds */ - guint64 nspm_curtimelastmsec; /* nspm_curtime last update time in milliseconds */ - guint64 nsg_creltime; - guint64 file_size; + uint32_t nspm_curtime; /* current time since 1970 */ + uint64_t nspm_curtimemsec; /* current time in milliseconds */ + uint64_t nspm_curtimelastmsec; /* nspm_curtime last update time in milliseconds */ + uint64_t nsg_creltime; + uint64_t file_size; } nstrace_t; /* @@ -612,40 +613,40 @@ typedef struct { #define NSPM_SIGNATURE_3_5 3 #define NSPM_SIGNATURE_NOMATCH -1 -static int nspm_signature_version(gchar*, guint); -static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, - gint64 *data_offset); -static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, - gint64 *data_offset); -static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, - gint64 *data_offset); -static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, +static int nspm_signature_version(char*, unsigned); +static bool nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, + int64_t *data_offset); +static bool nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, + int64_t *data_offset); +static bool nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, + int64_t *data_offset); +static bool nstrace_seek_read_v10(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); -static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, + int *err, char **err_info); +static bool nstrace_seek_read_v20(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); -static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, + int *err, char **err_info); +static bool nstrace_seek_read_v30(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + int *err, char **err_info); static void nstrace_close(wtap *wth); -static gboolean nstrace_set_start_time_v10(wtap *wth, int *err, - gchar **err_info); -static gboolean nstrace_set_start_time_v20(wtap *wth, int *err, - gchar **err_info); -static gboolean nstrace_set_start_time(wtap *wth, int version, int *err, - gchar **err_info); -static guint64 ns_hrtime2nsec(guint32 tm); +static bool nstrace_set_start_time_v10(wtap *wth, int *err, + char **err_info); +static bool nstrace_set_start_time_v20(wtap *wth, int *err, + char **err_info); +static bool nstrace_set_start_time(wtap *wth, int version, int *err, + char **err_info); +static uint64_t ns_hrtime2nsec(uint32_t tm); -static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); +static bool nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); static int nstrace_1_0_file_type_subtype = -1; @@ -659,38 +660,38 @@ void register_nstrace(void); * Minimum of the page size and the amount of data left in the file; * the last page of a file can be short. */ -#define GET_READ_PAGE_SIZE(remaining_file_size) ((gint32)((remaining_file_size>NSPR_PAGESIZE)?NSPR_PAGESIZE:remaining_file_size)) -#define GET_READ_PAGE_SIZEV3(remaining_file_size) ((gint32)((remaining_file_size>NSPR_PAGESIZE_TRACE)?NSPR_PAGESIZE_TRACE:remaining_file_size)) +#define GET_READ_PAGE_SIZE(remaining_file_size) ((int32_t)((remaining_file_size>NSPR_PAGESIZE)?NSPR_PAGESIZE:remaining_file_size)) +#define GET_READ_PAGE_SIZEV3(remaining_file_size) ((int32_t)((remaining_file_size>NSPR_PAGESIZE_TRACE)?NSPR_PAGESIZE_TRACE:remaining_file_size)) /* * Check whether we have enough room to retrieve the data in the caller. * If not, we have a malformed file. */ -static gboolean nstrace_ensure_buflen(nstrace_t* nstrace, guint offset, guint len, int *err, gchar** err_info) +static bool nstrace_ensure_buflen(nstrace_t* nstrace, unsigned offset, unsigned len, int *err, char** err_info) { if (offset > nstrace->nstrace_buflen || nstrace->nstrace_buflen - offset < len) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: malformed file"); - return FALSE; + return false; } - return TRUE; + return true; } -static guint64 ns_hrtime2nsec(guint32 tm) +static uint64_t ns_hrtime2nsec(uint32_t tm) { - guint32 val = tm & NSPR_HRTIME_MASKTM; + uint32_t val = tm & NSPR_HRTIME_MASKTM; switch(tm & NSPR_HRTIME_MASKFMT) { - case NSPR_HRTIME_SEC: return (guint64)val*1000000000; - case NSPR_HRTIME_MSEC: return (guint64)val*1000000; - case NSPR_HRTIME_USEC: return (guint64)val*1000; + case NSPR_HRTIME_SEC: return (uint64_t)val*1000000000; + case NSPR_HRTIME_MSEC: return (uint64_t)val*1000000; + case NSPR_HRTIME_USEC: return (uint64_t)val*1000; case NSPR_HRTIME_NSEC: return val; } return tm; } -static gboolean -nstrace_read_page(wtap *wth, int *err, gchar **err_info) +static bool +nstrace_read_page(wtap *wth, int *err, char **err_info) { nstrace_t *nstrace = (nstrace_t *)wth->priv; int bytes_read; @@ -698,28 +699,28 @@ nstrace_read_page(wtap *wth, int *err, gchar **err_info) bytes_read = file_read(nstrace->pnstrace_buf, nstrace->page_size, wth->fh); if (bytes_read < 0) { *err = file_error(wth->fh, err_info); - return FALSE; + return false; } if (bytes_read == 0) { /* * EOF. */ *err = 0; - return FALSE; + return false; } - nstrace->nstrace_buflen = (guint32)bytes_read; - return TRUE; + nstrace->nstrace_buflen = (uint32_t)bytes_read; + return true; } /* ** Netscaler trace format open routines */ -wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val nstrace_open(wtap *wth, int *err, char **err_info) { int file_version; - gchar *nstrace_buf; - gint64 file_size; - gint32 page_size; + char *nstrace_buf; + int64_t file_size; + int32_t page_size; int bytes_read; nstrace_t *nstrace; @@ -729,7 +730,7 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_NOT_MINE; /* The size is 64 bits; we assume it fits in 63 bits, so it's positive */ - nstrace_buf = (gchar *)g_malloc(NSPR_PAGESIZE); + nstrace_buf = (char *)g_malloc(NSPR_PAGESIZE); page_size = NSPR_PAGESIZE; /* @@ -752,7 +753,7 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) /* * Scan it for a signature block. */ - file_version = nspm_signature_version(nstrace_buf, (guint)bytes_read); + file_version = nspm_signature_version(nstrace_buf, (unsigned)bytes_read); switch (file_version) { case NSPM_SIGNATURE_1_0: @@ -773,7 +774,7 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) * (XXX - use g_realloc()?) */ g_free(nstrace_buf); - nstrace_buf = (gchar *)g_malloc(NSPR_PAGESIZE_TRACE); + nstrace_buf = (char *)g_malloc(NSPR_PAGESIZE_TRACE); page_size = NSPR_PAGESIZE_TRACE; break; @@ -785,7 +786,7 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) * (XXX - use g_realloc()?) */ g_free(nstrace_buf); - nstrace_buf = (gchar *)g_malloc(NSPR_PAGESIZE_TRACE); + nstrace_buf = (char *)g_malloc(NSPR_PAGESIZE_TRACE); page_size = NSPR_PAGESIZE_TRACE; break; @@ -851,7 +852,7 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) } /* Set the start time by looking for the abstime record */ - if ((nstrace_set_start_time(wth, file_version, err, err_info)) == FALSE) + if ((nstrace_set_start_time(wth, file_version, err, err_info)) == false) { /* * No absolute time record seen, so we just reset the read @@ -922,7 +923,7 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info) ** checking whether either a '\n' or '\0' follows the first line? */ #define nspm_signature_func(ver) \ - static guint32 nspm_signature_isv##ver(gchar *sigp, size_t sigsize) {\ + static uint32_t nspm_signature_isv##ver(char *sigp, size_t sigsize) {\ size_t versiglen = sizeof(NSPR_SIGSTR_V##ver)-1;\ return sigsize >= versiglen && strncmp(sigp,NSPR_SIGSTR_V##ver,versiglen) == 0;\ } @@ -945,9 +946,9 @@ nspm_signature_func(35) ** XXX - can we assume the signature block is the first block? */ static int -nspm_signature_version(gchar *nstrace_buf, guint len) +nspm_signature_version(char *nstrace_buf, unsigned len) { - gchar *dp = nstrace_buf; + char *dp = nstrace_buf; for ( ; len > MIN(nspr_signature_v10_s, nspr_signature_v20_s); dp++, len--) { @@ -1017,7 +1018,7 @@ nspm_signature_version(gchar *nstrace_buf, guint len) #define nspr_getv10recordsize(hdp) (pletoh16(&(hdp)->nsprRecordSize)) #define nspr_getv20recordtype(hdp) ((hdp)->phd_RecordType) #define nspr_getv20recordsize(hdp) \ - (guint32)(((hdp)->phd_RecordSizeLow & NSPR_V20RECORDSIZE_2BYTES)? \ + (uint32_t)(((hdp)->phd_RecordSizeLow & NSPR_V20RECORDSIZE_2BYTES)? \ (((hdp)->phd_RecordSizeHigh * NSPR_V20RECORDSIZE_2BYTES)+ \ ((hdp)->phd_RecordSizeLow & ~NSPR_V20RECORDSIZE_2BYTES)) : \ (hdp)->phd_RecordSizeLow) @@ -1032,29 +1033,29 @@ nspm_signature_version(gchar *nstrace_buf, guint len) * as a NetScaler trace. */ #define nstrace_set_start_time_ver(ver) \ - gboolean nstrace_set_start_time_v##ver(wtap *wth, int *err, gchar **err_info) \ + bool nstrace_set_start_time_v##ver(wtap *wth, int *err, char **err_info) \ {\ nstrace_t *nstrace = (nstrace_t *)wth->priv;\ - gchar* nstrace_buf = nstrace->pnstrace_buf;\ - guint32 nstrace_buf_offset = nstrace->nstrace_buf_offset;\ - guint32 nstrace_buflen = nstrace->nstrace_buflen;\ - guint32 record_size;\ + char* nstrace_buf = nstrace->pnstrace_buf;\ + uint32_t nstrace_buf_offset = nstrace->nstrace_buf_offset;\ + uint32_t nstrace_buflen = nstrace->nstrace_buflen;\ + uint32_t record_size;\ do\ {\ while (nstrace_buf_offset < nstrace_buflen)\ {\ if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_hd_v##ver##_t), err, err_info))\ - return FALSE;\ + return false;\ nspr_hd_v##ver##_t *fp = (nspr_hd_v##ver##_t *) &nstrace_buf[nstrace_buf_offset];\ switch (nspr_getv##ver##recordtype(fp))\ {\ case NSPR_ABSTIME_V##ver:\ if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_abstime_v##ver##_t), err, err_info))\ - return FALSE;\ + return false;\ ns_setabstime(nstrace, pletoh32(&((nspr_abstime_v##ver##_t *) fp)->abs_Time), pletoh16(&((nspr_abstime_v##ver##_t *) fp)->abs_RelTime));\ nstrace->nstrace_buf_offset = nstrace_buf_offset + nspr_getv##ver##recordsize(fp);\ nstrace->nstrace_buflen = nstrace_buflen;\ - return TRUE;\ + return true;\ case NSPR_UNUSEDSPACE_V10:\ nstrace_buf_offset = nstrace_buflen;\ break;\ @@ -1063,7 +1064,7 @@ nspm_signature_version(gchar *nstrace_buf, guint len) if (record_size == 0) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: zero size record found");\ - return FALSE;\ + return false;\ }\ nstrace_buf_offset += record_size;\ }\ @@ -1072,7 +1073,7 @@ nspm_signature_version(gchar *nstrace_buf, guint len) nstrace->xxx_offset += nstrace_buflen;\ nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset));\ }while((nstrace_buflen > 0) && (nstrace_read_page(wth, err, err_info)));\ - return FALSE;\ + return false;\ } nstrace_set_start_time_ver(10) @@ -1087,8 +1088,8 @@ nstrace_set_start_time_ver(20) ** the next record after the ABSTIME record. Inorder to report correct time values, all trace ** records before the ABSTIME record are ignored. */ -static gboolean nstrace_set_start_time(wtap *wth, int file_version, int *err, - gchar **err_info) +static bool nstrace_set_start_time(wtap *wth, int file_version, int *err, + char **err_info) { if (file_version == NSPM_SIGNATURE_1_0) return nstrace_set_start_time_v10(wth, err, err_info); @@ -1096,7 +1097,7 @@ static gboolean nstrace_set_start_time(wtap *wth, int file_version, int *err, return nstrace_set_start_time_v20(wth, err, err_info); else if (file_version == NSPM_SIGNATURE_3_0) return nstrace_set_start_time_v20(wth, err, err_info); - return FALSE; + return false; } #define __TNDO(rec,enumprefix,structname,hdrname)\ @@ -1126,8 +1127,8 @@ static gboolean nstrace_set_start_time(wtap *wth, int file_version, int *err, do {\ (rec)->presence_flags = WTAP_HAS_TS;\ nsg_creltime += ns_hrtime2nsec(pletoh32(&type->type##_RelTimeHr));\ - (rec)->ts.secs = nstrace->nspm_curtime + (guint32) (nsg_creltime / 1000000000);\ - (rec)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ + (rec)->ts.secs = nstrace->nspm_curtime + (uint32_t) (nsg_creltime / 1000000000);\ + (rec)->ts.nsecs = (uint32_t) (nsg_creltime % 1000000000);\ }while(0) #define PARTSIZEDEFV10(rec,pp,ver) \ @@ -1149,14 +1150,14 @@ static gboolean nstrace_set_start_time(wtap *wth, int file_version, int *err, if ((nstrace_buflen - nstrace_buf_offset) < sizeof(nspr_pktrace##fullpart##_v##ver##_t)) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record header crosses page boundary");\ - return FALSE;\ + return false;\ }\ nspr_pktrace##fullpart##_v##ver##_t *type = (nspr_pktrace##fullpart##_v##ver##_t *) &nstrace_buf[nstrace_buf_offset];\ /* Check sanity of record size */\ if (pletoh16(&type->nsprRecordSize) < sizeof *type) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record size is less than record header size");\ - return FALSE;\ + return false;\ }\ (rec)->rec_type = REC_TYPE_PACKET;\ (rec)->block = wtap_block_create(WTAP_BLOCK_PACKET);\ @@ -1167,7 +1168,7 @@ static gboolean nstrace_set_start_time(wtap *wth, int file_version, int *err, if ((nstrace_buflen - nstrace_buf_offset) < (rec)->rec_header.packet_header.caplen) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record crosses page boundary");\ - return FALSE;\ + return false;\ }\ ws_buffer_assure_space((buf), (rec)->rec_header.packet_header.caplen);\ memcpy(ws_buffer_start_ptr((buf)), type, (rec)->rec_header.packet_header.caplen);\ @@ -1175,24 +1176,24 @@ static gboolean nstrace_set_start_time(wtap *wth, int file_version, int *err, nstrace->nstrace_buf_offset = nstrace_buf_offset + (rec)->rec_header.packet_header.caplen;\ nstrace->nstrace_buflen = nstrace_buflen;\ nstrace->nsg_creltime = nsg_creltime;\ - return TRUE;\ + return true;\ }while(0) -static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { nstrace_t *nstrace = (nstrace_t *)wth->priv; - guint64 nsg_creltime = nstrace->nsg_creltime; - gchar *nstrace_buf = nstrace->pnstrace_buf; - guint32 nstrace_buf_offset = nstrace->nstrace_buf_offset; - guint32 nstrace_buflen = nstrace->nstrace_buflen; + uint64_t nsg_creltime = nstrace->nsg_creltime; + char *nstrace_buf = nstrace->pnstrace_buf; + uint32_t nstrace_buf_offset = nstrace->nstrace_buf_offset; + uint32_t nstrace_buflen = nstrace->nstrace_buflen; *err = 0; *err_info = NULL; do { while ((nstrace_buf_offset < nstrace_buflen) && - ((nstrace_buflen - nstrace_buf_offset) >= ((gint32)sizeof((( nspr_header_v10_t*)&nstrace_buf[nstrace_buf_offset])->ph_RecordType)))) + ((nstrace_buflen - nstrace_buf_offset) >= ((int32_t)sizeof((( nspr_header_v10_t*)&nstrace_buf[nstrace_buf_offset])->ph_RecordType)))) { #define GENERATE_CASE_FULL(rec,buf,ver,HEADERVER) \ @@ -1218,12 +1219,12 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, case NSPR_ABSTIME_V10: { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_pktracefull_v10_t), err, err_info)) - return FALSE; + return false; nspr_pktracefull_v10_t *fp = (nspr_pktracefull_v10_t *) &nstrace_buf[nstrace_buf_offset]; if (pletoh16(&fp->nsprRecordSize) == 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: zero size record found"); - return FALSE; + return false; } ns_setabstime(nstrace, pletoh32(((nspr_abstime_v10_t *) fp)->abs_Time), pletoh32(&((nspr_abstime_v10_t *) fp)->abs_RelTime)); nstrace_buf_offset += pletoh16(&fp->nsprRecordSize); @@ -1233,12 +1234,12 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, case NSPR_RELTIME_V10: { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_pktracefull_v10_t), err, err_info)) - return FALSE; + return false; nspr_pktracefull_v10_t *fp = (nspr_pktracefull_v10_t *) &nstrace_buf[nstrace_buf_offset]; if (pletoh16(&fp->nsprRecordSize) == 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: zero size record found"); - return FALSE; + return false; } ns_setrelativetime(nstrace, pletoh32(((nspr_abstime_v10_t *) fp)->abs_RelTime)); nstrace_buf_offset += pletoh16(&fp->nsprRecordSize); @@ -1252,12 +1253,12 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, default: { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_pktracefull_v10_t), err, err_info)) - return FALSE; + return false; nspr_pktracefull_v10_t *fp = (nspr_pktracefull_v10_t *) &nstrace_buf[nstrace_buf_offset]; if (pletoh16(&fp->nsprRecordSize) == 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: zero size record found"); - return FALSE; + return false; } nstrace_buf_offset += pletoh16(&fp->nsprRecordSize); break; @@ -1270,7 +1271,7 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset)); }while((nstrace_buflen > 0) && (nstrace_read_page(wth, err, err_info))); - return FALSE; + return false; } #undef PACKET_DESCRIBE @@ -1279,8 +1280,8 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, do {\ (rec)->presence_flags = WTAP_HAS_TS;\ nsg_creltime += ns_hrtime2nsec(pletoh32(fp->type##_RelTimeHr));\ - (rec)->ts.secs = nstrace->nspm_curtime + (guint32) (nsg_creltime / 1000000000);\ - (rec)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ + (rec)->ts.secs = nstrace->nspm_curtime + (uint32_t) (nsg_creltime / 1000000000);\ + (rec)->ts.nsecs = (uint32_t) (nsg_creltime % 1000000000);\ }while(0) #define TIMEDEFV23(rec,fp,type) \ @@ -1288,8 +1289,8 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, (rec)->presence_flags = WTAP_HAS_TS;\ /* access _AbsTimeHr as a 64bit value */\ nsg_creltime = pletoh64(fp->type##_AbsTimeHr);\ - (rec)->ts.secs = (guint32) (nsg_creltime / 1000000000);\ - (rec)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ + (rec)->ts.secs = (uint32_t) (nsg_creltime / 1000000000);\ + (rec)->ts.nsecs = (uint32_t) (nsg_creltime % 1000000000);\ }while(0) #define TIMEDEFV21(rec,fp,type) TIMEDEFV20(rec,fp,type) @@ -1336,13 +1337,13 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, if ((nstrace_buflen - nstrace_buf_offset) < sizeof *fp) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record header crosses page boundary");\ - return FALSE;\ + return false;\ }\ /* Check sanity of record size */\ if (nspr_getv20recordsize((nspr_hd_v20_t *)fp) < sizeof *fp) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record size is less than record header size");\ - return FALSE;\ + return false;\ }\ (rec)->rec_type = REC_TYPE_PACKET;\ (rec)->block = wtap_block_create(WTAP_BLOCK_PACKET);\ @@ -1354,7 +1355,7 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, if ((nstrace_buflen - nstrace_buf_offset) < (rec)->rec_header.packet_header.caplen) {\ *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record crosses page boundary");\ - return FALSE;\ + return false;\ }\ ws_buffer_assure_space((buf), (rec)->rec_header.packet_header.caplen);\ memcpy(ws_buffer_start_ptr((buf)), fp, (rec)->rec_header.packet_header.caplen);\ @@ -1362,24 +1363,24 @@ static gboolean nstrace_read_v10(wtap *wth, wtap_rec *rec, Buffer *buf, nstrace->nstrace_buf_offset = nstrace_buf_offset + nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ nstrace->nstrace_buflen = nstrace_buflen;\ nstrace->nsg_creltime = nsg_creltime;\ - return TRUE;\ + return true;\ }while(0) -static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { nstrace_t *nstrace = (nstrace_t *)wth->priv; - guint64 nsg_creltime = nstrace->nsg_creltime; - gchar *nstrace_buf = nstrace->pnstrace_buf; - guint32 nstrace_buf_offset = nstrace->nstrace_buf_offset; - guint32 nstrace_buflen = nstrace->nstrace_buflen; + uint64_t nsg_creltime = nstrace->nsg_creltime; + char *nstrace_buf = nstrace->pnstrace_buf; + uint32_t nstrace_buf_offset = nstrace->nstrace_buf_offset; + uint32_t nstrace_buflen = nstrace->nstrace_buflen; *err = 0; *err_info = NULL; do { while ((nstrace_buf_offset < nstrace_buflen) && - ((nstrace_buflen - nstrace_buf_offset) >= ((gint32)sizeof((( nspr_hd_v20_t*)&nstrace_buf[nstrace_buf_offset])->phd_RecordType)))) + ((nstrace_buflen - nstrace_buf_offset) >= ((int32_t)sizeof((( nspr_hd_v20_t*)&nstrace_buf[nstrace_buf_offset])->phd_RecordType)))) { switch ((( nspr_hd_v20_t*)&nstrace_buf[nstrace_buf_offset])->phd_RecordType) { @@ -1433,18 +1434,18 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, case NSPR_ABSTIME_V20: { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_pktracefull_v20_t), err, err_info)) - return FALSE; + return false; nspr_pktracefull_v20_t *fp20 = (nspr_pktracefull_v20_t *) &nstrace_buf[nstrace_buf_offset]; if (nspr_getv20recordsize((nspr_hd_v20_t *)fp20) == 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: zero size record found"); - return FALSE; + return false; } if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_hd_v20_t), err, err_info)) - return FALSE; + return false; nstrace_buf_offset += nspr_getv20recordsize((nspr_hd_v20_t *)fp20); if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_abstime_v20_t), err, err_info)) - return FALSE; + return false; ns_setabstime(nstrace, pletoh32(&((nspr_abstime_v20_t *) fp20)->abs_Time), pletoh16(&((nspr_abstime_v20_t *) fp20)->abs_RelTime)); break; } @@ -1452,15 +1453,15 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, case NSPR_RELTIME_V20: { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_pktracefull_v20_t), err, err_info)) - return FALSE; + return false; nspr_pktracefull_v20_t *fp20 = (nspr_pktracefull_v20_t *) &nstrace_buf[nstrace_buf_offset]; if (nspr_getv20recordsize((nspr_hd_v20_t *)fp20) == 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: zero size record found"); - return FALSE; + return false; } if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_abstime_v20_t), err, err_info)) - return FALSE; + return false; ns_setrelativetime(nstrace, pletoh16(&((nspr_abstime_v20_t *) fp20)->abs_RelTime)); nstrace_buf_offset += nspr_getv20recordsize((nspr_hd_v20_t *)fp20); break; @@ -1478,12 +1479,12 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, default: { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_pktracefull_v20_t), err, err_info)) - return FALSE; + return false; nspr_pktracefull_v20_t *fp20 = (nspr_pktracefull_v20_t *) &nstrace_buf[nstrace_buf_offset]; if (nspr_getv20recordsize((nspr_hd_v20_t *)fp20) == 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: zero size record found"); - return FALSE; + return false; } nstrace_buf_offset += nspr_getv20recordsize((nspr_hd_v20_t *)fp20); break; @@ -1496,7 +1497,7 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset)); }while((nstrace_buflen > 0) && (nstrace_read_page(wth, err, err_info))); - return FALSE; + return false; } #undef PACKET_DESCRIBE @@ -1511,8 +1512,8 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, (rec)->presence_flags = WTAP_HAS_TS;\ /* access _AbsTimeHr as a 64bit value */\ nsg_creltime = pletoh64(fp->type##_AbsTimeHr);\ - (rec)->ts.secs = (guint32) (nsg_creltime / 1000000000);\ - (rec)->ts.nsecs = (guint32) (nsg_creltime % 1000000000);\ + (rec)->ts.secs = (uint32_t) (nsg_creltime / 1000000000);\ + (rec)->ts.nsecs = (uint32_t) (nsg_creltime % 1000000000);\ }while(0) #define TIMEDEFV35 TIMEDEFV30 @@ -1542,7 +1543,7 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record header crosses page boundary");\ g_free(nstrace_tmpbuff);\ - return FALSE;\ + return false;\ }\ nspr_##structname##_t *fp = (nspr_##structname##_t *) &nstrace_buf[nstrace_buf_offset];\ (rec)->rec_type = REC_TYPE_PACKET;\ @@ -1557,7 +1558,7 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: record size is less than record header size");\ g_free(nstrace_tmpbuff);\ - return FALSE;\ + return false;\ }\ ws_buffer_assure_space((buf), (rec)->rec_header.packet_header.caplen);\ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;\ @@ -1567,13 +1568,13 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE;\ *err_info = g_strdup("nstrace: malformed file");\ g_free(nstrace_tmpbuff);\ - return FALSE;\ + return false;\ }\ nstrace_tmpbuff[nstrace_tmpbuff_off++] = nstrace_buf[nstrace_buf_offset++];\ }\ nst_dataSize = nspr_getv20recordsize(hdp);\ rec_size = nst_dataSize - nstrace_tmpbuff_off;\ - nsg_nextPageOffset = ((nstrace_buf_offset + rec_size) >= (guint)nstrace->nstrace_buflen) ?\ + nsg_nextPageOffset = ((nstrace_buf_offset + rec_size) >= (unsigned)nstrace->nstrace_buflen) ?\ ((nstrace_buf_offset + rec_size) - (NSPR_PAGESIZE_TRACE - 1)) : 0;\ /* Copy record data */\ while (nsg_nextPageOffset) {\ @@ -1587,13 +1588,13 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, bytes_read = file_read(nstrace_buf, NSPR_PAGESIZE_TRACE, wth->fh);\ if ( !file_eof(wth->fh) && bytes_read != NSPR_PAGESIZE_TRACE) {\ g_free(nstrace_tmpbuff);\ - return FALSE;\ + return false;\ } else {\ nstrace_buf_offset = 0;\ }\ nstrace_buflen = bytes_read;\ rec_size = nst_dataSize - nstrace_tmpbuff_off;\ - nsg_nextPageOffset = ((nstrace_buf_offset + rec_size) >= (guint)nstrace->nstrace_buflen) ?\ + nsg_nextPageOffset = ((nstrace_buf_offset + rec_size) >= (unsigned)nstrace->nstrace_buflen) ?\ ((nstrace_buf_offset + rec_size) - (NSPR_PAGESIZE_TRACE- 1)): 0;\ } \ /* Copy the rest of the record */\ @@ -1605,29 +1606,29 @@ static gboolean nstrace_read_v20(wtap *wth, wtap_rec *rec, Buffer *buf, nstrace->nstrace_buflen = nstrace_buflen;\ nstrace->nsg_creltime = nsg_creltime;\ g_free(nstrace_tmpbuff);\ - return TRUE;\ + return true;\ } while(0) -static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { nstrace_t *nstrace = (nstrace_t *)wth->priv; - guint64 nsg_creltime; - gchar *nstrace_buf = nstrace->pnstrace_buf; - guint32 nstrace_buf_offset = nstrace->nstrace_buf_offset; - guint32 nstrace_buflen = nstrace->nstrace_buflen; - guint8* nstrace_tmpbuff; - guint32 nstrace_tmpbuff_off=0,nst_dataSize=0,rec_size=0,nsg_nextPageOffset=0; + uint64_t nsg_creltime; + char *nstrace_buf = nstrace->pnstrace_buf; + uint32_t nstrace_buf_offset = nstrace->nstrace_buf_offset; + uint32_t nstrace_buflen = nstrace->nstrace_buflen; + uint8_t* nstrace_tmpbuff; + uint32_t nstrace_tmpbuff_off=0,nst_dataSize=0,rec_size=0,nsg_nextPageOffset=0; nspr_hd_v20_t *hdp; int bytes_read = 0; *err = 0; *err_info = NULL; if(nstrace_buflen == 0){ - return FALSE; /* Reached End Of File */ + return false; /* Reached End Of File */ } - nstrace_tmpbuff = (guint8*)g_malloc(65536); + nstrace_tmpbuff = (uint8_t*)g_malloc(65536); do { @@ -1636,7 +1637,7 @@ static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: malformed file"); g_free(nstrace_tmpbuff); - return FALSE; + return false; } if (!nstrace_buf[nstrace_buf_offset] && nstrace_buf_offset <= NSPR_PAGESIZE_TRACE){ @@ -1650,14 +1651,14 @@ static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_hd_v20_t), err, err_info)) { g_free(nstrace_tmpbuff); - return FALSE; + return false; } hdp = (nspr_hd_v20_t *) &nstrace_buf[nstrace_buf_offset]; if (nspr_getv20recordsize(hdp) == 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("nstrace: zero size record found"); g_free(nstrace_tmpbuff); - return FALSE; + return false; } switch (hdp->phd_RecordType) { @@ -1688,7 +1689,7 @@ static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, nstrace_buf_offset += nspr_getv20recordsize(hdp); if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_abstime_v20_t), err, err_info)) { g_free(nstrace_tmpbuff); - return FALSE; + return false; } ns_setabstime(nstrace, pletoh32(&((nspr_abstime_v20_t *) &nstrace_buf[nstrace_buf_offset])->abs_Time), pletoh16(&((nspr_abstime_v20_t *) &nstrace_buf[nstrace_buf_offset])->abs_RelTime)); break; @@ -1698,7 +1699,7 @@ static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_abstime_v20_t), err, err_info)) { g_free(nstrace_tmpbuff); - return FALSE; + return false; } ns_setrelativetime(nstrace, pletoh16(&((nspr_abstime_v20_t *) &nstrace_buf[nstrace_buf_offset])->abs_RelTime)); nstrace_buf_offset += nspr_getv20recordsize(hdp); @@ -1709,7 +1710,7 @@ static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, { if (!nstrace_ensure_buflen(nstrace, nstrace_buf_offset, sizeof(nspr_hd_v20_t), err, err_info)) { g_free(nstrace_tmpbuff); - return FALSE; + return false; } nstrace_buf_offset += nspr_getv20recordsize(hdp); break; @@ -1719,14 +1720,14 @@ static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, nstrace_buf_offset = 0; nstrace->xxx_offset += nstrace_buflen; nstrace_buflen = NSPR_PAGESIZE_TRACE; - } while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) > 0 && (file_eof(wth->fh) || (guint32)bytes_read == nstrace_buflen)); + } while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) > 0 && (file_eof(wth->fh) || (uint32_t)bytes_read == nstrace_buflen)); if (bytes_read < 0) *err = file_error(wth->fh, err_info); else *err = 0; g_free(nstrace_tmpbuff); - return FALSE; + return false; } #undef PACKET_DESCRIBE @@ -1752,25 +1753,25 @@ static gboolean nstrace_read_v30(wtap *wth, wtap_rec *rec, Buffer *buf, (rec)->rec_header.packet_header.pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ }while(0) -static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool nstrace_seek_read_v10(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { nspr_hd_v10_t hdr; - guint record_length; - guint8 *pd; + unsigned record_length; + uint8_t *pd; unsigned int bytes_to_read; *err = 0; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* ** Read the record header. */ if (!wtap_read_bytes(wth->random_fh, (void *)&hdr, sizeof hdr, err, err_info)) - return FALSE; + return false; /* ** Get the record length. @@ -1787,7 +1788,7 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, bytes_to_read = (unsigned int)(record_length - sizeof hdr); if (!wtap_read_bytes(wth->random_fh, pd + sizeof hdr, bytes_to_read, err, err_info)) - return FALSE; + return false; } /* @@ -1816,7 +1817,7 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, #undef GENERATE_CASE_FULL #undef GENERATE_CASE_PART - return TRUE; + return true; } #undef PACKET_DESCRIBE @@ -1845,29 +1846,29 @@ static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, FULLPART##SIZEDEFV##ver((rec),fp,ver);\ TRACE_V##ver##_REC_LEN_OFF((rec),enumprefix,type,structname);\ (rec)->rec_header.packet_header.pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ - return TRUE;\ + return true;\ }while(0) -static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool nstrace_seek_read_v20(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { nspr_hd_v20_t hdr; - guint record_length; - guint hdrlen; - guint8 *pd; + unsigned record_length; + unsigned hdrlen; + uint8_t *pd; unsigned int bytes_to_read; - guint64 nsg_creltime; + uint64_t nsg_creltime; *err = 0; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* ** Read the first 2 bytes of the record header. */ if (!wtap_read_bytes(wth->random_fh, (void *)&hdr, 2, err, err_info)) - return FALSE; + return false; hdrlen = 2; /* @@ -1876,7 +1877,7 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, if (hdr.phd_RecordSizeLow & NSPR_V20RECORDSIZE_2BYTES) { if (!wtap_read_bytes(wth->random_fh, (void *)&hdr.phd_RecordSizeHigh, 1, err, err_info)) - return FALSE; + return false; hdrlen = 3; } @@ -1895,7 +1896,7 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, bytes_to_read = (unsigned int)(record_length - hdrlen); if (!wtap_read_bytes(wth->random_fh, pd + hdrlen, bytes_to_read, err, err_info)) - return FALSE; + return false; } #define GENERATE_CASE_FULL(rec,ver,HEADERVER) \ @@ -1947,7 +1948,7 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, #undef GENERATE_CASE_PART #undef GENERATE_CASE_PART_V25 - return TRUE; + return true; } #undef PACKET_DESCRIBE @@ -1971,28 +1972,28 @@ static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, FULLPART##SIZEDEFV##ver((rec),fp,ver);\ TRACE_V##ver##_REC_LEN_OFF((rec),enumprefix,type,structname);\ (rec)->rec_header.packet_header.pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##HEADERVER;\ - return TRUE;\ + return true;\ }while(0) -static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool nstrace_seek_read_v30(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { nspr_hd_v20_t hdr; - guint record_length; - guint hdrlen; - guint8 *pd; + unsigned record_length; + unsigned hdrlen; + uint8_t *pd; unsigned int bytes_to_read; - guint64 nsg_creltime; + uint64_t nsg_creltime; *err = 0; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* ** Read the first 2 bytes of the record header. */ if (!wtap_read_bytes(wth->random_fh, (void *)&hdr, 2, err, err_info)) - return FALSE; + return false; hdrlen = 2; /* @@ -2001,7 +2002,7 @@ static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, if (hdr.phd_RecordSizeLow & NSPR_V20RECORDSIZE_2BYTES) { if (!wtap_read_bytes(wth->random_fh, (void *)&hdr.phd_RecordSizeHigh, 1, err, err_info)) - return FALSE; + return false; hdrlen = 3; } @@ -2022,7 +2023,7 @@ static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, bytes_to_read = (unsigned int)(record_length - hdrlen); if (!wtap_read_bytes(wth->random_fh, pd + hdrlen, bytes_to_read, err, err_info)) - return FALSE; + return false; } (rec)->rec_header.packet_header.caplen = (rec)->rec_header.packet_header.len = record_length; @@ -2040,7 +2041,7 @@ static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, GENERATE_CASE_V30(rec,35, 350); } - return TRUE; + return true; } @@ -2061,11 +2062,11 @@ static void nstrace_close(wtap *wth) #define NSTRACE_3_5 3 typedef struct { - guint version; - guint16 page_offset; - guint16 page_len; - guint32 absrec_time; - gboolean newfile; + unsigned version; + uint16_t page_offset; + uint16_t page_len; + uint32_t absrec_time; + bool newfile; } nstrace_dump_t; /* Returns 0 if we could write the specified encapsulation type, @@ -2109,10 +2110,10 @@ static int nstrace_35_dump_can_write_encap(int encap) return WTAP_ERR_UNWRITABLE_ENCAP; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on ** failure */ -static gboolean nstrace_dump_open(wtap_dumper *wdh, guint version, int *err _U_, - gchar **err_info _U_) +static bool nstrace_dump_open(wtap_dumper *wdh, unsigned version, int *err _U_, + char **err_info _U_) { nstrace_dump_t *nstrace; @@ -2129,42 +2130,42 @@ static gboolean nstrace_dump_open(wtap_dumper *wdh, guint version, int *err _U_, nstrace->page_len = NSPR_PAGESIZE; nstrace->absrec_time = 0; - nstrace->newfile = TRUE; + nstrace->newfile = true; - return TRUE; + return true; } -static gboolean nstrace_10_dump_open(wtap_dumper *wdh, int *err, - gchar **err_info) +static bool nstrace_10_dump_open(wtap_dumper *wdh, int *err, + char **err_info) { return nstrace_dump_open(wdh, NSTRACE_1_0, err, err_info); } -static gboolean nstrace_20_dump_open(wtap_dumper *wdh, int *err, - gchar **err_info) +static bool nstrace_20_dump_open(wtap_dumper *wdh, int *err, + char **err_info) { return nstrace_dump_open(wdh, NSTRACE_2_0, err, err_info); } -static gboolean nstrace_30_dump_open(wtap_dumper *wdh, int *err, - gchar **err_info) +static bool nstrace_30_dump_open(wtap_dumper *wdh, int *err, + char **err_info) { return nstrace_dump_open(wdh, NSTRACE_3_0, err, err_info); } -static gboolean nstrace_35_dump_open(wtap_dumper *wdh, int *err, - gchar **err_info) +static bool nstrace_35_dump_open(wtap_dumper *wdh, int *err, + char **err_info) { return nstrace_dump_open(wdh, NSTRACE_3_5, err, err_info); } -static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err) +static bool nstrace_add_signature(wtap_dumper *wdh, int *err) { nstrace_dump_t *nstrace = (nstrace_dump_t *)wdh->priv; if (nstrace->version == NSTRACE_1_0) { - guint16 val16b; + uint16_t val16b; nspr_signature_v10_t sig10; /* populate the record */ @@ -2178,10 +2179,10 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err) /* Write the record into the file */ if (!wtap_dump_file_write(wdh, &sig10, nspr_signature_v10_s, err)) - return FALSE; + return false; /* Move forward the page offset */ - nstrace->page_offset += (guint16) nspr_signature_v10_s; + nstrace->page_offset += (uint16_t) nspr_signature_v10_s; } else if (nstrace->version == NSTRACE_2_0) { @@ -2194,10 +2195,10 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err) /* Write the record into the file */ if (!wtap_dump_file_write(wdh, &sig20, sig20.sig_RecordSize, err)) - return FALSE; + return false; /* Move forward the page offset */ - nstrace->page_offset += (guint16) sig20.sig_RecordSize; + nstrace->page_offset += (uint16_t) sig20.sig_RecordSize; } else if (nstrace->version == NSTRACE_3_0) { @@ -2210,10 +2211,10 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err) /* Write the record into the file */ if (!wtap_dump_file_write(wdh, &sig30, sig30.sig_RecordSize, err)) - return FALSE; + return false; /* Move forward the page offset */ - nstrace->page_offset += (guint16) sig30.sig_RecordSize; + nstrace->page_offset += (uint16_t) sig30.sig_RecordSize; } else if (nstrace->version == NSTRACE_3_5) { nspr_signature_v35_t sig35; @@ -2225,32 +2226,32 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err) /* Write the record into the file */ if (!wtap_dump_file_write(wdh, &sig35, sig35.sig_RecordSize, err)) - return FALSE; + return false; /* Move forward the page offset */ - nstrace->page_offset += (guint16) sig35.sig_RecordSize; + nstrace->page_offset += (uint16_t) sig35.sig_RecordSize; } else { ws_assert_not_reached(); - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool nstrace_add_abstime(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err) + const uint8_t *pd, int *err) { nstrace_dump_t *nstrace = (nstrace_dump_t *)wdh->priv; - guint64 nsg_creltime; + uint64_t nsg_creltime; if (nstrace->version == NSTRACE_1_0) { - guint16 val16; - guint32 reltime; - guint64 abstime; + uint16_t val16; + uint32_t reltime; + uint64_t abstime; nspr_abstime_v10_t abs10; /* populate the record */ @@ -2263,12 +2264,12 @@ nstrace_add_abstime(wtap_dumper *wdh, const wtap_rec *rec, nsg_creltime = ns_hrtime2nsec(reltime); memset(abs10.abs_RelTime, 0, sizeof abs10.abs_RelTime); - abstime = GUINT32_TO_LE((guint32)rec->ts.secs - (guint32)(nsg_creltime/1000000000)); + abstime = GUINT32_TO_LE((uint32_t)rec->ts.secs - (uint32_t)(nsg_creltime/1000000000)); memcpy(abs10.abs_Time, &abstime, sizeof abs10.abs_Time); /* Write the record into the file */ if (!wtap_dump_file_write(wdh, &abs10, nspr_abstime_v10_s, err)) - return FALSE; + return false; /* Move forward the page offset */ nstrace->page_offset += nspr_abstime_v10_s; @@ -2276,8 +2277,8 @@ nstrace_add_abstime(wtap_dumper *wdh, const wtap_rec *rec, } else if ((nstrace->version == NSTRACE_2_0) || (nstrace->version == NSTRACE_3_0) || (nstrace->version == NSTRACE_3_5)) { - guint32 reltime; - guint64 abstime; + uint32_t reltime; + uint64_t abstime; nspr_abstime_v20_t abs20; abs20.abs_RecordType = NSPR_ABSTIME_V20; @@ -2287,12 +2288,12 @@ nstrace_add_abstime(wtap_dumper *wdh, const wtap_rec *rec, nsg_creltime = ns_hrtime2nsec(reltime); memset(abs20.abs_RelTime, 0, sizeof abs20.abs_RelTime); - abstime = GUINT32_TO_LE((guint32)rec->ts.secs - (guint32)(nsg_creltime/1000000000)); + abstime = GUINT32_TO_LE((uint32_t)rec->ts.secs - (uint32_t)(nsg_creltime/1000000000)); memcpy(abs20.abs_RelTime, &abstime, sizeof abs20.abs_RelTime); /* Write the record into the file */ if (!wtap_dump_file_write(wdh, &abs20, nspr_abstime_v20_s, err)) - return FALSE; + return false; /* Move forward the page offset */ nstrace->page_offset += nspr_abstime_v20_s; @@ -2300,24 +2301,24 @@ nstrace_add_abstime(wtap_dumper *wdh, const wtap_rec *rec, } else { ws_assert_not_reached(); - return FALSE; + return false; } - return TRUE; + return true; } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info _U_) { nstrace_dump_t *nstrace = (nstrace_dump_t *)wdh->priv; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -2326,33 +2327,33 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } - if (nstrace->newfile == TRUE) + if (nstrace->newfile == true) { - nstrace->newfile = FALSE; + nstrace->newfile = false; /* Add the signature record and abs time record */ if (nstrace->version == NSTRACE_1_0) { if (!nstrace_add_signature(wdh, err) || !nstrace_add_abstime(wdh, rec, pd, err)) - return FALSE; + return false; } else if (nstrace->version == NSTRACE_2_0) { if (!nstrace_add_signature(wdh, err) || !nstrace_add_abstime(wdh, rec, pd, err)) - return FALSE; + return false; } else if (nstrace->version == NSTRACE_3_0 || nstrace->version == NSTRACE_3_5 ) { if (!nstrace_add_signature(wdh, err) || !nstrace_add_abstime(wdh, rec, pd, err)) - return FALSE; + return false; } else { ws_assert_not_reached(); - return FALSE; + return false; } } @@ -2366,24 +2367,24 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, { /* Start on the next page */ if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1) - return FALSE; + return false; nstrace->page_offset = 0; /* Possibly add signature and abstime records and increment offset */ if (!nstrace_add_signature(wdh, err)) - return FALSE; + return false; } /* Write the actual record as is */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; - nstrace->page_offset += (guint16) rec->rec_header.packet_header.caplen; + nstrace->page_offset += (uint16_t) rec->rec_header.packet_header.caplen; } else if (nstrace->version == NSTRACE_2_0) { *err = WTAP_ERR_UNWRITABLE_FILE_TYPE; - return FALSE; + return false; } break; @@ -2398,27 +2399,27 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, if (nstrace->version == NSTRACE_1_0) { *err = WTAP_ERR_UNWRITABLE_FILE_TYPE; - return FALSE; + return false; } else if (nstrace->version == NSTRACE_2_0) { if (nstrace->page_offset + rec->rec_header.packet_header.caplen >= nstrace->page_len) { /* Start on the next page */ if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1) - return FALSE; + return false; nstrace->page_offset = 0; /* Possibly add signature and abstime records and increment offset */ if (!nstrace_add_signature(wdh, err)) - return FALSE; + return false; } /* Write the actual record as is */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; - nstrace->page_offset += (guint16) rec->rec_header.packet_header.caplen; + nstrace->page_offset += (uint16_t) rec->rec_header.packet_header.caplen; } break; @@ -2428,44 +2429,44 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec, if (nstrace->version == NSTRACE_1_0) { *err = WTAP_ERR_UNWRITABLE_FILE_TYPE; - return FALSE; + return false; } else if (nstrace->version == NSTRACE_2_0) { *err = WTAP_ERR_UNWRITABLE_FILE_TYPE; - return FALSE; + return false; } else if (nstrace->version == NSTRACE_3_0 || nstrace->version == NSTRACE_3_5) { if (nstrace->page_offset + rec->rec_header.packet_header.caplen >= nstrace->page_len) { /* Start on the next page */ if (wtap_dump_file_seek(wdh, (nstrace->page_len - nstrace->page_offset), SEEK_CUR, err) == -1) - return FALSE; + return false; nstrace->page_offset = 0; /* Possibly add signature and abstime records and increment offset */ if (!nstrace_add_signature(wdh, err)) - return FALSE; + return false; } /* Write the actual record as is */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; - nstrace->page_offset += (guint16) rec->rec_header.packet_header.caplen; + nstrace->page_offset += (uint16_t) rec->rec_header.packet_header.caplen; } else { ws_assert_not_reached(); - return FALSE; + return false; } break; default: ws_assert_not_reached(); - return FALSE; + return false; } - return TRUE; + return true; } static const struct supported_block_type nstrace_1_0_blocks_supported[] = { @@ -2477,7 +2478,7 @@ static const struct supported_block_type nstrace_1_0_blocks_supported[] = { static const struct file_type_subtype_info nstrace_1_0_info = { "NetScaler Trace (Version 1.0)", "nstrace10", NULL, NULL, - TRUE, BLOCKS_SUPPORTED(nstrace_1_0_blocks_supported), + true, BLOCKS_SUPPORTED(nstrace_1_0_blocks_supported), nstrace_10_dump_can_write_encap, nstrace_10_dump_open, NULL }; @@ -2490,7 +2491,7 @@ static const struct supported_block_type nstrace_2_0_blocks_supported[] = { static const struct file_type_subtype_info nstrace_2_0_info = { "NetScaler Trace (Version 2.0)", "nstrace20", "cap", NULL, - TRUE, BLOCKS_SUPPORTED(nstrace_2_0_blocks_supported), + true, BLOCKS_SUPPORTED(nstrace_2_0_blocks_supported), nstrace_20_dump_can_write_encap, nstrace_20_dump_open, NULL }; @@ -2503,7 +2504,7 @@ static const struct supported_block_type nstrace_3_0_blocks_supported[] = { static const struct file_type_subtype_info nstrace_3_0_info = { "NetScaler Trace (Version 3.0)", "nstrace30", "cap", NULL, - TRUE, BLOCKS_SUPPORTED(nstrace_3_0_blocks_supported), + true, BLOCKS_SUPPORTED(nstrace_3_0_blocks_supported), nstrace_30_dump_can_write_encap, nstrace_30_dump_open, NULL }; @@ -2516,7 +2517,7 @@ static const struct supported_block_type nstrace_3_5_blocks_supported[] = { static const struct file_type_subtype_info nstrace_3_5_info = { "NetScaler Trace (Version 3.5)", "nstrace35", "cap", NULL, - TRUE, BLOCKS_SUPPORTED(nstrace_3_5_blocks_supported), + true, BLOCKS_SUPPORTED(nstrace_3_5_blocks_supported), nstrace_35_dump_can_write_encap, nstrace_35_dump_open, NULL }; diff --git a/wiretap/netscaler.h b/wiretap/netscaler.h index a992bf8a..95678217 100644 --- a/wiretap/netscaler.h +++ b/wiretap/netscaler.h @@ -107,6 +107,6 @@ #define NSPR_HEADER_VERSION300 0x30 #define NSPR_HEADER_VERSION350 0x35 -wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val nstrace_open(wtap *wth, int *err, char **err_info); #endif /* _NETSCALER_H */ diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c index dc8f964b..baab6e97 100644 --- a/wiretap/netscreen.c +++ b/wiretap/netscreen.c @@ -11,8 +11,8 @@ */ #include "config.h" -#include "wtap-int.h" #include "netscreen.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <stdlib.h> @@ -29,13 +29,13 @@ * the frame-structure, a pseudo-header or use PPI." See the * message at * - * https://www.wireshark.org/lists/wireshark-dev/200708/msg00029.html + * https://lists.wireshark.org/archives/wireshark-dev/200708/msg00029.html * * to see whether any further discussion is still needed. I suspect * it doesn't; pcapng existed at the time, as per the final * message in that thread: * - * https://www.wireshark.org/lists/wireshark-dev/200708/msg00039.html + * https://lists.wireshark.org/archives/wireshark-dev/200708/msg00039.html * * but I don't think we fully *supported* it at that point. Now * that we do, we have the infrastructure to support this, except @@ -47,19 +47,19 @@ * pcapng captures. */ -static gboolean info_line(const gchar *line); -static gint64 netscreen_seek_next_packet(wtap *wth, int *err, gchar **err_info, +static bool info_line(const char *line); +static int64_t netscreen_seek_next_packet(wtap *wth, int *err, char **err_info, char *hdr); -static gboolean netscreen_check_file_type(wtap *wth, int *err, - gchar **err_info); -static gboolean netscreen_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean netscreen_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean parse_netscreen_packet(FILE_T fh, wtap_rec *rec, - Buffer* buf, char *line, int *err, gchar **err_info); -static int parse_single_hex_dump_line(char* rec, guint8 *buf, - guint byte_offset, guint pkt_len); +static bool netscreen_check_file_type(wtap *wth, int *err, + char **err_info); +static bool netscreen_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool netscreen_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool parse_netscreen_packet(FILE_T fh, wtap_rec *rec, + Buffer* buf, char *line, int *err, char **err_info); +static int parse_single_hex_dump_line(char* rec, uint8_t *buf, + unsigned byte_offset, unsigned pkt_len); /* Error returns from parse_single_hex_dump_line() */ #define PARSE_LINE_INVALID_CHARACTER -1 @@ -70,9 +70,9 @@ static int netscreen_file_type_subtype = -1; void register_netscreen(void); -/* Returns TRUE if the line appears to be a line with protocol info. - Otherwise it returns FALSE. */ -static gboolean info_line(const gchar *line) +/* Returns true if the line appears to be a line with protocol info. + Otherwise it returns false. */ +static bool info_line(const char *line) { int i=NETSCREEN_SPACES_ON_INFO_LINE; @@ -81,20 +81,20 @@ static gboolean info_line(const gchar *line) line++; continue; } else { - return FALSE; + return false; } } - return TRUE; + return true; } /* Seeks to the beginning of the next packet, and returns the byte offset. Copy the header line to hdr. Returns -1 on failure, and sets "*err" to the error and sets "*err_info" to null or an additional error string. */ -static gint64 netscreen_seek_next_packet(wtap *wth, int *err, gchar **err_info, +static int64_t netscreen_seek_next_packet(wtap *wth, int *err, char **err_info, char *hdr) { - gint64 cur_off; + int64_t cur_off; char buf[NETSCREEN_LINE_LENGTH]; while (1) { @@ -121,14 +121,14 @@ static gint64 netscreen_seek_next_packet(wtap *wth, int *err, gchar **err_info, /* Look through the first part of a file to see if this is * NetScreen snoop output. * - * 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" is set to null or an additional error string. */ -static gboolean netscreen_check_file_type(wtap *wth, int *err, gchar **err_info) +static bool netscreen_check_file_type(wtap *wth, int *err, char **err_info) { char buf[NETSCREEN_LINE_LENGTH]; - guint reclen, line; + unsigned reclen, line; buf[NETSCREEN_LINE_LENGTH-1] = '\0'; @@ -136,25 +136,25 @@ static gboolean netscreen_check_file_type(wtap *wth, int *err, gchar **err_info) if (file_gets(buf, NETSCREEN_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 < MIN(strlen(NETSCREEN_HDR_MAGIC_STR1), strlen(NETSCREEN_HDR_MAGIC_STR2))) { continue; } if (strstr(buf, NETSCREEN_HDR_MAGIC_STR1) || strstr(buf, NETSCREEN_HDR_MAGIC_STR2)) { - return TRUE; + return true; } } *err = 0; - return FALSE; + return false; } -wtap_open_return_val netscreen_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val netscreen_open(wtap *wth, int *err, char **err_info) { /* Look for a NetScreen snoop header line */ @@ -178,20 +178,20 @@ wtap_open_return_val netscreen_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean netscreen_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool netscreen_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { - gint64 offset; + int64_t offset; char line[NETSCREEN_LINE_LENGTH]; /* Find the next packet */ offset = netscreen_seek_next_packet(wth, err, err_info, line); if (offset < 0) - return FALSE; + return false; /* Parse the header and convert the ASCII hex dump to binary data */ if (!parse_netscreen_packet(wth->fh, rec, buf, line, err, err_info)) - return FALSE; + return false; /* * If the per-file encapsulation isn't known, set it to this @@ -209,18 +209,18 @@ static gboolean netscreen_read(wtap *wth, wtap_rec *rec, Buffer *buf, } *data_offset = offset; - return TRUE; + return true; } /* Used to read packets in random-access fashion */ -static gboolean -netscreen_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +static bool +netscreen_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { char line[NETSCREEN_LINE_LENGTH]; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return FALSE; + return false; } if (file_gets(line, NETSCREEN_LINE_LENGTH, wth->random_fh) == NULL) { @@ -228,7 +228,7 @@ netscreen_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } return parse_netscreen_packet(wth->random_fh, rec, buf, line, @@ -279,22 +279,22 @@ netscreen_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, * Following that is a hex/ASCII dump of the contents of the * packet, with 16 octets per line. */ -static gboolean +static bool parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, - char *line, int *err, gchar **err_info) + char *line, int *err, char **err_info) { - guint pkt_len; + unsigned pkt_len; int sec; int dsec; char cap_int[NETSCREEN_MAX_INT_NAME_LENGTH]; char direction[2]; char cap_src[13]; char cap_dst[13]; - guint8 *pd; - gchar *p; + uint8_t *pd; + char *p; int n, i = 0; int offset = 0; - gchar dststr[13]; + char dststr[13]; rec->rec_type = REC_TYPE_PACKET; rec->block = wtap_block_create(WTAP_BLOCK_PACKET); @@ -317,7 +317,7 @@ parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("netscreen: File has %u-byte packet, bigger than maximum of %u", pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } /* @@ -381,7 +381,7 @@ parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, if (n >= 0) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("netscreen: first line of packet data has only %d hex bytes, < 6"); - return FALSE; + return false; } /* Otherwise, fall through to report error */ } @@ -414,7 +414,7 @@ parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, break; } - return FALSE; + return false; } /* Adjust the offset to the data that was just added to the buffer */ @@ -450,7 +450,7 @@ parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, rec->rec_header.packet_header.caplen = offset; - return TRUE; + return true; } /* Take a string representing one line from a hex dump, with leading white @@ -459,11 +459,11 @@ parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf, * * Returns number of bytes successfully read, -1 if bad. */ static int -parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset, guint pkt_len) +parse_single_hex_dump_line(char* rec, uint8_t *buf, unsigned byte_offset, unsigned pkt_len) { int num_items_scanned; - guint8 character; - guint8 byte; + uint8_t character; + uint8_t byte; for (num_items_scanned = 0; num_items_scanned < 16; num_items_scanned++) { @@ -523,7 +523,7 @@ static const struct supported_block_type netscreen_blocks_supported[] = { static const struct file_type_subtype_info netscreen_info = { "NetScreen snoop text file", "netscreen", "txt", NULL, - FALSE, BLOCKS_SUPPORTED(netscreen_blocks_supported), + false, BLOCKS_SUPPORTED(netscreen_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/netscreen.h b/wiretap/netscreen.h index 6ea391c8..bfa37833 100644 --- a/wiretap/netscreen.h +++ b/wiretap/netscreen.h @@ -31,9 +31,9 @@ #define NETSCREEN_SPACES_ON_INFO_LINE 14 #define NETSCREEN_MAX_INT_NAME_LENGTH 16 -#define NETSCREEN_INGRESS FALSE -#define NETSCREEN_EGRESS TRUE +#define NETSCREEN_INGRESS false +#define NETSCREEN_EGRESS true -wtap_open_return_val netscreen_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val netscreen_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/nettl.c b/wiretap/nettl.c index 2a462710..8f07cefd 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -10,12 +10,12 @@ */ #include "config.h" +#include "nettl.h" #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "nettl.h" /* HP nettl file header */ @@ -23,11 +23,11 @@ #define MAGIC_SIZE 12 /* HP-UX 9.x */ -static const guint8 nettl_magic_hpux9[MAGIC_SIZE] = { +static const uint8_t nettl_magic_hpux9[MAGIC_SIZE] = { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x00 }; /* HP-UX 10.x and 11.x */ -static const guint8 nettl_magic_hpux10[MAGIC_SIZE] = { +static const uint8_t nettl_magic_hpux10[MAGIC_SIZE] = { 0x54, 0x52, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }; @@ -35,33 +35,33 @@ static const guint8 nettl_magic_hpux10[MAGIC_SIZE] = { #define NETTL_FILENAME_SIZE 56 struct nettl_file_hdr { - guint8 magic[MAGIC_SIZE]; - gchar file_name[NETTL_FILENAME_SIZE]; - gchar tz[20]; - gchar host_name[9]; - gchar os_vers[9]; - guint8 os_v; - guint8 xxa[8]; - gchar model[11]; - guint16 unknown; /* just padding to 128 bytes? */ + uint8_t magic[MAGIC_SIZE]; + char file_name[NETTL_FILENAME_SIZE]; + char tz[20]; + char host_name[9]; + char os_vers[9]; + uint8_t os_v; + uint8_t xxa[8]; + char model[11]; + uint16_t unknown; /* just padding to 128 bytes? */ }; /* HP nettl record header */ /* see /usr/include/sys/netdiag1.h for hints */ struct nettlrec_hdr { - guint16 hdr_len; - guint16 subsys; - guint32 devid; - guint8 xxa[4]; - guint32 kind; - guint8 xxb[16]; - guint32 caplen; - guint32 length; - guint32 sec; - guint32 usec; - guint32 pid; - guint8 xxc[8]; - guint32 uid; + uint16_t hdr_len; + uint16_t subsys; + uint32_t devid; + uint8_t xxa[4]; + uint32_t kind; + uint8_t xxb[16]; + uint32_t caplen; + uint32_t length; + uint32_t sec; + uint32_t usec; + uint32_t pid; + uint8_t xxc[8]; + uint32_t uid; /* Other stuff might be here, but isn't always here */ }; @@ -75,15 +75,15 @@ struct nettlrec_hdr { /* HP nettl record header for the SX25L2 subsystem - The FCS is not included in the file. */ struct nettlrec_sx25l2_hdr { - guint8 xxa[8]; - guint8 from_dce; - guint8 xxb[55]; - guint8 caplen[2]; - guint8 length[2]; - guint8 xxc[4]; - guint8 sec[4]; - guint8 usec[4]; - guint8 xxd[4]; + uint8_t xxa[8]; + uint8_t from_dce; + uint8_t xxb[55]; + uint8_t caplen[2]; + uint8_t length[2]; + uint8_t xxc[4]; + uint8_t sec[4]; + uint8_t usec[4]; + uint8_t xxd[4]; }; /* NL_LS_DRIVER : @@ -140,13 +140,13 @@ For now, the subheader for 100baseT seems to be 20-21 unknown */ struct nettlrec_ns_ls_drv_eth_hdr { - guint8 xxa[4]; - guint8 caplen[2]; - guint8 length[2]; - guint8 xxb[4]; - guint8 sec[4]; - guint8 usec[4]; - guint8 xxc[2]; + uint8_t xxa[4]; + uint8_t caplen[2]; + uint8_t length[2]; + uint8_t xxb[4]; + uint8_t sec[4]; + uint8_t usec[4]; + uint8_t xxc[2]; }; /* @@ -159,27 +159,27 @@ struct nettlrec_ns_ls_drv_eth_hdr { /* header is followed by data and once again the total length (2 bytes) ! */ typedef struct { - gboolean is_hpux_11; + bool is_hpux_11; } nettl_t; -static gboolean nettl_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean nettl_seek_read(wtap *wth, gint64 seek_off, +static bool nettl_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool nettl_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); -static gboolean nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); -static gboolean nettl_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); + int *err, char **err_info); +static bool nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info); +static bool nettl_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); static int nettl_file_type_subtype = -1; void register_nettl(void); -wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val nettl_open(wtap *wth, int *err, char **err_info) { struct nettl_file_hdr file_hdr; - guint16 dummy[2]; + uint16_t dummy[2]; int subsys; nettl_t *nettl; @@ -207,9 +207,9 @@ wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info) nettl = g_new(nettl_t,1); wth->priv = (void *)nettl; if (file_hdr.os_vers[2] == '1' && file_hdr.os_vers[3] == '1') - nettl->is_hpux_11 = TRUE; + nettl->is_hpux_11 = true; else - nettl->is_hpux_11 = FALSE; + nettl->is_hpux_11 = false; wth->subtype_read = nettl_read; wth->subtype_seek_read = nettl_seek_read; wth->snapshot_length = 0; /* not available */ @@ -265,14 +265,14 @@ wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean nettl_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool nettl_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { /* Read record. */ *data_offset = file_tell(wth->fh); if (!nettl_read_rec(wth, wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } /* @@ -290,15 +290,15 @@ static gboolean nettl_read(wtap *wth, wtap_rec *rec, Buffer *buf, wth->file_encap = WTAP_ENCAP_PER_PACKET; } - return TRUE; + return true; } -static gboolean -nettl_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +nettl_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read record. */ if (!nettl_read_rec(wth, wth->random_fh, rec, buf, err, err_info)) { @@ -307,47 +307,47 @@ nettl_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, /* EOF means "short read" in random-access mode */ *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool nettl_read_rec(wtap *wth, 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; nettl_t *nettl = (nettl_t *)wth->priv; - gboolean fddihack = FALSE; + bool fddihack = false; struct nettlrec_hdr rec_hdr; - guint16 hdr_len; + uint16_t hdr_len; struct nettlrec_ns_ls_drv_eth_hdr drv_eth_hdr; - guint32 length, caplen; + uint32_t length, caplen; int subsys; - guint padlen; + unsigned padlen; int datalen; - guint8 dummyc[16]; + uint8_t dummyc[16]; int bytes_to_read; - guint8 *pd; + uint8_t *pd; if (!wtap_read_bytes_or_eof(fh, &rec_hdr.hdr_len, sizeof rec_hdr.hdr_len, err, err_info)) - return FALSE; + return false; hdr_len = g_ntohs(rec_hdr.hdr_len); if (hdr_len < NETTL_REC_HDR_LEN) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettl: record header length %u too short", hdr_len); - return FALSE; + return false; } if (!wtap_read_bytes(fh, &rec_hdr.subsys, NETTL_REC_HDR_LEN - 2, err, err_info)) - return FALSE; + return false; subsys = g_ntohs(rec_hdr.subsys); hdr_len -= NETTL_REC_HDR_LEN; /* Skip the rest of the header. */ if (!wtap_read_bytes(fh, NULL, hdr_len, err, err_info)) - return FALSE; + return false; if ( (pntoh32(&rec_hdr.kind) & NETTL_HDR_PDU_MASK) == 0 ) { /* not actually a data packet (PDU) trace record */ @@ -427,16 +427,16 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, there are an extra 3 bytes after the DSAP and SSAP for SNAP frames ??? */ - fddihack=TRUE; + fddihack=true; padlen = 0; } else { /* outbound appears to have variable padding */ if (!wtap_read_bytes(fh, dummyc, 9, err, err_info)) - return FALSE; + return false; /* padding is usually either a total 11 or 16 bytes??? */ padlen = (int)dummyc[8]; if (!wtap_read_bytes(fh, NULL, padlen, err, err_info)) - return FALSE; + return false; padlen += 9; } } else if ( (subsys == NETTL_SUBSYS_PCI_FDDI) @@ -444,12 +444,12 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, || (subsys == NETTL_SUBSYS_HSC_FDDI) ) { /* other flavor FDDI cards have an extra 3 bytes of padding */ if (!wtap_read_bytes(fh, NULL, 3, err, err_info)) - return FALSE; + return false; padlen = 3; } else if (subsys == NETTL_SUBSYS_NS_LS_LOOPBACK) { /* LOOPBACK has an extra 26 bytes of padding */ if (!wtap_read_bytes(fh, NULL, 26, err, err_info)) - return FALSE; + return false; padlen = 26; } else if (subsys == NETTL_SUBSYS_NS_LS_SCTP) { /* @@ -463,7 +463,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, * 2 = Outbound */ if (!wtap_read_bytes(fh, NULL, 8, err, err_info)) - return FALSE; + return false; padlen = 8; } else { padlen = 0; @@ -477,7 +477,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_NETTL_ETHERNET; if (!wtap_read_bytes(fh, &drv_eth_hdr, NS_LS_DRV_ETH_HDR_LEN, err, err_info)) - return FALSE; + return false; length = pntoh16(&drv_eth_hdr.length); caplen = pntoh16(&drv_eth_hdr.caplen); @@ -490,7 +490,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, */ if (nettl->is_hpux_11) { if (!wtap_read_bytes(fh, NULL, 2, err, err_info)) - return FALSE; + return false; } padlen = 0; break; @@ -502,12 +502,12 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, * packet lengths, time stamps, etc., just as is the case * for NETTL_SUBSYS_NS_LS_DRIVER? It might be * - * guint8 caplen[2]; - * guint8 length[2]; - * guint8 xxc[4]; - * guint8 sec[4]; - * guint8 usec[4]; - * guint8 xxd[4]; + * uint8_t caplen[2]; + * uint8_t length[2]; + * uint8_t xxc[4]; + * uint8_t sec[4]; + * uint8_t usec[4]; + * uint8_t xxd[4]; * * or something such as that - if it has 4 bytes before that * (making it 24 bytes), it'd be like struct @@ -520,7 +520,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, caplen = pntoh32(&rec_hdr.caplen); padlen = 24; /* sizeof (struct nettlrec_sx25l2_hdr) - NETTL_REC_HDR_LEN + 4 */ if (!wtap_read_bytes(fh, NULL, padlen, err, err_info)) - return FALSE; + return false; break; default: @@ -538,7 +538,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettl: packet length %u in record header too short, less than %u", length, padlen); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; rec->block = wtap_block_create(WTAP_BLOCK_PACKET); @@ -548,7 +548,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettl: captured length %u in record header too short, less than %u", caplen, padlen); - return FALSE; + return false; } datalen = caplen - padlen; rec->rec_header.packet_header.caplen = datalen; @@ -569,7 +569,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettl: File has %u-byte packet, bigger than maximum of %u", rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } /* @@ -583,11 +583,11 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, if (bytes_to_read > datalen) bytes_to_read = datalen; if (!wtap_read_bytes(fh, pd, bytes_to_read, err, err_info)) - return FALSE; + return false; datalen -= bytes_to_read; if (datalen == 0) { /* There's nothing past the FC, dest, src, DSAP and SSAP */ - return TRUE; + return true; } if (pd[13] == 0xAA) { /* it's SNAP, have to eat 3 bytes??? */ @@ -595,21 +595,21 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, if (bytes_to_read > datalen) bytes_to_read = datalen; if (!wtap_read_bytes(fh, NULL, bytes_to_read, err, err_info)) - return FALSE; + return false; datalen -= bytes_to_read; if (datalen == 0) { /* There's nothing past the FC, dest, src, DSAP, SSAP, and 3 bytes to eat */ - return TRUE; + return true; } } if (!wtap_read_bytes(fh, pd + 15, datalen, err, err_info)) - return FALSE; + return false; } else { if (!wtap_read_bytes(fh, pd, datalen, err, err_info)) - return FALSE; + return false; } - return TRUE; + return true; } /* Returns 0 if we could write the specified encapsulation type, @@ -644,9 +644,9 @@ static int nettl_dump_can_write_encap(int encap) } -/* Returns TRUE on success, FALSE on failure; +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean nettl_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool nettl_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { struct nettl_file_hdr file_hdr; @@ -664,31 +664,31 @@ static gboolean nettl_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_ (void) g_strlcpy(file_hdr.model,"9000/800",11); file_hdr.unknown=g_htons(0x406); if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err)) - return FALSE; + return false; - return TRUE; + return true; } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean nettl_dump(wtap_dumper *wdh, + Returns true on success, false on failure. */ +static bool nettl_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct nettlrec_hdr rec_hdr; - guint8 dummyc[24]; + uint8_t dummyc[24]; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* Don't write anything we're not willing to read. */ if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } memset(&rec_hdr,0,sizeof(rec_hdr)); @@ -701,11 +701,11 @@ static gboolean nettl_dump(wtap_dumper *wdh, * be made to work once the last 32-bit UN*X is gone and time_t * is universally 64-bit. */ - if (rec->ts.secs < 0 || rec->ts.secs > G_MAXINT32) { + if (rec->ts.secs < 0 || rec->ts.secs > INT32_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - rec_hdr.sec = g_htonl((guint32)rec->ts.secs); + rec_hdr.sec = g_htonl((uint32_t)rec->ts.secs); rec_hdr.usec = g_htonl(rec->ts.nsecs/1000); rec_hdr.caplen = g_htonl(rec->rec_header.packet_header.caplen); rec_hdr.length = g_htonl(rec->rec_header.packet_header.len); @@ -767,38 +767,38 @@ static gboolean nettl_dump(wtap_dumper *wdh, default: /* found one we don't support */ *err = WTAP_ERR_UNWRITABLE_ENCAP; - return FALSE; + return false; } if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof(rec_hdr), err)) - return FALSE; + return false; /* Write out 4 extra bytes of unknown stuff for HP-UX11 * header format. */ memset(dummyc, 0, sizeof dummyc); if (!wtap_dump_file_write(wdh, dummyc, 4, err)) - return FALSE; + return false; if ((rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) || (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_NETTL_FDDI)) { /* add those weird 3 bytes of padding */ if (!wtap_dump_file_write(wdh, dummyc, 3, err)) - return FALSE; + return false; } /* } else if (rec->rec_header.packet_header.pkt_encap == WTAP_ENCAP_NETTL_X25) { if (!wtap_dump_file_write(wdh, dummyc, 24, err)) - return FALSE; + return false; } */ /* write actual PDU data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; - return TRUE; + return true; } static const struct supported_block_type nettl_blocks_supported[] = { @@ -810,7 +810,7 @@ static const struct supported_block_type nettl_blocks_supported[] = { static const struct file_type_subtype_info nettl_info = { "HP-UX nettl trace", "nettl", "trc0", "trc1", - FALSE, BLOCKS_SUPPORTED(nettl_blocks_supported), + false, BLOCKS_SUPPORTED(nettl_blocks_supported), nettl_dump_can_write_encap, nettl_dump_open, NULL }; diff --git a/wiretap/nettl.h b/wiretap/nettl.h index 3bb41fde..5eb26999 100644 --- a/wiretap/nettl.h +++ b/wiretap/nettl.h @@ -116,6 +116,6 @@ #define NETTL_HDR_PDU_MASK 0x30000000 -wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val nettl_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index 7de46946..809fca2f 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -9,6 +9,7 @@ */ #include "config.h" +#include "nettrace_3gpp_32_423.h" #include <sys/types.h> @@ -30,9 +31,7 @@ #include "wsutil/str_util.h" #include <wsutil/inet_addr.h> #include <wsutil/ws_assert.h> - - -#include "nettrace_3gpp_32_423.h" +#include <glib.h> /* String constants sought in the XML data. * Written as strings instead of lists of chars for readability. @@ -40,39 +39,40 @@ * the null byte at the end. */ #define CLEN(x) (sizeof(x)-1) -static const guchar c_xml_magic[] = "<?xml"; -static const guchar c_file_header[] = "<fileHeader"; -static const guchar c_file_format_version[] = "fileFormatVersion=\""; -static const guchar c_threegpp_doc_no[] = "32.423"; -static const guchar c_begin_time[] = "<traceCollec beginTime=\""; -static const guchar c_s_msg[] = "<msg"; -static const guchar c_e_msg[] = "</msg>"; -static const guchar c_s_rawmsg[] = "<rawMsg"; -static const guchar c_change_time[] = "changeTime=\""; -static const guchar c_function[] = "function=\""; -static const guchar c_proto_name[] = "name=\""; -static const guchar c_address[] = "ddress"; /* omit the 'a' to cater for "Address" */ -static const guchar c_s_initiator[] = "<initiator"; -static const guchar c_e_initiator[] = "</initiator>"; -static const guchar c_s_target[] = "<target"; -static const guchar c_e_target[] = "</target>"; -static const guchar c_protocol[] = "protocol=\""; +static const unsigned char c_xml_magic[] = "<?xml"; +static const unsigned char c_file_header[] = "<fileHeader"; +static const unsigned char c_file_format_version[] = "fileFormatVersion=\""; +static const unsigned char c_threegpp_doc_no[] = "32.423"; +static const unsigned char c_begin_time[] = "<traceCollec beginTime=\""; +static const unsigned char c_s_msg[] = "<msg"; +static const unsigned char c_e_msg[] = "</msg>"; +static const unsigned char c_s_rawmsg[] = "<rawMsg"; +static const unsigned char c_change_time[] = "changeTime=\""; +static const unsigned char c_function[] = "function=\""; +static const unsigned char c_proto_name[] = "name=\""; +//static const unsigned char c_address[] = "ddress"; /* omit the 'a' to cater for "Address" */ +static const unsigned char c_s_initiator[] = "<initiator"; +static const unsigned char c_e_initiator[] = "</initiator>"; +static const unsigned char c_s_target[] = "<target"; +static const unsigned char c_e_target[] = "</target>"; +static const unsigned char c_protocol[] = "protocol=\""; /* These are protocol names we may put in the exported-pdu data based on * what's in the XML. They're defined here as constants so we can use * sizeof()/CLEN() on them and slightly reduce our use of magic constants * for their size. (Modern compilers should make this no slower than that.) */ -static const guchar c_sai_req[] = "gsm_map.v3.arg.opcode"; -static const guchar c_sai_rsp[] = "gsm_map.v3.res.opcode"; -static const guchar c_nas_eps[] = "nas-eps_plain"; -static const guchar c_nas_5gs[] = "nas-5gs"; +static const unsigned char c_sai_req[] = "gsm_map.v3.arg.opcode"; +static const unsigned char c_sai_rsp[] = "gsm_map.v3.res.opcode"; +static const unsigned char c_nas_eps[] = "nas-eps_plain"; +static const unsigned char c_nas_5gs[] = "nas-5gs"; + -#define RINGBUFFER_START_SIZE G_MAXINT +#define RINGBUFFER_START_SIZE INT_MAX #define RINGBUFFER_CHUNK_SIZE 1024 #define MAX_FUNCTION_LEN 64 -#define MAX_NAME_LEN 64 +#define MAX_NAME_LEN 128 #define MAX_PROTO_LEN 16 #define MAX_DTBL_LEN 32 @@ -83,18 +83,18 @@ static const guchar c_nas_5gs[] = "nas-5gs"; typedef struct nettrace_3gpp_32_423_file_info { GByteArray *buffer; // holds current chunk of file - gint64 start_offset; // where in the file the start of the buffer points + int64_t start_offset; // where in the file the start of the buffer points nstime_t start_time; // from <traceCollec beginTime=""> attribute } nettrace_3gpp_32_423_file_info_t; typedef struct exported_pdu_info { - guint32 presence_flags; - guint8 src_ip[16]; - guint32 ptype; /* Based on epan/address.h port_type valid for both src and dst*/ - guint32 src_port; - guint8 dst_ip[16]; - guint32 dst_port; + uint32_t presence_flags; + uint8_t src_ip[16]; + uint32_t ptype; /* Based on epan/address.h port_type valid for both src and dst*/ + uint32_t src_port; + uint8_t dst_ip[16]; + uint32_t dst_port; char* proto_col_str; } exported_pdu_info_t; @@ -120,20 +120,19 @@ void register_nettrace_3gpp_32_423(void); * Also parses the port pairs and transport layer type. */ static char* -nettrace_parse_address(char* curr_pos, char* next_pos, gboolean is_src_addr, exported_pdu_info_t *exported_pdu_info) +nettrace_parse_address(char* curr_pos, char* next_pos, bool is_src_addr, exported_pdu_info_t *exported_pdu_info) { - guint port; - char transp_str[5]; - int scan_found; - char str[3]; - char* end_pos, *skip_pos; - char ip_addr_str[WS_INET6_ADDRSTRLEN]; - int str_len; + unsigned port=0; ws_in6_addr ip6_addr; - guint32 ip4_addr; - gchar tempchar; + uint32_t ip4_addr; + char *err; //for strtol function + char saved_next_char; - /* curr_pos pointing to first char after address */ + GMatchInfo *match_info; + static GRegex *regex = NULL; + char *matched_ipaddress = NULL; + char *matched_port = NULL; + char *matched_transport = NULL; /* Excample from one trace, unsure if it's generic... * {address == 192.168.73.1, port == 5062, transport == Udp} @@ -141,39 +140,44 @@ nettrace_parse_address(char* curr_pos, char* next_pos, gboolean is_src_addr, exp * {address == 2001:1B70:8294:210A::90, port... * Address=198.142.204.199,Port=2123 */ - /* Skip whitespace and equalsigns) */ - for (skip_pos = curr_pos; skip_pos < next_pos && - ((tempchar = *skip_pos) == ' ' || - tempchar == '\t' || tempchar == '\r' || tempchar == '\n' || tempchar == '='); - skip_pos++); - - curr_pos = skip_pos; - (void) g_strlcpy(str, curr_pos, 3); - /* If we find "" here we have no IP address */ - if (strcmp(str, "\"\"") == 0) { + if (regex == NULL) { + regex = g_regex_new ( + "^.*address\\s*=*\\s*" //curr_pos will begin with address + "\\[?(?P<ipaddress>(?:" //store ipv4 or ipv6 address in named group "ipaddress" + "(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})" //match an IPv4 address + "|" // or + "(?:[0-9a-f:]*)))\\]?" //match an IPv6 address. + "(?:.*port\\s*=*\\s*(?P<port>\\d{1,5}))?" //match a port store it in named group "port" + "(?:.*transport\\s*=*\\s*(?P<transport>\\w+))?", //match a transport store it in named group "transport" + G_REGEX_CASELESS | G_REGEX_FIRSTLINE, 0, NULL); + } + + /* curr_pos pointing to first char of "address" */ + /* Ensure we don't overrun the intended input. The input will always + * be a mutable buffer, so modifying it is safe. */ + saved_next_char = *next_pos; + *next_pos = '\0'; /* Insert a NUL terminator. */ + g_regex_match (regex, curr_pos, 0, &match_info); + + if (g_match_info_matches (match_info)) { + matched_ipaddress = g_match_info_fetch_named(match_info, "ipaddress"); //will be empty string if no ipv4 or ipv6 + matched_port = g_match_info_fetch_named(match_info, "port"); //will be empty string if port not in trace + if (matched_port != NULL) { + port = (unsigned) strtol(matched_port, &err, 10); + g_free(matched_port); + } + matched_transport = g_match_info_fetch_named(match_info, "transport"); //will be empty string if transport not in trace + } else { + g_match_info_free(match_info); + *next_pos = saved_next_char; return next_pos; } - str[1] = 0; - if (strcmp(str, "[") == 0) { - /* Should we check for a digit here?*/ - end_pos = strstr(curr_pos, "]"); - }else { - /* Should we check for a digit here?*/ - end_pos = strstr(curr_pos, ","); - } - if (!end_pos) { - return next_pos; - } + g_match_info_free(match_info); + *next_pos = saved_next_char; - str_len = (int)(end_pos - curr_pos)+1; - if (str_len > WS_INET6_ADDRSTRLEN) { - return next_pos; - } - (void) g_strlcpy(ip_addr_str, curr_pos, str_len); - curr_pos = end_pos; - if (ws_inet_pton6(ip_addr_str, &ip6_addr)) { + if (ws_inet_pton6(matched_ipaddress, &ip6_addr)) { if (is_src_addr) { exported_pdu_info->presence_flags |= EXP_PDU_TAG_IP6_SRC_BIT; memcpy(exported_pdu_info->src_ip, ip6_addr.bytes, EXP_PDU_TAG_IPV6_LEN); @@ -183,7 +187,7 @@ nettrace_parse_address(char* curr_pos, char* next_pos, gboolean is_src_addr, exp memcpy(exported_pdu_info->dst_ip, ip6_addr.bytes, EXP_PDU_TAG_IPV6_LEN); } } - else if (ws_inet_pton4(ip_addr_str, &ip4_addr)) { + else if (ws_inet_pton4(matched_ipaddress, &ip4_addr)) { if (is_src_addr) { exported_pdu_info->presence_flags |= EXP_PDU_TAG_IP_SRC_BIT; memcpy(exported_pdu_info->src_ip, &ip4_addr, EXP_PDU_TAG_IPV4_LEN); @@ -194,18 +198,16 @@ nettrace_parse_address(char* curr_pos, char* next_pos, gboolean is_src_addr, exp } } - curr_pos++; - scan_found = sscanf(curr_pos, ", %*s %*s %5u, %*s %*s %4s", &port, transp_str); - if (scan_found == 2) { + if (port > 0) { /* Only add port_type once */ if (exported_pdu_info->ptype == EXP_PDU_PT_NONE) { - if (g_ascii_strncasecmp(transp_str, "udp", 3) == 0) { + if (g_ascii_strncasecmp(matched_transport, "udp", 3) == 0) { exported_pdu_info->ptype = EXP_PDU_PT_UDP; } - else if (g_ascii_strncasecmp(transp_str, "tcp", 3) == 0) { + else if (g_ascii_strncasecmp(matched_transport, "tcp", 3) == 0) { exported_pdu_info->ptype = EXP_PDU_PT_TCP; } - else if (g_ascii_strncasecmp(transp_str, "sctp", 4) == 0) { + else if (g_ascii_strncasecmp(matched_transport, "sctp", 4) == 0) { exported_pdu_info->ptype = EXP_PDU_PT_SCTP; } } @@ -218,18 +220,20 @@ nettrace_parse_address(char* curr_pos, char* next_pos, gboolean is_src_addr, exp exported_pdu_info->dst_port = port; } } + g_free(matched_ipaddress); + g_free(matched_transport); return next_pos; } /* Parse a <msg ...><rawMsg ...>XXXX</rawMsg></msg> into packet data. */ -static gboolean -nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *rec, Buffer *buf, guint8 *input, gsize len, int *err, gchar **err_info) +static bool +nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *rec, Buffer *buf, uint8_t *input, size_t len, int *err, char **err_info) { /* Convenience macro. haystack must be >= input! */ -#define STRNSTR(haystack, needle) g_strstr_len(haystack, (len - ((guint8*)(haystack) - (guint8*)input)), needle) +#define STRNSTR(haystack, needle) g_strstr_len(haystack, (len - ((uint8_t*)(haystack) - (uint8_t*)input)), needle) - gboolean status = TRUE; + bool status = true; char *curr_pos, *next_msg_pos, *next_pos, *prev_pos; exported_pdu_info_t exported_pdu_info = {0}; @@ -244,15 +248,15 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re int function_str_len = 0; int name_str_len = 0; int proto_str_len, dissector_table_str_len, raw_data_len, pkt_data_len, exp_pdu_tags_len, i; - guint8 *packet_buf; - gint val1, val2; - gboolean use_proto_table = FALSE; + uint8_t *packet_buf; + int val1, val2; + bool use_proto_table = false; /* We should always and only be called with a <msg....</msg> payload */ if (0 != strncmp(input, c_s_msg, CLEN(c_s_msg))) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettrace_3gpp_32_423: Did not start with \"%s\"", c_s_msg); - return FALSE; + return false; } curr_pos = input + CLEN(c_s_msg); @@ -274,7 +278,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re /* Something's wrong, bail out */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Did not find end of tag \">\""); - status = FALSE; + status = false; goto end; } /* Check if its a tag close "/>" */ @@ -282,7 +286,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re /* There is no rawmsg here. Should have been caught before we got called */ *err = WTAP_ERR_INTERNAL; *err_info = g_strdup("Had \"<msg />\" with no \"<rawMsg>\""); - status = FALSE; + status = false; goto end; } start_msg_tag_cont = curr_pos = prev_pos; @@ -291,7 +295,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re /* Something's wrong, bail out */ *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettrace_3gpp_32_423: Did not find \"%s\"", c_e_msg); - status = FALSE; + status = false; goto end; } @@ -301,7 +305,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re */ if (!nstime_is_unset(&(file_info->start_time))) { int scan_found; - guint second = 0, ms = 0; + unsigned second = 0, ms = 0; curr_pos = STRNSTR(start_msg_tag_cont, c_change_time); /* Check if we have the tag or if we passed the end of the current message */ @@ -310,8 +314,8 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re scan_found = sscanf(curr_pos, "%u.%u", &second, &ms); if (scan_found == 2) { - guint start_ms = file_info->start_time.nsecs / 1000000; - guint elapsed_ms = start_ms + ms; + unsigned start_ms = file_info->start_time.nsecs / 1000000; + unsigned elapsed_ms = start_ms + ms; if (elapsed_ms > 1000) { elapsed_ms -= 1000; second++; @@ -337,7 +341,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re goto end; } - (void) g_strlcpy(function_str, curr_pos, (gsize)function_str_len + 1); + (void) g_strlcpy(function_str, curr_pos, (size_t)function_str_len + 1); ascii_strdown_inplace(function_str); } @@ -356,7 +360,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re goto end; } - (void) g_strlcpy(name_str, curr_pos, (gsize)name_str_len + 1); + (void) g_strlcpy(name_str, curr_pos, (size_t)name_str_len + 1); ascii_strdown_inplace(name_str); } @@ -369,10 +373,9 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re curr_pos += CLEN(c_s_initiator); next_pos = STRNSTR(curr_pos, c_e_initiator); /* Find address */ - curr_pos = STRNSTR(curr_pos, c_address); + //curr_pos = STRNSTR(curr_pos, c_address) - 1; //Not needed due to regex if (curr_pos != NULL) { - curr_pos += CLEN(c_address); - nettrace_parse_address(curr_pos, next_pos, TRUE/* SRC */, &exported_pdu_info); + nettrace_parse_address(curr_pos, next_pos, true/* SRC */, &exported_pdu_info); } } @@ -383,14 +386,12 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re /* Check if we have the tag or if we passed the end of the current message */ if (curr_pos != NULL) { curr_pos += CLEN(c_s_target); - curr_pos = curr_pos + 7; next_pos = STRNSTR(curr_pos, c_e_target); /* Find address */ - curr_pos = STRNSTR(curr_pos, c_address); + //curr_pos = STRNSTR(curr_pos, c_address) - 1; //Not needed due to regex if (curr_pos != NULL) { - curr_pos += CLEN(c_address); /* curr_pos set below */ - nettrace_parse_address(curr_pos, next_pos, FALSE/* DST */, &exported_pdu_info); + nettrace_parse_address(curr_pos, next_pos, false/* DST */, &exported_pdu_info); } } @@ -399,24 +400,24 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re if (raw_msg_pos == NULL) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettrace_3gpp_32_423: Did not find \"%s\"", c_s_rawmsg); - status = FALSE; + status = false; goto end; } curr_pos = STRNSTR(raw_msg_pos, c_protocol); if (curr_pos == NULL) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettrace_3gpp_32_423: Did not find \"%s\"", c_protocol); - status = FALSE; + status = false; goto end; } curr_pos += CLEN(c_protocol); next_pos = STRNSTR(curr_pos, "\""); proto_str_len = (int)(next_pos - curr_pos); if (proto_str_len > MAX_PROTO_LEN){ - status = FALSE; + status = false; goto end; } - (void) g_strlcpy(proto_name_str, curr_pos, (gsize)proto_str_len+1); + (void) g_strlcpy(proto_name_str, curr_pos, (size_t)proto_str_len+1); ascii_strdown_inplace(proto_name_str); /* Do string matching and replace with Wiresharks protocol name */ @@ -437,7 +438,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re } else { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("nettrace_3gpp_32_423: No handle of message \"%s\" on function \"%s\" ", proto_name_str, function_str); - status = FALSE; + status = false; goto end; } } @@ -449,14 +450,14 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re exported_pdu_info.proto_col_str = g_strdup("GSM MAP"); if (strcmp(name_str, "sai_request") == 0) { - use_proto_table = TRUE; + use_proto_table = true; (void) g_strlcpy(dissector_table_str, c_sai_req, sizeof(c_sai_req)); dissector_table_str_len = CLEN(c_sai_req); dissector_table_val = 56; exported_pdu_info.presence_flags |= EXP_PDU_TAG_COL_PROT_BIT; } else if (strcmp(name_str, "sai_response") == 0) { - use_proto_table = TRUE; + use_proto_table = true; (void) g_strlcpy(dissector_table_str, c_sai_rsp, sizeof(c_sai_rsp)); dissector_table_str_len = CLEN(c_sai_rsp); dissector_table_val = 56; @@ -473,7 +474,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re /* Fill packet buff */ ws_buffer_clean(buf); - if (use_proto_table == FALSE) { + if (use_proto_table == false) { wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_DISSECTOR_NAME, proto_name_str, proto_str_len); } else { @@ -520,14 +521,14 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re packet_buf = ws_buffer_end_ptr(buf); for (i = 0; i < pkt_data_len; i++) { - gchar chr1, chr2; + char chr1, chr2; chr1 = *curr_pos++; chr2 = *curr_pos++; val1 = g_ascii_xdigit_value(chr1); val2 = g_ascii_xdigit_value(chr2); if ((val1 != -1) && (val2 != -1)) { - *packet_buf++ = ((guint8)val1 * 16) + val2; + *packet_buf++ = ((uint8_t)val1 * 16) + val2; } else { /* Something wrong, bail out */ @@ -537,14 +538,14 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re chr1, chr2); *err = WTAP_ERR_BAD_FILE; - status = FALSE; + status = false; goto end; } } ws_buffer_increase_length(buf, pkt_data_len); - rec->rec_header.packet_header.caplen = (guint32)ws_buffer_length(buf); - rec->rec_header.packet_header.len = (guint32)ws_buffer_length(buf); + rec->rec_header.packet_header.caplen = (uint32_t)ws_buffer_length(buf); + rec->rec_header.packet_header.len = (uint32_t)ws_buffer_length(buf); end: return status; @@ -555,12 +556,12 @@ end: * Returns location of needle once found, or NULL if it's never found * (due to either EOF or read error). */ -static guint8 * -read_until(GByteArray *buffer, const guchar *needle, FILE_T fh, int *err, gchar **err_info) +static uint8_t * +read_until(GByteArray *buffer, const unsigned char *needle, FILE_T fh, int *err, char **err_info) { - guint8 read_buffer[RINGBUFFER_CHUNK_SIZE]; - guint8 *found_it; - gint bytes_read = 0; + uint8_t read_buffer[RINGBUFFER_CHUNK_SIZE]; + uint8_t *found_it; + int bytes_read = 0; while (NULL == (found_it = g_strstr_len(buffer->data, buffer->len, needle))) { bytes_read = file_read(read_buffer, RINGBUFFER_CHUNK_SIZE, fh); @@ -579,15 +580,15 @@ read_until(GByteArray *buffer, const guchar *needle, FILE_T fh, int *err, gchar /* Find a complete packet, parse and return it to wiretap. * Set as the subtype_read function in the file_open function below. */ -static gboolean -nettrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) +static bool +nettrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, int64_t *data_offset) { nettrace_3gpp_32_423_file_info_t *file_info = (nettrace_3gpp_32_423_file_info_t *)wth->priv; - guint8 *buf_start; - guint8 *msg_start, *msg_end; - guint msg_offset = 0; - gsize msg_len = 0; - gboolean status = FALSE; + uint8_t *buf_start; + uint8_t *msg_start, *msg_end; + unsigned msg_offset = 0; + size_t msg_len = 0; + bool status = false; /* Make sure we have a start and end of message in our buffer -- end first */ msg_end = read_until(file_info->buffer, c_e_msg, wth->fh, err, err_info); @@ -599,7 +600,7 @@ nettrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, /* Now search backwards for the message start * (doing it this way should skip over any empty "<msg ... />" tags we have) */ - msg_start = g_strrstr_len(buf_start, (guint)(msg_end - buf_start), c_s_msg); + msg_start = g_strrstr_len(buf_start, (unsigned)(msg_end - buf_start), c_s_msg); if (msg_start == NULL || msg_start > msg_end) { *err_info = ws_strdup_printf("nettrace_3gpp_32_423: Found \"%s\" without matching \"%s\"", c_e_msg, c_s_msg); *err = WTAP_ERR_BAD_FILE; @@ -607,9 +608,9 @@ nettrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, } /* We know we have a message, what's its offset from the buffer start? */ - msg_offset = (guint)(msg_start - buf_start); + msg_offset = (unsigned)(msg_start - buf_start); msg_end += CLEN(c_e_msg); - msg_len = (guint)(msg_end - msg_start); + msg_len = (unsigned)(msg_end - msg_start); /* Tell Wireshark to put us at the start of the "<msg" for seek_read later */ *data_offset = file_info->start_offset + msg_offset; @@ -621,15 +622,15 @@ nettrace_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, * Re-use msg_len to get the length of the data we're done with. */ msg_len = msg_end - file_info->buffer->data; - while (G_UNLIKELY(msg_len > G_MAXUINT)) { - g_byte_array_remove_range(file_info->buffer, 0, G_MAXUINT); - msg_len -= G_MAXUINT; + while (G_UNLIKELY(msg_len > UINT_MAX)) { + g_byte_array_remove_range(file_info->buffer, 0, UINT_MAX); + msg_len -= UINT_MAX; } - g_byte_array_remove_range(file_info->buffer, 0, (guint)msg_len); + g_byte_array_remove_range(file_info->buffer, 0, (unsigned)msg_len); file_info->start_offset += msg_len; end: - if (status == FALSE) { + if (status == false) { /* There's no more to read. Empty out the buffer */ g_byte_array_set_size(file_info->buffer, 0); } @@ -640,24 +641,24 @@ end: /* Seek to the complete packet at the offset, parse and return it to wiretap. * Set as the subtype_seek_read function in the file_open function below. */ -static gboolean -nettrace_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +nettrace_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { nettrace_3gpp_32_423_file_info_t *file_info = (nettrace_3gpp_32_423_file_info_t *)wth->priv; - gboolean status = FALSE; - guint8 *msg_end; - guint msg_len = 0; + bool status = false; + uint8_t *msg_end; + unsigned msg_len = 0; /* We stored the offset of the "<msg" for this packet */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; msg_end = read_until(file_info->buffer, c_e_msg, wth->random_fh, err, err_info); if (msg_end == NULL) { - return FALSE; + return false; } msg_end += CLEN(c_e_msg); - msg_len = (guint)(msg_end - file_info->buffer->data); + msg_len = (unsigned)(msg_end - file_info->buffer->data); status = nettrace_msg_to_packet(file_info, rec, buf, file_info->buffer->data, msg_len, err, err_info); g_byte_array_set_size(file_info->buffer, 0); @@ -674,7 +675,7 @@ nettrace_close(wtap *wth) nettrace_3gpp_32_423_file_info_t *file_info = (nettrace_3gpp_32_423_file_info_t *)wth->priv; if (file_info != NULL && file_info->buffer != NULL) { - g_byte_array_free(file_info->buffer, TRUE); + g_byte_array_free(file_info->buffer, true); file_info->buffer = NULL; } } @@ -683,14 +684,14 @@ nettrace_close(wtap *wth) * Set in file_access.c as the function to be called for this file type. */ wtap_open_return_val -nettrace_3gpp_32_423_file_open(wtap *wth, int *err, gchar **err_info) +nettrace_3gpp_32_423_file_open(wtap *wth, int *err, char **err_info) { char magic_buf[MAGIC_BUF_SIZE+1]; int bytes_read; const char *curr_pos; nstime_t start_time; nettrace_3gpp_32_423_file_info_t *file_info; - gint64 start_offset; + int64_t start_offset; start_offset = file_tell(wth->fh); // Most likely 0 but doesn't hurt to check bytes_read = file_read(magic_buf, MAGIC_BUF_SIZE, wth->fh); @@ -736,7 +737,7 @@ nettrace_3gpp_32_423_file_open(wtap *wth, int *err, gchar **err_info) file_info->start_time = start_time; file_info->start_offset = start_offset + (curr_pos - magic_buf); file_info->buffer = g_byte_array_sized_new(RINGBUFFER_START_SIZE); - g_byte_array_append(file_info->buffer, curr_pos, (guint)(bytes_read - (curr_pos - magic_buf))); + g_byte_array_append(file_info->buffer, curr_pos, (unsigned)(bytes_read - (curr_pos - magic_buf))); wth->file_type_subtype = nettrace_3gpp_32_423_file_type_subtype; wth->file_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU; @@ -759,7 +760,7 @@ static const struct supported_block_type nettrace_3gpp_32_423_blocks_supported[] static const struct file_type_subtype_info nettrace_3gpp_32_423_info = { "3GPP TS 32.423 Trace", "3gpp32423", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(nettrace_3gpp_32_423_blocks_supported), + false, BLOCKS_SUPPORTED(nettrace_3gpp_32_423_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/nettrace_3gpp_32_423.h b/wiretap/nettrace_3gpp_32_423.h index e34100ed..052002e7 100644 --- a/wiretap/nettrace_3gpp_32_423.h +++ b/wiretap/nettrace_3gpp_32_423.h @@ -12,6 +12,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val nettrace_3gpp_32_423_file_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val nettrace_3gpp_32_423_file_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/netxray.c b/wiretap/netxray.c index 6ba6c795..086bd4cf 100644 --- a/wiretap/netxray.c +++ b/wiretap/netxray.c @@ -7,11 +7,11 @@ */ #include "config.h" +#include "netxray.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "netxray.h" #include "atm.h" /* Capture file header, *including* magic number, is padded to 128 bytes. */ @@ -39,43 +39,43 @@ static const char netxray_magic[MAGIC_SIZE] = { /* where <hex_hdr_offset> *includes* the magic number) */ struct netxray_hdr { - char version[8]; /* version number */ - guint32 start_time; /* UNIX [UTC] time when capture started */ - - guint32 nframes; /* number of packets */ - guint32 xxx_x14; /* unknown [some kind of file offset] */ - guint32 start_offset; /* offset of first packet in capture */ - guint32 end_offset; /* offset after last packet in capture */ - - guint32 xxx_x20; /* unknown [some kind of file offset] */ - guint32 xxx_x24; /* unknown [unused ?] */ - guint32 xxx_x28; /* unknown [some kind of file offset] */ - guint8 network; /* datalink type */ - guint8 network_plus; /* [See code] */ - guint8 xxx_x2E[2]; /* unknown */ - - guint8 timeunit; /* encodes length of a tick */ - guint8 xxx_x31[3]; /* XXX - upper 3 bytes of timeunit ? */ - guint32 timelo; /* lower 32 bits of capture start time stamp */ - guint32 timehi; /* upper 32 bits of capture start time stamp */ - guint32 linespeed; /* speed of network, in bits/second */ - - guint8 xxx_x40[12]; /* unknown [other stuff] */ - guint8 realtick[4]; /* (ticks/sec for Ethernet/Ndis/Timeunit=2 ?) */ + char version[8]; /* version number */ + uint32_t start_time; /* UNIX [UTC] time when capture started */ + + uint32_t nframes; /* number of packets */ + uint32_t xxx_x14; /* unknown [some kind of file offset] */ + uint32_t start_offset; /* offset of first packet in capture */ + uint32_t end_offset; /* offset after last packet in capture */ + + uint32_t xxx_x20; /* unknown [some kind of file offset] */ + uint32_t xxx_x24; /* unknown [unused ?] */ + uint32_t xxx_x28; /* unknown [some kind of file offset] */ + uint8_t network; /* datalink type */ + uint8_t network_plus; /* [See code] */ + uint8_t xxx_x2E[2]; /* unknown */ + + uint8_t timeunit; /* encodes length of a tick */ + uint8_t xxx_x31[3]; /* XXX - upper 3 bytes of timeunit ? */ + uint32_t timelo; /* lower 32 bits of capture start time stamp */ + uint32_t timehi; /* upper 32 bits of capture start time stamp */ + uint32_t linespeed; /* speed of network, in bits/second */ + + uint8_t xxx_x40[12]; /* unknown [other stuff] */ + uint8_t realtick[4]; /* (ticks/sec for Ethernet/Ndis/Timeunit=2 ?) */ /* (realtick[1], realtick[2] also currently */ /* used as flag for 'FCS presence') */ - guint8 xxx_x50[4]; /* unknown [other stuff] */ - guint8 captype; /* capture type */ - guint8 xxx_x55[3]; /* unknown [other stuff] */ - guint8 xxx_x58[4]; /* unknown [other stuff] */ - guint8 wan_hdlc_subsub_captype; /* WAN HDLC subsub_captype */ - guint8 xxx_x5D[3]; /* unknown [other stuff] */ + uint8_t xxx_x50[4]; /* unknown [other stuff] */ + uint8_t captype; /* capture type */ + uint8_t xxx_x55[3]; /* unknown [other stuff] */ + uint8_t xxx_x58[4]; /* unknown [other stuff] */ + uint8_t wan_hdlc_subsub_captype; /* WAN HDLC subsub_captype */ + uint8_t xxx_x5D[3]; /* unknown [other stuff] */ - guint8 xxx_x60[16]; /* unknown [other stuff] */ + uint8_t xxx_x60[16]; /* unknown [other stuff] */ - guint8 xxx_x70[14]; /* unknown [other stuff] */ - gint16 timezone_hrs; /* timezone hours [at least for version 2.2..]; */ + uint8_t xxx_x70[14]; /* unknown [other stuff] */ + int16_t timezone_hrs; /* timezone hours [at least for version 2.2..]; */ /* positive values = west of UTC: */ /* negative values = east of UTC: */ /* e.g. +5 is American Eastern */ @@ -179,7 +179,7 @@ struct netxray_hdr { * that captype be? */ static const double TpS[] = { 1e6, 1193000.0, 1193182.0 }; -#define NUM_NETXRAY_TIMEUNITS (sizeof TpS / sizeof TpS[0]) +#define NUM_NETXRAY_TIMEUNITS array_length(TpS) /* * Table of time units for Ethernet captures with captype ETH_CAPTYPE_GIGPOD. @@ -204,7 +204,7 @@ static const double TpS[] = { 1e6, 1193000.0, 1193182.0 }; * correct TpS values for the 'gigpod' captype). */ static const double TpS_gigpod[] = { 1e9, 0.0, 31250000.0 }; -#define NUM_NETXRAY_TIMEUNITS_GIGPOD (sizeof TpS_gigpod / sizeof TpS_gigpod[0]) +#define NUM_NETXRAY_TIMEUNITS_GIGPOD array_length(TpS_gigpod) /* * Table of time units for Ethernet captures with captype ETH_CAPTYPE_OTHERPOD. @@ -212,7 +212,7 @@ static const double TpS_gigpod[] = { 1e9, 0.0, 31250000.0 }; * correct TpS values for the 'otherpod' captype). */ static const double TpS_otherpod[] = { 1e6, 0.0, 1250000.0 }; -#define NUM_NETXRAY_TIMEUNITS_OTHERPOD (sizeof TpS_otherpod / sizeof TpS_otherpod[0]) +#define NUM_NETXRAY_TIMEUNITS_OTHERPOD array_length(TpS_otherpod) /* * Table of time units for Ethernet captures with captype ETH_CAPTYPE_OTHERPOD2. @@ -220,7 +220,7 @@ static const double TpS_otherpod[] = { 1e6, 0.0, 1250000.0 }; * correct TpS values for the 'otherpod2' captype). */ static const double TpS_otherpod2[] = { 1e6, 0.0, 0.0 }; -#define NUM_NETXRAY_TIMEUNITS_OTHERPOD2 (sizeof TpS_otherpod2 / sizeof TpS_otherpod2[0]) +#define NUM_NETXRAY_TIMEUNITS_OTHERPOD2 array_length(TpS_otherpod2) /* * Table of time units for Ethernet captures with captype ETH_CAPTYPE_GIGPOD2. @@ -228,7 +228,7 @@ static const double TpS_otherpod2[] = { 1e6, 0.0, 0.0 }; * correct TpS values for the 'gigpod2' captype). */ static const double TpS_gigpod2[] = { 1e9, 0.0, 20000000.0 }; -#define NUM_NETXRAY_TIMEUNITS_GIGPOD2 (sizeof TpS_gigpod2 / sizeof TpS_gigpod2[0]) +#define NUM_NETXRAY_TIMEUNITS_GIGPOD2 array_length(TpS_gigpod2) /* Version number strings. */ static const char vers_1_0[] = { @@ -257,19 +257,19 @@ static const char vers_2_003[] = { /* Old NetXRay data record format - followed by frame data. */ struct old_netxrayrec_hdr { - guint32 timelo; /* lower 32 bits of time stamp */ - guint32 timehi; /* upper 32 bits of time stamp */ - guint16 len; /* packet length */ - guint8 xxx[6]; /* unknown */ + uint32_t timelo; /* lower 32 bits of time stamp */ + uint32_t timehi; /* upper 32 bits of time stamp */ + uint16_t len; /* packet length */ + uint8_t xxx[6]; /* unknown */ }; /* NetXRay format version 1.x data record format - followed by frame data. */ struct netxrayrec_1_x_hdr { - guint32 timelo; /* lower 32 bits of time stamp */ - guint32 timehi; /* upper 32 bits of time stamp */ - guint16 orig_len; /* packet length */ - guint16 incl_len; /* capture length */ - guint8 xxx[16]; /* unknown */ + uint32_t timelo; /* lower 32 bits of time stamp */ + uint32_t timehi; /* upper 32 bits of time stamp */ + uint16_t orig_len; /* packet length */ + uint16_t incl_len; /* capture length */ + uint8_t xxx[16]; /* unknown */ }; /* @@ -377,11 +377,11 @@ struct netxrayrec_1_x_hdr { * xxx[27]: for 802.11, one of 0x00 or 0x30? */ struct netxrayrec_2_x_hdr { - guint32 timelo; /* lower 32 bits of time stamp */ - guint32 timehi; /* upper 32 bits of time stamp */ - guint16 orig_len; /* packet length */ - guint16 incl_len; /* capture length */ - guint8 xxx[28]; /* various data */ + uint32_t timelo; /* lower 32 bits of time stamp */ + uint32_t timehi; /* upper 32 bits of time stamp */ + uint16_t orig_len; /* packet length */ + uint16_t incl_len; /* capture length */ + uint8_t xxx[28]; /* various data */ }; /* @@ -397,33 +397,33 @@ typedef struct { time_t start_time; double ticks_per_sec; double start_timestamp; - gboolean wrapped; - guint32 nframes; - gint64 start_offset; - gint64 end_offset; + bool wrapped; + uint32_t nframes; + int64_t start_offset; + int64_t end_offset; int version_major; - gboolean fcs_valid; /* if packets have valid FCS at the end */ - guint isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */ + bool fcs_valid; /* if packets have valid FCS at the end */ + unsigned isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */ } netxray_t; -static gboolean netxray_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean netxray_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool netxray_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool netxray_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int netxray_process_rec_header(wtap *wth, FILE_T fh, - wtap_rec *rec, int *err, gchar **err_info); + wtap_rec *rec, int *err, char **err_info); static void netxray_guess_atm_type(wtap *wth, wtap_rec *rec, Buffer *buf); -static gboolean netxray_dump_1_1(wtap_dumper *wdh, +static bool netxray_dump_1_1(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gboolean netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, - gchar **err_info); -static gboolean netxray_dump_2_0(wtap_dumper *wdh, + const uint8_t *pd, int *err, char **err_info); +static bool netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, + char **err_info); +static bool netxray_dump_2_0(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gboolean netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, - gchar **err_info); + const uint8_t *pd, int *err, char **err_info); +static bool netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, + char **err_info); static int netxray_old_file_type_subtype = -1; static int netxray_1_0_file_type_subtype = -1; @@ -433,12 +433,12 @@ static int netxray_2_00x_file_type_subtype = -1; void register_netxray(void); wtap_open_return_val -netxray_open(wtap *wth, int *err, gchar **err_info) +netxray_open(wtap *wth, int *err, char **err_info) { char magic[MAGIC_SIZE]; - gboolean is_old; + bool is_old; struct netxray_hdr hdr; - guint network_type; + unsigned network_type; double ticks_per_sec; int version_major, version_minor; int file_type; @@ -466,9 +466,9 @@ netxray_open(wtap *wth, int *err, gchar **err_info) /* Wireless WAN with radio information */ WTAP_ENCAP_UNKNOWN /* IrDA */ }; - #define NUM_NETXRAY_ENCAPS (sizeof netxray_encap / sizeof netxray_encap[0]) + #define NUM_NETXRAY_ENCAPS array_length(netxray_encap) int file_encap; - guint isdn_type = 0; + unsigned isdn_type = 0; netxray_t *netxray; /* Read in the string that should be at the start of a NetXRay @@ -480,9 +480,9 @@ netxray_open(wtap *wth, int *err, gchar **err_info) } if (memcmp(magic, netxray_magic, MAGIC_SIZE) == 0) { - is_old = FALSE; + is_old = false; } else if (memcmp(magic, old_netxray_magic, MAGIC_SIZE) == 0) { - is_old = TRUE; + is_old = true; } else { return WTAP_OPEN_NOT_MINE; } @@ -883,7 +883,7 @@ netxray_open(wtap *wth, int *err, gchar **err_info) * If frames have an extra 4 bytes of stuff at the end, is * it an FCS, or just junk? */ - netxray->fcs_valid = FALSE; + netxray->fcs_valid = false; switch (file_encap) { case WTAP_ENCAP_ETHERNET: @@ -970,7 +970,7 @@ netxray_open(wtap *wth, int *err, gchar **err_info) */ if (version_major == 2) { if (hdr.realtick[1] == 0x34 && hdr.realtick[2] == 0x12) - netxray->fcs_valid = TRUE; + netxray->fcs_valid = true; } break; } @@ -986,7 +986,7 @@ netxray_open(wtap *wth, int *err, gchar **err_info) * there's sometimes crud after it. * XXX: Remember 'start_offset' to help testing for 'short file' at EOF */ - netxray->wrapped = FALSE; + netxray->wrapped = false; netxray->nframes = pletoh32(&hdr.nframes); netxray->start_offset = pletoh32(&hdr.start_offset); netxray->end_offset = pletoh32(&hdr.end_offset); @@ -1008,9 +1008,9 @@ netxray_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean +static bool netxray_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { netxray_t *netxray = (netxray_t *)wth->priv; int padding; @@ -1026,7 +1026,7 @@ reread: if (*data_offset == netxray->end_offset) { /* Yes. */ *err = 0; /* it's just an EOF, not an error */ - return FALSE; + return false; } /* Read and process record header. */ @@ -1039,7 +1039,7 @@ reread: /* * Error of some sort; give up. */ - return FALSE; + return false; } /* We're at EOF. Wrap? @@ -1064,20 +1064,20 @@ reread: */ if (netxray->start_offset < netxray->end_offset) { *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } if (!netxray->wrapped) { /* Yes. Remember that we did. */ - netxray->wrapped = TRUE; + netxray->wrapped = true; if (file_seek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1) - return FALSE; + return false; goto reread; } /* We've already wrapped - don't wrap again. */ - return FALSE; + return false; } /* @@ -1085,13 +1085,13 @@ reread: */ if (!wtap_read_packet_bytes(wth->fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) - return FALSE; + return false; /* * If there's extra stuff at the end of the record, skip it. */ if (!wtap_read_bytes(wth->fh, NULL, padding, err, err_info)) - return FALSE; + return false; /* * If it's an ATM packet, and we don't have enough information @@ -1099,16 +1099,16 @@ reread: * attempt to guess them from the packet data. */ netxray_guess_atm_type(wth, rec, buf); - return TRUE; + return true; } -static gboolean -netxray_seek_read(wtap *wth, gint64 seek_off, +static bool +netxray_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, SEEK_SET, err) == -1) - return FALSE; + return false; if (netxray_process_rec_header(wth, wth->random_fh, rec, err, err_info) == -1) { @@ -1120,7 +1120,7 @@ netxray_seek_read(wtap *wth, gint64 seek_off, */ *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } /* @@ -1128,7 +1128,7 @@ netxray_seek_read(wtap *wth, gint64 seek_off, */ if (!wtap_read_packet_bytes(wth->random_fh, buf, rec->rec_header.packet_header.caplen, err, err_info)) - return FALSE; + return false; /* * If it's an ATM packet, and we don't have enough information @@ -1136,12 +1136,12 @@ netxray_seek_read(wtap *wth, gint64 seek_off, * attempt to guess them from the packet data. */ netxray_guess_atm_type(wth, rec, buf); - return TRUE; + return true; } static int netxray_process_rec_header(wtap *wth, FILE_T fh, wtap_rec *rec, - int *err, gchar **err_info) + int *err, char **err_info) { netxray_t *netxray = (netxray_t *)wth->priv; union netxrayrec_hdr hdr; @@ -1280,8 +1280,8 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, wtap_rec *rec, } else rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = false; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = false; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; /* @@ -1289,15 +1289,15 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, wtap_rec *rec, * type, frequency, 11n/11ac information, * etc.? */ - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = hdr.hdr_2_x.xxx[12]; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate = hdr.hdr_2_x.xxx[13]; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = hdr.hdr_2_x.xxx[14]; @@ -1308,7 +1308,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, wtap_rec *rec, * from 0x00 to 0x7F for 0 to 100%. */ if (hdr.hdr_2_x.xxx[15] != 0xFF) { - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_percent = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_percent = hdr.hdr_2_x.xxx[15]*100/127; } @@ -1421,7 +1421,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, wtap_rec *rec, case WTAP_ENCAP_SDLC: case WTAP_ENCAP_CHDLC_WITH_PHDR: rec->rec_header.packet_header.pseudo_header.p2p.sent = - (hdr.hdr_2_x.xxx[12] & 0x01) ? TRUE : FALSE; + (hdr.hdr_2_x.xxx[12] & 0x01) ? true : false; break; case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED: @@ -1661,7 +1661,7 @@ netxray_process_rec_header(wtap *wth, FILE_T fh, wtap_rec *rec, static void netxray_guess_atm_type(wtap *wth, wtap_rec *rec, Buffer *buf) { - const guint8 *pd; + const uint8_t *pd; if (wth->file_encap == WTAP_ENCAP_ATM_PDUS_UNTRUNCATED && !(rec->rec_header.packet_header.pseudo_header.atm.flags & ATM_REASSEMBLY_ERROR)) { @@ -1685,9 +1685,9 @@ netxray_guess_atm_type(wtap *wth, wtap_rec *rec, Buffer *buf) } typedef struct { - gboolean first_frame; - guint32 start_secs; - guint32 nframes; + bool first_frame; + uint32_t start_secs; + uint32_t nframes; } netxray_dump_t; static const struct { @@ -1699,7 +1699,7 @@ static const struct { { WTAP_ENCAP_FDDI, 2 }, /* -> NDIS FDDI */ { WTAP_ENCAP_FDDI_BITSWAPPED, 2 }, /* -> NDIS FDDI */ }; -#define NUM_WTAP_ENCAPS_1_1 (sizeof wtap_encap_1_1 / sizeof wtap_encap_1_1[0]) +#define NUM_WTAP_ENCAPS_1_1 array_length(wtap_encap_1_1) static int wtap_encap_to_netxray_1_1_encap(int encap) @@ -1729,10 +1729,10 @@ netxray_dump_can_write_encap_1_1(int encap) return 0; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -netxray_dump_open_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool +netxray_dump_open_1_1(wtap_dumper *wdh, int *err, char **err_info _U_) { netxray_dump_t *netxray; @@ -1744,34 +1744,34 @@ netxray_dump_open_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_) the header when we've written out all the packets, we just skip over the header for now. */ if (wtap_dump_file_seek(wdh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1) - return FALSE; + return false; wdh->bytes_dumped += CAPTUREFILE_HEADER_SIZE; netxray = g_new(netxray_dump_t, 1); wdh->priv = (void *)netxray; - netxray->first_frame = TRUE; + netxray->first_frame = true; netxray->start_secs = 0; netxray->nframes = 0; - return TRUE; + return true; } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean + Returns true on success, false on failure. */ +static bool netxray_dump_1_1(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; - guint64 timestamp; - guint32 t32; + uint64_t timestamp; + uint32_t t32; struct netxrayrec_1_x_hdr rec_hdr; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -1780,14 +1780,14 @@ netxray_dump_1_1(wtap_dumper *wdh, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* The captured length field is 16 bits, so there's a hard limit of 65535. */ if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } /* NetXRay/Windows Sniffer files have a capture start date/time @@ -1801,66 +1801,66 @@ netxray_dump_1_1(wtap_dumper *wdh, packets being the delta between the stamp of the packet and the stamp of the first packet with the microseconds part 0. */ if (netxray->first_frame) { - netxray->first_frame = FALSE; + netxray->first_frame = false; /* * XXX - NetXRay ran on Windows, where MSVC's localtime() * can't handle time_t < 0, so *maybe* it makes sense * to allow time stamps up to 2^32-1 "seconds since the * Epoch", but maybe the start time in those files is * signed, in which case we should check against - * G_MININT32 and G_MAXINT32 and make start_secs a - * gint32. + * INT32_MIN and INT32_MAX and make start_secs a + * int32_t. */ if (rec->ts.secs < 0 || rec->ts.secs > WTAP_NSTIME_32BIT_SECS_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - netxray->start_secs = (guint32)rec->ts.secs; + netxray->start_secs = (uint32_t)rec->ts.secs; } /* build the header for each packet */ memset(&rec_hdr, '\0', sizeof(rec_hdr)); - timestamp = ((guint64)rec->ts.secs - (guint64)netxray->start_secs)*1000000 - + ((guint64)rec->ts.nsecs)/1000; - t32 = (guint32)(timestamp%G_GINT64_CONSTANT(4294967296)); + timestamp = ((uint64_t)rec->ts.secs - (uint64_t)netxray->start_secs)*1000000 + + ((uint64_t)rec->ts.nsecs)/1000; + t32 = (uint32_t)(timestamp%INT64_C(4294967296)); rec_hdr.timelo = GUINT32_TO_LE(t32); - t32 = (guint32)(timestamp/G_GINT64_CONSTANT(4294967296)); + t32 = (uint32_t)(timestamp/INT64_C(4294967296)); rec_hdr.timehi = GUINT32_TO_LE(t32); rec_hdr.orig_len = GUINT16_TO_LE(rec->rec_header.packet_header.len); rec_hdr.incl_len = GUINT16_TO_LE(rec->rec_header.packet_header.caplen); if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof(rec_hdr), err)) - return FALSE; + return false; /* write the packet data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; netxray->nframes++; - return TRUE; + return true; } /* Finish writing to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean -netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool +netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, char **err_info _U_) { char hdr_buf[CAPTUREFILE_HEADER_SIZE - sizeof(netxray_magic)]; netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; - gint64 filelen; + int64_t filelen; struct netxray_hdr file_hdr; if (-1 == (filelen = wtap_dump_file_tell(wdh, err))) - return FALSE; + return false; /* Go back to beginning */ if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) - return FALSE; + return false; /* Rewrite the file header. */ if (!wtap_dump_file_write(wdh, netxray_magic, sizeof netxray_magic, err)) - return FALSE; + return false; /* "sniffer" version ? */ memset(&file_hdr, '\0', sizeof file_hdr); @@ -1869,7 +1869,7 @@ netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_) file_hdr.nframes = GUINT32_TO_LE(netxray->nframes); file_hdr.start_offset = GUINT32_TO_LE(CAPTUREFILE_HEADER_SIZE); /* XXX - large files? */ - file_hdr.end_offset = GUINT32_TO_LE((guint32)filelen); + file_hdr.end_offset = GUINT32_TO_LE((uint32_t)filelen); file_hdr.network = wtap_encap_to_netxray_1_1_encap(wdh->file_encap); file_hdr.timelo = GUINT32_TO_LE(0); file_hdr.timehi = GUINT32_TO_LE(0); @@ -1877,11 +1877,11 @@ netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_) memset(hdr_buf, '\0', sizeof hdr_buf); memcpy(hdr_buf, &file_hdr, sizeof(file_hdr)); if (!wtap_dump_file_write(wdh, hdr_buf, sizeof hdr_buf, err)) - return FALSE; + return false; /* Don't double-count the size of the file header */ wdh->bytes_dumped = filelen; - return TRUE; + return true; } static const struct { @@ -1897,7 +1897,7 @@ static const struct { { WTAP_ENCAP_LAPB, 3 }, /* -> NDIS WAN */ { WTAP_ENCAP_SDLC, 3 }, /* -> NDIS WAN */ }; -#define NUM_WTAP_ENCAPS_2_0 (sizeof wtap_encap_2_0 / sizeof wtap_encap_2_0[0]) +#define NUM_WTAP_ENCAPS_2_0 array_length(wtap_encap_2_0) static int wtap_encap_to_netxray_2_0_encap(int encap) @@ -1927,10 +1927,10 @@ netxray_dump_can_write_encap_2_0(int encap) return 0; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -netxray_dump_open_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool +netxray_dump_open_2_0(wtap_dumper *wdh, int *err, char **err_info _U_) { netxray_dump_t *netxray; @@ -1942,35 +1942,35 @@ netxray_dump_open_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_) the header when we've written out all the packets, we just skip over the header for now. */ if (wtap_dump_file_seek(wdh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1) - return FALSE; + return false; wdh->bytes_dumped += CAPTUREFILE_HEADER_SIZE; netxray = g_new(netxray_dump_t, 1); wdh->priv = (void *)netxray; - netxray->first_frame = TRUE; + netxray->first_frame = true; netxray->start_secs = 0; netxray->nframes = 0; - return TRUE; + return true; } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean + Returns true on success, false on failure. */ +static bool netxray_dump_2_0(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; - guint64 timestamp; - guint32 t32; + uint64_t timestamp; + uint32_t t32; struct netxrayrec_2_x_hdr rec_hdr; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -1979,13 +1979,13 @@ netxray_dump_2_0(wtap_dumper *wdh, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* Don't write anything we're not willing to read. */ if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } /* NetXRay/Windows Sniffer files have a capture start date/time @@ -1999,30 +1999,30 @@ netxray_dump_2_0(wtap_dumper *wdh, packets being the delta between the stamp of the packet and the stamp of the first packet with the microseconds part 0. */ if (netxray->first_frame) { - netxray->first_frame = FALSE; + netxray->first_frame = false; /* * XXX - NetXRay ran on Windows, where MSVC's localtime() * can't handle time_t < 0, so *maybe* it makes sense * to allow time stamps up to 2^32-1 "seconds since the * Epoch", but maybe the start time in those files is * signed, in which case we should check against - * G_MININT32 and G_MAXINT32 and make start_secs a - * gint32. + * INT32_MIN and INT32_MAX and make start_secs a + * int32_t. */ if (rec->ts.secs < 0 || rec->ts.secs > WTAP_NSTIME_32BIT_SECS_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - netxray->start_secs = (guint32)rec->ts.secs; + netxray->start_secs = (uint32_t)rec->ts.secs; } /* build the header for each packet */ memset(&rec_hdr, '\0', sizeof(rec_hdr)); - timestamp = ((guint64)rec->ts.secs - (guint64)netxray->start_secs)*1000000 - + ((guint64)rec->ts.nsecs)/1000; - t32 = (guint32)(timestamp%G_GINT64_CONSTANT(4294967296)); + timestamp = ((uint64_t)rec->ts.secs - (uint64_t)netxray->start_secs)*1000000 + + ((uint64_t)rec->ts.nsecs)/1000; + t32 = (uint32_t)(timestamp%INT64_C(4294967296)); rec_hdr.timelo = GUINT32_TO_LE(t32); - t32 = (guint32)(timestamp/G_GINT64_CONSTANT(4294967296)); + t32 = (uint32_t)(timestamp/INT64_C(4294967296)); rec_hdr.timehi = GUINT32_TO_LE(t32); rec_hdr.orig_len = GUINT16_TO_LE(rec->rec_header.packet_header.len); rec_hdr.incl_len = GUINT16_TO_LE(rec->rec_header.packet_header.caplen); @@ -2036,7 +2036,7 @@ netxray_dump_2_0(wtap_dumper *wdh, 0; rec_hdr.xxx[13] = pseudo_header->ieee_802_11.has_data_rate ? - (guint8)pseudo_header->ieee_802_11.data_rate : + (uint8_t)pseudo_header->ieee_802_11.data_rate : 0; rec_hdr.xxx[14] = pseudo_header->ieee_802_11.has_signal_percent ? @@ -2059,37 +2059,37 @@ netxray_dump_2_0(wtap_dumper *wdh, } if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof(rec_hdr), err)) - return FALSE; + return false; /* write the packet data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; netxray->nframes++; - return TRUE; + return true; } /* Finish writing to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean -netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool +netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, char **err_info _U_) { char hdr_buf[CAPTUREFILE_HEADER_SIZE - sizeof(netxray_magic)]; netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; - gint64 filelen; + int64_t filelen; struct netxray_hdr file_hdr; if (-1 == (filelen = wtap_dump_file_tell(wdh, err))) - return FALSE; + return false; /* Go back to beginning */ if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) - return FALSE; + return false; /* Rewrite the file header. */ if (!wtap_dump_file_write(wdh, netxray_magic, sizeof netxray_magic, err)) - return FALSE; + return false; /* "sniffer" version ? */ memset(&file_hdr, '\0', sizeof file_hdr); @@ -2098,7 +2098,7 @@ netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_) file_hdr.nframes = GUINT32_TO_LE(netxray->nframes); file_hdr.start_offset = GUINT32_TO_LE(CAPTUREFILE_HEADER_SIZE); /* XXX - large files? */ - file_hdr.end_offset = GUINT32_TO_LE((guint32)filelen); + file_hdr.end_offset = GUINT32_TO_LE((uint32_t)filelen); file_hdr.network = wtap_encap_to_netxray_2_0_encap(wdh->file_encap); file_hdr.timelo = GUINT32_TO_LE(0); file_hdr.timehi = GUINT32_TO_LE(0); @@ -2129,11 +2129,11 @@ netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_) memset(hdr_buf, '\0', sizeof hdr_buf); memcpy(hdr_buf, &file_hdr, sizeof(file_hdr)); if (!wtap_dump_file_write(wdh, hdr_buf, sizeof hdr_buf, err)) - return FALSE; + return false; /* Don't double-count the size of the file header */ wdh->bytes_dumped = filelen; - return TRUE; + return true; } static const struct supported_block_type netxray_old_blocks_supported[] = { @@ -2145,7 +2145,7 @@ static const struct supported_block_type netxray_old_blocks_supported[] = { static const struct file_type_subtype_info netxray_old_info = { "Cinco Networks NetXRay 1.x", "netxray1", "cap", NULL, - TRUE, BLOCKS_SUPPORTED(netxray_old_blocks_supported), + true, BLOCKS_SUPPORTED(netxray_old_blocks_supported), NULL, NULL, NULL }; @@ -2158,7 +2158,7 @@ static const struct supported_block_type netxray_1_0_blocks_supported[] = { static const struct file_type_subtype_info netxray_1_0_info = { "Cinco Networks NetXRay 2.0 or later", "netxray2", "cap", NULL, - TRUE, BLOCKS_SUPPORTED(netxray_1_0_blocks_supported), + true, BLOCKS_SUPPORTED(netxray_1_0_blocks_supported), NULL, NULL, NULL }; @@ -2171,7 +2171,7 @@ static const struct supported_block_type netxray_1_1_blocks_supported[] = { static const struct file_type_subtype_info netxray_1_1_info = { "NetXray, Sniffer (Windows) 1.1", "ngwsniffer_1_1", "cap", NULL, - TRUE, BLOCKS_SUPPORTED(netxray_1_1_blocks_supported), + true, BLOCKS_SUPPORTED(netxray_1_1_blocks_supported), netxray_dump_can_write_encap_1_1, netxray_dump_open_1_1, NULL }; @@ -2184,7 +2184,7 @@ static const struct supported_block_type netxray_2_00x_blocks_supported[] = { static const struct file_type_subtype_info netxray_2_00x_info = { "Sniffer (Windows) 2.00x", "ngwsniffer_2_0", "cap", "caz", - TRUE, BLOCKS_SUPPORTED(netxray_2_00x_blocks_supported), + true, BLOCKS_SUPPORTED(netxray_2_00x_blocks_supported), netxray_dump_can_write_encap_2_0, netxray_dump_open_2_0, NULL }; diff --git a/wiretap/netxray.h b/wiretap/netxray.h index 68b24167..19824815 100644 --- a/wiretap/netxray.h +++ b/wiretap/netxray.h @@ -12,6 +12,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val netxray_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val netxray_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index 4ee4eda1..4b198c80 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -41,11 +41,11 @@ * */ #include "config.h" +#include "ngsniffer.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "ngsniffer.h" #include <wsutil/ws_assert.h> /* Magic number in Sniffer files. */ @@ -92,25 +92,25 @@ static const char ngsniffer_magic[] = { * Sniffer record header structure. */ struct rec_header { - guint16 type; /* record type */ - guint16 length; /* record length */ + uint16_t type; /* record type */ + uint16_t length; /* record length */ }; /* * Sniffer version record format. */ struct vers_rec { - gint16 maj_vers; /* major version number */ - gint16 min_vers; /* minor version number */ - gint16 time_dos; /* DOS-format time */ - gint16 date; /* DOS-format date */ - gint8 type; /* what type of records follow */ - guint8 network; /* network type */ - gint8 format; /* format version */ - guint8 timeunit; /* timestamp units */ - gint8 cmprs_vers; /* compression version */ - gint8 cmprs_level; /* compression level */ - gint16 rsvd[2]; /* reserved */ + int16_t maj_vers; /* major version number */ + int16_t min_vers; /* minor version number */ + int16_t time_dos; /* DOS-format time */ + int16_t date; /* DOS-format date */ + int8_t type; /* what type of records follow */ + uint8_t network; /* network type */ + int8_t format; /* format version */ + uint8_t timeunit; /* timestamp units */ + int8_t cmprs_vers; /* compression version */ + int8_t cmprs_level; /* compression level */ + int16_t rsvd[2]; /* reserved */ }; /* @@ -175,15 +175,15 @@ struct vers_rec { * the time when the capture starts). */ struct frame2_rec { - guint16 time_low; /* low part of time stamp */ - guint16 time_med; /* middle part of time stamp */ - guint8 time_high; /* high part of the time stamp */ - guint8 time_day; /* time in days since start of capture */ - gint16 size; /* number of bytes of data */ - guint8 fs; /* frame error status bits */ - guint8 flags; /* buffer flags */ - gint16 true_size; /* size of original frame, in bytes */ - gint16 rsvd; /* reserved */ + uint16_t time_low; /* low part of time stamp */ + uint16_t time_med; /* middle part of time stamp */ + uint8_t time_high; /* high part of the time stamp */ + uint8_t time_day; /* time in days since start of capture */ + int16_t size; /* number of bytes of data */ + uint8_t fs; /* frame error status bits */ + uint8_t flags; /* buffer flags */ + int16_t true_size; /* size of original frame, in bytes */ + int16_t rsvd; /* reserved */ }; /* @@ -259,28 +259,28 @@ struct frame2_rec { * rather than a cell. */ typedef struct _ATM_AAL5Trailer { - guint16 aal5t_u2u; /* user-to-user indicator */ - guint16 aal5t_len; /* length of the packet */ - guint32 aal5t_chksum; /* checksum for AAL5 packet */ + uint16_t aal5t_u2u; /* user-to-user indicator */ + uint16_t aal5t_len; /* length of the packet */ + uint32_t aal5t_chksum; /* checksum for AAL5 packet */ } ATM_AAL5Trailer; typedef struct _ATMTimeStamp { - guint32 msw; /* most significant word */ - guint32 lsw; /* least significant word */ + uint32_t msw; /* most significant word */ + uint32_t lsw; /* least significant word */ } ATMTimeStamp; typedef struct _ATMSaveInfo { - guint32 StatusWord; /* status word from driver */ + uint32_t StatusWord; /* status word from driver */ ATM_AAL5Trailer Trailer; /* AAL5 trailer */ - guint8 AppTrafType; /* traffic type */ - guint8 AppHLType; /* protocol type */ - guint16 AppReserved; /* reserved */ - guint16 Vpi; /* virtual path identifier */ - guint16 Vci; /* virtual circuit identifier */ - guint16 channel; /* link: 0 for DCE, 1 for DTE */ - guint16 cells; /* number of cells */ - guint32 AppVal1; /* type-dependent */ - guint32 AppVal2; /* type-dependent */ + uint8_t AppTrafType; /* traffic type */ + uint8_t AppHLType; /* protocol type */ + uint16_t AppReserved; /* reserved */ + uint16_t Vpi; /* virtual path identifier */ + uint16_t Vci; /* virtual circuit identifier */ + uint16_t channel; /* link: 0 for DCE, 1 for DTE */ + uint16_t cells; /* number of cells */ + uint32_t AppVal1; /* type-dependent */ + uint32_t AppVal2; /* type-dependent */ } ATMSaveInfo; /* @@ -355,16 +355,16 @@ typedef struct _ATMSaveInfo { #define AHLT_VCMX_BPDU 0xe /* VCMX: BPDU */ struct frame4_rec { - guint16 time_low; /* low part of time stamp */ - guint16 time_med; /* middle part of time stamp */ - guint8 time_high; /* high part of time stamp */ - guint8 time_day; /* time in days since start of capture */ - gint16 size; /* number of bytes of data */ - gint8 fs; /* frame error status bits */ - gint8 flags; /* buffer flags */ - gint16 true_size; /* size of original frame, in bytes */ - gint16 rsvd3; /* reserved */ - gint16 atm_pad; /* pad to 4-byte boundary */ + uint16_t time_low; /* low part of time stamp */ + uint16_t time_med; /* middle part of time stamp */ + uint8_t time_high; /* high part of time stamp */ + uint8_t time_day; /* time in days since start of capture */ + int16_t size; /* number of bytes of data */ + int8_t fs; /* frame error status bits */ + int8_t flags; /* buffer flags */ + int16_t true_size; /* size of original frame, in bytes */ + int16_t rsvd3; /* reserved */ + int16_t atm_pad; /* pad to 4-byte boundary */ ATMSaveInfo atm_info; /* ATM-specific stuff */ }; @@ -375,15 +375,15 @@ struct frame4_rec { * - Gerald */ struct frame6_rec { - guint16 time_low; /* low part of time stamp */ - guint16 time_med; /* middle part of time stamp */ - guint8 time_high; /* high part of time stamp */ - guint8 time_day; /* time in days since start of capture */ - gint16 size; /* number of bytes of data */ - guint8 fs; /* frame error status bits */ - guint8 flags; /* buffer flags */ - gint16 true_size; /* size of original frame, in bytes */ - guint8 chemical_x[22]; /* ? */ + uint16_t time_low; /* low part of time stamp */ + uint16_t time_med; /* middle part of time stamp */ + uint8_t time_high; /* high part of time stamp */ + uint8_t time_day; /* time in days since start of capture */ + int16_t size; /* number of bytes of data */ + uint8_t fs; /* frame error status bits */ + uint8_t flags; /* buffer flags */ + int16_t true_size; /* size of original frame, in bytes */ + uint8_t chemical_x[22];/* ? */ }; /* @@ -447,7 +447,7 @@ struct frame6_rec { * so that interpretation is probably wrong. Perhaps the interpretation * of V.timeunit depends on the version number of the file? */ -static const guint32 Psec[] = { +static const uint32_t Psec[] = { 15000000, /* 15.0 usecs = 15000000 psecs */ 838096, /* .838096 usecs = 838096 psecs */ 15000000, /* 15.0 usecs = 15000000 psecs */ @@ -457,24 +457,24 @@ static const guint32 Psec[] = { /* XXX - Sniffer doc says 0.08 usecs = 80000 psecs */ 100000 /* 0.1 usecs = 100000 psecs */ }; -#define NUM_NGSNIFF_TIMEUNITS (sizeof Psec / sizeof Psec[0]) +#define NUM_NGSNIFF_TIMEUNITS array_length(Psec) /* Information for a compressed Sniffer data stream. */ typedef struct { unsigned char *buf; /* buffer into which we uncompress data */ unsigned int nbytes; /* number of bytes of data in that buffer */ int nextout; /* offset in that buffer of stream's current position */ - gint64 comp_offset; /* current offset in compressed data stream */ - gint64 uncomp_offset; /* current offset in uncompressed data stream */ + int64_t comp_offset; /* current offset in compressed data stream */ + int64_t uncomp_offset; /* current offset in uncompressed data stream */ } ngsniffer_comp_stream_t; typedef struct { - guint maj_vers; - guint min_vers; - gboolean is_compressed; - guint32 timeunit; + unsigned maj_vers; + unsigned min_vers; + bool is_compressed; + uint32_t timeunit; time_t start; - guint network; /* network type */ + unsigned network; /* network type */ ngsniffer_comp_stream_t seq; /* sequential access */ ngsniffer_comp_stream_t rand; /* random access */ GList *first_blob; /* list element for first blob */ @@ -497,48 +497,48 @@ typedef struct { #define DOS_DAY_SHIFT 0 #define DOS_DAY_MASK (0x1F<<DOS_DAY_SHIFT) -static int process_header_records(wtap *wth, int *err, gchar **err_info, - gint16 maj_vers, guint8 network); +static int process_header_records(wtap *wth, int *err, char **err_info, + int16_t maj_vers, uint8_t network); static int process_rec_header2_v2(wtap *wth, unsigned char *buffer, - guint16 length, int *err, gchar **err_info); + uint16_t length, int *err, char **err_info); static int process_rec_header2_v145(wtap *wth, unsigned char *buffer, - guint16 length, gint16 maj_vers, int *err, gchar **err_info); -static gboolean ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean read_rec_header(wtap *wth, gboolean is_random, - struct rec_header *hdr, int *err, gchar **err_info); -static gboolean process_frame_record(wtap *wth, gboolean is_random, - guint *padding, struct rec_header *hdr, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + uint16_t length, int16_t maj_vers, int *err, char **err_info); +static bool ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool ngsniffer_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool read_rec_header(wtap *wth, bool is_random, + struct rec_header *hdr, int *err, char **err_info); +static bool process_frame_record(wtap *wth, bool is_random, + unsigned *padding, struct rec_header *hdr, wtap_rec *rec, Buffer *buf, + int *err, char **err_info); static void set_metadata_frame2(wtap *wth, wtap_rec *rec, struct frame2_rec *frame2); static void set_pseudo_header_frame4(union wtap_pseudo_header *pseudo_header, struct frame4_rec *frame4); static void set_pseudo_header_frame6(wtap *wth, union wtap_pseudo_header *pseudo_header, struct frame6_rec *frame6); -static int infer_pkt_encap(const guint8 *pd, int len); +static int infer_pkt_encap(const uint8_t *pd, int len); static int fix_pseudo_header(int encap, Buffer *buf, int len, union wtap_pseudo_header *pseudo_header); static void ngsniffer_sequential_close(wtap *wth); static void ngsniffer_close(wtap *wth); -static gboolean ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gboolean ngsniffer_dump_finish(wtap_dumper *wdh, int *err, - gchar **err_info); +static bool ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); +static bool ngsniffer_dump_finish(wtap_dumper *wdh, int *err, + char **err_info); static int SnifferDecompress( unsigned char * inbuf, size_t inlen, - unsigned char * outbuf, size_t outlen, int *err, gchar **err_info ); -static gboolean ng_read_bytes_or_eof(wtap *wth, void *buffer, - unsigned int nbytes, gboolean is_random, int *err, gchar **err_info); -static gboolean ng_read_bytes(wtap *wth, void *buffer, unsigned int nbytes, - gboolean is_random, int *err, gchar **err_info); -static gboolean read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, - int *err, gchar **err_info); -static gboolean ng_skip_bytes_seq(wtap *wth, unsigned int count, int *err, - gchar **err_info); -static gboolean ng_file_seek_rand(wtap *wth, gint64 offset, int *err, - gchar **err_info); + unsigned char * outbuf, size_t outlen, int *err, char **err_info ); +static bool ng_read_bytes_or_eof(wtap *wth, void *buffer, + unsigned int nbytes, bool is_random, int *err, char **err_info); +static bool ng_read_bytes(wtap *wth, void *buffer, unsigned int nbytes, + bool is_random, int *err, char **err_info); +static bool read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, + int *err, char **err_info); +static bool ng_skip_bytes_seq(wtap *wth, unsigned int count, int *err, + char **err_info); +static bool ng_file_seek_rand(wtap *wth, int64_t offset, int *err, + char **err_info); static int ngsniffer_uncompressed_file_type_subtype = -1; static int ngsniffer_compressed_file_type_subtype = -1; @@ -546,18 +546,18 @@ static int ngsniffer_compressed_file_type_subtype = -1; void register_ngsniffer(void); wtap_open_return_val -ngsniffer_open(wtap *wth, int *err, gchar **err_info) +ngsniffer_open(wtap *wth, int *err, char **err_info) { char magic[sizeof ngsniffer_magic]; char record_type[2]; char record_length[4]; /* only the first 2 bytes are length, the last 2 are "reserved" and are thrown away */ - guint16 type; + uint16_t type; struct vers_rec version; - guint16 maj_vers; - guint16 start_date; + uint16_t maj_vers; + uint16_t start_date; #if 0 - guint16 start_time; + uint16_t start_time; #endif static const int sniffer_encap[] = { WTAP_ENCAP_TOKEN_RING, @@ -572,9 +572,9 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) WTAP_ENCAP_FDDI_BITSWAPPED, WTAP_ENCAP_ATM_PDUS }; - #define NUM_NGSNIFF_ENCAPS (sizeof sniffer_encap / sizeof sniffer_encap[0]) + #define NUM_NGSNIFF_ENCAPS array_length(sniffer_encap) struct tm tm; - gint64 current_offset; + int64_t current_offset; ngsniffer_t *ngsniffer; /* Read in the string that should be at the start of a Sniffer file */ @@ -705,10 +705,10 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) /* compressed or uncompressed Sniffer file? */ if (version.format != 1) { wth->file_type_subtype = ngsniffer_compressed_file_type_subtype; - ngsniffer->is_compressed = TRUE; + ngsniffer->is_compressed = true; } else { wth->file_type_subtype = ngsniffer_uncompressed_file_type_subtype; - ngsniffer->is_compressed = FALSE; + ngsniffer->is_compressed = false; } ngsniffer->maj_vers = maj_vers; @@ -786,13 +786,13 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info) } static int -process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers, - guint8 network) +process_header_records(wtap *wth, int *err, char **err_info, int16_t maj_vers, + uint8_t network) { char record_type[2]; char record_length[4]; /* only the first 2 bytes are length, the last 2 are "reserved" and are thrown away */ - guint16 rec_type, rec_length_remaining; + uint16_t rec_type, rec_length_remaining; int bytes_to_read; unsigned char buffer[256]; @@ -882,8 +882,8 @@ process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers, } static int -process_rec_header2_v2(wtap *wth, unsigned char *buffer, guint16 length, - int *err, gchar **err_info) +process_rec_header2_v2(wtap *wth, unsigned char *buffer, uint16_t length, + int *err, char **err_info) { static const char x_25_str[] = "HDLC\nX.25\n"; @@ -918,8 +918,8 @@ process_rec_header2_v2(wtap *wth, unsigned char *buffer, guint16 length, } static int -process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length, - gint16 maj_vers, int *err, gchar **err_info) +process_rec_header2_v145(wtap *wth, unsigned char *buffer, uint16_t length, + int16_t maj_vers, int *err, char **err_info) { /* * The 5th byte of the REC_HEADER2 record appears to be a @@ -1025,13 +1025,13 @@ process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length, } /* Read the next packet */ -static gboolean +static bool ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { ngsniffer_t *ngsniffer; struct rec_header hdr; - guint padding; + unsigned padding; ngsniffer = (ngsniffer_t *)wth->priv; for (;;) { @@ -1044,9 +1044,9 @@ ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, /* * Read the record header. */ - if (!read_rec_header(wth, FALSE, &hdr, err, err_info)) { + if (!read_rec_header(wth, false, &hdr, err, err_info)) { /* Read error or short read */ - return FALSE; + return false; } /* @@ -1058,10 +1058,10 @@ ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, case REC_FRAME4: case REC_FRAME6: /* Frame record */ - if (!process_frame_record(wth, FALSE, &padding, + if (!process_frame_record(wth, false, &padding, &hdr, rec, buf, err, err_info)) { /* Read error, short read, or other error */ - return FALSE; + return false; } /* @@ -1070,9 +1070,9 @@ ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, if (padding != 0) { if (!ng_skip_bytes_seq(wth, padding, err, err_info)) - return FALSE; + return false; } - return TRUE; + return true; case REC_EOF: /* @@ -1083,10 +1083,10 @@ ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, if (hdr.length != 0) { if (!ng_skip_bytes_seq(wth, hdr.length, err, err_info)) - return FALSE; + return false; } *err = 0; /* EOF, not error */ - return FALSE; + return false; default: /* @@ -1098,25 +1098,25 @@ ngsniffer_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, if (hdr.length != 0) { if (!ng_skip_bytes_seq(wth, hdr.length, err, err_info)) - return FALSE; + return false; } break; } } } -static gboolean -ngsniffer_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +ngsniffer_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { struct rec_header hdr; if (!ng_file_seek_rand(wth, seek_off, err, err_info)) - return FALSE; + return false; - if (!read_rec_header(wth, TRUE, &hdr, err, err_info)) { + if (!read_rec_header(wth, true, &hdr, err, err_info)) { /* Read error or short read */ - return FALSE; + return false; } /* @@ -1128,10 +1128,10 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, case REC_FRAME4: case REC_FRAME6: /* Frame record */ - if (!process_frame_record(wth, TRUE, NULL, &hdr, rec, buf, + if (!process_frame_record(wth, true, NULL, &hdr, rec, buf, err, err_info)) { /* Read error, short read, or other error */ - return FALSE; + return false; } break; @@ -1141,20 +1141,20 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, * This "can't happen". */ ws_assert_not_reached(); - return FALSE; + return false; } - return TRUE; + return true; } /* * Read the record header. * - * Returns TRUE on success, FALSE on error. + * Returns true on success, false on error. */ -static gboolean -read_rec_header(wtap *wth, gboolean is_random, struct rec_header *hdr, - int *err, gchar **err_info) +static bool +read_rec_header(wtap *wth, bool is_random, struct rec_header *hdr, + int *err, char **err_info) { char record_type[2]; char record_length[4]; /* only 1st 2 bytes are length */ @@ -1164,7 +1164,7 @@ read_rec_header(wtap *wth, gboolean is_random, struct rec_header *hdr, */ if (!ng_read_bytes_or_eof(wth, record_type, 2, is_random, err, err_info)) { if (*err != 0) - return FALSE; + return false; /* * End-of-file; construct a fake EOF record. * (A file might have an EOF record at the end, or @@ -1173,38 +1173,38 @@ read_rec_header(wtap *wth, gboolean is_random, struct rec_header *hdr, */ hdr->type = REC_EOF; hdr->length = 0; - return TRUE; + return true; } /* * Read the record length. */ if (!ng_read_bytes(wth, record_length, 4, is_random, err, err_info)) - return FALSE; + return false; hdr->type = pletoh16(record_type); hdr->length = pletoh16(record_length); - return TRUE; + return true; } /* - * Returns TRUE on success, FALSE on error. + * Returns true on success, false on error. * If padding is non-null, sets *padding to the amount of padding at * the end of the record. */ -static gboolean -process_frame_record(wtap *wth, gboolean is_random, guint *padding, +static bool +process_frame_record(wtap *wth, bool is_random, unsigned *padding, struct rec_header *hdr, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info) + char **err_info) { ngsniffer_t *ngsniffer; - guint rec_length_remaining; + unsigned rec_length_remaining; struct frame2_rec frame2; struct frame4_rec frame4; struct frame6_rec frame6; - guint16 time_low, time_med, true_size, size; - guint8 time_high, time_day; - guint64 t, tsecs, tpsecs; + uint16_t time_low, time_med, true_size, size; + uint8_t time_high, time_day; + uint64_t t, tsecs, tpsecs; rec_length_remaining = hdr->length; @@ -1224,20 +1224,20 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("ngsniffer: REC_FRAME2 record in an ATM Sniffer file"); - return FALSE; + return false; } /* Do we have an f_frame2_struct worth of data? */ if (rec_length_remaining < sizeof frame2) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("ngsniffer: REC_FRAME2 record length is less than record header length"); - return FALSE; + return false; } /* Read the f_frame2_struct */ if (!ng_read_bytes(wth, &frame2, (unsigned int)sizeof frame2, is_random, err, err_info)) - return FALSE; + return false; time_low = pletoh16(&frame2.time_low); time_med = pletoh16(&frame2.time_med); time_high = frame2.time_high; @@ -1245,7 +1245,7 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, size = pletoh16(&frame2.size); true_size = pletoh16(&frame2.true_size); - rec_length_remaining -= (guint)sizeof frame2; /* we already read that much */ + rec_length_remaining -= (unsigned)sizeof frame2; /* we already read that much */ set_metadata_frame2(wth, rec, &frame2); break; @@ -1258,7 +1258,7 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("ngsniffer: REC_FRAME4 record in a non-ATM Sniffer file"); - return FALSE; + return false; } /* @@ -1269,19 +1269,19 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, * record, so it's too short by (sizeof frame4 - sizeof frame2). */ if (ngsniffer->maj_vers < 5 && ngsniffer->min_vers >= 95) - rec_length_remaining += (guint)(sizeof frame4 - sizeof frame2); + rec_length_remaining += (unsigned)(sizeof frame4 - sizeof frame2); /* Do we have an f_frame4_struct worth of data? */ if (rec_length_remaining < sizeof frame4) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("ngsniffer: REC_FRAME4 record length is less than record header length"); - return FALSE; + return false; } /* Read the f_frame4_struct */ if (!ng_read_bytes(wth, &frame4, (unsigned int)sizeof frame4, is_random, err, err_info)) - return FALSE; + return false; time_low = pletoh16(&frame4.time_low); time_med = pletoh16(&frame4.time_med); time_high = frame4.time_high; @@ -1289,7 +1289,7 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, size = pletoh16(&frame4.size); true_size = pletoh16(&frame4.true_size); - rec_length_remaining -= (guint)sizeof frame4; /* we already read that much */ + rec_length_remaining -= (unsigned)sizeof frame4; /* we already read that much */ set_pseudo_header_frame4(&rec->rec_header.packet_header.pseudo_header, &frame4); break; @@ -1299,13 +1299,13 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, if (rec_length_remaining < sizeof frame6) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("ngsniffer: REC_FRAME6 record length is less than record header length"); - return FALSE; + return false; } /* Read the f_frame6_struct */ if (!ng_read_bytes(wth, &frame6, (unsigned int)sizeof frame6, is_random, err, err_info)) - return FALSE; + return false; time_low = pletoh16(&frame6.time_low); time_med = pletoh16(&frame6.time_med); time_high = frame6.time_high; @@ -1313,7 +1313,7 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, size = pletoh16(&frame6.size); true_size = pletoh16(&frame6.true_size); - rec_length_remaining -= (guint)sizeof frame6; /* we already read that much */ + rec_length_remaining -= (unsigned)sizeof frame6; /* we already read that much */ set_pseudo_header_frame6(wth, &rec->rec_header.packet_header.pseudo_header, &frame6); break; @@ -1323,7 +1323,7 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, * This should never happen. */ ws_assert_not_reached(); - return FALSE; + return false; } /* @@ -1336,7 +1336,7 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("ngsniffer: Record length is less than packet size"); - return FALSE; + return false; } /* @@ -1362,7 +1362,7 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, ws_buffer_assure_space(buf, size); if (!ng_read_bytes(wth, ws_buffer_start_ptr(buf), size, is_random, err, err_info)) - return FALSE; + return false; rec->rec_header.packet_header.pkt_encap = fix_pseudo_header(wth->file_encap, buf, size, &rec->rec_header.packet_header.pseudo_header); @@ -1370,7 +1370,7 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, /* * 40-bit time stamp, in units of timeunit picoseconds. */ - t = (((guint64)time_high)<<32) | (((guint64)time_med) << 16) | time_low; + t = (((uint64_t)time_high)<<32) | (((uint64_t)time_med) << 16) | time_low; /* * timeunit is always < 2^(64-40), so t * timeunit fits in 64 @@ -1382,8 +1382,8 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, /* * Convert to seconds and picoseconds. */ - tsecs = t/G_GUINT64_CONSTANT(1000000000000); - tpsecs = t - tsecs*G_GUINT64_CONSTANT(1000000000000); + tsecs = t/UINT64_C(1000000000000); + tpsecs = t - tsecs*UINT64_C(1000000000000); /* * Add in the time_day value (86400 seconds/day). @@ -1398,14 +1398,14 @@ process_frame_record(wtap *wth, gboolean is_random, guint *padding, rec->ts.secs = (time_t)tsecs; rec->ts.nsecs = (int)(tpsecs/1000); /* psecs to nsecs */ - return TRUE; /* success */ + return true; /* success */ } static void set_metadata_frame2(wtap *wth, wtap_rec *rec, struct frame2_rec *frame2) { ngsniffer_t *ngsniffer; - guint32 pack_flags; + uint32_t pack_flags; union wtap_pseudo_header *pseudo_header; ngsniffer = (ngsniffer_t *)wth->priv; @@ -1497,7 +1497,7 @@ set_metadata_frame2(wtap *wth, wtap_rec *rec, struct frame2_rec *frame2) case WTAP_ENCAP_PPP_WITH_PHDR: case WTAP_ENCAP_SDLC: - pseudo_header->p2p.sent = (frame2->fs & FS_WAN_DTE) ? TRUE : FALSE; + pseudo_header->p2p.sent = (frame2->fs & FS_WAN_DTE) ? true : false; break; case WTAP_ENCAP_LAPB: @@ -1507,7 +1507,7 @@ set_metadata_frame2(wtap *wth, wtap_rec *rec, struct frame2_rec *frame2) break; case WTAP_ENCAP_ISDN: - pseudo_header->isdn.uton = (frame2->fs & FS_WAN_DTE) ? FALSE : TRUE; + pseudo_header->isdn.uton = (frame2->fs & FS_WAN_DTE) ? false : true; switch (frame2->fs & FS_ISDN_CHAN_MASK) { case FS_ISDN_CHAN_D: @@ -1533,9 +1533,9 @@ static void set_pseudo_header_frame4(union wtap_pseudo_header *pseudo_header, struct frame4_rec *frame4) { - guint32 StatusWord; - guint8 aal_type, hl_type; - guint16 vpi, vci; + uint32_t StatusWord; + uint8_t aal_type, hl_type; + uint16_t vpi, vci; /* * Map flags from frame4.atm_info.StatusWord. @@ -1812,7 +1812,7 @@ set_pseudo_header_frame6(wtap *wth, union wtap_pseudo_header *pseudo_header, * tell us what type of capture it is?) */ static int -infer_pkt_encap(const guint8 *pd, int len) +infer_pkt_encap(const uint8_t *pd, int len) { int i; @@ -1901,7 +1901,7 @@ static int fix_pseudo_header(int encap, Buffer *buf, int len, union wtap_pseudo_header *pseudo_header) { - const guint8 *pd; + const uint8_t *pd; pd = ws_buffer_start_ptr(buf); switch (encap) { @@ -1922,16 +1922,16 @@ fix_pseudo_header(int encap, Buffer *buf, int len, case WTAP_ENCAP_CHDLC_WITH_PHDR: case WTAP_ENCAP_PPP_WITH_PHDR: if (pseudo_header->dte_dce.flags == 0) - pseudo_header->p2p.sent = TRUE; + pseudo_header->p2p.sent = true; else - pseudo_header->p2p.sent = FALSE; + pseudo_header->p2p.sent = false; break; case WTAP_ENCAP_ISDN: if (pseudo_header->dte_dce.flags == 0x00) - pseudo_header->isdn.uton = FALSE; + pseudo_header->isdn.uton = false; else - pseudo_header->isdn.uton = TRUE; + pseudo_header->isdn.uton = true; /* * XXX - this is currently a per-packet @@ -2002,7 +2002,7 @@ ngsniffer_sequential_close(wtap *wth) } static void -free_blob(gpointer data, gpointer user_data _U_) +free_blob(void *data, void *user_data _U_) { g_free(data); } @@ -2023,7 +2023,7 @@ ngsniffer_close(wtap *wth) } typedef struct { - gboolean first_frame; + bool first_frame; time_t start; } ngsniffer_dump_t; @@ -2048,7 +2048,7 @@ static const int wtap_encap[] = { -1, /* WTAP_ENCAP_IP_OVER_FC -> unsupported */ 7, /* WTAP_ENCAP_PPP_WITH_PHDR -> Internetwork analyzer (synchronous) FIXME ! */ }; -#define NUM_WTAP_ENCAPS (sizeof wtap_encap / sizeof wtap_encap[0]) +#define NUM_WTAP_ENCAPS array_length(wtap_encap) /* Returns 0 if we could write the specified encapsulation type, an error indication otherwise. */ @@ -2065,10 +2065,10 @@ ngsniffer_dump_can_write_encap(int encap) return 0; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -ngsniffer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool +ngsniffer_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { ngsniffer_dump_t *ngsniffer; char buf[6] = {REC_VERS, 0x00, 0x12, 0x00, 0x00, 0x00}; /* version record */ @@ -2079,42 +2079,42 @@ ngsniffer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) ngsniffer = g_new(ngsniffer_dump_t, 1); wdh->priv = (void *)ngsniffer; - ngsniffer->first_frame = TRUE; + ngsniffer->first_frame = true; ngsniffer->start = 0; /* Write the file header. */ if (!wtap_dump_file_write(wdh, ngsniffer_magic, sizeof ngsniffer_magic, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, buf, 6, err)) - return FALSE; + return false; - return TRUE; + return true; } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean + Returns true on success, false on failure. */ +static bool ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; ngsniffer_dump_t *ngsniffer = (ngsniffer_dump_t *)wdh->priv; struct frame2_rec rec_hdr; char buf[6]; time_t tsecs; - guint64 t; - guint16 t_low, t_med; - guint8 t_high; + uint64_t t; + uint16_t t_low, t_med; + uint8_t t_high; struct vers_rec version; - gint16 maj_vers, min_vers; - guint16 start_date; + int16_t maj_vers, min_vers; + uint16_t start_date; struct tm *tm; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -2123,14 +2123,14 @@ ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* The captured length field is 16 bits, so there's a hard limit of 65535. */ if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } /* Sniffer files have a capture start date in the file header, and @@ -2138,7 +2138,7 @@ ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, headers; pick the date of the first packet as the capture start date. */ if (ngsniffer->first_frame) { - ngsniffer->first_frame=FALSE; + ngsniffer->first_frame=false; tm = localtime(&rec->ts.secs); if (tm != NULL && tm->tm_year >= DOS_YEAR_OFFSET) { start_date = (tm->tm_year - DOS_YEAR_OFFSET) << DOS_YEAR_SHIFT; @@ -2167,7 +2167,7 @@ ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, version.rsvd[0] = 0; version.rsvd[1] = 0; if (!wtap_dump_file_write(wdh, &version, sizeof version, err)) - return FALSE; + return false; } buf[0] = REC_FRAME2; @@ -2177,20 +2177,20 @@ ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, buf[4] = 0x00; buf[5] = 0x00; if (!wtap_dump_file_write(wdh, buf, 6, err)) - return FALSE; + return false; /* Seconds since the start of the capture */ tsecs = rec->ts.secs - ngsniffer->start; /* Extract the number of days since the start of the capture */ - rec_hdr.time_day = (guint8)(tsecs / 86400); /* # days of capture - 86400 secs/day */ + rec_hdr.time_day = (uint8_t)(tsecs / 86400); /* # days of capture - 86400 secs/day */ tsecs -= rec_hdr.time_day * 86400; /* time within day */ /* Convert to picoseconds */ - t = tsecs*G_GUINT64_CONSTANT(1000000000000) + - rec->ts.nsecs*G_GUINT64_CONSTANT(1000); + t = tsecs*UINT64_C(1000000000000) + + rec->ts.nsecs*UINT64_C(1000); /* Convert to units of timeunit = 1 */ t /= Psec[1]; - t_low = (guint16)((t >> 0) & 0xFFFF); - t_med = (guint16)((t >> 16) & 0xFFFF); - t_high = (guint8)((t >> 32) & 0xFF); + t_low = (uint16_t)((t >> 0) & 0xFFFF); + t_med = (uint16_t)((t >> 16) & 0xFFFF); + t_high = (uint8_t)((t >> 32) & 0xFF); rec_hdr.time_low = GUINT16_TO_LE(t_low); rec_hdr.time_med = GUINT16_TO_LE(t_med); rec_hdr.time_high = t_high; @@ -2233,23 +2233,23 @@ ngsniffer_dump(wtap_dumper *wdh, const wtap_rec *rec, rec_hdr.true_size = rec->rec_header.packet_header.len != rec->rec_header.packet_header.caplen ? GUINT16_TO_LE(rec->rec_header.packet_header.len) : 0; rec_hdr.rsvd = 0; if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; - return TRUE; + return false; + return true; } /* Finish writing to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean -ngsniffer_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool +ngsniffer_dump_finish(wtap_dumper *wdh, int *err, char **err_info _U_) { /* EOF record */ char buf[6] = {REC_EOF, 0x00, 0x00, 0x00, 0x00, 0x00}; if (!wtap_dump_file_write(wdh, buf, 6, err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -2347,7 +2347,7 @@ ngsniffer_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info _U_) static int SnifferDecompress(unsigned char *inbuf, size_t inlen, unsigned char *outbuf, - size_t outlen, int *err, gchar **err_info) + size_t outlen, int *err, char **err_info) { unsigned char * pin = inbuf; unsigned char * pout = outbuf; @@ -2360,7 +2360,7 @@ SnifferDecompress(unsigned char *inbuf, size_t inlen, unsigned char *outbuf, int length; /* length of RLE sequence or repeated string */ int offset; /* offset of string to repeat */ - if (inlen > G_MAXUINT16) { + if (inlen > UINT16_MAX) { return ( -1 ); } @@ -2484,13 +2484,13 @@ SnifferDecompress(unsigned char *inbuf, size_t inlen, unsigned char *outbuf, underlying compressed file, and the offset in the uncompressed data stream, of the blob. */ typedef struct { - gint64 blob_comp_offset; - gint64 blob_uncomp_offset; + int64_t blob_comp_offset; + int64_t blob_uncomp_offset; } blob_info_t; -static gboolean -ng_read_bytes_or_eof(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_random, - int *err, gchar **err_info) +static bool +ng_read_bytes_or_eof(wtap *wth, void *buffer, unsigned int nbytes, bool is_random, + int *err, char **err_info) { ngsniffer_t *ngsniffer; FILE_T infile; @@ -2512,10 +2512,10 @@ ng_read_bytes_or_eof(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_r if (!ngsniffer->is_compressed) { /* Uncompressed - just read bytes */ if (!wtap_read_bytes_or_eof(infile, buffer, nbytes, err, err_info)) - return FALSE; + return false; comp_stream->uncomp_offset += nbytes; comp_stream->comp_offset += nbytes; - return TRUE; + return true; } /* @@ -2550,7 +2550,7 @@ ng_read_bytes_or_eof(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_r /* Now read the first blob into the buffer. */ if (!read_blob(infile, comp_stream, err, err_info)) - return FALSE; + return false; } while (nbytes > 0) { bytes_left = comp_stream->nbytes - comp_stream->nextout; @@ -2567,7 +2567,7 @@ ng_read_bytes_or_eof(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_r * blob for every byte in the file. */ *err = WTAP_ERR_CANT_SEEK; - return FALSE; + return false; } } else { /* If we also have a random stream open, add a new element, @@ -2585,7 +2585,7 @@ ng_read_bytes_or_eof(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_r } if (!read_blob(infile, comp_stream, err, err_info)) - return FALSE; + return false; bytes_left = comp_stream->nbytes - comp_stream->nextout; } @@ -2599,12 +2599,12 @@ ng_read_bytes_or_eof(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_r comp_stream->nextout += bytes_to_copy; comp_stream->uncomp_offset += bytes_to_copy; } - return TRUE; + return true; } -static gboolean -ng_read_bytes(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_random, - int *err, gchar **err_info) +static bool +ng_read_bytes(wtap *wth, void *buffer, unsigned int nbytes, bool is_random, + int *err, char **err_info) { if (!ng_read_bytes_or_eof(wth, buffer, nbytes, is_random, err, err_info)) { /* @@ -2613,27 +2613,27 @@ ng_read_bytes(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_random, */ if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } /* Read a blob from a compressed stream. - Return FALSE and set "*err" and "*err_info" on error, otherwise return TRUE. */ -static gboolean + Return false and set "*err" and "*err_info" on error, otherwise return true. */ +static bool read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err, - gchar **err_info) + char **err_info) { int in_len; unsigned short blob_len; - gint16 blob_len_host; - gboolean uncompressed; + int16_t blob_len_host; + bool uncompressed; unsigned char *file_inbuf; int out_len; /* Read one 16-bit word which is length of next compressed blob */ if (!wtap_read_bytes_or_eof(infile, &blob_len, 2, err, err_info)) - return FALSE; + return false; comp_stream->comp_offset += 2; blob_len_host = pletoh16(&blob_len); @@ -2641,10 +2641,10 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err, if (blob_len_host < 0) { /* Uncompressed blob; blob length is absolute value of the number. */ in_len = -blob_len_host; - uncompressed = TRUE; + uncompressed = true; } else { in_len = blob_len_host; - uncompressed = FALSE; + uncompressed = false; } file_inbuf = (unsigned char *)g_malloc(INBUF_SIZE); @@ -2652,7 +2652,7 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err, /* Read the blob */ if (!wtap_read_bytes(infile, file_inbuf, in_len, err, err_info)) { g_free(file_inbuf); - return FALSE; + return false; } comp_stream->comp_offset += in_len; @@ -2666,19 +2666,19 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err, err_info); if (out_len < 0) { g_free(file_inbuf); - return FALSE; + return false; } } g_free(file_inbuf); comp_stream->nextout = 0; comp_stream->nbytes = out_len; - return TRUE; + return true; } /* Skip some number of bytes forward in the sequential stream. */ -static gboolean -ng_skip_bytes_seq(wtap *wth, unsigned int count, int *err, gchar **err_info) +static bool +ng_skip_bytes_seq(wtap *wth, unsigned int count, int *err, char **err_info) { ngsniffer_t *ngsniffer; char *buf; @@ -2704,16 +2704,16 @@ ng_skip_bytes_seq(wtap *wth, unsigned int count, int *err, gchar **err_info) else amount_to_read = count; - if (!ng_read_bytes(wth, buf, amount_to_read, FALSE, err, err_info)) { + if (!ng_read_bytes(wth, buf, amount_to_read, false, err, err_info)) { g_free(buf); - return FALSE; /* error */ + return false; /* error */ } count -= amount_to_read; } g_free(buf); - return TRUE; + return true; } /* Seek to a given offset in the random data stream. @@ -2724,11 +2724,11 @@ ng_skip_bytes_seq(wtap *wth, unsigned int count, int *err, gchar **err_info) we're seeking, and read that blob in. We can then move to the appropriate position within the blob we have in memory (whether it's the blob we already had in memory or, if necessary, the one we read in). */ -static gboolean -ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info) +static bool +ng_file_seek_rand(wtap *wth, int64_t offset, int *err, char **err_info) { ngsniffer_t *ngsniffer; - gint64 delta; + int64_t delta; GList *new_list, *next_list; blob_info_t *next_blob, *new_blob; @@ -2737,8 +2737,8 @@ ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info) if (!ngsniffer->is_compressed) { /* Uncompressed - just seek. */ if (file_seek(wth->random_fh, offset, SEEK_SET, err) == -1) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -2790,7 +2790,7 @@ ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info) * we've read so far. */ *err = WTAP_ERR_CANT_SEEK; - return FALSE; + return false; } } } else if (delta < 0) { @@ -2825,7 +2825,7 @@ ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info) * XXX - shouldn't happen. */ *err = WTAP_ERR_CANT_SEEK; - return FALSE; + return false; } } } @@ -2838,7 +2838,7 @@ ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info) /* Seek in the compressed file to the offset in the compressed file of the beginning of that blob. */ if (file_seek(wth->random_fh, new_blob->blob_comp_offset, SEEK_SET, err) == -1) - return FALSE; + return false; /* * Do we have a buffer for the random stream yet? @@ -2860,7 +2860,7 @@ ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info) /* Now fill the buffer. */ if (!read_blob(wth->random_fh, &ngsniffer->rand, err, err_info)) - return FALSE; + return false; /* Set "delta" to the amount to move within this blob; it had better be >= 0, and < the amount of uncompressed data in @@ -2877,7 +2877,7 @@ ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info) ngsniffer->rand.nextout += (int) delta; ngsniffer->rand.uncomp_offset += delta; - return TRUE; + return true; } static const struct supported_block_type ngsniffer_uncompressed_blocks_supported[] = { @@ -2889,7 +2889,7 @@ static const struct supported_block_type ngsniffer_uncompressed_blocks_supported static const struct file_type_subtype_info ngsniffer_uncompressed_info = { "Sniffer (DOS)", "ngsniffer", "cap", "enc;trc;fdc;syc", - FALSE, BLOCKS_SUPPORTED(ngsniffer_uncompressed_blocks_supported), + false, BLOCKS_SUPPORTED(ngsniffer_uncompressed_blocks_supported), ngsniffer_dump_can_write_encap, ngsniffer_dump_open, NULL }; @@ -2902,7 +2902,7 @@ static const struct supported_block_type ngsniffer_compressed_blocks_supported[] static const struct file_type_subtype_info ngsniffer_compressed_info = { "Sniffer (DOS), compressed", "ngsniffer_comp", "cap", "enc;trc;fdc;syc", - FALSE, BLOCKS_SUPPORTED(ngsniffer_compressed_blocks_supported), + false, BLOCKS_SUPPORTED(ngsniffer_compressed_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/ngsniffer.h b/wiretap/ngsniffer.h index 0a391f85..c0f620ba 100644 --- a/wiretap/ngsniffer.h +++ b/wiretap/ngsniffer.h @@ -12,6 +12,6 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val ngsniffer_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val ngsniffer_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/observer.c b/wiretap/observer.c index 6a745c14..61cbec9c 100644 --- a/wiretap/observer.c +++ b/wiretap/observer.c @@ -13,18 +13,18 @@ ***************************************************************************/ #include "config.h" +#include "observer.h" #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "observer.h" #include <wsutil/802_11-utils.h> static const char observer_magic[] = {"ObserverPktBufferVersion=15.00"}; static const int true_magic_length = 17; -static const guint32 observer_packet_magic = 0x88888888; +static const uint32_t observer_packet_magic = 0x88888888; /* * This structure is used to keep state when writing files. An instance is @@ -32,9 +32,9 @@ static const guint32 observer_packet_magic = 0x88888888; * pointer field. */ typedef struct { - guint64 packet_count; - guint8 network_type; - guint32 time_format; + uint64_t packet_count; + uint8_t network_type; + uint32_t time_format; } observer_dump_private_state; /* @@ -98,36 +98,36 @@ static const char *init_gmt_to_localtime_offset(void) return NULL; } -static gboolean observer_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean observer_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool observer_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool observer_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header, - packet_entry_header *packet_header, int *err, gchar **err_info); -static gboolean process_packet_header(wtap *wth, + packet_entry_header *packet_header, int *err, char **err_info); +static bool process_packet_header(wtap *wth, packet_entry_header *packet_header, wtap_rec *rec, int *err, - gchar **err_info); + char **err_info); static int read_packet_data(FILE_T fh, int offset_to_frame, int current_offset_from_packet_header, Buffer *buf, int length, int *err, char **err_info); -static gboolean skip_to_next_packet(wtap *wth, int offset_to_next_packet, +static bool skip_to_next_packet(wtap *wth, int offset_to_next_packet, int current_offset_from_packet_header, int *err, char **err_info); -static gboolean observer_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gint observer_to_wtap_encap(int observer_encap); -static gint wtap_to_observer_encap(int wtap_encap); +static bool observer_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); +static int observer_to_wtap_encap(int observer_encap); +static int wtap_to_observer_encap(int wtap_encap); static int observer_file_type_subtype = -1; void register_observer(void); -wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val observer_open(wtap *wth, int *err, char **err_info) { - guint offset; + unsigned offset; capture_file_header file_header; - guint header_offset; - guint i; + unsigned header_offset; + unsigned i; tlv_header tlvh; - guint seek_increment; + unsigned seek_increment; packet_entry_header packet_header; observer_dump_private_state * private_state = NULL; const char *err_str; @@ -141,7 +141,7 @@ wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_ERROR; return WTAP_OPEN_NOT_MINE; } - offset += (guint)sizeof file_header; + offset += (unsigned)sizeof file_header; CAPTURE_FILE_HEADER_FROM_LE_IN_PLACE(file_header); /* check if version info is present */ @@ -151,7 +151,7 @@ wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info) /* get the location of the first packet */ /* v15 and newer uses high byte offset, in previous versions it will be 0 */ - header_offset = file_header.offset_to_first_packet + ((guint)(file_header.offset_to_first_packet_high_byte)<<16); + header_offset = file_header.offset_to_first_packet + ((unsigned)(file_header.offset_to_first_packet_high_byte)<<16); if (offset > header_offset) { /* @@ -169,13 +169,13 @@ wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info) /* process extra information */ for (i = 0; i < file_header.number_of_information_elements; i++) { - guint tlv_data_length; + unsigned tlv_data_length; /* * Make sure reading the TLV header won't put us in the middle * of the packet data. */ - if (offset + (guint)sizeof tlvh > header_offset) { + if (offset + (unsigned)sizeof tlvh > header_offset) { /* * We're at or past the point where the packet data begins, * but we have the IE header to read. @@ -188,7 +188,7 @@ wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info) /* read the TLV header */ if (!wtap_read_bytes(wth->fh, &tlvh, sizeof tlvh, err, err_info)) return WTAP_OPEN_ERROR; - offset += (guint)sizeof tlvh; + offset += (unsigned)sizeof tlvh; TLV_HEADER_FROM_LE_IN_PLACE(tlvh); if (tlvh.length < sizeof tlvh) { @@ -198,7 +198,7 @@ wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_ERROR; } - tlv_data_length = tlvh.length - (guint)sizeof tlvh; + tlv_data_length = tlvh.length - (unsigned)sizeof tlvh; /* * Make sure reading the TLV data won't put us in the middle * of the packet data. @@ -229,7 +229,7 @@ wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info) err, err_info)) return WTAP_OPEN_ERROR; private_state->time_format = GUINT32_FROM_LE(private_state->time_format); - offset += (guint)sizeof private_state->time_format; + offset += (unsigned)sizeof private_state->time_format; break; default: if (tlv_data_length != 0) { @@ -322,8 +322,8 @@ wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info) } /* Reads the next packet. */ -static gboolean observer_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool observer_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { int header_bytes_consumed; int data_bytes_consumed; @@ -337,7 +337,7 @@ static gboolean observer_read(wtap *wth, wtap_rec *rec, Buffer *buf, header_bytes_consumed = read_packet_header(wth, wth->fh, &rec->rec_header.packet_header.pseudo_header, &packet_header, err, err_info); if (header_bytes_consumed <= 0) - return FALSE; /* EOF or error */ + return false; /* EOF or error */ if (packet_header.packet_type == PACKET_TYPE_DATA_PACKET) break; @@ -345,33 +345,33 @@ static gboolean observer_read(wtap *wth, wtap_rec *rec, Buffer *buf, /* skip to next packet */ if (!skip_to_next_packet(wth, packet_header.offset_to_next_packet, header_bytes_consumed, err, err_info)) { - return FALSE; /* EOF or error */ + return false; /* EOF or error */ } } if (!process_packet_header(wth, &packet_header, rec, err, err_info)) - return FALSE; + return false; /* read the frame data */ data_bytes_consumed = read_packet_data(wth->fh, packet_header.offset_to_frame, header_bytes_consumed, buf, rec->rec_header.packet_header.caplen, err, err_info); if (data_bytes_consumed < 0) { - return FALSE; + return false; } /* skip over any extra bytes following the frame data */ if (!skip_to_next_packet(wth, packet_header.offset_to_next_packet, header_bytes_consumed + data_bytes_consumed, err, err_info)) { - return FALSE; + return false; } - return TRUE; + return true; } /* Reads a packet at an offset. */ -static gboolean observer_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool observer_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; packet_entry_header packet_header; @@ -379,33 +379,33 @@ static gboolean observer_seek_read(wtap *wth, gint64 seek_off, int data_bytes_consumed; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* process the packet header, including TLVs */ offset = read_packet_header(wth, wth->random_fh, pseudo_header, &packet_header, err, err_info); if (offset <= 0) - return FALSE; /* EOF or error */ + return false; /* EOF or error */ if (!process_packet_header(wth, &packet_header, rec, err, err_info)) - return FALSE; + return false; /* read the frame data */ data_bytes_consumed = read_packet_data(wth->random_fh, packet_header.offset_to_frame, offset, buf, rec->rec_header.packet_header.caplen, err, err_info); if (data_bytes_consumed < 0) { - return FALSE; + return false; } - return TRUE; + return true; } static int read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header, - packet_entry_header *packet_header, int *err, gchar **err_info) + packet_entry_header *packet_header, int *err, char **err_info) { int offset; - guint i; + unsigned i; tlv_header tlvh; tlv_wireless_info wireless_header; @@ -432,7 +432,7 @@ read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header * rather than treat it as a bad record. */ for (i = 0; i < sizeof *packet_header; i++) { - if (((guint8*) packet_header)[i] != 0) + if (((uint8_t*) packet_header)[i] != 0) break; } if (i == sizeof *packet_header) { @@ -455,8 +455,8 @@ read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: memset(&pseudo_header->ieee_802_11, 0, sizeof(pseudo_header->ieee_802_11)); pseudo_header->ieee_802_11.fcs_len = 0; - pseudo_header->ieee_802_11.decrypted = FALSE; - pseudo_header->ieee_802_11.datapad = FALSE; + pseudo_header->ieee_802_11.decrypted = false; + pseudo_header->ieee_802_11.datapad = false; pseudo_header->ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; /* Updated below */ break; @@ -464,7 +464,7 @@ read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header /* process extra information */ for (i = 0; i < packet_header->number_of_information_elements; i++) { - guint tlv_data_length; + unsigned tlv_data_length; /* read the TLV header */ if (!wtap_read_bytes(fh, &tlvh, sizeof tlvh, err, err_info)) @@ -478,7 +478,7 @@ read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header tlvh.length, sizeof tlvh); return -1; } - tlv_data_length = tlvh.length - (guint)sizeof tlvh; + tlv_data_length = tlvh.length - (unsigned)sizeof tlvh; /* process (or skip over) the current TLV */ switch (tlvh.type) { @@ -495,11 +495,11 @@ read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header /* set decryption status */ /* XXX - what other bits are there in conditions? */ pseudo_header->ieee_802_11.decrypted = (wireless_header.conditions & WIRELESS_WEP_SUCCESS) != 0; - pseudo_header->ieee_802_11.has_channel = TRUE; + pseudo_header->ieee_802_11.has_channel = true; pseudo_header->ieee_802_11.channel = wireless_header.frequency; - pseudo_header->ieee_802_11.has_data_rate = TRUE; + pseudo_header->ieee_802_11.has_data_rate = true; pseudo_header->ieee_802_11.data_rate = wireless_header.rate; - pseudo_header->ieee_802_11.has_signal_percent = TRUE; + pseudo_header->ieee_802_11.has_signal_percent = true; pseudo_header->ieee_802_11.signal_percent = wireless_header.strengthPercent; /* @@ -509,18 +509,18 @@ read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header if (RATE_IS_DSSS(pseudo_header->ieee_802_11.data_rate)) { /* 11b */ pseudo_header->ieee_802_11.phy = PHDR_802_11_PHY_11B; - pseudo_header->ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE; + pseudo_header->ieee_802_11.phy_info.info_11b.has_short_preamble = false; } else if (RATE_IS_OFDM(pseudo_header->ieee_802_11.data_rate)) { /* 11a or 11g, depending on the band. */ if (CHAN_IS_BG(pseudo_header->ieee_802_11.channel)) { /* 11g */ pseudo_header->ieee_802_11.phy = PHDR_802_11_PHY_11G; - pseudo_header->ieee_802_11.phy_info.info_11g.has_mode = FALSE; + pseudo_header->ieee_802_11.phy_info.info_11g.has_mode = false; } else { /* 11a */ pseudo_header->ieee_802_11.phy = PHDR_802_11_PHY_11A; - pseudo_header->ieee_802_11.phy_info.info_11a.has_channel_type = FALSE; - pseudo_header->ieee_802_11.phy_info.info_11a.has_turbo_type = FALSE; + pseudo_header->ieee_802_11.phy_info.info_11a.has_channel_type = false; + pseudo_header->ieee_802_11.phy_info.info_11a.has_turbo_type = false; } } @@ -539,9 +539,9 @@ read_packet_header(wtap *wth, FILE_T fh, union wtap_pseudo_header *pseudo_header return offset; } -static gboolean +static bool process_packet_header(wtap *wth, packet_entry_header *packet_header, - wtap_rec *rec, int *err, gchar **err_info) + wtap_rec *rec, int *err, char **err_info) { /* set the wiretap record metadata fields */ rec->rec_type = REC_TYPE_PACKET; @@ -576,7 +576,7 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("Observer: bad record: Packet length %u < 4", packet_header->network_size); - return FALSE; + return false; } rec->rec_header.packet_header.len = packet_header->network_size - 4; @@ -618,7 +618,7 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header, } } - return TRUE; + return true; } static int @@ -647,13 +647,13 @@ read_packet_data(FILE_T fh, int offset_to_frame, int current_offset_from_packet_ /* read in the packet data */ if (!wtap_read_packet_bytes(fh, buf, length, err, err_info)) - return FALSE; + return false; bytes_consumed += length; return bytes_consumed; } -static gboolean +static bool skip_to_next_packet(wtap *wth, int offset_to_next_packet, int current_offset_from_packet_header, int *err, char **err_info) { @@ -664,17 +664,17 @@ skip_to_next_packet(wtap *wth, int offset_to_next_packet, int current_offset_fro *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("Observer: bad record (offset to next packet %d < %d)", offset_to_next_packet, current_offset_from_packet_header); - return FALSE; + return false; } /* skip to the next packet header */ seek_increment = offset_to_next_packet - current_offset_from_packet_header; if (seek_increment > 0) { if (!wtap_read_bytes(wth->fh, NULL, seek_increment, err, err_info)) - return FALSE; + return false; } - return TRUE; + return true; } /* Returns 0 if we could write the specified encapsulation type, @@ -691,15 +691,15 @@ static int observer_dump_can_write_encap(int encap) return 0; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure. */ -static gboolean observer_dump_open(wtap_dumper *wdh, int *err, - gchar **err_info) +static bool observer_dump_open(wtap_dumper *wdh, int *err, + char **err_info) { observer_dump_private_state * private_state = NULL; capture_file_header file_header; - guint header_offset; - const gchar *err_str; + unsigned header_offset; + const char *err_str; tlv_header comment_header; char comment[64]; size_t comment_length; @@ -721,7 +721,7 @@ static gboolean observer_dump_open(wtap_dumper *wdh, int *err, /* initialize the file header */ memset(&file_header, 0x00, sizeof(file_header)); (void) g_strlcpy(file_header.observer_version, observer_magic, 31); - header_offset = (guint16)sizeof(file_header); + header_offset = (uint16_t)sizeof(file_header); /* create the file comment TLV */ { @@ -735,7 +735,7 @@ static gboolean observer_dump_open(wtap_dumper *wdh, int *err, comment_length = strlen(comment); comment_header.type = INFORMATION_TYPE_COMMENT; - comment_header.length = (guint16) (sizeof(comment_header) + comment_length); + comment_header.length = (uint16_t) (sizeof(comment_header) + comment_length); /* update the file header to account for the comment TLV */ file_header.number_of_information_elements++; @@ -745,7 +745,7 @@ static gboolean observer_dump_open(wtap_dumper *wdh, int *err, /* create the timestamp encoding TLV */ { time_info_header.type = INFORMATION_TYPE_TIME_INFO; - time_info_header.length = (guint16) (sizeof(time_info_header) + sizeof(time_info)); + time_info_header.length = (uint16_t) (sizeof(time_info_header) + sizeof(time_info)); time_info.time_format = TIME_INFO_GMT; /* update the file header to account for the timestamp encoding TLV */ @@ -760,18 +760,18 @@ static gboolean observer_dump_open(wtap_dumper *wdh, int *err, /* write the file header, swapping any multibyte fields first */ CAPTURE_FILE_HEADER_TO_LE_IN_PLACE(file_header); if (!wtap_dump_file_write(wdh, &file_header, sizeof(file_header), err)) { - return FALSE; + return false; } /* write the comment TLV */ { TLV_HEADER_TO_LE_IN_PLACE(comment_header); if (!wtap_dump_file_write(wdh, &comment_header, sizeof(comment_header), err)) { - return FALSE; + return false; } if (!wtap_dump_file_write(wdh, &comment, comment_length, err)) { - return FALSE; + return false; } } @@ -779,12 +779,12 @@ static gboolean observer_dump_open(wtap_dumper *wdh, int *err, { TLV_HEADER_TO_LE_IN_PLACE(time_info_header); if (!wtap_dump_file_write(wdh, &time_info_header, sizeof(time_info_header), err)) { - return FALSE; + return false; } TLV_TIME_INFO_TO_LE_IN_PLACE(time_info); if (!wtap_dump_file_write(wdh, &time_info, sizeof(time_info), err)) { - return FALSE; + return false; } } @@ -792,26 +792,26 @@ static gboolean observer_dump_open(wtap_dumper *wdh, int *err, if (err_str != NULL) { *err = WTAP_ERR_INTERNAL; *err_info = ws_strdup_printf("observer: %s", err_str); - return FALSE; + return false; } - return TRUE; + return true; } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean observer_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, - int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool observer_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, + int *err, char **err_info _U_) { observer_dump_private_state * private_state = NULL; packet_entry_header packet_header; - guint64 seconds_since_2000; + uint64_t seconds_since_2000; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -820,14 +820,14 @@ static gboolean observer_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* The captured size field is 16 bits, so there's a hard limit of 65535. */ if (rec->rec_header.packet_header.caplen > 65535) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } /* convert the number of seconds since epoch from ANSI-relative to @@ -848,11 +848,11 @@ static gboolean observer_dump(wtap_dumper *wdh, const wtap_rec *rec, memset(&packet_header, 0x00, sizeof(packet_header)); packet_header.packet_magic = observer_packet_magic; packet_header.network_speed = 1000000; - packet_header.captured_size = (guint16) rec->rec_header.packet_header.caplen; - packet_header.network_size = (guint16) (rec->rec_header.packet_header.len + 4); + packet_header.captured_size = (uint16_t) rec->rec_header.packet_header.caplen; + packet_header.network_size = (uint16_t) (rec->rec_header.packet_header.len + 4); packet_header.offset_to_frame = sizeof(packet_header); /* XXX - what if this doesn't fit in 16 bits? It's not guaranteed to... */ - packet_header.offset_to_next_packet = (guint16)sizeof(packet_header) + rec->rec_header.packet_header.caplen; + packet_header.offset_to_next_packet = (uint16_t)sizeof(packet_header) + rec->rec_header.packet_header.caplen; packet_header.network_type = private_state->network_type; packet_header.flags = 0x00; packet_header.number_of_information_elements = 0; @@ -866,18 +866,18 @@ static gboolean observer_dump(wtap_dumper *wdh, const wtap_rec *rec, /* write the packet header */ PACKET_ENTRY_HEADER_TO_LE_IN_PLACE(packet_header); if (!wtap_dump_file_write(wdh, &packet_header, sizeof(packet_header), err)) { - return FALSE; + return false; } /* write the packet data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) { - return FALSE; + return false; } - return TRUE; + return true; } -static gint observer_to_wtap_encap(int observer_encap) +static int observer_to_wtap_encap(int observer_encap) { switch(observer_encap) { case OBSERVER_ETHERNET: @@ -894,7 +894,7 @@ static gint observer_to_wtap_encap(int observer_encap) return WTAP_ENCAP_UNKNOWN; } -static gint wtap_to_observer_encap(int wtap_encap) +static int wtap_to_observer_encap(int wtap_encap) { switch(wtap_encap) { case WTAP_ENCAP_ETHERNET: @@ -918,7 +918,7 @@ static const struct supported_block_type observer_blocks_supported[] = { static const struct file_type_subtype_info observer_info = { "Viavi Observer", "observer", "bfr", NULL, - FALSE, BLOCKS_SUPPORTED(observer_blocks_supported), + false, BLOCKS_SUPPORTED(observer_blocks_supported), observer_dump_can_write_encap, observer_dump_open, NULL }; diff --git a/wiretap/observer.h b/wiretap/observer.h index d203841d..d3fa711e 100644 --- a/wiretap/observer.h +++ b/wiretap/observer.h @@ -18,7 +18,7 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val observer_open(wtap *wth, int *err, char **err_info); /* * In v15 the high_byte was added to allow a larger offset This was done by @@ -28,10 +28,10 @@ wtap_open_return_val observer_open(wtap *wth, int *err, gchar **err_info); typedef struct capture_file_header { char observer_version[31]; - guint8 offset_to_first_packet_high_byte; /* allows to extend the offset to the first packet to 256*0x10000 = 16 MB */ - guint16 offset_to_first_packet; + uint8_t offset_to_first_packet_high_byte; /* allows to extend the offset to the first packet to 256*0x10000 = 16 MB */ + uint16_t offset_to_first_packet; char probe_instance; - guint8 number_of_information_elements; /* number of TLVs in the header */ + uint8_t number_of_information_elements; /* number of TLVs in the header */ } capture_file_header; #define CAPTURE_FILE_HEADER_FROM_LE_IN_PLACE(_capture_file_header) \ @@ -42,8 +42,8 @@ typedef struct capture_file_header typedef struct tlv_header { - guint16 type; - guint16 length; /* includes the length of the TLV header */ + uint16_t type; + uint16_t length; /* includes the length of the TLV header */ } tlv_header; #define TLV_HEADER_FROM_LE_IN_PLACE(_tlv_header) \ @@ -106,9 +106,9 @@ typedef struct tlv_header /* 0x0106 */ typedef struct tlv_time_info { - guint16 type; - guint16 length; - guint32 time_format; + uint16_t type; + uint16_t length; + uint32_t time_format; } tlv_time_info; /* @@ -129,13 +129,13 @@ typedef struct tlv_time_info { */ typedef struct tlv_network_load { - guint32 utilization; /* network utilization, in .1% units */ - guint32 unknown1; /* zero in all captures I've seen */ - guint32 unknown2; /* zero in all captures I've seen */ - guint32 packets_per_second; - guint32 unknown3; /* zero in all captures I've seen */ - guint32 bytes_per_second; - guint32 unknown4; /* zero in all captures I've seen */ + uint32_t utilization; /* network utilization, in .1% units */ + uint32_t unknown1; /* zero in all captures I've seen */ + uint32_t unknown2; /* zero in all captures I've seen */ + uint32_t packets_per_second; + uint32_t unknown3; /* zero in all captures I've seen */ + uint32_t bytes_per_second; + uint32_t unknown4; /* zero in all captures I've seen */ } tlv_network_load; #define TLV_NETWORK_LOAD_FROM_LE_IN_PLACE(_tlv_network_load) \ @@ -167,14 +167,14 @@ typedef struct tlv_network_load * are for TLVs where conditions is 0x90. */ typedef struct tlv_wireless_info { - guint8 quality; - guint8 signalStrength; - guint8 rate; - guint8 frequency; - guint8 qualityPercent; - guint8 strengthPercent; - guint8 conditions; - guint8 reserved; + uint8_t quality; + uint8_t signalStrength; + uint8_t rate; + uint8_t frequency; + uint8_t qualityPercent; + uint8_t strengthPercent; + uint8_t conditions; + uint8_t reserved; } tlv_wireless_info; /* @@ -186,7 +186,7 @@ typedef struct tlv_wireless_info { typedef struct tlv_capture_start_stop { - guint32 start_stop; + uint32_t start_stop; } tlv_capture_start_stop; #define START_STOP_TYPE_STOP 0 @@ -194,21 +194,21 @@ typedef struct tlv_capture_start_stop typedef struct packet_entry_header { - guint32 packet_magic; - guint32 network_speed; - guint16 captured_size; - guint16 network_size; - guint16 offset_to_frame; - guint16 offset_to_next_packet; - guint8 network_type; - guint8 flags; - guint8 number_of_information_elements; /* number of TLVs in the header */ - guint8 packet_type; - guint16 errors; - guint16 reserved; - guint64 packet_number; - guint64 original_packet_number; - guint64 nano_seconds_since_2000; + uint32_t packet_magic; + uint32_t network_speed; + uint16_t captured_size; + uint16_t network_size; + uint16_t offset_to_frame; + uint16_t offset_to_next_packet; + uint8_t network_type; + uint8_t flags; + uint8_t number_of_information_elements; /* number of TLVs in the header */ + uint8_t packet_type; + uint16_t errors; + uint16_t reserved; + uint64_t packet_number; + uint64_t original_packet_number; + uint64_t nano_seconds_since_2000; } packet_entry_header; #define PACKET_ENTRY_HEADER_FROM_LE_IN_PLACE(_packet_entry_header) \ diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c index 885d4505..515c8733 100644 --- a/wiretap/packetlogger.c +++ b/wiretap/packetlogger.c @@ -13,22 +13,22 @@ */ #include "config.h" +#include "packetlogger.h" #include <stdlib.h> #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "packetlogger.h" typedef struct { - gboolean byte_swapped; + bool byte_swapped; } packetlogger_t; typedef struct packetlogger_header { - guint32 len; - guint32 ts_secs; - guint32 ts_usecs; + uint32_t len; + uint32_t ts_secs; + uint32_t ts_usecs; } packetlogger_header_t; /* Packet types. */ @@ -49,23 +49,23 @@ typedef struct packetlogger_header { #define PKT_CONFIG 0xFD #define PKT_NEW_CONTROLLER 0xFE -static gboolean packetlogger_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, - gint64 *data_offset); -static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off, +static bool packetlogger_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, + int64_t *data_offset); +static bool packetlogger_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); -static gboolean packetlogger_read_header(packetlogger_header_t *pl_hdr, - FILE_T fh, gboolean byte_swapped, - int *err, gchar **err_info); + Buffer *buf, int *err, char **err_info); +static bool packetlogger_read_header(packetlogger_header_t *pl_hdr, + FILE_T fh, bool byte_swapped, + int *err, char **err_info); static void packetlogger_byte_swap_header(packetlogger_header_t *pl_hdr); static wtap_open_return_val packetlogger_check_record(wtap *wth, packetlogger_header_t *pl_hdr, int *err, - gchar **err_info); -static gboolean packetlogger_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, + char **err_info); +static bool packetlogger_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info); + char **err_info); static int packetlogger_file_type_subtype = -1; @@ -76,9 +76,9 @@ void register_packetlogger(void); */ #define PACKETS_TO_CHECK 5 -wtap_open_return_val packetlogger_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val packetlogger_open(wtap *wth, int *err, char **err_info) { - gboolean byte_swapped = FALSE; + bool byte_swapped = false; packetlogger_header_t pl_hdr; wtap_open_return_val ret; packetlogger_t *packetlogger; @@ -108,7 +108,7 @@ wtap_open_return_val packetlogger_open(wtap *wth, int *err, gchar **err_info) * Byte-swap the header. */ packetlogger_byte_swap_header(&pl_hdr); - byte_swapped = TRUE; + byte_swapped = true; } /* @@ -219,47 +219,47 @@ wtap_open_return_val packetlogger_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_MINE; /* Our kind of file */ } -static gboolean +static bool packetlogger_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return packetlogger_read_packet(wth, wth->fh, rec, buf, err, err_info); } -static gboolean -packetlogger_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +packetlogger_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if(!packetlogger_read_packet(wth, wth->random_fh, rec, buf, err, err_info)) { if(*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, - gboolean byte_swapped, int *err, gchar **err_info) + bool byte_swapped, int *err, char **err_info) { if (!wtap_read_bytes_or_eof(fh, &pl_hdr->len, 4, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &pl_hdr->ts_secs, 4, err, err_info)) - return FALSE; + return false; if (!wtap_read_bytes(fh, &pl_hdr->ts_usecs, 4, err, err_info)) - return FALSE; + return false; /* Convert multi-byte values to host endian */ if (byte_swapped) packetlogger_byte_swap_header(pl_hdr); - return TRUE; + return true; } static void @@ -272,10 +272,10 @@ packetlogger_byte_swap_header(packetlogger_header_t *pl_hdr) static wtap_open_return_val packetlogger_check_record(wtap *wth, packetlogger_header_t *pl_hdr, int *err, - gchar **err_info) + char **err_info) { - guint32 length; - guint8 type; + uint32_t length; + uint8_t type; /* Is the header length valid? If not, assume it's not ours. */ if (pl_hdr->len < 8 || pl_hdr->len >= 65536) @@ -341,21 +341,21 @@ packetlogger_check_record(wtap *wth, packetlogger_header_t *pl_hdr, int *err, return WTAP_OPEN_MINE; } -static gboolean +static bool packetlogger_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { packetlogger_t *packetlogger = (packetlogger_t *)wth->priv; packetlogger_header_t pl_hdr; if(!packetlogger_read_header(&pl_hdr, fh, packetlogger->byte_swapped, err, err_info)) - return FALSE; + return false; if (pl_hdr.len < 8) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("packetlogger: record length %u is too small", pl_hdr.len); - return FALSE; + return false; } if (pl_hdr.len - 8 > WTAP_MAX_PACKET_SIZE_STANDARD) { /* @@ -365,7 +365,7 @@ packetlogger_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("packetlogger: File has %u-byte packet, bigger than maximum of %u", pl_hdr.len - 8, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -390,7 +390,7 @@ static const struct supported_block_type packetlogger_blocks_supported[] = { static const struct file_type_subtype_info packetlogger_info = { "macOS PacketLogger", "pklg", "pklg", NULL, - FALSE, BLOCKS_SUPPORTED(packetlogger_blocks_supported), + false, BLOCKS_SUPPORTED(packetlogger_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/packetlogger.h b/wiretap/packetlogger.h index a82ef833..c599529f 100644 --- a/wiretap/packetlogger.h +++ b/wiretap/packetlogger.h @@ -13,7 +13,7 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val packetlogger_open(wtap *wth, int *err, gchar **err_info _U_); +wtap_open_return_val packetlogger_open(wtap *wth, int *err, char **err_info _U_); #endif /* __PACKETLOGGER_H__ */ diff --git a/wiretap/pcap-common.c b/wiretap/pcap-common.c index a4b02cb4..4b709788 100644 --- a/wiretap/pcap-common.c +++ b/wiretap/pcap-common.c @@ -11,6 +11,7 @@ */ #include "config.h" +#include "pcap-common.h" #include <stdlib.h> #include <string.h> @@ -19,7 +20,6 @@ #include "atm.h" #include "erf_record.h" #include "pcap-encap.h" -#include "pcap-common.h" /* * On some systems, the FDDI MAC addresses are bit-swapped. @@ -358,7 +358,7 @@ static const struct { { 203, WTAP_ENCAP_LAPD }, /* PPP with pseudoheader */ { 204, WTAP_ENCAP_PPP_WITH_PHDR }, - /* IPMB/I2C with a Linux-specific header (defined by Pigeon Point Systems) */ + /* I2C with a Linux-specific header (defined by Pigeon Point Systems) */ { 209, WTAP_ENCAP_I2C_LINUX }, /* FlexRay frame */ { 210, WTAP_ENCAP_FLEXRAY }, @@ -507,6 +507,9 @@ static const struct { /* MDB (Multi-Drop Bus) */ { 300, WTAP_ENCAP_MDB }, + /* DECT_NR (DECT-2020 New Radio (NR) MAC layer) */ + { 301, WTAP_ENCAP_DECT_NR }, + /* * To repeat: * @@ -694,7 +697,7 @@ static const struct { * the "linktype_value" field of "pcap_to_wtap_map[]". */ }; -#define NUM_PCAP_ENCAPS (sizeof pcap_to_wtap_map / sizeof pcap_to_wtap_map[0]) +#define NUM_PCAP_ENCAPS array_length(pcap_to_wtap_map) int wtap_pcap_encap_to_wtap_encap(int encap) @@ -776,7 +779,7 @@ wtap_wtap_encap_to_pcap_encap(int encap) * allocate a huge and wasteful buffer and, at least on 32-bit platforms, * run the risk of running out of memory. */ -guint +unsigned wtap_max_snaplen_for_encap(int wtap_encap) { switch (wtap_encap) { @@ -817,12 +820,12 @@ wtap_max_snaplen_for_encap(int wtap_encap) static int pcap_read_nokiaatm_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, guint packet_size, - int *err, gchar **err_info) + union wtap_pseudo_header *pseudo_header, unsigned packet_size, + int *err, char **err_info) { - guint8 atm_phdr[NOKIAATM_LEN]; - guint8 vpi; - guint16 vci; + uint8_t atm_phdr[NOKIAATM_LEN]; + uint8_t vpi; + uint16_t vci; if (packet_size < NOKIAATM_LEN) { /* @@ -864,12 +867,12 @@ pcap_read_nokiaatm_pseudoheader(FILE_T fh, static int pcap_read_sunatm_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, guint packet_size, - int *err, gchar **err_info) + union wtap_pseudo_header *pseudo_header, unsigned packet_size, + int *err, char **err_info) { - guint8 atm_phdr[SUNATM_LEN]; - guint8 vpi; - guint16 vci; + uint8_t atm_phdr[SUNATM_LEN]; + uint8_t vpi; + uint16_t vci; if (packet_size < SUNATM_LEN) { /* @@ -954,11 +957,11 @@ pcap_read_sunatm_pseudoheader(FILE_T fh, return SUNATM_LEN; } -static gboolean +static bool pcap_write_sunatm_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { - guint8 atm_hdr[SUNATM_LEN]; + uint8_t atm_hdr[SUNATM_LEN]; /* * Write the ATM header. @@ -992,11 +995,11 @@ pcap_write_sunatm_pseudoheader(wtap_dumper *wdh, } break; } - atm_hdr[SUNATM_VPI] = (guint8)pseudo_header->atm.vpi; + atm_hdr[SUNATM_VPI] = (uint8_t)pseudo_header->atm.vpi; phtons(&atm_hdr[SUNATM_VCI], pseudo_header->atm.vci); if (!wtap_dump_file_write(wdh, atm_hdr, sizeof(atm_hdr), err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -1010,9 +1013,9 @@ pcap_write_sunatm_pseudoheader(wtap_dumper *wdh, static int pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - guint packet_size, int *err, gchar **err_info) + unsigned packet_size, int *err, char **err_info) { - guint8 irda_phdr[IRDA_SLL_LEN]; + uint8_t irda_phdr[IRDA_SLL_LEN]; if (packet_size < IRDA_SLL_LEN) { /* @@ -1039,11 +1042,11 @@ pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, return IRDA_SLL_LEN; } -static gboolean +static bool pcap_write_irda_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { - guint8 irda_hdr[IRDA_SLL_LEN]; + uint8_t irda_hdr[IRDA_SLL_LEN]; /* * Write the IrDA header. @@ -1052,8 +1055,8 @@ pcap_write_irda_pseudoheader(wtap_dumper *wdh, phtons(&irda_hdr[IRDA_SLL_PKTTYPE_OFFSET], pseudo_header->irda.pkttype); phtons(&irda_hdr[IRDA_SLL_PROTOCOL_OFFSET], 0x0017); if (!wtap_dump_file_write(wdh, irda_hdr, sizeof(irda_hdr), err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -1066,9 +1069,9 @@ pcap_write_irda_pseudoheader(wtap_dumper *wdh, static int pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - guint packet_size, int *err, gchar **err_info) + unsigned packet_size, int *err, char **err_info) { - guint8 mtp2_hdr[MTP2_HDR_LEN]; + uint8_t mtp2_hdr[MTP2_HDR_LEN]; if (packet_size < MTP2_HDR_LEN) { /* @@ -1090,11 +1093,11 @@ pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, return MTP2_HDR_LEN; } -static gboolean +static bool pcap_write_mtp2_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { - guint8 mtp2_hdr[MTP2_HDR_LEN]; + uint8_t mtp2_hdr[MTP2_HDR_LEN]; /* * Write the MTP2 header. @@ -1105,8 +1108,8 @@ pcap_write_mtp2_pseudoheader(wtap_dumper *wdh, phtons(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET], pseudo_header->mtp2.link_number); if (!wtap_dump_file_write(wdh, mtp2_hdr, sizeof(mtp2_hdr), err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -1125,9 +1128,9 @@ pcap_write_mtp2_pseudoheader(wtap_dumper *wdh, static int pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - guint packet_size, int *err, gchar **err_info) + unsigned packet_size, int *err, char **err_info) { - guint8 lapd_phdr[LAPD_SLL_LEN]; + uint8_t lapd_phdr[LAPD_SLL_LEN]; if (packet_size < LAPD_SLL_LEN) { /* @@ -1155,11 +1158,11 @@ pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, return LAPD_SLL_LEN; } -static gboolean +static bool pcap_write_lapd_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { - guint8 lapd_hdr[LAPD_SLL_LEN]; + uint8_t lapd_hdr[LAPD_SLL_LEN]; /* * Write the LAPD header. @@ -1170,8 +1173,8 @@ pcap_write_lapd_pseudoheader(wtap_dumper *wdh, lapd_hdr[LAPD_SLL_ADDR_OFFSET + 0] = pseudo_header->lapd.we_network?0x01:0x00; if (!wtap_dump_file_write(wdh, lapd_hdr, sizeof(lapd_hdr), err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -1186,9 +1189,9 @@ pcap_write_lapd_pseudoheader(wtap_dumper *wdh, static int pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - guint packet_size, int *err, gchar **err_info) + unsigned packet_size, int *err, char **err_info) { - guint8 sita_phdr[SITA_HDR_LEN]; + uint8_t sita_phdr[SITA_HDR_LEN]; if (packet_size < SITA_HDR_LEN) { /* @@ -1212,11 +1215,11 @@ pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, return SITA_HDR_LEN; } -static gboolean +static bool pcap_write_sita_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { - guint8 sita_hdr[SITA_HDR_LEN]; + uint8_t sita_hdr[SITA_HDR_LEN]; /* * Write the SITA header. @@ -1228,8 +1231,8 @@ pcap_write_sita_pseudoheader(wtap_dumper *wdh, sita_hdr[SITA_ERRORS2_OFFSET] = pseudo_header->sita.sita_errors2; sita_hdr[SITA_PROTO_OFFSET] = pseudo_header->sita.sita_proto; if (!wtap_dump_file_write(wdh, sita_hdr, sizeof(sita_hdr), err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -1237,7 +1240,7 @@ pcap_write_sita_pseudoheader(wtap_dumper *wdh, * Values in network byte order. */ struct pcap_bt_phdr { - guint32 direction; /* Bit 0 hold the frame direction. */ + uint32_t direction; /* Bit 0 hold the frame direction. */ }; #define LIBPCAP_BT_PHDR_SENT 0 @@ -1245,7 +1248,7 @@ struct pcap_bt_phdr { static int pcap_read_bt_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - guint packet_size, int *err, gchar **err_info) + unsigned packet_size, int *err, char **err_info) { struct pcap_bt_phdr phdr; @@ -1262,22 +1265,22 @@ pcap_read_bt_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, if (!wtap_read_bytes(fh, &phdr, sizeof (struct pcap_bt_phdr), err, err_info)) return -1; - pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE; + pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? true: false; return (int)sizeof (struct pcap_bt_phdr); } -static gboolean +static bool pcap_write_bt_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { - guint32 direction; + uint32_t direction; struct pcap_bt_phdr bt_hdr; direction = pseudo_header->p2p.sent ? LIBPCAP_BT_PHDR_SENT : LIBPCAP_BT_PHDR_RECV; bt_hdr.direction = GUINT32_TO_BE(direction); if (!wtap_dump_file_write(wdh, &bt_hdr, sizeof bt_hdr, err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -1285,14 +1288,14 @@ pcap_write_bt_pseudoheader(wtap_dumper *wdh, * Values in network byte order. */ struct pcap_bt_monitor_phdr { - guint16 adapter_id; - guint16 opcode; + uint16_t adapter_id; + uint16_t opcode; }; static int pcap_read_bt_monitor_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, guint packet_size, - int *err, gchar **err_info) + union wtap_pseudo_header *pseudo_header, unsigned packet_size, + int *err, char **err_info) { struct pcap_bt_monitor_phdr phdr; @@ -1315,7 +1318,7 @@ pcap_read_bt_monitor_pseudoheader(FILE_T fh, return (int)sizeof (struct pcap_bt_monitor_phdr); } -static gboolean +static bool pcap_write_bt_monitor_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { @@ -1325,8 +1328,8 @@ pcap_write_bt_monitor_pseudoheader(wtap_dumper *wdh, bt_monitor_hdr.opcode = GUINT16_TO_BE(pseudo_header->btmon.opcode); if (!wtap_dump_file_write(wdh, &bt_monitor_hdr, sizeof bt_monitor_hdr, err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -1338,10 +1341,10 @@ pcap_write_bt_monitor_pseudoheader(wtap_dumper *wdh, static int pcap_read_llcp_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, guint packet_size, - int *err, gchar **err_info) + union wtap_pseudo_header *pseudo_header, unsigned packet_size, + int *err, char **err_info) { - guint8 phdr[LLCP_HEADER_LEN]; + uint8_t phdr[LLCP_HEADER_LEN]; if (packet_size < LLCP_HEADER_LEN) { *err = WTAP_ERR_BAD_FILE; @@ -1356,24 +1359,24 @@ pcap_read_llcp_pseudoheader(FILE_T fh, return LLCP_HEADER_LEN; } -static gboolean +static bool pcap_write_llcp_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { - guint8 phdr[LLCP_HEADER_LEN]; + uint8_t phdr[LLCP_HEADER_LEN]; phdr[LLCP_ADAPTER_OFFSET] = pseudo_header->llcp.adapter; phdr[LLCP_FLAGS_OFFSET] = pseudo_header->llcp.flags; if (!wtap_dump_file_write(wdh, &phdr, sizeof phdr, err)) - return FALSE; - return TRUE; + return false; + return true; } /* * Pseudo-header at the beginning of DLT_PPP_WITH_DIR frames. */ struct pcap_ppp_phdr { - guint8 direction; + uint8_t direction; }; /* @@ -1381,7 +1384,7 @@ struct pcap_ppp_phdr { */ static int pcap_read_ppp_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - guint packet_size, int *err, gchar **err_info) + unsigned packet_size, int *err, char **err_info) { struct pcap_ppp_phdr phdr; @@ -1399,11 +1402,11 @@ pcap_read_ppp_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, err, err_info)) return -1; /* Any non-zero value means "sent" */ - pseudo_header->p2p.sent = (phdr.direction != 0) ? TRUE: FALSE; + pseudo_header->p2p.sent = (phdr.direction != 0) ? true: false; return (int)sizeof (struct pcap_ppp_phdr); } -static gboolean +static bool pcap_write_ppp_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { @@ -1412,17 +1415,17 @@ pcap_write_ppp_pseudoheader(wtap_dumper *wdh, /* Any non-zero value means "sent" */ ppp_hdr.direction = (pseudo_header->p2p.sent ? 1 : 0); if (!wtap_dump_file_write(wdh, &ppp_hdr, sizeof ppp_hdr, err)) - return FALSE; - return TRUE; + return false; + return true; } static int pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, - union wtap_pseudo_header *pseudo_header, guint packet_size, - int *err, gchar **err_info) + union wtap_pseudo_header *pseudo_header, unsigned packet_size, + int *err, char **err_info) { - guint8 erf_hdr[sizeof(struct erf_phdr)]; - guint8 erf_subhdr[sizeof(union erf_subhdr)]; + uint8_t erf_hdr[sizeof(struct erf_phdr)]; + uint8_t erf_subhdr[sizeof(union erf_subhdr)]; int phdr_len; if (packet_size < sizeof(struct erf_phdr)) { @@ -1449,11 +1452,11 @@ pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, * while the lower 32 bits contain the binary fraction of the second. * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */ if (rec) { - guint64 ts = pseudo_header->erf.phdr.ts; + uint64_t ts = pseudo_header->erf.phdr.ts; rec->ts.secs = (time_t) (ts >> 32); ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000); ts += (ts & 0x80000000) << 1; /* rounding */ - rec->ts.nsecs = ((guint32) (ts >> 32)); + rec->ts.nsecs = ((uint32_t) (ts >> 32)); if (rec->ts.nsecs >= 1000000000) { rec->ts.nsecs -= 1000000000; rec->ts.secs += 1; @@ -1475,9 +1478,9 @@ pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, * extension headers. */ if (pseudo_header->erf.phdr.type & 0x80) { - int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr); - guint8 erf_exhdr[8]; - guint8 type; + int i = 0, max = array_length(pseudo_header->erf.ehdr_list); + uint8_t erf_exhdr[8]; + uint8_t type; do { if (phdr_len > INT_MAX - 8) { @@ -1486,7 +1489,7 @@ pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, INT_MAX); return -1; } - if (packet_size < (guint)phdr_len + 8) { + if (packet_size < (unsigned)phdr_len + 8) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcap/pcapng: ERF file has a %u-byte packet, too small to include the extension headers", packet_size); @@ -1496,7 +1499,7 @@ pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, return -1; type = erf_exhdr[0]; if (i < max) { - guint64 erf_exhdr_sw; + uint64_t erf_exhdr_sw; erf_exhdr_sw = pntoh64(erf_exhdr); memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw)); @@ -1522,7 +1525,7 @@ pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, INT_MAX); return -1; } - if (packet_size < (guint)(phdr_len + (int)sizeof(erf_mc_header_t))) { + if (packet_size < (unsigned)(phdr_len + (int)sizeof(erf_mc_header_t))) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcap/pcapng: ERF file has a %u-byte packet, too small to include the Multi Channel header", packet_size); @@ -1541,7 +1544,7 @@ pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, INT_MAX); return -1; } - if (packet_size < (guint)(phdr_len + (int)sizeof(erf_aal2_header_t))) { + if (packet_size < (unsigned)(phdr_len + (int)sizeof(erf_aal2_header_t))) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcap/pcapng: ERF file has a %u-byte packet, too small to include the AAL2 header", packet_size); @@ -1563,7 +1566,7 @@ pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, INT_MAX); return -1; } - if (packet_size < (guint)(phdr_len + (int)sizeof(erf_eth_header_t))) { + if (packet_size < (unsigned)(phdr_len + (int)sizeof(erf_eth_header_t))) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcap/pcapng: ERF file has a %u-byte packet, too small to include the Ethernet additional header", packet_size); @@ -1581,12 +1584,12 @@ pcap_read_erf_pseudoheader(FILE_T fh, wtap_rec *rec, return phdr_len; } -static gboolean +static bool pcap_write_erf_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { - guint8 erf_hdr[sizeof(struct erf_phdr)]; - guint8 erf_subhdr[sizeof(union erf_subhdr)]; + uint8_t erf_hdr[sizeof(struct erf_phdr)]; + uint8_t erf_subhdr[sizeof(union erf_subhdr)]; /* * Write the ERF header. @@ -1610,15 +1613,15 @@ pcap_write_erf_pseudoheader(wtap_dumper *wdh, phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr); phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen); if (!wtap_dump_file_write(wdh, erf_hdr, sizeof(struct erf_phdr), err)) - return FALSE; + return false; /* * Now write out the extension headers. */ if (pseudo_header->erf.phdr.type & 0x80) { - int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr); - guint8 erf_exhdr[8]; - guint8 type; + int i = 0, max = array_length(pseudo_header->erf.ehdr_list); + uint8_t erf_exhdr[8]; + uint8_t type; do { phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr); @@ -1627,7 +1630,7 @@ pcap_write_erf_pseudoheader(wtap_dumper *wdh, if(i == max-1) erf_exhdr[0] = erf_exhdr[0] & 0x7F; if (!wtap_dump_file_write(wdh, erf_exhdr, 8, err)) - return FALSE; + return false; i++; } while (type & 0x80 && i < max); } @@ -1646,13 +1649,13 @@ pcap_write_erf_pseudoheader(wtap_dumper *wdh, phtonl(&erf_subhdr[0], pseudo_header->erf.subhdr.mc_hdr); if (!wtap_dump_file_write(wdh, erf_subhdr, sizeof(struct erf_mc_hdr), err)) - return FALSE; + return false; break; case ERF_TYPE_AAL2: phtonl(&erf_subhdr[0], pseudo_header->erf.subhdr.aal2_hdr); if (!wtap_dump_file_write(wdh, erf_subhdr, sizeof(struct erf_aal2_hdr), err)) - return FALSE; + return false; break; case ERF_TYPE_ETH: case ERF_TYPE_COLOR_ETH: @@ -1661,12 +1664,12 @@ pcap_write_erf_pseudoheader(wtap_dumper *wdh, memcpy(&erf_subhdr[0], &pseudo_header->erf.subhdr.eth_hdr, sizeof pseudo_header->erf.subhdr.eth_hdr); if (!wtap_dump_file_write(wdh, erf_subhdr, sizeof(struct erf_eth_hdr), err)) - return FALSE; + return false; break; default: break; } - return TRUE; + return true; } /* @@ -1674,13 +1677,13 @@ pcap_write_erf_pseudoheader(wtap_dumper *wdh, * Pigeon Point Systems. */ struct i2c_linux_file_hdr { - guint8 bus; - guint8 flags[4]; + uint8_t bus; + uint8_t flags[4]; }; static int pcap_read_i2c_linux_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - guint packet_size, int *err, gchar **err_info) + unsigned packet_size, int *err, char **err_info) { struct i2c_linux_file_hdr i2c_linux_hdr; @@ -1704,7 +1707,7 @@ pcap_read_i2c_linux_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_hea return (int)sizeof (struct i2c_linux_file_hdr); } -static gboolean +static bool pcap_write_i2c_linux_pseudoheader(wtap_dumper *wdh, const union wtap_pseudo_header *pseudo_header, int *err) { @@ -1716,10 +1719,10 @@ pcap_write_i2c_linux_pseudoheader(wtap_dumper *wdh, memset(&i2c_linux_hdr, 0, sizeof(i2c_linux_hdr)); i2c_linux_hdr.bus = pseudo_header->i2c.bus | (pseudo_header->i2c.is_event ? 0x80 : 0x00); - phtonl((guint8 *)&i2c_linux_hdr.flags, pseudo_header->i2c.flags); + phtonl((uint8_t *)&i2c_linux_hdr.flags, pseudo_header->i2c.flags); if (!wtap_dump_file_write(wdh, &i2c_linux_hdr, sizeof(i2c_linux_hdr), err)) - return FALSE; - return TRUE; + return false; + return true; } /* @@ -1727,11 +1730,11 @@ pcap_write_i2c_linux_pseudoheader(wtap_dumper *wdh, */ #define NOKIA_LEN 4 /* length of the header */ -static gboolean +static bool pcap_read_nokia_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) + union wtap_pseudo_header *pseudo_header, int *err, char **err_info) { - guint8 phdr[NOKIA_LEN]; + uint8_t phdr[NOKIA_LEN]; /* backtrack to read the 4 mysterious bytes that aren't considered @@ -1742,15 +1745,15 @@ pcap_read_nokia_pseudoheader(FILE_T fh, *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } if (!wtap_read_bytes(fh, phdr, NOKIA_LEN, err, err_info)) - return FALSE; + return false; memcpy(pseudo_header->nokia.stuff, phdr, NOKIA_LEN); - return TRUE; + return true; } /* @@ -1803,8 +1806,8 @@ pcap_read_nokia_pseudoheader(FILE_T fh, * This structure is 8 bytes long. */ struct iso_rec { - gint32 error_count; - gint32 numdesc; + int32_t error_count; + int32_t numdesc; }; /* @@ -1815,19 +1818,19 @@ struct iso_rec { * The values are in *host* byte order. */ struct linux_usb_phdr { - guint64 id; /* urb id, to link submission and completion events */ - guint8 event_type; /* Submit ('S'), Completed ('C'), Error ('E') */ - guint8 transfer_type; /* ISO (0), Intr, Control, Bulk (3) */ - guint8 endpoint_number; /* Endpoint number (0-15) and transfer direction */ - guint8 device_address; /* 0-127 */ - guint16 bus_id; - gint8 setup_flag; /* 0, if the urb setup header is meaningful */ - gint8 data_flag; /* 0, if urb data is present */ - gint64 ts_sec; - gint32 ts_usec; - gint32 status; - guint32 urb_len; /* whole len of urb this event refers to */ - guint32 data_len; /* amount of urb data really present in this event */ + uint64_t id; /* urb id, to link submission and completion events */ + uint8_t event_type; /* Submit ('S'), Completed ('C'), Error ('E') */ + uint8_t transfer_type; /* ISO (0), Intr, Control, Bulk (3) */ + uint8_t endpoint_number; /* Endpoint number (0-15) and transfer direction */ + uint8_t device_address; /* 0-127 */ + uint16_t bus_id; + int8_t setup_flag; /* 0, if the urb setup header is meaningful */ + int8_t data_flag; /* 0, if urb data is present */ + int64_t ts_sec; + int32_t ts_usec; + int32_t status; + uint32_t urb_len; /* whole len of urb this event refers to */ + uint32_t data_len; /* amount of urb data really present in this event */ /* * Packet-type-dependent data. @@ -1835,7 +1838,7 @@ struct linux_usb_phdr { * Otherwise, some isochronous transfer information. */ union { - guint8 data[8]; + uint8_t data[8]; struct iso_rec iso; } s; @@ -1851,10 +1854,10 @@ struct linux_usb_phdr { * these last 16 bytes. In pre-2.6.31 kernels, it's zero padding; * in 2.6.31 and later, it's the following data. */ - gint32 interval; /* only for Interrupt and Isochronous events */ - gint32 start_frame; /* for Isochronous */ - guint32 xfer_flags; /* copy of URB's transfer_flags */ - guint32 ndesc; /* actual number of isochronous descriptors */ + int32_t interval; /* only for Interrupt and Isochronous events */ + int32_t start_frame; /* for Isochronous */ + uint32_t xfer_flags; /* copy of URB's transfer_flags */ + uint32_t ndesc; /* actual number of isochronous descriptors */ }; /* @@ -1876,10 +1879,10 @@ struct linux_usb_phdr { #define URB_TRANSFER_IN 0x80 /* to host */ struct linux_usb_isodesc { - gint32 iso_status; - guint32 iso_off; - guint32 iso_len; - guint32 _pad; + int32_t iso_status; + uint32_t iso_off; + uint32_t iso_len; + uint32_t _pad; }; /* @@ -1890,11 +1893,11 @@ struct linux_usb_isodesc { * This structure is 8 bytes long. */ struct usb_device_setup_hdr { - gint8 bmRequestType; - guint8 bRequest; - guint16 wValue; - guint16 wIndex; - guint16 wLength; + int8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; }; /* @@ -1914,21 +1917,21 @@ struct usb_device_setup_hdr { { \ if (!WITHIN_PACKET(usb_phdr, fieldp)) \ return; \ - PBSWAP16((guint8 *)fieldp); \ + PBSWAP16((uint8_t *)fieldp); \ } #define CHECK_AND_SWAP32(fieldp) \ { \ if (!WITHIN_PACKET(usb_phdr, fieldp)) \ return; \ - PBSWAP32((guint8 *)fieldp); \ + PBSWAP32((uint8_t *)fieldp); \ } #define CHECK_AND_SWAP64(fieldp) \ { \ if (!WITHIN_PACKET(usb_phdr, fieldp)) \ return; \ - PBSWAP64((guint8 *)fieldp); \ + PBSWAP64((uint8_t *)fieldp); \ } /* @@ -1969,8 +1972,8 @@ struct usb_device_setup_hdr { #define LINUX_SLL_P_CANXL 0x000E /* Controller Area Network extended length */ static void -pcap_byteswap_can_socketcan_pseudoheader(guint packet_size, guint16 protocol, - guint8 *pd) +pcap_byteswap_can_socketcan_pseudoheader(unsigned packet_size, uint16_t protocol, + uint8_t *pd) { switch (protocol) { @@ -2019,10 +2022,10 @@ pcap_byteswap_can_socketcan_pseudoheader(guint packet_size, guint16 protocol, } static void -pcap_byteswap_linux_sll_pseudoheader(wtap_rec *rec, guint8 *pd) +pcap_byteswap_linux_sll_pseudoheader(wtap_rec *rec, uint8_t *pd) { - guint packet_size; - guint16 protocol; + unsigned packet_size; + uint16_t protocol; /* * Minimum of captured and actual length (just in case the @@ -2047,10 +2050,10 @@ pcap_byteswap_linux_sll_pseudoheader(wtap_rec *rec, guint8 *pd) } static void -pcap_byteswap_linux_sll2_pseudoheader(wtap_rec *rec, guint8 *pd) +pcap_byteswap_linux_sll2_pseudoheader(wtap_rec *rec, uint8_t *pd) { - guint packet_size; - guint16 protocol; + unsigned packet_size; + uint16_t protocol; /* * Minimum of captured and actual length (just in case the @@ -2075,13 +2078,13 @@ pcap_byteswap_linux_sll2_pseudoheader(wtap_rec *rec, guint8 *pd) } static void -pcap_byteswap_linux_usb_pseudoheader(wtap_rec *rec, guint8 *pd, - gboolean header_len_64_bytes) +pcap_byteswap_linux_usb_pseudoheader(wtap_rec *rec, uint8_t *pd, + bool header_len_64_bytes) { - guint packet_size; + unsigned packet_size; struct linux_usb_phdr *usb_phdr; struct linux_usb_isodesc *pisodesc; - gint32 iso_numdesc, i; + int32_t iso_numdesc, i; /* * Minimum of captured and actual length (just in case the @@ -2157,25 +2160,25 @@ pcap_byteswap_linux_usb_pseudoheader(wtap_rec *rec, guint8 *pd, } struct nflog_hdr { - guint8 nflog_family; /* address family */ - guint8 nflog_version; /* version */ - guint16 nflog_rid; /* resource ID */ + uint8_t nflog_family; /* address family */ + uint8_t nflog_version; /* version */ + uint16_t nflog_rid; /* resource ID */ }; struct nflog_tlv { - guint16 tlv_length; /* tlv length */ - guint16 tlv_type; /* tlv type */ + uint16_t tlv_length; /* tlv length */ + uint16_t tlv_type; /* tlv type */ /* value follows this */ }; static void -pcap_byteswap_nflog_pseudoheader(wtap_rec *rec, guint8 *pd) +pcap_byteswap_nflog_pseudoheader(wtap_rec *rec, uint8_t *pd) { - guint packet_size; - guint8 *p; + unsigned packet_size; + uint8_t *p; struct nflog_hdr *nfhdr; struct nflog_tlv *tlv; - guint size; + unsigned size; /* * Minimum of captured and actual length (just in case the @@ -2198,15 +2201,15 @@ pcap_byteswap_nflog_pseudoheader(wtap_rec *rec, guint8 *pd) return; } - packet_size -= (guint)sizeof(struct nflog_hdr); + packet_size -= (unsigned)sizeof(struct nflog_hdr); p += sizeof(struct nflog_hdr); while (packet_size >= sizeof(struct nflog_tlv)) { tlv = (struct nflog_tlv *) p; /* Swap the type and length. */ - PBSWAP16((guint8 *)&tlv->tlv_type); - PBSWAP16((guint8 *)&tlv->tlv_length); + PBSWAP16((uint8_t *)&tlv->tlv_type); + PBSWAP16((uint8_t *)&tlv->tlv_length); /* Get the length of the TLV. */ size = tlv->tlv_length; @@ -2238,26 +2241,26 @@ pcap_byteswap_nflog_pseudoheader(wtap_rec *rec, guint8 *pd) #define PFLOG_RULESET_NAME_SIZE 16 struct pfloghdr { - guint8 length; - guint8 af; - guint8 action; - guint8 reason; + uint8_t length; + uint8_t af; + uint8_t action; + uint8_t reason; char ifname[PFLOG_IFNAMSIZ]; char ruleset[PFLOG_RULESET_NAME_SIZE]; - guint32 rulenr; - guint32 subrulenr; - guint32 uid; - gint32 pid; - guint32 rule_uid; - gint32 rule_pid; - guint8 dir; + uint32_t rulenr; + uint32_t subrulenr; + uint32_t uid; + int32_t pid; + uint32_t rule_uid; + int32_t rule_pid; + uint8_t dir; /* More follows, depending on the header length */ }; static void -pcap_byteswap_pflog_pseudoheader(wtap_rec *rec, guint8 *pd) +pcap_byteswap_pflog_pseudoheader(wtap_rec *rec, uint8_t *pd) { - guint packet_size; + unsigned packet_size; struct pfloghdr *pflhdr; /* @@ -2275,19 +2278,19 @@ pcap_byteswap_pflog_pseudoheader(wtap_rec *rec, guint8 *pd) } pflhdr = (struct pfloghdr *)pd; - if (pflhdr->length < (guint) (offsetof(struct pfloghdr, rule_pid) + sizeof pflhdr->rule_pid)) { + if (pflhdr->length < (unsigned) (offsetof(struct pfloghdr, rule_pid) + sizeof pflhdr->rule_pid)) { /* Header doesn't include the UID and PID fields */ return; } - PBSWAP32((guint8 *)&pflhdr->uid); - PBSWAP32((guint8 *)&pflhdr->pid); - PBSWAP32((guint8 *)&pflhdr->rule_uid); - PBSWAP32((guint8 *)&pflhdr->rule_pid); + PBSWAP32((uint8_t *)&pflhdr->uid); + PBSWAP32((uint8_t *)&pflhdr->pid); + PBSWAP32((uint8_t *)&pflhdr->rule_uid); + PBSWAP32((uint8_t *)&pflhdr->rule_pid); } int -pcap_process_pseudo_header(FILE_T fh, gboolean is_nokia, int wtap_encap, - guint packet_size, wtap_rec *rec, int *err, gchar **err_info) +pcap_process_pseudo_header(FILE_T fh, bool is_nokia, int wtap_encap, + unsigned packet_size, wtap_rec *rec, int *err, char **err_info) { int phdr_len = 0; @@ -2345,8 +2348,8 @@ pcap_process_pseudo_header(FILE_T fh, gboolean is_nokia, int wtap_encap, */ memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = -1; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = false; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = false; break; case WTAP_ENCAP_IRDA: @@ -2383,7 +2386,7 @@ pcap_process_pseudo_header(FILE_T fh, gboolean is_nokia, int wtap_encap, case WTAP_ENCAP_BLUETOOTH_H4: /* We don't have pseudoheader, so just pretend we received everything. */ - rec->rec_header.packet_header.pseudo_header.p2p.sent = FALSE; + rec->rec_header.packet_header.pseudo_header.p2p.sent = false; break; case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR: @@ -2487,7 +2490,7 @@ fix_linux_usb_mmapped_length(wtap_rec *rec, const u_char *bp) * while processing the isochronous descriptors. */ pre_truncation_data_len = 0; - for (guint32 desc = 0; + for (uint32_t desc = 0; desc < hdr->ndesc && bytes_left >= sizeof (struct linux_usb_isodesc); desc++, bytes_left -= sizeof (struct linux_usb_isodesc)) { u_int desc_end; @@ -2541,7 +2544,7 @@ fix_linux_usb_mmapped_length(wtap_rec *rec, const u_char *bp) } static void -pcap_fixup_len(wtap_rec *rec, const guint8 *pd) +pcap_fixup_len(wtap_rec *rec, const uint8_t *pd) { struct linux_usb_phdr *usb_phdr; @@ -2583,8 +2586,8 @@ pcap_fixup_len(wtap_rec *rec, const guint8 *pd) } void -pcap_read_post_process(gboolean is_nokia, int wtap_encap, - wtap_rec *rec, guint8 *pd, gboolean bytes_swapped, int fcs_len) +pcap_read_post_process(bool is_nokia, int wtap_encap, + wtap_rec *rec, uint8_t *pd, bool bytes_swapped, int fcs_len) { switch (wtap_encap) { @@ -2634,12 +2637,12 @@ pcap_read_post_process(gboolean is_nokia, int wtap_encap, case WTAP_ENCAP_USB_LINUX: if (bytes_swapped) - pcap_byteswap_linux_usb_pseudoheader(rec, pd, FALSE); + pcap_byteswap_linux_usb_pseudoheader(rec, pd, false); break; case WTAP_ENCAP_USB_LINUX_MMAPPED: if (bytes_swapped) - pcap_byteswap_linux_usb_pseudoheader(rec, pd, TRUE); + pcap_byteswap_linux_usb_pseudoheader(rec, pd, true); /* * Fix up the on-the-network length if necessary. @@ -2681,7 +2684,7 @@ pcap_read_post_process(gboolean is_nokia, int wtap_encap, } } -gboolean +bool wtap_encap_requires_phdr(int wtap_encap) { switch (wtap_encap) { @@ -2697,9 +2700,9 @@ wtap_encap_requires_phdr(int wtap_encap) case WTAP_ENCAP_PPP_WITH_PHDR: case WTAP_ENCAP_ERF: case WTAP_ENCAP_I2C_LINUX: - return TRUE; + return true; } - return FALSE; + return false; } int @@ -2754,9 +2757,9 @@ pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header) * add in the lengths of the extension headers. */ if (pseudo_header->erf.phdr.type & 0x80) { - int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr); - guint8 erf_exhdr[8]; - guint8 type; + int i = 0, max = array_length(pseudo_header->erf.ehdr_list); + uint8_t erf_exhdr[8]; + uint8_t type; do { phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr); @@ -2808,7 +2811,7 @@ pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header) return hdrsize; } -gboolean +bool pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header, int *err) { @@ -2816,60 +2819,60 @@ pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pse case WTAP_ENCAP_ATM_PDUS: if (!pcap_write_sunatm_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_IRDA: if (!pcap_write_irda_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_MTP2_WITH_PHDR: if (!pcap_write_mtp2_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_LINUX_LAPD: if (!pcap_write_lapd_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_SITA: if (!pcap_write_sita_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR: if (!pcap_write_bt_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR: if (!pcap_write_bt_monitor_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_NFC_LLCP: if (!pcap_write_llcp_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_PPP_WITH_PHDR: if (!pcap_write_ppp_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_ERF: if (!pcap_write_erf_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; case WTAP_ENCAP_I2C_LINUX: if (!pcap_write_i2c_linux_pseudoheader(wdh, pseudo_header, err)) - return FALSE; + return false; break; } - return TRUE; + return true; } /* diff --git a/wiretap/pcap-common.h b/wiretap/pcap-common.h index af6c8218..56be5fae 100644 --- a/wiretap/pcap-common.h +++ b/wiretap/pcap-common.h @@ -18,19 +18,19 @@ #include "wtap.h" #include "ws_symbol_export.h" -extern guint wtap_max_snaplen_for_encap(int wtap_encap); +extern unsigned wtap_max_snaplen_for_encap(int wtap_encap); -extern int pcap_process_pseudo_header(FILE_T fh, gboolean is_nokia, - int wtap_encap, guint packet_size, wtap_rec *rec, - int *err, gchar **err_info); +extern int pcap_process_pseudo_header(FILE_T fh, bool is_nokia, + int wtap_encap, unsigned packet_size, wtap_rec *rec, + int *err, char **err_info); -extern void pcap_read_post_process(gboolean is_nokia, int wtap_encap, - wtap_rec *rec, guint8 *pd, gboolean bytes_swapped, int fcs_len); +extern void pcap_read_post_process(bool is_nokia, int wtap_encap, + wtap_rec *rec, uint8_t *pd, bool bytes_swapped, int fcs_len); extern int pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header); -extern gboolean pcap_write_phdr(wtap_dumper *wdh, int wtap_encap, +extern bool pcap_write_phdr(wtap_dumper *wdh, int wtap_encap, const union wtap_pseudo_header *pseudo_header, int *err); #endif diff --git a/wiretap/pcap-encap.h b/wiretap/pcap-encap.h index 53af9c3e..872a3f96 100644 --- a/wiretap/pcap-encap.h +++ b/wiretap/pcap-encap.h @@ -22,7 +22,7 @@ extern "C" { WS_DLL_PUBLIC int wtap_pcap_encap_to_wtap_encap(int encap); int wtap_wtap_encap_to_pcap_encap(int encap); -WS_DLL_PUBLIC gboolean wtap_encap_requires_phdr(int encap); +WS_DLL_PUBLIC bool wtap_encap_requires_phdr(int encap); #ifdef __cplusplus } diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index f5c3b320..0fd5f0bf 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -17,6 +17,7 @@ #include "config.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP +#include "pcapng.h" #include "wtap_opttypes.h" @@ -36,45 +37,44 @@ #include "required_file_handlers.h" #include "pcap-common.h" #include "pcap-encap.h" -#include "pcapng.h" #include "pcapng_module.h" #include "secrets-types.h" #define ROUND_TO_4BYTE(len) WS_ROUNDUP_4(len) -static gboolean +static bool pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset); -static gboolean -pcapng_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); + char **err_info, int64_t *data_offset); +static bool +pcapng_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static void pcapng_close(wtap *wth); -static gboolean +static bool pcapng_encap_is_ft_specific(int encap); -static gboolean +static bool pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err); /* * Minimum block size = size of block header + size of block trailer. */ -#define MIN_BLOCK_SIZE ((guint32)(sizeof(pcapng_block_header_t) + sizeof(guint32))) +#define MIN_BLOCK_SIZE ((uint32_t)(sizeof(pcapng_block_header_t) + sizeof(uint32_t))) /* * Minimum SHB size = minimum block size + size of fixed length portion of SHB. */ -#define MIN_SHB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_section_header_block_t))) +#define MIN_SHB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_section_header_block_t))) /* pcapng: packet block file encoding (obsolete) */ typedef struct pcapng_packet_block_s { - guint16 interface_id; - guint16 drops_count; - guint32 timestamp_high; - guint32 timestamp_low; - guint32 captured_len; - guint32 packet_len; + uint16_t interface_id; + uint16_t drops_count; + uint32_t timestamp_high; + uint32_t timestamp_low; + uint32_t captured_len; + uint32_t packet_len; /* ... Packet Data ... */ /* ... Padding ... */ /* ... Options ... */ @@ -83,15 +83,15 @@ typedef struct pcapng_packet_block_s { /* * Minimum PB size = minimum block size + size of fixed length portion of PB. */ -#define MIN_PB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_packet_block_t))) +#define MIN_PB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_packet_block_t))) /* pcapng: enhanced packet block file encoding */ typedef struct pcapng_enhanced_packet_block_s { - guint32 interface_id; - guint32 timestamp_high; - guint32 timestamp_low; - guint32 captured_len; - guint32 packet_len; + uint32_t interface_id; + uint32_t timestamp_high; + uint32_t timestamp_low; + uint32_t captured_len; + uint32_t packet_len; /* ... Packet Data ... */ /* ... Padding ... */ /* ... Options ... */ @@ -100,11 +100,11 @@ typedef struct pcapng_enhanced_packet_block_s { /* * Minimum EPB size = minimum block size + size of fixed length portion of EPB. */ -#define MIN_EPB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_enhanced_packet_block_t))) +#define MIN_EPB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_enhanced_packet_block_t))) /* pcapng: simple packet block file encoding */ typedef struct pcapng_simple_packet_block_s { - guint32 packet_len; + uint32_t packet_len; /* ... Packet Data ... */ /* ... Padding ... */ } pcapng_simple_packet_block_t; @@ -112,12 +112,12 @@ typedef struct pcapng_simple_packet_block_s { /* * Minimum SPB size = minimum block size + size of fixed length portion of SPB. */ -#define MIN_SPB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_simple_packet_block_t))) +#define MIN_SPB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_simple_packet_block_t))) /* pcapng: name resolution block file encoding */ typedef struct pcapng_name_resolution_block_s { - guint16 record_type; - guint16 record_len; + uint16_t record_type; + uint16_t record_len; /* ... Record ... */ } pcapng_name_resolution_block_t; @@ -125,11 +125,11 @@ typedef struct pcapng_name_resolution_block_s { * Minimum NRB size = minimum block size + size of smallest NRB record * (there must at least be an "end of records" record). */ -#define MIN_NRB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_name_resolution_block_t))) +#define MIN_NRB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_name_resolution_block_t))) /* pcapng: custom block file encoding */ typedef struct pcapng_custom_block_s { - guint32 pen; + uint32_t pen; /* Custom data and options */ } pcapng_custom_block_t; @@ -137,12 +137,12 @@ typedef struct pcapng_custom_block_s { * Minimum CB size = minimum block size + size of fixed length portion of CB. */ -#define MIN_CB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_custom_block_t))) +#define MIN_CB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_custom_block_t))) /* * Minimum ISB size = minimum block size + size of fixed length portion of ISB. */ -#define MIN_ISB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_interface_statistics_block_t))) +#define MIN_ISB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_interface_statistics_block_t))) /* * Minimum Sysdig size = minimum block size + packed size of sysdig_event_phdr. @@ -150,9 +150,9 @@ typedef struct pcapng_custom_block_s { * to sysdig_event_phdr, includes the nparams 32bit value). */ #define SYSDIG_EVENT_HEADER_SIZE ((16 + 64 + 64 + 32 + 16)/8) /* CPU ID + TS + TID + Event len + Event type */ -#define MIN_SYSDIG_EVENT_SIZE ((guint32)(MIN_BLOCK_SIZE + SYSDIG_EVENT_HEADER_SIZE)) +#define MIN_SYSDIG_EVENT_SIZE ((uint32_t)(MIN_BLOCK_SIZE + SYSDIG_EVENT_HEADER_SIZE)) #define SYSDIG_EVENT_V2_HEADER_SIZE ((16 + 64 + 64 + 32 + 16 + 32)/8) /* CPU ID + TS + TID + Event len + Event type + nparams */ -#define MIN_SYSDIG_EVENT_V2_SIZE ((guint32)(MIN_BLOCK_SIZE + SYSDIG_EVENT_V2_HEADER_SIZE)) +#define MIN_SYSDIG_EVENT_V2_SIZE ((uint32_t)(MIN_BLOCK_SIZE + SYSDIG_EVENT_V2_HEADER_SIZE)) /* * We require __REALTIME_TIMESTAMP in the Journal Export Format reader in @@ -161,19 +161,19 @@ typedef struct pcapng_custom_block_s { */ #define SDJ__REALTIME_TIMESTAMP "__REALTIME_TIMESTAMP=" #define MIN_SYSTEMD_JOURNAL_EXPORT_ENTRY_SIZE 23 // "__REALTIME_TIMESTAMP=0\n" -#define MIN_SYSTEMD_JOURNAL_EXPORT_BLOCK_SIZE ((guint32)(MIN_SYSTEMD_JOURNAL_EXPORT_ENTRY_SIZE + MIN_BLOCK_SIZE)) +#define MIN_SYSTEMD_JOURNAL_EXPORT_BLOCK_SIZE ((uint32_t)(MIN_SYSTEMD_JOURNAL_EXPORT_ENTRY_SIZE + MIN_BLOCK_SIZE)) /* pcapng: common option header file encoding for every option type */ typedef struct pcapng_option_header_s { - guint16 option_code; - guint16 option_length; + uint16_t option_code; + uint16_t option_length; /* ... x bytes Option Body ... */ /* ... Padding ... */ } pcapng_option_header_t; struct pcapng_option { - guint16 type; - guint16 value_length; + uint16_t type; + uint16_t value_length; }; /* Option codes: 16-bit field */ @@ -224,12 +224,12 @@ struct pcapng_option { /* Packet data - used for both Enhanced Packet Block and the obsolete Packet Block data */ typedef struct wtapng_packet_s { /* mandatory */ - guint32 ts_high; /* seconds since 1.1.1970 */ - guint32 ts_low; /* fraction of seconds, depends on if_tsresol */ - guint32 cap_len; /* data length in the file */ - guint32 packet_len; /* data length on the wire */ - guint32 interface_id; /* identifier of the interface. */ - guint16 drops_count; /* drops count, only valid for packet block */ + uint32_t ts_high; /* seconds since 1.1.1970 */ + uint32_t ts_low; /* fraction of seconds, depends on if_tsresol */ + uint32_t cap_len; /* data length in the file */ + uint32_t packet_len; /* data length on the wire */ + uint32_t interface_id; /* identifier of the interface. */ + uint16_t drops_count; /* drops count, only valid for packet block */ /* 0xffff if information no available */ /* pack_hash */ /* XXX - put the packet data / pseudo_header here as well? */ @@ -238,23 +238,23 @@ typedef struct wtapng_packet_s { /* Simple Packet data */ typedef struct wtapng_simple_packet_s { /* mandatory */ - guint32 cap_len; /* data length in the file */ - guint32 packet_len; /* data length on the wire */ + uint32_t cap_len; /* data length in the file */ + uint32_t packet_len; /* data length on the wire */ /* XXX - put the packet data / pseudo_header here as well? */ } wtapng_simple_packet_t; /* Interface data in private struct */ typedef struct interface_info_s { int wtap_encap; - guint32 snap_len; - guint64 time_units_per_second; + uint32_t snap_len; + uint64_t time_units_per_second; int tsprecision; - gint64 tsoffset; + int64_t tsoffset; int fcslen; } interface_info_t; typedef struct { - guint current_section_number; /**< Section number of the current section being read sequentially */ + unsigned current_section_number; /**< Section number of the current section being read sequentially */ GArray *sections; /**< Sections found in the capture file. */ } pcapng_t; @@ -279,7 +279,7 @@ typedef struct { static GHashTable *block_handlers; void -register_pcapng_block_type_handler(guint block_type, block_reader reader, +register_pcapng_block_type_handler(unsigned block_type, block_reader reader, block_writer writer) { block_handler *handler; @@ -392,7 +392,7 @@ register_pcapng_block_type_handler(guint block_type, block_reader reader, * variable for an error string. * * It checks whether the length and option are valid, and, if they - * aren't, returns FALSE, setting the error code to the appropriate + * aren't, returns false, setting the error code to the appropriate * error (normally WTAP_ERR_BAD_FILE) and the error string to an * appropriate string indicating the problem. * @@ -415,8 +415,8 @@ register_pcapng_block_type_handler(guint block_type, block_reader reader, * the option, and an int * into which an error code should * be stored if an error occurs when writing the option. * - * It returns a gboolean value of TRUE if the attempt to - * write the option succeeds and FALSE if the attempt to + * It returns a bool value of true if the attempt to + * write the option succeeds and false if the attempt to * write the option gets an error. */ @@ -511,16 +511,16 @@ get_block_type_internal(unsigned block_type) * handled internally, which should hopefully be the same * for all blocks of a type.) */ - return FALSE; + return false; } #endif - return TRUE; + return true; } - return FALSE; + return false; } -static gboolean -get_block_type_index(guint block_type, guint *bt_index) +static bool +get_block_type_index(unsigned block_type, unsigned *bt_index) { ws_assert(bt_index); @@ -583,19 +583,19 @@ get_block_type_index(guint block_type, guint *bt_index) * * XXX - report an error? */ - return FALSE; + return false; } - return TRUE; + return true; } void -register_pcapng_option_handler(guint block_type, guint option_code, +register_pcapng_option_handler(unsigned block_type, unsigned option_code, option_parser parser, option_sizer sizer, option_writer writer) { - guint bt_index; + unsigned bt_index; option_handler *handler; if (!get_block_type_index(block_type, &bt_index)) @@ -622,8 +622,8 @@ register_pcapng_option_handler(guint block_type, guint option_code, void pcapng_process_uint8_option(wtapng_block_t *wblock, - guint16 option_code, guint16 option_length, - const guint8 *option_content) + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content) { if (option_length == 1) { /* @@ -639,14 +639,14 @@ void pcapng_process_uint32_option(wtapng_block_t *wblock, const section_info_t *section_info, pcapng_opt_byte_order_e byte_order, - guint16 option_code, guint16 option_length, - const guint8 *option_content) + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content) { - guint32 uint32; + uint32_t uint32; if (option_length == 4) { - /* Don't cast a guint8 * into a guint32 *--the - * guint8 * may not point to something that's + /* Don't cast a uint8_t * into a uint32_t *--the + * uint8_t * may not point to something that's * aligned correctly. * * XXX - options are aligned on 32-bit boundaries, so, while @@ -654,7 +654,7 @@ pcapng_process_uint32_option(wtapng_block_t *wblock, * aligned on 64-bit bounaries, it shouldn't be true that 32-bit * options aren't guaranteed to be aligned on 32-bit boundaries. */ - memcpy(&uint32, option_content, sizeof(guint32)); + memcpy(&uint32, option_content, sizeof(uint32_t)); switch (byte_order) { case OPT_SECTION_BYTE_ORDER: @@ -696,19 +696,19 @@ void pcapng_process_timestamp_option(wtapng_block_t *wblock, const section_info_t *section_info, pcapng_opt_byte_order_e byte_order, - guint16 option_code, guint16 option_length, - const guint8 *option_content) + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content) { if (option_length == 8) { - guint32 high, low; - guint64 timestamp; + uint32_t high, low; + uint64_t timestamp; - /* Don't cast a guint8 * into a guint32 *--the - * guint8 * may not point to something that's + /* Don't cast a uint8_t * into a uint32_t *--the + * uint8_t * may not point to something that's * aligned correctly. */ - memcpy(&high, option_content, sizeof(guint32)); - memcpy(&low, option_content + sizeof(guint32), sizeof(guint32)); + memcpy(&high, option_content, sizeof(uint32_t)); + memcpy(&low, option_content + sizeof(uint32_t), sizeof(uint32_t)); switch (byte_order) { case OPT_SECTION_BYTE_ORDER: @@ -739,9 +739,9 @@ pcapng_process_timestamp_option(wtapng_block_t *wblock, */ return; } - timestamp = (guint64)high; + timestamp = (uint64_t)high; timestamp <<= 32; - timestamp += (guint64)low; + timestamp += (uint64_t)low; /* * If this option can appear only once in a block, this call * will fail on the second and later occurrences of the option; @@ -755,17 +755,17 @@ void pcapng_process_uint64_option(wtapng_block_t *wblock, const section_info_t *section_info, pcapng_opt_byte_order_e byte_order, - guint16 option_code, guint16 option_length, - const guint8 *option_content) + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content) { - guint64 uint64; + uint64_t uint64; if (option_length == 8) { - /* Don't cast a guint8 * into a guint64 *--the - * guint8 * may not point to something that's + /* Don't cast a uint8_t * into a uint64_t *--the + * uint8_t * may not point to something that's * aligned correctly. */ - memcpy(&uint64, option_content, sizeof(guint64)); + memcpy(&uint64, option_content, sizeof(uint64_t)); switch (byte_order) { case OPT_SECTION_BYTE_ORDER: @@ -807,17 +807,17 @@ void pcapng_process_int64_option(wtapng_block_t *wblock, const section_info_t *section_info, pcapng_opt_byte_order_e byte_order, - guint16 option_code, guint16 option_length, - const guint8 *option_content) + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content) { - gint64 int64; + int64_t int64; if (option_length == 8) { - /* Don't cast a gint8 * into a gint64 *--the - * guint8 * may not point to something that's + /* Don't cast a int8_t * into a int64_t *--the + * uint8_t * may not point to something that's * aligned correctly. */ - memcpy(&int64, option_content, sizeof(gint64)); + memcpy(&int64, option_content, sizeof(int64_t)); switch (byte_order) { case OPT_SECTION_BYTE_ORDER: @@ -856,8 +856,8 @@ pcapng_process_int64_option(wtapng_block_t *wblock, } void -pcapng_process_string_option(wtapng_block_t *wblock, guint16 option_code, - guint16 option_length, const guint8 *option_content) +pcapng_process_string_option(wtapng_block_t *wblock, uint16_t option_code, + uint16_t option_length, const uint8_t *option_content) { const char *opt = (const char *)option_content; size_t optlen = option_length; @@ -870,34 +870,34 @@ pcapng_process_string_option(wtapng_block_t *wblock, guint16 option_code, } void -pcapng_process_bytes_option(wtapng_block_t *wblock, guint16 option_code, - guint16 option_length, const guint8 *option_content) +pcapng_process_bytes_option(wtapng_block_t *wblock, uint16_t option_code, + uint16_t option_length, const uint8_t *option_content) { wtap_block_add_bytes_option(wblock->block, option_code, (const char *)option_content, option_length); } -static gboolean +static bool pcapng_process_nflx_custom_option(wtapng_block_t *wblock, section_info_t *section_info, - const guint8 *value, guint16 length) + const uint8_t *value, uint16_t length) { struct nflx_dumpinfo dumpinfo; - guint32 type, version; - gint64 dumptime, temp; + uint32_t type, version; + int64_t dumptime, temp; if (length < 4) { ws_debug("Length = %u too small", length); - return FALSE; + return false; } - memcpy(&type, value, sizeof(guint32)); + memcpy(&type, value, sizeof(uint32_t)); type = GUINT32_FROM_LE(type); value += 4; length -= 4; ws_debug("Handling type = %u, payload of length = %u", type, length); switch (type) { case NFLX_OPT_TYPE_VERSION: - if (length == sizeof(guint32)) { - memcpy(&version, value, sizeof(guint32)); + if (length == sizeof(uint32_t)) { + memcpy(&version, value, sizeof(uint32_t)); version = GUINT32_FROM_LE(version); ws_debug("BBLog version: %u", version); section_info->bblog_version = version; @@ -911,18 +911,18 @@ pcapng_process_nflx_custom_option(wtapng_block_t *wblock, ws_buffer_assure_space(wblock->frame_buffer, length); wblock->rec->rec_header.custom_block_header.length = length + 4; memcpy(ws_buffer_start_ptr(wblock->frame_buffer), value, length); - memcpy(&temp, value, sizeof(guint64)); + memcpy(&temp, value, sizeof(uint64_t)); temp = GUINT64_FROM_LE(temp); wblock->rec->ts.secs = section_info->bblog_offset_tv_sec + temp; - memcpy(&temp, value + sizeof(guint64), sizeof(guint64)); + memcpy(&temp, value + sizeof(uint64_t), sizeof(uint64_t)); temp = GUINT64_FROM_LE(temp); - wblock->rec->ts.nsecs = (guint32)(section_info->bblog_offset_tv_usec + temp) * 1000; + wblock->rec->ts.nsecs = (uint32_t)(section_info->bblog_offset_tv_usec + temp) * 1000; if (wblock->rec->ts.nsecs >= 1000000000) { wblock->rec->ts.secs += 1; wblock->rec->ts.nsecs -= 1000000000; } wblock->rec->presence_flags = WTAP_HAS_TS; - wblock->internal = FALSE; + wblock->internal = false; } break; case NFLX_OPT_TYPE_DUMPINFO: @@ -936,8 +936,8 @@ pcapng_process_nflx_custom_option(wtapng_block_t *wblock, } break; case NFLX_OPT_TYPE_DUMPTIME: - if (length == sizeof(gint64)) { - memcpy(&dumptime, value, sizeof(gint64)); + if (length == sizeof(int64_t)) { + memcpy(&dumptime, value, sizeof(int64_t)); dumptime = GINT64_FROM_LE(dumptime); ws_debug("BBLog dumpinfo time offset: %" PRIu64, dumptime); } else { @@ -946,7 +946,7 @@ pcapng_process_nflx_custom_option(wtapng_block_t *wblock, break; case NFLX_OPT_TYPE_STACKNAME: if (length >= 2) { - ws_debug("BBLog stack name: %.*s(%u)", length - 1, value + 1, *(guint8 *)value); + ws_debug("BBLog stack name: %.*s(%u)", length - 1, value + 1, *(uint8_t *)value); } else { ws_debug("BBLog stack name has strange length: %u)", length); } @@ -958,24 +958,24 @@ pcapng_process_nflx_custom_option(wtapng_block_t *wblock, return wtap_block_add_nflx_custom_option(wblock->block, type, value, length) == WTAP_OPTTYPE_SUCCESS; } -static gboolean +static bool pcapng_process_custom_option(wtapng_block_t *wblock, section_info_t *section_info, - guint16 option_code, guint16 option_length, - const guint8 *option_content, + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content, pcapng_opt_byte_order_e byte_order, - int *err, gchar **err_info) + int *err, char **err_info) { - guint32 pen; - gboolean ret; + uint32_t pen; + bool ret; if (option_length < 4) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: option length (%d) too small for custom option", option_length); - return FALSE; + return false; } - memcpy(&pen, option_content, sizeof(guint32)); + memcpy(&pen, option_content, sizeof(uint32_t)); switch (byte_order) { case OPT_SECTION_BYTE_ORDER: @@ -1002,7 +1002,7 @@ pcapng_process_custom_option(wtapng_block_t *wblock, *err = WTAP_ERR_INTERNAL; *err_info = ws_strdup_printf("pcapng: invalid byte order %d passed to pcapng_process_custom_option()", byte_order); - return FALSE; + return false; } switch (pen) { case PEN_NFLX: @@ -1018,13 +1018,13 @@ pcapng_process_custom_option(wtapng_block_t *wblock, } #ifdef HAVE_PLUGINS -static gboolean +static bool pcapng_process_unhandled_option(wtapng_block_t *wblock, - guint bt_index, + unsigned bt_index, const section_info_t *section_info, - guint16 option_code, guint16 option_length, - const guint8 *option_content, - int *err, gchar **err_info) + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content, + int *err, char **err_info) { option_handler *handler; @@ -1033,65 +1033,65 @@ pcapng_process_unhandled_option(wtapng_block_t *wblock, */ if (option_handlers[bt_index] != NULL && (handler = (option_handler *)g_hash_table_lookup(option_handlers[bt_index], - GUINT_TO_POINTER((guint)option_code))) != NULL) { + GUINT_TO_POINTER((unsigned)option_code))) != NULL) { /* Yes - call the handler. */ if (!handler->parser(wblock->block, section_info->byte_swapped, option_length, option_content, err, err_info)) /* XXX - free anything? */ - return FALSE; + return false; } - return TRUE; + return true; } #else -static gboolean +static bool pcapng_process_unhandled_option(wtapng_block_t *wblock _U_, - guint bt_index _U_, + unsigned bt_index _U_, const section_info_t *section_info _U_, - guint16 option_code _U_, guint16 option_length _U_, - const guint8 *option_content _U_, - int *err _U_, gchar **err_info _U_) + uint16_t option_code _U_, uint16_t option_length _U_, + const uint8_t *option_content _U_, + int *err _U_, char **err_info _U_) { - return TRUE; + return true; } #endif -gboolean +bool pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, section_info_t *section_info, - guint opt_cont_buf_len, - gboolean (*process_option)(wtapng_block_t *, + unsigned opt_cont_buf_len, + bool (*process_option)(wtapng_block_t *, const section_info_t *, - guint16, guint16, - const guint8 *, - int *, gchar **), + uint16_t, uint16_t, + const uint8_t *, + int *, char **), pcapng_opt_byte_order_e byte_order, - int *err, gchar **err_info) + int *err, char **err_info) { - guint8 *option_content; /* Allocate as large as the options block */ - guint opt_bytes_remaining; - const guint8 *option_ptr; + uint8_t *option_content; /* Allocate as large as the options block */ + unsigned opt_bytes_remaining; + const uint8_t *option_ptr; const pcapng_option_header_t *oh; - guint16 option_code, option_length; - guint rounded_option_length; + uint16_t option_code, option_length; + unsigned rounded_option_length; ws_debug("Options %u bytes", opt_cont_buf_len); if (opt_cont_buf_len == 0) { /* No options, so nothing to do */ - return TRUE; + return true; } /* Allocate enough memory to hold all options */ - option_content = (guint8 *)g_try_malloc(opt_cont_buf_len); + option_content = (uint8_t *)g_try_malloc(opt_cont_buf_len); if (option_content == NULL) { *err = ENOMEM; /* we assume we're out of memory */ - return FALSE; + return false; } /* Read all the options into the buffer */ if (!wtap_read_bytes(fh, option_content, opt_cont_buf_len, err, err_info)) { ws_debug("failed to read options"); g_free(option_content); - return FALSE; + return false; } /* @@ -1110,7 +1110,7 @@ pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: Not enough data for option header"); g_free(option_content); - return FALSE; + return false; } option_code = oh->option_code; option_length = oh->option_length; @@ -1138,7 +1138,7 @@ pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, *err = WTAP_ERR_INTERNAL; *err_info = ws_strdup_printf("pcapng: invalid byte order %d passed to pcapng_process_options()", byte_order); - return FALSE; + return false; } option_ptr += sizeof (*oh); /* 4 bytes, so it remains aligned */ opt_bytes_remaining -= sizeof (*oh); @@ -1152,7 +1152,7 @@ pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: Not enough data to handle option of length %u", option_length); g_free(option_content); - return FALSE; + return false; } switch (option_code) { @@ -1177,7 +1177,7 @@ pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, byte_order, err, err_info)) { g_free(option_content); - return FALSE; + return false; } break; @@ -1187,14 +1187,14 @@ pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, option_length, option_ptr, err, err_info)) { g_free(option_content); - return FALSE; + return false; } } option_ptr += rounded_option_length; /* multiple of 4 bytes, so it remains aligned */ opt_bytes_remaining -= rounded_option_length; } g_free(option_content); - return TRUE; + return true; } typedef enum { @@ -1203,13 +1203,13 @@ typedef enum { PCAPNG_BLOCK_ERROR } block_return_val; -static gboolean +static bool pcapng_process_section_header_block_option(wtapng_block_t *wblock, const section_info_t *section_info, - guint16 option_code, - guint16 option_length, - const guint8 *option_content, - int *err, gchar **err_info) + uint16_t option_code, + uint16_t option_length, + const uint8_t *option_content, + int *err, char **err_info) { /* * Handle option content. @@ -1246,22 +1246,22 @@ pcapng_process_section_header_block_option(wtapng_block_t *wblock, section_info, option_code, option_length, option_content, err, err_info)) - return FALSE; + return false; break; } - return TRUE; + return true; } static block_return_val pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh, section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { - gboolean byte_swapped; - guint16 version_major; - guint16 version_minor; - guint opt_cont_buf_len; + bool byte_swapped; + uint16_t version_major; + uint16_t version_minor; + unsigned opt_cont_buf_len; pcapng_section_header_block_t shb; wtapng_section_mandatory_t* section_data; @@ -1281,7 +1281,7 @@ pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh, switch (shb.magic) { case(0x1A2B3C4D): /* this seems pcapng with correct byte order */ - byte_swapped = FALSE; + byte_swapped = false; version_major = shb.version_major; version_minor = shb.version_minor; @@ -1290,7 +1290,7 @@ pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh, break; case(0x4D3C2B1A): /* this seems pcapng with swapped byte order */ - byte_swapped = TRUE; + byte_swapped = true; version_major = GUINT16_SWAP_LE_BE(shb.version_major); version_minor = GUINT16_SWAP_LE_BE(shb.version_minor); @@ -1402,18 +1402,18 @@ pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh, /* * We don't return these to the caller in pcapng_read(). */ - wblock->internal = TRUE; + wblock->internal = true; return PCAPNG_BLOCK_OK; } -static gboolean +static bool pcapng_process_if_descr_block_option(wtapng_block_t *wblock, const section_info_t *section_info, - guint16 option_code, - guint16 option_length, - const guint8 *option_content, - int *err, gchar **err_info) + uint16_t option_code, + uint16_t option_length, + const uint8_t *option_content, + int *err, char **err_info) { if_filter_opt_t if_filter; @@ -1462,7 +1462,7 @@ pcapng_process_if_descr_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block verdict option length %u is < 1", option_length); /* XXX - free anything? */ - return FALSE; + return false; } /* The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string, * or BPF bytecode. @@ -1483,15 +1483,15 @@ pcapng_process_if_descr_block_option(wtapng_block_t *wblock, * XXX - what if option_length-1 is not a * multiple of the size of a BPF instruction? */ - guint num_insns; - const guint8 *insn_in; + unsigned num_insns; + const uint8_t *insn_in; if_filter.type = if_filter_bpf; num_insns = (option_length-1)/8; insn_in = option_content+1; if_filter.data.bpf_prog.bpf_prog_len = num_insns; if_filter.data.bpf_prog.bpf_prog = g_new(wtap_bpf_insn_t, num_insns); - for (guint i = 0; i < num_insns; i++) { + for (unsigned i = 0; i < num_insns; i++) { wtap_bpf_insn_t *insn = &if_filter.data.bpf_prog.bpf_prog[i]; memcpy(&insn->code, insn_in, 2); @@ -1591,26 +1591,26 @@ pcapng_process_if_descr_block_option(wtapng_block_t *wblock, section_info, option_code, option_length, option_content, err, err_info)) - return FALSE; + return false; break; } - return TRUE; + return true; } /* "Interface Description Block" */ -static gboolean +static bool pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, section_info_t *section_info, - wtapng_block_t *wblock, int *err, gchar **err_info) + wtapng_block_t *wblock, int *err, char **err_info) { /* Default time stamp resolution is 10^6 */ - guint64 time_units_per_second = 1000000; + uint64_t time_units_per_second = 1000000; int tsprecision = 6; - guint opt_cont_buf_len; + unsigned opt_cont_buf_len; pcapng_interface_description_block_t idb; wtapng_if_descr_mandatory_t* if_descr_mand; - guint link_type; - guint8 if_tsresol; + unsigned link_type; + uint8_t if_tsresol; /* * Is this block long enough to be an IDB? @@ -1622,13 +1622,13 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of an IDB is less than the minimum IDB size %u", bh->block_total_length, MIN_IDB_SIZE); - return FALSE; + return false; } /* read block content */ if (!wtap_read_bytes(fh, &idb, sizeof idb, err, err_info)) { ws_debug("failed to read IDB"); - return FALSE; + return false; } /* @@ -1671,7 +1671,7 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, if (!pcapng_process_options(fh, wblock, section_info, opt_cont_buf_len, pcapng_process_if_descr_block_option, OPT_SECTION_BYTE_ORDER, err, err_info)) - return FALSE; + return false; /* * Did we get a time stamp precision option? @@ -1681,9 +1681,9 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, /* * Yes. Set time_units_per_second appropriately. */ - guint8 exponent; + uint8_t exponent; - exponent = (guint8)(if_tsresol & 0x7f); + exponent = (uint8_t)(if_tsresol & 0x7f); if (if_tsresol & 0x80) { /* * 2^63 fits in a 64-bit unsigned number; 2^64 does not. @@ -1702,11 +1702,11 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_UNSUPPORTED; *err_info = ws_strdup_printf("pcapng: IDB power-of-2 time stamp resolution %u > 63", exponent); - return FALSE; + return false; } /* 2^exponent */ - time_units_per_second = G_GUINT64_CONSTANT(1) << exponent; + time_units_per_second = UINT64_C(1) << exponent; /* * Set the display precision to a value large enough to @@ -1719,7 +1719,7 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, * * Dealing with base-2 time stamps is a bit of a mess, * thanks to humans counting with their fingers rather - * than their hands, and it applies to mroe files than + * than their hands, and it applies to more files than * pcapng files, e.g. ERF files.) */ if (time_units_per_second >= 1000000000) @@ -1752,7 +1752,7 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, * 1.8 seconds, so the maximum useful power-of-10 exponent * in a pcapng file is less than 19.) */ - guint64 result; + uint64_t result; if (exponent > 19) { /* @@ -1762,12 +1762,12 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_UNSUPPORTED; *err_info = ws_strdup_printf("pcapng: IDB power-of-10 time stamp resolution %u > 19", exponent); - return FALSE; + return false; } /* 10^exponent */ result = 1; - for (guint i = 0; i < exponent; i++) { + for (unsigned i = 0; i < exponent; i++) { result *= 10U; } time_units_per_second = result; @@ -1784,7 +1784,7 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, tsprecision = WS_TSPREC_MAX; } } - if (time_units_per_second > (((guint64)1) << 32)) { + if (time_units_per_second > (((uint64_t)1) << 32)) { ws_debug("time conversion might be inaccurate"); } } @@ -1833,25 +1833,25 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, /* * We don't return these to the caller in pcapng_read(). */ - wblock->internal = TRUE; + wblock->internal = true; - return TRUE; + return true; } -static gboolean +static bool pcapng_read_decryption_secrets_block(FILE_T fh, pcapng_block_header_t *bh, const section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { - guint to_read; + unsigned to_read; pcapng_decryption_secrets_block_t dsb; wtapng_dsb_mandatory_t *dsb_mand; /* read block content */ if (!wtap_read_bytes(fh, &dsb, sizeof(dsb), err, err_info)) { ws_debug("failed to read DSB"); - return FALSE; + return false; } /* @@ -1874,47 +1874,47 @@ pcapng_read_decryption_secrets_block(FILE_T fh, pcapng_block_header_t *bh, if (dsb_mand->secrets_len > 1024 * 1024 * 1024) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: secrets block is too large: %u", dsb_mand->secrets_len); - return FALSE; + return false; } - dsb_mand->secrets_data = (guint8 *)g_malloc0(dsb_mand->secrets_len); + dsb_mand->secrets_data = (uint8_t *)g_malloc0(dsb_mand->secrets_len); if (!wtap_read_bytes(fh, dsb_mand->secrets_data, dsb_mand->secrets_len, err, err_info)) { ws_debug("failed to read DSB"); - return FALSE; + return false; } /* Skip past padding and discard options (not supported yet). */ to_read = bh->block_total_length - MIN_DSB_SIZE - dsb_mand->secrets_len; if (!wtap_read_bytes(fh, NULL, to_read, err, err_info)) { ws_debug("failed to read DSB options"); - return FALSE; + return false; } /* * We don't return these to the caller in pcapng_read(). */ - wblock->internal = TRUE; + wblock->internal = true; - return TRUE; + return true; } static bool -pcapng_read_sysdig_meta_event_block(FILE_T fh, pcapng_block_header_t *bh, +pcapng_read_meta_event_block(FILE_T fh, pcapng_block_header_t *bh, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { - guint to_read; - wtapng_sysdig_mev_mandatory_t *mev_mand; + unsigned to_read; + wtapng_meta_event_mandatory_t *mev_mand; /* * Set wblock->block to a newly-allocated Sysdig meta event block. */ - wblock->block = wtap_block_create(WTAP_BLOCK_SYSDIG_META_EVENT); + wblock->block = wtap_block_create(WTAP_BLOCK_META_EVENT); /* * Set the mandatory values for the block. */ - mev_mand = (wtapng_sysdig_mev_mandatory_t *)wtap_block_get_mandatory_data(wblock->block); - mev_mand->mev_type = bh->block_type; + mev_mand = (wtapng_meta_event_mandatory_t *)wtap_block_get_mandatory_data(wblock->block); + mev_mand->mev_block_type = bh->block_type; mev_mand->mev_data_len = bh->block_total_length - (int)sizeof(pcapng_block_header_t) - (int)sizeof(bh->block_total_length); @@ -1935,7 +1935,7 @@ pcapng_read_sysdig_meta_event_block(FILE_T fh, pcapng_block_header_t *bh, to_read = bh->block_total_length - MIN_BLOCK_SIZE - mev_mand->mev_data_len; if (!wtap_read_bytes(fh, NULL, to_read, err, err_info)) { ws_debug("failed to read Sysdig mev options"); - return FALSE; + return false; } /* @@ -1946,15 +1946,15 @@ pcapng_read_sysdig_meta_event_block(FILE_T fh, pcapng_block_header_t *bh, return true; } -static gboolean +static bool pcapng_process_packet_block_option(wtapng_block_t *wblock, const section_info_t *section_info, - guint16 option_code, - guint16 option_length, - const guint8 *option_content, - int *err, gchar **err_info) + uint16_t option_code, + uint16_t option_length, + const uint8_t *option_content, + int *err, char **err_info) { - guint64 tmp64; + uint64_t tmp64; packet_verdict_opt_t packet_verdict; packet_hash_opt_t packet_hash; @@ -1982,7 +1982,7 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block flags option length %u is not 4", option_length); /* XXX - free anything? */ - return FALSE; + return false; } pcapng_process_uint32_option(wblock, section_info, OPT_SECTION_BYTE_ORDER, @@ -1995,11 +1995,11 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block hash option length %u is < 1", option_length); /* XXX - free anything? */ - return FALSE; + return false; } packet_hash.type = option_content[0]; packet_hash.hash_bytes = - g_byte_array_new_take((guint8 *)g_memdup2(&option_content[1], + g_byte_array_new_take((uint8_t *)g_memdup2(&option_content[1], option_length - 1), option_length - 1); wtap_block_add_packet_hash_option(wblock->block, option_code, &packet_hash); @@ -2013,7 +2013,7 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block drop count option length %u is not 8", option_length); /* XXX - free anything? */ - return FALSE; + return false; } pcapng_process_uint64_option(wblock, section_info, OPT_SECTION_BYTE_ORDER, @@ -2026,7 +2026,7 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block packet id option length %u is not 8", option_length); /* XXX - free anything? */ - return FALSE; + return false; } pcapng_process_uint64_option(wblock, section_info, OPT_SECTION_BYTE_ORDER, @@ -2039,7 +2039,7 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block queue option length %u is not 4", option_length); /* XXX - free anything? */ - return FALSE; + return false; } pcapng_process_uint32_option(wblock, section_info, OPT_SECTION_BYTE_ORDER, @@ -2052,14 +2052,14 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block verdict option length %u is < 1", option_length); /* XXX - free anything? */ - return FALSE; + return false; } switch (option_content[0]) { case(OPT_VERDICT_TYPE_HW): packet_verdict.type = packet_verdict_hardware; packet_verdict.data.verdict_bytes = - g_byte_array_new_take((guint8 *)g_memdup2(&option_content[1], + g_byte_array_new_take((uint8_t *)g_memdup2(&option_content[1], option_length - 1), option_length - 1); break; @@ -2070,13 +2070,13 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block TC verdict option length %u is != 9", option_length); /* XXX - free anything? */ - return FALSE; + return false; } - /* Don't cast a guint8 * into a guint64 *--the - * guint8 * may not point to something that's + /* Don't cast a uint8_t * into a uint64_t *--the + * uint8_t * may not point to something that's * aligned correctly. */ - memcpy(&tmp64, &option_content[1], sizeof(guint64)); + memcpy(&tmp64, &option_content[1], sizeof(uint64_t)); if (section_info->byte_swapped) tmp64 = GUINT64_SWAP_LE_BE(tmp64); packet_verdict.type = packet_verdict_linux_ebpf_tc; @@ -2089,13 +2089,13 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, *err_info = ws_strdup_printf("pcapng: packet block XDP verdict option length %u is != 9", option_length); /* XXX - free anything? */ - return FALSE; + return false; } - /* Don't cast a guint8 * into a guint64 *--the - * guint8 * may not point to something that's + /* Don't cast a uint8_t * into a uint64_t *--the + * uint8_t * may not point to something that's * aligned correctly. */ - memcpy(&tmp64, &option_content[1], sizeof(guint64)); + memcpy(&tmp64, &option_content[1], sizeof(uint64_t)); if (section_info->byte_swapped) tmp64 = GUINT64_SWAP_LE_BE(tmp64); packet_verdict.type = packet_verdict_linux_ebpf_xdp; @@ -2104,7 +2104,7 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, default: /* Silently ignore unknown verdict types */ - return TRUE; + return true; } wtap_block_add_packet_verdict_option(wblock->block, option_code, &packet_verdict); wtap_packet_verdict_free(&packet_verdict); @@ -2116,28 +2116,28 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock, section_info, option_code, option_length, option_content, err, err_info)) - return FALSE; + return false; break; } - return TRUE; + return true; } -static gboolean +static bool pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info, gboolean enhanced) + int *err, char **err_info, bool enhanced) { - guint block_read; - guint opt_cont_buf_len; + unsigned block_read; + unsigned opt_cont_buf_len; pcapng_enhanced_packet_block_t epb; pcapng_packet_block_t pb; wtapng_packet_t packet; - guint32 padding; - guint32 flags; - guint64 tmp64; + uint32_t padding; + uint32_t flags; + uint64_t tmp64; interface_info_t iface_info; - guint64 ts; + uint64_t ts; int pseudo_header_len; int fcslen; @@ -2155,13 +2155,13 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of an EPB is less than the minimum EPB size %u", bh->block_total_length, MIN_EPB_SIZE); - return FALSE; + return false; } if (!wtap_read_bytes(fh, &epb, sizeof epb, err, err_info)) { ws_debug("failed to read packet data"); - return FALSE; + return false; } - block_read = (guint)sizeof epb; + block_read = (unsigned)sizeof epb; if (section_info->byte_swapped) { packet.interface_id = GUINT32_SWAP_LE_BE(epb.interface_id); @@ -2191,13 +2191,13 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of a PB is less than the minimum PB size %u", bh->block_total_length, MIN_PB_SIZE); - return FALSE; + return false; } if (!wtap_read_bytes(fh, &pb, sizeof pb, err, err_info)) { ws_debug("failed to read packet data"); - return FALSE; + return false; } - block_read = (guint)sizeof pb; + block_read = (unsigned)sizeof pb; if (section_info->byte_swapped) { packet.interface_id = GUINT16_SWAP_LE_BE(pb.interface_id); @@ -2238,7 +2238,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of an EPB is too small for %u bytes of packet data", bh->block_total_length, packet.cap_len); - return FALSE; + return false; } } else { if (bh->block_total_length < @@ -2249,7 +2249,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of a PB is too small for %u bytes of packet data", bh->block_total_length, packet.cap_len); - return FALSE; + return false; } } @@ -2263,7 +2263,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err_info = ws_strdup_printf("pcapng: interface index %u is not less than section interface count %u", packet.interface_id, section_info->interfaces->len); - return FALSE; + return false; } iface_info = g_array_index(section_info->interfaces, interface_info_t, packet.interface_id); @@ -2273,7 +2273,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err_info = ws_strdup_printf("pcapng: cap_len %u is larger than %u", packet.cap_len, wtap_max_snaplen_for_encap(iface_info.wtap_encap)); - return FALSE; + return false; } wblock->rec->rec_type = REC_TYPE_PACKET; @@ -2289,21 +2289,21 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, memset((void *)&wblock->rec->rec_header.packet_header.pseudo_header, 0, sizeof(union wtap_pseudo_header)); pseudo_header_len = pcap_process_pseudo_header(fh, - FALSE, /* not a Nokia pcap - not a pcap at all */ + false, /* not a Nokia pcap - not a pcap at all */ iface_info.wtap_encap, packet.cap_len, wblock->rec, err, err_info); if (pseudo_header_len < 0) { - return FALSE; + return false; } block_read += pseudo_header_len; wblock->rec->rec_header.packet_header.caplen = packet.cap_len - pseudo_header_len; wblock->rec->rec_header.packet_header.len = packet.packet_len - pseudo_header_len; /* Combine the two 32-bit pieces of the timestamp into one 64-bit value */ - ts = (((guint64)packet.ts_high) << 32) | ((guint64)packet.ts_low); + ts = (((uint64_t)packet.ts_high) << 32) | ((uint64_t)packet.ts_low); /* Convert it to seconds and nanoseconds. */ wblock->rec->ts.secs = (time_t)(ts / iface_info.time_units_per_second); @@ -2315,13 +2315,13 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, /* "(Enhanced) Packet Block" read capture data */ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer, packet.cap_len - pseudo_header_len, err, err_info)) - return FALSE; + return false; block_read += packet.cap_len - pseudo_header_len; /* jump over potential padding bytes at end of the packet data */ if (padding != 0) { if (!wtap_read_bytes(fh, NULL, padding, err, err_info)) - return FALSE; + return false; block_read += padding; } @@ -2336,7 +2336,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, if (!pcapng_process_options(fh, wblock, section_info, opt_cont_buf_len, pcapng_process_packet_block_option, OPT_SECTION_BYTE_ORDER, err, err_info)) - return FALSE; + return false; /* * Did we get a packet flags option? @@ -2354,17 +2354,17 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, * How about a drop_count option? If not, set it from other sources */ if (WTAP_OPTTYPE_SUCCESS != wtap_block_get_uint64_option_value(wblock->block, OPT_PKT_DROPCOUNT, &tmp64) && packet.drops_count != 0xFFFF) { - wtap_block_add_uint64_option(wblock->block, OPT_PKT_DROPCOUNT, (guint64)packet.drops_count); + wtap_block_add_uint64_option(wblock->block, OPT_PKT_DROPCOUNT, (uint64_t)packet.drops_count); } - pcap_read_post_process(FALSE, iface_info.wtap_encap, + pcap_read_post_process(false, iface_info.wtap_encap, wblock->rec, ws_buffer_start_ptr(wblock->frame_buffer), section_info->byte_swapped, fcslen); /* * We return these to the caller in pcapng_read(). */ - wblock->internal = FALSE; + wblock->internal = false; /* * We want dissectors (particularly packet_frame) to be able to @@ -2375,20 +2375,20 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, wblock->rec->block = wblock->block; wblock->block = NULL; - return TRUE; + return true; } -static gboolean +static bool pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, const section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { interface_info_t iface_info; pcapng_simple_packet_block_t spb; wtapng_simple_packet_t simple_packet; - guint32 padding; + uint32_t padding; int pseudo_header_len; /* @@ -2401,19 +2401,19 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of an SPB is less than the minimum SPB size %u", bh->block_total_length, MIN_SPB_SIZE); - return FALSE; + return false; } /* "Simple Packet Block" read fixed part */ if (!wtap_read_bytes(fh, &spb, sizeof spb, err, err_info)) { ws_debug("failed to read packet data"); - return FALSE; + return false; } if (0 >= section_info->interfaces->len) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("pcapng: SPB appeared before any IDBs in the section"); - return FALSE; + return false; } iface_info = g_array_index(section_info->interfaces, interface_info_t, 0); @@ -2454,7 +2454,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of an SPB is too small for %u bytes of packet data", bh->block_total_length, simple_packet.packet_len); - return FALSE; + return false; } if (simple_packet.cap_len > wtap_max_snaplen_for_encap(iface_info.wtap_encap)) { @@ -2462,7 +2462,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, *err_info = ws_strdup_printf("pcapng: cap_len %u is larger than %u", simple_packet.cap_len, wtap_max_snaplen_for_encap(iface_info.wtap_encap)); - return FALSE; + return false; } ws_debug("packet data: packet_len %u", simple_packet.packet_len); @@ -2482,14 +2482,14 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, memset((void *)&wblock->rec->rec_header.packet_header.pseudo_header, 0, sizeof(union wtap_pseudo_header)); pseudo_header_len = pcap_process_pseudo_header(fh, - FALSE, + false, iface_info.wtap_encap, simple_packet.cap_len, wblock->rec, err, err_info); if (pseudo_header_len < 0) { - return FALSE; + return false; } wblock->rec->rec_header.packet_header.caplen = simple_packet.cap_len - pseudo_header_len; wblock->rec->rec_header.packet_header.len = simple_packet.packet_len - pseudo_header_len; @@ -2499,24 +2499,24 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, /* "Simple Packet Block" read capture data */ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer, simple_packet.cap_len, err, err_info)) - return FALSE; + return false; /* jump over potential padding bytes at end of the packet data */ if ((simple_packet.cap_len % 4) != 0) { if (!wtap_read_bytes(fh, NULL, 4 - (simple_packet.cap_len % 4), err, err_info)) - return FALSE; + return false; } - pcap_read_post_process(FALSE, iface_info.wtap_encap, + pcap_read_post_process(false, iface_info.wtap_encap, wblock->rec, ws_buffer_start_ptr(wblock->frame_buffer), section_info->byte_swapped, iface_info.fcslen); /* * We return these to the caller in pcapng_read(). */ - wblock->internal = FALSE; + wblock->internal = false; - return TRUE; + return true; } #define NRES_ENDOFRECORD 0 @@ -2536,8 +2536,8 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, * *err_info appropriately. */ static int -name_resolution_block_find_name_end(const char *p, guint record_len, int *err, - gchar **err_info) +name_resolution_block_find_name_end(const char *p, unsigned record_len, int *err, + char **err_info) { int namelen; @@ -2563,13 +2563,13 @@ name_resolution_block_find_name_end(const char *p, guint record_len, int *err, return namelen + 1; } -static gboolean +static bool pcapng_process_name_resolution_block_option(wtapng_block_t *wblock, const section_info_t *section_info, - guint16 option_code, - guint16 option_length, - const guint8 *option_content, - int *err, gchar **err_info) + uint16_t option_code, + uint16_t option_length, + const uint8_t *option_content, + int *err, char **err_info) { /* * Handle option content. @@ -2599,24 +2599,24 @@ pcapng_process_name_resolution_block_option(wtapng_block_t *wblock, section_info, option_code, option_length, option_content, err, err_info)) - return FALSE; + return false; break; } - return TRUE; + return true; } -static gboolean +static bool pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { int block_read; int to_read; pcapng_name_resolution_block_t nrb; Buffer nrb_rec; - guint32 v4_addr; - guint record_len, opt_cont_buf_len; + uint32_t v4_addr; + unsigned record_len, opt_cont_buf_len; char *namep; int namelen; wtapng_nrb_mandatory_t *nrb_mand; @@ -2631,7 +2631,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of an NRB is less than the minimum NRB size %u", bh->block_total_length, MIN_NRB_SIZE); - return FALSE; + return false; } to_read = bh->block_total_length - 8 - 4; /* We have read the header and should not read the final block_total_length */ @@ -2664,13 +2664,13 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: %d bytes left in the block < NRB record header size %u", to_read - block_read, - (guint)sizeof nrb); - return FALSE; + (unsigned)sizeof nrb); + return false; } if (!wtap_read_bytes(fh, &nrb, sizeof nrb, err, err_info)) { ws_buffer_free(&nrb_rec); ws_debug("failed to read record header"); - return FALSE; + return false; } block_read += (int)sizeof nrb; @@ -2685,7 +2685,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, *err_info = ws_strdup_printf("pcapng: %d bytes left in the block < NRB record length + padding %u", to_read - block_read, nrb.record_len + PADDING4(nrb.record_len)); - return FALSE; + return false; } switch (nrb.record_type) { case NRES_ENDOFRECORD: @@ -2712,14 +2712,14 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: NRB record length for IPv4 record %u < minimum length 4", nrb.record_len); - return FALSE; + return false; } ws_buffer_assure_space(&nrb_rec, nrb.record_len); if (!wtap_read_bytes(fh, ws_buffer_start_ptr(&nrb_rec), nrb.record_len, err, err_info)) { ws_buffer_free(&nrb_rec); ws_debug("failed to read IPv4 record data"); - return FALSE; + return false; } block_read += nrb.record_len; @@ -2741,7 +2741,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, namelen = name_resolution_block_find_name_end(namep, record_len, err, err_info); if (namelen == -1) { ws_buffer_free(&nrb_rec); - return FALSE; /* fail */ + return false; /* fail */ } hashipv4_t *tp = g_new0(hashipv4_t, 1); tp->addr = v4_addr; @@ -2751,7 +2751,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, if (!wtap_read_bytes(fh, NULL, PADDING4(nrb.record_len), err, err_info)) { ws_buffer_free(&nrb_rec); - return FALSE; + return false; } block_read += PADDING4(nrb.record_len); break; @@ -2775,20 +2775,20 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: NRB record length for IPv6 record %u < minimum length 16", nrb.record_len); - return FALSE; + return false; } if (to_read < nrb.record_len) { ws_buffer_free(&nrb_rec); *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: NRB record length for IPv6 record %u > remaining data in NRB", nrb.record_len); - return FALSE; + return false; } ws_buffer_assure_space(&nrb_rec, nrb.record_len); if (!wtap_read_bytes(fh, ws_buffer_start_ptr(&nrb_rec), nrb.record_len, err, err_info)) { ws_buffer_free(&nrb_rec); - return FALSE; + return false; } block_read += nrb.record_len; @@ -2802,7 +2802,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, namelen = name_resolution_block_find_name_end(namep, record_len, err, err_info); if (namelen == -1) { ws_buffer_free(&nrb_rec); - return FALSE; /* fail */ + return false; /* fail */ } hashipv6_t *tp = g_new0(hashipv6_t, 1); memcpy(tp->addr, ws_buffer_start_ptr(&nrb_rec), sizeof tp->addr); @@ -2812,7 +2812,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, if (!wtap_read_bytes(fh, NULL, PADDING4(nrb.record_len), err, err_info)) { ws_buffer_free(&nrb_rec); - return FALSE; + return false; } block_read += PADDING4(nrb.record_len); break; @@ -2820,7 +2820,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, ws_debug("unknown record type 0x%x", nrb.record_type); if (!wtap_read_bytes(fh, NULL, nrb.record_len + PADDING4(nrb.record_len), err, err_info)) { ws_buffer_free(&nrb_rec); - return FALSE; + return false; } block_read += nrb.record_len + PADDING4(nrb.record_len); break; @@ -2835,25 +2835,25 @@ read_options: if (!pcapng_process_options(fh, wblock, section_info, opt_cont_buf_len, pcapng_process_name_resolution_block_option, OPT_SECTION_BYTE_ORDER, err, err_info)) - return FALSE; + return false; ws_buffer_free(&nrb_rec); /* * We don't return these to the caller in pcapng_read(). */ - wblock->internal = TRUE; + wblock->internal = true; - return TRUE; + return true; } -static gboolean +static bool pcapng_process_interface_statistics_block_option(wtapng_block_t *wblock, const section_info_t *section_info, - guint16 option_code, - guint16 option_length, - const guint8 *option_content, - int *err, gchar **err_info) + uint16_t option_code, + uint16_t option_length, + const uint8_t *option_content, + int *err, char **err_info) { /* * Handle option content. @@ -2920,19 +2920,19 @@ pcapng_process_interface_statistics_block_option(wtapng_block_t *wblock, section_info, option_code, option_length, option_content, err, err_info)) - return FALSE; + return false; break; } - return TRUE; + return true; } -static gboolean +static bool pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { - guint opt_cont_buf_len; + unsigned opt_cont_buf_len; pcapng_interface_statistics_block_t isb; wtapng_if_stats_mandatory_t* if_stats_mand; @@ -2946,13 +2946,13 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of an ISB is too small (< %u)", bh->block_total_length, MIN_ISB_SIZE); - return FALSE; + return false; } /* "Interface Statistics Block" read fixed part */ if (!wtap_read_bytes(fh, &isb, sizeof isb, err, err_info)) { ws_debug("failed to read packet data"); - return FALSE; + return false; } /* @@ -2977,44 +2977,44 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, /* Options */ opt_cont_buf_len = bh->block_total_length - - (MIN_BLOCK_SIZE + (guint)sizeof isb); /* fixed and variable part, including padding */ + (MIN_BLOCK_SIZE + (unsigned)sizeof isb); /* fixed and variable part, including padding */ if (!pcapng_process_options(fh, wblock, section_info, opt_cont_buf_len, pcapng_process_interface_statistics_block_option, OPT_SECTION_BYTE_ORDER, err, err_info)) - return FALSE; + return false; /* * We don't return these to the caller in pcapng_read(). */ - wblock->internal = TRUE; + wblock->internal = true; - return TRUE; + return true; } #define NFLX_BLOCK_TYPE_EVENT 1 #define NFLX_BLOCK_TYPE_SKIP 2 typedef struct pcapng_nflx_custom_block_s { - guint32 nflx_type; + uint32_t nflx_type; } pcapng_nflx_custom_block_t; -#define MIN_NFLX_CB_SIZE ((guint32)(MIN_CB_SIZE + sizeof(pcapng_nflx_custom_block_t))) +#define MIN_NFLX_CB_SIZE ((uint32_t)(MIN_CB_SIZE + sizeof(pcapng_nflx_custom_block_t))) -static gboolean +static bool pcapng_read_nflx_custom_block(FILE_T fh, pcapng_block_header_t *bh, section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { pcapng_nflx_custom_block_t nflx_cb; - guint opt_cont_buf_len; - guint32 type, skipped; + unsigned opt_cont_buf_len; + uint32_t type, skipped; if (bh->block_total_length < MIN_NFLX_CB_SIZE) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of a Netflix CB is too small (< %u)", bh->block_total_length, MIN_NFLX_CB_SIZE); - return FALSE; + return false; } wblock->rec->rec_type = REC_TYPE_CUSTOM_BLOCK; @@ -3022,7 +3022,7 @@ pcapng_read_nflx_custom_block(FILE_T fh, pcapng_block_header_t *bh, /* "NFLX Custom Block" read fixed part */ if (!wtap_read_bytes(fh, &nflx_cb, sizeof nflx_cb, err, err_info)) { ws_debug("Failed to read nflx type"); - return FALSE; + return false; } type = GUINT32_FROM_LE(nflx_cb.nflx_type); ws_debug("BBLog type: %u", type); @@ -3043,44 +3043,44 @@ pcapng_read_nflx_custom_block(FILE_T fh, pcapng_block_header_t *bh, * * Make sure we have that much data in the block. */ - if (bh->block_total_length < MIN_NFLX_CB_SIZE + (guint32)sizeof(guint32)) { + if (bh->block_total_length < MIN_NFLX_CB_SIZE + (uint32_t)sizeof(uint32_t)) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of a Netflix skip CB is too small (< %u)", bh->block_total_length, - MIN_NFLX_CB_SIZE + (guint32)sizeof(guint32)); - return FALSE; + MIN_NFLX_CB_SIZE + (uint32_t)sizeof(uint32_t)); + return false; } - if (!wtap_read_bytes(fh, &skipped, sizeof(guint32), err, err_info)) { + if (!wtap_read_bytes(fh, &skipped, sizeof(uint32_t), err, err_info)) { ws_debug("Failed to read skipped"); - return FALSE; + return false; } wblock->rec->presence_flags = 0; wblock->rec->rec_header.custom_block_header.length = 4; wblock->rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.type = BBLOG_TYPE_SKIPPED_BLOCK; wblock->rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.skipped = GUINT32_FROM_LE(skipped); - wblock->internal = FALSE; - opt_cont_buf_len = bh->block_total_length - MIN_NFLX_CB_SIZE - sizeof(guint32); + wblock->internal = false; + opt_cont_buf_len = bh->block_total_length - MIN_NFLX_CB_SIZE - sizeof(uint32_t); ws_debug("skipped: %u", wblock->rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.skipped); break; default: ws_debug("Unknown type %u", type); - return FALSE; + return false; } /* Options */ if (!pcapng_process_options(fh, wblock, section_info, opt_cont_buf_len, NULL, OPT_LITTLE_ENDIAN, err, err_info)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean +static bool pcapng_handle_generic_custom_block(FILE_T fh, pcapng_block_header_t *bh, - guint32 pen, wtapng_block_t *wblock, - int *err, gchar **err_info) + uint32_t pen, wtapng_block_t *wblock, + int *err, char **err_info) { - guint to_read; + unsigned to_read; ws_debug("unknown pen %u", pen); if (bh->block_total_length % 4) { @@ -3095,23 +3095,23 @@ pcapng_handle_generic_custom_block(FILE_T fh, pcapng_block_header_t *bh, wblock->rec->rec_header.custom_block_header.pen = pen; wblock->rec->rec_header.custom_block_header.copy_allowed = (bh->block_type == BLOCK_TYPE_CB_COPY); if (!wtap_read_packet_bytes(fh, wblock->frame_buffer, to_read, err, err_info)) { - return FALSE; + return false; } /* * We return these to the caller in pcapng_read(). */ - wblock->internal = FALSE; - return TRUE; + wblock->internal = false; + return true; } -static gboolean +static bool pcapng_read_custom_block(FILE_T fh, pcapng_block_header_t *bh, section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { pcapng_custom_block_t cb; - guint32 pen; + uint32_t pen; /* Is this block long enough to be an CB? */ if (bh->block_total_length < MIN_CB_SIZE) { @@ -3121,7 +3121,7 @@ pcapng_read_custom_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of a CB is too small (< %u)", bh->block_total_length, MIN_CB_SIZE); - return FALSE; + return false; } wblock->block = wtap_block_create(WTAP_BLOCK_CUSTOM); @@ -3129,7 +3129,7 @@ pcapng_read_custom_block(FILE_T fh, pcapng_block_header_t *bh, /* Custom block read fixed part */ if (!wtap_read_bytes(fh, &cb, sizeof cb, err, err_info)) { ws_debug("failed to read pen"); - return FALSE; + return false; } if (section_info->byte_swapped) { pen = GUINT32_SWAP_LE_BE(cb.pen); @@ -3141,37 +3141,37 @@ pcapng_read_custom_block(FILE_T fh, pcapng_block_header_t *bh, switch (pen) { case PEN_NFLX: if (!pcapng_read_nflx_custom_block(fh, bh, section_info, wblock, err, err_info)) - return FALSE; + return false; break; default: if (!pcapng_handle_generic_custom_block(fh, bh, pen, wblock, err, err_info)) { - return FALSE; + return false; } break; } wblock->rec->block = wblock->block; wblock->block = NULL; - wblock->internal = FALSE; + wblock->internal = false; - return TRUE; + return true; } -static gboolean -pcapng_read_sysdig_event_block(FILE_T fh, pcapng_block_header_t *bh, +static bool +pcapng_read_sysdig_event_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, const section_info_t *section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { unsigned block_read; - guint16 cpu_id; - guint64 wire_ts; - guint64 ts; - guint64 thread_id; - guint32 event_len; - guint16 event_type; - guint32 nparams = 0; - guint min_event_size; + uint16_t cpu_id; + uint64_t wire_ts; + uint64_t ts; + uint64_t thread_id; + uint32_t event_len; + uint16_t event_type; + uint32_t nparams = 0; + unsigned min_event_size; switch (bh->block_type) { case BLOCK_TYPE_SYSDIG_EVENT_V2_LARGE: @@ -3187,41 +3187,42 @@ pcapng_read_sysdig_event_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of a Sysdig event block is too small (< %u)", bh->block_total_length, min_event_size); - return FALSE; + return false; } wblock->rec->rec_type = REC_TYPE_SYSCALL; wblock->rec->rec_header.syscall_header.record_type = bh->block_type; - wblock->rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN /*|WTAP_HAS_INTERFACE_ID */; + wblock->rec->presence_flags = WTAP_HAS_CAP_LEN /*|WTAP_HAS_INTERFACE_ID */; wblock->rec->tsprec = WTAP_TSPREC_NSEC; if (!wtap_read_bytes(fh, &cpu_id, sizeof cpu_id, err, err_info)) { ws_debug("failed to read sysdig event cpu id"); - return FALSE; + return false; } if (!wtap_read_bytes(fh, &wire_ts, sizeof wire_ts, err, err_info)) { ws_debug("failed to read sysdig event timestamp"); - return FALSE; + return false; } if (!wtap_read_bytes(fh, &thread_id, sizeof thread_id, err, err_info)) { ws_debug("failed to read sysdig event thread id"); - return FALSE; + return false; } if (!wtap_read_bytes(fh, &event_len, sizeof event_len, err, err_info)) { ws_debug("failed to read sysdig event length"); - return FALSE; + return false; } if (!wtap_read_bytes(fh, &event_type, sizeof event_type, err, err_info)) { ws_debug("failed to read sysdig event type"); - return FALSE; + return false; } if (bh->block_type == BLOCK_TYPE_SYSDIG_EVENT_V2 || bh->block_type == BLOCK_TYPE_SYSDIG_EVENT_V2_LARGE) { if (!wtap_read_bytes(fh, &nparams, sizeof nparams, err, err_info)) { ws_debug("failed to read sysdig number of parameters"); - return FALSE; + return false; } } + wblock->rec->rec_header.syscall_header.pathname = wth->pathname; wblock->rec->rec_header.syscall_header.byte_order = G_BYTE_ORDER; /* XXX Use Gxxx_FROM_LE macros instead? */ @@ -3247,6 +3248,10 @@ pcapng_read_sysdig_event_block(FILE_T fh, pcapng_block_header_t *bh, wblock->rec->rec_header.syscall_header.nparams = nparams; } + if (ts) { + wblock->rec->presence_flags |= WTAP_HAS_TS; + } + wblock->rec->ts.secs = (time_t) (ts / 1000000000); wblock->rec->ts.nsecs = (int) (ts % 1000000000); @@ -3257,30 +3262,30 @@ pcapng_read_sysdig_event_block(FILE_T fh, pcapng_block_header_t *bh, /* "Sysdig Event Block" read event data */ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer, block_read, err, err_info)) - return FALSE; + return false; /* XXX Read comment? */ /* * We return these to the caller in pcapng_read(). */ - wblock->internal = FALSE; + wblock->internal = false; - return TRUE; + return true; } -static gboolean -pcapng_read_systemd_journal_export_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn _U_, wtapng_block_t *wblock, int *err, gchar **err_info) +static bool +pcapng_read_systemd_journal_export_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn _U_, wtapng_block_t *wblock, int *err, char **err_info) { - guint32 entry_length; - guint64 rt_ts; - gboolean have_ts = FALSE; + uint32_t entry_length; + uint64_t rt_ts; + bool have_ts = false; if (bh->block_total_length < MIN_SYSTEMD_JOURNAL_EXPORT_BLOCK_SIZE) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of a systemd journal export block is too small (< %u)", bh->block_total_length, MIN_SYSTEMD_JOURNAL_EXPORT_BLOCK_SIZE); - return FALSE; + return false; } entry_length = bh->block_total_length - MIN_BLOCK_SIZE; @@ -3288,7 +3293,7 @@ pcapng_read_systemd_journal_export_block(wtap *wth, FILE_T fh, pcapng_block_head /* Includes padding bytes. */ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer, entry_length, err, err_info)) { - return FALSE; + return false; } /* @@ -3297,7 +3302,7 @@ pcapng_read_systemd_journal_export_block(wtap *wth, FILE_T fh, pcapng_block_head */ ws_buffer_assure_space(wblock->frame_buffer, entry_length+1); - gchar *buf_ptr = (gchar *) ws_buffer_start_ptr(wblock->frame_buffer); + char *buf_ptr = (char *) ws_buffer_start_ptr(wblock->frame_buffer); while (entry_length > 0 && buf_ptr[entry_length-1] == '\0') { entry_length--; } @@ -3306,7 +3311,7 @@ pcapng_read_systemd_journal_export_block(wtap *wth, FILE_T fh, pcapng_block_head *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: entry length %u is too small (< %u)", bh->block_total_length, MIN_SYSTEMD_JOURNAL_EXPORT_ENTRY_SIZE); - return FALSE; + return false; } ws_debug("entry_length %u", entry_length); @@ -3342,7 +3347,7 @@ pcapng_read_systemd_journal_export_block(wtap *wth, FILE_T fh, pcapng_block_head /* * We return these to the caller in pcapng_read(). */ - wblock->internal = FALSE; + wblock->internal = false; if (wth->file_encap == WTAP_ENCAP_NONE) { /* @@ -3353,10 +3358,10 @@ pcapng_read_systemd_journal_export_block(wtap *wth, FILE_T fh, pcapng_block_head wth->file_encap = WTAP_ENCAP_PER_PACKET; } - return TRUE; + return true; } -static gboolean +static bool pcapng_read_unknown_block(FILE_T fh, pcapng_block_header_t *bh, #ifdef HAVE_PLUGINS const section_info_t *section_info, @@ -3364,9 +3369,9 @@ pcapng_read_unknown_block(FILE_T fh, pcapng_block_header_t *bh, const section_info_t *section_info _U_, #endif wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { - guint32 block_read; + uint32_t block_read; #ifdef HAVE_PLUGINS block_handler *handler; #endif @@ -3375,7 +3380,7 @@ pcapng_read_unknown_block(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u of an unknown block type is less than the minimum block size %u", bh->block_total_length, MIN_BLOCK_SIZE); - return FALSE; + return false; } block_read = bh->block_total_length - MIN_BLOCK_SIZE; @@ -3390,37 +3395,37 @@ pcapng_read_unknown_block(FILE_T fh, pcapng_block_header_t *bh, /* Yes - call it to read this block type. */ if (!handler->reader(fh, block_read, section_info->byte_swapped, wblock, err, err_info)) - return FALSE; + return false; } else #endif { /* No. Skip over this unknown block. */ if (!wtap_read_bytes(fh, NULL, block_read, err, err_info)) { - return FALSE; + return false; } /* * We're skipping this, so we won't return these to the caller * in pcapng_read(). */ - wblock->internal = TRUE; + wblock->internal = true; } - return TRUE; + return true; } -static gboolean +static bool pcapng_read_and_check_block_trailer(FILE_T fh, pcapng_block_header_t *bh, section_info_t *section_info, - int *err, gchar **err_info) + int *err, char **err_info) { - guint32 block_total_length; + uint32_t block_total_length; /* sanity check: first and second block lengths must match */ if (!wtap_read_bytes(fh, &block_total_length, sizeof block_total_length, err, err_info)) { ws_debug("couldn't read second block length"); - return FALSE; + return false; } if (section_info->byte_swapped) @@ -3443,17 +3448,17 @@ pcapng_read_and_check_block_trailer(FILE_T fh, pcapng_block_header_t *bh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block lengths (first %u and second %u) don't match", bh->block_total_length, block_total_length); - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool pcapng_read_block(wtap *wth, FILE_T fh, pcapng_t *pn, section_info_t *section_info, section_info_t *new_section_info, wtapng_block_t *wblock, - int *err, gchar **err_info) + int *err, char **err_info) { block_return_val ret; pcapng_block_header_t bh; @@ -3463,7 +3468,7 @@ pcapng_read_block(wtap *wth, FILE_T fh, pcapng_t *pn, /* Try to read the (next) block header */ if (!wtap_read_bytes_or_eof(fh, &bh, sizeof bh, err, err_info)) { ws_debug("wtap_read_bytes_or_eof() failed, err = %d.", *err); - return FALSE; + return false; } /* @@ -3499,7 +3504,7 @@ pcapng_read_block(wtap *wth, FILE_T fh, pcapng_t *pn, ret = pcapng_read_section_header_block(fh, &bh, new_section_info, wblock, err, err_info); if (ret != PCAPNG_BLOCK_OK) { - return FALSE; + return false; } /* @@ -3559,7 +3564,7 @@ pcapng_read_block(wtap *wth, FILE_T fh, pcapng_t *pn, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pcapng: total block length %u is too large (> %u)", bh.block_total_length, MAX_BLOCK_SIZE); - return FALSE; + return false; } /* @@ -3575,31 +3580,31 @@ pcapng_read_block(wtap *wth, FILE_T fh, pcapng_t *pn, switch (bh.block_type) { case(BLOCK_TYPE_IDB): if (!pcapng_read_if_descr_block(wth, fh, &bh, section_info, wblock, err, err_info)) - return FALSE; + return false; break; case(BLOCK_TYPE_PB): - if (!pcapng_read_packet_block(fh, &bh, section_info, wblock, err, err_info, FALSE)) - return FALSE; + if (!pcapng_read_packet_block(fh, &bh, section_info, wblock, err, err_info, false)) + return false; break; case(BLOCK_TYPE_SPB): if (!pcapng_read_simple_packet_block(fh, &bh, section_info, wblock, err, err_info)) - return FALSE; + return false; break; case(BLOCK_TYPE_EPB): - if (!pcapng_read_packet_block(fh, &bh, section_info, wblock, err, err_info, TRUE)) - return FALSE; + if (!pcapng_read_packet_block(fh, &bh, section_info, wblock, err, err_info, true)) + return false; break; case(BLOCK_TYPE_NRB): if (!pcapng_read_name_resolution_block(fh, &bh, section_info, wblock, err, err_info)) - return FALSE; + return false; break; case(BLOCK_TYPE_ISB): if (!pcapng_read_interface_statistics_block(fh, &bh, section_info, wblock, err, err_info)) - return FALSE; + return false; break; case(BLOCK_TYPE_DSB): if (!pcapng_read_decryption_secrets_block(fh, &bh, section_info, wblock, err, err_info)) - return FALSE; + return false; break; case BLOCK_TYPE_SYSDIG_MI: case BLOCK_TYPE_SYSDIG_PL_V1: @@ -3617,30 +3622,30 @@ pcapng_read_block(wtap *wth, FILE_T fh, pcapng_t *pn, case BLOCK_TYPE_SYSDIG_FDL_V2: case BLOCK_TYPE_SYSDIG_IL_V2: case BLOCK_TYPE_SYSDIG_UL_V2: - if (!pcapng_read_sysdig_meta_event_block(fh, &bh, wblock, err, err_info)) - return FALSE; + if (!pcapng_read_meta_event_block(fh, &bh, wblock, err, err_info)) + return false; break; case(BLOCK_TYPE_CB_COPY): case(BLOCK_TYPE_CB_NO_COPY): if (!pcapng_read_custom_block(fh, &bh, section_info, wblock, err, err_info)) - return FALSE; + return false; break; case(BLOCK_TYPE_SYSDIG_EVENT): case(BLOCK_TYPE_SYSDIG_EVENT_V2): case(BLOCK_TYPE_SYSDIG_EVENT_V2_LARGE): /* case(BLOCK_TYPE_SYSDIG_EVF): */ - if (!pcapng_read_sysdig_event_block(fh, &bh, section_info, wblock, err, err_info)) - return FALSE; + if (!pcapng_read_sysdig_event_block(wth, fh, &bh, section_info, wblock, err, err_info)) + return false; break; case(BLOCK_TYPE_SYSTEMD_JOURNAL_EXPORT): if (!pcapng_read_systemd_journal_export_block(wth, fh, &bh, pn, wblock, err, err_info)) - return FALSE; + return false; break; default: ws_debug("Unknown block_type: 0x%08x (block ignored), block total length %d", bh.block_type, bh.block_total_length); if (!pcapng_read_unknown_block(fh, &bh, section_info, wblock, err, err_info)) - return FALSE; + return false; break; } } @@ -3650,9 +3655,9 @@ pcapng_read_block(wtap *wth, FILE_T fh, pcapng_t *pn, */ if (!pcapng_read_and_check_block_trailer(fh, &bh, section_info, err, err_info)) { /* Not readable or not valid. */ - return FALSE; + return false; } - return TRUE; + return true; } /* Process an IDB that we've just read. The contents of wblock are copied as needed. */ @@ -3664,7 +3669,7 @@ pcapng_process_idb(wtap *wth, section_info_t *section_info, interface_info_t iface_info; wtapng_if_descr_mandatory_t *if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data), *wblock_if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(wblock->block); - guint8 if_fcslen; + uint8_t if_fcslen; wtap_block_copy(int_data, wblock->block); @@ -3727,7 +3732,7 @@ pcapng_process_nrb(wtap *wth, wtapng_block_t *wblock) wtapng_process_nrb(wth, wblock->block); if (wth->nrbs == NULL) { - wth->nrbs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + wth->nrbs = g_array_new(false, false, sizeof(wtap_block_t)); } /* Store NRB such that it can be saved by the dumper. */ g_array_append_val(wth->nrbs, wblock->block); @@ -3745,16 +3750,16 @@ pcapng_process_dsb(wtap *wth, wtapng_block_t *wblock) /* Process a Sysdig meta event block that we have just read. */ static void -pcapng_process_sysdig_mev(wtap *wth, wtapng_block_t *wblock) +pcapng_process_meta_event(wtap *wth, wtapng_block_t *wblock) { - // XXX add wtapng_process_sysdig_meb(wth, wblock->block); + // XXX add wtapng_process_meta_event(wth, wblock->block); /* Store meta event such that it can be saved by the dumper. */ - g_array_append_val(wth->sysdig_meta_events, wblock->block); + g_array_append_val(wth->meta_events, wblock->block); } static void -pcapng_process_internal_block(wtap *wth, pcapng_t *pcapng, section_info_t *current_section, section_info_t new_section, wtapng_block_t *wblock, const gint64 *data_offset) +pcapng_process_internal_block(wtap *wth, pcapng_t *pcapng, section_info_t *current_section, section_info_t new_section, wtapng_block_t *wblock, const int64_t *data_offset) { wtap_block_t wtapng_if_descr; wtap_block_t if_stats; @@ -3770,6 +3775,7 @@ pcapng_process_internal_block(wtap *wth, pcapng_t *pcapng, section_info_t *curre * Add this SHB to the table of SHBs. */ g_array_append_val(wth->shb_hdrs, wblock->block); + g_array_append_val(wth->shb_iface_to_global, wth->interface_data->len); /* * Update the current section number, and add @@ -3777,7 +3783,7 @@ pcapng_process_internal_block(wtap *wth, pcapng_t *pcapng, section_info_t *curre * section_info_t's for this file. */ pcapng->current_section_number++; - new_section.interfaces = g_array_new(FALSE, FALSE, sizeof(interface_info_t)); + new_section.interfaces = g_array_new(false, false, sizeof(interface_info_t)); new_section.shb_off = *data_offset; g_array_append_val(pcapng->sections, new_section); break; @@ -3836,7 +3842,7 @@ pcapng_process_internal_block(wtap *wth, pcapng_t *pcapng, section_info_t *curre if (wtapng_if_descr_mand->num_stat_entries == 0) { /* First ISB found, no previous entry */ ws_debug("block type BLOCK_TYPE_ISB. First ISB found, no previous entry"); - wtapng_if_descr_mand->interface_statistics = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + wtapng_if_descr_mand->interface_statistics = g_array_new(false, false, sizeof(wtap_block_t)); } if_stats = wtap_block_create(WTAP_BLOCK_IF_STATISTICS); @@ -3868,9 +3874,9 @@ pcapng_process_internal_block(wtap *wth, pcapng_t *pcapng, section_info_t *curre case BLOCK_TYPE_SYSDIG_FDL_V2: case BLOCK_TYPE_SYSDIG_IL_V2: case BLOCK_TYPE_SYSDIG_UL_V2: - /* Decryption secrets. */ + /* Meta events */ ws_debug("block type Sysdig meta event"); - pcapng_process_sysdig_mev(wth, wblock); + pcapng_process_meta_event(wth, wblock); /* Do not free wblock->block, it is consumed by pcapng_process_sysdig_meb */ break; @@ -3883,12 +3889,12 @@ pcapng_process_internal_block(wtap *wth, pcapng_t *pcapng, section_info_t *curre /* classic wtap: open capture file */ wtap_open_return_val -pcapng_open(wtap *wth, int *err, gchar **err_info) +pcapng_open(wtap *wth, int *err, char **err_info) { wtapng_block_t wblock; pcapng_t *pcapng; pcapng_block_header_t bh; - gint64 saved_offset; + int64_t saved_offset; section_info_t first_section, new_section, *current_section; ws_debug("opening file"); @@ -4009,7 +4015,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) /* * Create the array of interfaces for the first section. */ - first_section.interfaces = g_array_new(FALSE, FALSE, sizeof(interface_info_t)); + first_section.interfaces = g_array_new(false, false, sizeof(interface_info_t)); /* * The first section is at the very beginning of the file. @@ -4020,7 +4026,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) * Allocate the sections table with space reserved for the first * section, and add that section. */ - pcapng->sections = g_array_sized_new(FALSE, FALSE, sizeof(section_info_t), 1); + pcapng->sections = g_array_sized_new(false, false, sizeof(section_info_t), 1); g_array_append_val(pcapng->sections, first_section); wth->subtype_read = pcapng_read; @@ -4032,9 +4038,9 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) * Resolution Blocks, and Sysdig meta event blocks such that a * wtap_dumper can refer to them right after opening the capture * file. */ - wth->dsbs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); - wth->nrbs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); - wth->sysdig_meta_events = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + wth->dsbs = g_array_new(false, false, sizeof(wtap_block_t)); + wth->nrbs = g_array_new(false, false, sizeof(wtap_block_t)); + wth->meta_events = g_array_new(false, false, sizeof(wtap_block_t)); /* Most other capture types (such as pcap) support a single link-layer * type, indicated in the header, and don't support WTAP_ENCAP_PER_PACKET. @@ -4116,9 +4122,9 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) } /* classic wtap: read packet */ -static gboolean +static bool pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *data_offset) + char **err_info, int64_t *data_offset) { pcapng_t *pcapng = (pcapng_t *)wth->priv; section_info_t *current_section, new_section; @@ -4146,7 +4152,7 @@ pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, ws_noisy("data_offset is finally %" PRId64, *data_offset); ws_debug("couldn't read packet block"); wtap_block_unref(wblock.block); - return FALSE; + return false; } if (!wblock.internal) { @@ -4171,14 +4177,14 @@ pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, rec->presence_flags |= WTAP_HAS_SECTION_NUMBER; rec->section_number = pcapng->current_section_number; - return TRUE; + return true; } /* classic wtap: seek to file position and read packet */ -static gboolean -pcapng_seek_read(wtap *wth, gint64 seek_off, +static bool +pcapng_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { pcapng_t *pcapng = (pcapng_t *)wth->priv; section_info_t *section_info, new_section; @@ -4187,7 +4193,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, /* seek to the right file position */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) < 0) { - return FALSE; /* Seek error */ + return false; /* Seek error */ } ws_noisy("reading at offset %" PRIu64, seek_off); @@ -4207,7 +4213,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, * Yes, that's O(n) in the number of blocks, but we're unlikely to * have many blocks and pretty unlikely to have more than one. */ - guint section_number = pcapng->sections->len - 1; + unsigned section_number = pcapng->sections->len - 1; for (;;) { section_info = &g_array_index(pcapng->sections, section_info_t, section_number); @@ -4230,7 +4236,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, &new_section, &wblock, err, err_info)) { ws_debug("couldn't read packet block (err=%d).", *err); wtap_block_unref(wblock.block); - return FALSE; + return false; } /* block must not be one we process internally rather than supplying */ @@ -4238,7 +4244,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, ws_debug("block type 0x%08x is not one we return", wblock.type); wtap_block_unref(wblock.block); - return FALSE; + return false; } wtap_block_unref(wblock.block); @@ -4247,7 +4253,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, rec->presence_flags |= WTAP_HAS_SECTION_NUMBER; rec->section_number = section_number; - return TRUE; + return true; } /* classic wtap: close capture file */ @@ -4261,89 +4267,77 @@ pcapng_close(wtap *wth) /* * Free up the interfaces tables for all the sections. */ - for (guint i = 0; i < pcapng->sections->len; i++) { + for (unsigned i = 0; i < pcapng->sections->len; i++) { section_info_t *section_info = &g_array_index(pcapng->sections, section_info_t, i); - g_array_free(section_info->interfaces, TRUE); + g_array_free(section_info->interfaces, true); } - g_array_free(pcapng->sections, TRUE); + g_array_free(pcapng->sections, true); } -typedef guint32 (*compute_option_size_func)(wtap_block_t, guint, wtap_opttype_e, wtap_optval_t*); +typedef uint32_t (*compute_option_size_func)(wtap_block_t, unsigned, wtap_opttype_e, wtap_optval_t*); typedef struct compute_options_size_t { - guint32 size; + uint32_t size; compute_option_size_func compute_option_size; } compute_options_size_t; -static guint32 pcapng_compute_string_option_size(wtap_optval_t *optval) -{ - guint32 size = 0, pad; +/* + * As it says at the top of the file, an option sizer "calculates how many + * bytes the option's data requires, not including any padding bytes." + * Callers are responsible for rounding up to multiples of 4 bytes. + * compute_block_options_size() does that for each option in the block; + * option writers that call an option sizer (which helps ensure that the + * sizes are internally consistent) should do the same. + */ - size = (guint32)strlen(optval->stringval) & 0xffff; - if ((size % 4)) { - pad = 4 - (size % 4); - } else { - pad = 0; - } +static uint32_t pcapng_compute_string_option_size(wtap_optval_t *optval) +{ + uint32_t size = 0; - size += pad; + size = (uint32_t)strlen(optval->stringval) & 0xffff; return size; } #if 0 -static guint32 pcapng_compute_bytes_option_size(wtap_optval_t *optval) +static uint32_t pcapng_compute_bytes_option_size(wtap_optval_t *optval) { - guint32 size = 0, pad; + uint32_t size = 0; - size = (guint32)g_bytes_get_size(optval->byteval) & 0xffff; - if ((size % 4)) { - pad = 4 - (size % 4); - } else { - pad = 0; - } - - size += pad; + size = (uint32_t)g_bytes_get_size(optval->byteval) & 0xffff; return size; } #endif -static guint32 pcapng_compute_if_filter_option_size(wtap_optval_t *optval) +static uint32_t pcapng_compute_if_filter_option_size(wtap_optval_t *optval) { if_filter_opt_t* filter = &optval->if_filterval; - guint32 size; - guint32 pad; + uint32_t size; if (filter->type == if_filter_pcap) { - size = (guint32)(strlen(filter->data.filter_str) + 1) & 0xffff; + size = (uint32_t)(strlen(filter->data.filter_str) + 1) & 0xffff; } else if (filter->type == if_filter_bpf) { - size = (guint32)((filter->data.bpf_prog.bpf_prog_len * 8) + 1) & 0xffff; + size = (uint32_t)((filter->data.bpf_prog.bpf_prog_len * 8) + 1) & 0xffff; } else { /* Unknown type; don't write it */ size = 0; } - if ((size % 4)) { - pad = 4 - (size % 4); - } else { - pad = 0; - } - size += pad; return size; } -static guint32 pcapng_compute_custom_option_size(wtap_optval_t *optval) +static uint32_t pcapng_compute_custom_option_size(wtap_optval_t *optval) { - size_t size, pad; + size_t size; /* PEN */ - size = sizeof(guint32); + size = sizeof(uint32_t); switch (optval->custom_opt.pen) { case PEN_NFLX: /* NFLX type */ - size += sizeof(guint32); + size += sizeof(uint32_t); size += optval->custom_opt.data.nflx_data.custom_data_len; break; default: @@ -4353,21 +4347,14 @@ static guint32 pcapng_compute_custom_option_size(wtap_optval_t *optval) if (size > 65535) { size = 65535; } - if ((size % 4)) { - pad = 4 - (size % 4); - } else { - pad = 0; - } - size += pad; - - return (guint32)size; + return (uint32_t)size; } -static guint32 pcapng_compute_packet_hash_option_size(wtap_optval_t *optval) +static uint32_t pcapng_compute_packet_hash_option_size(wtap_optval_t *optval) { packet_hash_opt_t* hash = &optval->packet_hash; - guint32 size; + uint32_t size; switch (hash->type) { case OPT_HASH_CRC32: @@ -4396,23 +4383,14 @@ static guint32 pcapng_compute_packet_hash_option_size(wtap_optval_t *optval) */ /* Account for the size of the algorithm type field. */ size += 1; -#if 0 - /* compute_block_option_size() handles padding. */ - uint32_t pad; - if ((size % 4)) { - pad = 4 - (size % 4); - } else { - pad = 0; - } - size += pad; -#endif + return size; } -static guint32 pcapng_compute_packet_verdict_option_size(wtap_optval_t *optval) +static uint32_t pcapng_compute_packet_verdict_option_size(wtap_optval_t *optval) { packet_verdict_opt_t* verdict = &optval->packet_verdictval; - guint32 size; + uint32_t size; switch (verdict->type) { @@ -4436,24 +4414,15 @@ static guint32 pcapng_compute_packet_verdict_option_size(wtap_optval_t *optval) if (size) { size += 1; } -#if 0 - /* compute_block_option_size() handles padding. */ - uint32_t pad; - if ((size % 4)) { - pad = 4 - (size % 4); - } else { - pad = 0; - } - size += pad; -#endif + return size; } -static gboolean -compute_block_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type, wtap_optval_t *optval, void *user_data) +static bool +compute_block_option_size(wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type, wtap_optval_t *optval, void *user_data) { compute_options_size_t* options_size = (compute_options_size_t*)user_data; - guint32 size = 0; + uint32_t size = 0; /* * Process the option IDs that are the same for all block types here; @@ -4512,17 +4481,17 @@ compute_block_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_ options_size->size += 4 - (size & 0x03); } } - return TRUE; /* we always succeed */ + return true; /* we always succeed */ } -static guint32 +static uint32_t compute_options_size(wtap_block_t block, compute_option_size_func compute_option_size) { compute_options_size_t compute_options_size; /* * Compute the total size of all the options in the block. - * This always suceeds, so we don't check the return value. + * This always succeeds, so we don't check the return value. */ compute_options_size.size = 0; compute_options_size.compute_option_size = compute_option_size; @@ -4536,9 +4505,9 @@ compute_options_size(wtap_block_t block, compute_option_size_func compute_option return compute_options_size.size; } -static guint32 compute_shb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval) +static uint32_t compute_shb_option_size(wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval) { - guint32 size; + uint32_t size; switch(option_id) { @@ -4555,7 +4524,7 @@ static guint32 compute_shb_option_size(wtap_block_t block _U_, guint option_id, return size; } -typedef gboolean (*write_option_func)(wtap_dumper *, wtap_block_t, guint, wtap_opttype_e, wtap_optval_t*, int*); +typedef bool (*write_option_func)(wtap_dumper *, wtap_block_t, unsigned, wtap_opttype_e, wtap_optval_t*, int*); typedef struct write_options_t { @@ -4565,7 +4534,7 @@ typedef struct write_options_t } write_options_t; -static gboolean pcapng_write_option_eofopt(wtap_dumper *wdh, int *err) +static bool pcapng_write_option_eofopt(wtap_dumper *wdh, int *err) { struct pcapng_option_header option_hdr; @@ -4573,88 +4542,88 @@ static gboolean pcapng_write_option_eofopt(wtap_dumper *wdh, int *err) option_hdr.type = OPT_EOFOPT; option_hdr.value_length = 0; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; - return TRUE; + return false; + return true; } -static gboolean pcapng_write_uint8_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_uint8_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; - const guint32 zero_pad = 0; + const uint32_t zero_pad = 0; - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)1; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)1; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &optval->uint8val, 1, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &zero_pad, 3, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean pcapng_write_uint32_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_uint32_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)4; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)4; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &optval->uint32val, 4, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean pcapng_write_uint64_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_uint64_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)8; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)8; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &optval->uint64val, 8, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean pcapng_write_timestamp_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_timestamp_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; - guint32 high, low; + uint32_t high, low; - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)8; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)8; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; - high = (guint32)(optval->uint64val >> 32); - low = (guint32)(optval->uint64val >> 0); + high = (uint32_t)(optval->uint64val >> 32); + low = (uint32_t)(optval->uint64val >> 0); if (!wtap_dump_file_write(wdh, &high, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &low, 4, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean pcapng_write_string_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_string_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; size_t size = strlen(optval->stringval); - const guint32 zero_pad = 0; - guint32 pad; + const uint32_t zero_pad = 0; + uint32_t pad; if (size == 0) - return TRUE; + return true; if (size > 65535) { /* * Too big to fit in the option. @@ -4662,17 +4631,17 @@ static gboolean pcapng_write_string_option(wtap_dumper *wdh, guint option_id, wt * * XXX - truncate it? Report an error? */ - return TRUE; + return true; } /* String options don't consider pad bytes part of the length */ - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)size; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)size; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, optval->stringval, size, err)) - return FALSE; + return false; if ((size % 4)) { pad = 4 - (size % 4); @@ -4683,22 +4652,22 @@ static gboolean pcapng_write_string_option(wtap_dumper *wdh, guint option_id, wt /* write padding (if any) */ if (pad != 0) { if (!wtap_dump_file_write(wdh, &zero_pad, pad, err)) - return FALSE; + return false; } - return TRUE; + return true; } #if 0 -static gboolean pcapng_write_bytes_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_bytes_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; size_t size = g_bytes_get_size(optval->byteval); - const guint32 zero_pad = 0; - guint32 pad; + const uint32_t zero_pad = 0; + uint32_t pad; if (size == 0) - return TRUE; + return true; if (size > 65535) { /* * Too big to fit in the option. @@ -4706,17 +4675,17 @@ static gboolean pcapng_write_bytes_option(wtap_dumper *wdh, guint option_id, wta * * XXX - truncate it? Report an error? */ - return TRUE; + return true; } /* Bytes options don't consider pad bytes part of the length */ - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)size; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)size; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, optval->stringval, size, err)) - return FALSE; + return false; if ((size % 4)) { pad = 4 - (size % 4); @@ -4727,51 +4696,51 @@ static gboolean pcapng_write_bytes_option(wtap_dumper *wdh, guint option_id, wta /* write padding (if any) */ if (pad != 0) { if (!wtap_dump_file_write(wdh, &zero_pad, pad, err)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean pcapng_write_ipv4_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_ipv4_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)4; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)4; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &optval->ipv4val, 1, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean pcapng_write_ipv6_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_ipv6_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)IPv6_ADDR_SIZE; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)IPv6_ADDR_SIZE; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &optval->ipv6val.bytes, IPv6_ADDR_SIZE, err)) - return FALSE; + return false; - return TRUE; + return true; } #endif -static gboolean pcapng_write_if_filter_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_if_filter_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { if_filter_opt_t* filter = &optval->if_filterval; - guint32 size, pad; - guint8 filter_type; + uint32_t size, pad; + uint8_t filter_type; size_t filter_data_len; struct pcapng_option_header option_hdr; - const guint32 zero_pad = 0; + const uint32_t zero_pad = 0; switch (filter->type) { @@ -4785,7 +4754,7 @@ static gboolean pcapng_write_if_filter_option(wtap_dumper *wdh, guint option_id, * * XXX - truncate it? Report an error? */ - return TRUE; + return true; } break; @@ -4800,15 +4769,15 @@ static gboolean pcapng_write_if_filter_option(wtap_dumper *wdh, guint option_id, * * XXX - truncate it? Report an error? */ - return TRUE; + return true; } break; default: /* Unknown filter type; don't write anything. */ - return TRUE; + return true; } - size = (guint32)(filter_data_len + 1); + size = (uint32_t)(filter_data_len + 1); if ((size % 4)) { pad = 4 - (size % 4); } else { @@ -4818,58 +4787,58 @@ static gboolean pcapng_write_if_filter_option(wtap_dumper *wdh, guint option_id, option_hdr.type = option_id; option_hdr.value_length = size; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; /* Write the filter type */ if (!wtap_dump_file_write(wdh, &filter_type, 1, err)) - return FALSE; + return false; switch (filter->type) { case if_filter_pcap: /* Write the filter string */ if (!wtap_dump_file_write(wdh, filter->data.filter_str, filter_data_len, err)) - return FALSE; + return false; break; case if_filter_bpf: if (!wtap_dump_file_write(wdh, filter->data.bpf_prog.bpf_prog, filter_data_len, err)) - return FALSE; + return false; break; default: ws_assert_not_reached(); - return TRUE; + return true; } /* write padding (if any) */ if (pad != 0) { if (!wtap_dump_file_write(wdh, &zero_pad, pad, err)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean pcapng_write_custom_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_custom_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { struct pcapng_option_header option_hdr; - gsize pad; - gsize size; - const guint32 zero_pad = 0; - guint32 pen, type; - gboolean use_little_endian; + size_t pad; + size_t size; + const uint32_t zero_pad = 0; + uint32_t pen, type; + bool use_little_endian; if ((option_id == OPT_CUSTOM_STR_NO_COPY) || (option_id == OPT_CUSTOM_BIN_NO_COPY)) - return TRUE; + return true; ws_debug("PEN %d", optval->custom_opt.pen); switch (optval->custom_opt.pen) { case PEN_NFLX: - size = sizeof(guint32) + sizeof(guint32) + optval->custom_opt.data.nflx_data.custom_data_len; + size = sizeof(uint32_t) + sizeof(uint32_t) + optval->custom_opt.data.nflx_data.custom_data_len; use_little_endian = optval->custom_opt.data.nflx_data.use_little_endian; break; default: - size = sizeof(guint32) + optval->custom_opt.data.generic_data.custom_data_len; + size = sizeof(uint32_t) + optval->custom_opt.data.generic_data.custom_data_len; use_little_endian = false; break; } @@ -4881,43 +4850,43 @@ static gboolean pcapng_write_custom_option(wtap_dumper *wdh, guint option_id, wt * * XXX - truncate it? Report an error? */ - return TRUE; + return true; } /* write option header */ - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)size; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)size; if (use_little_endian) { option_hdr.type = GUINT16_TO_LE(option_hdr.type); option_hdr.value_length = GUINT16_TO_LE(option_hdr.value_length); } if (!wtap_dump_file_write(wdh, &option_hdr, sizeof(struct pcapng_option_header), err)) - return FALSE; + return false; /* write PEN */ pen = optval->custom_opt.pen; if (use_little_endian) { pen = GUINT32_TO_LE(pen); } - if (!wtap_dump_file_write(wdh, &pen, sizeof(guint32), err)) - return FALSE; + if (!wtap_dump_file_write(wdh, &pen, sizeof(uint32_t), err)) + return false; switch (optval->custom_opt.pen) { case PEN_NFLX: /* write NFLX type */ type = GUINT32_TO_LE(optval->custom_opt.data.nflx_data.type); ws_debug("type=%d", type); - if (!wtap_dump_file_write(wdh, &type, sizeof(guint32), err)) - return FALSE; + if (!wtap_dump_file_write(wdh, &type, sizeof(uint32_t), err)) + return false; /* write custom data */ if (!wtap_dump_file_write(wdh, optval->custom_opt.data.nflx_data.custom_data, optval->custom_opt.data.nflx_data.custom_data_len, err)) { - return FALSE; + return false; } break; default: /* write custom data */ if (!wtap_dump_file_write(wdh, optval->custom_opt.data.generic_data.custom_data, optval->custom_opt.data.generic_data.custom_data_len, err)) { - return FALSE; + return false; } break; } @@ -4930,28 +4899,28 @@ static gboolean pcapng_write_custom_option(wtap_dumper *wdh, guint option_id, wt } if (pad != 0) { if (!wtap_dump_file_write(wdh, &zero_pad, pad, err)) { - return FALSE; + return false; } } ws_debug("Wrote custom option: type %u, length %u", option_hdr.type, option_hdr.value_length); - return TRUE; + return true; } -static gboolean pcapng_write_packet_verdict_option(wtap_dumper *wdh, guint option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_packet_verdict_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { packet_verdict_opt_t* verdict = &optval->packet_verdictval; struct pcapng_option_header option_hdr; - guint8 type; + uint8_t type; size_t size; - const guint32 zero_pad = 0; - guint32 pad; + const uint32_t zero_pad = 0; + uint32_t pad; + + size = pcapng_compute_packet_verdict_option_size(optval); switch (verdict->type) { case packet_verdict_hardware: - /* Include type octet */ - size = verdict->data.verdict_bytes->len + 1; if (size > 65535) { /* * Too big to fit in the option. @@ -4959,69 +4928,67 @@ static gboolean pcapng_write_packet_verdict_option(wtap_dumper *wdh, guint optio * * XXX - truncate it? Report an error? */ - return TRUE; + return true; } option_hdr.type = option_id; - option_hdr.value_length = (guint16)size; + option_hdr.value_length = (uint16_t)size; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; type = packet_verdict_hardware; - if (!wtap_dump_file_write(wdh, &type, sizeof(guint8), err)) - return FALSE; + if (!wtap_dump_file_write(wdh, &type, sizeof(uint8_t), err)) + return false; if (!wtap_dump_file_write(wdh, verdict->data.verdict_bytes->data, verdict->data.verdict_bytes->len, err)) - return FALSE; + return false; break; case packet_verdict_linux_ebpf_tc: - size = 9; option_hdr.type = option_id; - option_hdr.value_length = (guint16)size; + option_hdr.value_length = (uint16_t)size; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; type = packet_verdict_linux_ebpf_tc; - if (!wtap_dump_file_write(wdh, &type, sizeof(guint8), err)) - return FALSE; + if (!wtap_dump_file_write(wdh, &type, sizeof(uint8_t), err)) + return false; if (!wtap_dump_file_write(wdh, &verdict->data.verdict_linux_ebpf_tc, - sizeof(guint64), err)) - return FALSE; + sizeof(uint64_t), err)) + return false; break; case packet_verdict_linux_ebpf_xdp: - size = 9; option_hdr.type = option_id; - option_hdr.value_length = (guint16)size; + option_hdr.value_length = (uint16_t)size; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; type = packet_verdict_linux_ebpf_xdp; - if (!wtap_dump_file_write(wdh, &type, sizeof(guint8), err)) - return FALSE; + if (!wtap_dump_file_write(wdh, &type, sizeof(uint8_t), err)) + return false; if (!wtap_dump_file_write(wdh, &verdict->data.verdict_linux_ebpf_xdp, - sizeof(guint64), err)) - return FALSE; + sizeof(uint64_t), err)) + return false; break; default: /* Unknown - don't write it out. */ - return TRUE; + return true; } /* write padding (if any) */ if ((size % 4)) { pad = 4 - (size % 4); if (!wtap_dump_file_write(wdh, &zero_pad, pad, err)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean pcapng_write_packet_hash_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) +static bool pcapng_write_packet_hash_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) { packet_hash_opt_t* hash = &optval->packet_hash; struct pcapng_option_header option_hdr; @@ -5039,7 +5006,7 @@ static gboolean pcapng_write_packet_hash_option(wtap_dumper *wdh, unsigned optio * * XXX - truncate it? Report an error? */ - return TRUE; + return true; } if (size > hash->hash_bytes->len + 1) { @@ -5051,7 +5018,7 @@ static gboolean pcapng_write_packet_hash_option(wtap_dumper *wdh, unsigned optio * XXX - Is this the best error type? */ *err = WTAP_ERR_UNWRITABLE_REC_DATA; - return FALSE; + return false; } type = hash->type; @@ -5060,25 +5027,25 @@ static gboolean pcapng_write_packet_hash_option(wtap_dumper *wdh, unsigned optio /* Include type byte */ option_hdr.value_length = (uint16_t)size; if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &type, sizeof(uint8_t), err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, hash->hash_bytes->data, size - 1, err)) - return FALSE; + return false; /* write padding (if any) */ if ((size % 4)) { pad = 4 - (size % 4); if (!wtap_dump_file_write(wdh, &zero_pad, pad, err)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean write_block_option(wtap_block_t block, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data) +static bool write_block_option(wtap_block_t block, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data) { write_options_t* options = (write_options_t*)user_data; @@ -5090,12 +5057,12 @@ static gboolean write_block_option(wtap_block_t block, guint option_id, wtap_opt { case OPT_COMMENT: if (!pcapng_write_string_option(options->wdh, option_id, optval, options->err)) - return FALSE; + return false; break; case OPT_CUSTOM_STR_COPY: case OPT_CUSTOM_BIN_COPY: if (!pcapng_write_custom_option(options->wdh, option_id, optval, options->err)) - return FALSE; + return false; break; case OPT_CUSTOM_STR_NO_COPY: case OPT_CUSTOM_BIN_NO_COPY: @@ -5111,13 +5078,13 @@ static gboolean write_block_option(wtap_block_t block, guint option_id, wtap_opt /* Block-type dependent; call the callback, if we have one. */ if (options->write_option != NULL && !(*options->write_option)(options->wdh, block, option_id, option_type, optval, options->err)) - return FALSE; + return false; break; } - return TRUE; + return true; } -static gboolean +static bool write_options(wtap_dumper *wdh, wtap_block_t block, write_option_func write_option, int *err) { write_options_t options; @@ -5126,13 +5093,13 @@ write_options(wtap_dumper *wdh, wtap_block_t block, write_option_func write_opti options.err = err; options.write_option = write_option; if (!wtap_block_foreach_option(block, write_block_option, &options)) - return FALSE; + return false; /* Write end of options */ return pcapng_write_option_eofopt(wdh, err); } -static gboolean write_wtap_shb_option(wtap_dumper *wdh, wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err) +static bool write_wtap_shb_option(wtap_dumper *wdh, wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err) { switch(option_id) { @@ -5140,32 +5107,32 @@ static gboolean write_wtap_shb_option(wtap_dumper *wdh, wtap_block_t block _U_, case OPT_SHB_OS: case OPT_SHB_USERAPPL: if (!pcapng_write_string_option(wdh, option_id, optval, err)) - return FALSE; + return false; break; default: /* Unknown options - write by datatype? */ break; } - return TRUE; /* success */ + return true; /* success */ } /* Write a section header block. * If we don't have a section block header already, create a default * one with no options. */ -static gboolean +static bool pcapng_write_section_header_block(wtap_dumper *wdh, int *err) { pcapng_block_header_t bh; pcapng_section_header_block_t shb; - guint32 options_size; + uint32_t options_size; wtap_block_t wdh_shb = NULL; if (wdh->shb_hdrs && (wdh->shb_hdrs->len > 0)) { wdh_shb = g_array_index(wdh->shb_hdrs, wtap_block_t, 0); } - bh.block_total_length = (guint32)(sizeof(bh) + sizeof(shb) + 4); + bh.block_total_length = (uint32_t)(sizeof(bh) + sizeof(shb) + 4); options_size = 0; if (wdh_shb) { ws_debug("Have shb_hdr"); @@ -5182,7 +5149,7 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err) bh.block_type = BLOCK_TYPE_SHB; if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) - return FALSE; + return false; /* write block fixed content */ shb.magic = 0x1A2B3C4D; @@ -5196,22 +5163,22 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err) } if (!wtap_dump_file_write(wdh, &shb, sizeof shb, err)) - return FALSE; + return false; if (wdh_shb) { /* Write options, if we have any */ if (options_size != 0) { if (!write_options(wdh, wdh_shb, write_wtap_shb_option, err)) - return FALSE; + return false; } } /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) - return FALSE; + return false; - return TRUE; + return true; } /* options defined in Section 2.5 (Options) @@ -5263,10 +5230,10 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err) * defined in the Linux pbf.h include). * opt_endofopt 0 0 It delimits the end of the optional fields. This block cannot be repeated within a given list of options. */ -static guint32 -compute_epb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval) +static uint32_t +compute_epb_option_size(wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval) { - guint32 size; + uint32_t size; switch(option_id) { @@ -5296,25 +5263,25 @@ compute_epb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e return size; } -static gboolean write_wtap_epb_option(wtap_dumper *wdh, wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err) +static bool write_wtap_epb_option(wtap_dumper *wdh, wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err) { switch(option_id) { case OPT_PKT_FLAGS: if (!pcapng_write_uint32_option(wdh, OPT_EPB_FLAGS, optval, err)) - return FALSE; + return false; break; case OPT_PKT_DROPCOUNT: if (!pcapng_write_uint64_option(wdh, OPT_EPB_DROPCOUNT, optval, err)) - return FALSE; + return false; break; case OPT_PKT_PACKETID: if (!pcapng_write_uint64_option(wdh, OPT_EPB_PACKETID, optval, err)) - return FALSE; + return false; break; case OPT_PKT_QUEUE: if (!pcapng_write_uint32_option(wdh, OPT_EPB_QUEUE, optval, err)) - return FALSE; + return false; break; case OPT_PKT_VERDICT: if (!pcapng_write_packet_verdict_option(wdh, OPT_EPB_VERDICT, optval, @@ -5330,32 +5297,93 @@ static gboolean write_wtap_epb_option(wtap_dumper *wdh, wtap_block_t block _U_, /* Unknown options - write by datatype? */ break; } - return TRUE; /* success */ + return true; /* success */ } -static gboolean +static bool +pcapng_write_simple_packet_block(wtap_dumper* wdh, const wtap_rec* rec, + const uint8_t* pd, int* err, char** err_info _U_) +{ + const union wtap_pseudo_header* pseudo_header = &rec->rec_header.packet_header.pseudo_header; + pcapng_block_header_t bh; + pcapng_simple_packet_block_t spb; + const uint32_t zero_pad = 0; + uint32_t pad_len; + uint32_t phdr_len; + + /* Don't write anything we're not willing to read. */ + if (rec->rec_header.packet_header.caplen > wtap_max_snaplen_for_encap(wdh->file_encap)) { + *err = WTAP_ERR_PACKET_TOO_LARGE; + return false; + } + + phdr_len = (uint32_t)pcap_get_phdr_size(rec->rec_header.packet_header.pkt_encap, pseudo_header); + if ((phdr_len + rec->rec_header.packet_header.caplen) % 4) { + pad_len = 4 - ((phdr_len + rec->rec_header.packet_header.caplen) % 4); + } + else { + pad_len = 0; + } + + /* write (simple) packet block header */ + bh.block_type = BLOCK_TYPE_SPB; + bh.block_total_length = (uint32_t)sizeof(bh) + (uint32_t)sizeof(spb) + phdr_len + rec->rec_header.packet_header.caplen + pad_len + 4; + + if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) + return false; + + /* write block fixed content */ + spb.packet_len = rec->rec_header.packet_header.len + phdr_len; + + if (!wtap_dump_file_write(wdh, &spb, sizeof spb, err)) + return false; + + /* write pseudo header */ + if (!pcap_write_phdr(wdh, rec->rec_header.packet_header.pkt_encap, pseudo_header, err)) { + return false; + } + + /* write packet data */ + if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) + return false; + + /* write padding (if any) */ + if (pad_len != 0) { + if (!wtap_dump_file_write(wdh, &zero_pad, pad_len, err)) + return false; + } + + /* write block footer */ + if (!wtap_dump_file_write(wdh, &bh.block_total_length, + sizeof bh.block_total_length, err)) + return false; + + return true; +} + +static bool pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info) + const uint8_t *pd, int *err, char **err_info) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; pcapng_block_header_t bh; pcapng_enhanced_packet_block_t epb; - guint32 options_size = 0; - guint64 ts; - const guint32 zero_pad = 0; - guint32 pad_len; - guint32 phdr_len; - guint32 options_total_length = 0; + uint32_t options_size = 0; + uint64_t ts; + const uint32_t zero_pad = 0; + uint32_t pad_len; + uint32_t phdr_len; + uint32_t options_total_length = 0; wtap_block_t int_data; wtapng_if_descr_mandatory_t *int_data_mand; /* Don't write anything we're not willing to read. */ if (rec->rec_header.packet_header.caplen > wtap_max_snaplen_for_encap(wdh->file_encap)) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } - phdr_len = (guint32)pcap_get_phdr_size(rec->rec_header.packet_header.pkt_encap, pseudo_header); + phdr_len = (uint32_t)pcap_get_phdr_size(rec->rec_header.packet_header.pkt_encap, pseudo_header); if ((phdr_len + rec->rec_header.packet_header.caplen) % 4) { pad_len = 4 - ((phdr_len + rec->rec_header.packet_header.caplen) % 4); } else { @@ -5371,9 +5399,16 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec, * Check the interface ID. Do this before writing the header, * in case we need to add a new IDB. */ - if (rec->presence_flags & WTAP_HAS_INTERFACE_ID) + if (rec->presence_flags & WTAP_HAS_INTERFACE_ID) { epb.interface_id = rec->rec_header.packet_header.interface_id; - else { + if (rec->presence_flags & WTAP_HAS_SECTION_NUMBER && wdh->shb_iface_to_global) { + /* + * In the extremely unlikely event this overflows we give the + * wrong interface ID. + */ + epb.interface_id += g_array_index(wdh->shb_iface_to_global, unsigned, rec->section_number); + } + } else { /* * The source isn't sending us IDBs. See if we already have a * matching interface, and use it if so. @@ -5396,7 +5431,7 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec, int_data = wtap_rec_generate_idb(rec); g_array_append_val(wdh->interface_data, int_data); if (!pcapng_write_if_descr_block(wdh, int_data, err)) { - return FALSE; + return false; } } } @@ -5407,7 +5442,7 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec, *err = WTAP_ERR_INTERNAL; *err_info = ws_strdup_printf("pcapng: epb.interface_id (%u) >= wdh->interface_data->len (%u)", epb.interface_id, wdh->interface_data->len); - return FALSE; + return false; } int_data = g_array_index(wdh->interface_data, wtap_block_t, epb.interface_id); @@ -5421,85 +5456,85 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec, epb.interface_id, int_data_mand->wtap_encap, rec->rec_header.packet_header.pkt_encap); - return FALSE; + return false; } /* write (enhanced) packet block header */ bh.block_type = BLOCK_TYPE_EPB; - bh.block_total_length = (guint32)sizeof(bh) + (guint32)sizeof(epb) + phdr_len + rec->rec_header.packet_header.caplen + pad_len + options_total_length + options_size + 4; + bh.block_total_length = (uint32_t)sizeof(bh) + (uint32_t)sizeof(epb) + phdr_len + rec->rec_header.packet_header.caplen + pad_len + options_total_length + options_size + 4; if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) - return FALSE; + return false; /* write block fixed content */ /* Calculate the time stamp as a 64-bit integer. */ - ts = ((guint64)rec->ts.secs) * int_data_mand->time_units_per_second + - (((guint64)rec->ts.nsecs) * int_data_mand->time_units_per_second) / 1000000000; + ts = ((uint64_t)rec->ts.secs) * int_data_mand->time_units_per_second + + (((uint64_t)rec->ts.nsecs) * int_data_mand->time_units_per_second) / 1000000000; /* * Split the 64-bit timestamp into two 32-bit pieces, using * the time stamp resolution for the interface. */ - epb.timestamp_high = (guint32)(ts >> 32); - epb.timestamp_low = (guint32)ts; + epb.timestamp_high = (uint32_t)(ts >> 32); + epb.timestamp_low = (uint32_t)ts; epb.captured_len = rec->rec_header.packet_header.caplen + phdr_len; epb.packet_len = rec->rec_header.packet_header.len + phdr_len; if (!wtap_dump_file_write(wdh, &epb, sizeof epb, err)) - return FALSE; + return false; /* write pseudo header */ if (!pcap_write_phdr(wdh, rec->rec_header.packet_header.pkt_encap, pseudo_header, err)) { - return FALSE; + return false; } /* write packet data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; /* write padding (if any) */ if (pad_len != 0) { if (!wtap_dump_file_write(wdh, &zero_pad, pad_len, err)) - return FALSE; + return false; } /* Write options, if we have any */ if (options_size != 0) { if (!write_options(wdh, rec->block, write_wtap_epb_option, err)) - return FALSE; + return false; } /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean +static bool pcapng_write_sysdig_event_block(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err) + const uint8_t *pd, int *err) { pcapng_block_header_t bh; - const guint32 zero_pad = 0; - guint32 pad_len; + const uint32_t zero_pad = 0; + uint32_t pad_len; #if 0 - gboolean have_options = FALSE; + bool have_options = false; struct pcapng_option option_hdr; - guint32 comment_len = 0, comment_pad_len = 0; + uint32_t comment_len = 0, comment_pad_len = 0; #endif - guint32 options_total_length = 0; - guint16 cpu_id; - guint64 hdr_ts; - guint64 ts; - guint64 thread_id; - guint32 event_len; - guint16 event_type; + uint32_t options_total_length = 0; + uint16_t cpu_id; + uint64_t hdr_ts; + uint64_t ts; + uint64_t thread_id; + uint32_t event_len; + uint16_t event_type; /* Don't write anything we're not willing to read. */ if (rec->rec_header.syscall_header.event_filelen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } if (rec->rec_header.syscall_header.event_filelen % 4) { @@ -5511,8 +5546,8 @@ pcapng_write_sysdig_event_block(wtap_dumper *wdh, const wtap_rec *rec, #if 0 /* Check if we should write comment option */ if (rec->opt_comment) { - have_options = TRUE; - comment_len = (guint32)strlen(rec->opt_comment) & 0xffff; + have_options = true; + comment_len = (uint32_t)strlen(rec->opt_comment) & 0xffff; if ((comment_len % 4)) { comment_pad_len = 4 - (comment_len % 4); } else { @@ -5528,42 +5563,42 @@ pcapng_write_sysdig_event_block(wtap_dumper *wdh, const wtap_rec *rec, /* write sysdig event block header */ bh.block_type = BLOCK_TYPE_SYSDIG_EVENT; - bh.block_total_length = (guint32)sizeof(bh) + SYSDIG_EVENT_HEADER_SIZE + rec->rec_header.syscall_header.event_filelen + pad_len + options_total_length + 4; + bh.block_total_length = (uint32_t)sizeof(bh) + SYSDIG_EVENT_HEADER_SIZE + rec->rec_header.syscall_header.event_filelen + pad_len + options_total_length + 4; if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) - return FALSE; + return false; /* Sysdig is always LE? */ cpu_id = GUINT16_TO_LE(rec->rec_header.syscall_header.cpu_id); - hdr_ts = (((guint64)rec->ts.secs) * 1000000000) + rec->ts.nsecs; + hdr_ts = (((uint64_t)rec->ts.secs) * 1000000000) + rec->ts.nsecs; ts = GUINT64_TO_LE(hdr_ts); thread_id = GUINT64_TO_LE(rec->rec_header.syscall_header.thread_id); event_len = GUINT32_TO_LE(rec->rec_header.syscall_header.event_len); event_type = GUINT16_TO_LE(rec->rec_header.syscall_header.event_type); if (!wtap_dump_file_write(wdh, &cpu_id, sizeof cpu_id, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &ts, sizeof ts, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &thread_id, sizeof thread_id, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &event_len, sizeof event_len, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, &event_type, sizeof event_type, err)) - return FALSE; + return false; /* write event data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.syscall_header.event_filelen, err)) - return FALSE; + return false; /* write padding (if any) */ if (pad_len != 0) { if (!wtap_dump_file_write(wdh, &zero_pad, pad_len, err)) - return FALSE; + return false; } /* XXX Write comment? */ @@ -5571,24 +5606,24 @@ pcapng_write_sysdig_event_block(wtap_dumper *wdh, const wtap_rec *rec, /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean +static bool pcapng_write_systemd_journal_export_block(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err) + const uint8_t *pd, int *err) { pcapng_block_header_t bh; - const guint32 zero_pad = 0; - guint32 pad_len; + const uint32_t zero_pad = 0; + uint32_t pad_len; /* Don't write anything we're not willing to read. */ if (rec->rec_header.systemd_journal_export_header.record_len > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } if (rec->rec_header.systemd_journal_export_header.record_len % 4) { @@ -5599,52 +5634,52 @@ pcapng_write_systemd_journal_export_block(wtap_dumper *wdh, const wtap_rec *rec, /* write systemd journal export block header */ bh.block_type = BLOCK_TYPE_SYSTEMD_JOURNAL_EXPORT; - bh.block_total_length = (guint32)sizeof(bh) + rec->rec_header.systemd_journal_export_header.record_len + pad_len + 4; + bh.block_total_length = (uint32_t)sizeof(bh) + rec->rec_header.systemd_journal_export_header.record_len + pad_len + 4; ws_debug("writing %u bytes, %u padded", rec->rec_header.systemd_journal_export_header.record_len, bh.block_total_length); if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) - return FALSE; + return false; /* write entry data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.systemd_journal_export_header.record_len, err)) - return FALSE; + return false; /* write padding (if any) */ if (pad_len != 0) { if (!wtap_dump_file_write(wdh, &zero_pad, pad_len, err)) - return FALSE; + return false; } /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean +static bool pcapng_write_custom_block(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err) + const uint8_t *pd, int *err) { pcapng_block_header_t bh; pcapng_custom_block_t cb; - const guint32 zero_pad = 0; - guint32 pad_len; + const uint32_t zero_pad = 0; + uint32_t pad_len; /* Don't write anything we are not supposed to. */ if (!rec->rec_header.custom_block_header.copy_allowed) { - return TRUE; + return true; } /* Don't write anything we're not willing to read. */ if (rec->rec_header.custom_block_header.length > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } if (rec->rec_header.custom_block_header.length % 4) { @@ -5655,83 +5690,83 @@ pcapng_write_custom_block(wtap_dumper *wdh, const wtap_rec *rec, /* write block header */ bh.block_type = BLOCK_TYPE_CB_COPY; - bh.block_total_length = (guint32)sizeof(bh) + (guint32)sizeof(cb) + rec->rec_header.custom_block_header.length + pad_len + 4; + bh.block_total_length = (uint32_t)sizeof(bh) + (uint32_t)sizeof(cb) + rec->rec_header.custom_block_header.length + pad_len + 4; ws_debug("writing %u bytes, %u padded, PEN %u", rec->rec_header.custom_block_header.length, bh.block_total_length, rec->rec_header.custom_block_header.pen); if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) { - return FALSE; + return false; } /* write custom block header */ cb.pen = rec->rec_header.custom_block_header.pen; if (!wtap_dump_file_write(wdh, &cb, sizeof cb, err)) { - return FALSE; + return false; } ws_debug("wrote PEN = %u", cb.pen); /* write custom data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.custom_block_header.length, err)) { - return FALSE; + return false; } /* write padding (if any) */ if (pad_len > 0) { if (!wtap_dump_file_write(wdh, &zero_pad, pad_len, err)) { - return FALSE; + return false; } } /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) { - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool pcapng_write_bblog_block(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd _U_, int *err) + const uint8_t *pd _U_, int *err) { pcapng_block_header_t bh; - guint32 options_size = 0; - guint32 pen, skipped, type; + uint32_t options_size = 0; + uint32_t pen, skipped, type; /* Compute size of all the options */ options_size = compute_options_size(rec->block, compute_epb_option_size); /* write block header */ bh.block_type = BLOCK_TYPE_CB_COPY; - bh.block_total_length = (guint32)(sizeof(bh) + sizeof(guint32) + sizeof(guint32) + options_size + 4); + bh.block_total_length = (uint32_t)(sizeof(bh) + sizeof(uint32_t) + sizeof(uint32_t) + options_size + 4); if (rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.type == BBLOG_TYPE_SKIPPED_BLOCK) { - bh.block_total_length += (guint32)sizeof(guint32); + bh.block_total_length += (uint32_t)sizeof(uint32_t); } ws_debug("writing %u bytes, type %u", bh.block_total_length, rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.type); if (!wtap_dump_file_write(wdh, &bh, sizeof(bh), err)) { - return FALSE; + return false; } /* write PEN */ pen = PEN_NFLX; - if (!wtap_dump_file_write(wdh, &pen, sizeof(guint32), err)) { - return FALSE; + if (!wtap_dump_file_write(wdh, &pen, sizeof(uint32_t), err)) { + return false; } ws_debug("wrote PEN = %u", pen); /* write type */ type = GUINT32_TO_LE(rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.type); - if (!wtap_dump_file_write(wdh, &type, sizeof(guint32), err)) { - return FALSE; + if (!wtap_dump_file_write(wdh, &type, sizeof(uint32_t), err)) { + return false; } ws_debug("wrote type = %u", rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.type); if (rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.type == BBLOG_TYPE_SKIPPED_BLOCK) { skipped = GUINT32_TO_LE(rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.skipped); - if (!wtap_dump_file_write(wdh, &skipped, sizeof(guint32), err)) { - return FALSE; + if (!wtap_dump_file_write(wdh, &skipped, sizeof(uint32_t), err)) { + return false; } ws_debug("wrote skipped = %u", rec->rec_header.custom_block_header.custom_data_header.nflx_custom_data_header.skipped); } @@ -5743,25 +5778,25 @@ pcapng_write_bblog_block(wtap_dumper *wdh, const wtap_rec *rec, * so it doesn't need a callback. */ if (!write_options(wdh, rec->block, NULL, err)) - return FALSE; + return false; } /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) { - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool pcapng_write_decryption_secrets_block(wtap_dumper *wdh, wtap_block_t sdata, int *err) { pcapng_block_header_t bh; pcapng_decryption_secrets_block_t dsb; wtapng_dsb_mandatory_t *mand_data = (wtapng_dsb_mandatory_t *)wtap_block_get_mandatory_data(sdata); - guint pad_len = (4 - (mand_data->secrets_len & 3)) & 3; + unsigned pad_len = (4 - (mand_data->secrets_len & 3)) & 3; /* write block header */ bh.block_type = BLOCK_TYPE_DSB; @@ -5769,39 +5804,39 @@ pcapng_write_decryption_secrets_block(wtap_dumper *wdh, wtap_block_t sdata, int ws_debug("Total len %u", bh.block_total_length); if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) - return FALSE; + return false; /* write block fixed content */ dsb.secrets_type = mand_data->secrets_type; dsb.secrets_len = mand_data->secrets_len; if (!wtap_dump_file_write(wdh, &dsb, sizeof dsb, err)) - return FALSE; + return false; if (!wtap_dump_file_write(wdh, mand_data->secrets_data, mand_data->secrets_len, err)) - return FALSE; + return false; if (pad_len) { - const guint32 zero_pad = 0; + const uint32_t zero_pad = 0; if (!wtap_dump_file_write(wdh, &zero_pad, pad_len, err)) - return FALSE; + return false; } /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) - return FALSE; + return false; - return TRUE; + return true; } static bool -pcapng_write_sysdig_meta_event_block(wtap_dumper *wdh, wtap_block_t mev_data, int *err) +pcapng_write_meta_event_block(wtap_dumper *wdh, wtap_block_t mev_data, int *err) { pcapng_block_header_t bh; - wtapng_sysdig_mev_mandatory_t *mand_data = (wtapng_sysdig_mev_mandatory_t *)wtap_block_get_mandatory_data(mev_data); + wtapng_meta_event_mandatory_t *mand_data = (wtapng_meta_event_mandatory_t *)wtap_block_get_mandatory_data(mev_data); unsigned pad_len = (4 - (mand_data->mev_data_len & 3)) & 3; /* write block header */ - bh.block_type = mand_data->mev_type; + bh.block_type = mand_data->mev_block_type; bh.block_total_length = MIN_BLOCK_SIZE + mand_data->mev_data_len + pad_len; ws_debug("Sysdig mev total len %u", bh.block_total_length); @@ -5845,10 +5880,10 @@ pcapng_write_sysdig_meta_event_block(wtap_dumper *wdh, wtap_block_t mev_data, in #define NRES_BLOCK_MAX_SIZE (1024*1024) -static guint32 -compute_nrb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval) +static uint32_t +compute_nrb_option_size(wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval) { - guint32 size; + uint32_t size; switch(option_id) { @@ -5869,22 +5904,22 @@ compute_nrb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e return size; } -static gboolean -put_nrb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval, void* user_data) +static bool +put_nrb_option(wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval, void* user_data) { - guint8 **opt_ptrp = (guint8 **)user_data; - guint32 size = 0; + uint8_t **opt_ptrp = (uint8_t **)user_data; + uint32_t size = 0; struct pcapng_option_header option_hdr; - guint32 pad; + uint32_t pad; switch(option_id) { case OPT_COMMENT: case OPT_NS_DNSNAME: /* String options don't consider pad bytes part of the length */ - size = (guint32)strlen(optval->stringval) & 0xffff; - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)size; + size = (uint32_t)strlen(optval->stringval) & 0xffff; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)size; memcpy(*opt_ptrp, &option_hdr, 4); *opt_ptrp += 4; @@ -5906,14 +5941,14 @@ put_nrb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_ty case OPT_CUSTOM_STR_COPY: case OPT_CUSTOM_BIN_COPY: /* Custom options don't consider pad bytes part of the length */ - size = (guint32)(optval->custom_opt.data.generic_data.custom_data_len + sizeof(guint32)) & 0xffff; - option_hdr.type = (guint16)option_id; - option_hdr.value_length = (guint16)size; + size = (uint32_t)(optval->custom_opt.data.generic_data.custom_data_len + sizeof(uint32_t)) & 0xffff; + option_hdr.type = (uint16_t)option_id; + option_hdr.value_length = (uint16_t)size; memcpy(*opt_ptrp, &option_hdr, 4); *opt_ptrp += 4; - memcpy(*opt_ptrp, &optval->custom_opt.pen, sizeof(guint32)); - *opt_ptrp += sizeof(guint32); + memcpy(*opt_ptrp, &optval->custom_opt.pen, sizeof(uint32_t)); + *opt_ptrp += sizeof(uint32_t); memcpy(*opt_ptrp, optval->custom_opt.data.generic_data.custom_data, optval->custom_opt.data.generic_data.custom_data_len); *opt_ptrp += optval->custom_opt.data.generic_data.custom_data_len; @@ -5931,7 +5966,7 @@ put_nrb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_ty } break; case OPT_NS_DNSIP4ADDR: - option_hdr.type = (guint16)option_id; + option_hdr.type = (uint16_t)option_id; option_hdr.value_length = 4; memcpy(*opt_ptrp, &option_hdr, 4); *opt_ptrp += 4; @@ -5940,7 +5975,7 @@ put_nrb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_ty *opt_ptrp += 4; break; case OPT_NS_DNSIP6ADDR: - option_hdr.type = (guint16)option_id; + option_hdr.type = (uint16_t)option_id; option_hdr.value_length = 16; memcpy(*opt_ptrp, &option_hdr, 4); *opt_ptrp += 4; @@ -5952,11 +5987,11 @@ put_nrb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_ty /* Unknown options - size by datatype? */ break; } - return TRUE; /* we always succeed */ + return true; /* we always succeed */ } static void -put_nrb_options(wtap_dumper *wdh _U_, wtap_block_t nrb, guint8 *opt_ptr) +put_nrb_options(wtap_dumper *wdh _U_, wtap_block_t nrb, uint8_t *opt_ptr) { struct pcapng_option option_hdr; @@ -5968,19 +6003,19 @@ put_nrb_options(wtap_dumper *wdh _U_, wtap_block_t nrb, guint8 *opt_ptr) memcpy(opt_ptr, &option_hdr, 4); } -static gboolean +static bool pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *err) { pcapng_block_header_t bh; pcapng_name_resolution_block_t nrb; wtapng_nrb_mandatory_t *mand_data = (wtapng_nrb_mandatory_t *)wtap_block_get_mandatory_data(sdata); - guint32 options_size; + uint32_t options_size; size_t max_rec_data_size; - guint8 *block_data; - guint32 block_off; + uint8_t *block_data; + uint32_t block_off; size_t hostnamelen; - guint16 namelen; - guint32 tot_rec_len; + uint16_t namelen; + uint32_t tot_rec_len; hashipv4_t *ipv4_hash_list_entry; hashipv6_t *ipv6_hash_list_entry; int i; @@ -5990,7 +6025,7 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er * No name/address pairs to write. * XXX - what if we have options? */ - return TRUE; + return true; } /* Calculate the space needed for options. */ @@ -6014,13 +6049,13 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er * we're willing to write and still have room enough for a * maximum-sized record. Just discard the information for now. */ - return TRUE; + return true; } /* * Allocate a buffer for the largest block we'll write. */ - block_data = (guint8 *)g_malloc(NRES_BLOCK_MAX_SIZE); + block_data = (uint8_t *)g_malloc(NRES_BLOCK_MAX_SIZE); /* * Calculate the maximum amount of record data we'll be able to @@ -6044,7 +6079,7 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er nrb.record_type = NRES_IP4RECORD; hostnamelen = strlen(ipv4_hash_list_entry->name); - if (hostnamelen > (G_MAXUINT16 - 4) - 1) { + if (hostnamelen > (UINT16_MAX - 4) - 1) { /* * This won't fit in the largest possible NRB record; * discard it. @@ -6053,7 +6088,7 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er ipv4_hash_list_entry = (hashipv4_t *)g_list_nth_data(mand_data->ipv4_addr_list, i); continue; } - namelen = (guint16)(hostnamelen + 1); + namelen = (uint16_t)(hostnamelen + 1); nrb.record_len = 4 + namelen; /* 4 bytes IPv4 address length */ /* 2 bytes record type, 2 bytes length field */ tot_rec_len = 4 + nrb.record_len + PADDING4(nrb.record_len); @@ -6088,7 +6123,7 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er if (!wtap_dump_file_write(wdh, block_data, bh.block_total_length, err)) { g_free(block_data); - return FALSE; + return false; } /*Start a new NRB */ @@ -6120,7 +6155,7 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er nrb.record_type = NRES_IP6RECORD; hostnamelen = strlen(ipv6_hash_list_entry->name); - if (hostnamelen > (G_MAXUINT16 - 16) - 1) { + if (hostnamelen > (UINT16_MAX - 16) - 1) { /* * This won't fit in the largest possible NRB record; * discard it. @@ -6129,7 +6164,7 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er ipv6_hash_list_entry = (hashipv6_t *)g_list_nth_data(mand_data->ipv6_addr_list, i); continue; } - namelen = (guint16)(hostnamelen + 1); + namelen = (uint16_t)(hostnamelen + 1); nrb.record_len = 16 + namelen; /* 16 bytes IPv6 address length */ /* 2 bytes record type, 2 bytes length field */ tot_rec_len = 4 + nrb.record_len + PADDING4(nrb.record_len); @@ -6164,7 +6199,7 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er if (!wtap_dump_file_write(wdh, block_data, bh.block_total_length, err)) { g_free(block_data); - return FALSE; + return false; } /*Start a new NRB */ @@ -6212,17 +6247,17 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, wtap_block_t sdata, int *er if (!wtap_dump_file_write(wdh, block_data, bh.block_total_length, err)) { g_free(block_data); - return FALSE; + return false; } g_free(block_data); - return TRUE; + return true; } -static guint32 compute_isb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval _U_) +static uint32_t compute_isb_option_size(wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval _U_) { - guint32 size; + uint32_t size; switch(option_id) { @@ -6245,14 +6280,14 @@ static guint32 compute_isb_option_size(wtap_block_t block _U_, guint option_id, return size; } -static gboolean write_wtap_isb_option(wtap_dumper *wdh, wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err) +static bool write_wtap_isb_option(wtap_dumper *wdh, wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err) { switch(option_id) { case OPT_ISB_STARTTIME: case OPT_ISB_ENDTIME: if (!pcapng_write_timestamp_option(wdh, option_id, optval, err)) - return FALSE; + return false; break; case OPT_ISB_IFRECV: case OPT_ISB_IFDROP: @@ -6260,21 +6295,21 @@ static gboolean write_wtap_isb_option(wtap_dumper *wdh, wtap_block_t block _U_, case OPT_ISB_OSDROP: case OPT_ISB_USRDELIV: if (!pcapng_write_uint64_option(wdh, option_id, optval, err)) - return FALSE; + return false; break; default: /* Unknown options - write by datatype? */ break; } - return TRUE; /* success */ + return true; /* success */ } -static gboolean +static bool pcapng_write_interface_statistics_block(wtap_dumper *wdh, wtap_block_t if_stats, int *err) { pcapng_block_header_t bh; pcapng_interface_statistics_block_t isb; - guint32 options_size; + uint32_t options_size; wtapng_if_stats_mandatory_t* mand_data = (wtapng_if_stats_mandatory_t*)wtap_block_get_mandatory_data(if_stats); ws_debug("entering function"); @@ -6284,11 +6319,11 @@ pcapng_write_interface_statistics_block(wtap_dumper *wdh, wtap_block_t if_stats, /* write block header */ bh.block_type = BLOCK_TYPE_ISB; - bh.block_total_length = (guint32)(sizeof(bh) + sizeof(isb) + options_size + 4); + bh.block_total_length = (uint32_t)(sizeof(bh) + sizeof(isb) + options_size + 4); ws_debug("Total len %u", bh.block_total_length); if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) - return FALSE; + return false; /* write block fixed content */ isb.interface_id = mand_data->interface_id; @@ -6296,24 +6331,24 @@ pcapng_write_interface_statistics_block(wtap_dumper *wdh, wtap_block_t if_stats, isb.timestamp_low = mand_data->ts_low; if (!wtap_dump_file_write(wdh, &isb, sizeof isb, err)) - return FALSE; + return false; /* Write options */ if (options_size != 0) { if (!write_options(wdh, if_stats, write_wtap_isb_option, err)) - return FALSE; + return false; } /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) - return FALSE; - return TRUE; + return false; + return true; } -static guint32 compute_idb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval) +static uint32_t compute_idb_option_size(wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval) { - guint32 size; + uint32_t size; switch(option_id) { @@ -6356,7 +6391,7 @@ static guint32 compute_idb_option_size(wtap_block_t block _U_, guint option_id, return size; } -static gboolean write_wtap_idb_option(wtap_dumper *wdh, wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err) +static bool write_wtap_idb_option(wtap_dumper *wdh, wtap_block_t block _U_, unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err) { switch(option_id) { @@ -6365,23 +6400,23 @@ static gboolean write_wtap_idb_option(wtap_dumper *wdh, wtap_block_t block _U_, case OPT_IDB_OS: case OPT_IDB_HARDWARE: if (!pcapng_write_string_option(wdh, option_id, optval, err)) - return FALSE; + return false; break; case OPT_IDB_SPEED: if (!pcapng_write_uint64_option(wdh, option_id, optval, err)) - return FALSE; + return false; break; case OPT_IDB_TSRESOL: if (!pcapng_write_uint8_option(wdh, option_id, optval, err)) - return FALSE; + return false; break; case OPT_IDB_FILTER: if (!pcapng_write_if_filter_option(wdh, option_id, optval, err)) - return FALSE; + return false; break; case OPT_IDB_FCSLEN: if (!pcapng_write_uint8_option(wdh, option_id, optval, err)) - return FALSE; + return false; break; case OPT_IDB_TSOFFSET: /* @@ -6392,15 +6427,15 @@ static gboolean write_wtap_idb_option(wtap_dumper *wdh, wtap_block_t block _U_, /* Unknown options - size by datatype? */ break; } - return TRUE; + return true; } -static gboolean +static bool pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err) { pcapng_block_header_t bh; pcapng_interface_description_block_t idb; - guint32 options_size; + uint32_t options_size; wtapng_if_descr_mandatory_t* mand_data = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data); int link_type; @@ -6413,7 +6448,7 @@ pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err) if (link_type == -1) { if (!pcapng_encap_is_ft_specific(mand_data->wtap_encap)) { *err = WTAP_ERR_UNWRITABLE_ENCAP; - return FALSE; + return false; } } @@ -6422,11 +6457,11 @@ pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err) /* write block header */ bh.block_type = BLOCK_TYPE_IDB; - bh.block_total_length = (guint32)(sizeof(bh) + sizeof(idb) + options_size + 4); + bh.block_total_length = (uint32_t)(sizeof(bh) + sizeof(idb) + options_size + 4); ws_debug("Total len %u", bh.block_total_length); if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err)) - return FALSE; + return false; /* write block fixed content */ idb.linktype = link_type; @@ -6434,24 +6469,24 @@ pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err) idb.snaplen = mand_data->snap_len; if (!wtap_dump_file_write(wdh, &idb, sizeof idb, err)) - return FALSE; + return false; if (options_size != 0) { /* Write options */ if (!write_options(wdh, int_data, write_wtap_idb_option, err)) - return FALSE; + return false; } /* write block footer */ if (!wtap_dump_file_write(wdh, &bh.block_total_length, sizeof bh.block_total_length, err)) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean pcapng_add_idb(wtap_dumper *wdh, wtap_block_t idb, - int *err, gchar **err_info _U_) +static bool pcapng_add_idb(wtap_dumper *wdh, wtap_block_t idb, + int *err, char **err_info _U_) { wtap_block_t idb_copy; @@ -6468,17 +6503,17 @@ static gboolean pcapng_add_idb(wtap_dumper *wdh, wtap_block_t idb, return pcapng_write_if_descr_block(wdh, idb_copy, err); } -static gboolean pcapng_write_internal_blocks(wtap_dumper *wdh, int *err) +static bool pcapng_write_internal_blocks(wtap_dumper *wdh, int *err) { /* Write (optional) Decryption Secrets Blocks that were collected while * reading packet blocks. */ if (wdh->dsbs_growing) { - for (guint i = wdh->dsbs_growing_written; i < wdh->dsbs_growing->len; i++) { + for (unsigned i = wdh->dsbs_growing_written; i < wdh->dsbs_growing->len; i++) { ws_debug("writing DSB %u", i); wtap_block_t dsb = g_array_index(wdh->dsbs_growing, wtap_block_t, i); if (!pcapng_write_decryption_secrets_block(wdh, dsb, err)) { - return FALSE; + return false; } ++wdh->dsbs_growing_written; } @@ -6486,14 +6521,14 @@ static gboolean pcapng_write_internal_blocks(wtap_dumper *wdh, int *err) /* Write (optional) Sysdig Meta Event Blocks that were collected while * reading packet blocks. */ - if (wdh->sysdig_mev_growing) { - for (unsigned i = wdh->sysdig_mev_growing_written; i < wdh->sysdig_mev_growing->len; i++) { + if (wdh->mevs_growing) { + for (unsigned i = wdh->mevs_growing_written; i < wdh->mevs_growing->len; i++) { ws_debug("writing Sysdig mev %u", i); - wtap_block_t mev = g_array_index(wdh->sysdig_mev_growing, wtap_block_t, i); - if (!pcapng_write_sysdig_meta_event_block(wdh, mev, err)) { + wtap_block_t mev = g_array_index(wdh->mevs_growing, wtap_block_t, i); + if (!pcapng_write_meta_event_block(wdh, mev, err)) { return false; } - ++wdh->sysdig_mev_growing_written; + ++wdh->mevs_growing_written; } } @@ -6522,7 +6557,7 @@ static gboolean pcapng_write_internal_blocks(wtap_dumper *wdh, int *err) mand_data->ipv6_addr_list = wdh->addrinfo_lists->ipv6_addr_list; if (!pcapng_write_name_resolution_block(wdh, nrb, err)) { - return FALSE; + return false; } mand_data->ipv4_addr_list = NULL; mand_data->ipv6_addr_list = NULL; @@ -6548,28 +6583,28 @@ static gboolean pcapng_write_internal_blocks(wtap_dumper *wdh, int *err) /* Write (optional) Name Resolution Blocks that were collected while * reading packet blocks. */ if (wdh->nrbs_growing) { - for (guint i = wdh->nrbs_growing_written; i < wdh->nrbs_growing->len; i++) { + for (unsigned i = wdh->nrbs_growing_written; i < wdh->nrbs_growing->len; i++) { wtap_block_t nrb = g_array_index(wdh->nrbs_growing, wtap_block_t, i); if (!pcapng_write_name_resolution_block(wdh, nrb, err)) { - return FALSE; + return false; } ++wdh->nrbs_growing_written; } } - return TRUE; + return true; } -static gboolean pcapng_dump(wtap_dumper *wdh, +static bool pcapng_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info) + const uint8_t *pd, int *err, char **err_info) { #ifdef HAVE_PLUGINS block_handler *handler; #endif if (!pcapng_write_internal_blocks(wdh, err)) { - return FALSE; + return false; } ws_debug("encap = %d (%s) rec type = %u", @@ -6580,14 +6615,19 @@ static gboolean pcapng_dump(wtap_dumper *wdh, switch (rec->rec_type) { case REC_TYPE_PACKET: - /* - * XXX - write a Simple Packet Block if there's no time - * stamp or other information that doesn't appear in an - * SPB? - */ - if (!pcapng_write_enhanced_packet_block(wdh, rec, pd, err, - err_info)) { - return FALSE; + /* Write Simple Packet Block if appropriate, Enhanced Packet Block otherwise. */ + if (!(rec->presence_flags & WTAP_HAS_TS) && + (!(rec->presence_flags & WTAP_HAS_INTERFACE_ID) || rec->rec_header.packet_header.interface_id == 0) && + (!(rec->presence_flags & WTAP_HAS_CAP_LEN) || rec->rec_header.packet_header.len == rec->rec_header.packet_header.caplen) && + (rec->block == NULL || compute_options_size(rec->block, compute_epb_option_size) == 0)) { + if (!pcapng_write_simple_packet_block(wdh, rec, pd, err, err_info)) { + return false; + } + } + else { + if (!pcapng_write_enhanced_packet_block(wdh, rec, pd, err, err_info)) { + return false; + } } break; @@ -6602,25 +6642,25 @@ static gboolean pcapng_dump(wtap_dumper *wdh, GUINT_TO_POINTER(rec->rec_header.ft_specific_header.record_type))) != NULL) { /* Yes. Call it to write out this record. */ if (!handler->writer(wdh, rec, pd, err)) - return FALSE; + return false; } else #endif { /* No. */ *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } break; case REC_TYPE_SYSCALL: if (!pcapng_write_sysdig_event_block(wdh, rec, pd, err)) { - return FALSE; + return false; } break; case REC_TYPE_SYSTEMD_JOURNAL_EXPORT: if (!pcapng_write_systemd_journal_export_block(wdh, rec, pd, err)) { - return FALSE; + return false; } break; @@ -6628,12 +6668,12 @@ static gboolean pcapng_dump(wtap_dumper *wdh, switch (rec->rec_header.custom_block_header.pen) { case PEN_NFLX: if (!pcapng_write_bblog_block(wdh, rec, pd, err)) { - return FALSE; + return false; } break; default: if (!pcapng_write_custom_block(wdh, rec, pd, err)) { - return FALSE; + return false; } break; } @@ -6642,22 +6682,22 @@ static gboolean pcapng_dump(wtap_dumper *wdh, default: /* We don't support writing this record type. */ *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } - return TRUE; + return true; } /* Finish writing to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean pcapng_dump_finish(wtap_dumper *wdh, int *err, - gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool pcapng_dump_finish(wtap_dumper *wdh, int *err, + char **err_info _U_) { - guint i, j; + unsigned i, j; /* Flush any hostname resolution or decryption secrets info we may have */ if (!pcapng_write_internal_blocks(wdh, err)) { - return FALSE; + return false; } for (i = 0; i < wdh->interface_data->len; i++) { @@ -6676,21 +6716,21 @@ static gboolean pcapng_dump_finish(wtap_dumper *wdh, int *err, ws_debug("write ISB for interface %u", ((wtapng_if_stats_mandatory_t*)wtap_block_get_mandatory_data(if_stats))->interface_id); if (!pcapng_write_interface_statistics_block(wdh, if_stats, err)) { - return FALSE; + return false; } } } ws_debug("leaving function"); - return TRUE; + return true; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean -pcapng_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool +pcapng_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { - guint i; + unsigned i; ws_debug("entering function"); /* This is a pcapng file */ @@ -6700,7 +6740,7 @@ pcapng_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) /* write the section header block */ if (!pcapng_write_section_header_block(wdh, err)) { - return FALSE; + return false; } ws_debug("wrote section header block."); @@ -6716,7 +6756,7 @@ pcapng_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) idb = g_array_index(wdh->interface_data, wtap_block_t, i); if (!pcapng_write_if_descr_block(wdh, idb, err)) { - return FALSE; + return false; } } @@ -6726,12 +6766,12 @@ pcapng_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) for (i = 0; i < wdh->dsbs_initial->len; i++) { wtap_block_t dsb = g_array_index(wdh->dsbs_initial, wtap_block_t, i); if (!pcapng_write_decryption_secrets_block(wdh, dsb, err)) { - return FALSE; + return false; } } } - return TRUE; + return true; } /* Returns 0 if we could write the specified encapsulation type, @@ -6763,16 +6803,16 @@ static int pcapng_dump_can_write_encap(int wtap_encap) } /* - * Returns TRUE if the specified encapsulation type is filetype-specific + * Returns true if the specified encapsulation type is filetype-specific * and one that we support. */ -gboolean pcapng_encap_is_ft_specific(int encap) +bool pcapng_encap_is_ft_specific(int encap) { switch (encap) { case WTAP_ENCAP_SYSTEMD_JOURNAL: - return TRUE; + return true; } - return FALSE; + return false; } /* @@ -6854,8 +6894,8 @@ static const struct supported_option_type decryption_secrets_block_options_suppo { OPT_CUSTOM_BIN_NO_COPY, MULTIPLE_OPTIONS_SUPPORTED } }; -/* Options for Sysdig meta event blocks. */ -static const struct supported_option_type sysdig_meta_events_block_options_supported[] = { +/* Options for meta event blocks. */ +static const struct supported_option_type meta_events_block_options_supported[] = { { OPT_COMMENT, MULTIPLE_OPTIONS_SUPPORTED }, { OPT_CUSTOM_STR_COPY, MULTIPLE_OPTIONS_SUPPORTED }, { OPT_CUSTOM_BIN_COPY, MULTIPLE_OPTIONS_SUPPORTED }, @@ -6878,7 +6918,7 @@ static const struct supported_option_type packet_block_options_supported[] = { { OPT_CUSTOM_BIN_NO_COPY, MULTIPLE_OPTIONS_SUPPORTED } }; -/* Options for file-type-sepcific reports. */ +/* Options for file-type-specific reports. */ static const struct supported_option_type ft_specific_report_block_options_supported[] = { { OPT_COMMENT, MULTIPLE_OPTIONS_SUPPORTED }, { OPT_CUSTOM_STR_COPY, MULTIPLE_OPTIONS_SUPPORTED }, @@ -6887,7 +6927,7 @@ static const struct supported_option_type ft_specific_report_block_options_suppo { OPT_CUSTOM_BIN_NO_COPY, MULTIPLE_OPTIONS_SUPPORTED } }; -/* Options for file-type-sepcific event. */ +/* Options for file-type-specific event. */ static const struct supported_option_type ft_specific_event_block_options_supported[] = { { OPT_COMMENT, MULTIPLE_OPTIONS_SUPPORTED }, { OPT_CUSTOM_STR_COPY, MULTIPLE_OPTIONS_SUPPORTED }, @@ -6922,7 +6962,7 @@ static const struct supported_block_type pcapng_blocks_supported[] = { { WTAP_BLOCK_DECRYPTION_SECRETS, MULTIPLE_BLOCKS_SUPPORTED, OPTION_TYPES_SUPPORTED(decryption_secrets_block_options_supported) }, /* Multiple blocks of decryption secrets. */ - { WTAP_BLOCK_SYSDIG_META_EVENT, MULTIPLE_BLOCKS_SUPPORTED, OPTION_TYPES_SUPPORTED(sysdig_meta_events_block_options_supported) }, + { WTAP_BLOCK_META_EVENT, MULTIPLE_BLOCKS_SUPPORTED, OPTION_TYPES_SUPPORTED(meta_events_block_options_supported) }, /* And, obviously, multiple packets. */ { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, OPTION_TYPES_SUPPORTED(packet_block_options_supported) }, @@ -6941,8 +6981,8 @@ static const struct supported_block_type pcapng_blocks_supported[] = { }; static const struct file_type_subtype_info pcapng_info = { - "Wireshark/... - pcapng", "pcapng", "pcapng", "ntar", - FALSE, BLOCKS_SUPPORTED(pcapng_blocks_supported), + "Wireshark/... - pcapng", "pcapng", "pcapng", "scap;ntar", + false, BLOCKS_SUPPORTED(pcapng_blocks_supported), pcapng_dump_can_write_encap, pcapng_dump_open, NULL }; diff --git a/wiretap/pcapng.h b/wiretap/pcapng.h index 3e5735d9..74e8019c 100644 --- a/wiretap/pcapng.h +++ b/wiretap/pcapng.h @@ -21,57 +21,57 @@ /* pcapng: common block header file encoding for every block type */ typedef struct pcapng_block_header_s { - guint32 block_type; - guint32 block_total_length; + uint32_t block_type; + uint32_t block_total_length; /* x bytes block_body */ - /* guint32 block_total_length */ + /* uint32_t block_total_length */ } pcapng_block_header_t; /* pcapng: section header block file encoding */ typedef struct pcapng_section_header_block_s { /* pcapng_block_header_t */ - guint32 magic; - guint16 version_major; - guint16 version_minor; - guint64 section_length; /* might be -1 for unknown */ + uint32_t magic; + uint16_t version_major; + uint16_t version_minor; + uint64_t section_length; /* might be -1 for unknown */ /* ... Options ... */ } pcapng_section_header_block_t; /* pcapng: interface description block file encoding */ typedef struct pcapng_interface_description_block_s { - guint16 linktype; - guint16 reserved; - guint32 snaplen; + uint16_t linktype; + uint16_t reserved; + uint32_t snaplen; /* ... Options ... */ } pcapng_interface_description_block_t; /* pcapng: interface statistics block file encoding */ typedef struct pcapng_interface_statistics_block_s { - guint32 interface_id; - guint32 timestamp_high; - guint32 timestamp_low; + uint32_t interface_id; + uint32_t timestamp_high; + uint32_t timestamp_low; /* ... Options ... */ } pcapng_interface_statistics_block_t; /* pcapng: Decryption Secrets Block file encoding */ typedef struct pcapng_decryption_secrets_block_s { - guint32 secrets_type; /* Secrets Type, see secrets-types.h */ - guint32 secrets_len; /* Size of variable-length secrets data. */ + uint32_t secrets_type; /* Secrets Type, see secrets-types.h */ + uint32_t secrets_len; /* Size of variable-length secrets data. */ /* x bytes Secrets Data. */ /* ... Options ... */ } pcapng_decryption_secrets_block_t; struct pcapng_option_header { - guint16 type; - guint16 value_length; + uint16_t type; + uint16_t value_length; }; /* * Minimum IDB size = minimum block size + size of fixed length portion of IDB. */ -#define MIN_IDB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_interface_description_block_t))) -#define MIN_DSB_SIZE ((guint32)(MIN_BLOCK_SIZE + sizeof(pcapng_decryption_secrets_block_t))) +#define MIN_IDB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_interface_description_block_t))) +#define MIN_DSB_SIZE ((uint32_t)(MIN_BLOCK_SIZE + sizeof(pcapng_decryption_secrets_block_t))) -wtap_open_return_val pcapng_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val pcapng_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/pcapng_module.h b/wiretap/pcapng_module.h index e4ff9463..239998b3 100644 --- a/wiretap/pcapng_module.h +++ b/wiretap/pcapng_module.h @@ -63,8 +63,8 @@ /* Block data to be passed between functions during reading */ typedef struct wtapng_block_s { - guint32 type; /* block_type as defined by pcapng */ - gboolean internal; /* TRUE if this block type shouldn't be returned from pcapng_read() */ + uint32_t type; /* block_type as defined by pcapng */ + bool internal; /* true if this block type shouldn't be returned from pcapng_read() */ wtap_block_t block; wtap_rec *rec; Buffer *frame_buffer; @@ -76,43 +76,43 @@ typedef struct wtapng_block_s { * BBLog blocks and options. */ typedef struct section_info_t { - gboolean byte_swapped; /**< TRUE if this section is not in our byte order */ - guint16 version_major; /**< Major version number of this section */ - guint16 version_minor; /**< Minor version number of this section */ + bool byte_swapped; /**< true if this section is not in our byte order */ + uint16_t version_major; /**< Major version number of this section */ + uint16_t version_minor; /**< Minor version number of this section */ GArray *interfaces; /**< Interfaces found in this section */ - gint64 shb_off; /**< File offset of the SHB for this section */ - guint32 bblog_version; /**< BBLog: version used */ - guint64 bblog_offset_tv_sec; /**< BBLog: UTC offset */ - guint64 bblog_offset_tv_usec; + int64_t shb_off; /**< File offset of the SHB for this section */ + uint32_t bblog_version; /**< BBLog: version used */ + uint64_t bblog_offset_tv_sec; /**< BBLog: UTC offset */ + uint64_t bblog_offset_tv_usec; } section_info_t; /* * Reader and writer routines for pcapng block types. */ -typedef gboolean (*block_reader)(FILE_T fh, guint32 block_read, - gboolean byte_swapped, +typedef bool (*block_reader)(FILE_T fh, uint32_t block_read, + bool byte_swapped, wtapng_block_t *wblock, - int *err, gchar **err_info); -typedef gboolean (*block_writer)(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err); + int *err, char **err_info); +typedef bool (*block_writer)(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err); /* * Register a handler for a pcapng block type. */ WS_DLL_PUBLIC -void register_pcapng_block_type_handler(guint block_type, block_reader reader, +void register_pcapng_block_type_handler(unsigned block_type, block_reader reader, block_writer writer); /* * Handler routines for pcapng option type. */ -typedef gboolean (*option_parser)(wtap_block_t block, - gboolean byte_swapped, - guint option_length, - const guint8 *option_content, - int *err, gchar **err_info); -typedef guint32 (*option_sizer)(guint option_id, wtap_optval_t *optval); -typedef gboolean (*option_writer)(wtap_dumper *wdh, guint option_id, +typedef bool (*option_parser)(wtap_block_t block, + bool byte_swapped, + unsigned option_length, + const uint8_t *option_content, + int *err, char **err_info); +typedef uint32_t (*option_sizer)(unsigned option_id, wtap_optval_t *optval); +typedef bool (*option_writer)(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err); /* @@ -120,7 +120,7 @@ typedef gboolean (*option_writer)(wtap_dumper *wdh, guint option_id, * type. */ WS_DLL_PUBLIC -void register_pcapng_option_handler(guint block_type, guint option_code, +void register_pcapng_option_handler(unsigned block_type, unsigned option_code, option_parser parser, option_sizer sizer, option_writer writer); @@ -152,16 +152,16 @@ typedef enum { * options. */ WS_DLL_PUBLIC -gboolean pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, +bool pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, section_info_t *section_info, - guint opt_cont_buf_len, - gboolean (*process_option)(wtapng_block_t *, + unsigned opt_cont_buf_len, + bool (*process_option)(wtapng_block_t *, const section_info_t *, - guint16, guint16, - const guint8 *, - int *, gchar **), + uint16_t, uint16_t, + const uint8_t *, + int *, char **), pcapng_opt_byte_order_e byte_order, - int *err, gchar **err_info); + int *err, char **err_info); /* * Helper routines to process options with types used in more than one @@ -169,43 +169,43 @@ gboolean pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, */ WS_DLL_PUBLIC void pcapng_process_uint8_option(wtapng_block_t *wblock, - guint16 option_code, guint16 option_length, - const guint8 *option_content); + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content); WS_DLL_PUBLIC void pcapng_process_uint32_option(wtapng_block_t *wblock, const section_info_t *section_info, pcapng_opt_byte_order_e byte_order, - guint16 option_code, guint16 option_length, - const guint8 *option_content); + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content); WS_DLL_PUBLIC void pcapng_process_timestamp_option(wtapng_block_t *wblock, const section_info_t *section_info, pcapng_opt_byte_order_e byte_order, - guint16 option_code, guint16 option_length, - const guint8 *option_content); + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content); WS_DLL_PUBLIC void pcapng_process_uint64_option(wtapng_block_t *wblock, const section_info_t *section_info, pcapng_opt_byte_order_e byte_order, - guint16 option_code, guint16 option_length, - const guint8 *option_content); + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content); WS_DLL_PUBLIC void pcapng_process_int64_option(wtapng_block_t *wblock, const section_info_t *section_info, pcapng_opt_byte_order_e byte_order, - guint16 option_code, guint16 option_length, - const guint8 *option_content); + uint16_t option_code, uint16_t option_length, + const uint8_t *option_content); WS_DLL_PUBLIC -void pcapng_process_string_option(wtapng_block_t *wblock, guint16 option_code, - guint16 option_length, const guint8 *option_content); +void pcapng_process_string_option(wtapng_block_t *wblock, uint16_t option_code, + uint16_t option_length, const uint8_t *option_content); WS_DLL_PUBLIC -void pcapng_process_bytes_option(wtapng_block_t *wblock, guint16 option_code, - guint16 option_length, const guint8 *option_content); +void pcapng_process_bytes_option(wtapng_block_t *wblock, uint16_t option_code, + uint16_t option_length, const uint8_t *option_content); #endif /* __PCAP_MODULE_H__ */ diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c index 18b926dd..ab94ded3 100644 --- a/wiretap/peekclassic.c +++ b/wiretap/peekclassic.c @@ -22,6 +22,8 @@ */ #include "config.h" +#include "peekclassic.h" + #include <string.h> #include <wsutil/epochs.h> @@ -30,7 +32,6 @@ #include "wtap-int.h" #include "file_wrappers.h" -#include "peekclassic.h" /* CREDITS * @@ -40,23 +41,23 @@ /* master header */ typedef struct peekclassic_master_header { - guint8 version; - guint8 status; + uint8_t version; + uint8_t status; } peekclassic_master_header_t; #define PEEKCLASSIC_MASTER_HDR_SIZE 2 /* secondary header (V5,V6,V7) */ typedef struct peekclassic_v567_header { - guint32 filelength; - guint32 numPackets; - guint32 timeDate; - guint32 timeStart; - guint32 timeStop; - guint32 mediaType; /* Media Type Ethernet=0 Token Ring = 1 */ - guint32 physMedium; /* Physical Medium native=0 802.1=1 */ - guint32 appVers; /* App Version Number Maj.Min.Bug.Build */ - guint32 linkSpeed; /* Link Speed Bits/sec */ - guint32 reserved[3]; + uint32_t filelength; + uint32_t numPackets; + uint32_t timeDate; + uint32_t timeStart; + uint32_t timeStop; + uint32_t mediaType; /* Media Type Ethernet=0 Token Ring = 1 */ + uint32_t physMedium; /* Physical Medium native=0 802.1=1 */ + uint32_t appVers; /* App Version Number Maj.Min.Bug.Build */ + uint32_t linkSpeed; /* Link Speed Bits/sec */ + uint32_t reserved[3]; } peekclassic_v567_header_t; #define PEEKCLASSIC_V567_HDR_SIZE 48 @@ -96,8 +97,8 @@ typedef struct peekclassic_header { /* 64-bit time in micro seconds from the (Mac) epoch */ typedef struct peekclassic_utime { - guint32 upper; - guint32 lower; + uint32_t upper; + uint32_t lower; } peekclassic_utime; /* @@ -139,25 +140,25 @@ typedef struct { time_t reference_time; } peekclassic_t; -static gboolean peekclassic_read_v7(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool peekclassic_read_v7(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool peekclassic_seek_read_v7(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean peekclassic_read_v56(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool peekclassic_read_v56(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool peekclassic_seek_read_v56(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool peekclassic_read_packet_v56(wtap *wth, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int peekclassic_v56_file_type_subtype = -1; static int peekclassic_v7_file_type_subtype = -1; void register_peekclassic(void); -wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val peekclassic_open(wtap *wth, int *err, char **err_info) { peekclassic_header_t ep_hdr; time_t reference_time; @@ -360,8 +361,8 @@ wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_MINE; } -static gboolean peekclassic_read_v7(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool peekclassic_read_v7(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { int sliceLength; @@ -371,59 +372,59 @@ static gboolean peekclassic_read_v7(wtap *wth, wtap_rec *rec, Buffer *buf, sliceLength = peekclassic_read_packet_v7(wth, wth->fh, rec, buf, err, err_info); if (sliceLength < 0) - return FALSE; + return false; /* Skip extra ignored data at the end of the packet. */ - if ((guint32)sliceLength > rec->rec_header.packet_header.caplen) { + if ((uint32_t)sliceLength > rec->rec_header.packet_header.caplen) { if (!wtap_read_bytes(wth->fh, NULL, sliceLength - rec->rec_header.packet_header.caplen, err, err_info)) - return FALSE; + return false; } /* Records are padded to an even length, so if the slice length is odd, read the padding byte. */ if (sliceLength & 0x01) { if (!wtap_read_bytes(wth->fh, NULL, 1, err, err_info)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool peekclassic_seek_read_v7(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read the packet. */ if (peekclassic_read_packet_v7(wth, wth->random_fh, rec, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } #define RADIO_INFO_SIZE 4 static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { - guint8 ep_pkt[PEEKCLASSIC_V7_PKT_SIZE]; + uint8_t ep_pkt[PEEKCLASSIC_V7_PKT_SIZE]; #if 0 - guint16 protoNum; + uint16_t protoNum; #endif - guint16 length; - guint16 sliceLength; - guint8 flags; - guint8 status; - guint64 timestamp; + uint16_t length; + uint16_t sliceLength; + uint8_t flags; + uint8_t status; + uint64_t timestamp; time_t tsecs; - guint32 tusecs; - guint32 pack_flags; - guint8 radio_info[RADIO_INFO_SIZE]; + uint32_t tusecs; + uint32_t pack_flags; + uint8_t radio_info[RADIO_INFO_SIZE]; if (!wtap_read_bytes_or_eof(fh, ep_pkt, sizeof(ep_pkt), err, err_info)) return -1; @@ -453,7 +454,7 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, rec->block = wtap_block_create(WTAP_BLOCK_PACKET); rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; tsecs = (time_t) (timestamp/1000000); - tusecs = (guint32) (timestamp - tsecs*1000000); + tusecs = (uint32_t) (timestamp - tsecs*1000000); rec->ts.secs = tsecs - EPOCH_DELTA_1904_01_01_00_00_00_UTC; rec->ts.nsecs = tusecs * 1000; rec->rec_header.packet_header.len = length; @@ -472,8 +473,8 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; /* no FCS */ - rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = false; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = false; rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; /* @@ -509,13 +510,13 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, if (!wtap_read_bytes(fh, radio_info, RADIO_INFO_SIZE, err, err_info)) return -1; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate = radio_info[0]; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = radio_info[1]; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = TRUE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = true; rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = radio_info[2]; /* @@ -525,18 +526,18 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, if (RATE_IS_DSSS(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate)) { /* 11b */ rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11b.has_short_preamble = false; } else if (RATE_IS_OFDM(rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate)) { /* 11a or 11g, depending on the band. */ if (CHAN_IS_BG(rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel)) { /* 11g */ rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11g.has_mode = false; } else { /* 11a */ rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_channel_type = FALSE; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_channel_type = false; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy_info.info_11a.has_turbo_type = false; } } @@ -572,63 +573,63 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, return sliceLength; } -static gboolean peekclassic_read_v56(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool peekclassic_read_v56(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); /* read the packet */ if (!peekclassic_read_packet_v56(wth, wth->fh, rec, buf, err, err_info)) - return FALSE; + return false; /* * XXX - is the captured packet data padded to a multiple * of 2 bytes? */ - return TRUE; + return true; } -static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool peekclassic_seek_read_v56(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* read the packet */ if (!peekclassic_read_packet_v56(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool peekclassic_read_packet_v56(wtap *wth, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { peekclassic_t *peekclassic = (peekclassic_t *)wth->priv; - guint8 ep_pkt[PEEKCLASSIC_V56_PKT_SIZE]; - guint16 length; - guint16 sliceLength; - guint8 flags; + uint8_t ep_pkt[PEEKCLASSIC_V56_PKT_SIZE]; + uint16_t length; + uint16_t sliceLength; + uint8_t flags; #if 0 - guint8 status; + uint8_t status; #endif - guint32 timestamp; + uint32_t timestamp; #if 0 - guint16 destNum; - guint16 srcNum; + uint16_t destNum; + uint16_t srcNum; #endif #if 0 - guint16 protoNum; + uint16_t protoNum; char protoStr[8]; #endif - guint32 pack_flags; + uint32_t pack_flags; if (!wtap_read_bytes_or_eof(fh, ep_pkt, sizeof(ep_pkt), err, err_info)) - return FALSE; + return false; /* Extract the fields from the packet */ length = pntoh16(&ep_pkt[PEEKCLASSIC_V56_LENGTH_OFFSET]); @@ -700,7 +701,7 @@ static const struct supported_block_type peekclassic_v56_blocks_supported[] = { static const struct file_type_subtype_info peekclassic_v56_info = { "Savvius classic (V5 and V6)", "peekclassic56", "pkt", "tpc;apc;wpz", - FALSE, BLOCKS_SUPPORTED(peekclassic_v56_blocks_supported), + false, BLOCKS_SUPPORTED(peekclassic_v56_blocks_supported), NULL, NULL, NULL }; @@ -713,7 +714,7 @@ static const struct supported_block_type peekclassic_v7_blocks_supported[] = { static const struct file_type_subtype_info peekclassic_v7_info = { "Savvius classic (V7)", "peekclassic7", "pkt", "tpc;apc;wpz", - FALSE, BLOCKS_SUPPORTED(peekclassic_v7_blocks_supported), + false, BLOCKS_SUPPORTED(peekclassic_v7_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/peekclassic.h b/wiretap/peekclassic.h index 36a98226..65359643 100644 --- a/wiretap/peekclassic.h +++ b/wiretap/peekclassic.h @@ -14,6 +14,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val peekclassic_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c index acef3463..d2e72622 100644 --- a/wiretap/peektagged.c +++ b/wiretap/peektagged.c @@ -19,11 +19,12 @@ */ #include "config.h" +#include "peektagged.h" + #include <string.h> #include <stdlib.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "peektagged.h" #include <wsutil/802_11-utils.h> /* CREDITS @@ -59,9 +60,9 @@ * by the raw packet data. */ typedef struct peektagged_section_header { - gint8 section_id[4]; /* string identifying the section */ - guint32 section_len; /* little-endian section length */ - guint32 section_const; /* little-endian 0x00000200 */ + int8_t section_id[4]; /* string identifying the section */ + uint32_t section_len; /* little-endian section length */ + uint32_t section_const; /* little-endian 0x00000200 */ } peektagged_section_header_t; /* @@ -144,25 +145,25 @@ typedef struct peektagged_section_header { /* 64-bit time in nanoseconds from the (Windows FILETIME) epoch */ typedef struct peektagged_utime { - guint32 upper; - guint32 lower; + uint32_t upper; + uint32_t lower; } peektagged_utime; typedef struct { - gboolean has_fcs; + bool has_fcs; } peektagged_t; -static gboolean peektagged_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean peektagged_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool peektagged_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool peektagged_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int peektagged_file_type_subtype = -1; void register_peektagged(void); static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err, - gchar **err_info) + char **err_info) { int c; const char *cp; @@ -194,7 +195,7 @@ static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err, static int wtap_file_read_till_separator (wtap *wth, char *buffer, int buflen, const char *separators, int *err, - gchar **err_info) + char **err_info) { int c; char *cp; @@ -222,8 +223,8 @@ static int wtap_file_read_till_separator (wtap *wth, char *buffer, int buflen, } -static int wtap_file_read_number (wtap *wth, guint32 *num, int *err, - gchar **err_info) +static int wtap_file_read_number (wtap *wth, uint32_t *num, int *err, + char **err_info) { int ret; char str_num[12]; @@ -238,20 +239,20 @@ static int wtap_file_read_number (wtap *wth, guint32 *num, int *err, return ret; } value = strtoul (str_num, &p, 10); - if (p == str_num || value > G_MAXUINT32) + if (p == str_num || value > UINT32_MAX) return 0; - *num = (guint32)value; + *num = (uint32_t)value; return 1; } -wtap_open_return_val peektagged_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val peektagged_open(wtap *wth, int *err, char **err_info) { peektagged_section_header_t ap_hdr; int ret; - guint32 fileVersion = 0; - guint32 mediaType; - guint32 mediaSubType = 0; + uint32_t fileVersion = 0; + uint32_t mediaType; + uint32_t mediaSubType = 0; int file_encap; static const int peektagged_encap[] = { WTAP_ENCAP_ETHERNET, @@ -259,7 +260,7 @@ wtap_open_return_val peektagged_open(wtap *wth, int *err, gchar **err_info) WTAP_ENCAP_IEEE_802_11_WITH_RADIO, WTAP_ENCAP_IEEE_802_11_WITH_RADIO }; - #define NUM_PEEKTAGGED_ENCAPS (sizeof peektagged_encap / sizeof peektagged_encap[0]) + #define NUM_PEEKTAGGED_ENCAPS array_length(peektagged_encap) peektagged_t *peektagged; if (!wtap_read_bytes(wth->fh, &ap_hdr, (int)sizeof(ap_hdr), err, err_info)) { @@ -387,11 +388,11 @@ wtap_open_return_val peektagged_open(wtap *wth, int *err, gchar **err_info) case PEEKTAGGED_NST_ETHERNET: case PEEKTAGGED_NST_802_11: case PEEKTAGGED_NST_802_11_2: - peektagged->has_fcs = FALSE; + peektagged->has_fcs = false; break; case PEEKTAGGED_NST_802_11_WITH_FCS: - peektagged->has_fcs = TRUE; + peektagged->has_fcs = true; break; } @@ -419,35 +420,35 @@ wtap_open_return_val peektagged_open(wtap *wth, int *err, gchar **err_info) */ static int peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { peektagged_t *peektagged = (peektagged_t *)wth->priv; - gboolean read_a_tag = FALSE; - guint8 tag_value[6]; - guint16 tag; - gboolean saw_length = FALSE; - guint32 length = 0; - guint32 sliceLength = 0; - gboolean saw_timestamp_lower = FALSE; - gboolean saw_timestamp_upper = FALSE; - gboolean saw_flags_and_status = FALSE; + bool read_a_tag = false; + uint8_t tag_value[6]; + uint16_t tag; + bool saw_length = false; + uint32_t length = 0; + uint32_t sliceLength = 0; + bool saw_timestamp_lower = false; + bool saw_timestamp_upper = false; + bool saw_flags_and_status = false; peektagged_utime timestamp; - guint32 flags_and_status = 0; - guint32 ext_flags = 0; - gboolean saw_data_rate_or_mcs_index = FALSE; - guint32 data_rate_or_mcs_index = 0; - gint channel; - guint frequency; + uint32_t flags_and_status = 0; + uint32_t ext_flags = 0; + bool saw_data_rate_or_mcs_index = false; + uint32_t data_rate_or_mcs_index = 0; + int channel; + unsigned frequency; struct ieee_802_11_phdr ieee_802_11 = {0}; - guint i; + unsigned i; int skip_len = 0; - guint64 t; + uint64_t t; timestamp.upper = 0; timestamp.lower = 0; ieee_802_11.fcs_len = -1; /* Unknown */ - ieee_802_11.decrypted = FALSE; - ieee_802_11.datapad = FALSE; + ieee_802_11.decrypted = false; + ieee_802_11.datapad = false; ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; /* Extract the fields from the packet header */ @@ -465,7 +466,7 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, } return -1; } - read_a_tag = TRUE; + read_a_tag = true; tag = pletoh16(&tag_value[0]); switch (tag) { @@ -476,7 +477,7 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, return -1; } length = pletoh32(&tag_value[2]); - saw_length = TRUE; + saw_length = true; break; case TAG_PEEKTAGGED_TIMESTAMP_LOWER: @@ -486,7 +487,7 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, return -1; } timestamp.lower = pletoh32(&tag_value[2]); - saw_timestamp_lower = TRUE; + saw_timestamp_lower = true; break; case TAG_PEEKTAGGED_TIMESTAMP_UPPER: @@ -496,41 +497,41 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, return -1; } timestamp.upper = pletoh32(&tag_value[2]); - saw_timestamp_upper = TRUE; + saw_timestamp_upper = true; break; case TAG_PEEKTAGGED_FLAGS_AND_STATUS: - saw_flags_and_status = TRUE; + saw_flags_and_status = true; flags_and_status = pletoh32(&tag_value[2]); break; case TAG_PEEKTAGGED_CHANNEL: - ieee_802_11.has_channel = TRUE; + ieee_802_11.has_channel = true; ieee_802_11.channel = pletoh32(&tag_value[2]); break; case TAG_PEEKTAGGED_DATA_RATE_OR_MCS_INDEX: data_rate_or_mcs_index = pletoh32(&tag_value[2]); - saw_data_rate_or_mcs_index = TRUE; + saw_data_rate_or_mcs_index = true; break; case TAG_PEEKTAGGED_SIGNAL_PERC: - ieee_802_11.has_signal_percent = TRUE; + ieee_802_11.has_signal_percent = true; ieee_802_11.signal_percent = pletoh32(&tag_value[2]); break; case TAG_PEEKTAGGED_SIGNAL_DBM: - ieee_802_11.has_signal_dbm = TRUE; + ieee_802_11.has_signal_dbm = true; ieee_802_11.signal_dbm = pletoh32(&tag_value[2]); break; case TAG_PEEKTAGGED_NOISE_PERC: - ieee_802_11.has_noise_percent = TRUE; + ieee_802_11.has_noise_percent = true; ieee_802_11.noise_percent = pletoh32(&tag_value[2]); break; case TAG_PEEKTAGGED_NOISE_DBM: - ieee_802_11.has_noise_dbm = TRUE; + ieee_802_11.has_noise_dbm = true; ieee_802_11.noise_dbm = pletoh32(&tag_value[2]); break; @@ -543,7 +544,7 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, case TAG_PEEKTAGGED_CENTER_FREQUENCY: /* XXX - also seen in an EtherPeek capture; value unknown */ - ieee_802_11.has_frequency = TRUE; + ieee_802_11.has_frequency = true; ieee_802_11.frequency = pletoh32(&tag_value[2]); break; @@ -626,12 +627,12 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, switch (ext_flags & EXT_FLAGS_GI) { case EXT_FLAG_HALF_GI: - ieee_802_11.phy_info.info_11ac.has_short_gi = TRUE; + ieee_802_11.phy_info.info_11ac.has_short_gi = true; ieee_802_11.phy_info.info_11ac.short_gi = 1; break; case EXT_FLAG_FULL_GI: - ieee_802_11.phy_info.info_11ac.has_short_gi = TRUE; + ieee_802_11.phy_info.info_11ac.has_short_gi = true; ieee_802_11.phy_info.info_11ac.short_gi = 0; break; @@ -644,22 +645,22 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, switch (ext_flags & EXT_FLAGS_BANDWIDTH) { case 0: - ieee_802_11.phy_info.info_11n.has_bandwidth = TRUE; + ieee_802_11.phy_info.info_11n.has_bandwidth = true; ieee_802_11.phy_info.info_11n.bandwidth = PHDR_802_11_BANDWIDTH_20_MHZ; break; case EXT_FLAG_20_MHZ_LOWER: - ieee_802_11.phy_info.info_11n.has_bandwidth = TRUE; + ieee_802_11.phy_info.info_11n.has_bandwidth = true; ieee_802_11.phy_info.info_11n.bandwidth = PHDR_802_11_BANDWIDTH_20_20L; break; case EXT_FLAG_20_MHZ_UPPER: - ieee_802_11.phy_info.info_11n.has_bandwidth = TRUE; + ieee_802_11.phy_info.info_11n.has_bandwidth = true; ieee_802_11.phy_info.info_11n.bandwidth = PHDR_802_11_BANDWIDTH_20_20U; break; case EXT_FLAG_40_MHZ: - ieee_802_11.phy_info.info_11n.has_bandwidth = TRUE; + ieee_802_11.phy_info.info_11n.has_bandwidth = true; ieee_802_11.phy_info.info_11n.bandwidth = PHDR_802_11_BANDWIDTH_40_MHZ; break; @@ -671,12 +672,12 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, switch (ext_flags & EXT_FLAGS_GI) { case EXT_FLAG_HALF_GI: - ieee_802_11.phy_info.info_11n.has_short_gi = TRUE; + ieee_802_11.phy_info.info_11n.has_short_gi = true; ieee_802_11.phy_info.info_11n.short_gi = 1; break; case EXT_FLAG_FULL_GI: - ieee_802_11.phy_info.info_11n.has_short_gi = TRUE; + ieee_802_11.phy_info.info_11n.has_short_gi = true; ieee_802_11.phy_info.info_11n.short_gi = 0; break; @@ -735,15 +736,15 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, rec->rec_header.packet_header.len = length; rec->rec_header.packet_header.caplen = sliceLength; if (saw_flags_and_status) { - guint32 flags = 0; + uint32_t flags = 0; if (flags_and_status & FLAGS_HAS_CRC_ERROR) flags |= PACK_FLAGS_CRC_ERROR; wtap_block_add_uint32_option(rec->block, OPT_PKT_FLAGS, flags); } /* calculate and fill in packet time stamp */ - t = (((guint64) timestamp.upper) << 32) + timestamp.lower; - if (!nsfiletime_to_nstime(&rec->ts, t)) { + t = (((uint64_t) timestamp.upper) << 32) + timestamp.lower; + if (!filetime_ns_to_nstime(&rec->ts, t)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("peektagged: time stamp outside supported range"); return -1; @@ -760,12 +761,12 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, * XXX - what about 11ac? */ if (!(ext_flags & EXT_FLAG_802_11ac)) { - ieee_802_11.phy_info.info_11n.has_mcs_index = TRUE; + ieee_802_11.phy_info.info_11n.has_mcs_index = true; ieee_802_11.phy_info.info_11n.mcs_index = data_rate_or_mcs_index; } } else { /* It's a data rate. */ - ieee_802_11.has_data_rate = TRUE; + ieee_802_11.has_data_rate = true; ieee_802_11.data_rate = data_rate_or_mcs_index; if (ieee_802_11.phy == PHDR_802_11_PHY_UNKNOWN) { /* @@ -776,11 +777,11 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, /* 11b */ ieee_802_11.phy = PHDR_802_11_PHY_11B; if (saw_flags_and_status) { - ieee_802_11.phy_info.info_11b.has_short_preamble = TRUE; + ieee_802_11.phy_info.info_11b.has_short_preamble = true; ieee_802_11.phy_info.info_11b.short_preamble = - (flags_and_status & STATUS_SHORT_PREAMBLE) ? TRUE : FALSE;; + (flags_and_status & STATUS_SHORT_PREAMBLE) ? true : false; } else - ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE; + ieee_802_11.phy_info.info_11b.has_short_preamble = false; } else if (RATE_IS_OFDM(ieee_802_11.data_rate)) { /* 11a or 11g, depending on the band. */ if (ieee_802_11.has_channel) { @@ -802,11 +803,11 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, } if (ieee_802_11.phy == PHDR_802_11_PHY_11G) { /* Set 11g metadata */ - ieee_802_11.phy_info.info_11g.has_mode = FALSE; + ieee_802_11.phy_info.info_11g.has_mode = false; } else if (ieee_802_11.phy == PHDR_802_11_PHY_11A) { /* Set 11a metadata */ - ieee_802_11.phy_info.info_11a.has_channel_type = FALSE; - ieee_802_11.phy_info.info_11a.has_turbo_type = FALSE; + ieee_802_11.phy_info.info_11a.has_channel_type = false; + ieee_802_11.phy_info.info_11a.has_turbo_type = false; } /* Otherwise we don't know the PHY */ } @@ -817,7 +818,7 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, /* Frequency, but no channel; try to calculate the channel. */ channel = ieee80211_mhz_to_chan(ieee_802_11.frequency); if (channel != -1) { - ieee_802_11.has_channel = TRUE; + ieee_802_11.has_channel = true; ieee_802_11.channel = channel; } } else if (ieee_802_11.has_channel && !ieee_802_11.has_frequency) { @@ -833,11 +834,11 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, case PHDR_802_11_PHY_11_DSSS: case PHDR_802_11_PHY_11B: case PHDR_802_11_PHY_11G: - frequency = ieee80211_chan_to_mhz(ieee_802_11.channel, TRUE); + frequency = ieee80211_chan_to_mhz(ieee_802_11.channel, true); break; case PHDR_802_11_PHY_11A: - frequency = ieee80211_chan_to_mhz(ieee_802_11.channel, FALSE); + frequency = ieee80211_chan_to_mhz(ieee_802_11.channel, false); break; default: @@ -846,7 +847,7 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, break; } if (frequency != 0) { - ieee_802_11.has_frequency = TRUE; + ieee_802_11.has_frequency = true; ieee_802_11.frequency = frequency; } } @@ -857,15 +858,15 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, if (rec->rec_header.packet_header.len < 4 || rec->rec_header.packet_header.caplen < 4) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("peektagged: 802.11 packet has length < 4"); - return FALSE; + return false; } rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; rec->rec_header.packet_header.len -= 4; rec->rec_header.packet_header.caplen -= 4; skip_len = 4; } - rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = FALSE; - rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = FALSE; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = false; + rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = false; break; case WTAP_ENCAP_ETHERNET: @@ -876,7 +877,7 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, if (rec->rec_header.packet_header.len < 4 || rec->rec_header.packet_header.caplen < 4) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("peektagged: Ethernet packet has length < 4"); - return FALSE; + return false; } rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; rec->rec_header.packet_header.len -= 4; @@ -892,8 +893,8 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, return skip_len; } -static gboolean peektagged_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool peektagged_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { int skip_len; @@ -902,31 +903,31 @@ static gboolean peektagged_read(wtap *wth, wtap_rec *rec, Buffer *buf, /* Read the packet. */ skip_len = peektagged_read_packet(wth, wth->fh, rec, buf, err, err_info); if (skip_len == -1) - return FALSE; + return false; if (skip_len != 0) { /* Skip extra junk at the end of the packet data. */ if (!wtap_read_bytes(wth->fh, NULL, skip_len, err, err_info)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean -peektagged_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +peektagged_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read the packet. */ if (peektagged_read_packet(wth, wth->random_fh, rec, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } static const struct supported_block_type peektagged_blocks_supported[] = { @@ -938,7 +939,7 @@ static const struct supported_block_type peektagged_blocks_supported[] = { static const struct file_type_subtype_info peektagged_info = { "Savvius tagged", "peektagged", "pkt", "tpc;apc;wpz", - FALSE, BLOCKS_SUPPORTED(peektagged_blocks_supported), + false, BLOCKS_SUPPORTED(peektagged_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/peektagged.h b/wiretap/peektagged.h index 04451ef1..15e379d2 100644 --- a/wiretap/peektagged.h +++ b/wiretap/peektagged.h @@ -10,7 +10,8 @@ #define __W_PEEKTAGGED_H__ #include <glib.h> #include "ws_symbol_export.h" +#include "wtap.h" -wtap_open_return_val peektagged_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val peektagged_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c index 15eda4fc..c711e50e 100644 --- a/wiretap/pppdump.c +++ b/wiretap/pppdump.c @@ -6,14 +6,15 @@ */ #include "config.h" -#include "wtap-int.h" #include "pppdump.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <stdlib.h> #include <errno.h> #include <string.h> +#include <wsutil/array.h> #include <wsutil/ws_assert.h> /* @@ -85,10 +86,10 @@ typedef enum { DIRECTION_RECV } direction_enum; -static gboolean pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean pppdump_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool pppdump_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int pppdump_file_type_subtype = -1; @@ -109,8 +110,8 @@ void register_pppdump(void); * "dir" is the direction of the packet. */ typedef struct { - gint64 offset; - gint64 num_bytes_to_skip; + int64_t offset; + int64_t num_bytes_to_skip; direction_enum dir; } pkt_id; @@ -124,8 +125,8 @@ typedef struct { * * "cnt" is the number of bytes of packet data we've accumulated. * - * "esc" is TRUE if the next byte we see is escaped (and thus must be XORed - * with 0x20 before saving it), FALSE otherwise. + * "esc" is true if the next byte we see is escaped (and thus must be XORed + * with 0x20 before saving it), false otherwise. * * "buf" is a buffer containing the packet data we've accumulated. * @@ -143,11 +144,11 @@ typedef struct { typedef struct { direction_enum dir; int cnt; - gboolean esc; - guint8 buf[PPPD_BUF_SIZE]; - gint64 id_offset; - gint64 sd_offset; - gint64 cd_offset; + bool esc; + uint8_t buf[PPPD_BUF_SIZE]; + int64_t id_offset; + int64_t sd_offset; + int64_t cd_offset; } pkt_t; /* @@ -187,25 +188,25 @@ typedef struct { */ typedef struct _pppdump_t { time_t timestamp; - guint tenths; + unsigned tenths; pkt_t spkt; pkt_t rpkt; - gint64 offset; + int64_t offset; int num_bytes; pkt_t *pkt; struct _pppdump_t *seek_state; GPtrArray *pids; - guint pkt_cnt; + unsigned pkt_cnt; } pppdump_t; static int -process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, - int *err, gchar **err_info, pkt_id *pid); +process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, uint8_t *pd, + int *err, char **err_info, pkt_id *pid); -static gboolean -collate(pppdump_t *state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, +static bool +collate(pppdump_t *state, FILE_T fh, int *err, char **err_info, uint8_t *pd, int *num_bytes, direction_enum *direction, pkt_id *pid, - gint64 num_bytes_to_skip); + int64_t num_bytes_to_skip); static void pppdump_close(wtap *wth); @@ -219,14 +220,14 @@ init_state(pppdump_t *state) state->spkt.dir = DIRECTION_SENT; state->spkt.cnt = 0; - state->spkt.esc = FALSE; + state->spkt.esc = false; state->spkt.id_offset = 0; state->spkt.sd_offset = 0; state->spkt.cd_offset = 0; state->rpkt.dir = DIRECTION_RECV; state->rpkt.cnt = 0; - state->rpkt.esc = FALSE; + state->rpkt.esc = false; state->rpkt.id_offset = 0; state->rpkt.sd_offset = 0; state->rpkt.cd_offset = 0; @@ -237,9 +238,9 @@ init_state(pppdump_t *state) wtap_open_return_val -pppdump_open(wtap *wth, int *err, gchar **err_info) +pppdump_open(wtap *wth, int *err, char **err_info) { - guint8 buffer[6]; /* Looking for: 0x07 t3 t2 t1 t0 ID */ + uint8_t buffer[6]; /* Looking for: 0x07 t3 t2 t1 t0 ID */ pppdump_t *state; /* There is no file header, only packet records. Fortunately for us, @@ -325,13 +326,13 @@ pppdump_set_phdr(wtap_rec *rec, int num_bytes, rec->rec_header.packet_header.caplen = num_bytes; rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR; - rec->rec_header.packet_header.pseudo_header.p2p.sent = (direction == DIRECTION_SENT ? TRUE : FALSE); + rec->rec_header.packet_header.pseudo_header.p2p.sent = (direction == DIRECTION_SENT ? true : false); } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean -pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, - gint64 *data_offset) +static bool +pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, + int64_t *data_offset) { int num_bytes; direction_enum direction; @@ -346,7 +347,7 @@ pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, pid = g_new(pkt_id, 1); if (!pid) { *err = errno; /* assume a malloc failed and set "errno" */ - return FALSE; + return false; } pid->offset = 0; } else @@ -356,7 +357,7 @@ pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, if (!collate(state, wth->fh, err, err_info, ws_buffer_start_ptr(buf), &num_bytes, &direction, pid, 0)) { g_free(pid); - return FALSE; + return false; } if (pid != NULL) @@ -373,7 +374,7 @@ pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, rec->ts.secs = state->timestamp; rec->ts.nsecs = state->tenths * 100000000; - return TRUE; + return true; } /* Returns number of bytes copied for record, -1 if failure. @@ -382,8 +383,8 @@ pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, * comes with the ppp distribution. */ static int -process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, - int *err, gchar **err_info, pkt_id *pid) +process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, uint8_t *pd, + int *err, char **err_info, pkt_id *pid) { int c; int num_bytes = n; @@ -423,7 +424,7 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, * so this is the end of a frame. * Make a frame out of that stuff. */ - pkt->esc = FALSE; + pkt->esc = false; num_written = pkt->cnt; pkt->cnt = 0; @@ -502,7 +503,7 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, * but XOR the next octet with * 0x20. */ - pkt->esc = TRUE; + pkt->esc = true; break; } /* @@ -523,7 +524,7 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, * character should be escaped. */ c ^= 0x20; - pkt->esc = FALSE; + pkt->esc = false; } if (pkt->cnt >= PPPD_BUF_SIZE) { @@ -541,19 +542,19 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, return 0; } -/* Returns TRUE if packet data copied, FALSE if error occurred or EOF (no more records). */ -static gboolean -collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, +/* Returns true if packet data copied, false if error occurred or EOF (no more records). */ +static bool +collate(pppdump_t* state, FILE_T fh, int *err, char **err_info, uint8_t *pd, int *num_bytes, direction_enum *direction, pkt_id *pid, - gint64 num_bytes_to_skip) + int64_t num_bytes_to_skip) { int id; pkt_t *pkt = NULL; int byte0, byte1; int n, num_written = 0; - gint64 start_offset; - guint32 time_long; - guint8 time_short; + int64_t start_offset; + uint32_t time_long; + uint8_t time_short; /* * Process any data left over in the current record when doing @@ -566,12 +567,12 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, pd, err, err_info, pid); if (num_written < 0) { - return FALSE; + return false; } else if (num_written > 0) { *num_bytes = num_written; *direction = pkt->dir; - return TRUE; + return true; } /* if 0 bytes written, keep processing */ } else { @@ -646,12 +647,12 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, pd, err, err_info, pid); if (num_written < 0) { - return FALSE; + return false; } else if (num_written > 0) { *num_bytes = num_written; *direction = pkt->dir; - return TRUE; + return true; } /* if 0 bytes written, keep looping */ break; @@ -662,17 +663,17 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, break; case PPPD_RESET_TIME: - if (!wtap_read_bytes(fh, &time_long, sizeof(guint32), err, err_info)) - return FALSE; - state->offset += sizeof(guint32); + if (!wtap_read_bytes(fh, &time_long, sizeof(uint32_t), err, err_info)) + return false; + state->offset += sizeof(uint32_t); state->timestamp = pntoh32(&time_long); state->tenths = 0; break; case PPPD_TIME_STEP_LONG: - if (!wtap_read_bytes(fh, &time_long, sizeof(guint32), err, err_info)) - return FALSE; - state->offset += sizeof(guint32); + if (!wtap_read_bytes(fh, &time_long, sizeof(uint32_t), err, err_info)) + return false; + state->offset += sizeof(uint32_t); state->tenths += pntoh32(&time_long); if (state->tenths >= 10) { @@ -683,9 +684,9 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, break; case PPPD_TIME_STEP_SHORT: - if (!wtap_read_bytes(fh, &time_short, sizeof(guint8), err, err_info)) - return FALSE; - state->offset += sizeof(guint8); + if (!wtap_read_bytes(fh, &time_short, sizeof(uint8_t), err, err_info)) + return false; + state->offset += sizeof(uint8_t); state->tenths += time_short; if (state->tenths >= 10) { @@ -699,7 +700,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd, /* XXX - bad file */ *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("pppdump: bad ID byte 0x%02x", id); - return FALSE; + return false; } } @@ -716,26 +717,26 @@ done: *err = WTAP_ERR_SHORT_READ; } } - return FALSE; + return false; } /* Used to read packets in random-access fashion */ -static gboolean +static bool pppdump_seek_read(wtap *wth, - gint64 seek_off, + int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info) + char **err_info) { int num_bytes; - guint8 *pd; + uint8_t *pd; direction_enum direction; pppdump_t *state; pkt_id *pid; - gint64 num_bytes_to_skip; + int64_t num_bytes_to_skip; state = (pppdump_t *)wth->priv; @@ -743,11 +744,11 @@ pppdump_seek_read(wtap *wth, if (!pid) { *err = WTAP_ERR_BAD_FILE; /* XXX - better error? */ *err_info = g_strdup("pppdump: PID not found for record"); - return FALSE; + return false; } if (file_seek(wth->random_fh, pid->offset, SEEK_SET, err) == -1) - return FALSE; + return false; init_state(state->seek_state); state->seek_state->offset = pid->offset; @@ -770,13 +771,13 @@ pppdump_seek_read(wtap *wth, do { if (!collate(state->seek_state, wth->random_fh, err, err_info, pd, &num_bytes, &direction, NULL, num_bytes_to_skip)) - return FALSE; + return false; num_bytes_to_skip = 0; } while (direction != pid->dir); pppdump_set_phdr(rec, num_bytes, pid->dir); - return TRUE; + return true; } static void @@ -786,7 +787,7 @@ pppdump_close(wtap *wth) state = (pppdump_t *)wth->priv; - if (state->seek_state) { /* should always be TRUE */ + if (state->seek_state) { /* should always be true */ g_free(state->seek_state); } @@ -795,7 +796,7 @@ pppdump_close(wtap *wth) for (i = 0; i < g_ptr_array_len(state->pids); i++) { g_free(g_ptr_array_index(state->pids, i)); } - g_ptr_array_free(state->pids, TRUE); + g_ptr_array_free(state->pids, true); } } @@ -808,7 +809,7 @@ static const struct supported_block_type pppdump_blocks_supported[] = { static const struct file_type_subtype_info pppdump_info = { "pppd log (pppdump format)", "pppd", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(pppdump_blocks_supported), + false, BLOCKS_SUPPORTED(pppdump_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/pppdump.h b/wiretap/pppdump.h index a0a022fe..19899fbc 100644 --- a/wiretap/pppdump.h +++ b/wiretap/pppdump.h @@ -13,6 +13,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val pppdump_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val pppdump_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/radcom.c b/wiretap/radcom.c index 6e6c5963..6e216e67 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -7,18 +7,18 @@ */ #include "config.h" +#include "radcom.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "radcom.h" struct frame_date { - guint16 year; - guint8 month; - guint8 day; - guint32 sec; /* seconds since midnight */ - guint32 usec; + uint16_t year; + uint8_t month; + uint8_t day; + uint32_t sec; /* seconds since midnight */ + uint32_t usec; }; struct unaligned_frame_date { @@ -31,15 +31,15 @@ struct unaligned_frame_date { /* Found at the beginning of the file. Bytes 2 and 3 (D2:00) seem to be * different in some captures */ -static const guint8 radcom_magic[8] = { +static const uint8_t radcom_magic[8] = { 0x42, 0xD2, 0x00, 0x34, 0x12, 0x66, 0x22, 0x88 }; -static const guint8 encap_magic[4] = { +static const uint8_t encap_magic[4] = { 0x00, 0x42, 0x43, 0x09 }; -static const guint8 active_time_magic[11] = { +static const uint8_t active_time_magic[11] = { 'A', 'c', 't', 'i', 'v', 'e', ' ', 'T', 'i', 'm', 'e' }; @@ -70,23 +70,23 @@ struct radcomrec_hdr { char xxw[9]; /* unknown */ }; -static gboolean radcom_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean radcom_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); +static bool radcom_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool radcom_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info); static int radcom_file_type_subtype = -1; void register_radcom(void); -wtap_open_return_val radcom_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val radcom_open(wtap *wth, int *err, char **err_info) { - guint8 r_magic[8], t_magic[11], search_encap[7]; + uint8_t r_magic[8], t_magic[11], search_encap[7]; struct frame_date start_date; #if 0 - guint32 sec; + uint32_t sec; struct tm tm; #endif @@ -241,8 +241,8 @@ wtap_open_return_val radcom_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static gboolean radcom_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool radcom_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { char fcs[2]; @@ -251,7 +251,7 @@ static gboolean radcom_read(wtap *wth, wtap_rec *rec, Buffer *buf, /* Read record. */ if (!radcom_read_rec(wth, wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } if (wth->file_encap == WTAP_ENCAP_LAPB) { @@ -260,19 +260,19 @@ static gboolean radcom_read(wtap *wth, wtap_rec *rec, Buffer *buf, presence and size of an FCS to our caller? That'd let us handle other file types as well. */ if (!wtap_read_bytes(wth->fh, &fcs, sizeof fcs, err, err_info)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean -radcom_seek_read(wtap *wth, gint64 seek_off, +static bool +radcom_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, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read record. */ if (!radcom_read_rec(wth, wth->random_fh, rec, buf, err, @@ -282,23 +282,23 @@ radcom_seek_read(wtap *wth, gint64 seek_off, /* EOF means "short read" in random-access mode */ *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { struct radcomrec_hdr hdr; - guint16 data_length, real_length, length; - guint32 sec; + uint16_t data_length, real_length, length; + uint32_t sec; struct tm tm; - guint8 atmhdr[8]; + uint8_t atmhdr[8]; if (!wtap_read_bytes_or_eof(fh, &hdr, sizeof hdr, err, err_info)) - return FALSE; + return false; data_length = pletoh16(&hdr.data_length); if (data_length == 0) { @@ -308,7 +308,7 @@ radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, * check for that and treat it as an EOF indication. */ *err = 0; - return FALSE; + return false; } length = pletoh16(&hdr.length); real_length = pletoh16(&hdr.real_length); @@ -354,7 +354,7 @@ radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, */ if (!wtap_read_bytes(fh, atmhdr, sizeof atmhdr, err, err_info)) - return FALSE; /* Read error */ + return false; /* Read error */ length -= 8; real_length -= 8; break; @@ -367,9 +367,9 @@ radcom_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, * Read the packet data. */ if (!wtap_read_packet_bytes(fh, buf, length, err, err_info)) - return FALSE; /* Read error */ + return false; /* Read error */ - return TRUE; + return true; } static const struct supported_block_type radcom_blocks_supported[] = { @@ -381,7 +381,7 @@ static const struct supported_block_type radcom_blocks_supported[] = { static const struct file_type_subtype_info radcom_info = { "RADCOM WAN/LAN analyzer", "radcom", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(radcom_blocks_supported), + false, BLOCKS_SUPPORTED(radcom_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/radcom.h b/wiretap/radcom.h index f45a5931..fdbf478a 100644 --- a/wiretap/radcom.h +++ b/wiretap/radcom.h @@ -14,6 +14,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val radcom_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val radcom_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/rfc7468.c b/wiretap/rfc7468.c index 1c143273..79824139 100644 --- a/wiretap/rfc7468.c +++ b/wiretap/rfc7468.c @@ -33,8 +33,8 @@ const char PREEB_BEGIN[] = "-----BEGIN "; const char POSTEB_BEGIN[] = "-----END "; #define POSTEB_BEGIN_LEN (sizeof POSTEB_BEGIN - 1) -static gboolean rfc7468_read_line(FILE_T fh, enum line_type *line_type, Buffer *buf, - int* err, gchar** err_info) +static bool rfc7468_read_line(FILE_T fh, enum line_type *line_type, Buffer *buf, + int* err, char** err_info) { /* Make the chunk size large enough that most lines can fit in a single chunk. Strict RFC 7468 syntax only allows up to 64 characters per line, but we provide @@ -45,7 +45,7 @@ static gboolean rfc7468_read_line(FILE_T fh, enum line_type *line_type, Buffer * if (!(line_chunk_end = file_getsp(line_chunk, sizeof line_chunk, fh))) { *err = file_error(fh, err_info); - return FALSE; + return false; } // First chunk determines the line type. @@ -57,13 +57,13 @@ static gboolean rfc7468_read_line(FILE_T fh, enum line_type *line_type, Buffer * *line_type = LINE_TYPE_OTHER; for (;;) { - gsize line_chunk_len = line_chunk_end - line_chunk; - if (line_chunk_len > G_MAXINT - ws_buffer_length(buf)) { + size_t line_chunk_len = line_chunk_end - line_chunk; + if (line_chunk_len > INT_MAX - ws_buffer_length(buf)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf( "File contains an encoding larger than the maximum of %d bytes", - G_MAXINT); - return FALSE; + INT_MAX); + return false; } ws_buffer_append(buf, line_chunk, line_chunk_len); @@ -73,35 +73,35 @@ static gboolean rfc7468_read_line(FILE_T fh, enum line_type *line_type, Buffer * if (!(line_chunk_end = file_getsp(line_chunk, sizeof line_chunk, fh))) { *err = file_error(fh, err_info); - return FALSE; + return false; } } - return TRUE; + return true; } -static gboolean rfc7468_read_impl(FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +static bool rfc7468_read_impl(FILE_T fh, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { ws_buffer_clean(buf); - gboolean saw_preeb = FALSE; + bool saw_preeb = false; for (;;) { enum line_type line_type; if (!rfc7468_read_line(fh, &line_type, buf, err, err_info)) { - if (*err != 0 || !saw_preeb) return FALSE; + if (*err != 0 || !saw_preeb) return false; *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Missing post-encapsulation boundary at end of file"); - return FALSE; + return false; } if (saw_preeb) { if (line_type == LINE_TYPE_POSTEB) break; } else { - if (line_type == LINE_TYPE_PREEB) saw_preeb = TRUE; + if (line_type == LINE_TYPE_PREEB) saw_preeb = true; } } @@ -109,30 +109,30 @@ static gboolean rfc7468_read_impl(FILE_T fh, wtap_rec *rec, Buffer *buf, rec->presence_flags = 0; rec->ts.secs = 0; rec->ts.nsecs = 0; - rec->rec_header.packet_header.caplen = (guint32)ws_buffer_length(buf); - rec->rec_header.packet_header.len = (guint32)ws_buffer_length(buf); + rec->rec_header.packet_header.caplen = (uint32_t)ws_buffer_length(buf); + rec->rec_header.packet_header.len = (uint32_t)ws_buffer_length(buf); - return TRUE; + return true; } -static gboolean rfc7468_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool rfc7468_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return rfc7468_read_impl(wth->fh, rec, buf, err, err_info); } -static gboolean rfc7468_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool rfc7468_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) < 0) - return FALSE; + return false; return rfc7468_read_impl(wth->random_fh, rec, buf, err, err_info); } -wtap_open_return_val rfc7468_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val rfc7468_open(wtap *wth, int *err, char **err_info) { /* To detect whether this file matches our format, we need to find the first pre-encapsulation boundary, which may be located anywhere in the file, @@ -191,7 +191,7 @@ static const struct supported_block_type rfc7468_blocks_supported[] = { static const struct file_type_subtype_info rfc7468_info = { "RFC 7468 files", "rfc7468", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(rfc7468_blocks_supported), + false, BLOCKS_SUPPORTED(rfc7468_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/rfc7468.h b/wiretap/rfc7468.h index 0a3d55f9..6ede8602 100644 --- a/wiretap/rfc7468.h +++ b/wiretap/rfc7468.h @@ -9,7 +9,7 @@ #include <glib.h> #include "wtap.h" -wtap_open_return_val rfc7468_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val rfc7468_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/rtpdump.c b/wiretap/rtpdump.c index cd18b28a..55aa5397 100644 --- a/wiretap/rtpdump.c +++ b/wiretap/rtpdump.c @@ -47,6 +47,8 @@ */ #include "config.h" +#include "rtpdump.h" + #include <wtap-int.h> #include <file_wrappers.h> #include <wsutil/exported_pdu_tlvs.h> @@ -54,7 +56,6 @@ #include <wsutil/nstime.h> #include <wsutil/strtoi.h> #include <wsutil/wslog.h> -#include "rtpdump.h" #include <string.h> /* NB. I've included the version string in the magic for stronger identification. @@ -85,15 +86,15 @@ */ #define RTP_BUFFER_INIT_LEN 20+EXP_PDU_TAG_IPV6_LEN -static gboolean +static bool rtpdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, - gint64 *data_offset); + int *err, char **err_info, + int64_t *data_offset); -static gboolean -rtpdump_seek_read(wtap *wth, gint64 seek_off, +static bool +rtpdump_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + int *err, char **err_info); static void rtpdump_close(wtap *wth); @@ -115,16 +116,16 @@ void register_rtpdump(void); wtap_open_return_val rtpdump_open(wtap *wth, int *err, char **err_info) { - guint8 buf_magic[RTP_MAGIC_LEN]; + uint8_t buf_magic[RTP_MAGIC_LEN]; char ch = '\0'; rtpdump_priv_t *priv = NULL; ip_addr_t txt_addr; ws_in4_addr bin_addr; - guint16 txt_port = 0; - guint16 bin_port = 0; + uint16_t txt_port = 0; + uint16_t bin_port = 0; GString *header_str = NULL; - gboolean is_ipv6 = FALSE; - gboolean got_ip = FALSE; + bool is_ipv6 = false; + bool got_ip = false; nstime_t start_time = NSTIME_INIT_ZERO; Buffer *buf; @@ -150,10 +151,10 @@ rtpdump_open(wtap *wth, int *err, char **err_info) if (ch == '/') { /* Everything up to now should be an IP address */ if (ws_inet_pton4(header_str->str, &txt_addr.ipv4)) { - is_ipv6 = FALSE; + is_ipv6 = false; } else if (ws_inet_pton6(header_str->str, &txt_addr.ipv6)) { - is_ipv6 = TRUE; + is_ipv6 = true; } else { *err = WTAP_ERR_BAD_FILE; @@ -162,7 +163,7 @@ rtpdump_open(wtap *wth, int *err, char **err_info) return WTAP_OPEN_ERROR; } - got_ip = TRUE; + got_ip = true; g_string_truncate(header_str, 0); } else if (ch == '\n') { @@ -235,22 +236,22 @@ rtpdump_open(wtap *wth, int *err, char **err_info) /* File must be generated by Wireshark. Text address is IPv6 destination, * binary address is invalid and ignored here. */ - wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_IPV6_DST, (const guint8 *)&txt_addr.ipv6, EXP_PDU_TAG_IPV6_LEN); + wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_IPV6_DST, (const uint8_t *)&txt_addr.ipv6, EXP_PDU_TAG_IPV6_LEN); wtap_buffer_append_epdu_uint(buf, EXP_PDU_TAG_DST_PORT, txt_port); } else if (txt_addr.ipv4 == bin_addr && txt_port == bin_port) { /* File must be generated by rtpdump. Both addresses are IPv4 source. */ - wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_IPV4_SRC, (const guint8 *)&bin_addr, EXP_PDU_TAG_IPV4_LEN); + wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_IPV4_SRC, (const uint8_t *)&bin_addr, EXP_PDU_TAG_IPV4_LEN); wtap_buffer_append_epdu_uint(buf, EXP_PDU_TAG_SRC_PORT, bin_port); } else { /* File must be generated by Wireshark. Text is IPv4 destination, * binary is IPv4 source. */ - wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_IPV4_DST, (const guint8 *)&txt_addr.ipv4, EXP_PDU_TAG_IPV4_LEN); + wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_IPV4_DST, (const uint8_t *)&txt_addr.ipv4, EXP_PDU_TAG_IPV4_LEN); wtap_buffer_append_epdu_uint(buf, EXP_PDU_TAG_DST_PORT, txt_port); - wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_IPV4_SRC, (const guint8 *)&bin_addr, EXP_PDU_TAG_IPV4_LEN); + wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_IPV4_SRC, (const uint8_t *)&bin_addr, EXP_PDU_TAG_IPV4_LEN); wtap_buffer_append_epdu_uint(buf, EXP_PDU_TAG_SRC_PORT, bin_port); } @@ -268,24 +269,24 @@ rtpdump_open(wtap *wth, int *err, char **err_info) return WTAP_OPEN_MINE; } -static gboolean +static bool rtpdump_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) + int *err, char **err_info) { rtpdump_priv_t *priv = (rtpdump_priv_t *)wth->priv; nstime_t ts = NSTIME_INIT_ZERO; - guint32 epdu_len = 0; /* length of the Exported PDU headers we add */ - const guint8 hdr_len = 8; /* Header comprised of the following 3 fields: */ - guint16 length; /* length of packet, including this header (may + uint32_t epdu_len = 0; /* length of the Exported PDU headers we add */ + const uint8_t hdr_len = 8; /* Header comprised of the following 3 fields: */ + uint16_t length; /* length of packet, including this header (may be smaller than plen if not whole packet recorded) */ - guint16 plen; /* actual header+payload length for RTP, 0 for RTCP */ - guint32 offset; /* milliseconds since the start of recording */ + uint16_t plen; /* actual header+payload length for RTP, 0 for RTCP */ + uint32_t offset; /* milliseconds since the start of recording */ - if (!wtap_read_bytes_or_eof(fh, (void *)&length, 2, err, err_info)) return FALSE; + if (!wtap_read_bytes_or_eof(fh, (void *)&length, 2, err, err_info)) return false; length = g_ntohs(length); - if (!wtap_read_bytes(fh, (void *)&plen, 2, err, err_info)) return FALSE; + if (!wtap_read_bytes(fh, (void *)&plen, 2, err, err_info)) return false; plen = g_ntohs(plen); - if (!wtap_read_bytes(fh, (void *)&offset, 4, err, err_info)) return FALSE; + if (!wtap_read_bytes(fh, (void *)&offset, 4, err, err_info)) return false; offset = g_ntohl(offset); /* Set length to remaining length of packet data */ @@ -315,20 +316,20 @@ rtpdump_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, return wtap_read_packet_bytes(fh, buf, length, err, err_info); } -static gboolean -rtpdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, - gint64 *data_offset) +static bool +rtpdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char **err_info, + int64_t *data_offset) { *data_offset = file_tell(wth->fh); return rtpdump_read_packet(wth, wth->fh, rec, buf, err, err_info); } -static gboolean -rtpdump_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +rtpdump_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return rtpdump_read_packet(wth, wth->random_fh, rec, buf, err, err_info); } @@ -346,7 +347,7 @@ static const struct supported_block_type rtpdump_blocks_supported[] = { static const struct file_type_subtype_info rtpdump_info = { "RTPDump stream file", "rtpdump", "rtp", "rtpdump", - FALSE, BLOCKS_SUPPORTED(rtpdump_blocks_supported), + false, BLOCKS_SUPPORTED(rtpdump_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/ruby_marshal.c b/wiretap/ruby_marshal.c index 026f7b65..377c688f 100644 --- a/wiretap/ruby_marshal.c +++ b/wiretap/ruby_marshal.c @@ -8,24 +8,23 @@ */ #include "config.h" +#include "ruby_marshal.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "ruby_marshal.h" - static int ruby_marshal_file_type_subtype = -1; void register_ruby_marshal(void); -static gboolean is_ruby_marshal(const guint8* filebuf) +static bool is_ruby_marshal(const uint8_t* filebuf) { if (filebuf[0] != RUBY_MARSHAL_MAJOR) - return FALSE; + return false; if (filebuf[1] != RUBY_MARSHAL_MINOR) - return FALSE; + return false; switch (filebuf[2]) { case '0': case 'T': @@ -46,17 +45,16 @@ static gboolean is_ruby_marshal(const guint8* filebuf) case 'e': case ';': case '@': - return TRUE; - break; + return true; default: - return FALSE; + return false; } } -wtap_open_return_val ruby_marshal_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val ruby_marshal_open(wtap *wth, int *err, char **err_info) { /* The size of this buffer should match the expectations of is_ruby_marshal */ - guint8 filebuf[3]; + uint8_t filebuf[3]; int bytes_read; bytes_read = file_read(filebuf, sizeof(filebuf), wth->fh); @@ -93,7 +91,7 @@ static const struct supported_block_type ruby_marshal_blocks_supported[] = { static const struct file_type_subtype_info ruby_marshal_info = { "Ruby marshal files", "ruby_marshal", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(ruby_marshal_blocks_supported), + false, BLOCKS_SUPPORTED(ruby_marshal_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/ruby_marshal.h b/wiretap/ruby_marshal.h index e89d3bf7..15d881bf 100644 --- a/wiretap/ruby_marshal.h +++ b/wiretap/ruby_marshal.h @@ -17,7 +17,7 @@ #define RUBY_MARSHAL_MAJOR 4 #define RUBY_MARSHAL_MINOR 8 -wtap_open_return_val ruby_marshal_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val ruby_marshal_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/secrets-types.c b/wiretap/secrets-types.c new file mode 100644 index 00000000..caae6327 --- /dev/null +++ b/wiretap/secrets-types.c @@ -0,0 +1,49 @@ +/* wtap_opttypes.c + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 2001 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "config.h" + +#include "secrets-types.h" + +const char* secrets_type_description(uint32_t type) +{ +#if 0 + /* value_string from file-pcapng.c + * XXX: value_string is defined in epan. Perhaps some of the + * functions (not the ones that allocate in wmem_packet_scope()) + * should be moved to wsutil so that other libraries can use them + * (capinfos, etc. don't link with libwireshark). + */ + static const value_string secrets_types_vals[] = { + { SECRETS_TYPE_TLS, "TLS Key Log" }, + { SECRETS_TYPE_SSH, "SSH Key Log" }, + { SECRETS_TYPE_WIREGUARD, "WireGuard Key Log" }, + { SECRETS_TYPE_ZIGBEE_NWK_KEY, "Zigbee NWK Key" }, + { SECRETS_TYPE_ZIGBEE_APS_KEY, "Zigbee APS Key" }, + { SECRETS_TYPE_OPCUA, "OPC UA Key Log" }, + { 0, NULL } + }; + return val_to_str_const(type, secrets_types_vals, "Unknown"); +#endif + switch (type) { + case SECRETS_TYPE_TLS: + return "TLS Key Log"; + case SECRETS_TYPE_SSH: + return "SSH Key Log"; + case SECRETS_TYPE_WIREGUARD: + return "WireGuard Key Log"; + case SECRETS_TYPE_ZIGBEE_NWK_KEY: + return "Zigbee NWK Key"; + case SECRETS_TYPE_ZIGBEE_APS_KEY: + return "Zigbee APS Key"; + case SECRETS_TYPE_OPCUA: + return "OPC UA Key Log"; + default: + return "Unknown"; + } +} diff --git a/wiretap/secrets-types.h b/wiretap/secrets-types.h index 7e44a736..629f40ff 100644 --- a/wiretap/secrets-types.h +++ b/wiretap/secrets-types.h @@ -12,6 +12,14 @@ #ifndef __SECRETS_TYPES_H__ #define __SECRETS_TYPES_H__ +#include "ws_symbol_export.h" + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + /* * Type describing the format of the opaque secrets value in a pcapng DSB. */ @@ -20,5 +28,13 @@ #define SECRETS_TYPE_WIREGUARD 0x57474b4c /* WireGuard Key Log */ #define SECRETS_TYPE_ZIGBEE_NWK_KEY 0x5a4e574b /* Zigbee NWK Key */ #define SECRETS_TYPE_ZIGBEE_APS_KEY 0x5a415053 /* Zigbee APS Key */ +#define SECRETS_TYPE_OPCUA 0x55414b4c /* OPC UA Key Log */ + +WS_DLL_PUBLIC +const char* secrets_type_description(uint32_t type); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ #endif /* __SECRETS_TYPES_H__ */ diff --git a/wiretap/snoop.c b/wiretap/snoop.c index 8621be6e..3db70920 100644 --- a/wiretap/snoop.c +++ b/wiretap/snoop.c @@ -7,18 +7,19 @@ */ #include "config.h" +#include "snoop.h" + #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" #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. */ typedef struct { - gboolean is_shomiti; + bool is_shomiti; } snoop_t; /* Magic number in "snoop" files. */ @@ -28,27 +29,27 @@ static const char snoop_magic[] = { /* "snoop" file header (minus magic number). */ struct snoop_hdr { - guint32 version; /* version number (should be 2) */ - guint32 network; /* network type */ + uint32_t version; /* version number (should be 2) */ + uint32_t network; /* network type */ }; /* "snoop" record header. */ struct snooprec_hdr { - guint32 orig_len; /* actual length of packet */ - guint32 incl_len; /* number of octets captured in file */ - guint32 rec_len; /* length of record */ - guint32 cum_drops; /* cumulative number of dropped packets */ - guint32 ts_sec; /* timestamp seconds */ - guint32 ts_usec; /* timestamp microseconds */ + uint32_t orig_len; /* actual length of packet */ + uint32_t incl_len; /* number of octets captured in file */ + uint32_t rec_len; /* length of record */ + uint32_t cum_drops; /* cumulative number of dropped packets */ + uint32_t ts_sec; /* timestamp seconds */ + uint32_t ts_usec; /* timestamp microseconds */ }; /* * The link-layer header on ATM packets. */ struct snoop_atm_hdr { - guint8 flags; /* destination and traffic type */ - guint8 vpi; /* VPI */ - guint16 vci; /* VCI */ + uint8_t flags; /* destination and traffic type */ + uint8_t vpi; /* VPI */ + uint16_t vci; /* VCI */ }; /* @@ -56,11 +57,11 @@ struct snoop_atm_hdr { * captures. */ struct shomiti_trailer { - guint16 phy_rx_length; /* length on the wire, including FCS? */ - guint16 phy_rx_status; /* status flags */ - guint32 ts_40_ns_lsb; /* 40 ns time stamp, low-order bytes? */ - guint32 ts_40_ns_msb; /* 40 ns time stamp, low-order bytes? */ - gint32 frame_id; /* "FrameID"? */ + uint16_t phy_rx_length; /* length on the wire, including FCS? */ + uint16_t phy_rx_status; /* status flags */ + uint32_t ts_40_ns_lsb; /* 40 ns time stamp, low-order bytes? */ + uint32_t ts_40_ns_msb; /* 40 ns time stamp, low-order bytes? */ + int32_t frame_id; /* "FrameID"? */ }; /* @@ -77,19 +78,19 @@ struct shomiti_trailer { #define RX_STATUS_FIFO_ERROR 0x0080 /* receive FIFO error */ #define RX_STATUS_TRIGGERED 0x0001 /* frame did trigger */ -static gboolean snoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean snoop_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +static bool snoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool snoop_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); static int snoop_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); -static gboolean snoop_read_atm_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); -static gboolean snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info, + Buffer *buf, int *err, char **err_info); +static bool snoop_read_atm_pseudoheader(FILE_T fh, + union wtap_pseudo_header *pseudo_header, int *err, char **err_info); +static bool snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, + union wtap_pseudo_header *pseudo_header, int *err, char **err_info, int *header_size); -static gboolean snoop_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); +static bool snoop_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); static int snoop_file_type_subtype = -1; static int shomiti_file_type_subtype = -1; @@ -175,13 +176,13 @@ void register_snoop(void); * 4MB from 16MB Token Ring, and distinguishing both of them from the * "Shomiti" versions of same. */ -wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val snoop_open(wtap *wth, int *err, char **err_info) { char magic[sizeof snoop_magic]; struct snoop_hdr hdr; struct snooprec_hdr rec_hdr; - guint padbytes; - gboolean is_shomiti; + unsigned padbytes; + bool is_shomiti; static const int snoop_encap[] = { WTAP_ENCAP_ETHERNET, /* IEEE 802.3 */ WTAP_ENCAP_UNKNOWN, /* IEEE 802.4 Token Bus */ @@ -211,7 +212,7 @@ wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info) WTAP_ENCAP_UNKNOWN, /* 100BaseT (but that's just Ethernet) */ WTAP_ENCAP_IP_OVER_IB_SNOOP, /* Infiniband */ }; - #define NUM_SNOOP_ENCAPS (sizeof snoop_encap / sizeof snoop_encap[0]) + #define NUM_SNOOP_ENCAPS array_length(snoop_encap) #define SNOOP_PRIVATE_BIT 0x80000000 static const int snoop_private_encap[] = { WTAP_ENCAP_UNKNOWN, /* Not Used */ @@ -223,7 +224,7 @@ wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info) WTAP_ENCAP_UNKNOWN, /* IPMP stub interface */ WTAP_ENCAP_UNKNOWN, /* 6to4 Tunnel Link */ }; - #define NUM_SNOOP_PRIVATE_ENCAPS (sizeof snoop_private_encap / sizeof snoop_private_encap[0]) + #define NUM_SNOOP_PRIVATE_ENCAPS array_length(snoop_private_encap) static const int shomiti_encap[] = { WTAP_ENCAP_ETHERNET, /* IEEE 802.3 */ WTAP_ENCAP_UNKNOWN, /* IEEE 802.4 Token Bus */ @@ -246,9 +247,9 @@ wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info) WTAP_ENCAP_IEEE_802_11_WITH_RADIO, /* IEEE 802.11 with Radio Header */ WTAP_ENCAP_ETHERNET, /* 10 Gigabit Ethernet */ }; - #define NUM_SHOMITI_ENCAPS (sizeof shomiti_encap / sizeof shomiti_encap[0]) + #define NUM_SHOMITI_ENCAPS array_length(shomiti_encap) int file_encap; - gint64 saved_offset; + int64_t saved_offset; snoop_t *snoop; /* Read in the string that should be at the start of a "snoop" file */ @@ -314,7 +315,7 @@ wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info) /* * Start out assuming it's not a Shomiti capture. */ - is_shomiti = FALSE; + is_shomiti = false; /* Read first record header. */ saved_offset = file_tell(wth->fh); @@ -348,7 +349,7 @@ wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info) * Well, we have padding; how much? */ padbytes = g_ntohl(rec_hdr.rec_len) - - ((guint)sizeof rec_hdr + g_ntohl(rec_hdr.incl_len)); + ((unsigned)sizeof rec_hdr + g_ntohl(rec_hdr.incl_len)); /* * Is it at least the size of a Shomiti trailer? @@ -443,20 +444,20 @@ wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info) * If the header is longer than 8 bytes, what are the other fields? */ typedef struct { - guint8 pad[4]; - guint8 undecrypt[2]; - guint8 rate; - guint8 preamble; - guint8 code; - guint8 signal; - guint8 qual; - guint8 channel; + uint8_t pad[4]; + uint8_t undecrypt[2]; + uint8_t rate; + uint8_t preamble; + uint8_t code; + uint8_t signal; + uint8_t qual; + uint8_t channel; } shomiti_wireless_header; /* Read the next packet */ -static gboolean snoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool snoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { int padbytes; @@ -464,43 +465,43 @@ static gboolean snoop_read(wtap *wth, wtap_rec *rec, Buffer *buf, padbytes = snoop_read_packet(wth, wth->fh, rec, buf, err, err_info); if (padbytes == -1) - return FALSE; + return false; /* * Skip over the padding, if any. */ if (padbytes != 0) { if (!wtap_read_bytes(wth->fh, NULL, padbytes, err, err_info)) - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean -snoop_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +snoop_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; if (snoop_read_packet(wth, wth->random_fh, rec, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } static int snoop_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { snoop_t *snoop = (snoop_t *)wth->priv; struct snooprec_hdr hdr; - guint32 rec_size; - guint32 packet_size; - guint32 orig_size; + uint32_t rec_size; + uint32_t packet_size; + uint32_t orig_size; int header_size; /* Read record header. */ @@ -566,9 +567,9 @@ snoop_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, /* * Don't count the pseudo-header as part of the packet. */ - rec_size -= (guint32)sizeof (struct snoop_atm_hdr); - orig_size -= (guint32)sizeof (struct snoop_atm_hdr); - packet_size -= (guint32)sizeof (struct snoop_atm_hdr); + rec_size -= (uint32_t)sizeof (struct snoop_atm_hdr); + orig_size -= (uint32_t)sizeof (struct snoop_atm_hdr); + packet_size -= (uint32_t)sizeof (struct snoop_atm_hdr); break; case WTAP_ENCAP_ETHERNET: @@ -640,19 +641,19 @@ snoop_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, atm_guess_lane_type(rec, ws_buffer_start_ptr(buf)); } - return rec_size - ((guint)sizeof hdr + packet_size); + return rec_size - ((unsigned)sizeof hdr + packet_size); } -static gboolean +static bool snoop_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, - int *err, gchar **err_info) + int *err, char **err_info) { struct snoop_atm_hdr atm_phdr; - guint8 vpi; - guint16 vci; + uint8_t vpi; + uint16_t vci; if (!wtap_read_bytes(fh, &atm_phdr, sizeof atm_phdr, err, err_info)) - return FALSE; + return false; vpi = atm_phdr.vpi; vci = pntoh16(&atm_phdr.vci); @@ -726,19 +727,19 @@ snoop_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, pseudo_header->atm.aal5t_len = 0; pseudo_header->atm.aal5t_chksum = 0; - return TRUE; + return true; } -static gboolean +static bool snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info, + union wtap_pseudo_header *pseudo_header, int *err, char **err_info, int *header_size) { shomiti_wireless_header whdr; int rsize; if (!wtap_read_bytes(fh, &whdr, sizeof whdr, err, err_info)) - return FALSE; + return false; /* the 4th byte of the pad is actually a header length, * we've already read 8 bytes of it, and it must never @@ -752,23 +753,23 @@ snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("snoop: Header length in Surveyor record is %u, less than minimum of 8", whdr.pad[3]); - return FALSE; + return false; } /* Skip the header. */ rsize = ((int) whdr.pad[3]) - 8; if (!wtap_read_bytes(fh, NULL, rsize, err, err_info)) - return FALSE; + return false; memset(&pseudo_header->ieee_802_11, 0, sizeof(pseudo_header->ieee_802_11)); pseudo_header->ieee_802_11.fcs_len = 4; - pseudo_header->ieee_802_11.decrypted = FALSE; - pseudo_header->ieee_802_11.datapad = FALSE; + pseudo_header->ieee_802_11.decrypted = false; + pseudo_header->ieee_802_11.datapad = false; pseudo_header->ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; - pseudo_header->ieee_802_11.has_channel = TRUE; + pseudo_header->ieee_802_11.has_channel = true; pseudo_header->ieee_802_11.channel = whdr.channel; - pseudo_header->ieee_802_11.has_data_rate = TRUE; + pseudo_header->ieee_802_11.has_data_rate = true; pseudo_header->ieee_802_11.data_rate = whdr.rate; - pseudo_header->ieee_802_11.has_signal_percent = TRUE; + pseudo_header->ieee_802_11.has_signal_percent = true; pseudo_header->ieee_802_11.signal_percent = whdr.signal; /* @@ -778,25 +779,25 @@ snoop_read_shomiti_wireless_pseudoheader(FILE_T fh, if (RATE_IS_DSSS(pseudo_header->ieee_802_11.data_rate)) { /* 11b */ pseudo_header->ieee_802_11.phy = PHDR_802_11_PHY_11B; - pseudo_header->ieee_802_11.phy_info.info_11b.has_short_preamble = FALSE; + pseudo_header->ieee_802_11.phy_info.info_11b.has_short_preamble = false; } else if (RATE_IS_OFDM(pseudo_header->ieee_802_11.data_rate)) { /* 11a or 11g, depending on the band. */ if (CHAN_IS_BG(pseudo_header->ieee_802_11.channel)) { /* 11g */ pseudo_header->ieee_802_11.phy = PHDR_802_11_PHY_11G; - pseudo_header->ieee_802_11.phy_info.info_11g.has_mode = FALSE; + pseudo_header->ieee_802_11.phy_info.info_11g.has_mode = false; } else { /* 11a */ pseudo_header->ieee_802_11.phy = PHDR_802_11_PHY_11A; - pseudo_header->ieee_802_11.phy_info.info_11a.has_channel_type = FALSE; - pseudo_header->ieee_802_11.phy_info.info_11a.has_turbo_type = FALSE; + pseudo_header->ieee_802_11.phy_info.info_11a.has_channel_type = false; + pseudo_header->ieee_802_11.phy_info.info_11a.has_turbo_type = false; } } /* add back the header and don't forget the pad as well */ *header_size = rsize + 8 + 4; - return TRUE; + return true; } static const int wtap_encap[] = { @@ -815,7 +816,7 @@ static const int wtap_encap[] = { -1, /* WTAP_ENCAP_LAPB -> unsupported*/ 0x12, /* WTAP_ENCAP_ATM_PDUS -> DL_IPATM */ }; -#define NUM_WTAP_ENCAPS (sizeof wtap_encap / sizeof wtap_encap[0]) +#define NUM_WTAP_ENCAPS array_length(wtap_encap) /* Returns 0 if we could write the specified encapsulation type, an error indication otherwise. */ @@ -831,9 +832,9 @@ static int snoop_dump_can_write_encap(int encap) return 0; } -/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on +/* Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean snoop_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool snoop_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { struct snoop_hdr file_hdr; @@ -842,27 +843,27 @@ static gboolean snoop_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_ /* Write the file header. */ if (!wtap_dump_file_write(wdh, &snoop_magic, sizeof snoop_magic, err)) - return FALSE; + return false; /* current "snoop" format is 2 */ file_hdr.version = g_htonl(2); file_hdr.network = g_htonl(wtap_encap[wdh->file_encap]); if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err)) - return FALSE; + return false; - return TRUE; + return true; } /* Write a record for a packet to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean snoop_dump(wtap_dumper *wdh, + Returns true on success, false on failure. */ +static bool snoop_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + const uint8_t *pd, int *err, char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct snooprec_hdr rec_hdr; int reclen; - guint padlen; + unsigned padlen; static const char zeroes[4] = {0}; struct snoop_atm_hdr atm_hdr; int atm_hdrsize; @@ -870,7 +871,7 @@ static gboolean snoop_dump(wtap_dumper *wdh, /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -879,7 +880,7 @@ static gboolean snoop_dump(wtap_dumper *wdh, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } if (wdh->file_encap == WTAP_ENCAP_ATM_PDUS) @@ -898,7 +899,7 @@ static gboolean snoop_dump(wtap_dumper *wdh, /* Don't write anything we're not willing to read. */ if (rec->rec_header.packet_header.caplen + atm_hdrsize > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } rec_hdr.orig_len = g_htonl(rec->rec_header.packet_header.len + atm_hdrsize); @@ -908,7 +909,7 @@ static gboolean snoop_dump(wtap_dumper *wdh, rec_hdr.ts_sec = g_htonl(rec->ts.secs); rec_hdr.ts_usec = g_htonl(rec->ts.nsecs / 1000); if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof rec_hdr, err)) - return FALSE; + return false; if (wdh->file_encap == WTAP_ENCAP_ATM_PDUS) { /* @@ -943,19 +944,19 @@ static gboolean snoop_dump(wtap_dumper *wdh, } break; } - atm_hdr.vpi = (guint8) pseudo_header->atm.vpi; + atm_hdr.vpi = (uint8_t) pseudo_header->atm.vpi; atm_hdr.vci = g_htons(pseudo_header->atm.vci); if (!wtap_dump_file_write(wdh, &atm_hdr, sizeof atm_hdr, err)) - return FALSE; + return false; } if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; /* Now write the padding. */ if (!wtap_dump_file_write(wdh, zeroes, padlen, err)) - return FALSE; - return TRUE; + return false; + return true; } static const struct supported_block_type snoop_blocks_supported[] = { @@ -967,7 +968,7 @@ static const struct supported_block_type snoop_blocks_supported[] = { static const struct file_type_subtype_info snoop_info = { "Sun snoop", "snoop", "snoop", "cap", - FALSE, BLOCKS_SUPPORTED(snoop_blocks_supported), + false, BLOCKS_SUPPORTED(snoop_blocks_supported), snoop_dump_can_write_encap, snoop_dump_open, NULL }; @@ -980,7 +981,7 @@ static const struct supported_block_type shomiti_blocks_supported[] = { static const struct file_type_subtype_info shomiti_info = { "Shomiti/Finisar Surveyor", "shomiti", "cap", NULL, - FALSE, BLOCKS_SUPPORTED(shomiti_blocks_supported), + false, BLOCKS_SUPPORTED(shomiti_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/snoop.h b/wiretap/snoop.h index 746764d9..b083eea9 100644 --- a/wiretap/snoop.h +++ b/wiretap/snoop.h @@ -13,6 +13,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val snoop_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/socketcan.h b/wiretap/socketcan.h index f864ca3f..9daf2c98 100644 --- a/wiretap/socketcan.h +++ b/wiretap/socketcan.h @@ -18,21 +18,21 @@ #define CANFD_MAX_DLEN 64 typedef struct can_frame { - guint32 can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ - guint8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ - guint8 __pad; /* padding */ - guint8 __res0; /* reserved / padding */ - guint8 __res1; /* reserved / padding */ - guint8 data[CAN_MAX_DLEN]; + uint32_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ + uint8_t can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ + uint8_t __pad; /* padding */ + uint8_t __res0; /* reserved / padding */ + uint8_t __res1; /* reserved / padding */ + uint8_t data[CAN_MAX_DLEN]; } can_frame_t; typedef struct canfd_frame { - guint32 can_id; /* 32 bit CAN_ID + EFF flag */ - guint8 len; /* frame payload length in byte */ - guint8 flags; /* additional flags for CAN FD */ - guint8 __res0; /* reserved / padding */ - guint8 __res1; /* reserved / padding */ - guint8 data[CANFD_MAX_DLEN]; + uint32_t can_id; /* 32 bit CAN_ID + EFF flag */ + uint8_t len; /* frame payload length in byte */ + uint8_t flags; /* additional flags for CAN FD */ + uint8_t __res0; /* reserved / padding */ + uint8_t __res1; /* reserved / padding */ + uint8_t data[CANFD_MAX_DLEN]; } canfd_frame_t; #endif /* SOCKETCAN_H__ */ diff --git a/wiretap/stanag4607.c b/wiretap/stanag4607.c index 0b2f2bff..40a370f8 100644 --- a/wiretap/stanag4607.c +++ b/wiretap/stanag4607.c @@ -14,11 +14,11 @@ */ #include "config.h" +#include "stanag4607.h" #include "wtap-int.h" #include "file_wrappers.h" #include <wsutil/buffer.h> -#include "stanag4607.h" typedef struct { time_t base_secs; @@ -31,37 +31,37 @@ static int stanag4607_file_type_subtype = -1; void register_stanag4607(void); -static gboolean is_valid_id(guint16 version_id) +static bool is_valid_id(uint16_t version_id) { #define VERSION_21 0x3231 #define VERSION_30 0x3330 if ((version_id != VERSION_21) && (version_id != VERSION_30)) /* Not a stanag4607 file */ - return FALSE; - return TRUE; + return false; + return true; } -static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { stanag4607_t *stanag4607 = (stanag4607_t *)wth->priv; - guint32 millisecs, secs, nsecs; - gint64 offset = 0; - guint8 stanag_pkt_hdr[PKT_HDR_SIZE+SEG_HDR_SIZE]; - guint32 packet_size; + uint32_t millisecs, secs, nsecs; + int64_t offset = 0; + uint8_t stanag_pkt_hdr[PKT_HDR_SIZE+SEG_HDR_SIZE]; + uint32_t packet_size; *err = 0; /* Combined packet header and segment header */ if (!wtap_read_bytes_or_eof(fh, stanag_pkt_hdr, sizeof stanag_pkt_hdr, err, err_info)) - return FALSE; + return false; offset += sizeof stanag_pkt_hdr; if (!is_valid_id(pntoh16(&stanag_pkt_hdr[0]))) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Bad version number"); - return FALSE; + return false; } rec->rec_type = REC_TYPE_PACKET; @@ -77,7 +77,7 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("stanag4607: File has %" PRIu32 "d-byte packet, " "bigger than maximum of %u", packet_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } if (packet_size < PKT_HDR_SIZE+SEG_HDR_SIZE) { /* @@ -87,7 +87,7 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("stanag4607: File has %" PRIu32 "d-byte packet, " "smaller than minimum of %u", packet_size, PKT_HDR_SIZE+SEG_HDR_SIZE); - return FALSE; + return false; } rec->rec_header.packet_header.caplen = packet_size; rec->rec_header.packet_header.len = packet_size; @@ -106,11 +106,11 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, #define JOB_DEFINITION_SEGMENT 5 #define PLATFORM_LOCATION_SEGMENT 13 if (MISSION_SEGMENT == stanag_pkt_hdr[32]) { - guint8 mseg[39]; + uint8_t mseg[39]; struct tm tm; if (!wtap_read_bytes(fh, &mseg, sizeof mseg, err, err_info)) - return FALSE; + return false; offset += sizeof mseg; tm.tm_year = pntoh16(&mseg[35]) - 1900; @@ -125,14 +125,14 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, } else if (PLATFORM_LOCATION_SEGMENT == stanag_pkt_hdr[32]) { if (!wtap_read_bytes(fh, &millisecs, sizeof millisecs, err, err_info)) - return FALSE; + return false; offset += sizeof millisecs; millisecs = g_ntohl(millisecs); } else if (DWELL_SEGMENT == stanag_pkt_hdr[32]) { - guint8 dseg[19]; + uint8_t dseg[19]; if (!wtap_read_bytes(fh, &dseg, sizeof dseg, err, err_info)) - return FALSE; + return false; offset += sizeof dseg; millisecs = pntoh32(&dseg[15]); } @@ -145,32 +145,32 @@ static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, /* wind back to the start of the packet ... */ if (file_seek(fh, - offset, SEEK_CUR, err) == -1) - return FALSE; + return false; return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static gboolean stanag4607_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool stanag4607_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); return stanag4607_read_file(wth, wth->fh, rec, buf, err, err_info); } -static gboolean stanag4607_seek_read(wtap *wth, gint64 seek_off, +static bool stanag4607_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return stanag4607_read_file(wth, wth->random_fh, rec, buf, err, err_info); } -wtap_open_return_val stanag4607_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val stanag4607_open(wtap *wth, int *err, char **err_info) { - guint16 version_id; + uint16_t version_id; stanag4607_t *stanag4607; if (!wtap_read_bytes(wth->fh, &version_id, sizeof version_id, err, err_info)) @@ -216,7 +216,7 @@ static const struct supported_block_type stanag4607_blocks_supported[] = { static const struct file_type_subtype_info stanag4607_info = { "STANAG 4607 Format", "stanag4607", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(stanag4607_blocks_supported), + false, BLOCKS_SUPPORTED(stanag4607_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/stanag4607.h b/wiretap/stanag4607.h index 1d322b88..44d894ed 100644 --- a/wiretap/stanag4607.h +++ b/wiretap/stanag4607.h @@ -13,6 +13,6 @@ #include <wiretap/wtap.h> #include "ws_symbol_export.h" -wtap_open_return_val stanag4607_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val stanag4607_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/systemd_journal.c b/wiretap/systemd_journal.c index 1cce5e59..2a0fab95 100644 --- a/wiretap/systemd_journal.c +++ b/wiretap/systemd_journal.c @@ -7,6 +7,7 @@ */ #include "config.h" +#include "systemd_journal.h" #include <errno.h> #include <string.h> @@ -14,7 +15,6 @@ #include "wtap-int.h" #include "pcapng_module.h" #include "file_wrappers.h" -#include "systemd_journal.h" // To do: // - Request a pcap encapsulation type. @@ -41,12 +41,12 @@ // SYSLOG_IDENTIFIER=kernel // MESSAGE=Initializing cgroup subsys cpuset -static gboolean systemd_journal_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean systemd_journal_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); +static bool systemd_journal_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool systemd_journal_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info); // The Journal Export Format specification doesn't place limits on entry // lengths or lines per entry. We do. @@ -66,13 +66,13 @@ static int systemd_journal_file_type_subtype = -1; void register_systemd_journal(void); -wtap_open_return_val systemd_journal_open(wtap *wth, int *err _U_, gchar **err_info _U_) +wtap_open_return_val systemd_journal_open(wtap *wth, int *err _U_, char **err_info _U_) { - gchar *entry_buff = (gchar*) g_malloc(MAX_EXPORT_ENTRY_LENGTH); - gchar *entry_line = NULL; - gboolean got_cursor = FALSE; - gboolean got_rt_ts = FALSE; - gboolean got_mt_ts = FALSE; + char *entry_buff = (char*) g_malloc(MAX_EXPORT_ENTRY_LENGTH); + char *entry_line = NULL; + bool got_cursor = false; + bool got_rt_ts = false; + bool got_mt_ts = false; int line_num; errno = 0; @@ -84,11 +84,11 @@ wtap_open_return_val systemd_journal_open(wtap *wth, int *err _U_, gchar **err_i if (entry_line[0] == '\n') { break; } else if (strncmp(entry_line, FLD__CURSOR, strlen(FLD__CURSOR)) == 0) { - got_cursor = TRUE; + got_cursor = true; } else if (strncmp(entry_line, FLD__REALTIME_TIMESTAMP, strlen(FLD__REALTIME_TIMESTAMP)) == 0) { - got_rt_ts = TRUE; + got_rt_ts = true; } else if (strncmp(entry_line, FLD__MONOTONIC_TIMESTAMP, strlen(FLD__MONOTONIC_TIMESTAMP)) == 0) { - got_mt_ts = TRUE; + got_mt_ts = true; } } g_free(entry_buff); @@ -119,27 +119,27 @@ wtap_open_return_val systemd_journal_open(wtap *wth, int *err _U_, gchar **err_i } /* Read the next packet */ -static gboolean systemd_journal_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool systemd_journal_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { *data_offset = file_tell(wth->fh); /* Read record. */ if (!systemd_journal_read_export_entry(wth->fh, rec, buf, err, err_info)) { /* Read error or EOF */ - return FALSE; + return false; } - return TRUE; + return true; } - static gboolean -systemd_journal_seek_read(wtap *wth, gint64 seek_off, + static bool +systemd_journal_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, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read record. */ if (!systemd_journal_read_export_entry(wth->random_fh, rec, buf, err, err_info)) { @@ -148,26 +148,26 @@ systemd_journal_seek_read(wtap *wth, gint64 seek_off, /* EOF means "short read" in random-access mode */ *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean -systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { size_t fld_end = 0; - gchar *buf_ptr; - gchar *entry_line = NULL; - gboolean got_cursor = FALSE; - gboolean got_rt_ts = FALSE; - gboolean got_mt_ts = FALSE; - gboolean got_double_newline = FALSE; + char *buf_ptr; + char *entry_line = NULL; + bool got_cursor = false; + bool got_rt_ts = false; + bool got_mt_ts = false; + bool got_double_newline = false; int line_num; size_t rt_ts_len = strlen(FLD__REALTIME_TIMESTAMP); ws_buffer_assure_space(buf, MAX_EXPORT_ENTRY_LENGTH); - buf_ptr = (gchar *) ws_buffer_start_ptr(buf); + buf_ptr = (char *) ws_buffer_start_ptr(buf); for (line_num = 0; line_num < MAX_EXPORT_ENTRY_LINES; line_num++) { entry_line = file_gets(buf_ptr + fld_end, MAX_EXPORT_ENTRY_LENGTH - (int) fld_end, fh); @@ -176,10 +176,10 @@ systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, Buffer *buf, int *er } fld_end += strlen(entry_line); if (entry_line[0] == '\n') { - got_double_newline = TRUE; + got_double_newline = true; break; } else if (strncmp(entry_line, FLD__CURSOR, strlen(FLD__CURSOR)) == 0) { - got_cursor = TRUE; + got_cursor = true; } else if (strncmp(entry_line, FLD__REALTIME_TIMESTAMP, rt_ts_len) == 0) { errno = 0; unsigned long rt_ts = strtoul(entry_line+rt_ts_len, NULL, 10); @@ -187,20 +187,20 @@ systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, Buffer *buf, int *er rec->ts.secs = (time_t) rt_ts / 1000000; rec->ts.nsecs = (rt_ts % 1000000) * 1000; rec->tsprec = WTAP_TSPREC_USEC; - got_rt_ts = TRUE; + got_rt_ts = true; } } else if (strncmp(entry_line, FLD__MONOTONIC_TIMESTAMP, strlen(FLD__MONOTONIC_TIMESTAMP)) == 0) { - got_mt_ts = TRUE; + got_mt_ts = true; } else if (!strstr(entry_line, "=")) { // Start of binary data. if (fld_end >= MAX_EXPORT_ENTRY_LENGTH - 8) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("systemd: binary length too long"); - return FALSE; + return false; } - guint64 data_len, le_data_len; + uint64_t data_len, le_data_len; if (!wtap_read_bytes(fh, &le_data_len, 8, err, err_info)) { - return FALSE; + return false; } memcpy(buf_ptr + fld_end, &le_data_len, 8); fld_end += 8; @@ -208,11 +208,11 @@ systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, Buffer *buf, int *er if (data_len < 1 || data_len - 1 >= MAX_EXPORT_ENTRY_LENGTH - fld_end) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("systemd: binary data too long"); - return FALSE; + return false; } // Data + trailing \n if (!wtap_read_bytes(fh, buf_ptr + fld_end, (unsigned) data_len + 1, err, err_info)) { - return FALSE; + return false; } fld_end += (size_t) data_len + 1; } @@ -222,19 +222,19 @@ systemd_journal_read_export_entry(FILE_T fh, wtap_rec *rec, Buffer *buf, int *er } if (!got_cursor || !got_rt_ts || !got_mt_ts) { - return FALSE; + return false; } if (!got_double_newline && !file_eof(fh)) { - return FALSE; + return false; } rec->rec_type = REC_TYPE_SYSTEMD_JOURNAL_EXPORT; rec->block = wtap_block_create(WTAP_BLOCK_SYSTEMD_JOURNAL_EXPORT); rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - rec->rec_header.systemd_journal_export_header.record_len = (guint32) fld_end; + rec->rec_header.systemd_journal_export_header.record_len = (uint32_t) fld_end; - return TRUE; + return true; } static const struct supported_block_type systemd_journal_blocks_supported[] = { @@ -246,7 +246,7 @@ static const struct supported_block_type systemd_journal_blocks_supported[] = { static const struct file_type_subtype_info systemd_journal_info = { "systemd journal export", "systemd_journal", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(systemd_journal_blocks_supported), + false, BLOCKS_SUPPORTED(systemd_journal_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/systemd_journal.h b/wiretap/systemd_journal.h index 0a34c66c..d68e9e00 100644 --- a/wiretap/systemd_journal.h +++ b/wiretap/systemd_journal.h @@ -14,6 +14,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val systemd_journal_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val systemd_journal_open(wtap *wth, int *err, char **err_info); #endif // __SYSTEMD_JOURNAL_H__ diff --git a/wiretap/tnef.c b/wiretap/tnef.c index a7b17c3a..af418083 100644 --- a/wiretap/tnef.c +++ b/wiretap/tnef.c @@ -6,19 +6,19 @@ */ #include "config.h" +#include "tnef.h" #include "wtap-int.h" #include "file_wrappers.h" #include <wsutil/buffer.h> -#include "tnef.h" static int tnef_file_type_subtype = -1; void register_tnef(void); -wtap_open_return_val tnef_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val tnef_open(wtap *wth, int *err, char **err_info) { - guint32 magic; + uint32_t magic; if (!wtap_read_bytes(wth->fh, &magic, sizeof magic, err, err_info)) return (*err != WTAP_ERR_SHORT_READ) ? WTAP_OPEN_ERROR : WTAP_OPEN_NOT_MINE; @@ -53,7 +53,7 @@ static const struct supported_block_type tnef_blocks_supported[] = { static const struct file_type_subtype_info tnef_info = { "Transport-Neutral Encapsulation Format", "tnef", NULL, NULL, - FALSE, BLOCKS_SUPPORTED(tnef_blocks_supported), + false, BLOCKS_SUPPORTED(tnef_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/tnef.h b/wiretap/tnef.h index 21873d14..46a9b2d8 100644 --- a/wiretap/tnef.h +++ b/wiretap/tnef.h @@ -15,6 +15,6 @@ #define TNEF_SIGNATURE 0x223E9F78 -wtap_open_return_val tnef_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val tnef_open(wtap *wth, int *err, char **err_info); #endif 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 }; diff --git a/wiretap/toshiba.h b/wiretap/toshiba.h index 9fe96df9..86d20738 100644 --- a/wiretap/toshiba.h +++ b/wiretap/toshiba.h @@ -13,6 +13,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -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); #endif diff --git a/wiretap/visual.c b/wiretap/visual.c index 684a6a2e..afff6cc9 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -9,10 +9,11 @@ */ #include "config.h" +#include "visual.h" + #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "visual.h" /* * A Visual Networks traffic capture file contains three sections. The @@ -50,15 +51,15 @@ static const char visual_magic[] = { /* This structure is used to extract information */ struct visual_file_hdr { - guint32 num_pkts; /* Number of packets in the file */ - guint32 start_time; /* Capture start time in PC format */ - guint16 media_type; /* IANA ifType of packet source */ - guint16 max_length; /* Max allowable stored packet length */ - guint16 file_flags; /* File type flags */ + uint32_t num_pkts; /* Number of packets in the file */ + uint32_t start_time; /* Capture start time in PC format */ + uint16_t media_type; /* IANA ifType of packet source */ + uint16_t max_length; /* Max allowable stored packet length */ + uint16_t file_flags; /* File type flags */ /* Bit 0 indicates indexes present */ - guint16 file_version; /* Version number of this file format */ - guint32 media_speed; /* ifSpeed of packet source in bits/sec. */ - guint16 media_param; /* Media-specific extra parameter. */ + uint16_t file_version; /* Version number of this file format */ + uint32_t media_speed; /* ifSpeed of packet source in bits/sec. */ + uint16_t media_param; /* Media-specific extra parameter. */ char RESERVED_[102]; /* MUST BE ALL ZEROS FOR FUTURE COMPATIBILITY */ char description[64]; /* File description (null terminated) */ }; @@ -77,12 +78,12 @@ struct visual_file_hdr /* This structure is used to extract information */ struct visual_pkt_hdr { - guint32 ts_delta; /* Time stamp - msecs since start of capture */ - guint16 orig_len; /* Actual length of packet */ - guint16 incl_len; /* Number of octets captured in file */ - guint32 status; /* Packet status flags (media specific) */ - guint8 encap_hint; /* Encapsulation type hint */ - guint8 encap_skip; /* Number of bytes to skip before decoding */ + uint32_t ts_delta; /* Time stamp - msecs since start of capture */ + uint16_t orig_len; /* Actual length of packet */ + uint16_t incl_len; /* Number of octets captured in file */ + uint32_t status; /* Packet status flags (media specific) */ + uint8_t encap_hint; /* Encapsulation type hint */ + uint8_t encap_skip; /* Number of bytes to skip before decoding */ char RESERVED_[6]; /* RESERVED - must be zero */ }; @@ -90,14 +91,14 @@ struct visual_pkt_hdr /* This structure is used to extract information */ struct visual_atm_hdr { - guint16 vpi; /* 4 bits of zeros; 12 bits of ATM VPI */ - guint16 vci; /* ATM VCI */ - guint8 info; /* 4 bits version; 3 bits unused-zero; 1 bit direction */ - guint8 category; /* indicates type of traffic. 4 bits of status + 4 bits of type */ - guint16 cell_count; /* number of cells that make up this pdu */ - guint32 data_length; /* PDU data length for AAL-5 PDUs, all others - cellcount * 48 */ - guint32 ts_secs; /* seonds value of sysUpTime when the last cell of this PDU was captured */ - guint32 ts_nsec; /* nanoseonds value of sysUpTime when the last cell of this PDU was captured */ + uint16_t vpi; /* 4 bits of zeros; 12 bits of ATM VPI */ + uint16_t vci; /* ATM VCI */ + uint8_t info; /* 4 bits version; 3 bits unused-zero; 1 bit direction */ + uint8_t category; /* indicates type of traffic. 4 bits of status + 4 bits of type */ + uint16_t cell_count; /* number of cells that make up this pdu */ + uint32_t data_length; /* PDU data length for AAL-5 PDUs, all others - cellcount * 48 */ + uint32_t ts_secs; /* seconds value of sysUpTime when the last cell of this PDU was captured */ + uint32_t ts_nsec; /* nanoseconds value of sysUpTime when the last cell of this PDU was captured */ }; @@ -126,8 +127,8 @@ struct visual_atm_hdr /* Additional information for reading Visual files */ struct visual_read_info { - guint32 num_pkts; /* Number of pkts in the file */ - guint32 current_pkt; /* Next packet to be read */ + uint32_t num_pkts; /* Number of pkts in the file */ + uint32_t current_pkt; /* Next packet to be read */ time_t start_time; /* Capture start time in seconds */ }; @@ -135,25 +136,25 @@ struct visual_read_info /* Additional information for writing Visual files */ struct visual_write_info { - guint32 start_time; /* Capture start time in seconds */ + uint32_t start_time; /* Capture start time in seconds */ int index_table_index; /* Index of the next index entry */ int index_table_size; /* Allocated size of the index table */ - guint32 * index_table; /* File offsets for the packets */ - guint32 next_offset; /* Offset of next packet */ + uint32_t * index_table; /* File offsets for the packets */ + uint32_t next_offset; /* Offset of next packet */ }; /* Local functions to handle file reads and writes */ -static gboolean visual_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean visual_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean visual_read_packet(wtap *wth, FILE_T fh, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); -static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gboolean visual_dump_finish(wtap_dumper *wdh, int *err, - gchar **err_info); +static bool visual_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool visual_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool visual_read_packet(wtap *wth, FILE_T fh, + wtap_rec *rec, Buffer *buf, int *err, char **err_info); +static bool visual_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info); +static bool visual_dump_finish(wtap_dumper *wdh, int *err, + char **err_info); static void visual_dump_free(wtap_dumper *wdh); static int visual_file_type_subtype = -1; @@ -162,7 +163,7 @@ void register_visual(void); /* Open a file for reading */ -wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val visual_open(wtap *wth, int *err, char **err_info) { char magic[sizeof visual_magic]; struct visual_file_hdr vfile_hdr; @@ -271,8 +272,8 @@ wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info) in a loop to sequentially read the entire file one time. After the file has been read once, any Future access to the packets is done through seek_read. */ -static gboolean visual_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool visual_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { struct visual_read_info *visual = (struct visual_read_info *)wth->priv; @@ -282,7 +283,7 @@ static gboolean visual_read(wtap *wth, wtap_rec *rec, Buffer *buf, if (visual->current_pkt > visual->num_pkts) { *err = 0; /* it's just an EOF, not an error */ - return FALSE; + return false; } visual->current_pkt++; @@ -292,38 +293,38 @@ static gboolean visual_read(wtap *wth, wtap_rec *rec, Buffer *buf, } /* Read packet header and data for random access. */ -static gboolean visual_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool visual_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *rec, Buffer *buf, int *err, char **err_info) { /* Seek to the packet header */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* Read the packet. */ if (!visual_read_packet(wth, wth->random_fh, rec, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean +static bool visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) + Buffer *buf, int *err, char **err_info) { struct visual_read_info *visual = (struct visual_read_info *)wth->priv; struct visual_pkt_hdr vpkt_hdr; - guint32 packet_size; + uint32_t packet_size; struct visual_atm_hdr vatm_hdr; - guint32 relmsecs; - guint32 packet_status; - guint8 *pd; + uint32_t relmsecs; + uint32_t packet_status; + uint8_t *pd; /* Read the packet header. */ if (!wtap_read_bytes_or_eof(fh, &vpkt_hdr, (unsigned int)sizeof vpkt_hdr, err, err_info)) { - return FALSE; + return false; } /* Get the included length of data. This includes extra headers + payload */ @@ -370,7 +371,7 @@ visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("visual: Ethernet packet has %u-byte original packet, less than the FCS length", rec->rec_header.packet_header.len); - return FALSE; + return false; } rec->rec_header.packet_header.len -= 4; @@ -386,18 +387,18 @@ visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("visual: Cisco HDLC packet has %u-byte original packet, less than the FCS length", rec->rec_header.packet_header.len); - return FALSE; + return false; } rec->rec_header.packet_header.len -= 2; - rec->rec_header.packet_header.pseudo_header.p2p.sent = (packet_status & PS_SENT) ? TRUE : FALSE; + rec->rec_header.packet_header.pseudo_header.p2p.sent = (packet_status & PS_SENT) ? true : false; break; case WTAP_ENCAP_PPP_WITH_PHDR: /* No FCS. XXX - true? Note that PPP can negotiate no FCS, a 2-byte FCS, or a 4-byte FCS. */ - rec->rec_header.packet_header.pseudo_header.p2p.sent = (packet_status & PS_SENT) ? TRUE : FALSE; + rec->rec_header.packet_header.pseudo_header.p2p.sent = (packet_status & PS_SENT) ? true : false; break; case WTAP_ENCAP_FRELAY_WITH_PHDR: @@ -407,7 +408,7 @@ visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("visual: Frame Relay packet has %u-byte original packet, less than the FCS length", rec->rec_header.packet_header.len); - return FALSE; + return false; } rec->rec_header.packet_header.len -= 2; @@ -422,7 +423,7 @@ visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("visual: Frame Relay packet has %u-byte original packet, less than the FCS length", rec->rec_header.packet_header.len); - return FALSE; + return false; } rec->rec_header.packet_header.len -= 2; @@ -438,13 +439,13 @@ visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, process it. */ if (!wtap_read_bytes(fh, &vatm_hdr, (unsigned int)sizeof vatm_hdr, err, err_info)) { - return FALSE; + return false; } /* Remove ATM header from length of included bytes in capture, as this header was appended by the processor doing the packet reassembly, and was not transmitted across the wire */ - packet_size -= (guint32)sizeof vatm_hdr; + packet_size -= (uint32_t)sizeof vatm_hdr; /* Set defaults */ rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; @@ -518,12 +519,12 @@ visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("visual: File has %u-byte packet, bigger than maximum of %u", packet_size, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } /* Read the packet data */ if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) - return FALSE; + return false; if (wth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR) { @@ -574,7 +575,7 @@ visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, } } - return TRUE; + return true; } /* Check for media types that may be written in Visual file format. @@ -604,9 +605,9 @@ static int visual_dump_can_write_encap(int encap) /* Open a file for writing. - Returns TRUE on success, FALSE on failure; sets "*err" to an + Returns true on success, false on failure; sets "*err" to an error code on failure */ -static gboolean visual_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static bool visual_dump_open(wtap_dumper *wdh, int *err, char **err_info _U_) { struct visual_write_info *visual; @@ -627,28 +628,28 @@ static gboolean visual_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U just skip over it for now. It will be created after all of the packets have been written. */ if (wtap_dump_file_seek(wdh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1) - return FALSE; + return false; - return TRUE; + return true; } /* Write a packet to a Visual dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool visual_dump(wtap_dumper *wdh, const wtap_rec *rec, + const uint8_t *pd, int *err, char **err_info _U_) { const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; struct visual_write_info * visual = (struct visual_write_info *)wdh->priv; struct visual_pkt_hdr vpkt_hdr = {0}; size_t hdr_size = sizeof vpkt_hdr; - guint delta_msec; - guint32 packet_status; + unsigned delta_msec; + uint32_t packet_status; /* We can only write packet records. */ if (rec->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_UNWRITABLE_REC_TYPE; - return FALSE; + return false; } /* @@ -657,19 +658,19 @@ static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec, */ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; - return FALSE; + return false; } /* Don't write anything we're not willing to read. */ if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { *err = WTAP_ERR_PACKET_TOO_LARGE; - return FALSE; + return false; } /* If the visual structure was never allocated then nothing useful can be done. */ if (visual == 0) - return FALSE; + return false; /* Visual UpTime capture files have a capture start time in the file header. Each packet has a capture time (in msec) relative @@ -681,23 +682,23 @@ static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec, * This is the first packet. Save its start time as the file time. * * XXX - is the start time signed, or unsigned? If it's signed, - * in which case we should check against G_MININT32 and G_MAXINT32 - * and make start_time a gint32. + * in which case we should check against INT32_MIN and INT32_MAX + * and make start_time a int32_t. */ if (rec->ts.secs < 0 || rec->ts.secs > WTAP_NSTIME_32BIT_SECS_MAX) { *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; - return FALSE; + return false; } - visual->start_time = (guint32)rec->ts.secs; + visual->start_time = (uint32_t)rec->ts.secs; /* Initialize the index table */ - visual->index_table = (guint32 *)g_malloc(1024 * sizeof *visual->index_table); + visual->index_table = (uint32_t *)g_malloc(1024 * sizeof *visual->index_table); visual->index_table_size = 1024; } /* Calculate milliseconds since capture start. */ delta_msec = rec->ts.nsecs / 1000000; - delta_msec += (guint32)((rec->ts.secs - visual->start_time) * 1000); + delta_msec += (uint32_t)((rec->ts.secs - visual->start_time) * 1000); vpkt_hdr.ts_delta = GUINT32_TO_LE(delta_msec); /* Fill in the length fields. */ @@ -750,34 +751,34 @@ static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec, /* Write the packet header. */ if (!wtap_dump_file_write(wdh, &vpkt_hdr, hdr_size, err)) - return FALSE; + return false; /* Write the packet data */ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) - return FALSE; + return false; /* Store the frame offset in the index table. */ if (visual->index_table_index >= visual->index_table_size) { /* End of table reached. Reallocate with a larger size */ visual->index_table_size *= 2; - visual->index_table = (guint32 *)g_realloc(visual->index_table, + visual->index_table = (uint32_t *)g_realloc(visual->index_table, visual->index_table_size * sizeof *visual->index_table); } visual->index_table[visual->index_table_index] = GUINT32_TO_LE(visual->next_offset); /* Update the table index and offset for the next frame. */ visual->index_table_index++; - visual->next_offset += (guint32) hdr_size + rec->rec_header.packet_header.caplen; + visual->next_offset += (uint32_t) hdr_size + rec->rec_header.packet_header.caplen; - return TRUE; + return true; } /* Finish writing to a dump file. - Returns TRUE on success, FALSE on failure. */ -static gboolean visual_dump_finish(wtap_dumper *wdh, int *err, - gchar **err_info _U_) + Returns true on success, false on failure. */ +static bool visual_dump_finish(wtap_dumper *wdh, int *err, + char **err_info _U_) { struct visual_write_info * visual = (struct visual_write_info *)wdh->priv; size_t n_to_write; @@ -788,7 +789,7 @@ static gboolean visual_dump_finish(wtap_dumper *wdh, int *err, /* If the visual structure was never allocated then nothing useful can be done. */ if (visual == 0) - return FALSE; + return false; /* Write out the frame table at the end of the file. */ if (visual->index_table) @@ -798,19 +799,19 @@ static gboolean visual_dump_finish(wtap_dumper *wdh, int *err, if (!wtap_dump_file_write(wdh, visual->index_table, n_to_write, err)) { visual_dump_free(wdh); - return FALSE; + return false; } } /* Write the magic number at the start of the file. */ if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) - return FALSE; + return false; magicp = visual_magic; magic_size = sizeof visual_magic; if (!wtap_dump_file_write(wdh, magicp, magic_size, err)) { visual_dump_free(wdh); - return FALSE; + return false; } vfile_hdr.num_pkts = GUINT32_TO_LE(visual->index_table_index); @@ -850,12 +851,12 @@ static gboolean visual_dump_finish(wtap_dumper *wdh, int *err, if (!wtap_dump_file_write(wdh, &vfile_hdr, sizeof vfile_hdr, err)) { visual_dump_free(wdh); - return FALSE; + return false; } /* Deallocate the file write data */ visual_dump_free(wdh); - return TRUE; + return true; } @@ -880,7 +881,7 @@ static const struct supported_block_type visual_blocks_supported[] = { static const struct file_type_subtype_info visual_info = { "Visual Networks traffic capture", "visual", NULL, NULL, - TRUE, BLOCKS_SUPPORTED(visual_blocks_supported), + true, BLOCKS_SUPPORTED(visual_blocks_supported), visual_dump_can_write_encap, visual_dump_open, NULL }; diff --git a/wiretap/visual.h b/wiretap/visual.h index c88e62f7..8ddaec11 100644 --- a/wiretap/visual.h +++ b/wiretap/visual.h @@ -18,6 +18,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val visual_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/vms.c b/wiretap/vms.c index f591695b..27435586 100644 --- a/wiretap/vms.c +++ b/wiretap/vms.c @@ -14,8 +14,8 @@ * at the start of every packet. */ #include "config.h" -#include "wtap-int.h" #include "vms.h" +#include "wtap-int.h" #include "file_wrappers.h" #include <wsutil/strtoi.h> @@ -126,14 +126,14 @@ to handle them. #define VMS_HEADER_LINES_TO_CHECK 200 #define VMS_LINE_LENGTH 240 -static gboolean vms_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); -static gboolean vms_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, +static bool vms_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset); +static bool vms_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, long byte_offset, int in_off, int remaining_bytes); -static gboolean parse_vms_packet(FILE_T fh, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); +static bool parse_vms_packet(FILE_T fh, wtap_rec *rec, + Buffer *buf, int *err, char **err_info); static int vms_file_type_subtype = -1; @@ -143,7 +143,7 @@ void register_vms(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 sets "*err_info" to null or an additional error string. */ -static long vms_seek_next_packet(wtap *wth, int *err, gchar **err_info) +static long vms_seek_next_packet(wtap *wth, int *err, char **err_info) { long cur_off; char buf[VMS_LINE_LENGTH]; @@ -174,18 +174,18 @@ static long vms_seek_next_packet(wtap *wth, int *err, gchar **err_info) /* Look through the first part of a file to see if this is * a VMS 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. * * Leaves file handle at beginning of line that contains the VMS Magic * identifier. */ -static gboolean vms_check_file_type(wtap *wth, int *err, gchar **err_info) +static bool vms_check_file_type(wtap *wth, int *err, char **err_info) { char buf[VMS_LINE_LENGTH]; - guint reclen, line; - gint64 mpos; + unsigned reclen, line; + int64_t mpos; buf[VMS_LINE_LENGTH-1] = '\0'; @@ -194,15 +194,15 @@ static gboolean vms_check_file_type(wtap *wth, int *err, gchar **err_info) if (mpos == -1) { /* Error. */ *err = file_error(wth->fh, err_info); - return FALSE; + return false; } if (file_gets(buf, VMS_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 < strlen(VMS_HDR_MAGIC_STR1) || reclen < strlen(VMS_HDR_MAGIC_STR2) || reclen < strlen(VMS_HDR_MAGIC_STR3)) { @@ -216,17 +216,17 @@ static gboolean vms_check_file_type(wtap *wth, int *err, gchar **err_info) * re-read it. */ if (file_seek(wth->fh, mpos, SEEK_SET, err) == -1) { /* Error. */ - return FALSE; + return false; } - return TRUE; + return true; } } *err = 0; - return FALSE; + return false; } -wtap_open_return_val vms_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val vms_open(wtap *wth, int *err, char **err_info) { /* Look for VMS header */ if (!vms_check_file_type(wth, err, err_info)) { @@ -254,10 +254,10 @@ wtap_open_return_val vms_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static gboolean vms_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool vms_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { - gint64 offset = 0; + int64_t offset = 0; /* Find the next packet */ #ifdef TCPIPTRACE_FRAGMENTS_HAVE_HEADER_LINE @@ -267,7 +267,7 @@ static gboolean vms_read(wtap *wth, wtap_rec *rec, Buffer *buf, #endif if (offset < 1) { *err = file_error(wth->fh, err_info); - return FALSE; + return false; } *data_offset = offset; @@ -276,19 +276,19 @@ static gboolean vms_read(wtap *wth, wtap_rec *rec, Buffer *buf, } /* Used to read packets in random-access fashion */ -static gboolean -vms_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info) +static bool +vms_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info) { if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) - return FALSE; + return false; if (!parse_vms_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; } /* isdumpline assumes that dump lines start with some non-alphanumerics @@ -296,7 +296,7 @@ vms_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, * by 3 spaces. */ static int -isdumpline( gchar *line ) +isdumpline( char *line ) { int i, j; @@ -306,34 +306,34 @@ isdumpline( gchar *line ) for (j=0; j<4; j++) { for (i=0; i<8; i++, line++) if (! g_ascii_isxdigit(*line)) - return FALSE; + return false; for (i=0; i<3; i++, line++) if (*line != ' ') - return FALSE; + return false; } return g_ascii_isspace(*line); } /* Parses a packet record. */ -static gboolean -parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { char line[VMS_LINE_LENGTH + 1]; int num_items_scanned; - gboolean have_pkt_len = FALSE; - guint32 pkt_len = 0; + bool have_pkt_len = false; + uint32_t pkt_len = 0; int pktnum; int csec = 101; struct tm tm; char mon[4] = {'J', 'A', 'N', 0}; - gchar *p; - const gchar *endp; - static const gchar months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"; - guint32 i; + char *p; + const char *endp; + static const char months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"; + uint32_t i; int offset = 0; - guint8 *pd; + uint8_t *pd; tm.tm_year = 1970; tm.tm_mon = 0; @@ -349,7 +349,7 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in if ((*err == 0) && (csec != 101)) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } line[VMS_LINE_LENGTH] = '\0'; @@ -376,7 +376,7 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in if (num_items_scanned != 8) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("vms: header line not valid"); - return FALSE; + return false; } } if ( (! have_pkt_len) && (p = strstr(line, "Length "))) { @@ -387,22 +387,22 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in if ( !*p ) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("vms: Length field not valid"); - return FALSE; + return false; } if (!ws_strtou32(p, &endp, &pkt_len) || (*endp != '\0' && !g_ascii_isspace(*endp))) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("vms: Length field '%s' not valid", p); - return FALSE; + return false; } - have_pkt_len = TRUE; + have_pkt_len = true; break; } } while (! isdumpline(line)); if (! have_pkt_len) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("vms: Length field not found"); - return FALSE; + return false; } if (pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) { /* @@ -413,7 +413,7 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("vms: File has %u-byte packet, bigger than maximum of %u", pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD); - return FALSE; + return false; } p = strstr(months, mon); @@ -441,7 +441,7 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } line[VMS_LINE_LENGTH] = '\0'; if (i == 0) { @@ -451,7 +451,7 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return FALSE; + return false; } line[VMS_LINE_LENGTH] = '\0'; } @@ -462,7 +462,7 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in offset, pkt_len - i)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("vms: hex dump not valid"); - return FALSE; + return false; } } /* Avoid TCPIPTRACE-W-BUFFERSFUL, TCPIPtrace could not save n packets. @@ -476,11 +476,11 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in if (*err == 0) { /* There is no next line, so there's no "TCPIPtrace could not * save n packets" line; not an error. */ - return TRUE; + return true; } - return FALSE; + return false; } - return TRUE; + return true; } /* @@ -498,10 +498,10 @@ parse_vms_packet(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_in * we are passed to validate the record. We place the bytes in the buffer * at the specified offset. * - * 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, long byte_offset, +static bool +parse_single_hex_dump_line(char* rec, uint8_t *buf, long byte_offset, int in_off, int remaining_bytes) { int i; @@ -516,7 +516,7 @@ parse_single_hex_dump_line(char* rec, guint8 *buf, long byte_offset, value = (int)strtoul(s + 45 + in_off, NULL, 16); /* XXX - error check? */ if (value != byte_offset) { - return FALSE; + return false; } if (remaining_bytes > 16) @@ -530,10 +530,10 @@ parse_single_hex_dump_line(char* rec, guint8 *buf, long byte_offset, lbuf[0] = rec[offsets[i] + in_off]; lbuf[1] = rec[offsets[i] + 1 + in_off]; - buf[byte_offset + i] = (guint8) strtoul(lbuf, NULL, 16); + buf[byte_offset + i] = (uint8_t) strtoul(lbuf, NULL, 16); } - return TRUE; + return true; } static const struct supported_block_type vms_blocks_supported[] = { @@ -545,7 +545,7 @@ static const struct supported_block_type vms_blocks_supported[] = { static const struct file_type_subtype_info vms_info = { "TCPIPtrace (VMS)", "tcpiptrace", "txt", NULL, - FALSE, BLOCKS_SUPPORTED(vms_blocks_supported), + false, BLOCKS_SUPPORTED(vms_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/vms.h b/wiretap/vms.h index cb8c98f8..1768c592 100644 --- a/wiretap/vms.h +++ b/wiretap/vms.h @@ -14,6 +14,6 @@ #include "wtap.h" #include "ws_symbol_export.h" -wtap_open_return_val vms_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val vms_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/vwr.c b/wiretap/vwr.c index 251ddf52..3bd47759 100644 --- a/wiretap/vwr.c +++ b/wiretap/vwr.c @@ -8,45 +8,45 @@ * */ #include "config.h" +#include "vwr.h" #include <string.h> #include "wtap-int.h" #include "file_wrappers.h" -#include "vwr.h" #include <wsutil/ws_assert.h> /* platform-specific definitions for portability */ /* unsigned long long constants */ -# define NS_IN_US G_GUINT64_CONSTANT(1000) /* nanoseconds-to-microseconds */ -# define NS_IN_SEC G_GUINT64_CONSTANT(1000000000) /* nanoseconds-to-seconds */ -# define US_IN_SEC G_GUINT64_CONSTANT(1000000) /* microseconds-to-seconds */ -# define LL_ZERO G_GUINT64_CONSTANT(0) /* zero in unsigned long long */ +# define NS_IN_US UINT64_C(1000) /* nanoseconds-to-microseconds */ +# define NS_IN_SEC UINT64_C(1000000000) /* nanoseconds-to-seconds */ +# define US_IN_SEC UINT64_C(1000000) /* microseconds-to-seconds */ +# define LL_ZERO UINT64_C(0) /* zero in unsigned long long */ /* * Fetch a 64-bit value in "Corey-endian" form. */ -#define pcoreytohll(p) ((guint64)*((const guint8 *)(p)+4)<<56| \ - (guint64)*((const guint8 *)(p)+5)<<48| \ - (guint64)*((const guint8 *)(p)+6)<<40| \ - (guint64)*((const guint8 *)(p)+7)<<32| \ - (guint64)*((const guint8 *)(p)+0)<<24| \ - (guint64)*((const guint8 *)(p)+1)<<16| \ - (guint64)*((const guint8 *)(p)+2)<<8| \ - (guint64)*((const guint8 *)(p)+3)<<0) +#define pcoreytohll(p) ((uint64_t)*((const uint8_t *)(p)+4)<<56| \ + (uint64_t)*((const uint8_t *)(p)+5)<<48| \ + (uint64_t)*((const uint8_t *)(p)+6)<<40| \ + (uint64_t)*((const uint8_t *)(p)+7)<<32| \ + (uint64_t)*((const uint8_t *)(p)+0)<<24| \ + (uint64_t)*((const uint8_t *)(p)+1)<<16| \ + (uint64_t)*((const uint8_t *)(p)+2)<<8| \ + (uint64_t)*((const uint8_t *)(p)+3)<<0) /* * Fetch a 48-bit value in "Corey-endian" form; it's stored as * a 64-bit Corey-endian value, with the upper 16 bits ignored. */ -#define pcorey48tohll(p) ((guint64)*((const guint8 *)(p)+6)<<40| \ - (guint64)*((const guint8 *)(p)+7)<<32| \ - (guint64)*((const guint8 *)(p)+0)<<24| \ - (guint64)*((const guint8 *)(p)+1)<<16| \ - (guint64)*((const guint8 *)(p)+2)<<8| \ - (guint64)*((const guint8 *)(p)+3)<<0) +#define pcorey48tohll(p) ((uint64_t)*((const uint8_t *)(p)+6)<<40| \ + (uint64_t)*((const uint8_t *)(p)+7)<<32| \ + (uint64_t)*((const uint8_t *)(p)+0)<<24| \ + (uint64_t)*((const uint8_t *)(p)+1)<<16| \ + (uint64_t)*((const uint8_t *)(p)+2)<<8| \ + (uint64_t)*((const uint8_t *)(p)+3)<<0) /* .vwr log file defines */ #define B_SIZE 32768 /* max var len message = 32 kB */ @@ -479,7 +479,7 @@ #define vVW510021_W_PREAMBLE_OFF vVW510021_W_L1P_1_OFF #define vVW510021_W_RSSI_TXPOWER_OFF 2 /* RSSI (NOTE: RSSI must be negated!) */ #define vVW510021_W_MSDU_LENGTH_OFF 3 /* 7:0 of length, next byte 11:8 in top 4 bits */ -#define vVW510021_W_BVCV_VALID_OFF 4 /* BV,CV Determine validaity of bssid and txpower */ +#define vVW510021_W_BVCV_VALID_OFF 4 /* BV,CV Determine validity of bssid and txpower */ #define vVW510021_W_VCID_OFF 6 /* offset of VC (client) ID */ #define vVW510021_W_PLCP_LENGTH_OFF 12 /* LENGTH field in the plcp header */ @@ -692,73 +692,73 @@ typedef struct { /* offsets in stats block; these are dependent on the frame type (Ethernet/WLAN) and */ /* version number of .vwr file, and are set up by setup_defaults() */ - guint32 STATS_LEN; /* length of stats block trailer */ - guint32 STATS_START_OFF; /* STATS OFF AFTER HEADER */ - guint32 VALID_OFF; /* bit 6 (0x40) is flow-is-valid flag */ - guint32 MTYPE_OFF; /* offset of modulation type */ - guint32 VCID_OFF; /* offset of VC ID */ - guint32 FLOWSEQ_OFF; /* offset of signature sequence number */ - guint32 FLOWID_OFF; /* offset of flow ID */ - guint32 OCTET_OFF; /* offset of octets */ - guint32 ERRORS_OFF; /* offset of error vector */ - guint32 PATN_OFF; /* offset of pattern match vector */ - guint32 RSSI_OFF; /* RSSI (NOTE: RSSI must be negated!) */ - guint32 STARTT_OFF; /* offset of start time, 64 bits */ - guint32 ENDT_OFF; /* offset of end time, 64 bits */ - guint32 LATVAL_OFF; /* offset of latency, 32 bits */ - guint32 INFO_OFF; /* offset of INFO field, 16 bits */ - guint32 L1P_1_OFF; /* offset 1ST Byte of l1params */ - guint32 L1P_2_OFF; /* offset 2nd Byte of l1params */ - guint32 L4ID_OFF; /* LAYER 4 id offset*/ - guint32 IPLEN_OFF; /* */ - guint32 PLCP_LENGTH_OFF; /* offset of length field in the PLCP header */ - guint32 FPGA_VERSION_OFF; /* offset of fpga version field, 16 bits */ - guint32 HEADER_VERSION_OFF; /* offset of header version, 16 bits */ - guint32 RXTX_OFF; /* offset of CMD bit, rx or tx */ - guint32 FRAME_TYPE_OFF; + uint32_t STATS_LEN; /* length of stats block trailer */ + uint32_t STATS_START_OFF; /* STATS OFF AFTER HEADER */ + uint32_t VALID_OFF; /* bit 6 (0x40) is flow-is-valid flag */ + uint32_t MTYPE_OFF; /* offset of modulation type */ + uint32_t VCID_OFF; /* offset of VC ID */ + uint32_t FLOWSEQ_OFF; /* offset of signature sequence number */ + uint32_t FLOWID_OFF; /* offset of flow ID */ + uint32_t OCTET_OFF; /* offset of octets */ + uint32_t ERRORS_OFF; /* offset of error vector */ + uint32_t PATN_OFF; /* offset of pattern match vector */ + uint32_t RSSI_OFF; /* RSSI (NOTE: RSSI must be negated!) */ + uint32_t STARTT_OFF; /* offset of start time, 64 bits */ + uint32_t ENDT_OFF; /* offset of end time, 64 bits */ + uint32_t LATVAL_OFF; /* offset of latency, 32 bits */ + uint32_t INFO_OFF; /* offset of INFO field, 16 bits */ + uint32_t L1P_1_OFF; /* offset 1ST Byte of l1params */ + uint32_t L1P_2_OFF; /* offset 2nd Byte of l1params */ + uint32_t L4ID_OFF; /* LAYER 4 id offset*/ + uint32_t IPLEN_OFF; /* */ + uint32_t PLCP_LENGTH_OFF; /* offset of length field in the PLCP header */ + uint32_t FPGA_VERSION_OFF; /* offset of fpga version field, 16 bits */ + uint32_t HEADER_VERSION_OFF; /* offset of header version, 16 bits */ + uint32_t RXTX_OFF; /* offset of CMD bit, rx or tx */ + uint32_t FRAME_TYPE_OFF; /* other information about the file in question */ - guint32 MT_10_HALF; /* 10 Mb/s half-duplex */ - guint32 MT_10_FULL; /* 10 Mb/s full-duplex */ - guint32 MT_100_HALF; /* 100 Mb/s half-duplex */ - guint32 MT_100_FULL; /* 100 Mb/s full-duplex */ - guint32 MT_1G_HALF; /* 1 Gb/s half-duplex */ - guint32 MT_1G_FULL; /* 1 Gb/s full-duplex */ - guint32 FCS_ERROR; /* FCS error in frame */ - guint32 CRYPTO_ERR; /* RX decrypt error flags */ - guint32 PAYCHK_ERR; /* payload checksum failure */ - guint32 RETRY_ERR; /* excessive retries on TX failure */ - guint8 IS_RX; /* TX/RX bit in STATS block */ - guint8 MT_MASK; /* modulation type mask */ - guint16 VCID_MASK; /* VC ID might not be a full 16 bits */ - guint32 FLOW_VALID; /* flow-is-valid flag (else force to 0) */ - guint16 QOS_VALID; - guint32 RX_DECRYPTS; /* RX-frame-was-decrypted bits */ - guint32 TX_DECRYPTS; /* TX-frame-was-decrypted bits */ - guint32 FC_PROT_BIT; /* Protected Frame bit in FC1 of frame */ - guint32 MT_CCKL; /* CCK modulation, long preamble */ - guint32 MT_CCKS; /* CCK modulation, short preamble */ - guint32 MT_OFDM; /* OFDM modulation */ - guint32 MCS_INDEX_MASK; /* mcs index type mask */ - guint32 FPGA_VERSION; - guint32 WEPTYPE; /* frame is WEP */ - guint32 TKIPTYPE; /* frame is TKIP */ - guint32 CCMPTYPE; /* frame is CCMP */ - guint32 IS_TCP; - guint32 IS_UDP; - guint32 IS_ICMP; - guint32 IS_IGMP; - guint16 IS_QOS; - guint32 IS_VLAN; - guint32 MPDU_OFF; - guint32 OCTO_VERSION; + uint32_t MT_10_HALF; /* 10 Mb/s half-duplex */ + uint32_t MT_10_FULL; /* 10 Mb/s full-duplex */ + uint32_t MT_100_HALF; /* 100 Mb/s half-duplex */ + uint32_t MT_100_FULL; /* 100 Mb/s full-duplex */ + uint32_t MT_1G_HALF; /* 1 Gb/s half-duplex */ + uint32_t MT_1G_FULL; /* 1 Gb/s full-duplex */ + uint32_t FCS_ERROR; /* FCS error in frame */ + uint32_t CRYPTO_ERR; /* RX decrypt error flags */ + uint32_t PAYCHK_ERR; /* payload checksum failure */ + uint32_t RETRY_ERR; /* excessive retries on TX failure */ + uint8_t IS_RX; /* TX/RX bit in STATS block */ + uint8_t MT_MASK; /* modulation type mask */ + uint16_t VCID_MASK; /* VC ID might not be a full 16 bits */ + uint32_t FLOW_VALID; /* flow-is-valid flag (else force to 0) */ + uint16_t QOS_VALID; + uint32_t RX_DECRYPTS; /* RX-frame-was-decrypted bits */ + uint32_t TX_DECRYPTS; /* TX-frame-was-decrypted bits */ + uint32_t FC_PROT_BIT; /* Protected Frame bit in FC1 of frame */ + uint32_t MT_CCKL; /* CCK modulation, long preamble */ + uint32_t MT_CCKS; /* CCK modulation, short preamble */ + uint32_t MT_OFDM; /* OFDM modulation */ + uint32_t MCS_INDEX_MASK; /* mcs index type mask */ + uint32_t FPGA_VERSION; + uint32_t WEPTYPE; /* frame is WEP */ + uint32_t TKIPTYPE; /* frame is TKIP */ + uint32_t CCMPTYPE; /* frame is CCMP */ + uint32_t IS_TCP; + uint32_t IS_UDP; + uint32_t IS_ICMP; + uint32_t IS_IGMP; + uint16_t IS_QOS; + uint32_t IS_VLAN; + uint32_t MPDU_OFF; + uint32_t OCTO_VERSION; } vwr_t; /* * NSS for various MCS values. */ #define MAX_HT_MCS 76 -static guint nss_for_mcs[MAX_HT_MCS+1] = { +static unsigned nss_for_mcs[MAX_HT_MCS+1] = { 1, 1, 1, 1, 1, 1, 1, 1, /* 0-7 */ 2, 2, 2, 2, 2, 2, 2, 2, /* 8-15 */ 3, 3, 3, 3, 3, 3, 3, 3, /* 16-23 */ @@ -771,42 +771,42 @@ static guint nss_for_mcs[MAX_HT_MCS+1] = { }; /* internal utility functions */ -static int decode_msg(vwr_t *vwr, register guint8 *, int *, int *, int *); -static guint8 get_ofdm_rate(const guint8 *); -static guint8 get_cck_rate(const guint8 *plcp); -static void setup_defaults(vwr_t *, guint16); - -static gboolean vwr_read(wtap *, wtap_rec *, Buffer *, int *, - gchar **, gint64 *); -static gboolean vwr_seek_read(wtap *, gint64, wtap_rec *, - Buffer *, int *, gchar **); - -static gboolean vwr_read_rec_header(vwr_t *, FILE_T, int *, int *, int *, int *, gchar **); -static gboolean vwr_process_rec_data(FILE_T fh, int rec_size, +static int decode_msg(vwr_t *vwr, register uint8_t *, int *, int *, int *); +static uint8_t get_ofdm_rate(const uint8_t *); +static uint8_t get_cck_rate(const uint8_t *plcp); +static void setup_defaults(vwr_t *, uint16_t); + +static bool vwr_read(wtap *, wtap_rec *, Buffer *, int *, + char **, int64_t *); +static bool vwr_seek_read(wtap *, int64_t, wtap_rec *, + Buffer *, int *, char **); + +static bool vwr_read_rec_header(vwr_t *, FILE_T, int *, int *, int *, int *, char **); +static bool vwr_process_rec_data(FILE_T fh, int rec_size, wtap_rec *record, Buffer *buf, vwr_t *vwr, int IS_TX, int log_mode, int *err, - gchar **err_info); + char **err_info); -static int vwr_get_fpga_version(wtap *, int *, gchar **); +static int vwr_get_fpga_version(wtap *, int *, char **); -static gboolean vwr_read_s1_W_rec(vwr_t *, wtap_rec *, Buffer *, - const guint8 *, int, int *, gchar **); -static gboolean vwr_read_s2_W_rec(vwr_t *, wtap_rec *, Buffer *, - const guint8 *, int, int, int *, - gchar **); +static bool vwr_read_s1_W_rec(vwr_t *, wtap_rec *, Buffer *, + const uint8_t *, int, int *, char **); +static bool vwr_read_s2_W_rec(vwr_t *, wtap_rec *, Buffer *, + const uint8_t *, int, int, int *, + char **); /* For FPGA version >= 48 (OCTO Platform), following function will be used */ -static gboolean vwr_read_s3_W_rec(vwr_t *, wtap_rec *, Buffer *, - const guint8 *, int, int, int, int *, - gchar **); -static gboolean vwr_read_rec_data_ethernet(vwr_t *, wtap_rec *, - Buffer *, const guint8 *, int, - int, int *, gchar **); - -static int find_signature(const guint8 *, int, int, register guint32, register guint8); -static guint64 get_signature_ts(const guint8 *, int, int); -static float get_legacy_rate(guint8); -static float get_ht_rate(guint8, guint16); -static float get_vht_rate(guint8, guint16, guint8); +static bool vwr_read_s3_W_rec(vwr_t *, wtap_rec *, Buffer *, + const uint8_t *, int, int, int, int *, + char **); +static bool vwr_read_rec_data_ethernet(vwr_t *, wtap_rec *, + Buffer *, const uint8_t *, int, + int, int *, char **); + +static int find_signature(const uint8_t *, int, int, register uint32_t, register uint8_t); +static uint64_t get_signature_ts(const uint8_t *, int, int); +static float get_legacy_rate(uint8_t); +static float get_ht_rate(uint8_t, uint16_t); +static float get_vht_rate(uint8_t, uint16_t, uint8_t); static int vwr_80211_file_type_subtype = -1; static int vwr_eth_file_type_subtype = -1; @@ -817,7 +817,7 @@ void register_vwr(void); /* This does very little, except setting the wiretap header for a VWR file type */ /* and setting the timestamp precision to microseconds. */ -wtap_open_return_val vwr_open(wtap *wth, int *err, gchar **err_info) +wtap_open_return_val vwr_open(wtap *wth, int *err, char **err_info) { int fpgaVer; vwr_t *vwr; @@ -871,15 +871,15 @@ wtap_open_return_val vwr_open(wtap *wth, int *err, gchar **err_info) /* frame, and a 64-byte statistics block trailer. */ /* The PLCP frame consists of a 4-byte or 6-byte PLCP header, followed by the MAC frame */ -static gboolean vwr_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) +static bool vwr_read(wtap *wth, wtap_rec *rec, Buffer *buf, + int *err, char **err_info, int64_t *data_offset) { vwr_t *vwr = (vwr_t *)wth->priv; int rec_size = 0, IS_TX = 0, log_mode = 0; /* read the next frame record header in the capture file; if no more frames, return */ if (!vwr_read_rec_header(vwr, wth->fh, &rec_size, &IS_TX, &log_mode, err, err_info)) - return FALSE; /* Read error or EOF */ + return false; /* Read error or EOF */ /* * We're past the header; return the offset of the header, not of @@ -890,26 +890,26 @@ static gboolean vwr_read(wtap *wth, wtap_rec *rec, Buffer *buf, /* got a frame record; read and process it */ if (!vwr_process_rec_data(wth->fh, rec_size, rec, buf, vwr, IS_TX, log_mode, err, err_info)) - return FALSE; + return false; - return TRUE; + return true; } /* read a random record in the middle of a file; the start of the record is @ seek_off */ -static gboolean vwr_seek_read(wtap *wth, gint64 seek_off, - wtap_rec *record, Buffer *buf, int *err, gchar **err_info) +static bool vwr_seek_read(wtap *wth, int64_t seek_off, + wtap_rec *record, Buffer *buf, int *err, char **err_info) { vwr_t *vwr = (vwr_t *)wth->priv; int rec_size, IS_TX = 0, log_mode = 0; /* first seek to the indicated record header */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; /* read in the record header */ if (!vwr_read_rec_header(vwr, wth->random_fh, &rec_size, &IS_TX, &log_mode, err, err_info)) - return FALSE; /* Read error or EOF */ + return false; /* Read error or EOF */ return vwr_process_rec_data(wth->random_fh, rec_size, record, buf, vwr, IS_TX, log_mode, err, err_info); @@ -917,13 +917,13 @@ static gboolean vwr_seek_read(wtap *wth, gint64 seek_off, /* Scan down in the input capture file to find the next frame header. */ /* Decode and skip over all non-frame messages that are in the way. */ -/* Return TRUE on success, FALSE on EOF or error. */ +/* Return true on success, false on EOF or error. */ /* Also return the frame size in bytes and the "is transmitted frame" flag. */ -static gboolean vwr_read_rec_header(vwr_t *vwr, FILE_T fh, int *rec_size, int *IS_TX, int *log_mode, int *err, gchar **err_info) +static bool vwr_read_rec_header(vwr_t *vwr, FILE_T fh, int *rec_size, int *IS_TX, int *log_mode, int *err, char **err_info) { int f_len, v_type; - guint8 header[VW_RECORD_HEADER_LENGTH]; + uint8_t header[VW_RECORD_HEADER_LENGTH]; *rec_size = 0; @@ -934,7 +934,7 @@ static gboolean vwr_read_rec_header(vwr_t *vwr, FILE_T fh, int *rec_size, int *I /* If we find a frame, we return (with the header in the passed buffer). */ while (1) { if (!wtap_read_bytes_or_eof(fh, header, VW_RECORD_HEADER_LENGTH, err, err_info)) - return FALSE; + return false; /* Got a header; invoke decode-message function to parse and process it. */ /* If the function returns a length, then a frame or variable-length message */ @@ -944,15 +944,15 @@ static gboolean vwr_read_rec_header(vwr_t *vwr, FILE_T fh, int *rec_size, int *I if (f_len > B_SIZE) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("vwr: Invalid message record length %d", f_len); - return FALSE; + return false; } else if (v_type != VT_FRAME) { if (!wtap_read_bytes(fh, NULL, f_len, err, err_info)) - return FALSE; + return false; } else { *rec_size = f_len; - return TRUE; + return true; } } } @@ -962,22 +962,22 @@ static gboolean vwr_read_rec_header(vwr_t *vwr, FILE_T fh, int *rec_size, int *I /* Return FPGA version if it's a known version, UNKNOWN_FPGA if it's not, */ /* and -1 on an I/O error. */ -static int vwr_get_fpga_version(wtap *wth, int *err, gchar **err_info) +static int vwr_get_fpga_version(wtap *wth, int *err, char **err_info) { - guint8 *rec; /* local buffer (holds input record) */ - guint8 header[VW_RECORD_HEADER_LENGTH]; + uint8_t *rec; /* local buffer (holds input record) */ + uint8_t header[VW_RECORD_HEADER_LENGTH]; int rec_size = 0; - guint8 i; - guint8 *s_510006_ptr = NULL; - guint8 *s_510024_ptr = NULL; - guint8 *s_510012_ptr = NULL; /* stats pointers */ - gint64 filePos = -1; - guint64 bytes_read = 0; - guint32 frame_type = 0; + uint8_t i; + uint8_t *s_510006_ptr = NULL; + uint8_t *s_510024_ptr = NULL; + uint8_t *s_510012_ptr = NULL; /* stats pointers */ + int64_t filePos = -1; + uint64_t bytes_read = 0; + uint32_t frame_type = 0; int f_len, v_type; - guint16 data_length = 0; - guint16 fpga_version; - gboolean valid_but_empty_file = FALSE; + uint16_t data_length = 0; + uint16_t fpga_version; + bool valid_but_empty_file = false; filePos = file_tell(wth->fh); if (filePos == -1) { @@ -986,7 +986,7 @@ static int vwr_get_fpga_version(wtap *wth, int *err, gchar **err_info) } fpga_version = 1000; - rec = (guint8*)g_malloc(B_SIZE); + rec = (uint8_t*)g_malloc(B_SIZE); /* Got a frame record; see if it is vwr */ /* If we don't get it all, then declare an error, we can't process the frame. */ /* Read out the file data in 16-byte messages, stopping either after we find a frame, */ @@ -1014,7 +1014,7 @@ static int vwr_get_fpga_version(wtap *wth, int *err, gchar **err_info) return -1; } else if (v_type == VT_CPMSG) - valid_but_empty_file = TRUE; + valid_but_empty_file = true; } else { rec_size = f_len; @@ -1140,34 +1140,34 @@ static int vwr_get_fpga_version(wtap *wth, int *err, gchar **err_info) /* The packet is constructed as a 38-byte VeriWave metadata header plus the raw */ /* MAC octets. */ -static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, - Buffer *buf, const guint8 *rec, int rec_size, - int *err, gchar **err_info) +static bool vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, + Buffer *buf, const uint8_t *rec, int rec_size, + int *err, char **err_info) { - guint8 *data_ptr; + uint8_t *data_ptr; int bytes_written = 0; /* bytes output to buf so far */ - const guint8 *s_ptr, *m_ptr; /* stats pointer */ - guint16 msdu_length, actual_octets; /* octets in frame */ - guint16 plcp_hdr_len; /* PLCP header length */ - guint16 rflags; - guint8 m_type; /* mod type (CCK-L/CCK-S/OFDM), seqnum */ - guint flow_seq; - guint64 s_time = LL_ZERO, e_time = LL_ZERO; /* start/end */ + const uint8_t *s_ptr, *m_ptr; /* stats pointer */ + uint16_t msdu_length, actual_octets; /* octets in frame */ + uint16_t plcp_hdr_len; /* PLCP header length */ + uint16_t rflags; + uint8_t m_type; /* mod type (CCK-L/CCK-S/OFDM), seqnum */ + unsigned flow_seq; + uint64_t s_time = LL_ZERO, e_time = LL_ZERO; /* start/end */ /* times, nsec */ - guint32 latency; - guint64 start_time, s_sec, s_usec = LL_ZERO; /* start time, sec + usec */ - guint64 end_time; /* end time */ - guint32 info; /* INFO/ERRORS fields in stats blk */ - gint8 rssi; /* RSSI, signed 8-bit number */ + uint32_t latency; + uint64_t start_time, s_sec, s_usec = LL_ZERO; /* start time, sec + usec */ + uint64_t end_time; /* end time */ + uint32_t info; /* INFO/ERRORS fields in stats blk */ + int8_t rssi; /* RSSI, signed 8-bit number */ int f_tx; /* flag: if set, is a TX frame */ - guint8 rate_index; /* pre-HT only */ - guint16 vc_id, ht_len=0; /* VC ID, total ip length */ - guint flow_id; /* flow ID */ - guint32 d_time, errors; /* packet duration & errors */ + uint8_t rate_index; /* pre-HT only */ + uint16_t vc_id, ht_len=0; /* VC ID, total ip length */ + unsigned flow_id; /* flow ID */ + uint32_t d_time, errors; /* packet duration & errors */ int sig_off, pay_off; /* MAC+SNAP header len, signature offset */ - guint64 sig_ts; /* 32 LSBs of timestamp in signature */ - guint16 phyRate; - guint16 vw_flags; /* VeriWave-specific packet flags */ + uint64_t sig_ts; /* 32 LSBs of timestamp in signature */ + uint16_t phyRate; + uint16_t vw_flags; /* VeriWave-specific packet flags */ /* * The record data must be large enough to hold the statistics trailer. @@ -1176,7 +1176,7 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid record length %d (must be at least %u)", rec_size, v22_W_STATS_LEN); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } /* Calculate the start of the statistics block in the buffer */ @@ -1188,7 +1188,7 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, vc_id = pntoh16(&s_ptr[v22_W_VCID_OFF]) & v22_E_VCID_MASK; flow_seq = s_ptr[v22_W_FLOWSEQ_OFF]; - latency = (guint32)pcorey48tohll(&s_ptr[v22_W_LATVAL_OFF]); + latency = (uint32_t)pcorey48tohll(&s_ptr[v22_W_LATVAL_OFF]); flow_id = pntoh16(&s_ptr[v22_W_FLOWID_OFF+1]); /* only 16 LSBs kept */ errors = pntoh16(&s_ptr[v22_W_ERRORS_OFF]); @@ -1207,7 +1207,7 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (runs past the end of the record)", actual_octets); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } /* Decode OFDM or CCK PLCP header and determine rate and short preamble flag. */ @@ -1229,7 +1229,7 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (too short to include %u-byte PLCP header)", actual_octets, plcp_hdr_len); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } m_ptr = &rec[plcp_hdr_len]; msdu_length = actual_octets; @@ -1250,7 +1250,7 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (too short to include %u-byte PLCP header and 4 bytes of FCS)", actual_octets, plcp_hdr_len); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } } else { actual_octets -= 4; @@ -1262,7 +1262,7 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, e_time = pcoreytohll(&s_ptr[v22_W_ENDT_OFF]); /* find the packet duration (difference between start and end times) */ - d_time = (guint32)((e_time - s_time) / NS_IN_US); /* find diff, converting to usec */ + d_time = (uint32_t)((e_time - s_time) / NS_IN_US); /* find diff, converting to usec */ /* also convert the packet start time to seconds and microseconds */ start_time = s_time / NS_IN_US; /* convert to microseconds first */ @@ -1356,7 +1356,7 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, phtoles(&data_ptr[bytes_written], CHAN_CCK); } bytes_written += 2; - phyRate = (guint16)(get_legacy_rate(rate_index) * 10); + phyRate = (uint16_t)(get_legacy_rate(rate_index) * 10); phtoles(&data_ptr[bytes_written], phyRate); bytes_written += 2; data_ptr[bytes_written] = vVW510021_W_PLCP_LEGACY; /* pre-HT */ @@ -1413,50 +1413,50 @@ static gboolean vwr_read_s1_W_rec(vwr_t *vwr, wtap_rec *record, */ memcpy(&data_ptr[bytes_written], &rec[plcp_hdr_len], actual_octets); - return TRUE; + return true; } -static gboolean vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, - Buffer *buf, const guint8 *rec, int rec_size, - int IS_TX, int *err, gchar **err_info) +static bool vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, + Buffer *buf, const uint8_t *rec, int rec_size, + int IS_TX, int *err, char **err_info) { - guint8 *data_ptr; + uint8_t *data_ptr; int bytes_written = 0; /* bytes output to buf so far */ - const guint8 *s_start_ptr,*s_trail_ptr, *plcp_ptr, *m_ptr; /* stats & MPDU ptr */ - guint32 msdu_length, actual_octets; /* octets in frame */ - guint8 l1p_1, l1p_2, plcp_type, rate_mcs_index, nss; /* mod (CCK-L/CCK-S/OFDM) */ - guint flow_seq; - guint64 s_time = LL_ZERO, e_time = LL_ZERO; /* start/end */ + const uint8_t *s_start_ptr,*s_trail_ptr, *plcp_ptr, *m_ptr; /* stats & MPDU ptr */ + uint32_t msdu_length, actual_octets; /* octets in frame */ + uint8_t l1p_1, l1p_2, plcp_type, rate_mcs_index, nss; /* mod (CCK-L/CCK-S/OFDM) */ + unsigned flow_seq; + uint64_t s_time = LL_ZERO, e_time = LL_ZERO; /* start/end */ /* times, nsec */ - guint64 latency = LL_ZERO; - guint64 start_time, s_sec, s_usec = LL_ZERO; /* start time, sec + usec */ - guint64 end_time; /* end time */ - guint16 info; /* INFO/ERRORS fields in stats blk */ - guint32 errors; - gint8 rssi[] = {0,0,0,0}; /* RSSI, signed 8-bit number */ + uint64_t latency = LL_ZERO; + uint64_t start_time, s_sec, s_usec = LL_ZERO; /* start time, sec + usec */ + uint64_t end_time; /* end time */ + uint16_t info; /* INFO/ERRORS fields in stats blk */ + uint32_t errors; + int8_t rssi[] = {0,0,0,0}; /* RSSI, signed 8-bit number */ int f_tx; /* flag: if set, is a TX frame */ - guint16 vc_id, ht_len=0; /* VC ID , total ip length*/ - guint32 flow_id, d_time; /* flow ID, packet duration*/ + uint16_t vc_id, ht_len=0; /* VC ID , total ip length*/ + uint32_t flow_id, d_time; /* flow ID, packet duration*/ int sig_off, pay_off; /* MAC+SNAP header len, signature offset */ - guint64 sig_ts, tsid; /* 32 LSBs of timestamp in signature */ - guint16 chanflags = 0; /* channel flags for WLAN metadata header */ - guint16 radioflags = 0; /* flags for WLAN metadata header */ - guint64 delta_b; /* Used for calculating latency */ + uint64_t sig_ts, tsid; /* 32 LSBs of timestamp in signature */ + uint16_t chanflags = 0; /* channel flags for WLAN metadata header */ + uint16_t radioflags = 0; /* flags for WLAN metadata header */ + uint64_t delta_b; /* Used for calculating latency */ float rate; - guint16 phyRate; - guint16 vw_flags; /* VeriWave-specific packet flags */ + uint16_t phyRate; + uint16_t vw_flags; /* VeriWave-specific packet flags */ /* * The record data must be large enough to hold the statistics header, * the PLCP, and the statistics trailer. */ - if ((guint)rec_size < vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN) { + if ((unsigned)rec_size < vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN) { *err_info = ws_strdup_printf("vwr: Invalid record length %d (must be at least %u)", rec_size, vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } /* Calculate the start of the statistics blocks in the buffer */ @@ -1505,7 +1505,7 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (runs past the end of the record)", actual_octets); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } f_tx = IS_TX; @@ -1615,7 +1615,7 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, * the PSDU. */ { - guint8 SBW = vVW510021_W_BANDWIDTH_VHT(l1p_2); + uint8_t SBW = vVW510021_W_BANDWIDTH_VHT(l1p_2); rate_mcs_index = vVW510021_W_S2_MCS_INDEX_VHT(l1p_1); radioflags |= FLAGS_CHAN_VHT | ((l1p_1 & vVW510021_W_IS_LONGGI) ? 0 : FLAGS_CHAN_SHORTGI); chanflags |= CHAN_OFDM; @@ -1651,7 +1651,7 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (too short to include 4 bytes of FCS)", actual_octets); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } } else { actual_octets -= 4; @@ -1663,7 +1663,7 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, e_time = pcoreytohll(&s_trail_ptr[vVW510021_W_ENDT_OFF]); /* find the packet duration (difference between start and end times) */ - d_time = (guint32)((e_time - s_time) / NS_IN_US); /* find diff, converting to usec */ + d_time = (uint32_t)((e_time - s_time) / NS_IN_US); /* find diff, converting to usec */ /* also convert the packet start time to seconds and microseconds */ start_time = s_time / NS_IN_US; /* convert to microseconds first */ @@ -1773,7 +1773,7 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, bytes_written += 2; phtoles(&data_ptr[bytes_written], chanflags); bytes_written += 2; - phyRate = (guint16)(rate * 10); + phyRate = (uint16_t)(rate * 10); phtoles(&data_ptr[bytes_written], phyRate); bytes_written += 2; @@ -1830,51 +1830,51 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, wtap_rec *record, */ memcpy(&data_ptr[bytes_written], &rec[vwr->MPDU_OFF], actual_octets); - return TRUE; + return true; } -static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, - Buffer *buf, const guint8 *rec, int rec_size, +static bool vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, + Buffer *buf, const uint8_t *rec, int rec_size, int IS_TX, int log_mode, int *err, - gchar **err_info) + char **err_info) { - guint8 *data_ptr; + uint8_t *data_ptr; int bytes_written = 0; /* bytes output to buf so far */ int i; int stats_offset = 0; - const guint8 *s_start_ptr = NULL,*s_trail_ptr = NULL, *plcp_ptr, *m_ptr; /* stats & MPDU ptr */ - guint32 msdu_length = 0, actual_octets = 0; /* octets in frame */ - guint8 l1p_1 = 0,l1p_2 = 0, plcp_type, rate_mcs_index, nss; /* mod (CCK-L/CCK-S/OFDM) */ - guint64 s_time = LL_ZERO, e_time = LL_ZERO; /* start/end */ + const uint8_t *s_start_ptr = NULL,*s_trail_ptr = NULL, *plcp_ptr, *m_ptr; /* stats & MPDU ptr */ + uint32_t msdu_length = 0, actual_octets = 0; /* octets in frame */ + uint8_t l1p_1 = 0,l1p_2 = 0, plcp_type, rate_mcs_index, nss; /* mod (CCK-L/CCK-S/OFDM) */ + uint64_t s_time = LL_ZERO, e_time = LL_ZERO; /* start/end */ /* times, nsec */ - guint64 latency = LL_ZERO; - guint64 start_time = 0, s_sec = 0, s_usec = LL_ZERO; /* start time, sec + usec */ - guint64 end_time = 0; /* end time */ - guint16 info = 0; /* INFO/ERRORS fields in stats blk */ - guint32 errors = 0; - gint8 info_2nd = 0,rssi[] = {0,0,0,0}; /* RSSI, signed 8-bit number */ + uint64_t latency = LL_ZERO; + uint64_t start_time = 0, s_sec = 0, s_usec = LL_ZERO; /* start time, sec + usec */ + uint64_t end_time = 0; /* end time */ + uint16_t info = 0; /* INFO/ERRORS fields in stats blk */ + uint32_t errors = 0; + int8_t info_2nd = 0,rssi[] = {0,0,0,0}; /* RSSI, signed 8-bit number */ int frame_size; - guint32 d_time = 0, flow_id = 0; /* packet duration, Flow Signature ID*/ + uint32_t d_time = 0, flow_id = 0; /* packet duration, Flow Signature ID*/ int sig_off, pay_off; /* MAC+SNAP header len, signature offset */ - guint64 sig_ts = 0, tsid; /* 32 LSBs of timestamp in signature */ - guint64 delta_b; /* Used for calculating latency */ - guint8 L1InfoC = 0, port_type, ver_fpga = 0; - guint8 flow_seq =0,plcp_hdr_flag = 0,rf_id = 0; /* indicates plcp hdr info */ - const guint8 *rf_ptr = NULL; + uint64_t sig_ts = 0, tsid; /* 32 LSBs of timestamp in signature */ + uint64_t delta_b; /* Used for calculating latency */ + uint8_t L1InfoC = 0, port_type, ver_fpga = 0; + uint8_t flow_seq =0,plcp_hdr_flag = 0,rf_id = 0; /* indicates plcp hdr info */ + const uint8_t *rf_ptr = NULL; float rate; - guint16 phyRate; + uint16_t phyRate; /* * The record data must be large enough to hold the statistics header, * the PLCP, and the statistics trailer. */ if (IS_TX == 3) { /*IS_TX =3, i.e., command type is RF Modified*/ - if ((guint)rec_size < OCTO_MODIFIED_RF_LEN) { + if ((unsigned)rec_size < OCTO_MODIFIED_RF_LEN) { *err_info = ws_strdup_printf("vwr: Invalid record length %d (must be at least %u)", rec_size, OCTO_MODIFIED_RF_LEN); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } rf_ptr = &(rec[0]); rf_id = rf_ptr[0]; @@ -1916,12 +1916,12 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, if (IS_TX == 4) /*IS_TX =4, i.e., command type is RF-RX Modified*/ { stats_offset = OCTO_RF_MOD_ACTUAL_LEN; - if ((guint)rec_size < stats_offset + vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN) { + if ((unsigned)rec_size < stats_offset + vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN) { *err_info = ws_strdup_printf("vwr: Invalid record length %d (must be at least %u)", rec_size, stats_offset + vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } rf_ptr = &(rec[0]); rf_id = rf_ptr[0]; @@ -1929,12 +1929,12 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, else { stats_offset = 0; - if ((guint)rec_size < vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN) { + if ((unsigned)rec_size < vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN) { *err_info = ws_strdup_printf("vwr: Invalid record length %d (must be at least %u)", rec_size, vwr->MPDU_OFF + vVW510021_W_STATS_TRAILER_LEN); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } } @@ -2022,7 +2022,7 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (runs past the end of the record)", actual_octets); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } flow_seq = s_trail_ptr[vVW510021_W_FLOWSEQ_OFF]; @@ -2065,7 +2065,7 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, */ { /* set the appropriate flags to indicate HT mode and CB */ - guint16 radioflags = FLAGS_CHAN_HT | ((plcp_ptr[3] & 0x80) ? FLAGS_CHAN_40MHZ : 0) | + uint16_t radioflags = FLAGS_CHAN_HT | ((plcp_ptr[3] & 0x80) ? FLAGS_CHAN_40MHZ : 0) | ((l1p_1 & vVW510021_W_IS_LONGGI) ? 0 : FLAGS_CHAN_SHORTGI); rate = get_ht_rate(rate_mcs_index, radioflags); } @@ -2084,7 +2084,7 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, */ { /* set the appropriate flags to indicate HT mode and CB */ - guint16 radioflags = FLAGS_CHAN_HT | ((plcp_ptr[0] & 0x80) ? FLAGS_CHAN_40MHZ : 0) | + uint16_t radioflags = FLAGS_CHAN_HT | ((plcp_ptr[0] & 0x80) ? FLAGS_CHAN_40MHZ : 0) | ((l1p_1 & vVW510021_W_IS_LONGGI) ? 0 : FLAGS_CHAN_SHORTGI); rate = get_ht_rate(rate_mcs_index, radioflags); } @@ -2102,8 +2102,8 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, * the PSDU. */ { - guint8 SBW = vVW510021_W_BANDWIDTH_VHT(l1p_2); - guint16 radioflags = FLAGS_CHAN_VHT | ((l1p_1 & vVW510021_W_IS_LONGGI) ? 0 : FLAGS_CHAN_SHORTGI); + uint8_t SBW = vVW510021_W_BANDWIDTH_VHT(l1p_2); + uint16_t radioflags = FLAGS_CHAN_VHT | ((l1p_1 & vVW510021_W_IS_LONGGI) ? 0 : FLAGS_CHAN_SHORTGI); if (SBW == 3) radioflags |= FLAGS_CHAN_40MHZ; else if (SBW == 4) @@ -2116,7 +2116,7 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, rate = 0.0f; break; } - phyRate = (guint16)(rate * 10); + phyRate = (uint16_t)(rate * 10); /* Calculation of Data rate ends*/ /* 'ver_fpga' is the 2nd Octet of each frame. @@ -2145,7 +2145,7 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (too short to include 4 bytes of FCS)", actual_octets); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } } else { actual_octets -= 4; @@ -2162,7 +2162,7 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, e_time = pcoreytohll(&s_trail_ptr[vVW510021_W_ENDT_OFF]); /* find the packet duration (difference between start and end times) */ - d_time = (guint32)((e_time - s_time) / NS_IN_US); /* find diff, converting to usec */ + d_time = (uint32_t)((e_time - s_time) / NS_IN_US); /* find diff, converting to usec */ /* also convert the packet start time to seconds and microseconds */ start_time = s_time / NS_IN_US; /* convert to microseconds first */ @@ -2220,7 +2220,7 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: File has %u-byte packet, bigger than maximum of %u", record->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } record->ts.secs = (time_t)s_sec; @@ -2545,45 +2545,45 @@ static gboolean vwr_read_s3_W_rec(vwr_t *vwr, wtap_rec *record, memcpy(&data_ptr[bytes_written], &rec[stats_offset+(vwr->MPDU_OFF)], actual_octets); } - return TRUE; + return true; } /* read an Ethernet packet */ /* Copy the actual packet data from the capture file into the target data block. */ /* The packet is constructed as a 38-byte VeriWave-extended Radiotap header plus the raw */ /* MAC octets. */ -static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, - Buffer *buf, const guint8 *rec, +static bool vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, + Buffer *buf, const uint8_t *rec, int rec_size, int IS_TX, int *err, - gchar **err_info) + char **err_info) { - guint8 *data_ptr; + uint8_t *data_ptr; int bytes_written = 0; /* bytes output to buf so far */ - const guint8 *s_ptr, *m_ptr; /* stats and MPDU pointers */ - guint16 msdu_length, actual_octets; /* octets in frame */ - guint flow_seq; /* seqnum */ - guint64 s_time = LL_ZERO, e_time = LL_ZERO; /* start/end */ + const uint8_t *s_ptr, *m_ptr; /* stats and MPDU pointers */ + uint16_t msdu_length, actual_octets; /* octets in frame */ + unsigned flow_seq; /* seqnum */ + uint64_t s_time = LL_ZERO, e_time = LL_ZERO; /* start/end */ /* times, nsec */ - guint32 latency = 0; - guint64 start_time, s_sec = LL_ZERO, s_usec = LL_ZERO; /* start time, sec + usec */ - guint64 end_time; /* end time */ - guint l4id; - guint16 info, validityBits; /* INFO/ERRORS fields in stats */ - guint32 errors; - guint16 vc_id; /* VC ID, total (incl of aggregates) */ - guint32 flow_id, d_time; /* packet duration */ + uint32_t latency = 0; + uint64_t start_time, s_sec = LL_ZERO, s_usec = LL_ZERO; /* start time, sec + usec */ + uint64_t end_time; /* end time */ + unsigned l4id; + uint16_t info, validityBits; /* INFO/ERRORS fields in stats */ + uint32_t errors; + uint16_t vc_id; /* VC ID, total (incl of aggregates) */ + uint32_t flow_id, d_time; /* packet duration */ int f_flow; /* flags: flow valid */ - guint32 frame_type; /* frame type field */ + uint32_t frame_type; /* frame type field */ int mac_len, sig_off, pay_off; /* MAC header len, signature offset */ /* XXX - the code here fetched tsid, but never used it! */ - guint64 sig_ts/*, tsid*/; /* 32 LSBs of timestamp in signature */ - guint64 delta_b; /* Used for calculating latency */ - guint16 vw_flags; /* VeriWave-specific packet flags */ + uint64_t sig_ts/*, tsid*/; /* 32 LSBs of timestamp in signature */ + uint64_t delta_b; /* Used for calculating latency */ + uint16_t vw_flags; /* VeriWave-specific packet flags */ - if ((guint)rec_size < vwr->STATS_LEN) { + if ((unsigned)rec_size < vwr->STATS_LEN) { *err_info = ws_strdup_printf("vwr: Invalid record length %d (must be at least %u)", rec_size, vwr->STATS_LEN); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } /* Calculate the start of the statistics block in the buffer. */ @@ -2605,7 +2605,7 @@ static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (runs past the end of the record)", actual_octets); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } vc_id = pntoh16(&s_ptr[vwr->VCID_OFF]) & vwr->VCID_MASK; @@ -2657,7 +2657,7 @@ static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, *err_info = ws_strdup_printf("vwr: Invalid data length %u (too short to include 4 bytes of FCS)", actual_octets); *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } } else { actual_octets -= 4; @@ -2669,7 +2669,7 @@ static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, e_time = pcoreytohll(&s_ptr[vwr->ENDT_OFF]); /* find the packet duration (difference between start and end times) */ - d_time = (guint32)((e_time - s_time)); /* find diff, leaving in nsec for Ethernet */ + d_time = (uint32_t)((e_time - s_time)); /* find diff, leaving in nsec for Ethernet */ /* also convert the packet start time to seconds and microseconds */ start_time = s_time / NS_IN_US; /* convert to microseconds first */ @@ -2709,7 +2709,7 @@ static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, /* Set latency based on rx/tx and signature timestamp */ if (!IS_TX) { if (sig_ts < s_time) { - latency = (guint32)(s_time - sig_ts); + latency = (uint32_t)(s_time - sig_ts); } else { /* Account for the rollover case. Since we cannot use 0x100000000 - l_time + s_time */ /* we look for a large difference between l_time and s_time. */ @@ -2717,7 +2717,7 @@ static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, if (delta_b > 0x10000000) { latency = 0; } else - latency = (guint32)delta_b; + latency = (uint32_t)delta_b; } } @@ -2740,7 +2740,7 @@ static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, record->block = wtap_block_create(WTAP_BLOCK_PACKET); record->presence_flags = WTAP_HAS_TS; - /*etap_hdr.vw_ip_length = (guint16)ip_len;*/ + /*etap_hdr.vw_ip_length = (uint16_t)ip_len;*/ ws_buffer_assure_space(buf, record->rec_header.packet_header.caplen); data_ptr = ws_buffer_start_ptr(buf); @@ -2815,16 +2815,16 @@ static gboolean vwr_read_rec_data_ethernet(vwr_t *vwr, wtap_rec *record, */ memcpy(&data_ptr[bytes_written], m_ptr, actual_octets); - return TRUE; + return true; } /*--------------------------------------------------------------------------------------*/ /* utility to split up and decode a 16-byte message record */ -static int decode_msg(vwr_t *vwr, guint8 *rec, int *v_type, int *IS_TX, int *log_mode) +static int decode_msg(vwr_t *vwr, uint8_t *rec, int *v_type, int *IS_TX, int *log_mode) { - guint8 cmd,fpga_log_mode; /* components of message */ - guint32 wd2, wd3; + uint8_t cmd,fpga_log_mode; /* components of message */ + uint32_t wd2, wd3; int v_size; /* size of var-len message */ /* break up the message record into its pieces */ @@ -2919,7 +2919,7 @@ static int decode_msg(vwr_t *vwr, guint8 *rec, int *v_type, int *IS_TX, int *log /* The integer returned by the get_xxx_rate() functions is in units of 0.5 Mb/s. */ /* The string returned by the decode_xxx_rate() functions is 3 characters wide. */ -static guint8 get_ofdm_rate(const guint8 *plcp) +static uint8_t get_ofdm_rate(const uint8_t *plcp) { /* extract the RATE field (LS nibble of first byte) then convert it to the MCS index used by the L1p fields */ switch (plcp[0] & 0x0f) { @@ -2935,7 +2935,7 @@ static guint8 get_ofdm_rate(const guint8 *plcp) } } -static guint8 get_cck_rate(const guint8 *plcp) +static uint8_t get_cck_rate(const uint8_t *plcp) { /* extract rate from the SIGNAL field then convert it to the MCS index used by the L1p fields */ switch (plcp[0]) { @@ -2950,7 +2950,7 @@ static guint8 get_cck_rate(const guint8 *plcp) /*--------------------------------------------------------------------------------------*/ /* utility to set up offsets and bitmasks for decoding the stats blocks */ -static void setup_defaults(vwr_t *vwr, guint16 fpga) +static void setup_defaults(vwr_t *vwr, uint16_t fpga) { switch (fpga) { /* WLAN frames */ @@ -3196,10 +3196,10 @@ static void setup_defaults(vwr_t *vwr, guint16 fpga) /* Utility routine: check that signature is at specified location; scan for it if not. */ /* If we can't find a signature at all, then simply return the originally supplied offset. */ -int find_signature(const guint8 *m_ptr, int rec_size, int pay_off, guint32 flow_id, guint8 flow_seq) +int find_signature(const uint8_t *m_ptr, int rec_size, int pay_off, uint32_t flow_id, uint8_t flow_seq) { int tgt; /* temps */ - guint32 fid; + uint32_t fid; /* initial check is very simple: look for a '0xdd' at the target location */ if (m_ptr[pay_off] == 0xdd) /* if magic byte is present */ @@ -3242,10 +3242,10 @@ int find_signature(const guint8 *m_ptr, int rec_size, int pay_off, guint32 flow_ } /* utility routine: harvest the signature time stamp from the data frame */ -guint64 get_signature_ts(const guint8 *m_ptr,int sig_off, int sig_max) +uint64_t get_signature_ts(const uint8_t *m_ptr,int sig_off, int sig_max) { int ts_offset; - guint64 sig_ts; + uint64_t sig_ts; if (sig_off + 15 >= sig_max) return 0; @@ -3261,7 +3261,7 @@ guint64 get_signature_ts(const guint8 *m_ptr,int sig_off, int sig_max) } static float -get_legacy_rate(guint8 rate_index) +get_legacy_rate(uint8_t rate_index) { /* Rate conversion data */ static const float canonical_rate_legacy[] = {1.0f, 2.0f, 5.5f, 11.0f, 6.0f, 9.0f, 12.0f, 18.0f, 24.0f, 36.0f, 48.0f, 54.0f}; @@ -3275,7 +3275,7 @@ get_legacy_rate(guint8 rate_index) } static float -get_ht_rate(guint8 mcs_index, guint16 rflags) +get_ht_rate(uint8_t mcs_index, uint16_t rflags) { /* Rate conversion data */ static const int canonical_ndbps_20_ht[8] = {26, 52, 78, 104, 156, 208, 234, 260}; @@ -3300,7 +3300,7 @@ get_ht_rate(guint8 mcs_index, guint16 rflags) } static float -get_vht_rate(guint8 mcs_index, guint16 rflags, guint8 nss) +get_vht_rate(uint8_t mcs_index, uint16_t rflags, uint8_t nss) { /* Rate conversion data */ static const int canonical_ndbps_20_vht[9] = {26, 52, 78, 104, 156, 208, 234, 260, 312}; @@ -3344,22 +3344,22 @@ get_vht_rate(guint8 mcs_index, guint16 rflags, guint8 nss) return bitrate; } -static gboolean +static bool vwr_process_rec_data(FILE_T fh, int rec_size, wtap_rec *record, Buffer *buf, vwr_t *vwr, - int IS_TX, int log_mode, int *err, gchar **err_info) + int IS_TX, int log_mode, int *err, char **err_info) { - guint8* rec; /* local buffer (holds input record) */ - gboolean ret = FALSE; + uint8_t* rec; /* local buffer (holds input record) */ + bool ret = false; - rec = (guint8*)g_malloc(B_SIZE); + rec = (uint8_t*)g_malloc(B_SIZE); /* Read over the entire record (frame + trailer) into a local buffer. */ /* If we don't get it all, then declare an error, we can't process the frame. */ if (!wtap_read_bytes(fh, rec, rec_size, err, err_info)) { g_free(rec); - return FALSE; + return false; } /* now format up the frame data */ @@ -3397,7 +3397,7 @@ static const struct supported_block_type vwr_80211_blocks_supported[] = { static const struct file_type_subtype_info vwr_80211_info = { "Ixia IxVeriWave .vwr Raw 802.11 Capture", "vwr80211", "vwr", NULL, - FALSE, BLOCKS_SUPPORTED(vwr_80211_blocks_supported), + false, BLOCKS_SUPPORTED(vwr_80211_blocks_supported), NULL, NULL, NULL }; @@ -3410,7 +3410,7 @@ static const struct supported_block_type vwr_eth_blocks_supported[] = { static const struct file_type_subtype_info vwr_eth_info = { "Ixia IxVeriWave .vwr Raw Ethernet Capture", "vwreth", "vwr", NULL, - FALSE, BLOCKS_SUPPORTED(vwr_eth_blocks_supported), + false, BLOCKS_SUPPORTED(vwr_eth_blocks_supported), NULL, NULL, NULL }; diff --git a/wiretap/vwr.h b/wiretap/vwr.h index d2074168..d6ce3a3f 100644 --- a/wiretap/vwr.h +++ b/wiretap/vwr.h @@ -11,7 +11,8 @@ #define __VWR_H__ #include "ws_symbol_export.h" +#include "wtap.h" -wtap_open_return_val vwr_open(wtap *wth, int *err, gchar **err_info); +wtap_open_return_val vwr_open(wtap *wth, int *err, char **err_info); #endif diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index e09819f2..a9aa0af6 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -16,6 +16,7 @@ #include <winsock2.h> #endif +#include <wsutil/array.h> #include <wsutil/file_util.h> #include "wtap_opttypes.h" @@ -25,9 +26,9 @@ void wtap_init_file_type_subtypes(void); WS_DLL_PUBLIC int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err); -typedef gboolean (*subtype_read_func)(struct wtap*, wtap_rec *, - Buffer *, int *, char **, gint64 *); -typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, wtap_rec *, +typedef bool (*subtype_read_func)(struct wtap*, wtap_rec *, + Buffer *, int *, char **, int64_t *); +typedef bool (*subtype_seek_read_func)(struct wtap*, int64_t, wtap_rec *, Buffer *, int *, char **); /** @@ -36,15 +37,16 @@ typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, wtap_rec *, struct wtap { FILE_T fh; FILE_T random_fh; /**< Secondary FILE_T for random access */ - gboolean ispipe; /**< TRUE if the file is a pipe */ + bool ispipe; /**< true if the file is a pipe */ int file_type_subtype; - guint snapshot_length; + unsigned snapshot_length; GArray *shb_hdrs; + GArray *shb_iface_to_global; /**< An array mapping the per-section interface numbers to global IDs */ GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?)*/ - guint next_interface_data; /**< Next interface data that wtap_get_next_interface_description() will show */ + unsigned next_interface_data; /**< Next interface data that wtap_get_next_interface_description() will show */ GArray *nrbs; /**< holds the Name Res Blocks, or NULL */ GArray *dsbs; /**< An array of DSBs (of type wtap_block_t), or NULL if not supported. */ - GArray *sysdig_meta_events; /**< An array of Sysdig meta eventss (of type wtap_block_t), or NULL if not supported. */ + GArray *meta_events; /**< An array of meta eventss (of type wtap_block_t), or NULL if not supported. */ char *pathname; /**< File pathname; might just be "-" */ @@ -74,24 +76,24 @@ struct wtap { wtap_new_ipv4_callback_t add_new_ipv4; wtap_new_ipv6_callback_t add_new_ipv6; wtap_new_secrets_callback_t add_new_secrets; - wtap_new_sysdig_meta_event_callback_t add_new_sysdig_meta_event; GPtrArray *fast_seek; }; struct wtap_dumper; /* - * This could either be a FILE * or a gzFile. + * This could either be a FILE * or a handle used by code that writes + * a compressed file. */ typedef void *WFILE_T; -typedef gboolean (*subtype_add_idb_func)(struct wtap_dumper*, wtap_block_t, - int *, gchar **); +typedef bool (*subtype_add_idb_func)(struct wtap_dumper*, wtap_block_t, + int *, char **); -typedef gboolean (*subtype_write_func)(struct wtap_dumper*, +typedef bool (*subtype_write_func)(struct wtap_dumper*, const wtap_rec *rec, - const guint8*, int*, gchar**); -typedef gboolean (*subtype_finish_func)(struct wtap_dumper*, int*, gchar**); + const uint8_t*, int*, char**); +typedef bool (*subtype_finish_func)(struct wtap_dumper*, int*, char**); struct wtap_dumper { WFILE_T fh; @@ -104,8 +106,8 @@ struct wtap_dumper { * encapsulation types */ wtap_compression_type compression_type; - gboolean needs_reload; /* TRUE if the file requires re-loading after saving with wtap */ - gint64 bytes_dumped; + bool needs_reload; /* true if the file requires re-loading after saving with wtap */ + int64_t bytes_dumped; void *priv; /* this one holds per-file state and is free'd automatically by wtap_dump_close() */ void *wslua_data; /* this one holds wslua state info and is not free'd */ @@ -116,6 +118,7 @@ struct wtap_dumper { addrinfo_lists_t *addrinfo_lists; /**< Struct containing lists of resolved addresses */ GArray *shb_hdrs; + const GArray *shb_iface_to_global; /**< An array mapping the per-section interface numbers to global IDs */ GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?) NULL if not present.*/ GArray *dsbs_initial; /**< An array of initial DSBs (of type wtap_block_t) */ @@ -125,18 +128,18 @@ struct wtap_dumper { */ const GArray *nrbs_growing; /**< A reference to an array of NRBs (of type wtap_block_t) */ const GArray *dsbs_growing; /**< A reference to an array of DSBs (of type wtap_block_t) */ - const GArray *sysdig_mev_growing; /**< A reference to an array of Sysdig meta events (of type wtap_block_t) */ - guint nrbs_growing_written; /**< Number of already processed NRBs in nrbs_growing. */ - guint dsbs_growing_written; /**< Number of already processed DSBs in dsbs_growing. */ - guint sysdig_mev_growing_written; /**< Number of already processed meta events in sysdig_mev_growing. */ + const GArray *mevs_growing; /**< A reference to an array of Sysdig meta events (of type wtap_block_t) */ + unsigned nrbs_growing_written; /**< Number of already processed NRBs in nrbs_growing. */ + unsigned dsbs_growing_written; /**< Number of already processed DSBs in dsbs_growing. */ + unsigned mevs_growing_written; /**< Number of already processed meta events in mevs_growing. */ }; -WS_DLL_PUBLIC gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf, +WS_DLL_PUBLIC bool wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize, int *err); -WS_DLL_PUBLIC gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err); -WS_DLL_PUBLIC gint64 wtap_dump_file_tell(wtap_dumper *wdh, int *err); +WS_DLL_PUBLIC int64_t wtap_dump_file_seek(wtap_dumper *wdh, int64_t offset, int whence, int *err); +WS_DLL_PUBLIC int64_t wtap_dump_file_tell(wtap_dumper *wdh, int *err); -extern gint wtap_num_file_types; +extern int wtap_num_file_types; #include <wsutil/pint.h> @@ -145,7 +148,7 @@ extern gint wtap_num_file_types; */ #define PBSWAP64(p) \ { \ - guint8 tmp; \ + uint8_t tmp; \ tmp = (p)[7]; \ (p)[7] = (p)[0]; \ (p)[0] = tmp; \ @@ -161,7 +164,7 @@ extern gint wtap_num_file_types; } #define PBSWAP32(p) \ { \ - guint8 tmp; \ + uint8_t tmp; \ tmp = (p)[3]; \ (p)[3] = (p)[0]; \ (p)[0] = tmp; \ @@ -171,7 +174,7 @@ extern gint wtap_num_file_types; } #define PBSWAP16(p) \ { \ - guint8 tmp; \ + uint8_t tmp; \ tmp = (p)[1]; \ (p)[1] = (p)[0]; \ (p)[0] = tmp; \ @@ -185,135 +188,130 @@ extern gint wtap_num_file_types; #ifndef phtons #define phtons(p, v) \ { \ - (p)[0] = (guint8)((v) >> 8); \ - (p)[1] = (guint8)((v) >> 0); \ + (p)[0] = (uint8_t)((v) >> 8); \ + (p)[1] = (uint8_t)((v) >> 0); \ } #endif #ifndef phton24 #define phton24(p, v) \ { \ - (p)[0] = (guint8)((v) >> 16); \ - (p)[1] = (guint8)((v) >> 8); \ - (p)[2] = (guint8)((v) >> 0); \ + (p)[0] = (uint8_t)((v) >> 16); \ + (p)[1] = (uint8_t)((v) >> 8); \ + (p)[2] = (uint8_t)((v) >> 0); \ } #endif #ifndef phtonl #define phtonl(p, v) \ { \ - (p)[0] = (guint8)((v) >> 24); \ - (p)[1] = (guint8)((v) >> 16); \ - (p)[2] = (guint8)((v) >> 8); \ - (p)[3] = (guint8)((v) >> 0); \ + (p)[0] = (uint8_t)((v) >> 24); \ + (p)[1] = (uint8_t)((v) >> 16); \ + (p)[2] = (uint8_t)((v) >> 8); \ + (p)[3] = (uint8_t)((v) >> 0); \ } #endif #ifndef phtonll #define phtonll(p, v) \ { \ - (p)[0] = (guint8)((v) >> 56); \ - (p)[1] = (guint8)((v) >> 48); \ - (p)[2] = (guint8)((v) >> 40); \ - (p)[3] = (guint8)((v) >> 32); \ - (p)[4] = (guint8)((v) >> 24); \ - (p)[5] = (guint8)((v) >> 16); \ - (p)[6] = (guint8)((v) >> 8); \ - (p)[7] = (guint8)((v) >> 0); \ + (p)[0] = (uint8_t)((v) >> 56); \ + (p)[1] = (uint8_t)((v) >> 48); \ + (p)[2] = (uint8_t)((v) >> 40); \ + (p)[3] = (uint8_t)((v) >> 32); \ + (p)[4] = (uint8_t)((v) >> 24); \ + (p)[5] = (uint8_t)((v) >> 16); \ + (p)[6] = (uint8_t)((v) >> 8); \ + (p)[7] = (uint8_t)((v) >> 0); \ } #endif #ifndef phtole8 #define phtole8(p, v) \ { \ - (p)[0] = (guint8)((v) >> 0); \ + (p)[0] = (uint8_t)((v) >> 0); \ } #endif #ifndef phtoles #define phtoles(p, v) \ { \ - (p)[0] = (guint8)((v) >> 0); \ - (p)[1] = (guint8)((v) >> 8); \ + (p)[0] = (uint8_t)((v) >> 0); \ + (p)[1] = (uint8_t)((v) >> 8); \ } #endif #ifndef phtole24 #define phtole24(p, v) \ { \ - (p)[0] = (guint8)((v) >> 0); \ - (p)[1] = (guint8)((v) >> 8); \ - (p)[2] = (guint8)((v) >> 16); \ + (p)[0] = (uint8_t)((v) >> 0); \ + (p)[1] = (uint8_t)((v) >> 8); \ + (p)[2] = (uint8_t)((v) >> 16); \ } #endif #ifndef phtolel #define phtolel(p, v) \ { \ - (p)[0] = (guint8)((v) >> 0); \ - (p)[1] = (guint8)((v) >> 8); \ - (p)[2] = (guint8)((v) >> 16); \ - (p)[3] = (guint8)((v) >> 24); \ + (p)[0] = (uint8_t)((v) >> 0); \ + (p)[1] = (uint8_t)((v) >> 8); \ + (p)[2] = (uint8_t)((v) >> 16); \ + (p)[3] = (uint8_t)((v) >> 24); \ } #endif #ifndef phtolell #define phtolell(p, v) \ { \ - (p)[0] = (guint8)((v) >> 0); \ - (p)[1] = (guint8)((v) >> 8); \ - (p)[2] = (guint8)((v) >> 16); \ - (p)[3] = (guint8)((v) >> 24); \ - (p)[4] = (guint8)((v) >> 32); \ - (p)[5] = (guint8)((v) >> 40); \ - (p)[6] = (guint8)((v) >> 48); \ - (p)[7] = (guint8)((v) >> 56); \ + (p)[0] = (uint8_t)((v) >> 0); \ + (p)[1] = (uint8_t)((v) >> 8); \ + (p)[2] = (uint8_t)((v) >> 16); \ + (p)[3] = (uint8_t)((v) >> 24); \ + (p)[4] = (uint8_t)((v) >> 32); \ + (p)[5] = (uint8_t)((v) >> 40); \ + (p)[6] = (uint8_t)((v) >> 48); \ + (p)[7] = (uint8_t)((v) >> 56); \ } #endif -/* glib doesn't have g_ptr_array_len of all things!*/ -#ifndef g_ptr_array_len -#define g_ptr_array_len(a) ((a)->len) -#endif - /* * Read a given number of bytes from a file into a buffer or, if * buf is NULL, just discard them. * - * If we succeed, return TRUE. + * If we succeed, return true. * - * If we get an EOF, return FALSE with *err set to 0, reporting this + * If we get an EOF, return false with *err set to 0, reporting this * as an EOF. * - * If we get fewer bytes than the specified number, return FALSE with + * If we get fewer bytes than the specified number, return false with * *err set to WTAP_ERR_SHORT_READ, reporting this as a short read * error. * - * If we get a read error, return FALSE with *err and *err_info set + * If we get a read error, return false with *err and *err_info set * appropriately. */ WS_DLL_PUBLIC -gboolean +bool wtap_read_bytes_or_eof(FILE_T fh, void *buf, unsigned int count, int *err, - gchar **err_info); + char **err_info); /* * Read a given number of bytes from a file into a buffer or, if * buf is NULL, just discard them. * - * If we succeed, return TRUE. + * If we succeed, return true. * * If we get fewer bytes than the specified number, including getting - * an EOF, return FALSE with *err set to WTAP_ERR_SHORT_READ, reporting + * an EOF, return false with *err set to WTAP_ERR_SHORT_READ, reporting * this as a short read error. * - * If we get a read error, return FALSE with *err and *err_info set + * If we get a read error, return false with *err and *err_info set * appropriately. */ WS_DLL_PUBLIC -gboolean +bool wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err, - gchar **err_info); + char **err_info); /* * Read packet data into a Buffer, growing the buffer as necessary. @@ -325,24 +323,24 @@ wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err, * has been cut short, even if the read didn't read any data at all.) */ WS_DLL_PUBLIC -gboolean -wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err, - gchar **err_info); +bool +wtap_read_packet_bytes(FILE_T fh, Buffer *buf, unsigned length, int *err, + char **err_info); /* * Implementation of wth->subtype_read that reads the full file contents * as a single packet. */ -gboolean +bool wtap_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset); + int *err, char **err_info, int64_t *data_offset); /* * Implementation of wth->subtype_seek_read that reads the full file contents * as a single packet. */ -gboolean -wtap_full_file_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info); +bool +wtap_full_file_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info); /** * Add an IDB to the interface data for a file. @@ -362,12 +360,6 @@ wtapng_process_nrb(wtap *wth, wtap_block_t nrb); void wtapng_process_dsb(wtap *wth, wtap_block_t dsb); -/** - * Invokes the callback with the given Sysdig meta event block. - */ -void -wtapng_process_sysdig_mev(wtap *wth, wtap_block_t mev); - void wtap_register_compatibility_file_subtype_name(const char *old_name, const char *new_name); diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 18432ef2..69056d98 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -7,6 +7,8 @@ */ #include <config.h> +#include "wtap.h" +#include "wtap-int.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP @@ -14,26 +16,24 @@ #include <sys/types.h> -#include "wtap-int.h" #include "wtap_opttypes.h" #include "file_wrappers.h" #include <wsutil/file_util.h> #include <wsutil/buffer.h> #include <wsutil/ws_assert.h> -#include <wsutil/wslog.h> #include <wsutil/exported_pdu_tlvs.h> #ifdef HAVE_PLUGINS #include <wsutil/plugins.h> #endif #ifdef HAVE_PLUGINS -static plugins_t *libwiretap_plugins = NULL; +static plugins_t *libwiretap_plugins; #endif #define PADDING4(x) ((((x + 3) >> 2) << 2) - x) -static GSList *wtap_plugins = NULL; +static GSList *wtap_plugins; #ifdef HAVE_PLUGINS void @@ -60,7 +60,7 @@ wtap_plugins_supported(void) } static void -call_plugin_register_wtap_module(gpointer data, gpointer user_data _U_) +call_plugin_register_wtap_module(void *data, void *user_data _U_) { wtap_plugin *plug = (wtap_plugin *)data; @@ -71,9 +71,9 @@ call_plugin_register_wtap_module(gpointer data, gpointer user_data _U_) /* * Return the size of the file, as reported by the OS. - * (gint64, in case that's 64 bits.) + * (int64_t, in case that's 64 bits.) */ -gint64 +int64_t wtap_file_size(wtap *wth, int *err) { ws_statb64 statb; @@ -102,7 +102,7 @@ wtap_file_type_subtype(wtap *wth) return wth->file_type_subtype; } -guint +unsigned wtap_snapshot_length(wtap *wth) { return wth->snapshot_length; @@ -120,14 +120,14 @@ wtap_file_tsprec(wtap *wth) return wth->file_tsprec; } -guint +unsigned wtap_file_get_num_shbs(wtap *wth) { return wth->shb_hdrs->len; } wtap_block_t -wtap_file_get_shb(wtap *wth, guint shb_num) +wtap_file_get_shb(wtap *wth, unsigned shb_num) { if ((wth == NULL) || (wth->shb_hdrs == NULL) || (shb_num >= wth->shb_hdrs->len)) return NULL; @@ -135,17 +135,28 @@ wtap_file_get_shb(wtap *wth, guint shb_num) return g_array_index(wth->shb_hdrs, wtap_block_t, shb_num); } +unsigned +wtap_file_get_shb_global_interface_id(wtap *wth, unsigned shb_num, uint32_t interface_id) +{ + if ((wth == NULL) || (wth->shb_hdrs == NULL) || (shb_num >= wth->shb_hdrs->len)) { + ws_warning("unexpected SHB %u and interface id %u", shb_num, interface_id); + return interface_id; + } + + return interface_id + g_array_index(wth->shb_iface_to_global, unsigned, shb_num); +} + GArray* wtap_file_get_shb_for_new_file(wtap *wth) { - guint shb_count; + unsigned shb_count; wtap_block_t shb_hdr_src, shb_hdr_dest; GArray* shb_hdrs; if ((wth == NULL) || (wth->shb_hdrs == NULL) || (wth->shb_hdrs->len == 0)) return NULL; - shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + shb_hdrs = g_array_new(false, false, sizeof(wtap_block_t)); for (shb_count = 0; shb_count < wth->shb_hdrs->len; shb_count++) { shb_hdr_src = g_array_index(wth->shb_hdrs, wtap_block_t, shb_count); @@ -160,10 +171,10 @@ wtap_file_get_shb_for_new_file(wtap *wth) * XXX - replace with APIs that let us handle multiple comments. */ void -wtap_write_shb_comment(wtap *wth, gchar *comment) +wtap_write_shb_comment(wtap *wth, char *comment) { if ((wth != NULL) && (wth->shb_hdrs != NULL) && (wth->shb_hdrs->len > 0)) { - wtap_block_set_nth_string_option_value(g_array_index(wth->shb_hdrs, wtap_block_t, 0), OPT_COMMENT, 0, comment, (gsize)(comment ? strlen(comment) : 0)); + wtap_block_set_nth_string_option_value(g_array_index(wth->shb_hdrs, wtap_block_t, 0), OPT_COMMENT, 0, comment, (size_t)(comment ? strlen(comment) : 0)); } } @@ -202,43 +213,61 @@ wtap_get_next_interface_description(wtap *wth) return NULL; } +unsigned +wtap_file_get_num_dsbs(wtap *wth) +{ + if (!wth->dsbs) { + return 0; + } + return wth->dsbs->len; +} + +wtap_block_t +wtap_file_get_dsb(wtap *wth, unsigned dsb_num) +{ + if ((wth == NULL) || (wth->dsbs == NULL) || (dsb_num >= wth->dsbs->len)) + return NULL; + + return g_array_index(wth->dsbs, wtap_block_t, dsb_num); +} + void wtap_file_add_decryption_secrets(wtap *wth, const wtap_block_t dsb) { if (!wth->dsbs) { - wth->dsbs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + wth->dsbs = g_array_new(false, false, sizeof(wtap_block_t)); } g_array_append_val(wth->dsbs, dsb); } -gboolean +bool wtap_file_discard_decryption_secrets(wtap *wth) { if (!wth->dsbs || wth->dsbs->len == 0) - return FALSE; + return false; wtap_block_array_free(wth->dsbs); wth->dsbs = NULL; - return TRUE; + return true; } void -wtap_file_add_sysdig_meta_event(wtap *wth, const wtap_block_t mev) +wtap_file_add_meta_event(wtap *wth, const wtap_block_t mev) { - if (!wth->sysdig_meta_events) { - wth->sysdig_meta_events = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + if (!wth->meta_events) { + wth->meta_events = g_array_new(false, false, sizeof(wtap_block_t)); } - g_array_append_val(wth->sysdig_meta_events, mev); + g_array_append_val(wth->meta_events, mev); } -gboolean -wtap_file_discard_sysdig_meta_events(wtap *wth) +bool +wtap_file_discard_meta_events(wtap *wth) { - if (!wth->sysdig_meta_events || wth->sysdig_meta_events->len == 0) + if (!wth->meta_events || wth->meta_events->len == 0) return false; - wtap_block_array_free(wth->sysdig_meta_events); - wth->sysdig_meta_events = NULL; + wtap_block_array_free(wth->meta_events); + wth->meta_events = NULL; return true; } @@ -340,7 +369,7 @@ wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info) g_free(idb_info); } -gchar * +char * wtap_get_debug_if_descr(const wtap_block_t if_descr, const int indent, const char* line_end) @@ -348,9 +377,9 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr, char* tmp_content; wtapng_if_descr_mandatory_t* if_descr_mand; GString *info = g_string_new(""); - gint64 itmp64; - guint64 tmp64; - guint8 tmp8; + int64_t itmp64; + uint64_t tmp64; + uint8_t tmp8; if_filter_opt_t if_filter; ws_assert(if_descr); @@ -423,7 +452,7 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr, if (wtap_block_get_int64_option_value(if_descr, OPT_IDB_TSOFFSET, &itmp64) == WTAP_OPTTYPE_SUCCESS) { g_string_append_printf(info, - "%*cTimestamp offset = %" G_GINT64_FORMAT "%s", indent, ' ', + "%*cTimestamp offset = %" PRId64 "%s", indent, ' ', itmp64, line_end); } @@ -491,14 +520,14 @@ wtap_file_get_nrb(wtap *wth) GArray* wtap_file_get_nrb_for_new_file(wtap *wth) { - guint nrb_count; + unsigned nrb_count; wtap_block_t nrb_src, nrb_dest; GArray* nrbs; if ((wth == NULL || wth->nrbs == NULL) || (wth->nrbs->len == 0)) return NULL; - nrbs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + nrbs = g_array_new(false, false, sizeof(wtap_block_t)); for (nrb_count = 0; nrb_count < wth->nrbs->len; nrb_count++) { nrb_src = g_array_index(wth->nrbs, wtap_block_t, nrb_count); @@ -524,10 +553,11 @@ wtap_dump_params_init(wtap_dump_params *params, wtap *wth) /* Assume that the input handle remains open until the dumper is closed. * Refer to the DSBs from the input file, wtap_dump will then copy DSBs * as they become available. */ + params->shb_iface_to_global = wth->shb_iface_to_global; params->nrbs_growing = wth->nrbs; params->dsbs_growing = wth->dsbs; - params->sysdig_mev_growing = wth->sysdig_meta_events; - params->dont_copy_idbs = FALSE; + params->mevs_growing = wth->meta_events; + params->dont_copy_idbs = false; } /* @@ -549,9 +579,10 @@ wtap_dump_params_init_no_idbs(wtap_dump_params *params, wtap *wth) /* Assume that the input handle remains open until the dumper is closed. * Refer to the DSBs from the input file, wtap_dump will then copy DSBs * as they become available. */ + params->shb_iface_to_global = wth->shb_iface_to_global; params->nrbs_growing = wth->nrbs; params->dsbs_growing = wth->dsbs; - params->dont_copy_idbs = TRUE; + params->dont_copy_idbs = true; } void @@ -568,9 +599,9 @@ wtap_dump_params_discard_decryption_secrets(wtap_dump_params *params) } void -wtap_dump_params_discard_sysdig_meta_events(wtap_dump_params *params) +wtap_dump_params_discard_meta_events(wtap_dump_params *params) { - params->sysdig_mev_growing = NULL; + params->mevs_growing = NULL; } void @@ -1266,11 +1297,17 @@ static struct encap_type_info encap_table_base[] = { /* WTAP_ENCAP_MDB */ { "mdb", "MDB (Multi-Drop Bus)"}, + + /* WTAP_ENCAP_EMS */ + { "ems", "EMS (EGNOS Message Server) file"}, + + /* WTAP_ENCAP_DECT_NR */ + { "dect_nr", "DECT-2020 New Radio (NR) MAC layer" }, }; WS_DLL_LOCAL -gint wtap_num_encap_types = sizeof(encap_table_base) / sizeof(struct encap_type_info); -static GArray* encap_table_arr = NULL; +int wtap_num_encap_types = array_length(encap_table_base); +static GArray* encap_table_arr; #define encap_table_entry(encap) \ g_array_index(encap_table_arr, struct encap_type_info, encap) @@ -1279,14 +1316,14 @@ static void wtap_init_encap_types(void) { if (encap_table_arr) return; - encap_table_arr = g_array_new(FALSE,TRUE,sizeof(struct encap_type_info)); + encap_table_arr = g_array_new(false,true,sizeof(struct encap_type_info)); g_array_append_vals(encap_table_arr,encap_table_base,wtap_num_encap_types); } static void wtap_cleanup_encap_types(void) { if (encap_table_arr) { - g_array_free(encap_table_arr, TRUE); + g_array_free(encap_table_arr, true); encap_table_arr = NULL; } } @@ -1464,7 +1501,7 @@ static const char *wtap_errlist[] = { /* WTAP_ERR_TIME_STAMP_NOT_SUPPORTED */ "We don't support writing that record's time stamp to that file type", }; -#define WTAP_ERRLIST_SIZE (sizeof wtap_errlist / sizeof wtap_errlist[0]) +#define WTAP_ERRLIST_SIZE array_length(wtap_errlist) const char * wtap_strerror(int err) @@ -1506,7 +1543,7 @@ wtap_sequential_close(wtap *wth) } static void -g_fast_seek_item_free(gpointer data, gpointer user_data _U_) +g_fast_seek_item_free(void *data, void *user_data _U_) { g_free(data); } @@ -1543,14 +1580,15 @@ wtap_close(wtap *wth) if (wth->fast_seek != NULL) { g_ptr_array_foreach(wth->fast_seek, g_fast_seek_item_free, NULL); - g_ptr_array_free(wth->fast_seek, TRUE); + g_ptr_array_free(wth->fast_seek, true); } wtap_block_array_free(wth->shb_hdrs); wtap_block_array_free(wth->nrbs); + g_array_free(wth->shb_iface_to_global, true); wtap_block_array_free(wth->interface_data); wtap_block_array_free(wth->dsbs); - wtap_block_array_free(wth->sysdig_meta_events); + wtap_block_array_free(wth->meta_events); g_free(wth); } @@ -1569,7 +1607,7 @@ wtapng_process_nrb_ipv4(wtap *wth, wtap_block_t nrb) if (wth->add_new_ipv4) { for (GList *elem = nrb_mand->ipv4_addr_list; elem != NULL; elem = elem->next) { hashipv4_t *tp = elem->data; - wth->add_new_ipv4(tp->addr, tp->name, FALSE); + wth->add_new_ipv4(tp->addr, tp->name, false); } } } @@ -1582,7 +1620,7 @@ wtapng_process_nrb_ipv6(wtap *wth, wtap_block_t nrb) if (wth->add_new_ipv6) { for (GList *elem = nrb_mand->ipv6_addr_list; elem != NULL; elem = elem->next) { hashipv6_t *tp = elem->data; - wth->add_new_ipv6(tp->addr, tp->name, FALSE); + wth->add_new_ipv6(tp->addr, tp->name, false); } } } @@ -1601,7 +1639,7 @@ void wtap_set_cb_new_ipv4(wtap *wth, wtap_new_ipv4_callback_t add_new_ipv4) { * relies on this to support redissection (during redissection, the * previous name resolutions are lost and has to be resupplied). */ - for (guint i = 0; i < wth->nrbs->len; i++) { + for (unsigned i = 0; i < wth->nrbs->len; i++) { wtap_block_t nrb = g_array_index(wth->nrbs, wtap_block_t, i); wtapng_process_nrb_ipv4(wth, nrb); } @@ -1621,7 +1659,7 @@ void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6) { * relies on this to support redissection (during redissection, the * previous name resolutions are lost and has to be resupplied). */ - for (guint i = 0; i < wth->nrbs->len; i++) { + for (unsigned i = 0; i < wth->nrbs->len; i++) { wtap_block_t nrb = g_array_index(wth->nrbs, wtap_block_t, i); wtapng_process_nrb_ipv6(wth, nrb); } @@ -1645,7 +1683,7 @@ void wtap_set_cb_new_secrets(wtap *wth, wtap_new_secrets_callback_t add_new_secr * relies on this to support redissection (during redissection, the * previous secrets are lost and has to be resupplied). */ - for (guint i = 0; i < wth->dsbs->len; i++) { + for (unsigned i = 0; i < wth->dsbs->len; i++) { wtap_block_t dsb = g_array_index(wth->dsbs, wtap_block_t, i); wtapng_process_dsb(wth, dsb); } @@ -1660,15 +1698,6 @@ wtapng_process_dsb(wtap *wth, wtap_block_t dsb) wth->add_new_secrets(dsb_mand->secrets_type, dsb_mand->secrets_data, dsb_mand->secrets_len); } -void -wtapng_process_sysdig_meta_event(wtap *wth, wtap_block_t mev) -{ - const wtapng_sysdig_mev_mandatory_t *mev_mand = (wtapng_sysdig_mev_mandatory_t*)wtap_block_get_mandatory_data(mev); - - if (wth->add_new_sysdig_meta_event) - wth->add_new_sysdig_meta_event(mev_mand->mev_type, mev_mand->mev_data, mev_mand->mev_data_len); -} - /* Perform per-packet initialization */ static void wtap_init_rec(wtap *wth, wtap_rec *rec) @@ -1686,7 +1715,7 @@ wtap_init_rec(wtap *wth, wtap_rec *rec) rec->rec_header.packet_header.pkt_encap = wth->file_encap; rec->tsprec = wth->file_tsprec; rec->block = NULL; - rec->block_was_modified = FALSE; + rec->block_was_modified = false; /* * Assume the file has only one section; the module for the @@ -1696,9 +1725,9 @@ wtap_init_rec(wtap *wth, wtap_rec *rec) rec->section_number = 0; } -gboolean +bool wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *offset) + char **err_info, int64_t *offset) { /* * Initialize the record to default values. @@ -1727,7 +1756,7 @@ wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, wtap_block_unref(rec->block); rec->block = NULL; } - return FALSE; /* failure */ + return false; /* failure */ } /* @@ -1744,68 +1773,68 @@ wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, ws_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_NONE); } - return TRUE; /* success */ + return true; /* success */ } /* * Read a given number of bytes from a file into a buffer or, if * buf is NULL, just discard them. * - * If we succeed, return TRUE. + * If we succeed, return true. * - * If we get an EOF, return FALSE with *err set to 0, reporting this + * If we get an EOF, return false with *err set to 0, reporting this * as an EOF. * - * If we get fewer bytes than the specified number, return FALSE with + * If we get fewer bytes than the specified number, return false with * *err set to WTAP_ERR_SHORT_READ, reporting this as a short read * error. * - * If we get a read error, return FALSE with *err and *err_info set + * If we get a read error, return false with *err and *err_info set * appropriately. */ -gboolean +bool wtap_read_bytes_or_eof(FILE_T fh, void *buf, unsigned int count, int *err, - gchar **err_info) + char **err_info) { int bytes_read; bytes_read = file_read(buf, count, fh); - if (bytes_read < 0 || (guint)bytes_read != count) { + if (bytes_read < 0 || (unsigned)bytes_read != count) { *err = file_error(fh, err_info); if (*err == 0 && bytes_read > 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } /* * Read a given number of bytes from a file into a buffer or, if * buf is NULL, just discard them. * - * If we succeed, return TRUE. + * If we succeed, return true. * * If we get fewer bytes than the specified number, including getting - * an EOF, return FALSE with *err set to WTAP_ERR_SHORT_READ, reporting + * an EOF, return false with *err set to WTAP_ERR_SHORT_READ, reporting * this as a short read error. * - * If we get a read error, return FALSE with *err and *err_info set + * If we get a read error, return false with *err and *err_info set * appropriately. */ -gboolean +bool wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err, - gchar **err_info) + char **err_info) { int bytes_read; bytes_read = file_read(buf, count, fh); - if (bytes_read < 0 || (guint)bytes_read != count) { + if (bytes_read < 0 || (unsigned)bytes_read != count) { *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return FALSE; + return false; } - return TRUE; + return true; } /* @@ -1817,11 +1846,11 @@ wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err, * header, so if we get an EOF trying to read the packet data, the file * has been cut short, even if the read didn't read any data at all.) */ -gboolean -wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err, - gchar **err_info) +bool +wtap_read_packet_bytes(FILE_T fh, Buffer *buf, unsigned length, int *err, + char **err_info) { - gboolean rv; + bool rv; ws_buffer_assure_space(buf, length); rv = wtap_read_bytes(fh, ws_buffer_end_ptr(buf), length, err, err_info); @@ -1833,9 +1862,9 @@ wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err, /* * Return an approximation of the amount of data we've read sequentially - * from the file so far. (gint64, in case that's 64 bits.) + * from the file so far. (int64_t, in case that's 64 bits.) */ -gint64 +int64_t wtap_read_so_far(wtap *wth) { return file_tell_raw(wth->fh); @@ -1859,7 +1888,7 @@ wtap_rec_reset(wtap_rec *rec) { wtap_block_unref(rec->block); rec->block = NULL; - rec->block_was_modified = FALSE; + rec->block_was_modified = false; } /* clean up record metadata */ @@ -1884,9 +1913,9 @@ wtap_rec_generate_idb(const wtap_rec *rec) return wtap_generate_idb(rec->rec_header.packet_header.pkt_encap, tsprec, 0); } -gboolean -wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +bool +wtap_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { /* * Initialize the record to default values. @@ -1904,7 +1933,7 @@ wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, wtap_block_unref(rec->block); rec->block = NULL; } - return FALSE; + return false; } /* @@ -1921,27 +1950,27 @@ wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, ws_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_NONE); } - return TRUE; + return true; } -static gboolean -wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +static bool +wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { - gint64 file_size; + int64_t file_size; int packet_size = 0; const int block_size = 1024 * 1024; if ((file_size = wtap_file_size(wth, err)) == -1) - return FALSE; + return false; - if (file_size > G_MAXINT) { + if (file_size > INT_MAX) { /* * Avoid allocating space for an immensely-large file. */ *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("%s: File has %" PRId64 "-byte packet, bigger than maximum of %u", - wtap_encap_name(wth->file_encap), file_size, G_MAXINT); - return FALSE; + wtap_encap_name(wth->file_encap), file_size, INT_MAX); + return false; } /* @@ -1954,8 +1983,8 @@ wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int * if (buffer_size <= 0) { *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("%s: Uncompressed file is bigger than maximum of %u", - wtap_encap_name(wth->file_encap), G_MAXINT); - return FALSE; + wtap_encap_name(wth->file_encap), INT_MAX); + return false; } ws_buffer_assure_space(buf, buffer_size); int nread = file_read(ws_buffer_start_ptr(buf) + packet_size, buffer_size - packet_size, fh); @@ -1963,7 +1992,7 @@ wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int * *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_BAD_FILE; - return FALSE; + return false; } packet_size += nread; if (packet_size != buffer_size) { @@ -1980,46 +2009,46 @@ wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int * rec->rec_header.packet_header.caplen = packet_size; rec->rec_header.packet_header.len = packet_size; - return TRUE; + return true; } -gboolean +bool wtap_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *data_offset) + int *err, char **err_info, int64_t *data_offset) { - gint64 offset = file_tell(wth->fh); + int64_t offset = file_tell(wth->fh); /* There is only one packet with the full file contents. */ if (offset != 0) { *err = 0; - return FALSE; + return false; } *data_offset = offset; return wtap_full_file_read_file(wth, wth->fh, rec, buf, err, err_info); } -gboolean -wtap_full_file_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) +bool +wtap_full_file_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info) { /* There is only one packet with the full file contents. */ if (seek_off > 0) { *err = 0; - return FALSE; + return false; } if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; + return false; return wtap_full_file_read_file(wth, wth->random_fh, rec, buf, err, err_info); } void -wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, const guint8 *data, guint16 data_len) +wtap_buffer_append_epdu_tag(Buffer *buf, uint16_t epdu_tag, const uint8_t *data, uint16_t data_len) { - guint8 pad_len = 0; - guint space_needed = 4; /* 2 for tag field, 2 for length field */ - guint8 *buf_data; + uint8_t pad_len = 0; + unsigned space_needed = 4; /* 2 for tag field, 2 for length field */ + uint8_t *buf_data; if (epdu_tag != 0 && data != NULL && data_len != 0) { pad_len += PADDING4(data_len); @@ -2046,10 +2075,10 @@ wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, const guint8 *data, g } void -wtap_buffer_append_epdu_uint(Buffer *buf, guint16 epdu_tag, guint32 val) +wtap_buffer_append_epdu_uint(Buffer *buf, uint16_t epdu_tag, uint32_t val) { - const guint space_needed = 8; /* 2 for tag field, 2 for length field, 4 for value */ - guint8 *buf_data; + const unsigned space_needed = 8; /* 2 for tag field, 2 for length field, 4 for value */ + uint8_t *buf_data; ws_assert(epdu_tag != 0); ws_buffer_assure_space(buf, space_needed); @@ -2062,41 +2091,41 @@ wtap_buffer_append_epdu_uint(Buffer *buf, guint16 epdu_tag, guint32 val) } void -wtap_buffer_append_epdu_string(Buffer *buf, guint16 epdu_tag, const char *val) +wtap_buffer_append_epdu_string(Buffer *buf, uint16_t epdu_tag, const char *val) { size_t string_len; string_len = strlen(val); /* - * Cut off string length at G_MAXUINT16. + * Cut off string length at UINT16_MAX. * * XXX - make sure we don't leave an incomplete UTF-8 * sequence at the end. */ - if (string_len > G_MAXUINT16) - string_len = G_MAXUINT16; - wtap_buffer_append_epdu_tag(buf, epdu_tag, val, (guint16) string_len); + if (string_len > UINT16_MAX) + string_len = UINT16_MAX; + wtap_buffer_append_epdu_tag(buf, epdu_tag, val, (uint16_t) string_len); } -gint +int wtap_buffer_append_epdu_end(Buffer *buf) { - const guint space_needed = 4; /* 2 for tag (=0000), 2 for length field (=0) */ - guint8 *buf_data; + const unsigned space_needed = 4; /* 2 for tag (=0000), 2 for length field (=0) */ + uint8_t *buf_data; ws_buffer_assure_space(buf, space_needed); buf_data = ws_buffer_end_ptr(buf); memset(buf_data, 0, space_needed); ws_buffer_increase_length(buf, space_needed); - return (gint)ws_buffer_length(buf); + return (int)ws_buffer_length(buf); } /* * Initialize the library. */ void -wtap_init(gboolean load_wiretap_plugins) +wtap_init(bool load_wiretap_plugins) { init_open_routines(); wtap_opttypes_initialize(); diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 2b25c03f..31a1a9eb 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -310,6 +310,8 @@ extern "C" { #define WTAP_ENCAP_FIRA_UCI 221 #define WTAP_ENCAP_SILABS_DEBUG_CHANNEL 222 #define WTAP_ENCAP_MDB 223 +#define WTAP_ENCAP_EMS 224 +#define WTAP_ENCAP_DECT_NR 225 /* After adding new item here, please also add new item to encap_table_base array */ @@ -386,22 +388,22 @@ extern "C" { /* Packet "pseudo-header" information for Ethernet capture files. */ struct eth_phdr { - gint fcs_len; /* Number of bytes of FCS - -1 means "unknown" */ + int fcs_len; /* Number of bytes of FCS - -1 means "unknown" */ }; /* Packet "pseudo-header" information for capture files for traffic between DTE and DCE. */ #define FROM_DCE 0x80 struct dte_dce_phdr { - guint8 flags; /* ENCAP_LAPB, ENCAP_V120, ENCAP_FRELAY: 1st bit means From DCE */ + uint8_t flags; /* ENCAP_LAPB, ENCAP_V120, ENCAP_FRELAY: 1st bit means From DCE */ }; /* Packet "pseudo-header" information for ISDN capture files. */ /* Direction */ struct isdn_phdr { - gboolean uton; - guint8 channel; /* 0 = D-channel; n = B-channel n */ + bool uton; + uint8_t channel; /* 0 = D-channel; n = B-channel n */ }; /* Packet "pseudo-header" for ATM capture files. @@ -413,10 +415,10 @@ struct isdn_phdr { /* * Status bits. */ -#define ATM_RAW_CELL 0x01 /* TRUE if the packet is a single cell */ -#define ATM_NO_HEC 0x02 /* TRUE if the cell has HEC stripped out */ -#define ATM_AAL2_NOPHDR 0x04 /* TRUE if the AAL2 PDU has no pseudo-header */ -#define ATM_REASSEMBLY_ERROR 0x08 /* TRUE if this is an incompletely-reassembled PDU */ +#define ATM_RAW_CELL 0x01 /* true if the packet is a single cell */ +#define ATM_NO_HEC 0x02 /* true if the cell has HEC stripped out */ +#define ATM_AAL2_NOPHDR 0x04 /* true if the AAL2 PDU has no pseudo-header */ +#define ATM_REASSEMBLY_ERROR 0x08 /* true if this is an incompletely-reassembled PDU */ /* * AAL types. @@ -483,18 +485,18 @@ struct isdn_phdr { #define TRAF_ST_IPSILON_FT2 3 /* Ipsilon: Flow Type 2 */ struct atm_phdr { - guint32 flags; /* status flags */ - guint8 aal; /* AAL of the traffic */ - guint8 type; /* traffic type */ - guint8 subtype; /* traffic subtype */ - guint16 vpi; /* virtual path identifier */ - guint16 vci; /* virtual circuit identifier */ - guint8 aal2_cid; /* channel id */ - guint16 channel; /* link: 0 for DTE->DCE, 1 for DCE->DTE */ - guint16 cells; /* number of cells */ - guint16 aal5t_u2u; /* user-to-user indicator */ - guint16 aal5t_len; /* length of the packet */ - guint32 aal5t_chksum; /* checksum for AAL5 packet */ + uint32_t flags; /* status flags */ + uint8_t aal; /* AAL of the traffic */ + uint8_t type; /* traffic type */ + uint8_t subtype; /* traffic subtype */ + uint16_t vpi; /* virtual path identifier */ + uint16_t vci; /* virtual circuit identifier */ + uint8_t aal2_cid; /* channel id */ + uint16_t channel; /* link: 0 for DTE->DCE, 1 for DCE->DTE */ + uint16_t cells; /* number of cells */ + uint16_t aal5t_u2u; /* user-to-user indicator */ + uint16_t aal5t_len; /* length of the packet */ + uint32_t aal5t_chksum; /* checksum for AAL5 packet */ }; /* Packet "pseudo-header" for the output from "wandsession", "wannext", @@ -510,17 +512,17 @@ struct atm_phdr { #define ASCEND_PFX_ETHER 6 struct ascend_phdr { - guint16 type; /* ASCEND_PFX_*, as defined above */ + uint16_t type; /* ASCEND_PFX_*, as defined above */ char user[ASCEND_MAX_STR_LEN]; /* Username, from wandsession header */ - guint32 sess; /* Session number, from wandsession header */ + uint32_t sess; /* Session number, from wandsession header */ char call_num[ASCEND_MAX_STR_LEN]; /* Called number, from WDD header */ - guint32 chunk; /* Chunk number, from WDD header */ - guint32 task; /* Task number */ + uint32_t chunk; /* Chunk number, from WDD header */ + uint32_t task; /* Task number */ }; /* Packet "pseudo-header" for point-to-point links with direction flags. */ struct p2p_phdr { - gboolean sent; + bool sent; }; /* @@ -573,13 +575,13 @@ struct p2p_phdr { * 802.11 legacy FHSS. */ struct ieee_802_11_fhss { - guint has_hop_set:1; - guint has_hop_pattern:1; - guint has_hop_index:1; + unsigned has_hop_set:1; + unsigned has_hop_pattern:1; + unsigned has_hop_index:1; - guint8 hop_set; /* Hop set */ - guint8 hop_pattern; /* Hop pattern */ - guint8 hop_index; /* Hop index */ + uint8_t hop_set; /* Hop set */ + uint8_t hop_pattern; /* Hop pattern */ + uint8_t hop_index; /* Hop index */ }; /* @@ -587,9 +589,9 @@ struct ieee_802_11_fhss { */ struct ieee_802_11b { /* Which of this information is present? */ - guint has_short_preamble:1; + unsigned has_short_preamble:1; - gboolean short_preamble; /* Short preamble */ + bool short_preamble; /* Short preamble */ }; /* @@ -597,11 +599,11 @@ struct ieee_802_11b { */ struct ieee_802_11a { /* Which of this information is present? */ - guint has_channel_type:1; - guint has_turbo_type:1; + unsigned has_channel_type:1; + unsigned has_turbo_type:1; - guint channel_type:2; - guint turbo_type:2; + unsigned channel_type:2; + unsigned turbo_type:2; }; /* @@ -633,9 +635,9 @@ struct ieee_802_11a { */ struct ieee_802_11g { /* Which of this information is present? */ - guint has_mode:1; + unsigned has_mode:1; - guint32 mode; /* Various proprietary extensions */ + uint32_t mode; /* Various proprietary extensions */ }; /* @@ -649,21 +651,21 @@ struct ieee_802_11g { */ struct ieee_802_11n { /* Which of this information is present? */ - guint has_mcs_index:1; - guint has_bandwidth:1; - guint has_short_gi:1; - guint has_greenfield:1; - guint has_fec:1; - guint has_stbc_streams:1; - guint has_ness:1; - - guint16 mcs_index; /* MCS index */ - guint bandwidth; /* Bandwidth = 20 MHz, 40 MHz, etc. */ - guint short_gi:1; /* True for short guard interval */ - guint greenfield:1; /* True for greenfield, short for mixed */ - guint fec:1; /* FEC: 0 = BCC, 1 = LDPC */ - guint stbc_streams:2; /* Number of STBC streams */ - guint ness; /* Number of extension spatial streams */ + unsigned has_mcs_index:1; + unsigned has_bandwidth:1; + unsigned has_short_gi:1; + unsigned has_greenfield:1; + unsigned has_fec:1; + unsigned has_stbc_streams:1; + unsigned has_ness:1; + + uint16_t mcs_index; /* MCS index */ + unsigned bandwidth; /* Bandwidth = 20 MHz, 40 MHz, etc. */ + unsigned short_gi:1; /* True for short guard interval */ + unsigned greenfield:1; /* True for greenfield, short for mixed */ + unsigned fec:1; /* FEC: 0 = BCC, 1 = LDPC */ + unsigned stbc_streams:2; /* Number of STBC streams */ + unsigned ness; /* Number of extension spatial streams */ }; /* @@ -701,29 +703,29 @@ struct ieee_802_11n { */ struct ieee_802_11ac { /* Which of this information is present? */ - guint has_stbc:1; - guint has_txop_ps_not_allowed:1; - guint has_short_gi:1; - guint has_short_gi_nsym_disambig:1; - guint has_ldpc_extra_ofdm_symbol:1; - guint has_beamformed:1; - guint has_bandwidth:1; - guint has_fec:1; - guint has_group_id:1; - guint has_partial_aid:1; - - guint stbc:1; /* 1 if all spatial streams have STBC */ - guint txop_ps_not_allowed:1; - guint short_gi:1; /* True for short guard interval */ - guint short_gi_nsym_disambig:1; - guint ldpc_extra_ofdm_symbol:1; - guint beamformed:1; - guint8 bandwidth; /* Bandwidth = 20 MHz, 40 MHz, etc. */ - guint8 mcs[4]; /* MCS index per user */ - guint8 nss[4]; /* NSS per user */ - guint8 fec; /* Bit array of FEC per user: 0 = BCC, 1 = LDPC */ - guint8 group_id; - guint16 partial_aid; + unsigned has_stbc:1; + unsigned has_txop_ps_not_allowed:1; + unsigned has_short_gi:1; + unsigned has_short_gi_nsym_disambig:1; + unsigned has_ldpc_extra_ofdm_symbol:1; + unsigned has_beamformed:1; + unsigned has_bandwidth:1; + unsigned has_fec:1; + unsigned has_group_id:1; + unsigned has_partial_aid:1; + + unsigned stbc:1; /* 1 if all spatial streams have STBC */ + unsigned txop_ps_not_allowed:1; + unsigned short_gi:1; /* True for short guard interval */ + unsigned short_gi_nsym_disambig:1; + unsigned ldpc_extra_ofdm_symbol:1; + unsigned beamformed:1; + uint8_t bandwidth; /* Bandwidth = 20 MHz, 40 MHz, etc. */ + uint8_t mcs[4]; /* MCS index per user */ + uint8_t nss[4]; /* NSS per user */ + uint8_t fec; /* Bit array of FEC per user: 0 = BCC, 1 = LDPC */ + uint8_t group_id; + uint16_t partial_aid; }; /* @@ -742,9 +744,9 @@ struct ieee_802_11ac { struct ieee_802_11ad { /* Which of this information is present? */ - guint has_mcs_index:1; + unsigned has_mcs_index:1; - guint8 mcs; /* MCS index */ + uint8_t mcs; /* MCS index */ }; /* @@ -752,16 +754,52 @@ struct ieee_802_11ad { */ struct ieee_802_11ax { /* Which of this information is present? */ - guint has_mcs_index:1; - guint has_bwru:1; - guint has_gi:1; - - guint8 nsts:4; /* Number of Space-time Streams */ - guint8 mcs:4; /* MCS index */ - guint8 bwru:4; /* Bandwidth/RU allocation */ - guint8 gi:2; /* Guard Interval */ + unsigned has_mcs_index:1; + unsigned has_bwru:1; + unsigned has_gi:1; + + uint8_t nsts:4; /* Number of Space-time Streams */ + uint8_t mcs:4; /* MCS index */ + uint8_t bwru:4; /* Bandwidth/RU allocation */ + uint8_t gi:2; /* Guard Interval */ }; +/* + * 802.11be (EHT). + */ +struct ieee_802_11be_user_info { + unsigned sta_id_known:1; + unsigned mcs_known:1; + unsigned coding_known:1; + unsigned rsv_known:1; + unsigned nsts_known:1; + unsigned bf_known:1; + unsigned spatial_config_known:1; + unsigned data_for_this_user:1; + unsigned sta_id:11; + unsigned ldpc_coding:1; + unsigned mcs:4; + unsigned nsts:4; + unsigned rsv:1; + unsigned beamform:1; + unsigned rsv2:2; +}; + +#define PHDR_802_11BE_MAX_USERS 4 +struct ieee_802_11be { + /* Which of this information is present? */ + unsigned has_ru_mru_size:1; + unsigned has_gi:1; + unsigned has_bandwidth:1; + + uint8_t bandwidth; + uint8_t ru_mru_size:4; /* RU/MRU allocation */ + uint8_t gi:2; /* Guard Interval */ + uint8_t num_users; + struct ieee_802_11be_user_info user[PHDR_802_11BE_MAX_USERS]; /* Adding info for only upto 4 users */ +}; + + union ieee_802_11_phy_info { struct ieee_802_11_fhss info_11_fhss; struct ieee_802_11b info_11b; @@ -771,43 +809,44 @@ union ieee_802_11_phy_info { struct ieee_802_11ac info_11ac; struct ieee_802_11ad info_11ad; struct ieee_802_11ax info_11ax; + struct ieee_802_11be info_11be; }; struct ieee_802_11_phdr { - gint fcs_len; /* Number of bytes of FCS - -1 means "unknown" */ - guint decrypted:1; /* TRUE if frame is decrypted even if "protected" bit is set */ - guint datapad:1; /* TRUE if frame has padding between 802.11 header and payload */ - guint no_a_msdus:1; /* TRUE if we should ignore the A-MSDU bit */ - guint phy; /* PHY type */ + int fcs_len; /* Number of bytes of FCS - -1 means "unknown" */ + unsigned decrypted:1; /* true if frame is decrypted even if "protected" bit is set */ + unsigned datapad:1; /* true if frame has padding between 802.11 header and payload */ + unsigned no_a_msdus:1; /* true if we should ignore the A-MSDU bit */ + unsigned phy; /* PHY type */ union ieee_802_11_phy_info phy_info; /* Which of this information is present? */ - guint has_channel:1; - guint has_frequency:1; - guint has_data_rate:1; - guint has_signal_percent:1; - guint has_noise_percent:1; - guint has_signal_dbm:1; - guint has_noise_dbm:1; - guint has_signal_db:1; - guint has_noise_db:1; - guint has_tsf_timestamp:1; - guint has_aggregate_info:1; /* aggregate flags and ID */ - guint has_zero_length_psdu_type:1; /* zero-length PSDU type */ - - guint16 channel; /* Channel number */ - guint32 frequency; /* Channel center frequency */ - guint16 data_rate; /* Data rate, in .5 Mb/s units */ - guint8 signal_percent; /* Signal level, as a percentage */ - guint8 noise_percent; /* Noise level, as a percentage */ - gint8 signal_dbm; /* Signal level, in dBm */ - gint8 noise_dbm; /* Noise level, in dBm */ - guint8 signal_db; /* Signal level, in dB from an arbitrary point */ - guint8 noise_db; /* Noise level, in dB from an arbitrary point */ - guint64 tsf_timestamp; - guint32 aggregate_flags; /* A-MPDU flags */ - guint32 aggregate_id; /* ID for A-MPDU reassembly */ - guint8 zero_length_psdu_type; /* type of zero-length PSDU */ + unsigned has_channel:1; + unsigned has_frequency:1; + unsigned has_data_rate:1; + unsigned has_signal_percent:1; + unsigned has_noise_percent:1; + unsigned has_signal_dbm:1; + unsigned has_noise_dbm:1; + unsigned has_signal_db:1; + unsigned has_noise_db:1; + unsigned has_tsf_timestamp:1; + unsigned has_aggregate_info:1; /* aggregate flags and ID */ + unsigned has_zero_length_psdu_type:1; /* zero-length PSDU type */ + + uint16_t channel; /* Channel number */ + uint32_t frequency; /* Channel center frequency */ + uint16_t data_rate; /* Data rate, in .5 Mb/s units */ + uint8_t signal_percent; /* Signal level, as a percentage */ + uint8_t noise_percent; /* Noise level, as a percentage */ + int8_t signal_dbm; /* Signal level, in dBm */ + int8_t noise_dbm; /* Noise level, in dBm */ + uint8_t signal_db; /* Signal level, in dB from an arbitrary point */ + uint8_t noise_db; /* Noise level, in dB from an arbitrary point */ + uint64_t tsf_timestamp; + uint32_t aggregate_flags; /* A-MPDU flags */ + uint32_t aggregate_id; /* ID for A-MPDU reassembly */ + uint8_t zero_length_psdu_type; /* type of zero-length PSDU */ }; /* @@ -821,7 +860,6 @@ struct ieee_802_11_phdr { */ #define PHDR_802_11_SOUNDING_PSDU 0 /* sounding PPDU */ #define PHDR_802_11_DATA_NOT_CAPTURED 1 /* data not captured, (e.g. multi-user PPDU) */ -#define PHDR_802_11_0_LENGTH_PSDU_S1G_NDP 2 /* S1G NDP CMAC */ #define PHDR_802_11_0_LENGTH_PSDU_VENDOR_SPECIFIC 0xff /* Packet "pseudo-header" for the output from CoSine L2 debug output. */ @@ -842,14 +880,14 @@ struct ieee_802_11_phdr { #define COSINE_DIR_RX 2 struct cosine_phdr { - guint8 encap; /* COSINE_ENCAP_* as defined above */ - guint8 direction; /* COSINE_DIR_*, as defined above */ + uint8_t encap; /* COSINE_ENCAP_* as defined above */ + uint8_t direction; /* COSINE_DIR_*, as defined above */ char if_name[COSINE_MAX_IF_NAME_LEN]; /* Encap & Logical I/F name */ - guint16 pro; /* Protocol */ - guint16 off; /* Offset */ - guint16 pri; /* Priority */ - guint16 rm; /* Rate Marking */ - guint16 err; /* Error Code */ + uint16_t pro; /* Protocol */ + uint16_t off; /* Offset */ + uint16_t pri; /* Priority */ + uint16_t rm; /* Rate Marking */ + uint16_t err; /* Error Code */ }; /* Packet "pseudo-header" for IrDA capture files. */ @@ -874,17 +912,17 @@ struct cosine_phdr { #define IRDA_CLASS_MASK 0xFF00 struct irda_phdr { - guint16 pkttype; /* packet type */ + uint16_t pkttype; /* packet type */ }; /* Packet "pseudo-header" for nettl (HP-UX) capture files. */ struct nettl_phdr { - guint16 subsys; - guint32 devid; - guint32 kind; - gint32 pid; - guint32 uid; + uint16_t subsys; + uint32_t devid; + uint32_t kind; + int32_t pid; + uint32_t uid; }; /* Packet "pseudo-header" for MTP2 files. */ @@ -894,31 +932,31 @@ struct nettl_phdr { #define MTP2_ANNEX_A_USED_UNKNOWN 2 struct mtp2_phdr { - guint8 sent; - guint8 annex_a_used; - guint16 link_number; + uint8_t sent; + uint8_t annex_a_used; + uint16_t link_number; }; /* Packet "pseudo-header" for K12 files. */ typedef union { struct { - guint16 vp; - guint16 vc; - guint16 cid; + uint16_t vp; + uint16_t vc; + uint16_t cid; } atm; - guint32 ds0mask; + uint32_t ds0mask; } k12_input_info_t; struct k12_phdr { - guint32 input; - const gchar *input_name; - const gchar *stack_file; - guint32 input_type; + uint32_t input; + const char *input_name; + const char *stack_file; + uint32_t input_type; k12_input_info_t input_info; - guint8 *extra_info; - guint32 extra_length; + uint8_t *extra_info; + uint32_t extra_length; void* stuff; }; @@ -927,8 +965,8 @@ struct k12_phdr { #define K12_PORT_ATMPVC 0x01020000 struct lapd_phdr { - guint16 pkttype; /* packet type */ - guint8 we_network; + uint16_t pkttype; /* packet type */ + uint8_t we_network; }; struct wtap; @@ -940,7 +978,7 @@ struct catapult_dct2000_phdr struct atm_phdr atm; struct p2p_phdr p2p; } inner_pseudo_header; - gint64 seek_off; + int64_t seek_off; struct wtap *wth; }; @@ -948,16 +986,16 @@ struct catapult_dct2000_phdr * Endace Record Format pseudo header */ struct erf_phdr { - guint64 ts; /* Time stamp */ - guint8 type; - guint8 flags; - guint16 rlen; - guint16 lctr; - guint16 wlen; + uint64_t ts; /* Time stamp */ + uint8_t type; + uint8_t flags; + uint16_t rlen; + uint16_t lctr; + uint16_t wlen; }; struct erf_ehdr { - guint64 ehdr; + uint64_t ehdr; }; /* @@ -968,8 +1006,8 @@ struct erf_ehdr { #define MAX_ERF_EHDR 16 struct wtap_erf_eth_hdr { - guint8 offset; - guint8 pad; + uint8_t offset; + uint8_t pad; }; struct erf_mc_phdr { @@ -978,8 +1016,8 @@ struct erf_mc_phdr { union { struct wtap_erf_eth_hdr eth_hdr; - guint32 mc_hdr; - guint32 aal2_hdr; + uint32_t mc_hdr; + uint32_t aal2_hdr; } subhdr; }; @@ -1039,17 +1077,17 @@ struct erf_mc_phdr { #define SITA_PROTO_BOP_FRL (0x12) struct sita_phdr { - guint8 sita_flags; - guint8 sita_signals; - guint8 sita_errors1; - guint8 sita_errors2; - guint8 sita_proto; + uint8_t sita_flags; + uint8_t sita_signals; + uint8_t sita_errors1; + uint8_t sita_errors2; + uint8_t sita_proto; }; /*pseudo header for Bluetooth HCI*/ struct bthci_phdr { - gboolean sent; - guint32 channel; + bool sent; + uint32_t channel; }; #define BTHCI_CHANNEL_COMMAND 1 @@ -1060,32 +1098,32 @@ struct bthci_phdr { /* pseudo header for WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR */ struct btmon_phdr { - guint16 adapter_id; - guint16 opcode; + uint16_t adapter_id; + uint16_t opcode; }; /* pseudo header for WTAP_ENCAP_LAYER1_EVENT */ struct l1event_phdr { - gboolean uton; + bool uton; }; /* * I2C pseudo header */ struct i2c_phdr { - guint8 is_event; - guint8 bus; - guint32 flags; + uint8_t is_event; + uint8_t bus; + uint32_t flags; }; /* pseudo header for WTAP_ENCAP_GSM_UM */ struct gsm_um_phdr { - gboolean uplink; - guint8 channel; + bool uplink; + uint8_t channel; /* The following are only populated for downlink */ - guint8 bsic; - guint16 arfcn; - guint32 tdma_frame; - guint8 error; - guint16 timeshift; + uint8_t bsic; + uint16_t arfcn; + uint32_t tdma_frame; + uint8_t error; + uint16_t timeshift; }; #define GSM_UM_CHANNEL_UNKNOWN 0 @@ -1100,51 +1138,51 @@ struct gsm_um_phdr { /* Pseudo-header for nstrace packets */ struct nstr_phdr { - gint64 rec_offset; - gint32 rec_len; - guint8 nicno_offset; - guint8 nicno_len; - guint8 dir_offset; - guint8 dir_len; - guint16 eth_offset; - guint8 pcb_offset; - guint8 l_pcb_offset; - guint8 rec_type; - guint8 vlantag_offset; - guint8 coreid_offset; - guint8 srcnodeid_offset; - guint8 destnodeid_offset; - guint8 clflags_offset; - guint8 src_vmname_len_offset; - guint8 dst_vmname_len_offset; - guint8 ns_activity_offset; - guint8 data_offset; + int64_t rec_offset; + int32_t rec_len; + uint8_t nicno_offset; + uint8_t nicno_len; + uint8_t dir_offset; + uint8_t dir_len; + uint16_t eth_offset; + uint8_t pcb_offset; + uint8_t l_pcb_offset; + uint8_t rec_type; + uint8_t vlantag_offset; + uint8_t coreid_offset; + uint8_t srcnodeid_offset; + uint8_t destnodeid_offset; + uint8_t clflags_offset; + uint8_t src_vmname_len_offset; + uint8_t dst_vmname_len_offset; + uint8_t ns_activity_offset; + uint8_t data_offset; }; /* Packet "pseudo-header" for Nokia output */ struct nokia_phdr { struct eth_phdr eth; - guint8 stuff[4]; /* mysterious stuff */ + uint8_t stuff[4]; /* mysterious stuff */ }; #define LLCP_PHDR_FLAG_SENT 0 struct llcp_phdr { - guint8 adapter; - guint8 flags; + uint8_t adapter; + uint8_t flags; }; /* pseudo header for WTAP_ENCAP_LOGCAT */ struct logcat_phdr { - gint version; + int version; }; /* Packet "pseudo-header" information for header data from NetMon files. */ struct netmon_phdr { - guint8* title; /* Comment title, as a null-terminated UTF-8 string */ - guint32 descLength; /* Number of bytes in the comment description */ - guint8* description; /* Comment description, in ASCII RTF */ - guint sub_encap; /* "Real" encap value for the record that will be used once pseudo header data is display */ + uint8_t* title; /* Comment title, as a null-terminated UTF-8 string */ + uint32_t descLength; /* Number of bytes in the comment description */ + uint8_t* description; /* Comment description, in ASCII RTF */ + unsigned sub_encap; /* "Real" encap value for the record that will be used once pseudo header data is display */ union sub_wtap_pseudo_header { struct eth_phdr eth; struct atm_phdr atm; @@ -1247,11 +1285,11 @@ union wtap_pseudo_header { #define REC_TYPE_CUSTOM_BLOCK 5 /**< pcapng custom block */ typedef struct { - guint32 caplen; /* data length in the file */ - guint32 len; /* data length on the wire */ + uint32_t caplen; /* data length in the file */ + uint32_t len; /* data length on the wire */ int pkt_encap; /* WTAP_ENCAP_ value for this packet */ /* pcapng variables */ - guint32 interface_id; /* identifier of the interface. */ + uint32_t interface_id; /* identifier of the interface. */ /* options */ union wtap_pseudo_header pseudo_header; @@ -1329,36 +1367,37 @@ typedef struct { (ll_dependent_errors)) typedef struct { - guint record_type; /* the type of record this is - file type-specific value */ - guint32 record_len; /* length of the record */ + unsigned record_type; /* the type of record this is - file type-specific value */ + uint32_t record_len; /* length of the record */ } wtap_ft_specific_header; typedef struct { - guint record_type; /* XXX match ft_specific_record_phdr so that we chain off of packet-pcapng_block for now. */ + const char *pathname; /* Path name of file. */ + unsigned record_type; /* XXX match ft_specific_record_phdr so that we chain off of packet-pcapng_block for now. */ int byte_order; - /* guint32 sentinel; */ - guint64 timestamp; /* ns since epoch - XXX dup of ts */ - guint64 thread_id; - guint32 event_len; /* length of the event */ - guint32 event_filelen; /* event data length in the file */ - guint16 event_type; - guint32 nparams; /* number of parameters of the event */ - guint16 cpu_id; + /* uint32_t sentinel; */ + uint64_t timestamp; /* ns since epoch - XXX dup of ts */ + uint64_t thread_id; + uint32_t event_len; /* length of the event */ + uint32_t event_filelen; /* event data length in the file */ + uint16_t event_type; + uint32_t nparams; /* number of parameters of the event */ + uint16_t cpu_id; /* ... Event ... */ } wtap_syscall_header; typedef struct { - guint32 record_len; /* length of the record */ + uint32_t record_len; /* length of the record */ } wtap_systemd_journal_export_header; typedef struct { - guint32 length; /* length of the record */ - guint32 pen; /* private enterprise number */ - gboolean copy_allowed; /* CB can be written */ + uint32_t length; /* length of the record */ + uint32_t pen; /* private enterprise number */ + bool copy_allowed; /* CB can be written */ union { struct nflx { - guint32 type; /* block type */ - guint32 skipped; /* Used if type == BBLOG_TYPE_SKIPPED_BLOCK */ + uint32_t type; /* block type */ + uint32_t skipped; /* Used if type == BBLOG_TYPE_SKIPPED_BLOCK */ } nflx_custom_data_header; } custom_data_header; } wtap_custom_block_header; @@ -1373,11 +1412,11 @@ typedef struct { * We assume that time_t is signed; it is signed on Windows/MSVC and * on many UN*Xes. * - * So, if time_t is 32-bit, we define this as G_MAXINT32, as that's + * So, if time_t is 32-bit, we define this as INT32_MAX, as that's * the largest value a time_t can have, and it fits in an unsigned * 32-bit quantity. If it's 64-bit or larger, we define this as - * G_MAXUINT32, as, even if it's signed, it can be as large as - * G_MAXUINT32, and that's the largest value that can fit in + * UINT32_MAX, as, even if it's signed, it can be as large as + * UINT32_MAX, and that's the largest value that can fit in * a 32-bit unsigned quantity. * * Comparing against this, rather than against G_MAXINT2, when checking @@ -1388,16 +1427,16 @@ typedef struct { * XXX - what if time_t is unsigned? Are there any platforms where * it is? */ -#define WTAP_NSTIME_32BIT_SECS_MAX ((time_t)(sizeof(time_t) > sizeof(gint32) ? G_MAXUINT32 : G_MAXINT32)) +#define WTAP_NSTIME_32BIT_SECS_MAX ((time_t)(sizeof(time_t) > sizeof(int32_t) ? UINT32_MAX : INT32_MAX)) typedef struct wtap_rec { - guint rec_type; /* what type of record is this? */ - guint32 presence_flags; /* what stuff do we have? */ - guint section_number; /* section, within file, containing this record */ + unsigned rec_type; /* what type of record is this? */ + uint32_t presence_flags; /* what stuff do we have? */ + unsigned section_number; /* section, within file, containing this record */ nstime_t ts; /* time stamp */ int tsprec; /* WTAP_TSPREC_ value for this record */ nstime_t ts_rel_cap; /* time stamp relative from capture start */ - gboolean ts_rel_cap_valid; /* is ts_rel_cap valid and can be used? */ + bool ts_rel_cap_valid; /* is ts_rel_cap valid and can be used? */ union { wtap_packet_header packet_header; wtap_ft_specific_header ft_specific_header; @@ -1407,7 +1446,7 @@ typedef struct wtap_rec { } rec_header; wtap_block_t block ; /* packet block; holds comments and verdicts in its options */ - gboolean block_was_modified; /* TRUE if ANY aspect of the block has been modified */ + bool block_was_modified; /* true if ANY aspect of the block has been modified */ /* * We use a Buffer so that we don't have to allocate and free @@ -1448,17 +1487,18 @@ typedef struct wtap_rec { #endif typedef struct hashipv4 { - guint addr; - guint8 flags; /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */ - gchar ip[WS_INET_ADDRSTRLEN]; - gchar name[MAXNAMELEN]; + unsigned addr; + uint8_t flags; /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */ + char ip[WS_INET_ADDRSTRLEN]; + char name[MAXNAMELEN]; + char cidr_addr[WS_INET_CIDRADDRSTRLEN]; } hashipv4_t; typedef struct hashipv6 { - guint8 addr[16]; - guint8 flags; /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */ - gchar ip6[WS_INET6_ADDRSTRLEN]; - gchar name[MAXNAMELEN]; + uint8_t addr[16]; + uint8_t flags; /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */ + char ip6[WS_INET6_ADDRSTRLEN]; + char name[MAXNAMELEN]; } hashipv6_t; /** A struct with lists of resolved addresses. @@ -1490,6 +1530,9 @@ typedef struct wtap_dump_params { int snaplen; /**< Per-file snapshot length (what if it's per-interface?) */ int tsprec; /**< Per-file time stamp precision */ GArray *shb_hdrs; /**< The section header block(s) information, or NULL. */ + const GArray *shb_iface_to_global; /**< An array mapping the per-section interface numbers to global IDs + This array may grow after the dumper is opened if a new + section header is read. */ wtapng_iface_descriptions_t *idb_inf; /**< The interface description information, or NULL. */ const GArray *nrbs_growing; /**< NRBs that will be written while writing packets, or NULL. This array may grow since the dumper was opened and will subsequently @@ -1498,10 +1541,10 @@ typedef struct wtap_dump_params { const GArray *dsbs_growing; /**< DSBs that will be written while writing packets, or NULL. This array may grow since the dumper was opened and will subsequently be written before newer packets are written in wtap_dump. */ - const GArray *sysdig_mev_growing; /**< Meta events that will be written while writing packets, or NULL. + const GArray *mevs_growing; /**< Meta events that will be written while writing packets, or NULL. This array may grow since the dumper was opened and will subsequently be written before newer packets are written in wtap_dump. */ - gboolean dont_copy_idbs; /**< XXX - don't copy IDBs; this should eventually always be the case. */ + bool dont_copy_idbs; /**< XXX - don't copy IDBs; this should eventually always be the case. */ } wtap_dump_params; /* Zero-initializer for wtap_dump_params. */ @@ -1572,8 +1615,8 @@ struct file_extension_info { /* the file type description */ const char *name; - /* TRUE if this is a capture file type */ - gboolean is_capture_file; + /* true if this is a capture file type */ + bool is_capture_file; /* a semicolon-separated list of file extensions used for this type */ const char *extensions; @@ -1672,7 +1715,7 @@ struct open_info { wtap_open_type type; /* Open routine type */ wtap_open_routine_t open_routine; /* Open routine */ const char *extensions; /* List of extensions used for this file type */ - gchar **extensions_set; /* Array of those extensions; populated using extensions member during initialization */ + char **extensions_set; /* Array of those extensions; populated using extensions member during initialization */ void* wslua_data; /* Data for Lua file readers */ }; WS_DLL_PUBLIC struct open_info *open_routines; @@ -1699,12 +1742,12 @@ typedef enum { * Entry in a table of supported option types. */ struct supported_option_type { - guint opt; + unsigned opt; option_support_t support; /* OPTION_NOT_SUPPORTED allowed, equivalent to absence */ }; #define OPTION_TYPES_SUPPORTED(option_type_array) \ - sizeof option_type_array / sizeof option_type_array[0], option_type_array + array_length(option_type_array), option_type_array #define NO_OPTIONS_SUPPORTED \ 0, NULL @@ -1730,7 +1773,7 @@ struct supported_block_type { }; #define BLOCKS_SUPPORTED(block_type_array) \ - sizeof block_type_array / sizeof block_type_array[0], block_type_array + array_length(block_type_array), block_type_array struct file_type_subtype_info { /** @@ -1761,7 +1804,7 @@ struct file_type_subtype_info { /** * When writing this file format, is seeking required? */ - gboolean writing_must_seek; + bool writing_must_seek; /** * Number of block types supported. @@ -1776,6 +1819,10 @@ struct file_type_subtype_info { /** * Can this type write this encapsulation format? * Should be NULL is this file type doesn't have write support. + * + * XXX - This returns an int because it can return err codes, + * specifically WTAP_ERR_CHECK_WSLUA (instead of having an + * int *err parameter like the other functions.) */ int (*can_write_encap)(int); @@ -1783,7 +1830,7 @@ struct file_type_subtype_info { * The function to open the capture file for writing. * Should be NULL if this file type doesn't have write support. */ - int (*dump_open)(wtap_dumper *, int *, gchar **); + bool (*dump_open)(wtap_dumper *, int *, char **); /** * If can_write_encap returned WTAP_ERR_CHECK_WSLUA, then this is used instead. @@ -1800,7 +1847,7 @@ struct file_type_subtype_info { * @param load_wiretap_plugins Load Wiretap plugins when initializing library. */ WS_DLL_PUBLIC -void wtap_init(gboolean load_wiretap_plugins); +void wtap_init(bool load_wiretap_plugins); /** On failure, "wtap_open_offline()" returns NULL, and puts into the * "int" pointed to by its second argument: @@ -1811,12 +1858,12 @@ void wtap_init(gboolean load_wiretap_plugins); * a negative number, indicating the type of error, on other failures. * @param[out] err_info for some errors, a string giving more details of * the error - * @param do_random TRUE if random access to the file will be done, - * FALSE if not + * @param do_random true if random access to the file will be done, + * false if not */ WS_DLL_PUBLIC struct wtap* wtap_open_offline(const char *filename, unsigned int type, int *err, - gchar **err_info, gboolean do_random); + char **err_info, bool do_random); /** * If we were compiled with zlib and we're at EOF, unset EOF so that @@ -1830,11 +1877,11 @@ void wtap_cleareof(wtap *wth); * Set callback functions to add new hostnames. Currently pcapng-only. * MUST match add_ipv4_name and add_ipv6_name in addr_resolv.c. */ -typedef void (*wtap_new_ipv4_callback_t) (const guint addr, const gchar *name, const gboolean static_entry); +typedef void (*wtap_new_ipv4_callback_t) (const unsigned addr, const char *name, const bool static_entry); WS_DLL_PUBLIC void wtap_set_cb_new_ipv4(wtap *wth, wtap_new_ipv4_callback_t add_new_ipv4); -typedef void (*wtap_new_ipv6_callback_t) (const void *addrp, const gchar *name, const gboolean static_entry); +typedef void (*wtap_new_ipv6_callback_t) (const void *addrp, const char *name, const bool static_entry); WS_DLL_PUBLIC void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6); @@ -1842,17 +1889,10 @@ void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6); * Set callback function to receive new decryption secrets for a particular * secrets type (as defined in secrets-types.h). Currently pcapng-only. */ -typedef void (*wtap_new_secrets_callback_t)(guint32 secrets_type, const void *secrets, guint size); +typedef void (*wtap_new_secrets_callback_t)(uint32_t secrets_type, const void *secrets, unsigned size); WS_DLL_PUBLIC void wtap_set_cb_new_secrets(wtap *wth, wtap_new_secrets_callback_t add_new_secrets); -/** - * Set callback function to receive new sysdig meta events. Currently pcapng-only. - */ -typedef void (*wtap_new_sysdig_meta_event_callback_t)(uint32_t mev_type, const uint8_t *mev_data, unsigned mev_data_size); -WS_DLL_PUBLIC -void wtap_set_cb_new_sysdig_meta_event(wtap *wth, wtap_new_sysdig_meta_event_callback_t add_new_sysdig_meta_event); - /** Read the next record in the file, filling in *phdr and *buf. * * @wth a wtap * returned by a call that opened a file for reading. @@ -1863,21 +1903,21 @@ void wtap_set_cb_new_sysdig_meta_event(wtap *wth, wtap_new_sysdig_meta_event_cal * the type of error, if the read failed. * @param err_info for some errors, a string giving more details of * the error - * @param offset a pointer to a gint64, set to the offset in the file + * @param offset a pointer to a int64_t, set to the offset in the file * that should be used on calls to wtap_seek_read() to reread that record, * if the read succeeded. - * @return TRUE on success, FALSE on failure. + * @return true on success, false on failure. */ WS_DLL_PUBLIC -gboolean wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, - gchar **err_info, gint64 *offset); +bool wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, + char **err_info, int64_t *offset); /** Read the record at a specified offset in a capture file, filling in * *phdr and *buf. * * @wth a wtap * returned by a call that opened a file for random-access * reading. - * @seek_off a gint64 giving an offset value returned by a previous + * @seek_off a int64_t giving an offset value returned by a previous * wtap_read() call. * @rec a pointer to a struct wtap_rec, filled in with information * about the record. @@ -1886,11 +1926,11 @@ gboolean wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, * the type of error, if the read failed. * @param err_info for some errors, a string giving more details of * the error - * @return TRUE on success, FALSE on failure. + * @return true on success, false on failure. */ WS_DLL_PUBLIC -gboolean wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, - Buffer *buf, int *err, gchar **err_info); +bool wtap_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, + Buffer *buf, int *err, char **err_info); /*** initialize a wtap_rec structure ***/ WS_DLL_PUBLIC @@ -1911,28 +1951,37 @@ typedef enum { WTAP_UNCOMPRESSED, WTAP_GZIP_COMPRESSED, WTAP_ZSTD_COMPRESSED, - WTAP_LZ4_COMPRESSED + WTAP_LZ4_COMPRESSED, + WTAP_UNKNOWN_COMPRESSION, } wtap_compression_type; WS_DLL_PUBLIC wtap_compression_type wtap_get_compression_type(wtap *wth); WS_DLL_PUBLIC +wtap_compression_type wtap_name_to_compression_type(const char *name); +WS_DLL_PUBLIC +wtap_compression_type wtap_extension_to_compression_type(const char *ext); +WS_DLL_PUBLIC const char *wtap_compression_type_description(wtap_compression_type compression_type); WS_DLL_PUBLIC const char *wtap_compression_type_extension(wtap_compression_type compression_type); WS_DLL_PUBLIC GSList *wtap_get_all_compression_type_extensions_list(void); +WS_DLL_PUBLIC +GSList *wtap_get_all_output_compression_type_names_list(void); +WS_DLL_PUBLIC +bool wtap_can_write_compression_type(wtap_compression_type compression_type); /*** get various information snippets about the current file ***/ /** Return an approximation of the amount of data we've read sequentially * from the file so far. */ WS_DLL_PUBLIC -gint64 wtap_read_so_far(wtap *wth); +int64_t wtap_read_so_far(wtap *wth); WS_DLL_PUBLIC -gint64 wtap_file_size(wtap *wth, int *err); +int64_t wtap_file_size(wtap *wth, int *err); WS_DLL_PUBLIC -guint wtap_snapshot_length(wtap *wth); /* per file */ +unsigned wtap_snapshot_length(wtap *wth); /* per file */ WS_DLL_PUBLIC int wtap_file_type_subtype(wtap *wth); WS_DLL_PUBLIC @@ -1948,7 +1997,7 @@ int wtap_file_tsprec(wtap *wth); * @return The number of existing section headers. */ WS_DLL_PUBLIC -guint wtap_file_get_num_shbs(wtap *wth); +unsigned wtap_file_get_num_shbs(wtap *wth); /** * @brief Gets existing section header block, not for new file. @@ -1963,7 +2012,7 @@ guint wtap_file_get_num_shbs(wtap *wth); * @return The specified existing section header, which must NOT be g_free'd. */ WS_DLL_PUBLIC -wtap_block_t wtap_file_get_shb(wtap *wth, guint shb_num); +wtap_block_t wtap_file_get_shb(wtap *wth, unsigned shb_num); /** * @brief Sets or replaces the section header comment. @@ -1976,7 +2025,21 @@ wtap_block_t wtap_file_get_shb(wtap *wth, guint shb_num); * @param comment The comment string. */ WS_DLL_PUBLIC -void wtap_write_shb_comment(wtap *wth, gchar *comment); +void wtap_write_shb_comment(wtap *wth, char *comment); + +/** + * @brief Gets the unique interface id for a SHB's interface + * @details Given an existing SHB number and an interface ID within + * that section, returns the unique ordinal number (0-based) + * of that interface over the entire wiretap session. + * + * @param wth The wiretap session. + * @param shb_num The ordinal number (0-based) of a section header + * @param interface_id An interface id within the section + * @return The unique wtap session-wide interface id for that interface + */ +WS_DLL_PUBLIC +unsigned wtap_file_get_shb_global_interface_id(wtap *wth, unsigned shb_num, uint32_t interface_id); /** * @brief Gets existing interface descriptions. @@ -2030,7 +2093,7 @@ void wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info); * @return A newly allocated gcahr array string, which must be g_free'd. */ WS_DLL_PUBLIC -gchar *wtap_get_debug_if_descr(const wtap_block_t if_descr, +char *wtap_get_debug_if_descr(const wtap_block_t if_descr, const int indent, const char* line_end); @@ -2050,6 +2113,29 @@ WS_DLL_PUBLIC wtap_block_t wtap_file_get_nrb(wtap *wth); /** + * @brief Gets number of decryption secrets blocks. + * @details Returns the number of existing DSBs. + * + * @param wth The wiretap session. + * @return The number of existing decryption secrets blocks. + */ +WS_DLL_PUBLIC +unsigned wtap_file_get_num_dsbs(wtap *wth); + +/** + * @brief Gets existing decryption secrets block, not for new file. + * @details Returns the pointer to an existing DSB, without creating a + * new one. This should only be used for accessing info. + * + * @param wth The wiretap session. + * @param dsb_num The ordinal number (0-based) of the decryption secrets block + * in the file + * @return The specified existing decryption secrets block, which must NOT be g_free'd. + */ +WS_DLL_PUBLIC +wtap_block_t wtap_file_get_dsb(wtap *wth, unsigned dsb_num); + +/** * @brief Adds a Decryption Secrets Block to the open wiretap session. * @details The passed-in DSB is added to the DSBs for the current * session. @@ -2066,10 +2152,10 @@ void wtap_file_add_decryption_secrets(wtap *wth, const wtap_block_t dsb); * * @param wth The wiretap session from which to remove the * decryption secrets. - * @return TRUE if any DSBs were removed + * @return true if any DSBs were removed */ WS_DLL_PUBLIC -gboolean wtap_file_discard_decryption_secrets(wtap *wth); +bool wtap_file_discard_decryption_secrets(wtap *wth); /*** close the file descriptors for the current file ***/ WS_DLL_PUBLIC @@ -2077,7 +2163,7 @@ void wtap_fdclose(wtap *wth); /*** reopen the random file descriptor for the current file ***/ WS_DLL_PUBLIC -gboolean wtap_fdreopen(wtap *wth, const char *filename, int *err); +bool wtap_fdreopen(wtap *wth, const char *filename, int *err); /** Close only the sequential side, freeing up memory it uses. */ WS_DLL_PUBLIC @@ -2089,7 +2175,7 @@ void wtap_close(wtap *wth); /*** dump packets into a capture file ***/ WS_DLL_PUBLIC -gboolean wtap_dump_can_open(int filetype); +bool wtap_dump_can_open(int filetype); /** * Given a GArray of WTAP_ENCAP_ types, return the per-file encapsulation @@ -2099,18 +2185,18 @@ WS_DLL_PUBLIC int wtap_dump_required_file_encap_type(const GArray *file_encaps); /** - * Return TRUE if we can write this encapsulation type in this - * capture file type/subtype, FALSE if not. + * Return true if we can write this encapsulation type in this + * capture file type/subtype, false if not. */ WS_DLL_PUBLIC -gboolean wtap_dump_can_write_encap(int file_type_subtype, int encap); +bool wtap_dump_can_write_encap(int file_type_subtype, int encap); /** - * Return TRUE if we can write this capture file type/subtype out in - * compressed form, FALSE if not. + * Return true if we can write this capture file type/subtype out in + * compressed form, false if not. */ WS_DLL_PUBLIC -gboolean wtap_dump_can_compress(int file_type_subtype); +bool wtap_dump_can_compress(int file_type_subtype); /** * Initialize the per-file information based on an existing file. Its @@ -2185,7 +2271,7 @@ void wtap_dump_params_cleanup(wtap_dump_params *params); WS_DLL_PUBLIC wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, - int *err, gchar **err_info); + int *err, char **err_info); /** * @brief Creates a dumper for a temporary file. @@ -2206,7 +2292,7 @@ WS_DLL_PUBLIC wtap_dumper* wtap_dump_open_tempfile(const char *tmpdir, char **filenamep, const char *pfx, int file_type_subtype, wtap_compression_type compression_type, - const wtap_dump_params *params, int *err, gchar **err_info); + const wtap_dump_params *params, int *err, char **err_info); /** * @brief Creates a dumper for an existing file descriptor. @@ -2223,7 +2309,7 @@ wtap_dumper* wtap_dump_open_tempfile(const char *tmpdir, char **filenamep, WS_DLL_PUBLIC wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, - int *err, gchar **err_info); + int *err, char **err_info); /** * @brief Creates a dumper for the standard output. @@ -2239,7 +2325,7 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, WS_DLL_PUBLIC wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, wtap_compression_type compression_type, const wtap_dump_params *params, - int *err, gchar **err_info); + int *err, char **err_info); /* * Add an IDB to the list of IDBs for a file we're writing. @@ -2250,27 +2336,27 @@ wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, * @param[out] err Will be set to an error code on failure. * @param[out] err_info for some errors, a string giving more details of * the error. - * @return TRUE on success, FALSE on failure. + * @return true on success, false on failure. */ WS_DLL_PUBLIC -gboolean wtap_dump_add_idb(wtap_dumper *wdh, wtap_block_t idb, int *err, - gchar **err_info); +bool wtap_dump_add_idb(wtap_dumper *wdh, wtap_block_t idb, int *err, + char **err_info); WS_DLL_PUBLIC -gboolean wtap_dump(wtap_dumper *, const wtap_rec *, const guint8 *, - int *err, gchar **err_info); +bool wtap_dump(wtap_dumper *, const wtap_rec *, const uint8_t *, + int *err, char **err_info); WS_DLL_PUBLIC -gboolean wtap_dump_flush(wtap_dumper *, int *); +bool wtap_dump_flush(wtap_dumper *, int *); WS_DLL_PUBLIC int wtap_dump_file_type_subtype(wtap_dumper *wdh); WS_DLL_PUBLIC -gint64 wtap_get_bytes_dumped(wtap_dumper *); +int64_t wtap_get_bytes_dumped(wtap_dumper *); WS_DLL_PUBLIC -void wtap_set_bytes_dumped(wtap_dumper *wdh, gint64 bytes_dumped); +void wtap_set_bytes_dumped(wtap_dumper *wdh, int64_t bytes_dumped); struct addrinfo; WS_DLL_PUBLIC -gboolean wtap_addrinfo_list_empty(addrinfo_lists_t *addrinfo_lists); +bool wtap_addrinfo_list_empty(addrinfo_lists_t *addrinfo_lists); WS_DLL_PUBLIC -gboolean wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists); +bool wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists); WS_DLL_PUBLIC void wtap_dump_discard_name_resolution(wtap_dumper *wdh); WS_DLL_PUBLIC @@ -2281,27 +2367,27 @@ void wtap_dump_discard_decryption_secrets(wtap_dumper *wdh); * shb_hdr and idb_inf are not freed by this routine. * * @param wdh handle for the file we're closing. - * @param[out] needs_reload if not null, points to a gboolean that will - * be set to TRUE if a full reload of the file would be required if - * this was done as part of a "Save" or "Save As" operation, FALSE + * @param[out] needs_reload if not null, points to a bool that will + * be set to true if a full reload of the file would be required if + * this was done as part of a "Save" or "Save As" operation, false * if no full reload would be required. * @param[out] err points to an int that will be set to an error code * on failure. - * @param[out] err_info for some errors, points to a gchar * that will + * @param[out] err_info for some errors, points to a char * that will * be set to a string giving more details of the error. * - * @return TRUE on success, FALSE on failure. + * @return true on success, false on failure. */ WS_DLL_PUBLIC -gboolean wtap_dump_close(wtap_dumper *wdh, gboolean *needs_reload, - int *err, gchar **err_info); +bool wtap_dump_close(wtap_dumper *wdh, bool *needs_reload, + int *err, char **err_info); /** - * Return TRUE if we can write a file out with the given GArray of file + * Return true if we can write a file out with the given GArray of file * encapsulations and the given bitmask of comment types. */ WS_DLL_PUBLIC -gboolean wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types); +bool wtap_dump_can_write(const GArray *file_encaps, uint32_t required_comment_types); /** * Generates arbitrary packet data in "exported PDU" format @@ -2316,7 +2402,7 @@ gboolean wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment * @param data_len length of data */ WS_DLL_PUBLIC -void wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, const guint8 *data, guint16 data_len); +void wtap_buffer_append_epdu_tag(Buffer *buf, uint16_t epdu_tag, const uint8_t *data, uint16_t data_len); /** * Generates packet data for an unsigned integer in "exported PDU" format. @@ -2327,7 +2413,7 @@ void wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, const guint8 *da * @param val integer value to write to buf */ WS_DLL_PUBLIC -void wtap_buffer_append_epdu_uint(Buffer *buf, guint16 epdu_tag, guint32 val); +void wtap_buffer_append_epdu_uint(Buffer *buf, uint16_t epdu_tag, uint32_t val); /** * Generates packet data for a string in "exported PDU" format. @@ -2338,7 +2424,7 @@ void wtap_buffer_append_epdu_uint(Buffer *buf, guint16 epdu_tag, guint32 val); * @param val string value to write to buf */ WS_DLL_PUBLIC -void wtap_buffer_append_epdu_string(Buffer *buf, guint16 epdu_tag, const char *val); +void wtap_buffer_append_epdu_string(Buffer *buf, uint16_t epdu_tag, const char *val); /** * Close off a set of "exported PDUs" added to the buffer. @@ -2349,7 +2435,7 @@ void wtap_buffer_append_epdu_string(Buffer *buf, guint16 epdu_tag, const char *v * @return Total length of buf populated to date */ WS_DLL_PUBLIC -gint wtap_buffer_append_epdu_end(Buffer *buf); +int wtap_buffer_append_epdu_end(Buffer *buf); /* * Sort the file types by name or by description? @@ -2366,7 +2452,7 @@ typedef enum { */ WS_DLL_PUBLIC GArray *wtap_get_savable_file_types_subtypes_for_file(int file_type_subtype, - const GArray *file_encaps, guint32 required_comment_types, + const GArray *file_encaps, uint32_t required_comment_types, ft_sort_order sort_order); /** @@ -2403,7 +2489,7 @@ block_support_t wtap_file_type_subtype_supports_block(int file_type_subtype, */ WS_DLL_PUBLIC option_support_t wtap_file_type_subtype_supports_option(int file_type_subtype, - wtap_block_type_t type, guint opttype); + wtap_block_type_t type, unsigned opttype); /* Return a list of all extensions that are used by all capture file * types, including compressed extensions, e.g. not just "pcap" but @@ -2461,7 +2547,7 @@ const char *wtap_default_file_extension(int file_type_subtype); /* Return a list of file extensions that are used by the specified file type * and subtype. * - * If include_compressed is TRUE, the list will include compressed + * If include_compressed is true, the list will include compressed * extensions, e.g. not just "pcap" but also "pcap.gz" if we can read * gzipped files. * @@ -2469,7 +2555,7 @@ const char *wtap_default_file_extension(int file_type_subtype); * with g_free(). */ WS_DLL_PUBLIC -GSList *wtap_get_file_extensions_list(int file_type_subtype, gboolean include_compressed); +GSList *wtap_get_file_extensions_list(int file_type_subtype, bool include_compressed); WS_DLL_PUBLIC const char *wtap_encap_name(int encap); @@ -2494,7 +2580,7 @@ int wtap_get_num_encap_types(void); WS_DLL_PUBLIC const char *wtap_get_file_extension_type_name(int extension_type); WS_DLL_PUBLIC -GSList *wtap_get_file_extension_type_extensions(guint extension_type); +GSList *wtap_get_file_extension_type_extensions(unsigned extension_type); /*** dynamically register new file types and encapsulations ***/ WS_DLL_PUBLIC @@ -2516,13 +2602,13 @@ WS_DLL_PUBLIC int wtap_plugins_supported(void); WS_DLL_PUBLIC -void wtap_register_open_info(struct open_info *oi, const gboolean first_routine); +void wtap_register_open_info(struct open_info *oi, const bool first_routine); WS_DLL_PUBLIC -gboolean wtap_has_open_info(const gchar *name); +bool wtap_has_open_info(const char *name); WS_DLL_PUBLIC -gboolean wtap_uses_lua_filehandler(const wtap* wth); +bool wtap_uses_lua_filehandler(const wtap* wth); WS_DLL_PUBLIC -void wtap_deregister_open_info(const gchar *name); +void wtap_deregister_open_info(const char *name); WS_DLL_PUBLIC unsigned int open_info_name_to_type(const char *name); diff --git a/wiretap/wtap_modules.h b/wiretap/wtap_modules.h index 05320c32..5bbbf745 100644 --- a/wiretap/wtap_modules.h +++ b/wiretap/wtap_modules.h @@ -26,9 +26,9 @@ typedef struct _wtap_module_reg { void (*cb_func)(void); } wtap_module_reg_t; -extern wtap_module_reg_t wtap_module_reg[]; +extern wtap_module_reg_t const wtap_module_reg[]; -extern const guint wtap_module_count; +extern const unsigned wtap_module_count; #ifdef __cplusplus } diff --git a/wiretap/wtap_opttypes.c b/wiretap/wtap_opttypes.c index 98ffe4dd..95e29b08 100644 --- a/wiretap/wtap_opttypes.c +++ b/wiretap/wtap_opttypes.c @@ -7,6 +7,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "config.h" +#include "wtap_opttypes.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP @@ -14,13 +15,11 @@ #include <string.h> #include "wtap.h" -#include "wtap_opttypes.h" #include "wtap-int.h" #include "pcapng_module.h" #include <wsutil/ws_assert.h> #include <wsutil/glib-compat.h> -#include <wsutil/inet_ipv6.h> #include <wsutil/unicode-utils.h> #if 0 @@ -55,7 +54,7 @@ typedef struct { const char *name; /**< name of option */ const char *description; /**< human-readable description of option */ wtap_opttype_e data_type; /**< data type of that option */ - guint flags; /**< flags for the option */ + unsigned flags; /**< flags for the option */ } wtap_opttype_t; /* Flags */ @@ -63,21 +62,21 @@ typedef struct { /* Debugging reference counting */ #ifdef DEBUG_COUNT_REFS -static guint block_count = 0; -static guint8 blocks_active[sizeof(guint)/8]; +static unsigned block_count; +static uint8_t blocks_active[sizeof(unsigned)/8]; -static void rc_set(guint refnum) +static void rc_set(unsigned refnum) { - guint cellno = refnum / 8; - guint bitno = refnum % 8; - blocks_active[cellno] |= (guint8)(1 << bitno); + unsigned cellno = refnum / 8; + unsigned bitno = refnum % 8; + blocks_active[cellno] |= (uint8_t)(1 << bitno); } -static void rc_clear(guint refnum) +static void rc_clear(unsigned refnum) { - guint cellno = refnum / 8; - guint bitno = refnum % 8; - blocks_active[cellno] &= (guint8)~(1 << bitno); + unsigned cellno = refnum / 8; + unsigned bitno = refnum % 8; + blocks_active[cellno] &= (uint8_t)~(1 << bitno); } #endif /* DEBUG_COUNT_REFS */ @@ -87,9 +86,9 @@ struct wtap_block wtap_blocktype_t* info; void* mandatory_data; GArray* options; - gint ref_count; + int ref_count; #ifdef DEBUG_COUNT_REFS - guint id; + unsigned id; #endif }; @@ -160,7 +159,7 @@ packet_verdict_dup(packet_verdict_opt_t* verdict_src) case packet_verdict_hardware: /* array of octets */ verdict_dest.data.verdict_bytes = - g_byte_array_new_take((guint8 *)g_memdup2(verdict_src->data.verdict_bytes->data, + g_byte_array_new_take((uint8_t *)g_memdup2(verdict_src->data.verdict_bytes->data, verdict_src->data.verdict_bytes->len), verdict_src->data.verdict_bytes->len); break; @@ -189,7 +188,7 @@ void wtap_packet_verdict_free(packet_verdict_opt_t* verdict) case packet_verdict_hardware: /* array of bytes */ - g_byte_array_free(verdict->data.verdict_bytes, TRUE); + g_byte_array_free(verdict->data.verdict_bytes, true); break; default: @@ -208,7 +207,7 @@ packet_hash_dup(packet_hash_opt_t* hash_src) hash_dest.type = hash_src->type; /* array of octets */ hash_dest.hash_bytes = - g_byte_array_new_take((guint8 *)g_memdup2(hash_src->hash_bytes->data, + g_byte_array_new_take((uint8_t *)g_memdup2(hash_src->hash_bytes->data, hash_src->hash_bytes->len), hash_src->hash_bytes->len); return hash_dest; @@ -217,7 +216,7 @@ packet_hash_dup(packet_hash_opt_t* hash_src) void wtap_packet_hash_free(packet_hash_opt_t* hash) { /* array of bytes */ - g_byte_array_free(hash->hash_bytes, TRUE); + g_byte_array_free(hash->hash_bytes, true); } static void wtap_opttype_block_register(wtap_blocktype_t *blocktype) @@ -259,23 +258,23 @@ static void wtap_opttype_block_register(wtap_blocktype_t *blocktype) */ blocktype->options = g_hash_table_new(g_direct_hash, g_direct_equal); g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_COMMENT), - (gpointer)&opt_comment); + (void *)&opt_comment); g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_CUSTOM_STR_COPY), - (gpointer)&opt_custom); + (void *)&opt_custom); g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_CUSTOM_BIN_COPY), - (gpointer)&opt_custom); + (void *)&opt_custom); g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_CUSTOM_STR_NO_COPY), - (gpointer)&opt_custom); + (void *)&opt_custom); g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_CUSTOM_BIN_NO_COPY), - (gpointer)&opt_custom); + (void *)&opt_custom); blocktype_list[block_type] = blocktype; } -static void wtap_opttype_option_register(wtap_blocktype_t *blocktype, guint opttype, const wtap_opttype_t *option) +static void wtap_opttype_option_register(wtap_blocktype_t *blocktype, unsigned opttype, const wtap_opttype_t *option) { g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(opttype), - (gpointer) option); + (void *) option); } wtap_block_type_t wtap_block_get_type(wtap_block_t block) @@ -289,9 +288,9 @@ void* wtap_block_get_mandatory_data(wtap_block_t block) } static wtap_optval_t * -wtap_block_get_option(wtap_block_t block, guint option_id) +wtap_block_get_option(wtap_block_t block, unsigned option_id) { - guint i; + unsigned i; wtap_option_t *opt; if (block == NULL) { @@ -308,11 +307,11 @@ wtap_block_get_option(wtap_block_t block, guint option_id) } static wtap_optval_t * -wtap_block_get_nth_option(wtap_block_t block, guint option_id, guint idx) +wtap_block_get_nth_option(wtap_block_t block, unsigned option_id, unsigned idx) { - guint i; + unsigned i; wtap_option_t *opt; - guint opt_idx; + unsigned opt_idx; if (block == NULL) { return NULL; @@ -340,7 +339,7 @@ wtap_block_t wtap_block_create(wtap_block_type_t block_type) block = g_new(struct wtap_block, 1); block->info = blocktype_list[block_type]; - block->options = g_array_new(FALSE, FALSE, sizeof(wtap_option_t)); + block->options = g_array_new(false, false, sizeof(wtap_option_t)); block->info->create(block); block->ref_count = 1; #ifdef DEBUG_COUNT_REFS @@ -401,7 +400,7 @@ static void wtap_block_free_option(wtap_block_t block, wtap_option_t *opt) static void wtap_block_free_options(wtap_block_t block) { - guint i; + unsigned i; wtap_option_t *opt; if (block == NULL || block->options == NULL) { @@ -442,7 +441,7 @@ void wtap_block_unref(wtap_block_t block) g_free(block->mandatory_data); wtap_block_free_options(block); - g_array_free(block->options, TRUE); + g_array_free(block->options, true); g_free(block); } #ifdef DEBUG_COUNT_REFS @@ -455,7 +454,7 @@ void wtap_block_unref(wtap_block_t block) void wtap_block_array_free(GArray* block_array) { - guint block; + unsigned block; if (block_array == NULL) return; @@ -463,7 +462,7 @@ void wtap_block_array_free(GArray* block_array) for (block = 0; block < block_array->len; block++) { wtap_block_unref(g_array_index(block_array, wtap_block_t, block)); } - g_array_free(block_array, TRUE); + g_array_free(block_array, true); } void wtap_block_array_ref(GArray* block_array) @@ -498,7 +497,7 @@ void wtap_block_array_unref(GArray* block_array) void wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block) { - guint i; + unsigned i; wtap_option_t *src_opt; const wtap_opttype_t *opttype; @@ -593,11 +592,11 @@ wtap_block_t wtap_block_make_copy(wtap_block_t block) return block_copy; } -guint -wtap_block_count_option(wtap_block_t block, guint option_id) +unsigned +wtap_block_count_option(wtap_block_t block, unsigned option_id) { - guint i; - guint ret_val = 0; + unsigned i; + unsigned ret_val = 0; wtap_option_t *opt; if (block == NULL) { @@ -614,31 +613,31 @@ wtap_block_count_option(wtap_block_t block, guint option_id) } -gboolean wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data) +bool wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data) { - guint i; + unsigned i; wtap_option_t *opt; const wtap_opttype_t *opttype; if (block == NULL) { - return TRUE; + return true; } for (i = 0; i < block->options->len; i++) { opt = &g_array_index(block->options, wtap_option_t, i); opttype = GET_OPTION_TYPE(block->info->options, opt->option_id); if (!func(block, opt->option_id, opttype->data_type, &opt->value, user_data)) - return FALSE; + return false; } - return TRUE; + return true; } static wtap_opttype_return_val -wtap_block_add_option_common(wtap_block_t block, guint option_id, wtap_opttype_e type, wtap_option_t **optp) +wtap_block_add_option_common(wtap_block_t block, unsigned option_id, wtap_opttype_e type, wtap_option_t **optp) { wtap_option_t *opt; const wtap_opttype_t *opttype; - guint i; + unsigned i; if (block == NULL) { return WTAP_OPTTYPE_BAD_BLOCK; @@ -687,7 +686,7 @@ wtap_block_add_option_common(wtap_block_t block, guint option_id, wtap_opttype_e } static wtap_opttype_return_val -wtap_block_get_option_common(wtap_block_t block, guint option_id, wtap_opttype_e type, wtap_optval_t **optvalp) +wtap_block_get_option_common(wtap_block_t block, unsigned option_id, wtap_opttype_e type, wtap_optval_t **optvalp) { const wtap_opttype_t *opttype; wtap_optval_t *optval; @@ -733,7 +732,7 @@ wtap_block_get_option_common(wtap_block_t block, guint option_id, wtap_opttype_e } static wtap_opttype_return_val -wtap_block_get_nth_option_common(wtap_block_t block, guint option_id, wtap_opttype_e type, guint idx, wtap_optval_t **optvalp) +wtap_block_get_nth_option_common(wtap_block_t block, unsigned option_id, wtap_opttype_e type, unsigned idx, wtap_optval_t **optvalp) { const wtap_opttype_t *opttype; wtap_optval_t *optval; @@ -779,7 +778,7 @@ wtap_block_get_nth_option_common(wtap_block_t block, guint option_id, wtap_optty } wtap_opttype_return_val -wtap_block_add_uint8_option(wtap_block_t block, guint option_id, guint8 value) +wtap_block_add_uint8_option(wtap_block_t block, unsigned option_id, uint8_t value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -792,7 +791,7 @@ wtap_block_add_uint8_option(wtap_block_t block, guint option_id, guint8 value) } wtap_opttype_return_val -wtap_block_set_uint8_option_value(wtap_block_t block, guint option_id, guint8 value) +wtap_block_set_uint8_option_value(wtap_block_t block, unsigned option_id, uint8_t value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -805,7 +804,7 @@ wtap_block_set_uint8_option_value(wtap_block_t block, guint option_id, guint8 va } wtap_opttype_return_val -wtap_block_get_uint8_option_value(wtap_block_t block, guint option_id, guint8* value) +wtap_block_get_uint8_option_value(wtap_block_t block, unsigned option_id, uint8_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -818,7 +817,7 @@ wtap_block_get_uint8_option_value(wtap_block_t block, guint option_id, guint8* v } wtap_opttype_return_val -wtap_block_add_uint32_option(wtap_block_t block, guint option_id, guint32 value) +wtap_block_add_uint32_option(wtap_block_t block, unsigned option_id, uint32_t value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -831,7 +830,7 @@ wtap_block_add_uint32_option(wtap_block_t block, guint option_id, guint32 value) } wtap_opttype_return_val -wtap_block_set_uint32_option_value(wtap_block_t block, guint option_id, guint32 value) +wtap_block_set_uint32_option_value(wtap_block_t block, unsigned option_id, uint32_t value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -844,7 +843,7 @@ wtap_block_set_uint32_option_value(wtap_block_t block, guint option_id, guint32 } wtap_opttype_return_val -wtap_block_get_uint32_option_value(wtap_block_t block, guint option_id, guint32* value) +wtap_block_get_uint32_option_value(wtap_block_t block, unsigned option_id, uint32_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -857,7 +856,7 @@ wtap_block_get_uint32_option_value(wtap_block_t block, guint option_id, guint32* } wtap_opttype_return_val -wtap_block_add_uint64_option(wtap_block_t block, guint option_id, guint64 value) +wtap_block_add_uint64_option(wtap_block_t block, unsigned option_id, uint64_t value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -870,7 +869,7 @@ wtap_block_add_uint64_option(wtap_block_t block, guint option_id, guint64 value) } wtap_opttype_return_val -wtap_block_set_uint64_option_value(wtap_block_t block, guint option_id, guint64 value) +wtap_block_set_uint64_option_value(wtap_block_t block, unsigned option_id, uint64_t value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -883,7 +882,7 @@ wtap_block_set_uint64_option_value(wtap_block_t block, guint option_id, guint64 } wtap_opttype_return_val -wtap_block_get_uint64_option_value(wtap_block_t block, guint option_id, guint64 *value) +wtap_block_get_uint64_option_value(wtap_block_t block, unsigned option_id, uint64_t *value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -896,7 +895,7 @@ wtap_block_get_uint64_option_value(wtap_block_t block, guint option_id, guint64 } wtap_opttype_return_val -wtap_block_add_int8_option(wtap_block_t block, guint option_id, gint8 value) +wtap_block_add_int8_option(wtap_block_t block, unsigned option_id, int8_t value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -909,7 +908,7 @@ wtap_block_add_int8_option(wtap_block_t block, guint option_id, gint8 value) } wtap_opttype_return_val -wtap_block_set_int8_option_value(wtap_block_t block, guint option_id, gint8 value) +wtap_block_set_int8_option_value(wtap_block_t block, unsigned option_id, int8_t value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -922,7 +921,7 @@ wtap_block_set_int8_option_value(wtap_block_t block, guint option_id, gint8 valu } wtap_opttype_return_val -wtap_block_get_int8_option_value(wtap_block_t block, guint option_id, gint8* value) +wtap_block_get_int8_option_value(wtap_block_t block, unsigned option_id, int8_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -935,7 +934,7 @@ wtap_block_get_int8_option_value(wtap_block_t block, guint option_id, gint8* val } wtap_opttype_return_val -wtap_block_add_int32_option(wtap_block_t block, guint option_id, gint32 value) +wtap_block_add_int32_option(wtap_block_t block, unsigned option_id, int32_t value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -948,7 +947,7 @@ wtap_block_add_int32_option(wtap_block_t block, guint option_id, gint32 value) } wtap_opttype_return_val -wtap_block_set_int32_option_value(wtap_block_t block, guint option_id, gint32 value) +wtap_block_set_int32_option_value(wtap_block_t block, unsigned option_id, int32_t value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -961,7 +960,7 @@ wtap_block_set_int32_option_value(wtap_block_t block, guint option_id, gint32 va } wtap_opttype_return_val -wtap_block_get_int32_option_value(wtap_block_t block, guint option_id, gint32* value) +wtap_block_get_int32_option_value(wtap_block_t block, unsigned option_id, int32_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -974,7 +973,7 @@ wtap_block_get_int32_option_value(wtap_block_t block, guint option_id, gint32* v } wtap_opttype_return_val -wtap_block_add_int64_option(wtap_block_t block, guint option_id, gint64 value) +wtap_block_add_int64_option(wtap_block_t block, unsigned option_id, int64_t value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -987,7 +986,7 @@ wtap_block_add_int64_option(wtap_block_t block, guint option_id, gint64 value) } wtap_opttype_return_val -wtap_block_set_int64_option_value(wtap_block_t block, guint option_id, gint64 value) +wtap_block_set_int64_option_value(wtap_block_t block, unsigned option_id, int64_t value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1000,7 +999,7 @@ wtap_block_set_int64_option_value(wtap_block_t block, guint option_id, gint64 va } wtap_opttype_return_val -wtap_block_get_int64_option_value(wtap_block_t block, guint option_id, gint64 *value) +wtap_block_get_int64_option_value(wtap_block_t block, unsigned option_id, int64_t *value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1013,7 +1012,7 @@ wtap_block_get_int64_option_value(wtap_block_t block, guint option_id, gint64 *v } wtap_opttype_return_val -wtap_block_add_ipv4_option(wtap_block_t block, guint option_id, guint32 value) +wtap_block_add_ipv4_option(wtap_block_t block, unsigned option_id, uint32_t value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1026,7 +1025,7 @@ wtap_block_add_ipv4_option(wtap_block_t block, guint option_id, guint32 value) } wtap_opttype_return_val -wtap_block_set_ipv4_option_value(wtap_block_t block, guint option_id, guint32 value) +wtap_block_set_ipv4_option_value(wtap_block_t block, unsigned option_id, uint32_t value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1039,7 +1038,7 @@ wtap_block_set_ipv4_option_value(wtap_block_t block, guint option_id, guint32 va } wtap_opttype_return_val -wtap_block_get_ipv4_option_value(wtap_block_t block, guint option_id, guint32* value) +wtap_block_get_ipv4_option_value(wtap_block_t block, unsigned option_id, uint32_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1052,7 +1051,7 @@ wtap_block_get_ipv4_option_value(wtap_block_t block, guint option_id, guint32* v } wtap_opttype_return_val -wtap_block_add_ipv6_option(wtap_block_t block, guint option_id, ws_in6_addr *value) +wtap_block_add_ipv6_option(wtap_block_t block, unsigned option_id, ws_in6_addr *value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1065,7 +1064,7 @@ wtap_block_add_ipv6_option(wtap_block_t block, guint option_id, ws_in6_addr *val } wtap_opttype_return_val -wtap_block_set_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_addr *value) +wtap_block_set_ipv6_option_value(wtap_block_t block, unsigned option_id, ws_in6_addr *value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1078,7 +1077,7 @@ wtap_block_set_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_add } wtap_opttype_return_val -wtap_block_get_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_addr* value) +wtap_block_get_ipv6_option_value(wtap_block_t block, unsigned option_id, ws_in6_addr* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1091,7 +1090,7 @@ wtap_block_get_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_add } wtap_opttype_return_val -wtap_block_add_string_option(wtap_block_t block, guint option_id, const char *value, gsize value_length) +wtap_block_add_string_option(wtap_block_t block, unsigned option_id, const char *value, size_t value_length) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1105,7 +1104,7 @@ wtap_block_add_string_option(wtap_block_t block, guint option_id, const char *va } wtap_opttype_return_val -wtap_block_add_string_option_owned(wtap_block_t block, guint option_id, char *value) +wtap_block_add_string_option_owned(wtap_block_t block, unsigned option_id, char *value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1119,7 +1118,7 @@ wtap_block_add_string_option_owned(wtap_block_t block, guint option_id, char *va } static wtap_opttype_return_val -wtap_block_add_string_option_vformat(wtap_block_t block, guint option_id, const char *format, va_list va) +wtap_block_add_string_option_vformat(wtap_block_t block, unsigned option_id, const char *format, va_list va) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1133,7 +1132,7 @@ wtap_block_add_string_option_vformat(wtap_block_t block, guint option_id, const } wtap_opttype_return_val -wtap_block_add_string_option_format(wtap_block_t block, guint option_id, const char *format, ...) +wtap_block_add_string_option_format(wtap_block_t block, unsigned option_id, const char *format, ...) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1149,7 +1148,7 @@ wtap_block_add_string_option_format(wtap_block_t block, guint option_id, const c } wtap_opttype_return_val -wtap_block_set_string_option_value(wtap_block_t block, guint option_id, const char *value, size_t value_length) +wtap_block_set_string_option_value(wtap_block_t block, unsigned option_id, const char *value, size_t value_length) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1172,7 +1171,7 @@ wtap_block_set_string_option_value(wtap_block_t block, guint option_id, const ch } wtap_opttype_return_val -wtap_block_set_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, const char *value, size_t value_length) +wtap_block_set_nth_string_option_value(wtap_block_t block, unsigned option_id, unsigned idx, const char *value, size_t value_length) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1186,7 +1185,7 @@ wtap_block_set_nth_string_option_value(wtap_block_t block, guint option_id, guin } wtap_opttype_return_val -wtap_block_set_string_option_value_format(wtap_block_t block, guint option_id, const char *format, ...) +wtap_block_set_string_option_value_format(wtap_block_t block, unsigned option_id, const char *format, ...) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1215,7 +1214,7 @@ wtap_block_set_string_option_value_format(wtap_block_t block, guint option_id, c } wtap_opttype_return_val -wtap_block_set_nth_string_option_value_format(wtap_block_t block, guint option_id, guint idx, const char *format, ...) +wtap_block_set_nth_string_option_value_format(wtap_block_t block, unsigned option_id, unsigned idx, const char *format, ...) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1232,7 +1231,7 @@ wtap_block_set_nth_string_option_value_format(wtap_block_t block, guint option_i } wtap_opttype_return_val -wtap_block_get_string_option_value(wtap_block_t block, guint option_id, char** value) +wtap_block_get_string_option_value(wtap_block_t block, unsigned option_id, char** value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1245,7 +1244,7 @@ wtap_block_get_string_option_value(wtap_block_t block, guint option_id, char** v } wtap_opttype_return_val -wtap_block_get_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, char** value) +wtap_block_get_nth_string_option_value(wtap_block_t block, unsigned option_id, unsigned idx, char** value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1258,7 +1257,7 @@ wtap_block_get_nth_string_option_value(wtap_block_t block, guint option_id, guin } wtap_opttype_return_val -wtap_block_add_bytes_option(wtap_block_t block, guint option_id, const guint8 *value, gsize value_length) +wtap_block_add_bytes_option(wtap_block_t block, unsigned option_id, const uint8_t *value, size_t value_length) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1271,7 +1270,7 @@ wtap_block_add_bytes_option(wtap_block_t block, guint option_id, const guint8 *v } wtap_opttype_return_val -wtap_block_add_bytes_option_borrow(wtap_block_t block, guint option_id, GBytes *value) +wtap_block_add_bytes_option_borrow(wtap_block_t block, unsigned option_id, GBytes *value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1284,7 +1283,7 @@ wtap_block_add_bytes_option_borrow(wtap_block_t block, guint option_id, GBytes * } wtap_opttype_return_val -wtap_block_set_bytes_option_value(wtap_block_t block, guint option_id, const guint8 *value, size_t value_length) +wtap_block_set_bytes_option_value(wtap_block_t block, unsigned option_id, const uint8_t *value, size_t value_length) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1307,7 +1306,7 @@ wtap_block_set_bytes_option_value(wtap_block_t block, guint option_id, const gui } wtap_opttype_return_val -wtap_block_set_nth_bytes_option_value(wtap_block_t block, guint option_id, guint idx, GBytes *value) +wtap_block_set_nth_bytes_option_value(wtap_block_t block, unsigned option_id, unsigned idx, GBytes *value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1321,7 +1320,7 @@ wtap_block_set_nth_bytes_option_value(wtap_block_t block, guint option_id, guint } wtap_opttype_return_val -wtap_block_get_bytes_option_value(wtap_block_t block, guint option_id, GBytes** value) +wtap_block_get_bytes_option_value(wtap_block_t block, unsigned option_id, GBytes** value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1334,7 +1333,7 @@ wtap_block_get_bytes_option_value(wtap_block_t block, guint option_id, GBytes** } wtap_opttype_return_val -wtap_block_get_nth_bytes_option_value(wtap_block_t block, guint option_id, guint idx, GBytes** value) +wtap_block_get_nth_bytes_option_value(wtap_block_t block, unsigned option_id, unsigned idx, GBytes** value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1347,7 +1346,7 @@ wtap_block_get_nth_bytes_option_value(wtap_block_t block, guint option_id, guint } wtap_opttype_return_val -wtap_block_add_nflx_custom_option(wtap_block_t block, guint32 type, const char *custom_data, gsize custom_data_len) +wtap_block_add_nflx_custom_option(wtap_block_t block, uint32_t type, const char *custom_data, size_t custom_data_len) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1364,11 +1363,11 @@ wtap_block_add_nflx_custom_option(wtap_block_t block, guint32 type, const char * } wtap_opttype_return_val -wtap_block_get_nflx_custom_option(wtap_block_t block, guint32 nflx_type, char *nflx_custom_data _U_, gsize nflx_custom_data_len) +wtap_block_get_nflx_custom_option(wtap_block_t block, uint32_t nflx_type, char *nflx_custom_data _U_, size_t nflx_custom_data_len) { const wtap_opttype_t *opttype; wtap_option_t *opt; - guint i; + unsigned i; if (block == NULL) { return WTAP_OPTTYPE_BAD_BLOCK; @@ -1397,11 +1396,11 @@ wtap_block_get_nflx_custom_option(wtap_block_t block, guint32 nflx_type, char *n } switch (nflx_type) { case NFLX_OPT_TYPE_VERSION: { - guint32 *src, *dst; + uint32_t *src, *dst; - ws_assert(nflx_custom_data_len == sizeof(guint32)); - src = (guint32 *)opt->value.custom_opt.data.nflx_data.custom_data; - dst = (guint32 *)nflx_custom_data; + ws_assert(nflx_custom_data_len == sizeof(uint32_t)); + src = (uint32_t *)opt->value.custom_opt.data.nflx_data.custom_data; + dst = (uint32_t *)nflx_custom_data; *dst = GUINT32_FROM_LE(*src); break; } @@ -1512,11 +1511,11 @@ wtap_block_get_nflx_custom_option(wtap_block_t block, guint32 nflx_type, char *n break; } case NFLX_OPT_TYPE_DUMPTIME: { - guint64 *src, *dst; + uint64_t *src, *dst; - ws_assert(nflx_custom_data_len == sizeof(guint64)); - src = (guint64 *)opt->value.custom_opt.data.nflx_data.custom_data; - dst = (guint64 *)nflx_custom_data; + ws_assert(nflx_custom_data_len == sizeof(uint64_t)); + src = (uint64_t *)opt->value.custom_opt.data.nflx_data.custom_data; + dst = (uint64_t *)nflx_custom_data; *dst = GUINT64_FROM_LE(*src); break; } @@ -1531,7 +1530,7 @@ wtap_block_get_nflx_custom_option(wtap_block_t block, guint32 nflx_type, char *n } wtap_opttype_return_val -wtap_block_add_custom_option(wtap_block_t block, guint option_id, guint32 pen, const char *custom_data, gsize custom_data_len) +wtap_block_add_custom_option(wtap_block_t block, unsigned option_id, uint32_t pen, const char *custom_data, size_t custom_data_len) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1546,7 +1545,7 @@ wtap_block_add_custom_option(wtap_block_t block, guint option_id, guint32 pen, c } wtap_opttype_return_val -wtap_block_add_if_filter_option(wtap_block_t block, guint option_id, if_filter_opt_t* value) +wtap_block_add_if_filter_option(wtap_block_t block, unsigned option_id, if_filter_opt_t* value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1559,7 +1558,7 @@ wtap_block_add_if_filter_option(wtap_block_t block, guint option_id, if_filter_o } wtap_opttype_return_val -wtap_block_set_if_filter_option_value(wtap_block_t block, guint option_id, if_filter_opt_t* value) +wtap_block_set_if_filter_option_value(wtap_block_t block, unsigned option_id, if_filter_opt_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1577,7 +1576,7 @@ wtap_block_set_if_filter_option_value(wtap_block_t block, guint option_id, if_fi } wtap_opttype_return_val -wtap_block_get_if_filter_option_value(wtap_block_t block, guint option_id, if_filter_opt_t* value) +wtap_block_get_if_filter_option_value(wtap_block_t block, unsigned option_id, if_filter_opt_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1590,7 +1589,7 @@ wtap_block_get_if_filter_option_value(wtap_block_t block, guint option_id, if_fi } wtap_opttype_return_val -wtap_block_add_packet_verdict_option(wtap_block_t block, guint option_id, packet_verdict_opt_t* value) +wtap_block_add_packet_verdict_option(wtap_block_t block, unsigned option_id, packet_verdict_opt_t* value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1603,7 +1602,7 @@ wtap_block_add_packet_verdict_option(wtap_block_t block, guint option_id, packet } wtap_opttype_return_val -wtap_block_set_nth_packet_verdict_option_value(wtap_block_t block, guint option_id, guint idx, packet_verdict_opt_t* value) +wtap_block_set_nth_packet_verdict_option_value(wtap_block_t block, unsigned option_id, unsigned idx, packet_verdict_opt_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1621,7 +1620,7 @@ wtap_block_set_nth_packet_verdict_option_value(wtap_block_t block, guint option_ } wtap_opttype_return_val -wtap_block_get_nth_packet_verdict_option_value(wtap_block_t block, guint option_id, guint idx, packet_verdict_opt_t* value) +wtap_block_get_nth_packet_verdict_option_value(wtap_block_t block, unsigned option_id, unsigned idx, packet_verdict_opt_t* value) { wtap_opttype_return_val ret; wtap_optval_t *optval; @@ -1634,7 +1633,7 @@ wtap_block_get_nth_packet_verdict_option_value(wtap_block_t block, guint option_ } wtap_opttype_return_val -wtap_block_add_packet_hash_option(wtap_block_t block, guint option_id, packet_hash_opt_t* value) +wtap_block_add_packet_hash_option(wtap_block_t block, unsigned option_id, packet_hash_opt_t* value) { wtap_opttype_return_val ret; wtap_option_t *opt; @@ -1647,10 +1646,10 @@ wtap_block_add_packet_hash_option(wtap_block_t block, guint option_id, packet_ha } wtap_opttype_return_val -wtap_block_remove_option(wtap_block_t block, guint option_id) +wtap_block_remove_option(wtap_block_t block, unsigned option_id) { const wtap_opttype_t *opttype; - guint i; + unsigned i; wtap_option_t *opt; if (block == NULL) { @@ -1689,13 +1688,13 @@ wtap_block_remove_option(wtap_block_t block, guint option_id) } wtap_opttype_return_val -wtap_block_remove_nth_option_instance(wtap_block_t block, guint option_id, - guint idx) +wtap_block_remove_nth_option_instance(wtap_block_t block, unsigned option_id, + unsigned idx) { const wtap_opttype_t *opttype; - guint i; + unsigned i; wtap_option_t *opt; - guint opt_idx; + unsigned opt_idx; if (block == NULL) { return WTAP_OPTTYPE_BAD_BLOCK; @@ -1763,7 +1762,7 @@ static void nrb_free_mand(wtap_block_t block) } #if 0 -static gpointer copy_hashipv4(gconstpointer src, gpointer user_data _U_ +static void *copy_hashipv4(const void *src, void *user_data _U_ { hashipv4_t *src_ipv4 = (hashipv4_t*)src; hashipv4_t *dst = g_new0(hashipv4_t, 1); @@ -1772,7 +1771,7 @@ static gpointer copy_hashipv4(gconstpointer src, gpointer user_data _U_ return dst; } -static gpointer copy_hashipv4(gconstpointer src, gpointer user_data _U_ +static void *copy_hashipv4(const void *src, void *user_data _U_ { hashipv6_t *src_ipv6 = (hashipv6_t*)src; hashipv6_t *dst = g_new0(hashipv6_t, 1); @@ -1809,7 +1808,7 @@ static void idb_create(wtap_block_t block) static void idb_free_mand(wtap_block_t block) { - guint j; + unsigned j; wtap_block_t if_stats; wtapng_if_descr_mandatory_t* mand = (wtapng_if_descr_mandatory_t*)block->mandatory_data; @@ -1819,24 +1818,24 @@ static void idb_free_mand(wtap_block_t block) } if (mand->interface_statistics) - g_array_free(mand->interface_statistics, TRUE); + g_array_free(mand->interface_statistics, true); } static void idb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block) { - guint j; + unsigned j; wtap_block_t src_if_stats, dest_if_stats; wtapng_if_descr_mandatory_t *src_mand = (wtapng_if_descr_mandatory_t*)src_block->mandatory_data, *dest_mand = (wtapng_if_descr_mandatory_t*)dest_block->mandatory_data; /* Need special consideration for copying of the interface_statistics member */ if (dest_mand->num_stat_entries != 0) - g_array_free(dest_mand->interface_statistics, TRUE); + g_array_free(dest_mand->interface_statistics, true); memcpy(dest_mand, src_mand, sizeof(wtapng_if_descr_mandatory_t)); if (src_mand->num_stat_entries != 0) { - dest_mand->interface_statistics = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); + dest_mand->interface_statistics = g_array_new(false, false, sizeof(wtap_block_t)); for (j = 0; j < src_mand->num_stat_entries; j++) { src_if_stats = g_array_index(src_mand->interface_statistics, wtap_block_t, j); @@ -1864,28 +1863,28 @@ static void dsb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block) dst->secrets_type = src->secrets_type; dst->secrets_len = src->secrets_len; g_free(dst->secrets_data); - dst->secrets_data = (guint8 *)g_memdup2(src->secrets_data, src->secrets_len); + dst->secrets_data = (uint8_t *)g_memdup2(src->secrets_data, src->secrets_len); } -static void sysdig_mev_create(wtap_block_t block) +static void mev_create(wtap_block_t block) { - block->mandatory_data = g_new0(wtapng_sysdig_mev_mandatory_t, 1); + block->mandatory_data = g_new0(wtapng_meta_event_mandatory_t, 1); } -static void sysdig_mev_free_mand(wtap_block_t block) +static void mev_free_mand(wtap_block_t block) { - wtapng_sysdig_mev_mandatory_t *mand = (wtapng_sysdig_mev_mandatory_t *)block->mandatory_data; + wtapng_meta_event_mandatory_t *mand = (wtapng_meta_event_mandatory_t *)block->mandatory_data; g_free(mand->mev_data); } -static void sysdig_mev_copy_mand(wtap_block_t dest_block, wtap_block_t src_block) +static void mev_copy_mand(wtap_block_t dest_block, wtap_block_t src_block) { - wtapng_sysdig_mev_mandatory_t *src = (wtapng_sysdig_mev_mandatory_t *)src_block->mandatory_data; - wtapng_sysdig_mev_mandatory_t *dst = (wtapng_sysdig_mev_mandatory_t *)dest_block->mandatory_data; - dst->mev_type = src->mev_type; + wtapng_meta_event_mandatory_t *src = (wtapng_meta_event_mandatory_t *)src_block->mandatory_data; + wtapng_meta_event_mandatory_t *dst = (wtapng_meta_event_mandatory_t *)dest_block->mandatory_data; + dst->mev_block_type = src->mev_block_type; dst->mev_data_len = src->mev_data_len; g_free(dst->mev_data); - dst->mev_data = (guint8 *)g_memdup2(src->mev_data, src->mev_data_len); + dst->mev_data = (uint8_t *)g_memdup2(src->mev_data, src->mev_data_len); } static void pkt_create(wtap_block_t block) @@ -2105,13 +2104,13 @@ void wtap_opttypes_initialize(void) 0 }; - static wtap_blocktype_t sysdig_mev_block = { - WTAP_BLOCK_SYSDIG_META_EVENT, - "Sysdig MEV", - "Sysdig Meta Event Block", - sysdig_mev_create, - sysdig_mev_free_mand, - sysdig_mev_copy_mand, + static wtap_blocktype_t mev_block = { + WTAP_BLOCK_META_EVENT, + "MEV", + "Meta Event Block", + mev_create, + mev_free_mand, + mev_copy_mand, NULL }; @@ -2231,7 +2230,7 @@ void wtap_opttypes_initialize(void) /* * Register the Sysdig MEV, currently no options are defined. */ - wtap_opttype_block_register(&sysdig_mev_block); + wtap_opttype_block_register(&mev_block); /* * Register EPB/SPB/PB and the options that can appear in it/them. @@ -2264,16 +2263,16 @@ void wtap_opttypes_initialize(void) void wtap_opttypes_cleanup(void) { - guint block_type; + unsigned block_type; #ifdef DEBUG_COUNT_REFS - guint i; - guint cellno; - guint bitno; - guint8 mask; + unsigned i; + unsigned cellno; + unsigned bitno; + uint8_t mask; #endif /* DEBUG_COUNT_REFS */ - for (block_type = (guint)WTAP_BLOCK_SECTION; - block_type < (guint)MAX_WTAP_BLOCK_TYPE_VALUE; block_type++) { + for (block_type = (unsigned)WTAP_BLOCK_SECTION; + block_type < (unsigned)MAX_WTAP_BLOCK_TYPE_VALUE; block_type++) { if (blocktype_list[block_type]) { if (blocktype_list[block_type]->options) g_hash_table_destroy(blocktype_list[block_type]->options); diff --git a/wiretap/wtap_opttypes.h b/wiretap/wtap_opttypes.h index 91dafd6c..665f18a0 100644 --- a/wiretap/wtap_opttypes.h +++ b/wiretap/wtap_opttypes.h @@ -12,8 +12,7 @@ #include "ws_symbol_export.h" -#include <wsutil/inet_ipv4.h> -#include <wsutil/inet_ipv6.h> +#include <wsutil/inet_addr.h> #ifdef __cplusplus extern "C" { @@ -192,7 +191,7 @@ typedef enum { WTAP_BLOCK_FT_SPECIFIC_REPORT, WTAP_BLOCK_FT_SPECIFIC_EVENT, WTAP_BLOCK_SYSDIG_EVENT, - WTAP_BLOCK_SYSDIG_META_EVENT, + WTAP_BLOCK_META_EVENT, WTAP_BLOCK_SYSTEMD_JOURNAL_EXPORT, WTAP_BLOCK_CUSTOM, MAX_WTAP_BLOCK_TYPE_VALUE @@ -202,7 +201,7 @@ typedef enum { * Holds the required data from a WTAP_BLOCK_SECTION. */ typedef struct wtapng_section_mandatory_s { - guint64 section_length; /**< 64-bit value specifying the length in bytes of the + uint64_t section_length; /**< 64-bit value specifying the length in bytes of the * following section. * Section Length equal -1 (0xFFFFFFFFFFFFFFFF) means * that the size of the section is not specified @@ -225,12 +224,12 @@ typedef struct wtapng_iface_descriptions_s { */ typedef struct wtapng_if_descr_mandatory_s { int wtap_encap; /**< link_type translated to wtap_encap */ - guint64 time_units_per_second; + uint64_t time_units_per_second; int tsprecision; /**< WTAP_TSPREC_ value for this interface */ - guint32 snap_len; + uint32_t snap_len; - guint8 num_stat_entries; + uint8_t num_stat_entries; GArray *interface_statistics; /**< An array holding the interface statistics from * pcapng ISB:s or equivalent(?)*/ } wtapng_if_descr_mandatory_t; @@ -247,28 +246,28 @@ typedef struct wtapng_nrb_mandatory_s { * Holds the required data from a WTAP_BLOCK_IF_STATISTICS. */ typedef struct wtapng_if_stats_mandatory_s { - guint32 interface_id; - guint32 ts_high; - guint32 ts_low; + uint32_t interface_id; + uint32_t ts_high; + uint32_t ts_low; } wtapng_if_stats_mandatory_t; /** * Holds the required data from a WTAP_BLOCK_DECRYPTION_SECRETS. */ typedef struct wtapng_dsb_mandatory_s { - guint32 secrets_type; /** Type of secrets stored in data (see secrets-types.h) */ - guint32 secrets_len; /** Length of the secrets data in bytes */ - guint8 *secrets_data; /** Buffer of secrets (not NUL-terminated) */ + uint32_t secrets_type; /** Type of secrets stored in data (see secrets-types.h) */ + uint32_t secrets_len; /** Length of the secrets data in bytes */ + uint8_t *secrets_data; /** Buffer of secrets (not NUL-terminated) */ } wtapng_dsb_mandatory_t; /** - * Holds the required data from a WTAP_BLOCK_SYSDIG_META_EVENT. + * Holds the required data from a WTAP_BLOCK_META_EVENT. */ -typedef struct wtapng_sysdig_mev_mandatory_s { - uint32_t mev_type; /** pcapng block type of the event, e.g. BLOCK_TYPE_SYSDIG_MI */ - uint32_t mev_data_len; /** Length of the mev data in bytes */ +typedef struct wtapng_meta_event_mandatory_s { + uint32_t mev_block_type; /** pcapng block type of the event, e.g. BLOCK_TYPE_SYSDIG_MI */ + unsigned mev_data_len; /** Length of the mev data in bytes */ uint8_t *mev_data; /** Buffer of mev data (not NUL-terminated) */ -} wtapng_sysdig_mev_mandatory_t; +} wtapng_meta_event_mandatory_t; /** * Holds the required data from a WTAP_BLOCK_PACKET. @@ -281,11 +280,11 @@ typedef struct wtapng_sysdig_mev_mandatory_s { * Wireshark in other ways. */ typedef struct wtapng_packet_mandatory_s { - guint32 interface_id; - guint32 ts_high; - guint32 ts_low; - guint32 captured_len; - guint32 orig_len; + uint32_t interface_id; + uint32_t ts_high; + uint32_t ts_low; + uint32_t captured_len; + uint32_t orig_len; } wtapng_packet_mandatory_t; #endif @@ -293,7 +292,7 @@ typedef struct wtapng_packet_mandatory_s { * Holds the required data from a WTAP_BLOCK_FT_SPECIFIC_REPORT. */ typedef struct wtapng_ft_specific_mandatory_s { - guint record_type; /* the type of record this is - file type-specific value */ + unsigned record_type; /* the type of record this is - file type-specific value */ } wtapng_ft_specific_mandatory_t; /* @@ -339,17 +338,17 @@ typedef enum { */ typedef struct custom_opt_s { - guint32 pen; + uint32_t pen; union { struct generic_custom_opt_data { - gsize custom_data_len; - gchar *custom_data; + size_t custom_data_len; + char *custom_data; } generic_data; struct nflx_custom_opt_data { - guint32 type; - gsize custom_data_len; - gchar *custom_data; - gboolean use_little_endian; + uint32_t type; + size_t custom_data_len; + char *custom_data; + bool use_little_endian; } nflx_data; } data; } custom_opt_t; @@ -358,20 +357,20 @@ typedef struct custom_opt_s { * Structure describing a NFLX custom option. */ typedef struct nflx_custom_opt_s { - gboolean nflx_use_little_endian; - guint32 nflx_type; - gsize nflx_custom_data_len; - gchar *nflx_custom_data; + bool nflx_use_little_endian; + uint32_t nflx_type; + size_t nflx_custom_data_len; + char *nflx_custom_data; } nflx_custom_opt_t; /* Interface description data - if_filter option structure */ /* BPF instruction */ typedef struct wtap_bpf_insn_s { - guint16 code; - guint8 jt; - guint8 jf; - guint32 k; + uint16_t code; + uint8_t jt; + uint8_t jf; + uint32_t k; } wtap_bpf_insn_t; /* @@ -385,9 +384,9 @@ typedef enum { typedef struct if_filter_opt_s { if_filter_type_e type; union { - gchar *filter_str; /**< pcap filter string */ + char *filter_str; /**< pcap filter string */ struct wtap_bpf_insns { - guint bpf_prog_len; /**< number of BPF instructions */ + unsigned bpf_prog_len; /**< number of BPF instructions */ wtap_bpf_insn_t *bpf_prog; /**< BPF instructions */ } bpf_prog; /**< BPF program */ } data; @@ -408,13 +407,13 @@ typedef struct packet_verdict_opt_s { packet_verdict_type_e type; union { GByteArray *verdict_bytes; - guint64 verdict_linux_ebpf_tc; - guint64 verdict_linux_ebpf_xdp; + uint64_t verdict_linux_ebpf_tc; + uint64_t verdict_linux_ebpf_xdp; } data; } packet_verdict_opt_t; typedef struct packet_hash_opt_s { - guint8 type; + uint8_t type; GByteArray *hash_bytes; } packet_hash_opt_t; @@ -422,12 +421,12 @@ typedef struct packet_hash_opt_s { * Structure describing a value of an option. */ typedef union { - guint8 uint8val; - guint32 uint32val; - guint64 uint64val; - gint8 int8val; - gint32 int32val; - gint64 int64val; + uint8_t uint8val; + uint32_t uint32val; + uint64_t uint64val; + int8_t int8val; + int32_t int32val; + int64_t int64val; ws_in4_addr ipv4val; /* network byte order */ ws_in6_addr ipv6val; char *stringval; @@ -442,7 +441,7 @@ typedef union { * Structure describing an option in a block. */ typedef struct { - guint option_id; /**< option code for the option */ + unsigned option_id; /**< option code for the option */ wtap_optval_t value; /**< value */ } wtap_option_t; @@ -453,21 +452,21 @@ typedef struct { #define NFLX_OPT_TYPE_STACKNAME 6 struct nflx_dumpinfo { - guint32 tlh_version; - guint32 tlh_type; - guint64 tlh_length; - guint16 tlh_ie_fport; - guint16 tlh_ie_lport; - guint32 tlh_ie_faddr_addr32[4]; - guint32 tlh_ie_laddr_addr32[4]; - guint32 tlh_ie_zoneid; - guint64 tlh_offset_tv_sec; - guint64 tlh_offset_tv_usec; + uint32_t tlh_version; + uint32_t tlh_type; + uint64_t tlh_length; + uint16_t tlh_ie_fport; + uint16_t tlh_ie_lport; + uint32_t tlh_ie_faddr_addr32[4]; + uint32_t tlh_ie_laddr_addr32[4]; + uint32_t tlh_ie_zoneid; + uint64_t tlh_offset_tv_sec; + uint64_t tlh_offset_tv_usec; char tlh_id[64]; char tlh_reason[32]; char tlh_tag[32]; - guint8 tlh_af; - guint8 _pad[7]; + uint8_t tlh_af; + uint8_t _pad[7]; }; /* Flags used in tlb_eventflags */ @@ -486,80 +485,80 @@ struct nflx_dumpinfo { #define NFLX_TLB_IS_SYNCHRONIZED(state) (state >= NFLX_TLB_TCPS_ESTABLISHED) struct nflx_tcpinfo { - guint64 tlb_tv_sec; - guint64 tlb_tv_usec; - guint32 tlb_ticks; - guint32 tlb_sn; - guint8 tlb_stackid; - guint8 tlb_eventid; - guint16 tlb_eventflags; - gint32 tlb_errno; - guint32 tlb_rxbuf_tls_sb_acc; - guint32 tlb_rxbuf_tls_sb_ccc; - guint32 tlb_rxbuf_tls_sb_spare; - guint32 tlb_txbuf_tls_sb_acc; - guint32 tlb_txbuf_tls_sb_ccc; - guint32 tlb_txbuf_tls_sb_spare; - gint32 tlb_state; - guint32 tlb_starttime; - guint32 tlb_iss; - guint32 tlb_flags; - guint32 tlb_snd_una; - guint32 tlb_snd_max; - guint32 tlb_snd_cwnd; - guint32 tlb_snd_nxt; - guint32 tlb_snd_recover; - guint32 tlb_snd_wnd; - guint32 tlb_snd_ssthresh; - guint32 tlb_srtt; - guint32 tlb_rttvar; - guint32 tlb_rcv_up; - guint32 tlb_rcv_adv; - guint32 tlb_flags2; - guint32 tlb_rcv_nxt; - guint32 tlb_rcv_wnd; - guint32 tlb_dupacks; - gint32 tlb_segqlen; - gint32 tlb_snd_numholes; - guint32 tlb_flex1; - guint32 tlb_flex2; - guint32 tlb_fbyte_in; - guint32 tlb_fbyte_out; - guint8 tlb_snd_scale:4, + uint64_t tlb_tv_sec; + uint64_t tlb_tv_usec; + uint32_t tlb_ticks; + uint32_t tlb_sn; + uint8_t tlb_stackid; + uint8_t tlb_eventid; + uint16_t tlb_eventflags; + int32_t tlb_errno; + uint32_t tlb_rxbuf_tls_sb_acc; + uint32_t tlb_rxbuf_tls_sb_ccc; + uint32_t tlb_rxbuf_tls_sb_spare; + uint32_t tlb_txbuf_tls_sb_acc; + uint32_t tlb_txbuf_tls_sb_ccc; + uint32_t tlb_txbuf_tls_sb_spare; + int32_t tlb_state; + uint32_t tlb_starttime; + uint32_t tlb_iss; + uint32_t tlb_flags; + uint32_t tlb_snd_una; + uint32_t tlb_snd_max; + uint32_t tlb_snd_cwnd; + uint32_t tlb_snd_nxt; + uint32_t tlb_snd_recover; + uint32_t tlb_snd_wnd; + uint32_t tlb_snd_ssthresh; + uint32_t tlb_srtt; + uint32_t tlb_rttvar; + uint32_t tlb_rcv_up; + uint32_t tlb_rcv_adv; + uint32_t tlb_flags2; + uint32_t tlb_rcv_nxt; + uint32_t tlb_rcv_wnd; + uint32_t tlb_dupacks; + int32_t tlb_segqlen; + int32_t tlb_snd_numholes; + uint32_t tlb_flex1; + uint32_t tlb_flex2; + uint32_t tlb_fbyte_in; + uint32_t tlb_fbyte_out; + uint8_t tlb_snd_scale:4, tlb_rcv_scale:4; - guint8 _pad[3]; + uint8_t _pad[3]; /* The following fields might become part of a union */ - guint64 tlb_stackinfo_bbr_cur_del_rate; - guint64 tlb_stackinfo_bbr_delRate; - guint64 tlb_stackinfo_bbr_rttProp; - guint64 tlb_stackinfo_bbr_bw_inuse; - guint32 tlb_stackinfo_bbr_inflight; - guint32 tlb_stackinfo_bbr_applimited; - guint32 tlb_stackinfo_bbr_delivered; - guint32 tlb_stackinfo_bbr_timeStamp; - guint32 tlb_stackinfo_bbr_epoch; - guint32 tlb_stackinfo_bbr_lt_epoch; - guint32 tlb_stackinfo_bbr_pkts_out; - guint32 tlb_stackinfo_bbr_flex1; - guint32 tlb_stackinfo_bbr_flex2; - guint32 tlb_stackinfo_bbr_flex3; - guint32 tlb_stackinfo_bbr_flex4; - guint32 tlb_stackinfo_bbr_flex5; - guint32 tlb_stackinfo_bbr_flex6; - guint32 tlb_stackinfo_bbr_lost; - guint16 tlb_stackinfo_bbr_pacing_gain; - guint16 tlb_stackinfo_bbr_cwnd_gain; - guint16 tlb_stackinfo_bbr_flex7; - guint8 tlb_stackinfo_bbr_bbr_state; - guint8 tlb_stackinfo_bbr_bbr_substate; - guint8 tlb_stackinfo_bbr_inhpts; - guint8 tlb_stackinfo_bbr_ininput; - guint8 tlb_stackinfo_bbr_use_lt_bw; - guint8 tlb_stackinfo_bbr_flex8; - guint32 tlb_stackinfo_bbr_pkt_epoch; - - guint32 tlb_len; + uint64_t tlb_stackinfo_bbr_cur_del_rate; + uint64_t tlb_stackinfo_bbr_delRate; + uint64_t tlb_stackinfo_bbr_rttProp; + uint64_t tlb_stackinfo_bbr_bw_inuse; + uint32_t tlb_stackinfo_bbr_inflight; + uint32_t tlb_stackinfo_bbr_applimited; + uint32_t tlb_stackinfo_bbr_delivered; + uint32_t tlb_stackinfo_bbr_timeStamp; + uint32_t tlb_stackinfo_bbr_epoch; + uint32_t tlb_stackinfo_bbr_lt_epoch; + uint32_t tlb_stackinfo_bbr_pkts_out; + uint32_t tlb_stackinfo_bbr_flex1; + uint32_t tlb_stackinfo_bbr_flex2; + uint32_t tlb_stackinfo_bbr_flex3; + uint32_t tlb_stackinfo_bbr_flex4; + uint32_t tlb_stackinfo_bbr_flex5; + uint32_t tlb_stackinfo_bbr_flex6; + uint32_t tlb_stackinfo_bbr_lost; + uint16_t tlb_stackinfo_bbr_pacing_gain; + uint16_t tlb_stackinfo_bbr_cwnd_gain; + uint16_t tlb_stackinfo_bbr_flex7; + uint8_t tlb_stackinfo_bbr_bbr_state; + uint8_t tlb_stackinfo_bbr_bbr_substate; + uint8_t tlb_stackinfo_bbr_inhpts; + uint8_t tlb_stackinfo_bbr_ininput; + uint8_t tlb_stackinfo_bbr_use_lt_bw; + uint8_t tlb_stackinfo_bbr_flex8; + uint32_t tlb_stackinfo_bbr_pkt_epoch; + + uint32_t tlb_len; }; typedef void (*wtap_block_create_func)(wtap_block_t block); @@ -658,10 +657,10 @@ wtap_block_get_mandatory_data(wtap_block_t block); * * @param[in] block Block to which to add the option * @param[in] option_id Identifier value for option - * @return guint - the number of times the option was found + * @return unsigned - the number of times the option was found */ -WS_DLL_PUBLIC guint -wtap_block_count_option(wtap_block_t block, guint option_id); +WS_DLL_PUBLIC unsigned +wtap_block_count_option(wtap_block_t block, unsigned option_id); /** Add UINT8 option value to a block * @@ -672,7 +671,7 @@ wtap_block_count_option(wtap_block_t block, guint option_id); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_uint8_option(wtap_block_t block, guint option_id, guint8 value); +wtap_block_add_uint8_option(wtap_block_t block, unsigned option_id, uint8_t value); /** Set UINT8 option value in a block * @@ -683,7 +682,7 @@ wtap_block_add_uint8_option(wtap_block_t block, guint option_id, guint8 value); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_uint8_option_value(wtap_block_t block, guint option_id, guint8 value); +wtap_block_set_uint8_option_value(wtap_block_t block, unsigned option_id, uint8_t value); /** Get UINT8 option value from a block * @@ -694,7 +693,7 @@ wtap_block_set_uint8_option_value(wtap_block_t block, guint option_id, guint8 va * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_uint8_option_value(wtap_block_t block, guint option_id, guint8* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_uint8_option_value(wtap_block_t block, unsigned option_id, uint8_t* value) G_GNUC_WARN_UNUSED_RESULT; /** Add UINT32 option value to a block * @@ -705,7 +704,7 @@ wtap_block_get_uint8_option_value(wtap_block_t block, guint option_id, guint8* v * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_uint32_option(wtap_block_t block, guint option_id, guint32 value); +wtap_block_add_uint32_option(wtap_block_t block, unsigned option_id, uint32_t value); /** Set UINT32 option value in a block * @@ -716,7 +715,7 @@ wtap_block_add_uint32_option(wtap_block_t block, guint option_id, guint32 value) * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_uint32_option_value(wtap_block_t block, guint option_id, guint32 value); +wtap_block_set_uint32_option_value(wtap_block_t block, unsigned option_id, uint32_t value); /** Get UINT32 option value from a block * @@ -727,7 +726,7 @@ wtap_block_set_uint32_option_value(wtap_block_t block, guint option_id, guint32 * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_uint32_option_value(wtap_block_t block, guint option_id, guint32* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_uint32_option_value(wtap_block_t block, unsigned option_id, uint32_t* value) G_GNUC_WARN_UNUSED_RESULT; /** Add UINT64 option value to a block * @@ -738,7 +737,7 @@ wtap_block_get_uint32_option_value(wtap_block_t block, guint option_id, guint32* * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_uint64_option(wtap_block_t block, guint option_id, guint64 value); +wtap_block_add_uint64_option(wtap_block_t block, unsigned option_id, uint64_t value); /** Set UINT64 option value in a block * @@ -749,7 +748,7 @@ wtap_block_add_uint64_option(wtap_block_t block, guint option_id, guint64 value) * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_uint64_option_value(wtap_block_t block, guint option_id, guint64 value); +wtap_block_set_uint64_option_value(wtap_block_t block, unsigned option_id, uint64_t value); /** Get UINT64 option value from a block * @@ -760,7 +759,7 @@ wtap_block_set_uint64_option_value(wtap_block_t block, guint option_id, guint64 * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_uint64_option_value(wtap_block_t block, guint option_id, guint64* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_uint64_option_value(wtap_block_t block, unsigned option_id, uint64_t* value) G_GNUC_WARN_UNUSED_RESULT; /** Add INT8 option value to a block * @@ -771,7 +770,7 @@ wtap_block_get_uint64_option_value(wtap_block_t block, guint option_id, guint64* * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_int8_option(wtap_block_t block, guint option_id, gint8 value); +wtap_block_add_int8_option(wtap_block_t block, unsigned option_id, int8_t value); /** Set INT8 option value in a block * @@ -782,7 +781,7 @@ wtap_block_add_int8_option(wtap_block_t block, guint option_id, gint8 value); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_int8_option_value(wtap_block_t block, guint option_id, gint8 value); +wtap_block_set_int8_option_value(wtap_block_t block, unsigned option_id, int8_t value); /** Get INT8 option value from a block * @@ -793,7 +792,7 @@ wtap_block_set_int8_option_value(wtap_block_t block, guint option_id, gint8 valu * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_int8_option_value(wtap_block_t block, guint option_id, gint8* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_int8_option_value(wtap_block_t block, unsigned option_id, int8_t* value) G_GNUC_WARN_UNUSED_RESULT; /** Add INT32 option value to a block * @@ -804,7 +803,7 @@ wtap_block_get_int8_option_value(wtap_block_t block, guint option_id, gint8* val * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_int32_option(wtap_block_t block, guint option_id, gint32 value); +wtap_block_add_int32_option(wtap_block_t block, unsigned option_id, int32_t value); /** Set INT32 option value in a block * @@ -815,7 +814,7 @@ wtap_block_add_int32_option(wtap_block_t block, guint option_id, gint32 value); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_int32_option_value(wtap_block_t block, guint option_id, gint32 value); +wtap_block_set_int32_option_value(wtap_block_t block, unsigned option_id, int32_t value); /** Get INT32 option value from a block * @@ -826,7 +825,7 @@ wtap_block_set_int32_option_value(wtap_block_t block, guint option_id, gint32 va * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_int32_option_value(wtap_block_t block, guint option_id, gint32* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_int32_option_value(wtap_block_t block, unsigned option_id, int32_t* value) G_GNUC_WARN_UNUSED_RESULT; /** Add INT64 option value to a block * @@ -837,7 +836,7 @@ wtap_block_get_int32_option_value(wtap_block_t block, guint option_id, gint32* v * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_int64_option(wtap_block_t block, guint option_id, gint64 value); +wtap_block_add_int64_option(wtap_block_t block, unsigned option_id, int64_t value); /** Set INT64 option value in a block * @@ -848,7 +847,7 @@ wtap_block_add_int64_option(wtap_block_t block, guint option_id, gint64 value); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_int64_option_value(wtap_block_t block, guint option_id, gint64 value); +wtap_block_set_int64_option_value(wtap_block_t block, unsigned option_id, int64_t value); /** Get INT64 option value from a block * @@ -859,7 +858,7 @@ wtap_block_set_int64_option_value(wtap_block_t block, guint option_id, gint64 va * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_int64_option_value(wtap_block_t block, guint option_id, gint64* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_int64_option_value(wtap_block_t block, unsigned option_id, int64_t* value) G_GNUC_WARN_UNUSED_RESULT; /** Add IPv4 address option value to a block * @@ -870,7 +869,7 @@ wtap_block_get_int64_option_value(wtap_block_t block, guint option_id, gint64* v * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_ipv4_option(wtap_block_t block, guint option_id, guint32 value); +wtap_block_add_ipv4_option(wtap_block_t block, unsigned option_id, uint32_t value); /** Set IPv4 option value in a block * @@ -881,7 +880,7 @@ wtap_block_add_ipv4_option(wtap_block_t block, guint option_id, guint32 value); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_ipv4_option_value(wtap_block_t block, guint option_id, guint32 value); +wtap_block_set_ipv4_option_value(wtap_block_t block, unsigned option_id, uint32_t value); /** Get IPv4 option value from a block * @@ -892,7 +891,7 @@ wtap_block_set_ipv4_option_value(wtap_block_t block, guint option_id, guint32 va * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_ipv4_option_value(wtap_block_t block, guint option_id, guint32* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_ipv4_option_value(wtap_block_t block, unsigned option_id, uint32_t* value) G_GNUC_WARN_UNUSED_RESULT; /** Add IPv6 address option value to a block * @@ -903,7 +902,7 @@ wtap_block_get_ipv4_option_value(wtap_block_t block, guint option_id, guint32* v * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_ipv6_option(wtap_block_t block, guint option_id, ws_in6_addr *value); +wtap_block_add_ipv6_option(wtap_block_t block, unsigned option_id, ws_in6_addr *value); /** Set IPv6 option value in a block * @@ -914,7 +913,7 @@ wtap_block_add_ipv6_option(wtap_block_t block, guint option_id, ws_in6_addr *val * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_addr *value); +wtap_block_set_ipv6_option_value(wtap_block_t block, unsigned option_id, ws_in6_addr *value); /** Get IPv6 option value from a block * @@ -925,7 +924,7 @@ wtap_block_set_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_add * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_addr* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_ipv6_option_value(wtap_block_t block, unsigned option_id, ws_in6_addr* value) G_GNUC_WARN_UNUSED_RESULT; /** Add a string option to a block * @@ -937,7 +936,7 @@ wtap_block_get_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_add * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_string_option(wtap_block_t block, guint option_id, const char *value, gsize value_length); +wtap_block_add_string_option(wtap_block_t block, unsigned option_id, const char *value, size_t value_length); /** Add a string option to a block taking ownership of the null-terminated string. * @@ -948,7 +947,7 @@ wtap_block_add_string_option(wtap_block_t block, guint option_id, const char *va * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_string_option_owned(wtap_block_t block, guint option_id, char *value); +wtap_block_add_string_option_owned(wtap_block_t block, unsigned option_id, char *value); /** Add a string option to a block with a printf-formatted string as its value * @@ -959,7 +958,7 @@ wtap_block_add_string_option_owned(wtap_block_t block, guint option_id, char *va * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_string_option_format(wtap_block_t block, guint option_id, const char *format, ...) +wtap_block_add_string_option_format(wtap_block_t block, unsigned option_id, const char *format, ...) G_GNUC_PRINTF(3,4); /** Set string option value in a block @@ -972,7 +971,7 @@ wtap_block_add_string_option_format(wtap_block_t block, guint option_id, const c * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_string_option_value(wtap_block_t block, guint option_id, const char* value, gsize value_length); +wtap_block_set_string_option_value(wtap_block_t block, unsigned option_id, const char* value, size_t value_length); /** Set string option value for the nth instance of a particular option * in a block @@ -986,7 +985,7 @@ wtap_block_set_string_option_value(wtap_block_t block, guint option_id, const ch * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, const char* value, gsize value_length); +wtap_block_set_nth_string_option_value(wtap_block_t block, unsigned option_id, unsigned idx, const char* value, size_t value_length); /** Set string option value in a block to a printf-formatted string * @@ -997,7 +996,7 @@ wtap_block_set_nth_string_option_value(wtap_block_t block, guint option_id, guin * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_string_option_value_format(wtap_block_t block, guint option_id, const char *format, ...) +wtap_block_set_string_option_value_format(wtap_block_t block, unsigned option_id, const char *format, ...) G_GNUC_PRINTF(3,4); /** Set string option value for the nth instance of a particular option @@ -1011,7 +1010,7 @@ wtap_block_set_string_option_value_format(wtap_block_t block, guint option_id, c * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_nth_string_option_value_format(wtap_block_t block, guint option_id, guint idx, const char *format, ...) +wtap_block_set_nth_string_option_value_format(wtap_block_t block, unsigned option_id, unsigned idx, const char *format, ...) G_GNUC_PRINTF(4,5); /** Get string option value from a block @@ -1023,7 +1022,7 @@ wtap_block_set_nth_string_option_value_format(wtap_block_t block, guint option_i * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_string_option_value(wtap_block_t block, guint option_id, char** value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_string_option_value(wtap_block_t block, unsigned option_id, char** value) G_GNUC_WARN_UNUSED_RESULT; /** Get string option value for the nth instance of a particular option * in a block @@ -1036,7 +1035,7 @@ wtap_block_get_string_option_value(wtap_block_t block, guint option_id, char** v * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, char** value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_nth_string_option_value(wtap_block_t block, unsigned option_id, unsigned idx, char** value) G_GNUC_WARN_UNUSED_RESULT; /** Add a bytes option to a block * @@ -1048,7 +1047,7 @@ wtap_block_get_nth_string_option_value(wtap_block_t block, guint option_id, guin * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_bytes_option(wtap_block_t block, guint option_id, const guint8 *value, gsize value_length); +wtap_block_add_bytes_option(wtap_block_t block, unsigned option_id, const uint8_t *value, size_t value_length); /** Add a bytes option to a block, borrowing the value from a GBytes * @@ -1059,7 +1058,7 @@ wtap_block_add_bytes_option(wtap_block_t block, guint option_id, const guint8 *v * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_bytes_option_borrow(wtap_block_t block, guint option_id, GBytes *value); +wtap_block_add_bytes_option_borrow(wtap_block_t block, unsigned option_id, GBytes *value); /** Set bytes option value in a block * @@ -1071,7 +1070,7 @@ wtap_block_add_bytes_option_borrow(wtap_block_t block, guint option_id, GBytes * * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_bytes_option_value(wtap_block_t block, guint option_id, const guint8* value, gsize value_length); +wtap_block_set_bytes_option_value(wtap_block_t block, unsigned option_id, const uint8_t* value, size_t value_length); /** Set bytes option value for nth instance of a particular option in a block * @@ -1083,7 +1082,7 @@ wtap_block_set_bytes_option_value(wtap_block_t block, guint option_id, const gui * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_nth_bytes_option_value(wtap_block_t block, guint option_id, guint idx, GBytes* value); +wtap_block_set_nth_bytes_option_value(wtap_block_t block, unsigned option_id, unsigned idx, GBytes* value); /** Get bytes option value from a block * @@ -1096,7 +1095,7 @@ wtap_block_set_nth_bytes_option_value(wtap_block_t block, guint option_id, guint * (and then g_bytes_unref() when you're done with it). */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_bytes_option_value(wtap_block_t block, guint option_id, GBytes** value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_bytes_option_value(wtap_block_t block, unsigned option_id, GBytes** value) G_GNUC_WARN_UNUSED_RESULT; /** Get bytes option value for nth instance of a particular option in a block * @@ -1110,7 +1109,7 @@ wtap_block_get_bytes_option_value(wtap_block_t block, guint option_id, GBytes** * (and then g_bytes_unref() when you're done with it). */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_nth_bytes_option_value(wtap_block_t block, guint option_id, guint idx, GBytes** value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_nth_bytes_option_value(wtap_block_t block, unsigned option_id, unsigned idx, GBytes** value) G_GNUC_WARN_UNUSED_RESULT; /** Add an NFLX custom option to a block * @@ -1122,7 +1121,7 @@ wtap_block_get_nth_bytes_option_value(wtap_block_t block, guint option_id, guint * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_nflx_custom_option(wtap_block_t block, guint32 nflx_type, const char *nflx_custom_data, gsize nflx_custom_data_len); +wtap_block_add_nflx_custom_option(wtap_block_t block, uint32_t nflx_type, const char *nflx_custom_data, size_t nflx_custom_data_len); /** Get an NFLX custom option value from a block * @@ -1134,7 +1133,7 @@ wtap_block_add_nflx_custom_option(wtap_block_t block, guint32 nflx_type, const c * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_nflx_custom_option(wtap_block_t block, guint32 nflx_type, char *nflx_custom_data, gsize nflx_custom_data_len); +wtap_block_get_nflx_custom_option(wtap_block_t block, uint32_t nflx_type, char *nflx_custom_data, size_t nflx_custom_data_len); /** Add a custom option to a block * @@ -1147,7 +1146,7 @@ wtap_block_get_nflx_custom_option(wtap_block_t block, guint32 nflx_type, char *n * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_custom_option(wtap_block_t block, guint option_id, guint32 pen, const char *custom_data, gsize custom_data_len); +wtap_block_add_custom_option(wtap_block_t block, unsigned option_id, uint32_t pen, const char *custom_data, size_t custom_data_len); /** Add an if_filter option value to a block * @@ -1158,7 +1157,7 @@ wtap_block_add_custom_option(wtap_block_t block, guint option_id, guint32 pen, c * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_if_filter_option(wtap_block_t block, guint option_id, if_filter_opt_t* value); +wtap_block_add_if_filter_option(wtap_block_t block, unsigned option_id, if_filter_opt_t* value); /** Set an if_filter option value in a block * @@ -1169,7 +1168,7 @@ wtap_block_add_if_filter_option(wtap_block_t block, guint option_id, if_filter_o * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_if_filter_option_value(wtap_block_t block, guint option_id, if_filter_opt_t* value); +wtap_block_set_if_filter_option_value(wtap_block_t block, unsigned option_id, if_filter_opt_t* value); /** Get an if_filter option value from a block * @@ -1180,7 +1179,7 @@ wtap_block_set_if_filter_option_value(wtap_block_t block, guint option_id, if_fi * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_if_filter_option_value(wtap_block_t block, guint option_id, if_filter_opt_t* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_if_filter_option_value(wtap_block_t block, unsigned option_id, if_filter_opt_t* value) G_GNUC_WARN_UNUSED_RESULT; /** Add a packet_verdict option value to a block * @@ -1191,7 +1190,7 @@ wtap_block_get_if_filter_option_value(wtap_block_t block, guint option_id, if_fi * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_packet_verdict_option(wtap_block_t block, guint option_id, packet_verdict_opt_t* value); +wtap_block_add_packet_verdict_option(wtap_block_t block, unsigned option_id, packet_verdict_opt_t* value); /** Set packet_verdict option value for the nth instsance of a particular * option in a block @@ -1204,7 +1203,7 @@ wtap_block_add_packet_verdict_option(wtap_block_t block, guint option_id, packet * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_set_nth_packet_verdict_option_value(wtap_block_t block, guint option_id, guint idx, packet_verdict_opt_t* value); +wtap_block_set_nth_packet_verdict_option_value(wtap_block_t block, unsigned option_id, unsigned idx, packet_verdict_opt_t* value); /** Get packet_verdict option value for the nth instance of a particular * option in a block @@ -1217,7 +1216,7 @@ wtap_block_set_nth_packet_verdict_option_value(wtap_block_t block, guint option_ * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_get_nth_packet_verdict_option_value(wtap_block_t block, guint option_id, guint idx, packet_verdict_opt_t* value) G_GNUC_WARN_UNUSED_RESULT; +wtap_block_get_nth_packet_verdict_option_value(wtap_block_t block, unsigned option_id, unsigned idx, packet_verdict_opt_t* value) G_GNUC_WARN_UNUSED_RESULT; WS_DLL_PUBLIC void wtap_packet_verdict_free(packet_verdict_opt_t* verdict); @@ -1231,7 +1230,7 @@ wtap_packet_verdict_free(packet_verdict_opt_t* verdict); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_add_packet_hash_option(wtap_block_t block, guint option_id, packet_hash_opt_t* value); +wtap_block_add_packet_hash_option(wtap_block_t block, unsigned option_id, packet_hash_opt_t* value); WS_DLL_PUBLIC void wtap_packet_hash_free(packet_hash_opt_t* hash); @@ -1244,7 +1243,7 @@ wtap_packet_hash_free(packet_hash_opt_t* hash); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_remove_option(wtap_block_t block, guint option_id); +wtap_block_remove_option(wtap_block_t block, unsigned option_id); /** Remove the nth instance of an option from a block * @@ -1255,7 +1254,7 @@ wtap_block_remove_option(wtap_block_t block, guint option_id); * error code otherwise */ WS_DLL_PUBLIC wtap_opttype_return_val -wtap_block_remove_nth_option_instance(wtap_block_t block, guint option_id, guint idx); +wtap_block_remove_nth_option_instance(wtap_block_t block, unsigned option_id, unsigned idx); /** Copy a block to another. * @@ -1276,8 +1275,8 @@ wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block); WS_DLL_PUBLIC wtap_block_t wtap_block_make_copy(wtap_block_t block); -typedef gboolean (*wtap_block_foreach_func)(wtap_block_t block, guint option_id, wtap_opttype_e option_type, wtap_optval_t *option, void *user_data); -WS_DLL_PUBLIC gboolean +typedef bool (*wtap_block_foreach_func)(wtap_block_t block, unsigned option_id, wtap_opttype_e option_type, wtap_optval_t *option, void *user_data); +WS_DLL_PUBLIC bool wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data); /** Cleanup the internal structures |