Convert ringbuffer, frame_tvbuff, and file_packet_provider to C99
Convert more files in the root directory to use C99 types. Ping #19116
This commit is contained in:
parent
ab1c56f9a9
commit
92d97c7106
6
cfile.h
6
cfile.h
@ -131,9 +131,9 @@ typedef struct _capture_file {
|
|||||||
|
|
||||||
extern void cap_file_init(capture_file *cf);
|
extern void cap_file_init(capture_file *cf);
|
||||||
|
|
||||||
const nstime_t *cap_file_provider_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num);
|
const nstime_t *cap_file_provider_get_frame_ts(struct packet_provider_data *prov, uint32_t frame_num);
|
||||||
const char *cap_file_provider_get_interface_name(struct packet_provider_data *prov, guint32 interface_id, unsigned section_number);
|
const char *cap_file_provider_get_interface_name(struct packet_provider_data *prov, uint32_t interface_id, unsigned section_number);
|
||||||
const char *cap_file_provider_get_interface_description(struct packet_provider_data *prov, guint32 interface_id, unsigned section_number);
|
const char *cap_file_provider_get_interface_description(struct packet_provider_data *prov, uint32_t interface_id, unsigned section_number);
|
||||||
wtap_block_t cap_file_provider_get_modified_block(struct packet_provider_data *prov, const frame_data *fd);
|
wtap_block_t cap_file_provider_get_modified_block(struct packet_provider_data *prov, const frame_data *fd);
|
||||||
void cap_file_provider_set_modified_block(struct packet_provider_data *prov, frame_data *fd, const wtap_block_t new_block);
|
void cap_file_provider_set_modified_block(struct packet_provider_data *prov, frame_data *fd, const wtap_block_t new_block);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include "cfile.h"
|
#include "cfile.h"
|
||||||
|
|
||||||
const nstime_t *
|
const nstime_t *
|
||||||
cap_file_provider_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
|
cap_file_provider_get_frame_ts(struct packet_provider_data *prov, uint32_t frame_num)
|
||||||
{
|
{
|
||||||
const frame_data *fd = NULL;
|
const frame_data *fd = NULL;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ frame_cmp(const void *a, const void *b, void *user_data _U_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
cap_file_provider_get_interface_name(struct packet_provider_data *prov, guint32 interface_id, unsigned section_number)
|
cap_file_provider_get_interface_name(struct packet_provider_data *prov, uint32_t interface_id, unsigned section_number)
|
||||||
{
|
{
|
||||||
wtapng_iface_descriptions_t *idb_info;
|
wtapng_iface_descriptions_t *idb_info;
|
||||||
wtap_block_t wtapng_if_descr = NULL;
|
wtap_block_t wtapng_if_descr = NULL;
|
||||||
@ -70,7 +70,7 @@ cap_file_provider_get_interface_name(struct packet_provider_data *prov, guint32
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
cap_file_provider_get_interface_description(struct packet_provider_data *prov, guint32 interface_id, unsigned section_number)
|
cap_file_provider_get_interface_description(struct packet_provider_data *prov, uint32_t interface_id, unsigned section_number)
|
||||||
{
|
{
|
||||||
wtapng_iface_descriptions_t *idb_info;
|
wtapng_iface_descriptions_t *idb_info;
|
||||||
wtap_block_t wtapng_if_descr = NULL;
|
wtap_block_t wtapng_if_descr = NULL;
|
||||||
@ -111,5 +111,5 @@ cap_file_provider_set_modified_block(struct packet_provider_data *prov, frame_da
|
|||||||
/* insert new packet block */
|
/* insert new packet block */
|
||||||
g_tree_replace(prov->frames_modified_blocks, fd, (void *)new_block);
|
g_tree_replace(prov->frames_modified_blocks, fd, (void *)new_block);
|
||||||
|
|
||||||
fd->has_modified_block = TRUE;
|
fd->has_modified_block = 1;
|
||||||
}
|
}
|
||||||
|
@ -26,17 +26,17 @@ struct tvb_frame {
|
|||||||
Buffer *buf; /* Packet data */
|
Buffer *buf; /* Packet data */
|
||||||
|
|
||||||
const struct packet_provider_data *prov; /* provider of packet information */
|
const struct packet_provider_data *prov; /* provider of packet information */
|
||||||
gint64 file_off; /**< File offset */
|
int64_t file_off; /**< File offset */
|
||||||
|
|
||||||
guint offset;
|
unsigned offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
static gboolean
|
static bool
|
||||||
frame_read(struct tvb_frame *frame_tvb, wtap_rec *rec, Buffer *buf)
|
frame_read(struct tvb_frame *frame_tvb, wtap_rec *rec, Buffer *buf)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
gchar *err_info;
|
char *err_info;
|
||||||
gboolean ok = TRUE;
|
bool ok = true;
|
||||||
|
|
||||||
/* XXX, what if phdr->caplen isn't equal to
|
/* XXX, what if phdr->caplen isn't equal to
|
||||||
* frame_tvb->tvb.length + frame_tvb->offset?
|
* frame_tvb->tvb.length + frame_tvb->offset?
|
||||||
@ -46,7 +46,7 @@ frame_read(struct tvb_frame *frame_tvb, wtap_rec *rec, Buffer *buf)
|
|||||||
switch (err) {
|
switch (err) {
|
||||||
case WTAP_ERR_BAD_FILE:
|
case WTAP_ERR_BAD_FILE:
|
||||||
g_free(err_info);
|
g_free(err_info);
|
||||||
ok = FALSE;
|
ok = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,8 +93,8 @@ frame_free(tvbuff_t *tvb)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const guint8 *
|
static const uint8_t *
|
||||||
frame_get_ptr(tvbuff_t *tvb, guint abs_offset, guint abs_length _U_)
|
frame_get_ptr(tvbuff_t *tvb, unsigned abs_offset, unsigned abs_length _U_)
|
||||||
{
|
{
|
||||||
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ frame_get_ptr(tvbuff_t *tvb, guint abs_offset, guint abs_length _U_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
frame_memcpy(tvbuff_t *tvb, void *target, guint abs_offset, guint abs_length)
|
frame_memcpy(tvbuff_t *tvb, void *target, unsigned abs_offset, unsigned abs_length)
|
||||||
{
|
{
|
||||||
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
||||||
|
|
||||||
@ -113,23 +113,23 @@ frame_memcpy(tvbuff_t *tvb, void *target, guint abs_offset, guint abs_length)
|
|||||||
return memcpy(target, tvb->real_data + abs_offset, abs_length);
|
return memcpy(target, tvb->real_data + abs_offset, abs_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static int
|
||||||
frame_find_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, guint8 needle)
|
frame_find_guint8(tvbuff_t *tvb, unsigned abs_offset, unsigned limit, uint8_t needle)
|
||||||
{
|
{
|
||||||
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
||||||
const guint8 *result;
|
const uint8_t *result;
|
||||||
|
|
||||||
frame_cache(frame_tvb);
|
frame_cache(frame_tvb);
|
||||||
|
|
||||||
result = (const guint8 *)memchr(tvb->real_data + abs_offset, needle, limit);
|
result = (const uint8_t *)memchr(tvb->real_data + abs_offset, needle, limit);
|
||||||
if (result)
|
if (result)
|
||||||
return (gint) (result - tvb->real_data);
|
return (int) (result - tvb->real_data);
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static int
|
||||||
frame_pbrk_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, const ws_mempbrk_pattern* pattern, guchar *found_needle)
|
frame_pbrk_guint8(tvbuff_t *tvb, unsigned abs_offset, unsigned limit, const ws_mempbrk_pattern* pattern, unsigned char *found_needle)
|
||||||
{
|
{
|
||||||
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
||||||
|
|
||||||
@ -138,14 +138,14 @@ frame_pbrk_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, const ws_mempbrk
|
|||||||
return tvb_ws_mempbrk_pattern_guint8(tvb, abs_offset, limit, pattern, found_needle);
|
return tvb_ws_mempbrk_pattern_guint8(tvb, abs_offset, limit, pattern, found_needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint
|
static unsigned
|
||||||
frame_offset(const tvbuff_t *tvb _U_, const guint counter)
|
frame_offset(const tvbuff_t *tvb _U_, const unsigned counter)
|
||||||
{
|
{
|
||||||
/* XXX: frame_tvb->offset */
|
/* XXX: frame_tvb->offset */
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
static tvbuff_t *frame_clone(tvbuff_t *tvb, guint abs_offset, guint abs_length);
|
static tvbuff_t *frame_clone(tvbuff_t *tvb, unsigned abs_offset, unsigned abs_length);
|
||||||
|
|
||||||
static const struct tvb_ops tvb_frame_ops = {
|
static const struct tvb_ops tvb_frame_ops = {
|
||||||
sizeof(struct tvb_frame), /* size */
|
sizeof(struct tvb_frame), /* size */
|
||||||
@ -162,7 +162,7 @@ static const struct tvb_ops tvb_frame_ops = {
|
|||||||
/* based on tvb_new_real_data() */
|
/* based on tvb_new_real_data() */
|
||||||
tvbuff_t *
|
tvbuff_t *
|
||||||
frame_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
|
frame_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
|
||||||
const guint8 *buf)
|
const uint8_t *buf)
|
||||||
{
|
{
|
||||||
struct tvb_frame *frame_tvb;
|
struct tvb_frame *frame_tvb;
|
||||||
tvbuff_t *tvb;
|
tvbuff_t *tvb;
|
||||||
@ -185,7 +185,7 @@ frame_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
|
|||||||
* filtered out, and should not be filtered out,
|
* filtered out, and should not be filtered out,
|
||||||
* as those lengths are not necessarily invalid.
|
* as those lengths are not necessarily invalid.
|
||||||
*
|
*
|
||||||
* For now, we clip the reported length at G_MAXINT
|
* For now, we clip the reported length at INT_MAX
|
||||||
*
|
*
|
||||||
* (XXX, is this still a problem?) There was an exception when we call
|
* (XXX, is this still a problem?) There was an exception when we call
|
||||||
* tvb_new_real_data() now there's no one
|
* tvb_new_real_data() now there's no one
|
||||||
@ -193,9 +193,9 @@ frame_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
|
|||||||
|
|
||||||
tvb->real_data = buf;
|
tvb->real_data = buf;
|
||||||
tvb->length = fd->cap_len;
|
tvb->length = fd->cap_len;
|
||||||
tvb->reported_length = fd->pkt_len > G_MAXINT ? G_MAXINT : fd->pkt_len;
|
tvb->reported_length = fd->pkt_len > INT_MAX ? INT_MAX : fd->pkt_len;
|
||||||
tvb->contained_length = tvb->reported_length;
|
tvb->contained_length = tvb->reported_length;
|
||||||
tvb->initialized = TRUE;
|
tvb->initialized = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the top-level real tvbuff for this data source,
|
* This is the top-level real tvbuff for this data source,
|
||||||
@ -226,7 +226,7 @@ frame_tvbuff_new_buffer(const struct packet_provider_data *prov,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static tvbuff_t *
|
static tvbuff_t *
|
||||||
frame_clone(tvbuff_t *tvb, guint abs_offset, guint abs_length)
|
frame_clone(tvbuff_t *tvb, unsigned abs_offset, unsigned abs_length)
|
||||||
{
|
{
|
||||||
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ frame_clone(tvbuff_t *tvb, guint abs_offset, guint abs_length)
|
|||||||
cloned_tvb->length = abs_length;
|
cloned_tvb->length = abs_length;
|
||||||
cloned_tvb->reported_length = abs_length; /* XXX? */
|
cloned_tvb->reported_length = abs_length; /* XXX? */
|
||||||
cloned_tvb->contained_length = cloned_tvb->reported_length;
|
cloned_tvb->contained_length = cloned_tvb->reported_length;
|
||||||
cloned_tvb->initialized = TRUE;
|
cloned_tvb->initialized = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the top-level real tvbuff for this data source,
|
* This is the top-level real tvbuff for this data source,
|
||||||
@ -267,7 +267,7 @@ frame_clone(tvbuff_t *tvb, guint abs_offset, guint abs_length)
|
|||||||
/* based on tvb_new_real_data() */
|
/* based on tvb_new_real_data() */
|
||||||
tvbuff_t *
|
tvbuff_t *
|
||||||
file_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
|
file_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
|
||||||
const guint8 *buf)
|
const uint8_t *buf)
|
||||||
{
|
{
|
||||||
struct tvb_frame *frame_tvb;
|
struct tvb_frame *frame_tvb;
|
||||||
tvbuff_t *tvb;
|
tvbuff_t *tvb;
|
||||||
@ -290,7 +290,7 @@ file_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
|
|||||||
* filtered out, and should not be filtered out,
|
* filtered out, and should not be filtered out,
|
||||||
* as those lengths are not necessarily invalid.
|
* as those lengths are not necessarily invalid.
|
||||||
*
|
*
|
||||||
* For now, we clip the reported length at G_MAXINT
|
* For now, we clip the reported length at INT_MAX
|
||||||
*
|
*
|
||||||
* (XXX, is this still a problem?) There was an exception when we call
|
* (XXX, is this still a problem?) There was an exception when we call
|
||||||
* tvb_new_real_data() now there's no one
|
* tvb_new_real_data() now there's no one
|
||||||
@ -298,9 +298,9 @@ file_tvbuff_new(const struct packet_provider_data *prov, const frame_data *fd,
|
|||||||
|
|
||||||
tvb->real_data = buf;
|
tvb->real_data = buf;
|
||||||
tvb->length = fd->cap_len;
|
tvb->length = fd->cap_len;
|
||||||
tvb->reported_length = fd->pkt_len > G_MAXINT ? G_MAXINT : fd->pkt_len;
|
tvb->reported_length = fd->pkt_len > INT_MAX ? INT_MAX : fd->pkt_len;
|
||||||
tvb->contained_length = tvb->reported_length;
|
tvb->contained_length = tvb->reported_length;
|
||||||
tvb->initialized = TRUE;
|
tvb->initialized = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the top-level real tvbuff for this data source,
|
* This is the top-level real tvbuff for this data source,
|
||||||
|
@ -21,13 +21,13 @@ extern "C" {
|
|||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
extern tvbuff_t *frame_tvbuff_new(const struct packet_provider_data *prov,
|
extern tvbuff_t *frame_tvbuff_new(const struct packet_provider_data *prov,
|
||||||
const frame_data *fd, const guint8 *buf);
|
const frame_data *fd, const uint8_t *buf);
|
||||||
|
|
||||||
extern tvbuff_t *frame_tvbuff_new_buffer(const struct packet_provider_data *prov,
|
extern tvbuff_t *frame_tvbuff_new_buffer(const struct packet_provider_data *prov,
|
||||||
const frame_data *fd, Buffer *buf);
|
const frame_data *fd, Buffer *buf);
|
||||||
|
|
||||||
extern tvbuff_t *file_tvbuff_new(const struct packet_provider_data *prov,
|
extern tvbuff_t *file_tvbuff_new(const struct packet_provider_data *prov,
|
||||||
const frame_data *fd, const guint8 *buf);
|
const frame_data *fd, const uint8_t *buf);
|
||||||
|
|
||||||
extern tvbuff_t *file_tvbuff_new_buffer(const struct packet_provider_data *prov,
|
extern tvbuff_t *file_tvbuff_new_buffer(const struct packet_provider_data *prov,
|
||||||
const frame_data *fd, Buffer *buf);
|
const frame_data *fd, Buffer *buf);
|
||||||
|
84
ringbuffer.c
84
ringbuffer.c
@ -69,7 +69,7 @@ typedef z_stream zlib_stream;
|
|||||||
|
|
||||||
/* Ringbuffer file structure */
|
/* Ringbuffer file structure */
|
||||||
typedef struct _rb_file {
|
typedef struct _rb_file {
|
||||||
gchar *name;
|
char *name;
|
||||||
} rb_file;
|
} rb_file;
|
||||||
|
|
||||||
#define MAX_FILENAME_QUEUE 100
|
#define MAX_FILENAME_QUEUE 100
|
||||||
@ -77,22 +77,22 @@ typedef struct _rb_file {
|
|||||||
/** Ringbuffer data structure */
|
/** Ringbuffer data structure */
|
||||||
typedef struct _ringbuf_data {
|
typedef struct _ringbuf_data {
|
||||||
rb_file *files;
|
rb_file *files;
|
||||||
guint num_files; /**< Number of ringbuffer files (1 to ...) */
|
unsigned num_files; /**< Number of ringbuffer files (1 to ...) */
|
||||||
guint curr_file_num; /**< Number of the current file (ever increasing) */
|
unsigned curr_file_num; /**< Number of the current file (ever increasing) */
|
||||||
gchar *fprefix; /**< Filename prefix */
|
char *fprefix; /**< Filename prefix */
|
||||||
gchar *fsuffix; /**< Filename suffix */
|
char *fsuffix; /**< Filename suffix */
|
||||||
gboolean nametimenum; /**< ...num_time... or ...time_num... */
|
bool nametimenum; /**< ...num_time... or ...time_num... */
|
||||||
gboolean unlimited; /**< TRUE if unlimited number of files */
|
bool unlimited; /**< true if unlimited number of files */
|
||||||
|
|
||||||
int fd; /**< Current ringbuffer file descriptor */
|
int fd; /**< Current ringbuffer file descriptor */
|
||||||
FILE *pdh;
|
FILE *pdh;
|
||||||
char *io_buffer; /**< The IO buffer used to write to the file */
|
char *io_buffer; /**< The IO buffer used to write to the file */
|
||||||
gboolean group_read_access; /**< TRUE if files need to be opened with group read access */
|
bool group_read_access; /**< true if files need to be opened with group read access */
|
||||||
FILE *name_h; /**< write names of completed files to this handle */
|
FILE *name_h; /**< write names of completed files to this handle */
|
||||||
gchar *compress_type; /**< compress type */
|
char *compress_type; /**< compress type */
|
||||||
|
|
||||||
GMutex mutex; /**< mutex for oldnames */
|
GMutex mutex; /**< mutex for oldnames */
|
||||||
gchar *oldnames[MAX_FILENAME_QUEUE]; /**< filename list of pending to be deleted */
|
char *oldnames[MAX_FILENAME_QUEUE]; /**< filename list of pending to be deleted */
|
||||||
} ringbuf_data;
|
} ringbuf_data;
|
||||||
|
|
||||||
static ringbuf_data rb_data;
|
static ringbuf_data rb_data;
|
||||||
@ -101,7 +101,7 @@ static ringbuf_data rb_data;
|
|||||||
* delete pending uncompressed pcap files.
|
* delete pending uncompressed pcap files.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
CleanupOldCap(gchar* name)
|
CleanupOldCap(char* name)
|
||||||
{
|
{
|
||||||
ws_statb64 statb;
|
ws_statb64 statb;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -139,13 +139,13 @@ CleanupOldCap(gchar* name)
|
|||||||
* compress capture file
|
* compress capture file
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ringbuf_exec_compress(gchar* name)
|
ringbuf_exec_compress(char* name)
|
||||||
{
|
{
|
||||||
guint8 *buffer = NULL;
|
uint8_t *buffer = NULL;
|
||||||
gchar* outgz = NULL;
|
char* outgz = NULL;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
gboolean delete_org_file = TRUE;
|
bool delete_org_file = true;
|
||||||
gzFile fi = NULL;
|
gzFile fi = NULL;
|
||||||
|
|
||||||
fd = ws_open(name, O_RDONLY | O_BINARY, 0000);
|
fd = ws_open(name, O_RDONLY | O_BINARY, 0000);
|
||||||
@ -162,7 +162,7 @@ ringbuf_exec_compress(gchar* name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define FS_READ_SIZE 65536
|
#define FS_READ_SIZE 65536
|
||||||
buffer = (guint8*)g_malloc(FS_READ_SIZE);
|
buffer = (uint8_t*)g_malloc(FS_READ_SIZE);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
ws_close(fd);
|
ws_close(fd);
|
||||||
ZLIB_PREFIX(gzclose)(fi);
|
ZLIB_PREFIX(gzclose)(fi);
|
||||||
@ -173,13 +173,13 @@ ringbuf_exec_compress(gchar* name)
|
|||||||
int n = ZLIB_PREFIX(gzwrite)(fi, buffer, (unsigned int)nread);
|
int n = ZLIB_PREFIX(gzwrite)(fi, buffer, (unsigned int)nread);
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
/* mark compression as failed */
|
/* mark compression as failed */
|
||||||
delete_org_file = FALSE;
|
delete_org_file = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
/* mark compression as failed */
|
/* mark compression as failed */
|
||||||
delete_org_file = FALSE;
|
delete_org_file = false;
|
||||||
}
|
}
|
||||||
ws_close(fd);
|
ws_close(fd);
|
||||||
ZLIB_PREFIX(gzclose)(fi);
|
ZLIB_PREFIX(gzclose)(fi);
|
||||||
@ -200,7 +200,7 @@ ringbuf_exec_compress(gchar* name)
|
|||||||
static void*
|
static void*
|
||||||
exec_compress_thread(void* arg)
|
exec_compress_thread(void* arg)
|
||||||
{
|
{
|
||||||
ringbuf_exec_compress((gchar*)arg);
|
ringbuf_exec_compress((char*)arg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ exec_compress_thread(void* arg)
|
|||||||
static int
|
static int
|
||||||
ringbuf_start_compress_file(rb_file* rfile)
|
ringbuf_start_compress_file(rb_file* rfile)
|
||||||
{
|
{
|
||||||
gchar* name = g_strdup(rfile->name);
|
char* name = g_strdup(rfile->name);
|
||||||
g_thread_new("exec_compress", &exec_compress_thread, name);
|
g_thread_new("exec_compress", &exec_compress_thread, name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -228,7 +228,7 @@ ringbuf_open_file(rb_file *rfile, int *err)
|
|||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
|
|
||||||
if (rfile->name != NULL) {
|
if (rfile->name != NULL) {
|
||||||
if (rb_data.unlimited == FALSE) {
|
if (rb_data.unlimited == false) {
|
||||||
/* remove old file (if any, so ignore error) */
|
/* remove old file (if any, so ignore error) */
|
||||||
ws_unlink(rfile->name);
|
ws_unlink(rfile->name);
|
||||||
}
|
}
|
||||||
@ -277,8 +277,8 @@ ringbuf_open_file(rb_file *rfile, int *err)
|
|||||||
* Initialize the ringbuffer data structures
|
* Initialize the ringbuffer data structures
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
ringbuf_init(const char *capfile_name, guint num_files, gboolean group_read_access,
|
ringbuf_init(const char *capfile_name, unsigned num_files, bool group_read_access,
|
||||||
gchar *compress_type, gboolean has_nametimenum)
|
char *compress_type, bool has_nametimenum)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char *pfx;
|
char *pfx;
|
||||||
@ -289,7 +289,7 @@ ringbuf_init(const char *capfile_name, guint num_files, gboolean group_read_acce
|
|||||||
rb_data.fprefix = NULL;
|
rb_data.fprefix = NULL;
|
||||||
rb_data.fsuffix = NULL;
|
rb_data.fsuffix = NULL;
|
||||||
rb_data.nametimenum = has_nametimenum;
|
rb_data.nametimenum = has_nametimenum;
|
||||||
rb_data.unlimited = FALSE;
|
rb_data.unlimited = false;
|
||||||
rb_data.fd = -1;
|
rb_data.fd = -1;
|
||||||
rb_data.pdh = NULL;
|
rb_data.pdh = NULL;
|
||||||
rb_data.io_buffer = NULL;
|
rb_data.io_buffer = NULL;
|
||||||
@ -343,7 +343,7 @@ ringbuf_init(const char *capfile_name, guint num_files, gboolean group_read_acce
|
|||||||
need to save all file names in that case) */
|
need to save all file names in that case) */
|
||||||
|
|
||||||
if (num_files == RINGBUFFER_UNLIMITED_FILES) {
|
if (num_files == RINGBUFFER_UNLIMITED_FILES) {
|
||||||
rb_data.unlimited = TRUE;
|
rb_data.unlimited = true;
|
||||||
rb_data.num_files = 1;
|
rb_data.num_files = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,15 +368,15 @@ ringbuf_init(const char *capfile_name, guint num_files, gboolean group_read_acce
|
|||||||
/*
|
/*
|
||||||
* Set name of file to which to print ringbuffer file names.
|
* Set name of file to which to print ringbuffer file names.
|
||||||
*/
|
*/
|
||||||
gboolean
|
bool
|
||||||
ringbuf_set_print_name(gchar *name, int *err)
|
ringbuf_set_print_name(char *name, int *err)
|
||||||
{
|
{
|
||||||
if (rb_data.name_h != NULL) {
|
if (rb_data.name_h != NULL) {
|
||||||
if (EOF == fclose(rb_data.name_h)) {
|
if (EOF == fclose(rb_data.name_h)) {
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
*err = errno;
|
*err = errno;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!strcmp(name, "-") || !strcmp(name, "stdout")) {
|
if (!strcmp(name, "-") || !strcmp(name, "stdout")) {
|
||||||
@ -388,23 +388,23 @@ ringbuf_set_print_name(gchar *name, int *err)
|
|||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
*err = errno;
|
*err = errno;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Whether the ringbuf filenames are ready.
|
* Whether the ringbuf filenames are ready.
|
||||||
* (Whether ringbuf_init is called and ringbuf_free is not called.)
|
* (Whether ringbuf_init is called and ringbuf_free is not called.)
|
||||||
*/
|
*/
|
||||||
gboolean
|
bool
|
||||||
ringbuf_is_initialized(void)
|
ringbuf_is_initialized(void)
|
||||||
{
|
{
|
||||||
return rb_data.files != NULL;
|
return rb_data.files != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
const char *
|
||||||
ringbuf_current_filename(void)
|
ringbuf_current_filename(void)
|
||||||
{
|
{
|
||||||
return rb_data.files[rb_data.curr_file_num % rb_data.num_files].name;
|
return rb_data.files[rb_data.curr_file_num % rb_data.num_files].name;
|
||||||
@ -443,8 +443,8 @@ ringbuf_init_libpcap_fdopen(int *err)
|
|||||||
/*
|
/*
|
||||||
* Switches to the next ringbuffer file
|
* Switches to the next ringbuffer file
|
||||||
*/
|
*/
|
||||||
gboolean
|
bool
|
||||||
ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
|
ringbuf_switch_file(FILE **pdh, char **save_file, int *save_file_fd, int *err)
|
||||||
{
|
{
|
||||||
int next_file_index;
|
int next_file_index;
|
||||||
rb_file *next_rfile = NULL;
|
rb_file *next_rfile = NULL;
|
||||||
@ -460,7 +460,7 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
|
|||||||
rb_data.fd = -1;
|
rb_data.fd = -1;
|
||||||
g_free(rb_data.io_buffer);
|
g_free(rb_data.io_buffer);
|
||||||
rb_data.io_buffer = NULL;
|
rb_data.io_buffer = NULL;
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_data.pdh = NULL;
|
rb_data.pdh = NULL;
|
||||||
@ -478,11 +478,11 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
|
|||||||
next_rfile = &rb_data.files[next_file_index];
|
next_rfile = &rb_data.files[next_file_index];
|
||||||
|
|
||||||
if (ringbuf_open_file(next_rfile, err) == -1) {
|
if (ringbuf_open_file(next_rfile, err) == -1) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ringbuf_init_libpcap_fdopen(err) == NULL) {
|
if (ringbuf_init_libpcap_fdopen(err) == NULL) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* switch to the new file */
|
/* switch to the new file */
|
||||||
@ -490,16 +490,16 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
|
|||||||
*save_file_fd = rb_data.fd;
|
*save_file_fd = rb_data.fd;
|
||||||
(*pdh) = rb_data.pdh;
|
(*pdh) = rb_data.pdh;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calls fclose() for the current ringbuffer file
|
* Calls fclose() for the current ringbuffer file
|
||||||
*/
|
*/
|
||||||
gboolean
|
bool
|
||||||
ringbuf_libpcap_dump_close(gchar **save_file, int *err)
|
ringbuf_libpcap_dump_close(char **save_file, int *err)
|
||||||
{
|
{
|
||||||
gboolean ret_val = TRUE;
|
bool ret_val = true;
|
||||||
|
|
||||||
/* close current file, if it's open */
|
/* close current file, if it's open */
|
||||||
if (rb_data.pdh != NULL) {
|
if (rb_data.pdh != NULL) {
|
||||||
@ -508,7 +508,7 @@ ringbuf_libpcap_dump_close(gchar **save_file, int *err)
|
|||||||
*err = errno;
|
*err = errno;
|
||||||
}
|
}
|
||||||
ws_close(rb_data.fd);
|
ws_close(rb_data.fd);
|
||||||
ret_val = FALSE;
|
ret_val = false;
|
||||||
}
|
}
|
||||||
rb_data.pdh = NULL;
|
rb_data.pdh = NULL;
|
||||||
rb_data.fd = -1;
|
rb_data.fd = -1;
|
||||||
|
14
ringbuffer.h
14
ringbuffer.h
@ -24,16 +24,16 @@
|
|||||||
/* Maximum number for FAT filesystems */
|
/* Maximum number for FAT filesystems */
|
||||||
#define RINGBUFFER_WARN_NUM_FILES 65535
|
#define RINGBUFFER_WARN_NUM_FILES 65535
|
||||||
|
|
||||||
int ringbuf_init(const char *capture_name, guint num_files, gboolean group_read_access, gchar* compress_type,
|
int ringbuf_init(const char *capture_name, unsigned num_files, bool group_read_access, char* compress_type,
|
||||||
gboolean nametimenum);
|
bool nametimenum);
|
||||||
gboolean ringbuf_is_initialized(void);
|
bool ringbuf_is_initialized(void);
|
||||||
const gchar *ringbuf_current_filename(void);
|
const char *ringbuf_current_filename(void);
|
||||||
FILE *ringbuf_init_libpcap_fdopen(int *err);
|
FILE *ringbuf_init_libpcap_fdopen(int *err);
|
||||||
gboolean ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd,
|
bool ringbuf_switch_file(FILE **pdh, char **save_file, int *save_file_fd,
|
||||||
int *err);
|
int *err);
|
||||||
gboolean ringbuf_libpcap_dump_close(gchar **save_file, int *err);
|
bool ringbuf_libpcap_dump_close(char **save_file, int *err);
|
||||||
void ringbuf_free(void);
|
void ringbuf_free(void);
|
||||||
void ringbuf_error_cleanup(void);
|
void ringbuf_error_cleanup(void);
|
||||||
gboolean ringbuf_set_print_name(gchar *name, int *err);
|
bool ringbuf_set_print_name(char *name, int *err);
|
||||||
|
|
||||||
#endif /* ringbuffer.h */
|
#endif /* ringbuffer.h */
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
static ssize_t
|
static ssize_t
|
||||||
sync_pipe_write_header(int pipe_fd, char indicator, unsigned int length)
|
sync_pipe_write_header(int pipe_fd, char indicator, unsigned int length)
|
||||||
{
|
{
|
||||||
guchar header[1+3]; /* indicator + 3-byte len */
|
unsigned char header[1+3]; /* indicator + 3-byte len */
|
||||||
|
|
||||||
ws_assert(length <= SP_MAX_MSG_LEN);
|
ws_assert(length <= SP_MAX_MSG_LEN);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user