Rename routines that write pcap-ng files to "pcapng_xxx" rather than
"libpcap_xxx". Rename the low-level write routine in pcapio.c to write_to_file(), as it's used for both pcap and pcap-ng files. svn path=/trunk/; revision=52275
This commit is contained in:
parent
c42263f28a
commit
b06876390d
88
dumpcap.c
88
dumpcap.c
|
@ -417,7 +417,7 @@ static void report_cfilter_error(capture_options *capture_opts, guint i, const c
|
||||||
|
|
||||||
#define MSG_MAX_LENGTH 4096
|
#define MSG_MAX_LENGTH 4096
|
||||||
|
|
||||||
/* Copied from pcapio.c libpcap_write_interface_statistics_block()*/
|
/* Copied from pcapio.c pcapng_write_interface_statistics_block()*/
|
||||||
static guint64
|
static guint64
|
||||||
create_timestamp(void) {
|
create_timestamp(void) {
|
||||||
guint64 timestamp;
|
guint64 timestamp;
|
||||||
|
@ -2881,7 +2881,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
|
||||||
get_os_version_info(os_info_str);
|
get_os_version_info(os_info_str);
|
||||||
|
|
||||||
g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
|
g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
|
||||||
successful = libpcap_write_session_header_block(ld->pdh,
|
successful = pcapng_write_session_header_block(ld->pdh,
|
||||||
(const char *)capture_opts->capture_comment, /* Comment*/
|
(const char *)capture_opts->capture_comment, /* Comment*/
|
||||||
NULL, /* HW*/
|
NULL, /* HW*/
|
||||||
os_info_str->str, /* OS*/
|
os_info_str->str, /* OS*/
|
||||||
|
@ -2898,18 +2898,18 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
|
||||||
} else {
|
} else {
|
||||||
pcap_opts->snaplen = pcap_snapshot(pcap_opts->pcap_h);
|
pcap_opts->snaplen = pcap_snapshot(pcap_opts->pcap_h);
|
||||||
}
|
}
|
||||||
successful = libpcap_write_interface_description_block(global_ld.pdh,
|
successful = pcapng_write_interface_description_block(global_ld.pdh,
|
||||||
NULL, /* OPT_COMMENT 1 */
|
NULL, /* OPT_COMMENT 1 */
|
||||||
interface_opts.name, /* IDB_NAME 2 */
|
interface_opts.name, /* IDB_NAME 2 */
|
||||||
interface_opts.descr, /* IDB_DESCRIPTION 3 */
|
interface_opts.descr, /* IDB_DESCRIPTION 3 */
|
||||||
interface_opts.cfilter, /* IDB_FILTER 11 */
|
interface_opts.cfilter, /* IDB_FILTER 11 */
|
||||||
os_info_str->str, /* IDB_OS 12 */
|
os_info_str->str, /* IDB_OS 12 */
|
||||||
pcap_opts->linktype,
|
pcap_opts->linktype,
|
||||||
pcap_opts->snaplen,
|
pcap_opts->snaplen,
|
||||||
&(global_ld.bytes_written),
|
&(global_ld.bytes_written),
|
||||||
0, /* IDB_IF_SPEED 8 */
|
0, /* IDB_IF_SPEED 8 */
|
||||||
pcap_opts->ts_nsec ? 9 : 6, /* IDB_TSRESOL 9 */
|
pcap_opts->ts_nsec ? 9 : 6, /* IDB_TSRESOL 9 */
|
||||||
&global_ld.err);
|
&global_ld.err);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_string_free(os_info_str, TRUE);
|
g_string_free(os_info_str, TRUE);
|
||||||
|
@ -2983,15 +2983,15 @@ capture_loop_close_output(capture_options *capture_opts, loop_data *ld, int *err
|
||||||
isb_ifrecv = G_MAXUINT64;
|
isb_ifrecv = G_MAXUINT64;
|
||||||
isb_ifdrop = G_MAXUINT64;
|
isb_ifdrop = G_MAXUINT64;
|
||||||
}
|
}
|
||||||
libpcap_write_interface_statistics_block(ld->pdh,
|
pcapng_write_interface_statistics_block(ld->pdh,
|
||||||
i,
|
i,
|
||||||
&ld->bytes_written,
|
&ld->bytes_written,
|
||||||
"Counters provided by dumpcap",
|
"Counters provided by dumpcap",
|
||||||
start_time,
|
start_time,
|
||||||
end_time,
|
end_time,
|
||||||
isb_ifrecv,
|
isb_ifrecv,
|
||||||
isb_ifdrop,
|
isb_ifdrop,
|
||||||
err_close);
|
err_close);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3374,7 +3374,7 @@ do_file_switch_or_stop(capture_options *capture_opts,
|
||||||
get_os_version_info(os_info_str);
|
get_os_version_info(os_info_str);
|
||||||
|
|
||||||
g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
|
g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
|
||||||
successful = libpcap_write_session_header_block(global_ld.pdh,
|
successful = pcapng_write_session_header_block(global_ld.pdh,
|
||||||
NULL, /* Comment */
|
NULL, /* Comment */
|
||||||
NULL, /* HW */
|
NULL, /* HW */
|
||||||
os_info_str->str, /* OS */
|
os_info_str->str, /* OS */
|
||||||
|
@ -3386,18 +3386,18 @@ do_file_switch_or_stop(capture_options *capture_opts,
|
||||||
for (i = 0; successful && (i < capture_opts->ifaces->len); i++) {
|
for (i = 0; successful && (i < capture_opts->ifaces->len); i++) {
|
||||||
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
|
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
|
||||||
pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, i);
|
pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, i);
|
||||||
successful = libpcap_write_interface_description_block(global_ld.pdh,
|
successful = pcapng_write_interface_description_block(global_ld.pdh,
|
||||||
NULL, /* OPT_COMMENT 1 */
|
NULL, /* OPT_COMMENT 1 */
|
||||||
interface_opts.name, /* IDB_NAME 2 */
|
interface_opts.name, /* IDB_NAME 2 */
|
||||||
interface_opts.descr, /* IDB_DESCRIPTION 3 */
|
interface_opts.descr, /* IDB_DESCRIPTION 3 */
|
||||||
interface_opts.cfilter, /* IDB_FILTER 11 */
|
interface_opts.cfilter, /* IDB_FILTER 11 */
|
||||||
os_info_str->str, /* IDB_OS 12 */
|
os_info_str->str, /* IDB_OS 12 */
|
||||||
pcap_opts->linktype,
|
pcap_opts->linktype,
|
||||||
pcap_opts->snaplen,
|
pcap_opts->snaplen,
|
||||||
&(global_ld.bytes_written),
|
&(global_ld.bytes_written),
|
||||||
0, /* IDB_IF_SPEED 8 */
|
0, /* IDB_IF_SPEED 8 */
|
||||||
pcap_opts->ts_nsec ? 9 : 6, /* IDB_TSRESOL 9 */
|
pcap_opts->ts_nsec ? 9 : 6, /* IDB_TSRESOL 9 */
|
||||||
&global_ld.err);
|
&global_ld.err);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_string_free(os_info_str, TRUE);
|
g_string_free(os_info_str, TRUE);
|
||||||
|
@ -4028,14 +4028,14 @@ capture_loop_write_packet_cb(u_char *pcap_opts_p, const struct pcap_pkthdr *phdr
|
||||||
If this fails, set "ld->go" to FALSE, to stop the capture, and set
|
If this fails, set "ld->go" to FALSE, to stop the capture, and set
|
||||||
"ld->err" to the error. */
|
"ld->err" to the error. */
|
||||||
if (global_capture_opts.use_pcapng) {
|
if (global_capture_opts.use_pcapng) {
|
||||||
successful = libpcap_write_enhanced_packet_block(global_ld.pdh,
|
successful = pcapng_write_enhanced_packet_block(global_ld.pdh,
|
||||||
NULL,
|
NULL,
|
||||||
phdr->ts.tv_sec, (gint32)phdr->ts.tv_usec,
|
phdr->ts.tv_sec, (gint32)phdr->ts.tv_usec,
|
||||||
phdr->caplen, phdr->len,
|
phdr->caplen, phdr->len,
|
||||||
pcap_opts->interface_id,
|
pcap_opts->interface_id,
|
||||||
ts_mul,
|
ts_mul,
|
||||||
pd, 0,
|
pd, 0,
|
||||||
&global_ld.bytes_written, &err);
|
&global_ld.bytes_written, &err);
|
||||||
} else {
|
} else {
|
||||||
successful = libpcap_write_packet(global_ld.pdh,
|
successful = libpcap_write_packet(global_ld.pdh,
|
||||||
phdr->ts.tv_sec, (gint32)phdr->ts.tv_usec,
|
phdr->ts.tv_sec, (gint32)phdr->ts.tv_usec,
|
||||||
|
|
300
pcapio.c
300
pcapio.c
|
@ -180,11 +180,8 @@ struct option {
|
||||||
|
|
||||||
/* Write to capture file */
|
/* Write to capture file */
|
||||||
static gboolean
|
static gboolean
|
||||||
libpcap_write_to_file(FILE* pfile,
|
write_to_file(FILE* pfile, const guint8* data, size_t data_length,
|
||||||
const guint8* data,
|
guint64 *bytes_written, int *err)
|
||||||
size_t data_length,
|
|
||||||
guint64 *bytes_written,
|
|
||||||
int *err)
|
|
||||||
{
|
{
|
||||||
size_t nwritten;
|
size_t nwritten;
|
||||||
|
|
||||||
|
@ -202,6 +199,8 @@ libpcap_write_to_file(FILE* pfile,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Writing pcap files */
|
||||||
|
|
||||||
/* Write the file header to a dump file.
|
/* Write the file header to a dump file.
|
||||||
Returns TRUE on success, FALSE on failure.
|
Returns TRUE on success, FALSE on failure.
|
||||||
Sets "*err" to an error code, or 0 for a short write, on failure*/
|
Sets "*err" to an error code, or 0 for a short write, on failure*/
|
||||||
|
@ -219,7 +218,7 @@ libpcap_write_file_header(FILE* pfile, int linktype, int snaplen, gboolean ts_ns
|
||||||
file_hdr.snaplen = snaplen;
|
file_hdr.snaplen = snaplen;
|
||||||
file_hdr.network = linktype;
|
file_hdr.network = linktype;
|
||||||
|
|
||||||
return libpcap_write_to_file(pfile, (const guint8*)&file_hdr, sizeof(file_hdr), bytes_written, err);
|
return write_to_file(pfile, (const guint8*)&file_hdr, sizeof(file_hdr), bytes_written, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a record for a packet to a dump file.
|
/* Write a record for a packet to a dump file.
|
||||||
|
@ -237,16 +236,18 @@ libpcap_write_packet(FILE* pfile,
|
||||||
rec_hdr.ts_usec = usec;
|
rec_hdr.ts_usec = usec;
|
||||||
rec_hdr.incl_len = caplen;
|
rec_hdr.incl_len = caplen;
|
||||||
rec_hdr.orig_len = len;
|
rec_hdr.orig_len = len;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&rec_hdr, sizeof(rec_hdr), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&rec_hdr, sizeof(rec_hdr), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return libpcap_write_to_file(pfile, pd, caplen, bytes_written, err);
|
return write_to_file(pfile, pd, caplen, bytes_written, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Writing pcap-ng files */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
write_string_option(FILE* pfile,
|
pcapng_write_string_option(FILE* pfile,
|
||||||
guint16 option_type, const char *option_value,
|
guint16 option_type, const char *option_value,
|
||||||
guint64 *bytes_written, int *err)
|
guint64 *bytes_written, int *err)
|
||||||
{
|
{
|
||||||
size_t option_value_length;
|
size_t option_value_length;
|
||||||
struct option option;
|
struct option option;
|
||||||
|
@ -260,14 +261,14 @@ write_string_option(FILE* pfile,
|
||||||
option.type = option_type;
|
option.type = option_type;
|
||||||
option.value_length = (guint16)option_value_length;
|
option.value_length = (guint16)option_value_length;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)option_value, (int) option_value_length, bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)option_value, (int) option_value_length, bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (option_value_length % 4) {
|
if (option_value_length % 4) {
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - option_value_length % 4, bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&padding, 4 - option_value_length % 4, bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,14 +276,14 @@ write_string_option(FILE* pfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
libpcap_write_session_header_block(FILE* pfile,
|
pcapng_write_session_header_block(FILE* pfile,
|
||||||
const char *comment,
|
const char *comment,
|
||||||
const char *hw,
|
const char *hw,
|
||||||
const char *os,
|
const char *os,
|
||||||
const char *appname,
|
const char *appname,
|
||||||
guint64 section_length,
|
guint64 section_length,
|
||||||
guint64 *bytes_written,
|
guint64 *bytes_written,
|
||||||
int *err)
|
int *err)
|
||||||
{
|
{
|
||||||
struct shb shb;
|
struct shb shb;
|
||||||
struct option option;
|
struct option option;
|
||||||
|
@ -324,46 +325,46 @@ libpcap_write_session_header_block(FILE* pfile,
|
||||||
shb.minor_version = PCAPNG_MINOR_VERSION;
|
shb.minor_version = PCAPNG_MINOR_VERSION;
|
||||||
shb.section_length = section_length;
|
shb.section_length = section_length;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&shb, sizeof(struct shb), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&shb, sizeof(struct shb), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!write_string_option(pfile, OPT_COMMENT, comment,
|
if (!pcapng_write_string_option(pfile, OPT_COMMENT, comment,
|
||||||
bytes_written, err))
|
bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!write_string_option(pfile, SHB_HARDWARE, hw,
|
if (!pcapng_write_string_option(pfile, SHB_HARDWARE, hw,
|
||||||
bytes_written, err))
|
bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!write_string_option(pfile, SHB_OS, os,
|
if (!pcapng_write_string_option(pfile, SHB_OS, os,
|
||||||
bytes_written, err))
|
bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!write_string_option(pfile, SHB_USERAPPL, appname,
|
if (!pcapng_write_string_option(pfile, SHB_USERAPPL, appname,
|
||||||
bytes_written, err))
|
bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (have_options) {
|
if (have_options) {
|
||||||
/* write end of options */
|
/* write end of options */
|
||||||
option.type = OPT_ENDOFOPT;
|
option.type = OPT_ENDOFOPT;
|
||||||
option.value_length = 0;
|
option.value_length = 0;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write the trailing block total length */
|
/* write the trailing block total length */
|
||||||
return libpcap_write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
|
return write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
libpcap_write_interface_description_block(FILE* pfile,
|
pcapng_write_interface_description_block(FILE* pfile,
|
||||||
const char *comment, /* OPT_COMMENT 1 */
|
const char *comment, /* OPT_COMMENT 1 */
|
||||||
const char *name, /* IDB_NAME 2 */
|
const char *name, /* IDB_NAME 2 */
|
||||||
const char *descr, /* IDB_DESCRIPTION 3 */
|
const char *descr, /* IDB_DESCRIPTION 3 */
|
||||||
const char *filter, /* IDB_FILTER 11 */
|
const char *filter, /* IDB_FILTER 11 */
|
||||||
const char *os, /* IDB_OS 12 */
|
const char *os, /* IDB_OS 12 */
|
||||||
int link_type,
|
int link_type,
|
||||||
int snap_len,
|
int snap_len,
|
||||||
guint64 *bytes_written,
|
guint64 *bytes_written,
|
||||||
guint64 if_speed, /* IDB_IF_SPEED 8 */
|
guint64 if_speed, /* IDB_IF_SPEED 8 */
|
||||||
guint8 tsresol, /* IDB_TSRESOL 9 */
|
guint8 tsresol, /* IDB_TSRESOL 9 */
|
||||||
int *err)
|
int *err)
|
||||||
{
|
{
|
||||||
struct idb idb;
|
struct idb idb;
|
||||||
struct option option;
|
struct option option;
|
||||||
|
@ -432,70 +433,34 @@ libpcap_write_interface_description_block(FILE* pfile,
|
||||||
idb.link_type = link_type;
|
idb.link_type = link_type;
|
||||||
idb.reserved = 0;
|
idb.reserved = 0;
|
||||||
idb.snap_len = snap_len;
|
idb.snap_len = snap_len;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&idb, sizeof(struct idb), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&idb, sizeof(struct idb), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* 01 - OPT_COMMENT - write comment string if applicable */
|
/* 01 - OPT_COMMENT - write comment string if applicable */
|
||||||
if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
|
if (!pcapng_write_string_option(pfile, OPT_COMMENT, comment,
|
||||||
option.type = OPT_COMMENT;
|
bytes_written, err))
|
||||||
option.value_length = (guint16)strlen(comment);
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (strlen(comment) % 4) {
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 02 - IDB_NAME - write interface name string if applicable */
|
/* 02 - IDB_NAME - write interface name string if applicable */
|
||||||
if ((name != NULL) && (strlen(name) > 0) && (strlen(name) < G_MAXUINT16)) {
|
if (!pcapng_write_string_option(pfile, IDB_NAME, name,
|
||||||
option.type = IDB_NAME;
|
bytes_written, err))
|
||||||
option.value_length = (guint16)strlen(name);
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)name, (int) strlen(name), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (strlen(name) % 4) {
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(name) % 4, bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 03 - IDB_DESCRIPTION */
|
/* 03 - IDB_DESCRIPTION */
|
||||||
/* write interface description string if applicable */
|
/* write interface description string if applicable */
|
||||||
if ((descr != NULL) && (strlen(descr) > 0) && (strlen(descr) < G_MAXUINT16)) {
|
if (!pcapng_write_string_option(pfile, IDB_DESCRIPTION, descr,
|
||||||
option.type = IDB_DESCRIPTION;
|
bytes_written, err))
|
||||||
option.value_length = (guint16)strlen(descr);
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)descr, (int) strlen(descr), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (strlen(descr) % 4) {
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(descr) % 4, bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 08 - IDB_IF_SPEED */
|
/* 08 - IDB_IF_SPEED */
|
||||||
if (if_speed != 0) {
|
if (if_speed != 0) {
|
||||||
option.type = IDB_IF_SPEED;
|
option.type = IDB_IF_SPEED;
|
||||||
option.value_length = sizeof(guint64);
|
option.value_length = sizeof(guint64);
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&if_speed, sizeof(guint64), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&if_speed, sizeof(guint64), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,75 +469,66 @@ libpcap_write_interface_description_block(FILE* pfile,
|
||||||
option.type = IDB_TSRESOL;
|
option.type = IDB_TSRESOL;
|
||||||
option.value_length = sizeof(guint8);
|
option.value_length = sizeof(guint8);
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&tsresol, sizeof(guint8), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&tsresol, sizeof(guint8), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 3, bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&padding, 3, bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 11 - IDB_FILTER - write filter string if applicable
|
/* 11 - IDB_FILTER - write filter string if applicable
|
||||||
* We only write version 1 of the filter, libpcap string
|
* We only write version 1 of the filter, pcapng string
|
||||||
*/
|
*/
|
||||||
if ((filter != NULL) && (strlen(filter) > 0) && (strlen(filter) < G_MAXUINT16)) {
|
if ((filter != NULL) && (strlen(filter) > 0) && (strlen(filter) < G_MAXUINT16)) {
|
||||||
option.type = IDB_FILTER;
|
option.type = IDB_FILTER;
|
||||||
option.value_length = (guint16)(strlen(filter) + 1 );
|
option.value_length = (guint16)(strlen(filter) + 1 );
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* The first byte of the Option Data keeps a code of the filter used, 0 = lipbpcap filter string */
|
/* The first byte of the Option Data keeps a code of the filter used, 0 = lipbpcap filter string */
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 1, bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&padding, 1, bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)filter, (int) strlen(filter), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)filter, (int) strlen(filter), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if ((strlen(filter) + 1) % 4) {
|
if ((strlen(filter) + 1) % 4) {
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - (strlen(filter) + 1) % 4, bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&padding, 4 - (strlen(filter) + 1) % 4, bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 12 - IDB_OS - write os string if applicable */
|
/* 12 - IDB_OS - write os string if applicable */
|
||||||
if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
|
if (!pcapng_write_string_option(pfile, IDB_OS, os,
|
||||||
option.type = IDB_OS;
|
bytes_written, err))
|
||||||
option.value_length = (guint16)strlen(os);
|
return FALSE;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)os, (int) strlen(os), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
if (strlen(os) % 4) {
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(os) % 4, bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (have_options) {
|
if (have_options) {
|
||||||
/* write end of options */
|
/* write end of options */
|
||||||
option.type = OPT_ENDOFOPT;
|
option.type = OPT_ENDOFOPT;
|
||||||
option.value_length = 0;
|
option.value_length = 0;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write the trailing Block Total Length */
|
/* write the trailing Block Total Length */
|
||||||
return libpcap_write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
|
return write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a record for a packet to a dump file.
|
/* Write a record for a packet to a dump file.
|
||||||
Returns TRUE on success, FALSE on failure. */
|
Returns TRUE on success, FALSE on failure. */
|
||||||
gboolean
|
gboolean
|
||||||
libpcap_write_enhanced_packet_block(FILE* pfile,
|
pcapng_write_enhanced_packet_block(FILE* pfile,
|
||||||
const char *comment,
|
const char *comment,
|
||||||
time_t sec, guint32 usec,
|
time_t sec, guint32 usec,
|
||||||
guint32 caplen, guint32 len,
|
guint32 caplen, guint32 len,
|
||||||
guint32 interface_id,
|
guint32 interface_id,
|
||||||
guint ts_mul,
|
guint ts_mul,
|
||||||
const guint8 *pd,
|
const guint8 *pd,
|
||||||
guint32 flags,
|
guint32 flags,
|
||||||
guint64 *bytes_written,
|
guint64 *bytes_written,
|
||||||
int *err)
|
int *err)
|
||||||
{
|
{
|
||||||
struct epb epb;
|
struct epb epb;
|
||||||
struct option option;
|
struct option option;
|
||||||
|
@ -606,55 +562,43 @@ libpcap_write_enhanced_packet_block(FILE* pfile,
|
||||||
epb.timestamp_low = (guint32)(timestamp & 0xffffffff);
|
epb.timestamp_low = (guint32)(timestamp & 0xffffffff);
|
||||||
epb.captured_len = caplen;
|
epb.captured_len = caplen;
|
||||||
epb.packet_len = len;
|
epb.packet_len = len;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&epb, sizeof(struct epb), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&epb, sizeof(struct epb), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!libpcap_write_to_file(pfile, pd, caplen, bytes_written, err))
|
if (!write_to_file(pfile, pd, caplen, bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (caplen % 4) {
|
if (caplen % 4) {
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - caplen % 4, bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&padding, 4 - caplen % 4, bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
|
if (!pcapng_write_string_option(pfile, OPT_COMMENT, comment,
|
||||||
option.type = OPT_COMMENT;
|
bytes_written, err))
|
||||||
option.value_length = (guint16)strlen(comment);
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (strlen(comment) % 4) {
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (flags != 0) {
|
if (flags != 0) {
|
||||||
option.type = EPB_FLAGS;
|
option.type = EPB_FLAGS;
|
||||||
option.value_length = sizeof(guint32);
|
option.value_length = sizeof(guint32);
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&flags, sizeof(guint32), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&flags, sizeof(guint32), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
option.type = OPT_ENDOFOPT;
|
option.type = OPT_ENDOFOPT;
|
||||||
option.value_length = 0;
|
option.value_length = 0;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return libpcap_write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
|
return write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
libpcap_write_interface_statistics_block(FILE* pfile,
|
pcapng_write_interface_statistics_block(FILE* pfile,
|
||||||
guint32 interface_id,
|
guint32 interface_id,
|
||||||
guint64 *bytes_written,
|
guint64 *bytes_written,
|
||||||
const char *comment, /* OPT_COMMENT 1 */
|
const char *comment, /* OPT_COMMENT 1 */
|
||||||
guint64 isb_starttime, /* ISB_STARTTIME 2 */
|
guint64 isb_starttime, /* ISB_STARTTIME 2 */
|
||||||
guint64 isb_endtime, /* ISB_ENDTIME 3 */
|
guint64 isb_endtime, /* ISB_ENDTIME 3 */
|
||||||
guint64 isb_ifrecv, /* ISB_IFRECV 4 */
|
guint64 isb_ifrecv, /* ISB_IFRECV 4 */
|
||||||
guint64 isb_ifdrop, /* ISB_IFDROP 5 */
|
guint64 isb_ifdrop, /* ISB_IFDROP 5 */
|
||||||
int *err)
|
int *err)
|
||||||
{
|
{
|
||||||
struct isb isb;
|
struct isb isb;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -666,7 +610,6 @@ libpcap_write_interface_statistics_block(FILE* pfile,
|
||||||
guint32 block_total_length;
|
guint32 block_total_length;
|
||||||
guint64 timestamp;
|
guint64 timestamp;
|
||||||
gboolean have_options = FALSE;
|
gboolean have_options = FALSE;
|
||||||
const guint32 padding = 0;
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/*
|
/*
|
||||||
* Current time, represented as 100-nanosecond intervals since
|
* Current time, represented as 100-nanosecond intervals since
|
||||||
|
@ -743,24 +686,13 @@ libpcap_write_interface_statistics_block(FILE* pfile,
|
||||||
isb.interface_id = interface_id;
|
isb.interface_id = interface_id;
|
||||||
isb.timestamp_high = (guint32)((timestamp>>32) & 0xffffffff);
|
isb.timestamp_high = (guint32)((timestamp>>32) & 0xffffffff);
|
||||||
isb.timestamp_low = (guint32)(timestamp & 0xffffffff);
|
isb.timestamp_low = (guint32)(timestamp & 0xffffffff);
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&isb, sizeof(struct isb), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&isb, sizeof(struct isb), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* write comment string if applicable */
|
/* write comment string if applicable */
|
||||||
if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
|
if (!pcapng_write_string_option(pfile, OPT_COMMENT, comment,
|
||||||
option.type = OPT_COMMENT;
|
bytes_written, err))
|
||||||
option.value_length = (guint16)strlen(comment);
|
return FALSE;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (strlen(comment) % 4) {
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isb_starttime !=0) {
|
if (isb_starttime !=0) {
|
||||||
guint32 high, low;
|
guint32 high, low;
|
||||||
|
@ -769,13 +701,13 @@ libpcap_write_interface_statistics_block(FILE* pfile,
|
||||||
option.value_length = sizeof(guint64);
|
option.value_length = sizeof(guint64);
|
||||||
high = (guint32)((isb_starttime>>32) & 0xffffffff);
|
high = (guint32)((isb_starttime>>32) & 0xffffffff);
|
||||||
low = (guint32)(isb_starttime & 0xffffffff);
|
low = (guint32)(isb_starttime & 0xffffffff);
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&high, sizeof(guint32), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&high, sizeof(guint32), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&low, sizeof(guint32), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&low, sizeof(guint32), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (isb_endtime !=0) {
|
if (isb_endtime !=0) {
|
||||||
|
@ -785,42 +717,42 @@ libpcap_write_interface_statistics_block(FILE* pfile,
|
||||||
option.value_length = sizeof(guint64);
|
option.value_length = sizeof(guint64);
|
||||||
high = (guint32)((isb_endtime>>32) & 0xffffffff);
|
high = (guint32)((isb_endtime>>32) & 0xffffffff);
|
||||||
low = (guint32)(isb_endtime & 0xffffffff);
|
low = (guint32)(isb_endtime & 0xffffffff);
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&high, sizeof(guint32), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&high, sizeof(guint32), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&low, sizeof(guint32), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&low, sizeof(guint32), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (isb_ifrecv != G_MAXUINT64) {
|
if (isb_ifrecv != G_MAXUINT64) {
|
||||||
option.type = ISB_IFRECV;
|
option.type = ISB_IFRECV;
|
||||||
option.value_length = sizeof(guint64);
|
option.value_length = sizeof(guint64);
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&isb_ifrecv, sizeof(guint64), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&isb_ifrecv, sizeof(guint64), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (isb_ifdrop != G_MAXUINT64) {
|
if (isb_ifdrop != G_MAXUINT64) {
|
||||||
option.type = ISB_IFDROP;
|
option.type = ISB_IFDROP;
|
||||||
option.value_length = sizeof(guint64);
|
option.value_length = sizeof(guint64);
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&isb_ifdrop, sizeof(guint64), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&isb_ifdrop, sizeof(guint64), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (have_options) {
|
if (have_options) {
|
||||||
/* write end of options */
|
/* write end of options */
|
||||||
option.type = OPT_ENDOFOPT;
|
option.type = OPT_ENDOFOPT;
|
||||||
option.value_length = 0;
|
option.value_length = 0;
|
||||||
if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
if (!write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return libpcap_write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
|
return write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
98
pcapio.h
98
pcapio.h
|
@ -25,6 +25,8 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Writing pcap files */
|
||||||
|
|
||||||
/** Write the file header to a dump file.
|
/** Write the file header to a dump file.
|
||||||
Returns TRUE on success, FALSE on failure.
|
Returns TRUE on success, FALSE on failure.
|
||||||
Sets "*err" to an error code, or 0 for a short write, on failure*/
|
Sets "*err" to an error code, or 0 for a short write, on failure*/
|
||||||
|
@ -41,60 +43,62 @@ libpcap_write_packet(FILE* pfile,
|
||||||
const guint8 *pd,
|
const guint8 *pd,
|
||||||
guint64 *bytes_written, int *err);
|
guint64 *bytes_written, int *err);
|
||||||
|
|
||||||
|
/* Writing pcap-ng files */
|
||||||
|
|
||||||
/** Write a section header block (SHB)
|
/** Write a section header block (SHB)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
extern gboolean
|
extern gboolean
|
||||||
libpcap_write_session_header_block(FILE* pfile, /**< Write information */
|
pcapng_write_session_header_block(FILE* pfile, /**< Write information */
|
||||||
const char *comment, /**< Comment on the section, Optinon 1 opt_comment
|
const char *comment, /**< Comment on the section, Optinon 1 opt_comment
|
||||||
* A UTF-8 string containing a comment that is associated to the current block.
|
* A UTF-8 string containing a comment that is associated to the current block.
|
||||||
*/
|
*/
|
||||||
const char *hw, /**< HW, Optinon 2 shb_hardware
|
const char *hw, /**< HW, Optinon 2 shb_hardware
|
||||||
* An UTF-8 string containing the description of the hardware used to create this section.
|
* An UTF-8 string containing the description of the hardware used to create this section.
|
||||||
*/
|
*/
|
||||||
const char *os, /**< Operating system name, Optinon 3 shb_os
|
const char *os, /**< Operating system name, Optinon 3 shb_os
|
||||||
* An UTF-8 string containing the name of the operating system used to create this section.
|
* An UTF-8 string containing the name of the operating system used to create this section.
|
||||||
*/
|
*/
|
||||||
const char *appname, /**< Application name, Optinon 4 shb_userappl
|
const char *appname, /**< Application name, Optinon 4 shb_userappl
|
||||||
* An UTF-8 string containing the name of the application used to create this section.
|
* An UTF-8 string containing the name of the application used to create this section.
|
||||||
*/
|
*/
|
||||||
guint64 section_length,
|
guint64 section_length,
|
||||||
guint64 *bytes_written,
|
guint64 *bytes_written,
|
||||||
int *err);
|
int *err);
|
||||||
|
|
||||||
extern gboolean
|
extern gboolean
|
||||||
libpcap_write_interface_description_block(FILE* pfile,
|
pcapng_write_interface_description_block(FILE* pfile,
|
||||||
const char *comment, /* OPT_COMMENT 1 */
|
const char *comment, /* OPT_COMMENT 1 */
|
||||||
const char *name, /* IDB_NAME 2 */
|
const char *name, /* IDB_NAME 2 */
|
||||||
const char *descr, /* IDB_DESCRIPTION 3 */
|
const char *descr, /* IDB_DESCRIPTION 3 */
|
||||||
const char *filter, /* IDB_FILTER 11 */
|
const char *filter, /* IDB_FILTER 11 */
|
||||||
const char *os, /* IDB_OS 12 */
|
const char *os, /* IDB_OS 12 */
|
||||||
int link_type,
|
int link_type,
|
||||||
int snap_len,
|
int snap_len,
|
||||||
guint64 *bytes_written,
|
|
||||||
guint64 if_speed, /* IDB_IF_SPEED 8 */
|
|
||||||
guint8 tsresol, /* IDB_TSRESOL 9 */
|
|
||||||
int *err);
|
|
||||||
|
|
||||||
extern gboolean
|
|
||||||
libpcap_write_interface_statistics_block(FILE* pfile,
|
|
||||||
guint32 interface_id,
|
|
||||||
guint64 *bytes_written,
|
guint64 *bytes_written,
|
||||||
const char *comment, /* OPT_COMMENT 1 */
|
guint64 if_speed, /* IDB_IF_SPEED 8 */
|
||||||
guint64 isb_starttime, /* ISB_STARTTIME 2 */
|
guint8 tsresol, /* IDB_TSRESOL 9 */
|
||||||
guint64 isb_endtime, /* ISB_ENDTIME 3 */
|
|
||||||
guint64 isb_ifrecv, /* ISB_IFRECV 4 */
|
|
||||||
guint64 isb_ifdrop, /* ISB_IFDROP 5 */
|
|
||||||
int *err);
|
int *err);
|
||||||
|
|
||||||
extern gboolean
|
extern gboolean
|
||||||
libpcap_write_enhanced_packet_block(FILE* pfile,
|
pcapng_write_interface_statistics_block(FILE* pfile,
|
||||||
const char *comment,
|
guint32 interface_id,
|
||||||
time_t sec, guint32 usec,
|
guint64 *bytes_written,
|
||||||
guint32 caplen, guint32 len,
|
const char *comment, /* OPT_COMMENT 1 */
|
||||||
guint32 interface_id,
|
guint64 isb_starttime, /* ISB_STARTTIME 2 */
|
||||||
guint ts_mul,
|
guint64 isb_endtime, /* ISB_ENDTIME 3 */
|
||||||
const guint8 *pd,
|
guint64 isb_ifrecv, /* ISB_IFRECV 4 */
|
||||||
guint32 flags,
|
guint64 isb_ifdrop, /* ISB_IFDROP 5 */
|
||||||
guint64 *bytes_written,
|
int *err);
|
||||||
int *err);
|
|
||||||
|
extern gboolean
|
||||||
|
pcapng_write_enhanced_packet_block(FILE* pfile,
|
||||||
|
const char *comment,
|
||||||
|
time_t sec, guint32 usec,
|
||||||
|
guint32 caplen, guint32 len,
|
||||||
|
guint32 interface_id,
|
||||||
|
guint ts_mul,
|
||||||
|
const guint8 *pd,
|
||||||
|
guint32 flags,
|
||||||
|
guint64 *bytes_written,
|
||||||
|
int *err);
|
||||||
|
|
74
text2pcap.c
74
text2pcap.c
|
@ -842,14 +842,14 @@ write_current_packet(gboolean cont)
|
||||||
length = 60;
|
length = 60;
|
||||||
}
|
}
|
||||||
if (use_pcapng) {
|
if (use_pcapng) {
|
||||||
success = libpcap_write_enhanced_packet_block(output_file,
|
success = pcapng_write_enhanced_packet_block(output_file,
|
||||||
NULL,
|
NULL,
|
||||||
ts_sec, ts_usec,
|
ts_sec, ts_usec,
|
||||||
length, length,
|
length, length,
|
||||||
0,
|
0,
|
||||||
1000000,
|
1000000,
|
||||||
packet_buf, direction,
|
packet_buf, direction,
|
||||||
&bytes_written, &err);
|
&bytes_written, &err);
|
||||||
} else {
|
} else {
|
||||||
success = libpcap_write_packet(output_file,
|
success = libpcap_write_packet(output_file,
|
||||||
ts_sec, ts_usec,
|
ts_sec, ts_usec,
|
||||||
|
@ -895,27 +895,27 @@ write_file_header (void)
|
||||||
char comment[100];
|
char comment[100];
|
||||||
|
|
||||||
g_snprintf(comment, sizeof(comment), "Generated from input file %s.", input_filename);
|
g_snprintf(comment, sizeof(comment), "Generated from input file %s.", input_filename);
|
||||||
success = libpcap_write_session_header_block(output_file,
|
success = pcapng_write_session_header_block(output_file,
|
||||||
comment,
|
comment,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
appname,
|
appname,
|
||||||
-1,
|
-1,
|
||||||
&bytes_written,
|
&bytes_written,
|
||||||
&err);
|
&err);
|
||||||
if (success) {
|
if (success) {
|
||||||
success = libpcap_write_interface_description_block(output_file,
|
success = pcapng_write_interface_description_block(output_file,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
"",
|
"",
|
||||||
NULL,
|
NULL,
|
||||||
pcap_link_type,
|
pcap_link_type,
|
||||||
PCAP_SNAPLEN,
|
PCAP_SNAPLEN,
|
||||||
&bytes_written,
|
&bytes_written,
|
||||||
0,
|
0,
|
||||||
6,
|
6,
|
||||||
&err);
|
&err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
success = libpcap_write_file_header(output_file, pcap_link_type, PCAP_SNAPLEN,
|
success = libpcap_write_file_header(output_file, pcap_link_type, PCAP_SNAPLEN,
|
||||||
|
@ -935,15 +935,15 @@ write_file_trailer (void)
|
||||||
gboolean success;
|
gboolean success;
|
||||||
|
|
||||||
if (use_pcapng) {
|
if (use_pcapng) {
|
||||||
success = libpcap_write_interface_statistics_block(output_file,
|
success = pcapng_write_interface_statistics_block(output_file,
|
||||||
0,
|
0,
|
||||||
&bytes_written,
|
&bytes_written,
|
||||||
"Counters provided by text2pcap",
|
"Counters provided by text2pcap",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
num_packets_written,
|
num_packets_written,
|
||||||
num_packets_written - num_packets_written,
|
num_packets_written - num_packets_written,
|
||||||
&err);
|
&err);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
|
|
Loading…
Reference in New Issue