Fix the -S option :

- read only the real number of packets that have been written
  by the child process. That's avoid incomplete packet read.
- special timeout handling no more necessary and the whole
  real time capture and display behavior is much more
  satisfying with this patch.
- wiretap modified to allow the reading of 'count' packets
  with wtap_loop.

svn path=/trunk/; revision=398
This commit is contained in:
Laurent Deniel 1999-07-28 20:17:24 +00:00
parent e0b268397a
commit c42634dd82
4 changed files with 47 additions and 13 deletions

View File

@ -1,7 +1,7 @@
/* capture.c /* capture.c
* Routines for packet capture windows * Routines for packet capture windows
* *
* $Id: capture.c,v 1.36 1999/07/28 02:40:16 gerald Exp $ * $Id: capture.c,v 1.37 1999/07/28 20:17:14 deniel Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -413,6 +413,7 @@ capture(void) {
ld.max = cf.count; ld.max = cf.count;
ld.linktype = DLT_NULL; ld.linktype = DLT_NULL;
ld.sync_time = 0; ld.sync_time = 0;
ld.sync_packets = 0;
ld.counts.tcp = 0; ld.counts.tcp = 0;
ld.counts.udp = 0; ld.counts.udp = 0;
ld.counts.ospf = 0; ld.counts.ospf = 0;
@ -614,14 +615,21 @@ capture_pcap_cb(u_char *user, const struct pcap_pkthdr *phdr,
if (ld->pdh) pcap_dump((u_char *) ld->pdh, phdr, pd); if (ld->pdh) pcap_dump((u_char *) ld->pdh, phdr, pd);
cur_time = time(NULL); cur_time = time(NULL);
ld->sync_packets ++;
if (cur_time > *sync_time) { if (cur_time > *sync_time) {
/* sync every second */ /* sync every second */
*sync_time = cur_time; *sync_time = cur_time;
fflush((FILE *)ld->pdh); fflush((FILE *)ld->pdh);
if (sync_mode) if (sync_mode && ld->sync_packets) {
write(1, "D", 1); char tmp[20];
sprintf(tmp, "%d*", ld->sync_packets);
write(1, tmp, strlen(tmp));
ld->sync_packets = 0;
}
} }
switch (ld->linktype) { switch (ld->linktype) {
case DLT_EN10MB : case DLT_EN10MB :
capture_eth(pd, phdr->caplen, &ld->counts); capture_eth(pd, phdr->caplen, &ld->counts);

View File

@ -1,7 +1,7 @@
/* capture.h /* capture.h
* Definitions for packet capture windows * Definitions for packet capture windows
* *
* $Id: capture.h,v 1.9 1999/07/20 06:16:09 guy Exp $ * $Id: capture.h,v 1.10 1999/07/28 20:17:16 deniel Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -36,6 +36,7 @@ typedef struct _loop_data {
gint go; gint go;
gint max; gint max;
gint linktype; gint linktype;
gint sync_packets;
time_t sync_time; time_t sync_time;
packet_counts counts; packet_counts counts;
pcap_dumper_t *pdh; pcap_dumper_t *pdh;

36
file.c
View File

@ -1,7 +1,7 @@
/* file.c /* file.c
* File I/O routines * File I/O routines
* *
* $Id: file.c,v 1.49 1999/07/28 03:38:42 guy Exp $ * $Id: file.c,v 1.50 1999/07/28 20:17:15 deniel Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -261,7 +261,10 @@ void
cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) { cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) {
capture_file *cf = (capture_file *)data; capture_file *cf = (capture_file *)data;
char buffer[256]; char buffer[256], *p = buffer, *q = buffer;
int nread;
int to_read = 0;
gboolean exit_loop = FALSE;
/* avoid reentrancy problems and stack overflow */ /* avoid reentrancy problems and stack overflow */
gtk_input_remove(cap_input_id); gtk_input_remove(cap_input_id);
@ -283,7 +286,7 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) {
and do it only if we have to? */ and do it only if we have to? */
fseek(cf->wth->fh, 0, SEEK_CUR); fseek(cf->wth->fh, 0, SEEK_CUR);
if (read(sync_pipe[0], buffer, 256) <= 0) { if ((nread = read(sync_pipe[0], buffer, 256)) <= 0) {
/* The child has closed the sync pipe, meaning it's not going to be /* The child has closed the sync pipe, meaning it's not going to be
capturing any more packets. Read what remains of the capture file, capturing any more packets. Read what remains of the capture file,
@ -309,9 +312,28 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) {
return; return;
} }
gtk_clist_freeze(GTK_CLIST(packet_list)); buffer[nread] = '\0';
wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf);
while(!exit_loop) {
/* look for (possibly multiple) '*' */
switch (*q) {
case '*' :
to_read += atoi(p);
p = q + 1;
q++;
break;
case '\0' :
/* XXX should handle the case of a pipe full (i.e. no star found) */
exit_loop = TRUE;
break;
default :
q++;
break;
}
}
gtk_clist_freeze(GTK_CLIST(packet_list));
wtap_loop(cf->wth, to_read, wtap_dispatch_cb, (u_char *) cf);
gtk_clist_thaw(GTK_CLIST(packet_list)); gtk_clist_thaw(GTK_CLIST(packet_list));
/* restore pipe handler */ /* restore pipe handler */
@ -322,9 +344,11 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) {
(gpointer) cf, (gpointer) cf,
NULL); NULL);
#if 0
/* XXX tail_timeout feature to be removed */
/* only useful in case of low amount of captured data */ /* only useful in case of low amount of captured data */
tail_timeout_id = gtk_timeout_add(TAIL_TIMEOUT, tail_timeout_cb, (gpointer) cf); tail_timeout_id = gtk_timeout_add(TAIL_TIMEOUT, tail_timeout_cb, (gpointer) cf);
#endif
} }
gint gint

View File

@ -1,6 +1,6 @@
/* wtap.c /* wtap.c
* *
* $Id: wtap.c,v 1.10 1999/07/13 02:53:26 gram Exp $ * $Id: wtap.c,v 1.11 1999/07/28 20:17:24 deniel Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@ -74,10 +74,11 @@ void wtap_close(wtap *wth)
void wtap_loop(wtap *wth, int count, wtap_handler callback, u_char* user) void wtap_loop(wtap *wth, int count, wtap_handler callback, u_char* user)
{ {
int data_offset; int data_offset, loop = 0;
while ((data_offset = wth->subtype_read(wth)) > 0) { while ((data_offset = wth->subtype_read(wth)) > 0) {
callback(user, &wth->phdr, data_offset, callback(user, &wth->phdr, data_offset,
buffer_start_ptr(wth->frame_buffer)); buffer_start_ptr(wth->frame_buffer));
if (count > 0 && ++loop >= count) break;
} }
} }