summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Tüxen <tuexen@fh-muenster.de>2012-04-25 20:50:38 +0000
committerMichael Tüxen <tuexen@fh-muenster.de>2012-04-25 20:50:38 +0000
commit8ea1984ddc0620525dd1cafc60074755237eee31 (patch)
treedf75b00749abbfff6b07e052042dd392fc428d9b
parent1cd8ca08a6495a8a1ecb86fcdac36e7cc78d2997 (diff)
downloadwireshark-8ea1984ddc0620525dd1cafc60074755237eee31.tar.gz
Allow writing ISB with given recv/drop counters.
No functional change by this commit. svn path=/trunk/; revision=42242
-rw-r--r--dumpcap.c13
-rw-r--r--pcapio.c35
-rw-r--r--pcapio.h3
3 files changed, 28 insertions, 23 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 89a1754de0..ebbf7f949b 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -2749,13 +2749,24 @@ capture_loop_close_output(capture_options *capture_opts, loop_data *ld, int *err
for (i = 0; i < global_ld.pcaps->len; i++) {
pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, i);
if (!pcap_opts->from_cap_pipe) {
+ guint64 isb_ifrecv, isb_ifdrop;
+ struct pcap_stat stats;
+
+ if (pcap_stats(pcap_opts->pcap_h, &stats) >= 0) {
+ isb_ifrecv = stats.ps_recv;
+ isb_ifdrop = stats.ps_drop;
+ } else {
+ isb_ifrecv = G_MAXUINT64;
+ isb_ifdrop = G_MAXUINT64;
+ }
libpcap_write_interface_statistics_block(ld->pdh,
i,
- pcap_opts->pcap_h,
&ld->bytes_written,
"Counters provided by libpcap",
start_time,
end_time,
+ isb_ifrecv,
+ isb_ifdrop,
err_close);
}
}
diff --git a/pcapio.c b/pcapio.c
index d399606fb1..cb84ac7c52 100644
--- a/pcapio.c
+++ b/pcapio.c
@@ -588,11 +588,12 @@ libpcap_write_enhanced_packet_block(FILE *fp,
gboolean
libpcap_write_interface_statistics_block(FILE *fp,
guint32 interface_id,
- pcap_t *pd,
long *bytes_written,
const char *comment, /* OPT_COMMENT 1 */
guint64 isb_starttime, /* ISB_STARTTIME 2 */
guint64 isb_endtime, /* ISB_ENDTIME 3 */
+ guint64 isb_ifrecv, /* ISB_IFRECV 4 */
+ guint64 isb_ifdrop, /* ISB_IFDROP 5 */
int *err)
{
struct isb isb;
@@ -602,11 +603,8 @@ libpcap_write_interface_statistics_block(FILE *fp,
struct timeval now;
#endif
struct option option;
- struct pcap_stat stats;
guint32 block_total_length;
guint64 timestamp;
- guint64 counter;
- gboolean stats_retrieved;
gboolean have_options = FALSE;
const guint32 padding = 0;
#ifdef _WIN32
@@ -648,17 +646,14 @@ libpcap_write_interface_statistics_block(FILE *fp,
timestamp = (guint64)(now.tv_sec) * 1000000 +
(guint64)(now.tv_usec);
#endif
- if (pcap_stats(pd, &stats) < 0) {
- stats_retrieved = FALSE;
- g_warning("pcap_stats() failed.");
- } else {
- stats_retrieved = TRUE;
- have_options = TRUE;
+ block_total_length = sizeof(struct isb) + sizeof(guint32);
+ if (isb_ifrecv != G_MAXUINT64) {
+ block_total_length += sizeof(struct option) + sizeof(guint64);
+ have_options = TRUE;
}
- block_total_length = sizeof(struct isb) +
- sizeof(guint32);
- if (stats_retrieved) {
- block_total_length += 2 * sizeof(struct option) + 2 * sizeof(guint64); /* ISB_IFRECV + ISB_IFDROP */
+ if (isb_ifdrop != G_MAXUINT64) {
+ block_total_length += sizeof(struct option) + sizeof(guint64);
+ have_options = TRUE;
}
/* OPT_COMMENT */
if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
@@ -719,19 +714,17 @@ libpcap_write_interface_statistics_block(FILE *fp,
WRITE_DATA(fp, &high, sizeof(guint32), *bytes_written, err);
WRITE_DATA(fp, &low, sizeof(guint32), *bytes_written, err);
}
- if (stats_retrieved) {
- /* */
+ if (isb_ifrecv != G_MAXUINT64) {
option.type = ISB_IFRECV;
option.value_length = sizeof(guint64);
- counter = stats.ps_recv;
WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, &counter, sizeof(guint64), *bytes_written, err);
- /* */
+ WRITE_DATA(fp, &isb_ifrecv, sizeof(guint64), *bytes_written, err);
+ }
+ if (isb_ifdrop != G_MAXUINT64) {
option.type = ISB_IFDROP;
option.value_length = sizeof(guint64);
- counter = stats.ps_drop;
WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, &counter, sizeof(guint64), *bytes_written, err);
+ WRITE_DATA(fp, &isb_ifdrop, sizeof(guint64), *bytes_written, err);
}
if (have_options) {
/* write end of options */
diff --git a/pcapio.h b/pcapio.h
index 877552eb49..bd8942855e 100644
--- a/pcapio.h
+++ b/pcapio.h
@@ -79,11 +79,12 @@ libpcap_write_interface_description_block(FILE *fp,
extern gboolean
libpcap_write_interface_statistics_block(FILE *fp,
guint32 interface_id,
- pcap_t *pd,
long *bytes_written,
const char *comment, /* OPT_COMMENT 1 */
guint64 isb_starttime, /* ISB_STARTTIME 2 */
guint64 isb_endtime, /* ISB_ENDTIME 3 */
+ guint64 isb_ifrecv, /* ISB_IFRECV 4 */
+ guint64 isb_ifdrop, /* ISB_IFDROP 5 */
int *err);
extern gboolean