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:
parent
e0b268397a
commit
c42634dd82
16
capture.c
16
capture.c
|
@ -1,7 +1,7 @@
|
|||
/* capture.c
|
||||
* 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
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -413,6 +413,7 @@ capture(void) {
|
|||
ld.max = cf.count;
|
||||
ld.linktype = DLT_NULL;
|
||||
ld.sync_time = 0;
|
||||
ld.sync_packets = 0;
|
||||
ld.counts.tcp = 0;
|
||||
ld.counts.udp = 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);
|
||||
|
||||
cur_time = time(NULL);
|
||||
|
||||
ld->sync_packets ++;
|
||||
|
||||
if (cur_time > *sync_time) {
|
||||
/* sync every second */
|
||||
*sync_time = cur_time;
|
||||
fflush((FILE *)ld->pdh);
|
||||
if (sync_mode)
|
||||
write(1, "D", 1);
|
||||
if (sync_mode && ld->sync_packets) {
|
||||
char tmp[20];
|
||||
sprintf(tmp, "%d*", ld->sync_packets);
|
||||
write(1, tmp, strlen(tmp));
|
||||
ld->sync_packets = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (ld->linktype) {
|
||||
case DLT_EN10MB :
|
||||
capture_eth(pd, phdr->caplen, &ld->counts);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* capture.h
|
||||
* 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
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -36,6 +36,7 @@ typedef struct _loop_data {
|
|||
gint go;
|
||||
gint max;
|
||||
gint linktype;
|
||||
gint sync_packets;
|
||||
time_t sync_time;
|
||||
packet_counts counts;
|
||||
pcap_dumper_t *pdh;
|
||||
|
|
36
file.c
36
file.c
|
@ -1,7 +1,7 @@
|
|||
/* file.c
|
||||
* 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
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -261,7 +261,10 @@ void
|
|||
cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) {
|
||||
|
||||
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 */
|
||||
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? */
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
gtk_clist_freeze(GTK_CLIST(packet_list));
|
||||
wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf);
|
||||
buffer[nread] = '\0';
|
||||
|
||||
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));
|
||||
|
||||
/* restore pipe handler */
|
||||
|
@ -322,9 +344,11 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) {
|
|||
(gpointer) cf,
|
||||
NULL);
|
||||
|
||||
#if 0
|
||||
/* XXX tail_timeout feature to be removed */
|
||||
/* only useful in case of low amount of captured data */
|
||||
tail_timeout_id = gtk_timeout_add(TAIL_TIMEOUT, tail_timeout_cb, (gpointer) cf);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
gint
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* 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
|
||||
* 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)
|
||||
{
|
||||
int data_offset;
|
||||
int data_offset, loop = 0;
|
||||
|
||||
while ((data_offset = wth->subtype_read(wth)) > 0) {
|
||||
callback(user, &wth->phdr, data_offset,
|
||||
buffer_start_ptr(wth->frame_buffer));
|
||||
if (count > 0 && ++loop >= count) break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue