From e829856c0c03666c5b9b917fba4716b88fd580e6 Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Sun, 4 Dec 2005 02:04:18 +0000 Subject: move the complete functionality of the capture info dialog from capture_loop.c to capture_info.c and call it from capture.c (instead of capture_loop.c). This way, the capture child don't need to now any of the packet_counter things (no epan/packet.h and all alike). Currently the capture_info code will always open another wiretap file instance to build it's own counter values. This isn't optimized for now (next step: use data from cf_continue_tail() somehow). svn path=/trunk/; revision=16669 --- capture_info.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 97 insertions(+), 17 deletions(-) (limited to 'capture_info.c') diff --git a/capture_info.c b/capture_info.c index 473b93a6ec..05a09542d2 100644 --- a/capture_info.c +++ b/capture_info.c @@ -56,26 +56,106 @@ #include -void -capture_info_init(packet_counts *counts) + +void capture_info_packet( +packet_counts *counts, gint wtap_linktype, const u_char *pd, guint32 caplen, union wtap_pseudo_header *pseudo_header); + + + +typedef struct _info_data { + packet_counts counts; /* several packet type counters */ + struct wtap* wtap; /* current wtap file */ + capture_info ui; /* user interface data */ +} info_data_t; + + +info_data_t info_data; + + +/* open the info */ +void capture_info_open(const char *iface) +{ + info_data.counts.total = 0; + info_data.counts.sctp = 0; + info_data.counts.tcp = 0; + info_data.counts.udp = 0; + info_data.counts.icmp = 0; + info_data.counts.ospf = 0; + info_data.counts.gre = 0; + info_data.counts.ipx = 0; + info_data.counts.netbios = 0; + info_data.counts.vines = 0; + info_data.counts.other = 0; + info_data.counts.arp = 0; + + info_data.wtap = NULL; + info_data.ui.counts = &info_data.counts; + + capture_info_ui_create(&info_data.ui, iface); +} + + +/* new file arrived */ +void capture_info_new_file(const char *new_filename) +{ + int err; + gchar *err_info; + + + if(info_data.wtap != NULL) { + wtap_close(info_data.wtap); + } + + info_data.wtap = wtap_open_offline(new_filename, &err, &err_info, FALSE); + if (!info_data.wtap) { + g_warning("capture_info_new_file: wtap open failed: %s", err_info); + } + +} + + +/* new packets arrived */ +void capture_info_new_packets(int to_read) +{ + int err; + gchar *err_info; + long data_offset; + const struct wtap_pkthdr *phdr; + union wtap_pseudo_header *pseudo_header; + int wtap_linktype; + const guchar *buf; + + + info_data.ui.new_packets = to_read; + + /*g_warning("new packets: %u", to_read);*/ + + while (to_read != 0 && (wtap_read(info_data.wtap, &err, &err_info, &data_offset))) { + phdr = wtap_phdr(info_data.wtap); + pseudo_header = wtap_pseudoheader(info_data.wtap); + wtap_linktype = phdr->pkt_encap; + buf = wtap_buf_ptr(info_data.wtap); + + capture_info_packet(&info_data.counts, wtap_linktype, buf, phdr->caplen, pseudo_header); + + /*g_warning("new packet");*/ + to_read--; + } + + capture_info_ui_update(&info_data.ui); +} + + +/* close the info */ +void capture_info_close(void) { - counts->total = 0; - counts->sctp = 0; - counts->tcp = 0; - counts->udp = 0; - counts->icmp = 0; - counts->ospf = 0; - counts->gre = 0; - counts->ipx = 0; - counts->netbios = 0; - counts->vines = 0; - counts->other = 0; - counts->arp = 0; + capture_info_ui_destroy(&info_data.ui); + wtap_close(info_data.wtap); } -void -capture_info_packet(packet_counts *counts, gint wtap_linktype, const u_char *pd, guint32 caplen, union wtap_pseudo_header pseudo_header) +static void +capture_info_packet(packet_counts *counts, gint wtap_linktype, const u_char *pd, guint32 caplen, union wtap_pseudo_header *pseudo_header) { counts->total++; switch (wtap_linktype) { @@ -118,7 +198,7 @@ capture_info_packet(packet_counts *counts, gint wtap_linktype, const u_char *pd, capture_llap(counts); break; case WTAP_ENCAP_ATM_PDUS: - capture_atm(&pseudo_header, pd, caplen, counts); + capture_atm(pseudo_header, pd, caplen, counts); break; case WTAP_ENCAP_IP_OVER_FC: capture_ipfc(pd, caplen, counts); -- cgit v1.2.3