summaryrefslogtreecommitdiffstats
path: root/wiretap/visual.c
diff options
context:
space:
mode:
Diffstat (limited to 'wiretap/visual.c')
-rw-r--r--wiretap/visual.c199
1 files changed, 100 insertions, 99 deletions
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
};