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