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