From a344c9736efe5519543da1290e1ad9065d0b0cff Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 23 May 2014 10:50:02 +0000 Subject: [PATCH] Revert "Allow wtap_read() and wtap_seek_read() to return non-packet records." This reverts commit c0c480d08c175eed4524ea9e73ec86298f468cf4. A better way to do this is to have the record type be part of struct wtap_pkthdr; that keeps the metadata for the record together and requires fewer API changes. That is in-progress. Change-Id: Ic558f163a48e2c6d0df7f55e81a35a5e24b53bc6 Reviewed-on: https://code.wireshark.org/review/1741 Reviewed-by: Guy Harris --- capinfos.c | 91 +++-- capture.c | 6 +- capture_info.c | 26 +- capture_info.h | 4 +- capture_sync.c | 2 +- capture_sync.h | 4 +- editcap.c | 622 +++++++++++++++++----------------- file.c | 87 ++--- file.h | 31 +- frame_tvbuff.c | 2 +- proto_hier_stats.c | 2 +- reordercap.c | 29 +- tfshark.c | 2 +- tshark.c | 243 ++++++------- ui/gtk/capture_file_dlg.c | 35 +- ui/gtk/iax2_analysis.c | 2 +- ui/gtk/main.c | 4 +- ui/gtk/packet_list_store.c | 2 +- ui/gtk/packet_win.c | 2 +- ui/gtk/rlc_lte_graph.c | 2 +- ui/gtk/rtp_analysis.c | 2 +- ui/gtk/sctp_assoc_analyse.c | 2 +- ui/qt/capture_file_dialog.cpp | 35 +- ui/qt/packet_list.cpp | 2 +- ui/qt/packet_list_model.cpp | 2 +- ui/tap-tcp-stream.c | 2 +- ui/win32/file_dlg_win32.c | 41 +-- wiretap/5views.c | 28 +- wiretap/aethra.c | 22 +- wiretap/ascendtext.c | 20 +- wiretap/ber.c | 24 +- wiretap/btsnoop.c | 22 +- wiretap/camins.c | 16 +- wiretap/catapult_dct2000.c | 32 +- wiretap/commview.c | 24 +- wiretap/cosine.c | 26 +- wiretap/csids.c | 20 +- wiretap/daintree-sna.c | 32 +- wiretap/dbs-etherwatch.c | 48 +-- wiretap/dct3trace.c | 26 +- wiretap/erf.c | 34 +- wiretap/eyesdn.c | 28 +- wiretap/hcidump.c | 16 +- wiretap/i4btrace.c | 24 +- wiretap/ipfix.c | 18 +- wiretap/iptrace.c | 28 +- wiretap/iseries.c | 28 +- wiretap/k12.c | 20 +- wiretap/k12text.l | 16 +- wiretap/lanalyzer.c | 20 +- wiretap/libpcap.c | 18 +- wiretap/logcat.c | 16 +- wiretap/mime_file.c | 20 +- wiretap/mp2t.c | 16 +- wiretap/mpeg.c | 16 +- wiretap/netmon.c | 32 +- wiretap/netscaler.c | 94 ++--- wiretap/netscreen.c | 26 +- wiretap/nettl.c | 18 +- wiretap/network_instruments.c | 30 +- wiretap/netxray.c | 32 +- wiretap/ngsniffer.c | 26 +- wiretap/packetlogger.c | 26 +- wiretap/pcapng.c | 16 +- wiretap/peekclassic.c | 30 +- wiretap/peektagged.c | 20 +- wiretap/pppdump.c | 22 +- wiretap/radcom.c | 22 +- wiretap/snoop.c | 20 +- wiretap/stanag4607.c | 25 +- wiretap/tnef.c | 26 +- wiretap/toshiba.c | 22 +- wiretap/visual.c | 22 +- wiretap/vms.c | 18 +- wiretap/vwr.c | 25 +- wiretap/wtap-int.h | 8 +- wiretap/wtap.c | 22 +- wiretap/wtap.h | 21 +- 78 files changed, 1212 insertions(+), 1333 deletions(-) diff --git a/capinfos.c b/capinfos.c index a24a6ae5a2..bad557e2dd 100644 --- a/capinfos.c +++ b/capinfos.c @@ -803,7 +803,6 @@ static int process_cap_file(wtap *wth, const char *filename) { int status = 0; - int rec_type; int err; gchar *err_info; gint64 size; @@ -829,53 +828,51 @@ process_cap_file(wtap *wth, const char *filename) cf_info.encap_counts = g_new0(int,WTAP_NUM_ENCAP_TYPES); /* Tally up data that we need to parse through the file to find */ - while ((rec_type = wtap_read(wth, &err, &err_info, &data_offset)) != -1) { - if (rec_type == REC_TYPE_PACKET) { - phdr = wtap_phdr(wth); - if (phdr->presence_flags & WTAP_HAS_TS) { - prev_time = cur_time; - cur_time = nstime_to_sec(&phdr->ts); - if (packet == 0) { - start_time = cur_time; - stop_time = cur_time; - prev_time = cur_time; - } - if (cur_time < prev_time) { - order = NOT_IN_ORDER; - } - if (cur_time < start_time) { - start_time = cur_time; - } - if (cur_time > stop_time) { - stop_time = cur_time; - } + while (wtap_read(wth, &err, &err_info, &data_offset)) { + phdr = wtap_phdr(wth); + if (phdr->presence_flags & WTAP_HAS_TS) { + prev_time = cur_time; + cur_time = nstime_to_sec(&phdr->ts); + if (packet == 0) { + start_time = cur_time; + stop_time = cur_time; + prev_time = cur_time; + } + if (cur_time < prev_time) { + order = NOT_IN_ORDER; + } + if (cur_time < start_time) { + start_time = cur_time; + } + if (cur_time > stop_time) { + stop_time = cur_time; + } + } else { + have_times = FALSE; /* at least one packet has no time stamp */ + if (order != NOT_IN_ORDER) + order = ORDER_UNKNOWN; + } + + bytes+=phdr->len; + packet++; + + /* If caplen < len for a rcd, then presumably */ + /* 'Limit packet capture length' was done for this rcd. */ + /* Keep track as to the min/max actual snapshot lengths */ + /* seen for this file. */ + if (phdr->caplen < phdr->len) { + if (phdr->caplen < snaplen_min_inferred) + snaplen_min_inferred = phdr->caplen; + if (phdr->caplen > snaplen_max_inferred) + snaplen_max_inferred = phdr->caplen; + } + + /* Per-packet encapsulation */ + if (wtap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) { + if ((phdr->pkt_encap > 0) && (phdr->pkt_encap < WTAP_NUM_ENCAP_TYPES)) { + cf_info.encap_counts[phdr->pkt_encap] += 1; } else { - have_times = FALSE; /* at least one packet has no time stamp */ - if (order != NOT_IN_ORDER) - order = ORDER_UNKNOWN; - } - - bytes+=phdr->len; - packet++; - - /* If caplen < len for a rcd, then presumably */ - /* 'Limit packet capture length' was done for this rcd. */ - /* Keep track as to the min/max actual snapshot lengths */ - /* seen for this file. */ - if (phdr->caplen < phdr->len) { - if (phdr->caplen < snaplen_min_inferred) - snaplen_min_inferred = phdr->caplen; - if (phdr->caplen > snaplen_max_inferred) - snaplen_max_inferred = phdr->caplen; - } - - /* Per-packet encapsulation */ - if (wtap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) { - if ((phdr->pkt_encap > 0) && (phdr->pkt_encap < WTAP_NUM_ENCAP_TYPES)) { - cf_info.encap_counts[phdr->pkt_encap] += 1; - } else { - fprintf(stderr, "capinfos: Unknown per-packet encapsulation: %d [frame number: %d]\n", phdr->pkt_encap, packet); - } + fprintf(stderr, "capinfos: Unknown per-packet encapsulation: %d [frame number: %d]\n", phdr->pkt_encap, packet); } } diff --git a/capture.c b/capture.c index c7f9ebf995..c308727096 100644 --- a/capture.c +++ b/capture.c @@ -390,9 +390,9 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file) } -/* capture child tells us we have new records to read */ +/* capture child tells us we have new packets to read */ void -capture_input_new_records(capture_session *cap_session, int to_read) +capture_input_new_packets(capture_session *cap_session, int to_read) { capture_options *capture_opts = cap_session->capture_opts; int err; @@ -435,7 +435,7 @@ capture_input_new_records(capture_session *cap_session, int to_read) #endif if(capture_opts->show_info) - capture_info_new_records(to_read); + capture_info_new_packets(to_read); } diff --git a/capture_info.c b/capture_info.c index c3c232816c..3ef12df504 100644 --- a/capture_info.c +++ b/capture_info.c @@ -232,11 +232,9 @@ gboolean capture_info_new_file(const char *new_filename) } -/* new records arrived */ -void capture_info_new_records(int to_read) +/* new packets arrived */ +void capture_info_new_packets(int to_read) { - int rec_type; - int packets_read = 0; int err; gchar *err_info; gint64 data_offset; @@ -246,27 +244,25 @@ void capture_info_new_records(int to_read) const guchar *buf; + info_data.ui.new_packets = to_read; + /*g_warning("new packets: %u", to_read);*/ while (to_read > 0) { wtap_cleareof(info_data.wtap); - if ((rec_type = wtap_read(info_data.wtap, &err, &err_info, &data_offset)) != -1) { - if (rec_type == REC_TYPE_PACKET) { - phdr = wtap_phdr(info_data.wtap); - pseudo_header = &phdr->pseudo_header; - wtap_linktype = phdr->pkt_encap; - buf = wtap_buf_ptr(info_data.wtap); + if (wtap_read(info_data.wtap, &err, &err_info, &data_offset)) { + phdr = wtap_phdr(info_data.wtap); + pseudo_header = &phdr->pseudo_header; + 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); - packets_read++; + capture_info_packet(&info_data.counts, wtap_linktype, buf, phdr->caplen, pseudo_header); - /*g_warning("new packet");*/ - } + /*g_warning("new packet");*/ to_read--; } } - info_data.ui.new_packets = packets_read; capture_info_ui_update(&info_data.ui); } diff --git a/capture_info.h b/capture_info.h index 286dce12c0..3e5845ac6c 100644 --- a/capture_info.h +++ b/capture_info.h @@ -43,8 +43,8 @@ extern void capture_info_open(capture_session *cap_session); /* new file arrived - (eventually close old wtap), open wtap */ extern gboolean capture_info_new_file(const char *new_filename); -/* new records arrived - read from wtap, count */ -extern void capture_info_new_records(int to_read); +/* new packets arrived - read from wtap, count */ +extern void capture_info_new_packets(int to_read); /* close the info - close wtap, destroy dialog */ extern void capture_info_close(void); diff --git a/capture_sync.c b/capture_sync.c index 0b374e877c..2f9d2cc62e 100644 --- a/capture_sync.c +++ b/capture_sync.c @@ -1776,7 +1776,7 @@ sync_pipe_input_cb(gint source, gpointer user_data) case SP_PACKET_COUNT: npackets = atoi(buffer); g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", npackets); - capture_input_new_records(cap_session, npackets); + capture_input_new_packets(cap_session, npackets); break; case SP_ERROR_MSG: /* convert primary message */ diff --git a/capture_sync.h b/capture_sync.h index 2732690573..2c4bb639af 100644 --- a/capture_sync.h +++ b/capture_sync.h @@ -99,10 +99,10 @@ extern gboolean capture_input_new_file(capture_session *cap_session, gchar *new_file); /** - * Capture child told us we have new records to read. + * Capture child told us we have new packets to read. */ extern void -capture_input_new_records(capture_session *cap_session, int to_read); +capture_input_new_packets(capture_session *cap_session, int to_read); /** * Capture child told us how many dropped packets it counted. diff --git a/editcap.c b/editcap.c index 415e2e481e..70dfd0859a 100644 --- a/editcap.c +++ b/editcap.c @@ -842,7 +842,7 @@ main(int argc, char *argv[]) int i, j, err; gchar *err_info; int opt; - int rec_type; + char *p; guint32 snaplen = 0; /* No limit */ chop_t chop = {0, 0, 0, 0, 0, 0}; /* No chop */ @@ -1192,30 +1192,60 @@ main(int argc, char *argv[]) } } - while ((rec_type = wtap_read(wth, &err, &err_info, &data_offset)) != -1) { - if (rec_type == REC_TYPE_PACKET) { - read_count++; + while (wtap_read(wth, &err, &err_info, &data_offset)) { + read_count++; - phdr = wtap_phdr(wth); - buf = wtap_buf_ptr(wth); + phdr = wtap_phdr(wth); + buf = wtap_buf_ptr(wth); - if (nstime_is_unset(&block_start)) { /* should only be the first packet */ - block_start.secs = phdr->ts.secs; - block_start.nsecs = phdr->ts.nsecs; + if (nstime_is_unset(&block_start)) { /* should only be the first packet */ + block_start.secs = phdr->ts.secs; + block_start.nsecs = phdr->ts.nsecs; - if (split_packet_count > 0 || secs_per_block > 0) { - if (!fileset_extract_prefix_suffix(argv[optind+1], &fprefix, &fsuffix)) - exit(2); + if (split_packet_count > 0 || secs_per_block > 0) { + if (!fileset_extract_prefix_suffix(argv[optind+1], &fprefix, &fsuffix)) + exit(2); - filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); - } else { - filename = g_strdup(argv[optind+1]); + filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); + } else { + filename = g_strdup(argv[optind+1]); + } + + /* If we don't have an application name add Editcap */ + if (shb_hdr->shb_user_appl == NULL) { + shb_hdr->shb_user_appl = "Editcap " VERSION; + } + + pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, + snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), + FALSE /* compressed */, shb_hdr, idb_inf, &err); + + if (pdh == NULL) { + fprintf(stderr, "editcap: Can't open or create %s: %s\n", + filename, wtap_strerror(err)); + exit(2); + } + } + + g_assert(filename); + + if (secs_per_block > 0) { + while ((phdr->ts.secs - block_start.secs > secs_per_block) + || (phdr->ts.secs - block_start.secs == secs_per_block + && phdr->ts.nsecs >= block_start.nsecs )) { /* time for the next file */ + + if (!wtap_dump_close(pdh, &err)) { + fprintf(stderr, "editcap: Error writing to %s: %s\n", + filename, wtap_strerror(err)); + exit(2); } + block_start.secs = block_start.secs + secs_per_block; /* reset for next interval */ + g_free(filename); + filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); + g_assert(filename); - /* If we don't have an application name add Editcap */ - if (shb_hdr->shb_user_appl == NULL) { - shb_hdr->shb_user_appl = "Editcap " VERSION; - } + if (verbose) + fprintf(stderr, "Continuing writing in file %s\n", filename); pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), @@ -1227,138 +1257,89 @@ main(int argc, char *argv[]) exit(2); } } + } - g_assert(filename); + if (split_packet_count > 0) { + /* time for the next file? */ + if (written_count > 0 && written_count % split_packet_count == 0) { + if (!wtap_dump_close(pdh, &err)) { + fprintf(stderr, "editcap: Error writing to %s: %s\n", + filename, wtap_strerror(err)); + exit(2); + } - if (secs_per_block > 0) { - while ((phdr->ts.secs - block_start.secs > secs_per_block) - || (phdr->ts.secs - block_start.secs == secs_per_block - && phdr->ts.nsecs >= block_start.nsecs )) { /* time for the next file */ + g_free(filename); + filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); + g_assert(filename); - if (!wtap_dump_close(pdh, &err)) { - fprintf(stderr, "editcap: Error writing to %s: %s\n", - filename, wtap_strerror(err)); - exit(2); - } - block_start.secs = block_start.secs + secs_per_block; /* reset for next interval */ - g_free(filename); - filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); - g_assert(filename); + if (verbose) + fprintf(stderr, "Continuing writing in file %s\n", filename); - if (verbose) - fprintf(stderr, "Continuing writing in file %s\n", filename); + pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, + snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), + FALSE /* compressed */, shb_hdr, idb_inf, &err); + if (pdh == NULL) { + fprintf(stderr, "editcap: Can't open or create %s: %s\n", + filename, wtap_strerror(err)); + exit(2); + } + } + } - pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, - snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), - FALSE /* compressed */, shb_hdr, idb_inf, &err); + if (check_startstop) + ts_okay = check_timestamp(wth); - if (pdh == NULL) { - fprintf(stderr, "editcap: Can't open or create %s: %s\n", - filename, wtap_strerror(err)); - exit(2); - } + if (ts_okay && ((!selected(count) && !keep_em) + || (selected(count) && keep_em))) { + + if (verbose && !dup_detect && !dup_detect_by_time) + fprintf(stderr, "Packet: %u\n", count); + + /* We simply write it, perhaps after truncating it; we could + * do other things, like modify it. */ + + phdr = wtap_phdr(wth); + + if (snaplen != 0) { + if (phdr->caplen > snaplen) { + snap_phdr = *phdr; + snap_phdr.caplen = snaplen; + phdr = &snap_phdr; + } + if (adjlen && phdr->len > snaplen) { + snap_phdr = *phdr; + snap_phdr.len = snaplen; + phdr = &snap_phdr; } } - if (split_packet_count > 0) { - /* time for the next file? */ - if (written_count > 0 && written_count % split_packet_count == 0) { - if (!wtap_dump_close(pdh, &err)) { - fprintf(stderr, "editcap: Error writing to %s: %s\n", - filename, wtap_strerror(err)); - exit(2); - } + /* CHOP */ + snap_phdr = *phdr; + handle_chopping(chop, &snap_phdr, phdr, &buf, adjlen); + phdr = &snap_phdr; - g_free(filename); - filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); - g_assert(filename); + /* Do we adjust timestamps to ensure strict chronological + * order? */ + if (do_strict_time_adjustment) { + if (previous_time.secs || previous_time.nsecs) { + if (!strict_time_adj.is_negative) { + nstime_t current; + nstime_t delta; - if (verbose) - fprintf(stderr, "Continuing writing in file %s\n", filename); + current.secs = phdr->ts.secs; + current.nsecs = phdr->ts.nsecs; - pdh = wtap_dump_open_ng(filename, out_file_type_subtype, out_frame_type, - snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), - FALSE /* compressed */, shb_hdr, idb_inf, &err); - if (pdh == NULL) { - fprintf(stderr, "editcap: Can't open or create %s: %s\n", - filename, wtap_strerror(err)); - exit(2); - } - } - } + nstime_delta(&delta, ¤t, &previous_time); - if (check_startstop) - ts_okay = check_timestamp(wth); - - if (ts_okay && ((!selected(count) && !keep_em) - || (selected(count) && keep_em))) { - - if (verbose && !dup_detect && !dup_detect_by_time) - fprintf(stderr, "Packet: %u\n", count); - - /* We simply write it, perhaps after truncating it; we could - * do other things, like modify it. */ - - phdr = wtap_phdr(wth); - - if (snaplen != 0) { - if (phdr->caplen > snaplen) { - snap_phdr = *phdr; - snap_phdr.caplen = snaplen; - phdr = &snap_phdr; - } - if (adjlen && phdr->len > snaplen) { - snap_phdr = *phdr; - snap_phdr.len = snaplen; - phdr = &snap_phdr; - } - } - - /* CHOP */ - snap_phdr = *phdr; - handle_chopping(chop, &snap_phdr, phdr, &buf, adjlen); - phdr = &snap_phdr; - - /* Do we adjust timestamps to ensure strict chronological - * order? */ - if (do_strict_time_adjustment) { - if (previous_time.secs || previous_time.nsecs) { - if (!strict_time_adj.is_negative) { - nstime_t current; - nstime_t delta; - - current.secs = phdr->ts.secs; - current.nsecs = phdr->ts.nsecs; - - nstime_delta(&delta, ¤t, &previous_time); - - if (delta.secs < 0 || delta.nsecs < 0) { - /* - * A negative delta indicates that the current packet - * has an absolute timestamp less than the previous packet - * that it is being compared to. This is NOT a normal - * situation since trace files usually have packets in - * chronological order (oldest to newest). - */ - /* fprintf(stderr, "++out of order, need to adjust this packet!\n"); */ - snap_phdr = *phdr; - snap_phdr.ts.secs = previous_time.secs + strict_time_adj.tv.tv_sec; - snap_phdr.ts.nsecs = previous_time.nsecs; - if (snap_phdr.ts.nsecs + strict_time_adj.tv.tv_usec * 1000 > ONE_MILLION * 1000) { - /* carry */ - snap_phdr.ts.secs++; - snap_phdr.ts.nsecs += (strict_time_adj.tv.tv_usec - ONE_MILLION) * 1000; - } else { - snap_phdr.ts.nsecs += strict_time_adj.tv.tv_usec * 1000; - } - phdr = &snap_phdr; - } - } else { + if (delta.secs < 0 || delta.nsecs < 0) { /* - * A negative strict time adjustment is requested. - * Unconditionally set each timestamp to previous - * packet's timestamp plus delta. + * A negative delta indicates that the current packet + * has an absolute timestamp less than the previous packet + * that it is being compared to. This is NOT a normal + * situation since trace files usually have packets in + * chronological order (oldest to newest). */ + /* fprintf(stderr, "++out of order, need to adjust this packet!\n"); */ snap_phdr = *phdr; snap_phdr.ts.secs = previous_time.secs + strict_time_adj.tv.tv_sec; snap_phdr.ts.nsecs = previous_time.nsecs; @@ -1371,190 +1352,207 @@ main(int argc, char *argv[]) } phdr = &snap_phdr; } - } - previous_time.secs = phdr->ts.secs; - previous_time.nsecs = phdr->ts.nsecs; - } - - /* assume that if the frame's tv_sec is 0, then - * the timestamp isn't supported */ - if (phdr->ts.secs > 0 && time_adj.tv.tv_sec != 0) { - snap_phdr = *phdr; - if (time_adj.is_negative) - snap_phdr.ts.secs -= time_adj.tv.tv_sec; - else - snap_phdr.ts.secs += time_adj.tv.tv_sec; - phdr = &snap_phdr; - } - - /* assume that if the frame's tv_sec is 0, then - * the timestamp isn't supported */ - if (phdr->ts.secs > 0 && time_adj.tv.tv_usec != 0) { - snap_phdr = *phdr; - if (time_adj.is_negative) { /* subtract */ - if (snap_phdr.ts.nsecs/1000 < time_adj.tv.tv_usec) { /* borrow */ - snap_phdr.ts.secs--; - snap_phdr.ts.nsecs += ONE_MILLION * 1000; - } - snap_phdr.ts.nsecs -= time_adj.tv.tv_usec * 1000; - } else { /* add */ - if (snap_phdr.ts.nsecs + time_adj.tv.tv_usec * 1000 > ONE_MILLION * 1000) { + } else { + /* + * A negative strict time adjustment is requested. + * Unconditionally set each timestamp to previous + * packet's timestamp plus delta. + */ + snap_phdr = *phdr; + snap_phdr.ts.secs = previous_time.secs + strict_time_adj.tv.tv_sec; + snap_phdr.ts.nsecs = previous_time.nsecs; + if (snap_phdr.ts.nsecs + strict_time_adj.tv.tv_usec * 1000 > ONE_MILLION * 1000) { /* carry */ snap_phdr.ts.secs++; - snap_phdr.ts.nsecs += (time_adj.tv.tv_usec - ONE_MILLION) * 1000; + snap_phdr.ts.nsecs += (strict_time_adj.tv.tv_usec - ONE_MILLION) * 1000; } else { - snap_phdr.ts.nsecs += time_adj.tv.tv_usec * 1000; - } - } - phdr = &snap_phdr; - } - - /* suppress duplicates by packet window */ - if (dup_detect) { - if (is_duplicate(buf, phdr->caplen)) { - if (verbose) { - fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ", - count, phdr->caplen); - for (i = 0; i < 16; i++) - fprintf(stderr, "%02x", - (unsigned char)fd_hash[cur_dup_entry].digest[i]); - fprintf(stderr, "\n"); - } - duplicate_count++; - count++; - continue; - } else { - if (verbose) { - fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ", - count, phdr->caplen); - for (i = 0; i < 16; i++) - fprintf(stderr, "%02x", - (unsigned char)fd_hash[cur_dup_entry].digest[i]); - fprintf(stderr, "\n"); + snap_phdr.ts.nsecs += strict_time_adj.tv.tv_usec * 1000; } + phdr = &snap_phdr; } } - - /* suppress duplicates by time window */ - if (dup_detect_by_time) { - nstime_t current; - - current.secs = phdr->ts.secs; - current.nsecs = phdr->ts.nsecs; - - if (is_duplicate_rel_time(buf, phdr->caplen, ¤t)) { - if (verbose) { - fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ", - count, phdr->caplen); - for (i = 0; i < 16; i++) - fprintf(stderr, "%02x", - (unsigned char)fd_hash[cur_dup_entry].digest[i]); - fprintf(stderr, "\n"); - } - duplicate_count++; - count++; - continue; - } else { - if (verbose) { - fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ", - count, phdr->caplen); - for (i = 0; i < 16; i++) - fprintf(stderr, "%02x", - (unsigned char)fd_hash[cur_dup_entry].digest[i]); - fprintf(stderr, "\n"); - } - } - } - - /* Random error mutation */ - if (err_prob > 0.0) { - int real_data_start = 0; - - /* Protect non-protocol data */ - if (wtap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000) - real_data_start = find_dct2000_real_data(buf); - - for (i = real_data_start; i < (int) phdr->caplen; i++) { - if (rand() <= err_prob * RAND_MAX) { - err_type = rand() / (RAND_MAX / ERR_WT_TOTAL + 1); - - if (err_type < ERR_WT_BIT) { - buf[i] ^= 1 << (rand() / (RAND_MAX / 8 + 1)); - err_type = ERR_WT_TOTAL; - } else { - err_type -= ERR_WT_BYTE; - } - - if (err_type < ERR_WT_BYTE) { - buf[i] = rand() / (RAND_MAX / 255 + 1); - err_type = ERR_WT_TOTAL; - } else { - err_type -= ERR_WT_BYTE; - } - - if (err_type < ERR_WT_ALNUM) { - buf[i] = ALNUM_CHARS[rand() / (RAND_MAX / ALNUM_LEN + 1)]; - err_type = ERR_WT_TOTAL; - } else { - err_type -= ERR_WT_ALNUM; - } - - if (err_type < ERR_WT_FMT) { - if ((unsigned int)i < phdr->caplen - 2) - g_strlcpy((char*) &buf[i], "%s", 2); - err_type = ERR_WT_TOTAL; - } else { - err_type -= ERR_WT_FMT; - } - - if (err_type < ERR_WT_AA) { - for (j = i; j < (int) phdr->caplen; j++) - buf[j] = 0xAA; - i = phdr->caplen; - } - } - } - } - - if (!wtap_dump(pdh, phdr, buf, &err)) { - switch (err) { - case WTAP_ERR_UNSUPPORTED_ENCAP: - /* - * This is a problem with the particular frame we're - * writing and the file type and subtype we're - * writing; note that, and report the frame number - * and file type/subtype. - */ - fprintf(stderr, - "editcap: Frame %u of \"%s\" has a network type that can't be saved in a \"%s\" file\n.", - read_count, argv[optind], - wtap_file_type_subtype_string(out_file_type_subtype)); - break; - - case WTAP_ERR_PACKET_TOO_LARGE: - /* - * This is a problem with the particular frame we're - * writing and the file type and subtype we're - * writing; note that, and report the frame number - * and file type/subtype. - */ - fprintf(stderr, - "editcap: Frame %u of \"%s\" is too large for a \"%s\" file\n.", - read_count, argv[optind], - wtap_file_type_subtype_string(out_file_type_subtype)); - break; - - default: - fprintf(stderr, "editcap: Error writing to %s: %s\n", - filename, wtap_strerror(err)); - break; - } - exit(2); - } - written_count++; + previous_time.secs = phdr->ts.secs; + previous_time.nsecs = phdr->ts.nsecs; } - count++; + + /* assume that if the frame's tv_sec is 0, then + * the timestamp isn't supported */ + if (phdr->ts.secs > 0 && time_adj.tv.tv_sec != 0) { + snap_phdr = *phdr; + if (time_adj.is_negative) + snap_phdr.ts.secs -= time_adj.tv.tv_sec; + else + snap_phdr.ts.secs += time_adj.tv.tv_sec; + phdr = &snap_phdr; + } + + /* assume that if the frame's tv_sec is 0, then + * the timestamp isn't supported */ + if (phdr->ts.secs > 0 && time_adj.tv.tv_usec != 0) { + snap_phdr = *phdr; + if (time_adj.is_negative) { /* subtract */ + if (snap_phdr.ts.nsecs/1000 < time_adj.tv.tv_usec) { /* borrow */ + snap_phdr.ts.secs--; + snap_phdr.ts.nsecs += ONE_MILLION * 1000; + } + snap_phdr.ts.nsecs -= time_adj.tv.tv_usec * 1000; + } else { /* add */ + if (snap_phdr.ts.nsecs + time_adj.tv.tv_usec * 1000 > ONE_MILLION * 1000) { + /* carry */ + snap_phdr.ts.secs++; + snap_phdr.ts.nsecs += (time_adj.tv.tv_usec - ONE_MILLION) * 1000; + } else { + snap_phdr.ts.nsecs += time_adj.tv.tv_usec * 1000; + } + } + phdr = &snap_phdr; + } + + /* suppress duplicates by packet window */ + if (dup_detect) { + if (is_duplicate(buf, phdr->caplen)) { + if (verbose) { + fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ", + count, phdr->caplen); + for (i = 0; i < 16; i++) + fprintf(stderr, "%02x", + (unsigned char)fd_hash[cur_dup_entry].digest[i]); + fprintf(stderr, "\n"); + } + duplicate_count++; + count++; + continue; + } else { + if (verbose) { + fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ", + count, phdr->caplen); + for (i = 0; i < 16; i++) + fprintf(stderr, "%02x", + (unsigned char)fd_hash[cur_dup_entry].digest[i]); + fprintf(stderr, "\n"); + } + } + } + + /* suppress duplicates by time window */ + if (dup_detect_by_time) { + nstime_t current; + + current.secs = phdr->ts.secs; + current.nsecs = phdr->ts.nsecs; + + if (is_duplicate_rel_time(buf, phdr->caplen, ¤t)) { + if (verbose) { + fprintf(stderr, "Skipped: %u, Len: %u, MD5 Hash: ", + count, phdr->caplen); + for (i = 0; i < 16; i++) + fprintf(stderr, "%02x", + (unsigned char)fd_hash[cur_dup_entry].digest[i]); + fprintf(stderr, "\n"); + } + duplicate_count++; + count++; + continue; + } else { + if (verbose) { + fprintf(stderr, "Packet: %u, Len: %u, MD5 Hash: ", + count, phdr->caplen); + for (i = 0; i < 16; i++) + fprintf(stderr, "%02x", + (unsigned char)fd_hash[cur_dup_entry].digest[i]); + fprintf(stderr, "\n"); + } + } + } + + /* Random error mutation */ + if (err_prob > 0.0) { + int real_data_start = 0; + + /* Protect non-protocol data */ + if (wtap_file_type_subtype(wth) == WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000) + real_data_start = find_dct2000_real_data(buf); + + for (i = real_data_start; i < (int) phdr->caplen; i++) { + if (rand() <= err_prob * RAND_MAX) { + err_type = rand() / (RAND_MAX / ERR_WT_TOTAL + 1); + + if (err_type < ERR_WT_BIT) { + buf[i] ^= 1 << (rand() / (RAND_MAX / 8 + 1)); + err_type = ERR_WT_TOTAL; + } else { + err_type -= ERR_WT_BYTE; + } + + if (err_type < ERR_WT_BYTE) { + buf[i] = rand() / (RAND_MAX / 255 + 1); + err_type = ERR_WT_TOTAL; + } else { + err_type -= ERR_WT_BYTE; + } + + if (err_type < ERR_WT_ALNUM) { + buf[i] = ALNUM_CHARS[rand() / (RAND_MAX / ALNUM_LEN + 1)]; + err_type = ERR_WT_TOTAL; + } else { + err_type -= ERR_WT_ALNUM; + } + + if (err_type < ERR_WT_FMT) { + if ((unsigned int)i < phdr->caplen - 2) + g_strlcpy((char*) &buf[i], "%s", 2); + err_type = ERR_WT_TOTAL; + } else { + err_type -= ERR_WT_FMT; + } + + if (err_type < ERR_WT_AA) { + for (j = i; j < (int) phdr->caplen; j++) + buf[j] = 0xAA; + i = phdr->caplen; + } + } + } + } + + if (!wtap_dump(pdh, phdr, buf, &err)) { + switch (err) { + case WTAP_ERR_UNSUPPORTED_ENCAP: + /* + * This is a problem with the particular frame we're + * writing and the file type and subtype we're + * writing; note that, and report the frame number + * and file type/subtype. + */ + fprintf(stderr, + "editcap: Frame %u of \"%s\" has a network type that can't be saved in a \"%s\" file\n.", + read_count, argv[optind], + wtap_file_type_subtype_string(out_file_type_subtype)); + break; + + case WTAP_ERR_PACKET_TOO_LARGE: + /* + * This is a problem with the particular frame we're + * writing and the file type and subtype we're + * writing; note that, and report the frame number + * and file type/subtype. + */ + fprintf(stderr, + "editcap: Frame %u of \"%s\" is too large for a \"%s\" file\n.", + read_count, argv[optind], + wtap_file_type_subtype_string(out_file_type_subtype)); + break; + + default: + fprintf(stderr, "editcap: Error writing to %s: %s\n", + filename, wtap_strerror(err)); + break; + } + exit(2); + } + written_count++; } + count++; } g_free(fprefix); diff --git a/file.c b/file.c index c54188b550..e75a78d4f9 100644 --- a/file.c +++ b/file.c @@ -575,7 +575,6 @@ cf_read(capture_file *cf, gboolean reloading) { int err; gchar *err_info; - int rec_type; gchar *name_ptr; progdlg_t *progbar = NULL; gboolean stop_flag; @@ -652,7 +651,7 @@ cf_read(capture_file *cf, gboolean reloading) }else progbar_quantum = 0; - while ((rec_type = wtap_read(cf->wth, &err, &err_info, &data_offset)) != -1) { + while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) { if (size >= 0) { count++; file_pos = wtap_read_so_far(cf->wth); @@ -702,9 +701,7 @@ cf_read(capture_file *cf, gboolean reloading) hours even on fast machines) just to see that it was the wrong file. */ break; } - - if (rec_type == REC_TYPE_PACKET) - read_packet(cf, dfcode, &edt, cinfo, data_offset); + read_packet(cf, dfcode, &edt, cinfo, data_offset); } } CATCH(OutOfMemoryError) { @@ -840,7 +837,6 @@ cf_read(capture_file *cf, gboolean reloading) cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err) { - int rec_type; gchar *err_info; volatile int newly_displayed_packets = 0; dfilter_t *dfcode; @@ -879,7 +875,7 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err) while (to_read != 0) { wtap_cleareof(cf->wth); - if ((rec_type = wtap_read(cf->wth, err, &err_info, &data_offset)) == -1) { + if (!wtap_read(cf->wth, err, &err_info, &data_offset)) { break; } if (cf->state == FILE_READ_ABORTED) { @@ -888,10 +884,8 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err) aren't any packets left to read) exit. */ break; } - if (rec_type == REC_TYPE_PACKET) { - if (read_packet(cf, dfcode, &edt, (column_info *) cinfo, data_offset) != -1) { - newly_displayed_packets++; - } + if (read_packet(cf, dfcode, &edt, (column_info *) cinfo, data_offset) != -1) { + newly_displayed_packets++; } to_read--; } @@ -965,7 +959,6 @@ cf_fake_continue_tail(capture_file *cf) { cf_read_status_t cf_finish_tail(capture_file *cf, int *err) { - int rec_type; gchar *err_info; gint64 data_offset; dfilter_t *dfcode; @@ -999,15 +992,14 @@ cf_finish_tail(capture_file *cf, int *err) epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE); - while ((rec_type = wtap_read(cf->wth, err, &err_info, &data_offset)) != -1) { + while ((wtap_read(cf->wth, err, &err_info, &data_offset))) { if (cf->state == FILE_READ_ABORTED) { /* Well, the user decided to abort the read. Break out of the loop, and let the code below (which is called even if there aren't any packets left to read) exit. */ break; } - if (rec_type == REC_TYPE_PACKET) - read_packet(cf, dfcode, &edt, cinfo, data_offset); + read_packet(cf, dfcode, &edt, cinfo, data_offset); } /* Cleanup and release all dfilter resources */ @@ -1761,11 +1753,10 @@ cf_redissect_packets(capture_file *cf) } } -int +gboolean cf_read_frame_r(capture_file *cf, const frame_data *fdata, struct wtap_pkthdr *phdr, Buffer *buf) { - int rec_type; int err; gchar *err_info; gchar *display_basename; @@ -1777,19 +1768,17 @@ cf_read_frame_r(capture_file *cf, const frame_data *fdata, if (!frame) { simple_error_message_box("fdata->file_off == -1, but can't find modified frame!"); - return -1; + return FALSE; } *phdr = frame->phdr; buffer_assure_space(buf, frame->phdr.caplen); memcpy(buffer_start_ptr(buf), frame->pd, frame->phdr.caplen); - /* XXX - what if this isn't a packet? */ - return REC_TYPE_PACKET; + return TRUE; } #endif - rec_type = wtap_seek_read(cf->wth, fdata->file_off, phdr, buf, &err, &err_info); - if (rec_type == -1) { + if (!wtap_seek_read(cf->wth, fdata->file_off, phdr, buf, &err, &err_info)) { display_basename = g_filename_display_basename(cf->filename); switch (err) { @@ -1812,12 +1801,12 @@ cf_read_frame_r(capture_file *cf, const frame_data *fdata, break; } g_free(display_basename); - return -1; + return FALSE; } - return rec_type; + return TRUE; } -int +gboolean cf_read_frame(capture_file *cf, frame_data *fdata) { return cf_read_frame_r(cf, fdata, &cf->phdr, &cf->buf); @@ -2016,7 +2005,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb /* Frame dependencies from the previous dissection/filtering are no longer valid. */ fdata->flags.dependent_of_displayed = 0; - if (cf_read_frame(cf, fdata) == -1) + if (!cf_read_frame(cf, fdata)) break; /* error reading the frame */ /* If the previous frame is displayed, and we haven't yet seen the @@ -2343,7 +2332,7 @@ process_specified_packets(capture_file *cf, packet_range_t *range, } /* Get the packet */ - if (cf_read_frame_r(cf, fdata, &phdr, &buf) == -1) { + if (!cf_read_frame_r(cf, fdata, &phdr, &buf)) { /* Attempt to get the packet failed. */ ret = PSP_FAILED; break; @@ -3120,7 +3109,7 @@ match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion) epan_dissect_t edt; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3224,7 +3213,7 @@ match_summary_line(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3322,7 +3311,7 @@ match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3370,7 +3359,7 @@ match_narrow(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3417,7 +3406,7 @@ match_wide(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3463,7 +3452,7 @@ match_binary(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3533,7 +3522,7 @@ match_dfilter(capture_file *cf, frame_data *fdata, void *criterion) match_result result; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3859,7 +3848,7 @@ cf_select_packet(capture_file *cf, int row) } /* Get the data in that frame. */ - if (cf_read_frame (cf, fdata) == -1) { + if (!cf_read_frame (cf, fdata)) { return; } @@ -4039,7 +4028,7 @@ cf_get_comment(capture_file *cf, const frame_data *fd) memset(&phdr, 0, sizeof(struct wtap_pkthdr)); buffer_init(&buf, 1500); - if (cf_read_frame_r(cf, fd, &phdr, &buf) == -1) + if (!cf_read_frame_r(cf, fd, &phdr, &buf)) { /* XXX, what we can do here? */ } buffer_free(&buf); @@ -4333,7 +4322,6 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) { const struct wtap_pkthdr *phdr; gchar *err_info; - int rec_type; gchar *name_ptr; gint64 data_offset; gint64 file_pos; @@ -4420,7 +4408,10 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) framenum = 0; phdr = wtap_phdr(cf->wth); - while ((rec_type = wtap_read(cf->wth, err, &err_info, &data_offset)) != -1) { + while ((wtap_read(cf->wth, err, &err_info, &data_offset))) { + framenum++; + fdata = frame_data_sequence_find(cf->frames, framenum); + fdata->file_off = data_offset; if (size >= 0) { count++; file_pos = wtap_read_so_far(cf->wth); @@ -4464,19 +4455,13 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) break; } - if (rec_type == REC_TYPE_PACKET) { - framenum++; - fdata = frame_data_sequence_find(cf->frames, framenum); - fdata->file_off = data_offset; - - /* Add this packet's link-layer encapsulation type to cf->linktypes, if - it's not already there. - XXX - yes, this is O(N), so if every packet had a different - link-layer encapsulation type, it'd be O(N^2) to read the file, but - there are probably going to be a small number of encapsulation types - in a file. */ - cf_add_encapsulation_type(cf, phdr->pkt_encap); - } + /* Add this packet's link-layer encapsulation type to cf->linktypes, if + it's not already there. + XXX - yes, this is O(N), so if every packet had a different + link-layer encapsulation type, it'd be O(N^2) to read the file, but + there are probably going to be a small number of encapsulation types + in a file. */ + cf_add_encapsulation_type(cf, phdr->pkt_encap); } /* Free the display name */ diff --git a/file.h b/file.h index ed12f57044..79df1cfd68 100644 --- a/file.h +++ b/file.h @@ -137,30 +137,29 @@ void cf_reload(capture_file *cf); cf_read_status_t cf_read(capture_file *cf, gboolean from_save); /** - * Read a record from a capture file. It will pop up an alert box - * if there's an error. + * Read the pseudo-header and raw data for a packet. It will pop + * up an alert box if there's an error. * - * @param cf the capture file from which to read the record - * @param fdata the frame_data structure for the record in question + * @param cf the capture file from which to read the packet + * @param fdata the frame_data structure for the packet in question * @param phdr pointer to a wtap_pkthdr structure to contain the - * packet's pseudo-header and other metadata, if the record is a - * packet - * @param buf a Buffer into which to read the record's data - * @return record type if the read succeeded, -1 if there was an error + * packet's pseudo-header and other metadata + * @param buf a Buffer into which to read the packet's raw data + * @return TRUE if the read succeeded, FALSE if there was an error */ -int cf_read_frame_r(capture_file *cf, const frame_data *fdata, - struct wtap_pkthdr *phdr, Buffer *buf); +gboolean cf_read_frame_r(capture_file *cf, const frame_data *fdata, + struct wtap_pkthdr *phdr, Buffer *buf); /** - * Read a record from a capture file into a capture_file structure's - * pseudo_header and buf members. + * Read the pseudo-header and raw data for a packet into a + * capture_file structure's pseudo_header and buf members. * It will pop up an alert box if there's an error. * - * @param cf the capture file from which to read the record - * @param fdata the frame_data structure for the record in question - * @return record type if the read succeeded, -1 if there was an error + * @param cf the capture file from which to read the packet + * @param fdata the frame_data structure for the packet in question + * @return TRUE if the read succeeded, FALSE if there was an error */ -int cf_read_frame(capture_file *cf, frame_data *fdata); +gboolean cf_read_frame(capture_file *cf, frame_data *fdata); /** * Read packets from the "end" of a capture file. diff --git a/frame_tvbuff.c b/frame_tvbuff.c index e9321926bb..b47d206f07 100644 --- a/frame_tvbuff.c +++ b/frame_tvbuff.c @@ -57,7 +57,7 @@ frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf) /* XXX, what if phdr->caplen isn't equal to * frame_tvb->tvb.length + frame_tvb->offset? */ - if (wtap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, &err, &err_info) == -1) { + if (!wtap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, &err, &err_info)) { switch (err) { case WTAP_ERR_UNSUPPORTED_ENCAP: case WTAP_ERR_BAD_FILE: diff --git a/proto_hier_stats.c b/proto_hier_stats.c index ae0ee50350..68eaaa1eac 100644 --- a/proto_hier_stats.c +++ b/proto_hier_stats.c @@ -147,7 +147,7 @@ process_frame(frame_data *frame, column_info *cinfo, ph_stats_t* ps) /* Load the frame from the capture file */ buffer_init(&buf, 1500); - if (cf_read_frame_r(&cfile, frame, &phdr, &buf) == -1) + if (!cf_read_frame_r(&cfile, frame, &phdr, &buf)) return FALSE; /* failure */ /* Dissect the frame tree not visible */ diff --git a/reordercap.c b/reordercap.c index df46d7c166..4b363b84b1 100644 --- a/reordercap.c +++ b/reordercap.c @@ -103,7 +103,7 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf, /* Re-read the first frame from the stored location */ - if (wtap_seek_read(wth, frame->offset, &phdr, buf, &err, &err_info) == -1) { + if (!wtap_seek_read(wth, frame->offset, &phdr, buf, &err, &err_info)) { if (err != 0) { /* Print a message noting that the read failed somewhere along the line. */ fprintf(stderr, @@ -176,7 +176,6 @@ int main(int argc, char *argv[]) { wtap *wth = NULL; wtap_dumper *pdh = NULL; - int rec_type; Buffer buf; int err; gchar *err_info; @@ -262,24 +261,22 @@ int main(int argc, char *argv[]) frames = g_ptr_array_new(); /* Read each frame from infile */ - while ((rec_type = wtap_read(wth, &err, &err_info, &data_offset)) != -1) { - if (rec_type == REC_TYPE_PACKET) { - FrameRecord_t *newFrameRecord; + while (wtap_read(wth, &err, &err_info, &data_offset)) { + FrameRecord_t *newFrameRecord; - phdr = wtap_phdr(wth); + phdr = wtap_phdr(wth); - newFrameRecord = g_slice_new(FrameRecord_t); - newFrameRecord->num = frames->len + 1; - newFrameRecord->offset = data_offset; - newFrameRecord->time = phdr->ts; + newFrameRecord = g_slice_new(FrameRecord_t); + newFrameRecord->num = frames->len + 1; + newFrameRecord->offset = data_offset; + newFrameRecord->time = phdr->ts; - if (prevFrame && frames_compare(&newFrameRecord, &prevFrame) < 0) { - wrong_order_count++; - } - - g_ptr_array_add(frames, newFrameRecord); - prevFrame = newFrameRecord; + if (prevFrame && frames_compare(&newFrameRecord, &prevFrame) < 0) { + wrong_order_count++; } + + g_ptr_array_add(frames, newFrameRecord); + prevFrame = newFrameRecord; } if (err != 0) { /* Print a message noting that the read failed somewhere along the line. */ diff --git a/tfshark.c b/tfshark.c index 6de68cd53c..e62350400f 100644 --- a/tfshark.c +++ b/tfshark.c @@ -1857,7 +1857,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) for (framenum = 1; err == 0 && framenum <= cf->count; framenum++) { fdata = frame_data_sequence_find(cf->frames, framenum); #if 0 - if (local_wtap_seek_read(cf->wth, fdata->file_off, + if (wtap_seek_read(cf->wth, fdata->file_off, &buf, fdata->cap_len, &err, &err_info)) { process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf, tap_flags); } diff --git a/tshark.c b/tshark.c index afbf6310ac..f52b00502f 100644 --- a/tshark.c +++ b/tshark.c @@ -2651,11 +2651,11 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file) } -/* capture child tells us we have new records to read */ +/* capture child tells us we have new packets to read */ void -capture_input_new_records(capture_session *cap_session, int to_read) +capture_input_new_packets(capture_session *cap_session, int to_read) { - int rec_type; + gboolean ret; int err; gchar *err_info; gint64 data_offset; @@ -2696,21 +2696,20 @@ capture_input_new_records(capture_session *cap_session, int to_read) while (to_read-- && cf->wth) { wtap_cleareof(cf->wth); - rec_type = wtap_read(cf->wth, &err, &err_info, &data_offset); - if (rec_type == -1) { + ret = wtap_read(cf->wth, &err, &err_info, &data_offset); + if (ret == FALSE) { /* read from file failed, tell the capture child to stop */ sync_pipe_stop(cap_session); wtap_close(cf->wth); cf->wth = NULL; } else { - if (rec_type == REC_TYPE_PACKET) { - if (process_packet(cf, edt, data_offset, wtap_phdr(cf->wth), + ret = process_packet(cf, edt, data_offset, wtap_phdr(cf->wth), wtap_buf_ptr(cf->wth), - tap_flags)) { - /* packet successfully read and gone through the "Read Filter" */ - packet_count++; - } - } + tap_flags); + } + if (ret != FALSE) { + /* packet successfully read and gone through the "Read Filter" */ + packet_count++; } } @@ -3063,11 +3062,9 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type, int snapshot_length; wtap_dumper *pdh; guint32 framenum; - int rec_type; int err; gchar *err_info = NULL; gint64 data_offset; - gboolean packet_count_reached = FALSE; char *save_file_string = NULL; gboolean filtering_tap_listeners; guint tap_flags; @@ -3194,19 +3191,17 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type, edt = epan_dissect_new(cf->epan, create_proto_tree, FALSE); } - while ((rec_type = wtap_read(cf->wth, &err, &err_info, &data_offset)) != -1) { - if (rec_type == REC_TYPE_PACKET) { - if (process_packet_first_pass(cf, edt, data_offset, wtap_phdr(cf->wth), - wtap_buf_ptr(cf->wth))) { - /* Stop reading if we have the maximum number of packets; - * When the -c option has not been used, max_packet_count - * starts at 0, which practically means, never stop reading. - * (unless we roll over max_packet_count ?) - */ - if ( (--max_packet_count == 0) || (max_byte_count != 0 && data_offset >= max_byte_count)) { - err = 0; /* This is not an error */ - break; - } + while (wtap_read(cf->wth, &err, &err_info, &data_offset)) { + if (process_packet_first_pass(cf, edt, data_offset, wtap_phdr(cf->wth), + wtap_buf_ptr(cf->wth))) { + /* Stop reading if we have the maximum number of packets; + * When the -c option has not been used, max_packet_count + * starts at 0, which practically means, never stop reading. + * (unless we roll over max_packet_count ?) + */ + if ( (--max_packet_count == 0) || (max_byte_count != 0 && data_offset >= max_byte_count)) { + err = 0; /* This is not an error */ + break; } } } @@ -3245,57 +3240,55 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type, for (framenum = 1; err == 0 && framenum <= cf->count; framenum++) { fdata = frame_data_sequence_find(cf->frames, framenum); - if ((rec_type = wtap_seek_read(cf->wth, fdata->file_off, &phdr, &buf, &err, - &err_info)) == -1) { - if (rec_type == REC_TYPE_PACKET) { - if (process_packet_second_pass(cf, edt, fdata, &phdr, &buf, - tap_flags)) { - /* Either there's no read filtering or this packet passed the - filter, so, if we're writing to a capture file, write - this packet out. */ - if (pdh != NULL) { - if (!wtap_dump(pdh, &phdr, buffer_start_ptr(&buf), &err)) { - /* Error writing to a capture file */ - switch (err) { + if (wtap_seek_read(cf->wth, fdata->file_off, &phdr, &buf, &err, + &err_info)) { + if (process_packet_second_pass(cf, edt, fdata, &phdr, &buf, + tap_flags)) { + /* Either there's no read filtering or this packet passed the + filter, so, if we're writing to a capture file, write + this packet out. */ + if (pdh != NULL) { + if (!wtap_dump(pdh, &phdr, buffer_start_ptr(&buf), &err)) { + /* Error writing to a capture file */ + switch (err) { - case WTAP_ERR_UNSUPPORTED_ENCAP: - /* - * This is a problem with the particular frame we're writing - * and the file type and subtype we're writing; note that, - * and report the frame number and file type/subtype. - * - * XXX - framenum is not necessarily the frame number in - * the input file if there was a read filter. - */ - fprintf(stderr, - "Frame %u of \"%s\" has a network type that can't be saved in a \"%s\" file.\n", - framenum, cf->filename, - wtap_file_type_subtype_short_string(out_file_type)); - break; + case WTAP_ERR_UNSUPPORTED_ENCAP: + /* + * This is a problem with the particular frame we're writing + * and the file type and subtype we're writing; note that, + * and report the frame number and file type/subtype. + * + * XXX - framenum is not necessarily the frame number in + * the input file if there was a read filter. + */ + fprintf(stderr, + "Frame %u of \"%s\" has a network type that can't be saved in a \"%s\" file.\n", + framenum, cf->filename, + wtap_file_type_subtype_short_string(out_file_type)); + break; - case WTAP_ERR_PACKET_TOO_LARGE: - /* - * This is a problem with the particular frame we're writing - * and the file type and subtype we're writing; note that, - * and report the frame number and file type/subtype. - * - * XXX - framenum is not necessarily the frame number in - * the input file if there was a read filter. - */ - fprintf(stderr, - "Frame %u of \"%s\" is too large for a \"%s\" file.\n", - framenum, cf->filename, - wtap_file_type_subtype_short_string(out_file_type)); - break; + case WTAP_ERR_PACKET_TOO_LARGE: + /* + * This is a problem with the particular frame we're writing + * and the file type and subtype we're writing; note that, + * and report the frame number and file type/subtype. + * + * XXX - framenum is not necessarily the frame number in + * the input file if there was a read filter. + */ + fprintf(stderr, + "Frame %u of \"%s\" is too large for a \"%s\" file.\n", + framenum, cf->filename, + wtap_file_type_subtype_short_string(out_file_type)); + break; - default: - show_capture_file_io_error(save_file, err, FALSE); - break; - } - wtap_dump_close(pdh, &err); - g_free(shb_hdr); - exit(2); + default: + show_capture_file_io_error(save_file, err, FALSE); + break; } + wtap_dump_close(pdh, &err); + g_free(shb_hdr); + exit(2); } } } @@ -3328,72 +3321,60 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type, edt = epan_dissect_new(cf->epan, create_proto_tree, print_packet_info && print_details); } - while ((rec_type = wtap_read(cf->wth, &err, &err_info, &data_offset)) != -1) { - if (rec_type == REC_TYPE_PACKET) { - framenum++; + while (wtap_read(cf->wth, &err, &err_info, &data_offset)) { + framenum++; - if (process_packet(cf, edt, data_offset, wtap_phdr(cf->wth), - wtap_buf_ptr(cf->wth), - tap_flags)) { - /* Either there's no read filtering or this packet passed the - filter, so, if we're writing to a capture file, write - this packet out. */ - if (pdh != NULL) { - if (!wtap_dump(pdh, wtap_phdr(cf->wth), wtap_buf_ptr(cf->wth), &err)) { - /* Error writing to a capture file */ - switch (err) { + if (process_packet(cf, edt, data_offset, wtap_phdr(cf->wth), + wtap_buf_ptr(cf->wth), + tap_flags)) { + /* Either there's no read filtering or this packet passed the + filter, so, if we're writing to a capture file, write + this packet out. */ + if (pdh != NULL) { + if (!wtap_dump(pdh, wtap_phdr(cf->wth), wtap_buf_ptr(cf->wth), &err)) { + /* Error writing to a capture file */ + switch (err) { - case WTAP_ERR_UNSUPPORTED_ENCAP: - /* - * This is a problem with the particular frame we're writing - * and the file type and subtype we're writing; note that, - * and report the frame number and file type/subtype. - */ - fprintf(stderr, - "Frame %u of \"%s\" has a network type that can't be saved in a \"%s\" file.\n", - framenum, cf->filename, - wtap_file_type_subtype_short_string(out_file_type)); - break; + case WTAP_ERR_UNSUPPORTED_ENCAP: + /* + * This is a problem with the particular frame we're writing + * and the file type and subtype we're writing; note that, + * and report the frame number and file type/subtype. + */ + fprintf(stderr, + "Frame %u of \"%s\" has a network type that can't be saved in a \"%s\" file.\n", + framenum, cf->filename, + wtap_file_type_subtype_short_string(out_file_type)); + break; - case WTAP_ERR_PACKET_TOO_LARGE: - /* - * This is a problem with the particular frame we're writing - * and the file type and subtype we're writing; note that, - * and report the frame number and file type/subtype. - */ - fprintf(stderr, - "Frame %u of \"%s\" is too large for a \"%s\" file.\n", - framenum, cf->filename, - wtap_file_type_subtype_short_string(out_file_type)); - break; + case WTAP_ERR_PACKET_TOO_LARGE: + /* + * This is a problem with the particular frame we're writing + * and the file type and subtype we're writing; note that, + * and report the frame number and file type/subtype. + */ + fprintf(stderr, + "Frame %u of \"%s\" is too large for a \"%s\" file.\n", + framenum, cf->filename, + wtap_file_type_subtype_short_string(out_file_type)); + break; - default: - show_capture_file_io_error(save_file, err, FALSE); - break; - } - wtap_dump_close(pdh, &err); - g_free(shb_hdr); - exit(2); + default: + show_capture_file_io_error(save_file, err, FALSE); + break; } + wtap_dump_close(pdh, &err); + g_free(shb_hdr); + exit(2); } } - - /* If we're supposed to stop after max_packet_count packets, - * count this packet. - * When the -c option has not been used, max_packet_count - * starts at 0. - */ - if (max_packet_count != 0) { - max_packet_count--; - if (max_packet_count == 0) - packet_count_reached = TRUE; - } } - - /* Stop reading if we have the maximum number of packets or the - * maximum file size. + /* Stop reading if we have the maximum number of packets; + * When the -c option has not been used, max_packet_count + * starts at 0, which practically means, never stop reading. + * (unless we roll over max_packet_count ?) */ - if ( packet_count_reached || (max_byte_count != 0 && data_offset >= max_byte_count)) { + if ( (--max_packet_count == 0) || (max_byte_count != 0 && data_offset >= max_byte_count)) { err = 0; /* This is not an error */ break; } diff --git a/ui/gtk/capture_file_dlg.c b/ui/gtk/capture_file_dlg.c index 74f35d6748..baef2baed9 100644 --- a/ui/gtk/capture_file_dlg.c +++ b/ui/gtk/capture_file_dlg.c @@ -173,7 +173,6 @@ preview_set_filename(GtkWidget *prev, const gchar *cf_name) static void preview_do(GtkWidget *prev, wtap *wth) { - int rec_type; GtkWidget *label; unsigned int elapsed_time; time_t time_preview; @@ -184,7 +183,6 @@ preview_do(GtkWidget *prev, wtap *wth) double start_time = 0; /* seconds, with nsec resolution */ double stop_time = 0; /* seconds, with nsec resolution */ double cur_time; - unsigned int records = 0; unsigned int packets = 0; gboolean is_breaked = FALSE; gchar string_buff[PREVIEW_STR_MAX]; @@ -194,25 +192,22 @@ preview_do(GtkWidget *prev, wtap *wth) time(&time_preview); - while ( (rec_type = wtap_read(wth, &err, &err_info, &data_offset)) != -1 ) { - if (rec_type == REC_TYPE_PACKET) { - phdr = wtap_phdr(wth); - cur_time = nstime_to_sec(&phdr->ts); - if (packets == 0) { - start_time = cur_time; - stop_time = cur_time; - } - if (cur_time < start_time) { - start_time = cur_time; - } - if (cur_time > stop_time) { - stop_time = cur_time; - } - - packets++; + while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) { + phdr = wtap_phdr(wth); + cur_time = nstime_to_sec(&phdr->ts); + if (packets == 0) { + start_time = cur_time; + stop_time = cur_time; } - records++; - if (records%1000 == 0) { + if (cur_time < start_time) { + start_time = cur_time; + } + if (cur_time > stop_time) { + stop_time = cur_time; + } + + packets++; + if (packets%1000 == 0) { /* do we have a timeout? */ time(&time_current); if (time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) { diff --git a/ui/gtk/iax2_analysis.c b/ui/gtk/iax2_analysis.c index d756b3a58b..6f7fe77c73 100644 --- a/ui/gtk/iax2_analysis.c +++ b/ui/gtk/iax2_analysis.c @@ -3711,7 +3711,7 @@ void iax2_analysis_cb(GtkAction *action _U_, gpointer user_data _U_) return; /* if we exit here it's an error */ /* dissect the current frame */ - if (cf_read_frame(cf, fdata) == -1) + if (!cf_read_frame(cf, fdata)) return; /* error reading the frame */ epan_dissect_init(&edt, cf->epan, TRUE, FALSE); epan_dissect_prime_dfilter(&edt, sfcode); diff --git a/ui/gtk/main.c b/ui/gtk/main.c index a3140b18e1..e49e0531a0 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -543,7 +543,7 @@ get_ip_address_list_from_packet_list_row(gpointer data) if (fdata != NULL) { epan_dissect_t edt; - if (cf_read_frame (&cfile, fdata) == -1) + if (!cf_read_frame (&cfile, fdata)) return NULL; /* error reading the frame */ epan_dissect_init(&edt, cfile.epan, FALSE, FALSE); @@ -584,7 +584,7 @@ get_filter_from_packet_list_row_and_column(gpointer data) if (fdata != NULL) { epan_dissect_t edt; - if (cf_read_frame(&cfile, fdata) == -1) + if (!cf_read_frame(&cfile, fdata)) return NULL; /* error reading the frame */ /* proto tree, visible. We need a proto tree if there's custom columns */ epan_dissect_init(&edt, cfile.epan, have_custom_cols(&cfile.cinfo), FALSE); diff --git a/ui/gtk/packet_list_store.c b/ui/gtk/packet_list_store.c index efb8e44ea1..dd904b58be 100644 --- a/ui/gtk/packet_list_store.c +++ b/ui/gtk/packet_list_store.c @@ -1117,7 +1117,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord * cinfo = NULL; buffer_init(&buf, 1500); - if (cf_read_frame_r(&cfile, fdata, &phdr, &buf) == -1) { + if (!cf_read_frame_r(&cfile, fdata, &phdr, &buf)) { /* * Error reading the frame. * diff --git a/ui/gtk/packet_win.c b/ui/gtk/packet_win.c index 67fb5fddd2..c25d62b48a 100644 --- a/ui/gtk/packet_win.c +++ b/ui/gtk/packet_win.c @@ -961,7 +961,7 @@ void new_packet_window(GtkWidget *w _U_, gboolean reference, gboolean editable _ } /* With the new packetlists "lazy columns" it's necessary to reread the frame */ - if (cf_read_frame(&cfile, fd) == -1) { + if (!cf_read_frame(&cfile, fd)) { /* error reading the frame */ return; } diff --git a/ui/gtk/rlc_lte_graph.c b/ui/gtk/rlc_lte_graph.c index eb9e2635f1..aeb5b9996b 100644 --- a/ui/gtk/rlc_lte_graph.c +++ b/ui/gtk/rlc_lte_graph.c @@ -903,7 +903,7 @@ static rlc_lte_tap_info *select_rlc_lte_session(capture_file *cf, struct segment } /* dissect the current frame */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { return NULL; /* error reading the frame */ } diff --git a/ui/gtk/rtp_analysis.c b/ui/gtk/rtp_analysis.c index 66c2406658..0305b0a26a 100644 --- a/ui/gtk/rtp_analysis.c +++ b/ui/gtk/rtp_analysis.c @@ -3946,7 +3946,7 @@ rtp_analysis_cb(GtkAction *action _U_, gpointer user_data _U_) return; /* if we exit here it's an error */ /* dissect the current frame */ - if (cf_read_frame(cf, fdata) == -1) + if (!cf_read_frame(cf, fdata)) return; /* error reading the frame */ epan_dissect_init(&edt, cf->epan, TRUE, FALSE); epan_dissect_prime_dfilter(&edt, sfcode); diff --git a/ui/gtk/sctp_assoc_analyse.c b/ui/gtk/sctp_assoc_analyse.c index 927be97b0e..2b751f7135 100644 --- a/ui/gtk/sctp_assoc_analyse.c +++ b/ui/gtk/sctp_assoc_analyse.c @@ -975,7 +975,7 @@ sctp_analyse_cb(struct sctp_analyse *u_data, gboolean ext) return; /* if we exit here it's an error */ /* dissect the current frame */ - if (cf_read_frame(cf, fdata) == -1) + if (!cf_read_frame(cf, fdata)) return; /* error reading the frame */ epan_dissect_init(&edt, cf->epan, TRUE, FALSE); diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp index 3e123dc34b..03d4892411 100644 --- a/ui/qt/capture_file_dialog.cpp +++ b/ui/qt/capture_file_dialog.cpp @@ -736,13 +736,11 @@ void CaptureFileDialog::preview(const QString & path) wtap *wth; int err = 0; gchar *err_info; - int rec_type; gint64 data_offset; const struct wtap_pkthdr *phdr; double start_time = 0; /* seconds, with nsec resolution */ double stop_time = 0; /* seconds, with nsec resolution */ double cur_time; - unsigned int records = 0; unsigned int packets = 0; bool timed_out = FALSE; time_t time_preview; @@ -794,25 +792,22 @@ void CaptureFileDialog::preview(const QString & path) preview_size_.setText(QString(tr("%1 bytes")).arg(wtap_file_size(wth, &err))); time(&time_preview); - while ( (rec_type = wtap_read(wth, &err, &err_info, &data_offset)) != -1 ) { - if (rec_type == REC_TYPE_PACKET) { - phdr = wtap_phdr(wth); - cur_time = nstime_to_sec(&phdr->ts); - if(packets == 0) { - start_time = cur_time; - stop_time = cur_time; - } - if (cur_time < start_time) { - start_time = cur_time; - } - if (cur_time > stop_time){ - stop_time = cur_time; - } - - packets++; + while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) { + phdr = wtap_phdr(wth); + cur_time = nstime_to_sec(&phdr->ts); + if(packets == 0) { + start_time = cur_time; + stop_time = cur_time; } - records++; - if(records%1000 == 0) { + if (cur_time < start_time) { + start_time = cur_time; + } + if (cur_time > stop_time){ + stop_time = cur_time; + } + + packets++; + if(packets%1000 == 0) { /* do we have a timeout? */ time(&time_current); if(time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) { diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 2388c6b380..7e9ff94132 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -655,7 +655,7 @@ QString &PacketList::getFilterFromRowAndColumn() if (fdata != NULL) { epan_dissect_t edt; - if (cf_read_frame(cap_file_, fdata) == -1) + if (!cf_read_frame(cap_file_, fdata)) return filter; /* error reading the frame */ /* proto tree, visible. We need a proto tree if there's custom columns */ epan_dissect_init(&edt, cap_file_->epan, have_custom_cols(&cap_file_->cinfo), FALSE); diff --git a/ui/qt/packet_list_model.cpp b/ui/qt/packet_list_model.cpp index 805da14c8f..a6b68f51bd 100644 --- a/ui/qt/packet_list_model.cpp +++ b/ui/qt/packet_list_model.cpp @@ -221,7 +221,7 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const memset(&phdr, 0, sizeof(struct wtap_pkthdr)); buffer_init(&buf, 1500); - if (!cap_file_ || cf_read_frame_r(cap_file_, fdata, &phdr, &buf) == -1) { + if (!cap_file_ || !cf_read_frame_r(cap_file_, fdata, &phdr, &buf)) { /* * Error reading the frame. * diff --git a/ui/tap-tcp-stream.c b/ui/tap-tcp-stream.c index 8ba41c22cc..9dd1e46381 100644 --- a/ui/tap-tcp-stream.c +++ b/ui/tap-tcp-stream.c @@ -305,7 +305,7 @@ select_tcpip_session(capture_file *cf, struct segment *hdrs) } /* dissect the current frame */ - if (cf_read_frame(cf, fdata) == -1) + if (!cf_read_frame(cf, fdata)) return NULL; /* error reading the frame */ diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index 47cf06cd4c..a65aaf4d0f 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -1119,10 +1119,8 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) { int err = 0; gchar *err_info; TCHAR string_buff[PREVIEW_STR_MAX]; - int rec_type; gint64 data_offset; - guint records = 0; - guint packets = 0; + guint packet = 0; gint64 filesize; time_t ti_time; struct tm *ti_tm; @@ -1188,24 +1186,21 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) { SetWindowText(cur_ctrl, string_buff); time(&time_preview); - while ( (rec_type = wtap_read(wth, &err, &err_info, &data_offset)) != -1 ) { - if (rec_type == REC_TYPE_PACKET) { - phdr = wtap_phdr(wth); - cur_time = nstime_to_sec( (const nstime_t *) &phdr->ts ); - if(packets == 0) { - start_time = cur_time; - stop_time = cur_time; - } - if (cur_time < start_time) { - start_time = cur_time; - } - if (cur_time > stop_time){ - stop_time = cur_time; - } - packets++; + while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) { + phdr = wtap_phdr(wth); + cur_time = nstime_to_sec( (const nstime_t *) &phdr->ts ); + if(packet == 0) { + start_time = cur_time; + stop_time = cur_time; } - records++; - if(records%100 == 0) { + if (cur_time < start_time) { + start_time = cur_time; + } + if (cur_time > stop_time){ + stop_time = cur_time; + } + packet++; + if(packet%100 == 0) { time(&time_current); if(time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) { is_breaked = TRUE; @@ -1215,7 +1210,7 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) { } if(err != 0) { - StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("error after reading %u packets"), packets); + StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("error after reading %u packets"), packet); cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_PACKETS); SetWindowText(cur_ctrl, string_buff); wtap_close(wth); @@ -1224,9 +1219,9 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) { /* Packets */ if(is_breaked) { - StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("more than %u packets (preview timeout)"), packets); + StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("more than %u packets (preview timeout)"), packet); } else { - StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%u"), packets); + StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%u"), packet); } cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_PACKETS); SetWindowText(cur_ctrl, string_buff); diff --git a/wiretap/5views.c b/wiretap/5views.c index fed60d05ec..db377b1570 100644 --- a/wiretap/5views.c +++ b/wiretap/5views.c @@ -99,9 +99,9 @@ typedef struct #define CST_5VW_CAPTURES_RECORD (CST_5VW_SECTION_CAPTURES << 28) /* 0x80000000 */ #define CST_5VW_SYSTEM_RECORD 0x00000000U -static int _5views_read(wtap *wth, int *err, gchar **err_info, +static gboolean _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int _5views_seek_read(wtap *wth, gint64 seek_off, +static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, struct wtap_pkthdr *phdr, int *err, gchar **err_info); @@ -191,7 +191,7 @@ int _5views_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static int +static gboolean _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { t_5VW_TimeStamped_Header TimeStamped_Header; @@ -207,7 +207,7 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* Read record header. */ if (!_5views_read_header(wth, wth->fh, &TimeStamped_Header, &wth->phdr, err, err_info)) - return -1; + return FALSE; if (TimeStamped_Header.RecSubType == CST_5VW_FRAME_RECORD) { /* @@ -220,7 +220,7 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * Not a packet - skip to the next record. */ if (file_seek(wth->fh, TimeStamped_Header.RecSize, SEEK_CUR, err) == -1) - return -1; + return FALSE; } while (1); if (wth->phdr.caplen > WTAP_MAX_PACKET_SIZE) { @@ -231,13 +231,11 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("5views: File has %u-byte packet, bigger than maximum of %u", wth->phdr.caplen, WTAP_MAX_PACKET_SIZE); - return -1; + return FALSE; } - if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, - wth->phdr.caplen, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, + wth->phdr.caplen, err, err_info); } static gboolean @@ -247,7 +245,7 @@ _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, t_5VW_TimeStamped_Header TimeStamped_Header; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* * Read the header. @@ -256,16 +254,14 @@ _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, phdr, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } /* * Read the packet data. */ - if (!wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, - err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, + err, err_info); } /* Read the header of the next packet. Return TRUE on success, FALSE diff --git a/wiretap/aethra.c b/wiretap/aethra.c index bab0091fb0..a0b783b349 100644 --- a/wiretap/aethra.c +++ b/wiretap/aethra.c @@ -112,9 +112,9 @@ typedef struct { time_t start; } aethra_t; -static int aethra_read(wtap *wth, int *err, gchar **err_info, +static gboolean aethra_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int aethra_seek_read(wtap *wth, gint64 seek_off, +static gboolean aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr, struct wtap_pkthdr *phdr, int *err, gchar **err_info); @@ -182,7 +182,7 @@ static guint packet = 0; #endif /* Read the next packet */ -static int aethra_read(wtap *wth, int *err, gchar **err_info, +static gboolean aethra_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { struct aethrarec_hdr hdr; @@ -196,7 +196,7 @@ static int aethra_read(wtap *wth, int *err, gchar **err_info, /* Read record header. */ if (!aethra_read_rec_header(wth, wth->fh, &hdr, &wth->phdr, err, err_info)) - return -1; + return FALSE; /* * XXX - if this is big, we might waste memory by @@ -205,7 +205,7 @@ static int aethra_read(wtap *wth, int *err, gchar **err_info, if (wth->phdr.caplen != 0) { if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen, err, err_info)) - return -1; /* Read error */ + return FALSE; /* Read error */ } #if 0 packet++; @@ -270,32 +270,32 @@ packet, hdr.rec_type, wth->phdr.caplen, hdr.flags); } found: - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean aethra_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { struct aethrarec_hdr hdr; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (!aethra_read_rec_header(wth, wth->random_fh, &hdr, phdr, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } /* * Read the packet data. */ if (!wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, err, err_info)) - return -1; /* failed */ + return FALSE; /* failed */ - return REC_TYPE_PACKET; + return TRUE; } static gboolean diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c index 58ea2fbea6..32d4d49418 100644 --- a/wiretap/ascendtext.c +++ b/wiretap/ascendtext.c @@ -74,9 +74,9 @@ static const ascend_magic_string ascend_magic[] = { { ASCEND_PFX_ETHER, "ETHER" }, }; -static int ascend_read(wtap *wth, int *err, gchar **err_info, +static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int ascend_seek_read(wtap *wth, gint64 seek_off, +static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); @@ -237,36 +237,36 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, packet's header because we might mistake part of it for a new header. */ if (file_seek(wth->fh, ascend->next_packet_seek_start, SEEK_SET, err) == -1) - return -1; + return FALSE; offset = ascend_seek(wth, err, err_info); if (offset == -1) - return -1; + return FALSE; if (parse_ascend(ascend, wth->fh, &wth->phdr, wth->frame_buffer, wth->snapshot_length) != PARSED_RECORD) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error"); - return -1; + return FALSE; } *data_offset = offset; - return REC_TYPE_PACKET; + return TRUE; } -static int ascend_seek_read(wtap *wth, gint64 seek_off, +static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { ascend_t *ascend = (ascend_t *)wth->priv; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (parse_ascend(ascend, wth->random_fh, phdr, buf, wth->snapshot_length) != PARSED_RECORD) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error"); - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } diff --git a/wiretap/ber.c b/wiretap/ber.c index 1a3f4e6bf6..59e7e28f39 100644 --- a/wiretap/ber.c +++ b/wiretap/ber.c @@ -38,14 +38,14 @@ #define BER_UNI_TAG_SEQ 16 /* SEQUENCE, SEQUENCE OF */ #define BER_UNI_TAG_SET 17 /* SET, SET OF */ -static int ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, - Buffer *buf, int *err, gchar **err_info) +static gboolean ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, + Buffer *buf, int *err, gchar **err_info) { gint64 file_size; int packet_size; if ((file_size = wtap_file_size(wth, err)) == -1) - return -1; + return FALSE; if (file_size > WTAP_MAX_PACKET_SIZE) { /* @@ -55,7 +55,7 @@ static int ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("ber: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u", file_size, WTAP_MAX_PACKET_SIZE); - return -1; + return FALSE; } packet_size = (int)file_size; @@ -67,12 +67,10 @@ static int ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, phdr->ts.secs = 0; phdr->ts.nsecs = 0; - if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static int ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -82,24 +80,24 @@ static int ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* there is only ever one packet */ if (offset != 0) - return -1; + return FALSE; *data_offset = offset; return ber_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); } -static int ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr _U_, - Buffer *buf, int *err, gchar **err_info) +static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr _U_, + Buffer *buf, int *err, gchar **err_info) { /* there is only one packet */ if(seek_off > 0) { *err = 0; - return -1; + return FALSE; } if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; return ber_read_file(wth, wth->random_fh, phdr, buf, err, err_info); } diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c index c1e5a9881e..b7c0b4c5c5 100644 --- a/wiretap/btsnoop.c +++ b/wiretap/btsnoop.c @@ -73,11 +73,11 @@ struct btsnooprec_hdr { static const gint64 KUnixTimeBase = G_GINT64_CONSTANT(0x00dcddb30f2f8000); /* offset from symbian - unix time */ -static int btsnoop_read(wtap *wth, int *err, gchar **err_info, +static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int btsnoop_seek_read(wtap *wth, gint64 seek_off, +static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static int btsnoop_read_record(wtap *wth, FILE_T fh, +static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); int btsnoop_open(wtap *wth, int *err, gchar **err_info) @@ -160,7 +160,7 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info) return 1; } -static int btsnoop_read(wtap *wth, int *err, gchar **err_info, +static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -169,16 +169,16 @@ static int btsnoop_read(wtap *wth, int *err, gchar **err_info, err, err_info); } -static int btsnoop_seek_read(wtap *wth, gint64 seek_off, +static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; return btsnoop_read_record(wth, wth->random_fh, phdr, buf, err, err_info); } -static int btsnoop_read_record(wtap *wth, FILE_T fh, +static gboolean btsnoop_read_record(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { int bytes_read; @@ -196,7 +196,7 @@ static int btsnoop_read_record(wtap *wth, FILE_T fh, *err = file_error(fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } packet_size = g_ntohl(hdr.incl_len); @@ -210,7 +210,7 @@ static int btsnoop_read_record(wtap *wth, FILE_T fh, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("btsnoop: File has %u-byte packet, bigger than maximum of %u", packet_size, WTAP_MAX_PACKET_SIZE); - return -1; + return FALSE; } ts = GINT64_FROM_BE(hdr.ts_usec); @@ -248,9 +248,7 @@ static int btsnoop_read_record(wtap *wth, FILE_T fh, /* Read packet data. */ - if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info); } /* Returns 0 if we could write the specified encapsulation type, diff --git a/wiretap/camins.c b/wiretap/camins.c index d49cf96b80..ccc618498a 100644 --- a/wiretap/camins.c +++ b/wiretap/camins.c @@ -256,7 +256,7 @@ create_pseudo_hdr(guint8 *buf, guint8 dat_trans_type, guint16 dat_len) } -static int +static gboolean camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { @@ -266,7 +266,7 @@ camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, gint offset, bytes_read; if (!find_next_pkt_dat_type_len(fh, &dat_trans_type, &dat_len, err, err_info)) - return -1; + return FALSE; buffer_assure_space(buf, DVB_CI_PSEUDO_HDR_LEN+dat_len); p = buffer_start_ptr(buf); @@ -276,7 +276,7 @@ camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, /* shouldn't happen, all invalid packets must be detected by find_next_pkt_dat_type_len() */ *err = WTAP_ERR_INTERNAL; - return -1; + return FALSE; } bytes_read = read_packet_data(fh, dat_trans_type, @@ -284,7 +284,7 @@ camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, /* 0<=bytes_read<=dat_len is very likely a corrupted packet we let the dissector handle this */ if (bytes_read < 0) - return -1; + return FALSE; offset += bytes_read; phdr->pkt_encap = WTAP_ENCAP_DVBCI; @@ -292,11 +292,11 @@ camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, phdr->caplen = offset; phdr->len = offset; - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -306,12 +306,12 @@ camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) } -static int +static gboolean camins_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *pkthdr, Buffer *buf, int *err, gchar **err_info) { if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err)) - return -1; + return FALSE; return camins_read_packet(wth->random_fh, pkthdr, buf, err, err_info); } diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c index aece8e75fd..8b29a23880 100644 --- a/wiretap/catapult_dct2000.c +++ b/wiretap/catapult_dct2000.c @@ -103,12 +103,12 @@ static const gchar catapult_dct2000_magic[] = "Session Transcript"; /************************************************************/ /* Functions called from wiretap core */ -static int catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); -static int catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, - Buffer *buf, int *err, - gchar **err_info); +static gboolean catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); +static gboolean catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, + Buffer *buf, int *err, + gchar **err_info); static void catapult_dct2000_close(wtap *wth); static gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, @@ -331,9 +331,9 @@ static void write_timestamp_string(char *timestamp_string, int secs, int tenthou /**************************************************/ /* Read packet function. */ /* Look for and read the next usable packet */ -/* - return REC_TYPE_PACKET and details if found */ +/* - return TRUE and details if found */ /**************************************************/ -static int +static gboolean catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { @@ -370,7 +370,7 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, if (!read_new_line(wth->fh, &offset, &line_length, linebuff, sizeof linebuff, err, err_info)) { if (*err != 0) - return -1; /* error */ + return FALSE; /* error */ /* No more lines can be read, so quit. */ break; } @@ -434,19 +434,19 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info, g_hash_table_insert(file_externals->packet_prefix_table, pkey, line_prefix_info); /* OK, we have packet details to return */ - return REC_TYPE_PACKET; + return TRUE; } } /* No packet details to return... */ - return -1; + return FALSE; } /**************************************************/ /* Read & seek function. */ /**************************************************/ -static int +static gboolean catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) @@ -476,13 +476,13 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, /* Seek to beginning of packet */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return -1; + return FALSE; } /* Re-read whole line (this really should succeed) */ if (!read_new_line(wth->random_fh, &offset, &length, linebuff, sizeof linebuff, err, err_info)) { - return -1; + return FALSE; } /* Try to parse this line again (should succeed as re-reading...) */ @@ -508,7 +508,7 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, is_comment, data_chars); *err = errno = 0; - return REC_TYPE_PACKET; + return TRUE; } /* If get here, must have failed */ @@ -516,7 +516,7 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off, *err_info = g_strdup_printf("catapult dct2000: seek_read failed to read/parse " "line at position %" G_GINT64_MODIFIER "d", seek_off); - return -1; + return FALSE; } diff --git a/wiretap/commview.c b/wiretap/commview.c index fa7660bbff..e2a868a6b2 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -78,11 +78,11 @@ typedef struct commview_header { #define MEDIUM_WIFI 1 #define MEDIUM_TOKEN_RING 2 -static int commview_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); -static int commview_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, - Buffer *buf, int *err, gchar **err_info); +static gboolean commview_read(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); +static gboolean commview_seek_read(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, + Buffer *buf, int *err, gchar **err_info); static gboolean commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err, gchar **err_info); static gboolean commview_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, @@ -136,7 +136,7 @@ commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, struct tm tm; if(!commview_read_header(&cv_hdr, fh, err, err_info)) - return -1; + return FALSE; switch(cv_hdr.flags & FLAGS_MEDIUM) { @@ -162,7 +162,7 @@ commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("commview: unsupported encap: %u", cv_hdr.flags & FLAGS_MEDIUM); - return -1; + return FALSE; } tm.tm_year = cv_hdr.year - 1900; @@ -181,12 +181,10 @@ commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, phdr->ts.secs = mktime(&tm); phdr->ts.nsecs = cv_hdr.usecs * 1000; - if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info); } -static int +static gboolean commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -195,12 +193,12 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) err_info); } -static int +static gboolean commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; return commview_read_packet(wth->random_fh, phdr, buf, err, err_info); } diff --git a/wiretap/cosine.c b/wiretap/cosine.c index 18b2065287..d937018796 100644 --- a/wiretap/cosine.c +++ b/wiretap/cosine.c @@ -166,13 +166,13 @@ static gboolean empty_line(const gchar *line); static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info, char *hdr); static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info); -static int cosine_read(wtap *wth, int *err, gchar **err_info, +static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int cosine_seek_read(wtap *wth, gint64 seek_off, +static gboolean cosine_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line, int *err, gchar **err_info); -static int parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr, int pkt_len, Buffer* buf, int *err, gchar **err_info); static int parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset); @@ -286,7 +286,7 @@ int cosine_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static int cosine_read(wtap *wth, int *err, gchar **err_info, +static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -296,13 +296,13 @@ static int cosine_read(wtap *wth, int *err, gchar **err_info, /* Find the next packet */ offset = cosine_seek_next_packet(wth, err, err_info, line); if (offset < 0) - return -1; + return FALSE; *data_offset = offset; /* Parse the header */ pkt_len = parse_cosine_rec_hdr(&wth->phdr, line, err, err_info); if (pkt_len == -1) - return -1; + return FALSE; /* Convert the ASCII hex dump to binary data */ return parse_cosine_hex_dump(wth->fh, &wth->phdr, pkt_len, @@ -310,7 +310,7 @@ static int cosine_read(wtap *wth, int *err, gchar **err_info, } /* Used to read packets in random-access fashion */ -static int +static gboolean cosine_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { @@ -435,9 +435,9 @@ parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line, return pkt_len; } -/* Converts ASCII hex dump to binary data. Returns REC_TYPE_PACKET on success, - -1 if any error is encountered. */ -static int +/* Converts ASCII hex dump to binary data. Returns TRUE on success, + FALSE if any error is encountered. */ +static gboolean parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr, int pkt_len, Buffer* buf, int *err, gchar **err_info) { @@ -459,7 +459,7 @@ parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr, int pkt_len, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } if (empty_line(line)) { break; @@ -467,12 +467,12 @@ parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr, int pkt_len, if ((n = parse_single_hex_dump_line(line, pd, i*16)) == -1) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("cosine: hex dump line doesn't have 16 numbers"); - return -1; + return FALSE; } caplen += n; } phdr->caplen = caplen; - return REC_TYPE_PACKET; + return TRUE; } diff --git a/wiretap/csids.c b/wiretap/csids.c index 7145b62749..bc640f639d 100644 --- a/wiretap/csids.c +++ b/wiretap/csids.c @@ -44,9 +44,9 @@ typedef struct { gboolean byteswapped; } csids_t; -static int csids_read(wtap *wth, int *err, gchar **err_info, +static gboolean csids_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int csids_seek_read(wtap *wth, gint64 seek_off, +static gboolean csids_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean csids_read_packet(FILE_T fh, csids_t *csids, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); @@ -144,21 +144,19 @@ int csids_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static int csids_read(wtap *wth, int *err, gchar **err_info, +static gboolean csids_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { csids_t *csids = (csids_t *)wth->priv; *data_offset = file_tell(wth->fh); - if (!csids_read_packet( wth->fh, csids, &wth->phdr, wth->frame_buffer, - err, err_info )) - return -1; - return REC_TYPE_PACKET; + return csids_read_packet( wth->fh, csids, &wth->phdr, wth->frame_buffer, + err, err_info ); } /* Used to read packets in random-access fashion */ -static int +static gboolean csids_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, @@ -169,14 +167,14 @@ csids_seek_read(wtap *wth, csids_t *csids = (csids_t *)wth->priv; if( file_seek( wth->random_fh, seek_off, SEEK_SET, err ) == -1 ) - return -1; + return FALSE; if( !csids_read_packet( wth->random_fh, csids, phdr, buf, err, err_info ) ) { if( *err == 0 ) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static gboolean diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c index bb25611fd8..23785548d2 100644 --- a/wiretap/daintree-sna.c +++ b/wiretap/daintree-sna.c @@ -77,16 +77,16 @@ static const char daintree_magic_text[] = #define COMMENT_LINE daintree_magic_text[0] -static int daintree_sna_read(wtap *wth, int *err, gchar **err_info, +static gboolean daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int daintree_sna_seek_read(wtap *wth, gint64 seek_off, +static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean daintree_sna_scan_header(struct wtap_pkthdr *phdr, char *readLine, char *readData, int *err, gchar **err_info); -static int daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, +static gboolean daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, Buffer *buf, char *readData, int *err, gchar **err_info); /* Open a file and determine if it's a Daintree file */ @@ -134,7 +134,7 @@ int daintree_sna_open(wtap *wth, int *err, gchar **err_info) /* Read the capture file sequentially * Wireshark scans the file with sequential reads during preview and initial display. */ -static int +static gboolean daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { char readLine[DAINTREE_MAX_LINE_SIZE]; @@ -147,14 +147,14 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) do { if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh) == NULL) { *err = file_error(wth->fh, err_info); - return -1; /* all done */ + return FALSE; /* all done */ } } while (readLine[0] == COMMENT_LINE); /* parse one line of capture data */ if (!daintree_sna_scan_header(&wth->phdr, readLine, readData, err, err_info)) - return -1; + return FALSE; /* process packet data */ return daintree_sna_process_hex_data(&wth->phdr, wth->frame_buffer, @@ -163,7 +163,7 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* Read the capture file randomly * Wireshark opens the capture file for random access when displaying user-selected packets */ -static int +static gboolean daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { @@ -171,20 +171,20 @@ daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, char readData[READDATA_BUF_SIZE]; if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* It appears only file header lines start with '#', but * if we find any others, we toss them */ do { if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->random_fh) == NULL) { *err = file_error(wth->random_fh, err_info); - return -1; /* all done */ + return FALSE; /* all done */ } } while (readLine[0] == COMMENT_LINE); /* parse one line of capture data */ if (!daintree_sna_scan_header(phdr, readLine, readData, err, err_info)) - return -1; + return FALSE; /* process packet data */ return daintree_sna_process_hex_data(phdr, buf, readData, err, @@ -226,7 +226,7 @@ daintree_sna_scan_header(struct wtap_pkthdr *phdr, char *readLine, /* Convert packet data from ASCII hex string to binary in place, * sanity-check its length against what we assume is the packet length field, * and copy it into a Buffer */ -static int +static gboolean daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, Buffer *buf, char *readData, int *err, gchar **err_info) { @@ -242,7 +242,7 @@ daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, Buffer *buf, if (!isxdigit((guchar)*str)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("daintree_sna: non-hex digit in hex data"); - return -1; + return FALSE; } if(isdigit((guchar)*str)) { *p = (*str - '0') << 4; @@ -255,7 +255,7 @@ daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, Buffer *buf, if (!isxdigit((guchar)*str)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("daintree_sna: non-hex digit in hex data"); - return -1; + return FALSE; } if(isdigit((guchar)*str)) { *p += *str - '0'; @@ -274,19 +274,19 @@ daintree_sna_process_hex_data(struct wtap_pkthdr *phdr, Buffer *buf, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("daintree_sna: Only %u bytes of packet data", bytes); - return -1; + return FALSE; } bytes -= FCS_LENGTH; if (bytes > phdr->len) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("daintree_sna: capture length (%u) > packet length (%u)", bytes, phdr->len); - return -1; + return FALSE; } phdr->caplen = bytes; buffer_assure_space(buf, bytes); memcpy(buffer_start_ptr(buf), readData, bytes); - return REC_TYPE_PACKET; + return TRUE; } diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c index 31fa9af630..0a3e9f57e1 100644 --- a/wiretap/dbs-etherwatch.c +++ b/wiretap/dbs-etherwatch.c @@ -84,11 +84,11 @@ static const char dbs_etherwatch_rec_magic[] = */ #define DBS_ETHERWATCH_MAX_PACKET_LEN 16384 -static int dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, +static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off, +static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static int parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, +static gboolean parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, int *err, gchar **err_info); static guint parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset); @@ -196,7 +196,7 @@ int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static int dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, +static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -204,7 +204,7 @@ static int dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, /* Find the next packet */ offset = dbs_etherwatch_seek_next_packet(wth, err, err_info); if (offset < 1) - return -1; + return FALSE; *data_offset = offset; /* Parse the packet */ @@ -213,12 +213,12 @@ static int dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info, } /* Used to read packets in random-access fashion */ -static int +static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) - return -1; + return FALSE; return parse_dbs_etherwatch_packet(phdr, wth->random_fh, buf, err, err_info); @@ -268,7 +268,7 @@ unnumbered. Unnumbered has length 1, numbered 2. */ #define CTL_UNNUMB_MASK 0x03 #define CTL_UNNUMB_VALUE 0x03 -static int +static gboolean parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, int *err, gchar **err_info) { @@ -298,7 +298,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } /* Get the destination address */ @@ -306,14 +306,14 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, if(!p) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: destination address not found"); - return -1; + return FALSE; } p += strlen(DEST_MAC_PREFIX); if(parse_hex_dump(p, &pd[eth_hdr_len], HEX_HDR_SPR, HEX_HDR_END) != MAC_ADDR_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: destination address not valid"); - return -1; + return FALSE; } eth_hdr_len += MAC_ADDR_LENGTH; @@ -331,7 +331,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, HEX_HDR_END) != MAC_ADDR_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: source address not valid"); - return -1; + return FALSE; } eth_hdr_len += MAC_ADDR_LENGTH; @@ -341,14 +341,14 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } /* Check the lines is as least as long as the length position */ if(strlen(line) < LENGTH_POS) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: line too short"); - return -1; + return FALSE; } num_items_scanned = sscanf(line + LENGTH_POS, @@ -361,7 +361,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, if (num_items_scanned != 8) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: header line not valid"); - return -1; + return FALSE; } /* Determine whether it is Ethernet II or IEEE 802 */ @@ -373,7 +373,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, HEX_HDR_END) != PROTOCOL_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: Ethernet II protocol value not valid"); - return -1; + return FALSE; } eth_hdr_len += PROTOCOL_LENGTH; } else { @@ -389,7 +389,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, HEX_HDR_END) != SAP_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: 802.2 DSAP+SSAP value not valid"); - return -1; + return FALSE; } eth_hdr_len += SAP_LENGTH; /* Get the (first part of the) control field */ @@ -397,7 +397,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, HEX_HDR_END) != CTL_UNNUMB_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: 802.2 control field first part not valid"); - return -1; + return FALSE; } /* Determine whether the control is numbered, and thus longer */ if((pd[eth_hdr_len] & CTL_UNNUMB_MASK) != CTL_UNNUMB_VALUE) { @@ -407,7 +407,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, HEX_HDR_SPR) != CTL_NUMB_LENGTH - CTL_UNNUMB_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: 802.2 control field second part value not valid"); - return -1; + return FALSE; } eth_hdr_len += CTL_NUMB_LENGTH; } else { @@ -421,7 +421,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, HEX_PID_END) != PID_LENGTH) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: 802.2 PID value not valid"); - return -1; + return FALSE; } eth_hdr_len += PID_LENGTH; } @@ -457,22 +457,22 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } if (!(line_count = parse_single_hex_dump_line(line, &pd[eth_hdr_len + count], count))) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: packet data value not valid"); - return -1; + return FALSE; } count += line_count; if (count > pkt_len) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("dbs_etherwatch: packet data value has too many bytes"); - return -1; + return FALSE; } } - return REC_TYPE_PACKET; + return TRUE; } /* Parse a hex dump line */ diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c index 032df310a2..2a0eb9103a 100644 --- a/wiretap/dct3trace.c +++ b/wiretap/dct3trace.c @@ -73,9 +73,9 @@ static const char dct3trace_magic_end[] = ""; #define MAX_PACKET_LEN 23 -static int dct3trace_read(wtap *wth, int *err, gchar **err_info, +static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int dct3trace_seek_read(wtap *wth, gint64 seek_off, +static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); /* @@ -187,7 +187,7 @@ int dct3trace_open(wtap *wth, int *err, gchar **err_info) } -static int dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { char line[1024]; @@ -202,7 +202,7 @@ static int dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, { /* Return on end of file */ *err = 0; - return -1; + return FALSE; } else if( memcmp(dct3trace_magic_record_end, line, strlen(dct3trace_magic_record_end)) == 0 ) { @@ -222,14 +222,14 @@ static int dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, buffer_assure_space(buf, phdr->caplen); memcpy( buffer_start_ptr(buf), databuf, phdr->caplen ); - return REC_TYPE_PACKET; + return TRUE; } else { /* If not got any data return error */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("dct3trace: record without data"); - return -1; + return FALSE; } } else if( memcmp(dct3trace_magic_record_start, line, strlen(dct3trace_magic_record_start)) == 0 ) @@ -282,7 +282,7 @@ static int dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("dct3trace: record length %d too long", phdr->caplen); - return -1; + return FALSE; } } } @@ -322,7 +322,7 @@ static int dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("dct3trace: record length %d too long", phdr->caplen); - return -1; + return FALSE; } len += data_len; @@ -336,17 +336,17 @@ static int dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr, { *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; baddata: *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("dct3trace: record missing mandatory attributes"); - return -1; + return FALSE; } /* Find the next packet and parse it; called from wtap_read(). */ -static int dct3trace_read(wtap *wth, int *err, gchar **err_info, +static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -357,12 +357,12 @@ static int dct3trace_read(wtap *wth, int *err, gchar **err_info, /* Used to read packets in random-access fashion */ -static int dct3trace_seek_read(wtap *wth, gint64 seek_off, +static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return -1; + return FALSE; } return dct3trace_get_packet(wth->random_fh, phdr, buf, err, err_info); diff --git a/wiretap/erf.c b/wiretap/erf.c index 3513642121..67b7ccab1d 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -64,11 +64,11 @@ static int erf_read_header(FILE_T fh, gchar **err_info, guint32 *bytes_read, guint32 *packet_size); -static int erf_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); -static int erf_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, - int *err, gchar **err_info); +static gboolean erf_read(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); +static gboolean erf_seek_read(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, Buffer *buf, + int *err, gchar **err_info); static const struct { int erf_encap_value; @@ -280,7 +280,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static int erf_read(wtap *wth, int *err, gchar **err_info, +static gboolean erf_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { erf_header_t erf_header; @@ -292,38 +292,36 @@ static int erf_read(wtap *wth, int *err, gchar **err_info, if (!erf_read_header(wth->fh, &wth->phdr, &erf_header, err, err_info, &bytes_read, &packet_size)) { - return -1; + return FALSE; } if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size, err, err_info)) - return -1; + return FALSE; } while ( erf_header.type == ERF_TYPE_PAD ); - return REC_TYPE_PACKET; + return TRUE; } -static int erf_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, Buffer *buf, - int *err, gchar **err_info) +static gboolean erf_seek_read(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, Buffer *buf, + int *err, gchar **err_info) { erf_header_t erf_header; guint32 packet_size; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; do { if (!erf_read_header(wth->random_fh, phdr, &erf_header, err, err_info, NULL, &packet_size)) - return -1; + return FALSE; } while ( erf_header.type == ERF_TYPE_PAD ); - if (!wtap_read_packet_bytes(wth->random_fh, buf, packet_size, - err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(wth->random_fh, buf, packet_size, + err, err_info); } static int erf_read_header(FILE_T fh, diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c index 4444b0d9f5..8bd32c2249 100644 --- a/wiretap/eyesdn.c +++ b/wiretap/eyesdn.c @@ -90,9 +90,9 @@ static const unsigned char eyesdn_hdr_magic[] = */ #define EYESDN_MAX_PACKET_LEN 16384 -static int eyesdn_read(wtap *wth, int *err, gchar **err_info, +static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int eyesdn_seek_read(wtap *wth, gint64 seek_off, +static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf, int *err, gchar **err_info); @@ -149,7 +149,7 @@ int eyesdn_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static int eyesdn_read(wtap *wth, int *err, gchar **err_info, +static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -157,7 +157,7 @@ static int eyesdn_read(wtap *wth, int *err, gchar **err_info, /* Find the next record */ offset = eyesdn_seek_next_packet(wth, err, err_info); if (offset < 1) - return -1; + return FALSE; *data_offset = offset; /* Parse the record */ @@ -166,18 +166,18 @@ static int eyesdn_read(wtap *wth, int *err, gchar **err_info, } /* Used to read packets in random-access fashion */ -static int +static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; return read_eyesdn_rec(wth->random_fh, phdr, buf, err, err_info); } /* Parses a record. */ -static int +static gboolean read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { @@ -198,7 +198,7 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } /* extract information from header */ @@ -251,7 +251,7 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, *err_info = g_strdup_printf( "eyesdn: ATM cell has a length != 53 (%u)", pkt_len); - return -1; + return FALSE; } cur_off = file_tell(fh); @@ -259,10 +259,10 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } if (file_seek(fh, cur_off, SEEK_SET, err) == -1) - return -1; + return FALSE; phdr->pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; pseudo_header->atm.flags=ATM_RAW_CELL; pseudo_header->atm.aal=AAL_UNKNOWN; @@ -310,7 +310,7 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("eyesdn: File has %u-byte packet, bigger than maximum of %u", pkt_len, EYESDN_MAX_PACKET_LEN); - return -1; + return FALSE; } phdr->presence_flags = WTAP_HAS_TS; @@ -335,9 +335,9 @@ read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, *err_info = g_strdup("eyesdn: No flag character seen in frame"); } else *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET;; + return TRUE; } diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c index 22483b7d6a..cc38a62154 100644 --- a/wiretap/hcidump.c +++ b/wiretap/hcidump.c @@ -34,7 +34,7 @@ struct dump_hdr { #define DUMP_HDR_SIZE (sizeof(struct dump_hdr)) -static int hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr, +static gboolean hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { struct dump_hdr dh; @@ -45,7 +45,7 @@ static int hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr, *err = file_error(fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } packet_size = GUINT16_FROM_LE(dh.len); @@ -57,7 +57,7 @@ static int hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("hcidump: File has %u-byte packet, bigger than maximum of %u", packet_size, WTAP_MAX_PACKET_SIZE); - return -1; + return FALSE; } phdr->presence_flags = WTAP_HAS_TS; @@ -68,12 +68,10 @@ static int hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr, phdr->pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE); - if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static int hcidump_read(wtap *wth, int *err, gchar **err_info, +static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -82,11 +80,11 @@ static int hcidump_read(wtap *wth, int *err, gchar **err_info, err, err_info); } -static int hcidump_seek_read(wtap *wth, gint64 seek_off, +static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; return hcidump_process_packet(wth->random_fh, phdr, buf, err, err_info); } diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index 00cf9e876c..d474ec2c8f 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -33,11 +33,11 @@ typedef struct { gboolean byte_swapped; } i4btrace_t; -static int i4btrace_read(wtap *wth, int *err, gchar **err_info, +static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int i4btrace_seek_read(wtap *wth, gint64 seek_off, +static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); -static gboolean i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, +static int i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); /* @@ -110,23 +110,21 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static int i4btrace_read(wtap *wth, int *err, gchar **err_info, +static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - if (!i4b_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer, - err, err_info)) - return -1; - return REC_TYPE_PACKET; + return i4b_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer, + err, err_info); } -static int +static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (!i4b_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) { /* Read error or EOF */ @@ -134,12 +132,12 @@ i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, /* EOF means "short read" in random-access mode */ *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } -static gboolean +static int i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c index 87de433599..061a53d79c 100644 --- a/wiretap/ipfix.c +++ b/wiretap/ipfix.c @@ -85,10 +85,10 @@ #define RECORDS_FOR_IPFIX_CHECK 20 -static int +static gboolean ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int +static gboolean ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static void @@ -280,7 +280,7 @@ ipfix_open(wtap *wth, int *err, gchar **err_info) /* classic wtap: read packet */ -static int +static gboolean ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -289,15 +289,15 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) if (!ipfix_read_message(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) { ipfix_debug2("ipfix_read: couldn't read message header with code: %d\n, and error '%s'", *err, *err_info); - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } /* classic wtap: seek to file position and read packet */ -static int +static gboolean ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { @@ -305,7 +305,7 @@ ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { ipfix_debug2("ipfix_seek_read: couldn't read message header with code: %d\n, and error '%s'", *err, *err_info); - return -1; /* Seek error */ + return FALSE; /* Seek error */ } ipfix_debug1("ipfix_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off); @@ -314,9 +314,9 @@ ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, ipfix_debug0("ipfix_seek_read: couldn't read message header"); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c index 3f128fe205..67e8e65806 100644 --- a/wiretap/iptrace.c +++ b/wiretap/iptrace.c @@ -214,7 +214,7 @@ iptrace_read_rec_1_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, } /* Read the next packet */ -static int iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, +static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -223,7 +223,7 @@ static int iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, if (!iptrace_read_rec_1_0(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) { /* Read error or EOF */ - return -1; + return FALSE; } /* If the per-file encapsulation isn't known, set it to this @@ -239,22 +239,22 @@ static int iptrace_read_1_0(wtap *wth, int *err, gchar **err_info, wth->file_encap = WTAP_ENCAP_PER_PACKET; } - return REC_TYPE_PACKET; + return TRUE; } -static int iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, +static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* Read the packet */ if (!iptrace_read_rec_1_0(wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } /*********************************************************** @@ -409,7 +409,7 @@ iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, } /* Read the next packet */ -static int iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, +static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -418,7 +418,7 @@ static int iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, if (!iptrace_read_rec_2_0(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) { /* Read error or EOF */ - return -1; + return FALSE; } /* If the per-file encapsulation isn't known, set it to this @@ -434,22 +434,22 @@ static int iptrace_read_2_0(wtap *wth, int *err, gchar **err_info, wth->file_encap = WTAP_ENCAP_PER_PACKET; } - return REC_TYPE_PACKET; + return TRUE; } -static int iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, +static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* Read the packet */ if (!iptrace_read_rec_2_0(wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static int diff --git a/wiretap/iseries.c b/wiretap/iseries.c index 4c42fb4502..0a171a6341 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -187,9 +187,9 @@ static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, static gboolean iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format); static gint64 iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info); -static int iseries_parse_packet (wtap * wth, FILE_T fh, - struct wtap_pkthdr *phdr, - Buffer * buf, int *err, gchar ** err_info); +static gboolean iseries_parse_packet (wtap * wth, FILE_T fh, + struct wtap_pkthdr *phdr, + Buffer * buf, int *err, gchar ** err_info); static int iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes); static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf, size_t len); @@ -370,7 +370,7 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) /* * Find the next packet and parse it; called from wtap_read(). */ -static int +static gboolean iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset) { gint64 offset; @@ -457,14 +457,14 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info) /* * Read packets in random-access fashion */ -static int +static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer * buf, int *err, gchar ** err_info) { /* seek to packet location */ if (file_seek (wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) - return -1; + return FALSE; /* * Parse the packet and extract the various fields @@ -554,7 +554,7 @@ done: } /* Parses a packet. */ -static int +static gboolean iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { @@ -581,7 +581,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, if (file_gets (data, ISERIES_LINE_LENGTH, fh) == NULL) { *err = file_error (fh, err_info); - return -1; + return FALSE; } /* Convert UNICODE data to ASCII */ if (iseries->format == ISERIES_FORMAT_UNICODE) @@ -615,7 +615,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup ("iseries: packet header isn't valid"); - return -1; + return FALSE; } phdr->presence_flags = WTAP_HAS_CAP_LEN; @@ -747,7 +747,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, if (ascii_offset == -1) { /* Bad line. */ - return -1; + return FALSE; } continue; } @@ -769,7 +769,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, if (ascii_offset == -1) { /* Bad line. */ - return -1; + return FALSE; } continue; } @@ -792,7 +792,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, if (ascii_offset == -1) { /* Bad line. */ - return -1; + return FALSE; } continue; } @@ -842,11 +842,11 @@ iseries_parse_packet (wtap * wth, FILE_T fh, struct wtap_pkthdr *phdr, /* free buffer allocs and return */ *err = 0; g_free (ascii_buf); - return REC_TYPE_PACKET; + return TRUE; errxit: g_free (ascii_buf); - return -1; + return FALSE; } /* diff --git a/wiretap/k12.c b/wiretap/k12.c index 013c19e6f6..cd1bbe6104 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -623,7 +623,7 @@ process_packet_data(struct wtap_pkthdr *phdr, Buffer *target, guint8 *buffer, phdr->pseudo_header.k12.stuff = k12; } -static int k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { +static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { k12_t *k12 = (k12_t *)wth->priv; k12_src_desc_t* src_desc; guint8* buffer; @@ -644,16 +644,16 @@ static int k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) if (len < 0) { /* read error */ - return -1; + return FALSE; } else if (len == 0) { /* EOF */ *err = 0; - return -1; + return FALSE; } else if (len < K12_RECORD_SRC_ID + 4) { /* Record not large enough to contain a src ID */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("data record length %d too short", len); - return -1; + return FALSE; } buffer = k12->seq_read_buff; @@ -681,11 +681,11 @@ static int k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) process_packet_data(&wth->phdr, wth->frame_buffer, buffer, len, k12); - return REC_TYPE_PACKET; + return TRUE; } -static int k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { +static gboolean k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { k12_t *k12 = (k12_t *)wth->priv; guint8* buffer; gint len; @@ -694,18 +694,18 @@ static int k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, B if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { K12_DBG(5,("k12_seek_read: SEEK ERROR")); - return -1; + return FALSE; } len = get_record(k12, wth->random_fh, seek_off, TRUE, err, err_info); if (len < 0) { K12_DBG(5,("k12_seek_read: READ ERROR")); - return -1; + return FALSE; } else if (len < K12_RECORD_SRC_ID + 4) { /* Record not large enough to contain a src ID */ K12_DBG(5,("k12_seek_read: SHORT READ")); *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } buffer = k12->rand_read_buff; @@ -714,7 +714,7 @@ static int k12_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, B K12_DBG(5,("k12_seek_read: DONE OK")); - return REC_TYPE_PACKET; + return TRUE; } diff --git a/wiretap/k12text.l b/wiretap/k12text.l index 8db5c673c8..42de8e6875 100644 --- a/wiretap/k12text.l +++ b/wiretap/k12text.l @@ -244,7 +244,7 @@ k12text_reset(FILE_T fh) ii=0; } -static int +static gboolean k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset) { k12text_t *k12text = (k12text_t *)wth->priv; @@ -259,7 +259,7 @@ k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset) */ if ( file_seek(wth->fh, k12text->next_frame_offset, SEEK_SET, err) == -1) { - return -1; + return FALSE; } k12text_reset(wth->fh); /* init lexer buffer and vars set by lexer */ @@ -274,7 +274,7 @@ k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset) *err = WTAP_ERR_BAD_FILE; *err_info = error_str; } - return -1; + return FALSE; } *data_offset = k12text->next_frame_offset; /* file position for beginning of this frame */ @@ -285,14 +285,14 @@ k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset) buffer_assure_space(wth->frame_buffer, wth->phdr.caplen); memcpy(buffer_start_ptr(wth->frame_buffer), bb, wth->phdr.caplen); - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, char **err_info) { if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return -1; + return FALSE; } k12text_reset(wth->random_fh); /* init lexer buffer and vars set by lexer */ @@ -307,7 +307,7 @@ k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer * } else { *err_info = error_str; } - return -1; + return FALSE; } k12text_set_headers(phdr); @@ -315,7 +315,7 @@ k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer * buffer_assure_space(buf, phdr->caplen); memcpy(buffer_start_ptr(buf), bb, phdr->caplen); - return REC_TYPE_PACKET; + return TRUE; } int diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c index 5c4942b10e..8c2ce348a1 100644 --- a/wiretap/lanalyzer.c +++ b/wiretap/lanalyzer.c @@ -270,9 +270,9 @@ typedef struct { time_t start; } lanalyzer_t; -static int lanalyzer_read(wtap *wth, int *err, gchar **err_info, +static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int lanalyzer_seek_read(wtap *wth, gint64 seek_off, +static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err); @@ -560,32 +560,30 @@ static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh, } /* Read the next packet */ -static int lanalyzer_read(wtap *wth, int *err, gchar **err_info, +static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); /* Read the record */ - if (!lanalyzer_read_trace_record(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return lanalyzer_read_trace_record(wth, wth->fh, &wth->phdr, + wth->frame_buffer, err, err_info); } -static int lanalyzer_seek_read(wtap *wth, gint64 seek_off, +static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* Read the record */ if (!lanalyzer_read_trace_record(wth, wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } /*--------------------------------------------------- diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index 7d467cb06c..fe9c111261 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -63,9 +63,9 @@ typedef enum { } libpcap_try_t; static libpcap_try_t libpcap_try(wtap *wth, int *err); -static int libpcap_read(wtap *wth, int *err, gchar **err_info, +static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int libpcap_seek_read(wtap *wth, gint64 seek_off, +static gboolean libpcap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info, struct pcaprec_ss990915_hdr *hdr); @@ -590,15 +590,13 @@ static libpcap_try_t libpcap_try(wtap *wth, int *err) } /* Read the next packet */ -static int libpcap_read(wtap *wth, int *err, gchar **err_info, +static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - if (!libpcap_read_packet(wth, wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return libpcap_read_packet(wth, wth->fh, &wth->phdr, + wth->frame_buffer, err, err_info); } static gboolean @@ -606,15 +604,15 @@ libpcap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (!libpcap_read_packet(wth, wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static gboolean diff --git a/wiretap/logcat.c b/wiretap/logcat.c index 022b6a2308..a1a41c0689 100644 --- a/wiretap/logcat.c +++ b/wiretap/logcat.c @@ -214,31 +214,29 @@ static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T fh, return TRUE; } -static int logcat_read(wtap *wth, int *err, gchar **err_info, +static gboolean logcat_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - if (!logcat_read_packet((struct logcat_phdr *) wth->priv, wth->fh, - &wth->phdr, wth->frame_buffer, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return logcat_read_packet((struct logcat_phdr *) wth->priv, wth->fh, + &wth->phdr, wth->frame_buffer, err, err_info); } -static int logcat_seek_read(wtap *wth, gint64 seek_off, +static gboolean logcat_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (!logcat_read_packet((struct logcat_phdr *) wth->priv, wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } int logcat_open(wtap *wth, int *err, gchar **err_info _U_) diff --git a/wiretap/mime_file.c b/wiretap/mime_file.c index 0f8934a28e..2a7d8be0e4 100644 --- a/wiretap/mime_file.c +++ b/wiretap/mime_file.c @@ -94,7 +94,7 @@ static const mime_files_t magic_files[] = { */ #define MAX_FILE_SIZE (16*1024*1024) -static int +static gboolean mime_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { @@ -102,7 +102,7 @@ mime_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, int packet_size; if ((file_size = wtap_file_size(wth, err)) == -1) - return -1; + return FALSE; if (file_size > MAX_FILE_SIZE) { /* @@ -112,7 +112,7 @@ mime_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("mime_file: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u", file_size, MAX_FILE_SIZE); - return -1; + return FALSE; } packet_size = (int)file_size; @@ -124,12 +124,10 @@ mime_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, phdr->ts.secs = 0; phdr->ts.nsecs = 0; - if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static int +static gboolean mime_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -140,24 +138,24 @@ mime_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* there is only ever one packet */ if (offset != 0) - return -1; + return FALSE; *data_offset = offset; return mime_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); } -static int +static gboolean mime_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { /* there is only one packet */ if (seek_off > 0) { *err = 0; - return -1; + return FALSE; } if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; return mime_read_file(wth, wth->random_fh, phdr, buf, err, err_info); } diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c index 8b44a1bd4c..844fb40a13 100644 --- a/wiretap/mp2t.c +++ b/wiretap/mp2t.c @@ -102,7 +102,7 @@ mp2t_read_packet(mp2t_filetype_t *mp2t, FILE_T fh, gint64 offset, return TRUE; } -static int +static gboolean mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { mp2t_filetype_t *mp2t; @@ -113,27 +113,27 @@ mp2t_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) if (!mp2t_read_packet(mp2t, wth->fh, *data_offset, &wth->phdr, wth->frame_buffer, err, err_info)) { - return -1; + return FALSE; } /* if there's a trailer, skip it and go to the start of the next packet */ if (mp2t->trailer_len!=0) { if (-1 == file_seek(wth->fh, mp2t->trailer_len, SEEK_CUR, err)) { - return -1; + return FALSE; } } - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean mp2t_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { mp2t_filetype_t *mp2t; if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err)) { - return -1; + return FALSE; } mp2t = (mp2t_filetype_t*) wth->priv; @@ -142,9 +142,9 @@ mp2t_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } int diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c index 2f4998ebb3..abe87a37fe 100644 --- a/wiretap/mpeg.c +++ b/wiretap/mpeg.c @@ -220,32 +220,30 @@ mpeg_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, return TRUE; } -static int +static gboolean mpeg_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - if (!mpeg_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer, - FALSE, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return mpeg_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer, + FALSE, err, err_info); } -static int +static gboolean mpeg_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (!mpeg_read_packet(wth, wth->random_fh, phdr, buf, TRUE, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } struct _mpeg_magic { diff --git a/wiretap/netmon.c b/wiretap/netmon.c index 85f3234121..f12bf43a87 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -175,9 +175,9 @@ static const int netmon_encap[] = { #define NETMON_NET_DNS_CACHE 0xFFFE #define NETMON_NET_NETMON_FILTER 0xFFFF -static int netmon_read(wtap *wth, int *err, gchar **err_info, +static gboolean netmon_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int netmon_seek_read(wtap *wth, gint64 seek_off, +static gboolean netmon_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); @@ -677,7 +677,7 @@ static process_trailer_retval netmon_process_rec_trailer(netmon_t *netmon, } /* Read the next packet */ -static int netmon_read(wtap *wth, int *err, gchar **err_info, +static gboolean netmon_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { netmon_t *netmon = (netmon_t *)wth->priv; @@ -691,7 +691,7 @@ again: g_free(netmon->frame_table); netmon->frame_table = NULL; *err = 0; /* it's just an EOF, not an error */ - return -1; + return FALSE; } /* Seek to the beginning of the current record, if we're @@ -707,7 +707,7 @@ again: rec_offset = netmon->frame_table[netmon->current_frame]; if (file_tell(wth->fh) != rec_offset) { if (file_seek(wth->fh, rec_offset, SEEK_SET, err) == -1) - return -1; + return FALSE; } netmon->current_frame++; @@ -715,11 +715,11 @@ again: if (!netmon_process_rec_header(wth, wth->fh, &wth->phdr, err, err_info)) - return -1; + return FALSE; if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen, err, err_info)) - return -1; /* Read error */ + return FALSE; /* Read error */ /* * For version 2.1 and later, there's additional information @@ -735,33 +735,33 @@ again: break; case FAILURE: - return -1; + return FALSE; } netmon_set_pseudo_header_info(wth->phdr.pkt_encap, &wth->phdr, wth->frame_buffer); - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean netmon_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { netmon_t *netmon = (netmon_t *)wth->priv; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (!netmon_process_rec_header(wth, wth->random_fh, phdr, err, err_info)) - return -1; + return FALSE; /* * Read the packet data. */ if (!wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, err, err_info)) - return -1; + return FALSE; /* * For version 2.1 and later, there's additional information @@ -776,18 +776,18 @@ netmon_seek_read(wtap *wth, gint64 seek_off, */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("netmon: saw metadata in netmon_seek_read"); - return -1; + return FALSE; case SUCCESS: break; case FAILURE: - return -1; + return FALSE; } netmon_set_pseudo_header_info(phdr->pkt_encap, phdr, buf); - return REC_TYPE_PACKET; + return TRUE; } static gboolean diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c index 71e835a584..9772567ae7 100644 --- a/wiretap/netscaler.c +++ b/wiretap/netscaler.c @@ -613,24 +613,24 @@ typedef struct { } nstrace_t; static guint32 nspm_signature_version(wtap*, gchar*, gint32); -static int nstrace_read_v10(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); -static int nstrace_read_v20(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); -static int nstrace_read_v30(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); -static int nstrace_seek_read_v10(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, - Buffer *buf, - int *err, gchar **err_info); -static int nstrace_seek_read_v20(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, - Buffer *buf, - int *err, gchar **err_info); -static int nstrace_seek_read_v30(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, - Buffer *buf, - int *err, gchar **err_info); +static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); +static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); +static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); +static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, + Buffer *buf, + int *err, gchar **err_info); +static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, + Buffer *buf, + int *err, gchar **err_info); +static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, + Buffer *buf, + int *err, gchar **err_info); static void nstrace_close(wtap *wth); static gboolean nstrace_set_start_time_v10(wtap *wth); @@ -925,7 +925,7 @@ static gboolean nstrace_set_start_time(wtap *wth) /* ** Netscaler trace format read routines. */ -static int nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { nstrace_t *nstrace = (nstrace_t *)wth->priv; guint64 nsg_creltime = nstrace->nsg_creltime; @@ -965,7 +965,7 @@ static int nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *data_ nstrace->nstrace_buf_offset = nstrace_buf_offset + (phdr)->len;\ nstrace->nstrace_buflen = nstrace_buflen;\ nstrace->nsg_creltime = nsg_creltime;\ - return REC_TYPE_PACKET; + return TRUE; #define GENERATE_CASE_PART(phdr,type,acttype) \ case NSPR_PDPKTRACEPARTTX_V##type:\ @@ -988,7 +988,7 @@ static int nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *data_ nstrace->nstrace_buf_offset = nstrace_buf_offset + (phdr)->caplen;\ nstrace->nsg_creltime = nsg_creltime;\ nstrace->nstrace_buflen = nstrace_buflen;\ - return REC_TYPE_PACKET;\ + return TRUE;\ switch (pletoh16(&(( nspr_header_v10_t*)&nstrace_buf[nstrace_buf_offset])->ph_RecordType)) { @@ -1030,7 +1030,7 @@ static int nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *data_ nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset)); }while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && (bytes_read == nstrace_buflen)); - return -1; + return FALSE; } #define TIMEDEFV20(fp,type) \ @@ -1112,10 +1112,10 @@ static int nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *data_ nstrace->nstrace_buf_offset = nstrace_buf_offset + nspr_getv20recordsize((nspr_hd_v20_t *)fp);\ nstrace->nstrace_buflen = nstrace_buflen;\ nstrace->nsg_creltime = nsg_creltime;\ - return REC_TYPE_PACKET;\ + return TRUE;\ }while(0) -static int nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { nstrace_t *nstrace = (nstrace_t *)wth->priv; guint64 nsg_creltime = nstrace->nsg_creltime; @@ -1219,7 +1219,7 @@ static int nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *data_ nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset)); }while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && (bytes_read == nstrace_buflen)); - return -1; + return FALSE; } #undef PACKET_DESCRIBE @@ -1248,7 +1248,7 @@ static int nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *data_ nstrace->xxx_offset += nstrace_buflen;\ bytes_read = file_read(nstrace_buf, NSPR_PAGESIZE_TRACE, wth->fh);\ if (bytes_read != NSPR_PAGESIZE_TRACE) {\ - return -1;\ + return FALSE;\ } else {\ nstrace_buf_offset = 0;\ }\ @@ -1263,10 +1263,10 @@ static int nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *data_ nstrace->nstrace_buf_offset = nstrace_buf_offset;\ nstrace->nstrace_buflen = nstrace_buflen = ((gint32)NSPR_PAGESIZE_TRACE);\ nstrace->nsg_creltime = nsg_creltime;\ - return REC_TYPE_PACKET;\ + return TRUE;\ } while(0) -static int nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { nstrace_t *nstrace = (nstrace_t *)wth->priv; guint64 nsg_creltime = nstrace->nsg_creltime; @@ -1324,12 +1324,12 @@ static int nstrace_read_v30(wtap *wth, int *err, gchar **err_info, gint64 *data_ nstrace_buflen = NSPR_PAGESIZE_TRACE; } while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && (bytes_read == nstrace_buflen)); - return -1; + return FALSE; } #undef PACKET_DESCRIBE -static int nstrace_seek_read_v10(wtap *wth, gint64 seek_off, +static gboolean nstrace_seek_read_v10(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { nspr_hd_v10_t hdr; @@ -1343,7 +1343,7 @@ static int nstrace_seek_read_v10(wtap *wth, gint64 seek_off, *err = 0; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* ** Read the record header. @@ -1353,7 +1353,7 @@ static int nstrace_seek_read_v10(wtap *wth, gint64 seek_off, *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } /* @@ -1374,7 +1374,7 @@ static int nstrace_seek_read_v10(wtap *wth, gint64 seek_off, *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } } @@ -1408,7 +1408,7 @@ static int nstrace_seek_read_v10(wtap *wth, gint64 seek_off, #undef GENERATE_CASE_FULL #undef GENERATE_CASE_PART - return REC_TYPE_PACKET; + return TRUE; } #define PACKET_DESCRIBE(phdr,FPTIMEDEF,SIZEDEF,ver,enumprefix,type,structname,TYPE)\ @@ -1417,10 +1417,10 @@ static int nstrace_seek_read_v10(wtap *wth, gint64 seek_off, SIZEDEF##ver((phdr),fp,ver);\ TRACE_V##ver##_REC_LEN_OFF((phdr),enumprefix,type,structname);\ (phdr)->pseudo_header.nstr.rec_type = NSPR_HEADER_VERSION##TYPE;\ - return REC_TYPE_PACKET;\ + return TRUE;\ }while(0) -static int nstrace_seek_read_v20(wtap *wth, gint64 seek_off, +static gboolean nstrace_seek_read_v20(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { nspr_hd_v20_t hdr; @@ -1433,7 +1433,7 @@ static int nstrace_seek_read_v20(wtap *wth, gint64 seek_off, *err = 0; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* ** Read the first 2 bytes of the record header. @@ -1443,7 +1443,7 @@ static int nstrace_seek_read_v20(wtap *wth, gint64 seek_off, *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } hdrlen = 2; @@ -1456,7 +1456,7 @@ static int nstrace_seek_read_v20(wtap *wth, gint64 seek_off, *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } hdrlen = 3; } @@ -1479,7 +1479,7 @@ static int nstrace_seek_read_v20(wtap *wth, gint64 seek_off, *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } } @@ -1532,11 +1532,11 @@ static int nstrace_seek_read_v20(wtap *wth, gint64 seek_off, #undef GENERATE_CASE_PART #undef GENERATE_CASE_PART_V25 - return REC_TYPE_PACKET; + return TRUE; } -static int nstrace_seek_read_v30(wtap *wth, gint64 seek_off, +static gboolean nstrace_seek_read_v30(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { nspr_hd_v20_t hdr; @@ -1549,7 +1549,7 @@ static int nstrace_seek_read_v30(wtap *wth, gint64 seek_off, *err = 0; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* ** Read the first 2 bytes of the record header. */ @@ -1558,7 +1558,7 @@ static int nstrace_seek_read_v30(wtap *wth, gint64 seek_off, *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } hdrlen = 2; @@ -1571,7 +1571,7 @@ static int nstrace_seek_read_v30(wtap *wth, gint64 seek_off, *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } hdrlen = 3; } @@ -1594,7 +1594,7 @@ static int nstrace_seek_read_v30(wtap *wth, gint64 seek_off, *err = file_error(wth->random_fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } } @@ -1612,7 +1612,7 @@ static int nstrace_seek_read_v30(wtap *wth, gint64 seek_off, GENERATE_CASE_V30(phdr,30, 300); } - return REC_TYPE_PACKET; + return TRUE; } diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c index 91c82c796d..bbb4a535e9 100644 --- a/wiretap/netscreen.c +++ b/wiretap/netscreen.c @@ -67,9 +67,9 @@ static gint64 netscreen_seek_next_packet(wtap *wth, int *err, gchar **err_info, char *hdr); static gboolean netscreen_check_file_type(wtap *wth, int *err, gchar **err_info); -static int netscreen_read(wtap *wth, int *err, gchar **err_info, +static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int netscreen_seek_read(wtap *wth, gint64 seek_off, +static gboolean netscreen_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int parse_netscreen_rec_hdr(struct wtap_pkthdr *phdr, const char *line, @@ -190,7 +190,7 @@ int netscreen_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static int netscreen_read(wtap *wth, int *err, gchar **err_info, +static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -203,19 +203,19 @@ static int netscreen_read(wtap *wth, int *err, gchar **err_info, /* Find the next packet */ offset = netscreen_seek_next_packet(wth, err, err_info, line); if (offset < 0) - return -1; + return FALSE; /* Parse the header */ pkt_len = parse_netscreen_rec_hdr(&wth->phdr, line, cap_int, &cap_dir, cap_dst, err, err_info); if (pkt_len == -1) - return -1; + return FALSE; /* Convert the ASCII hex dump to binary data, and fill in some struct wtap_pkthdr fields */ if (!parse_netscreen_hex_dump(wth->fh, pkt_len, cap_int, cap_dst, &wth->phdr, wth->frame_buffer, err, err_info)) - return -1; + return FALSE; /* * If the per-file encapsulation isn't known, set it to this @@ -233,11 +233,11 @@ static int netscreen_read(wtap *wth, int *err, gchar **err_info, } *data_offset = offset; - return REC_TYPE_PACKET; + return TRUE; } /* Used to read packets in random-access fashion */ -static int +static gboolean netscreen_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) @@ -249,7 +249,7 @@ netscreen_seek_read(wtap *wth, gint64 seek_off, char cap_dst[13]; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { - return -1; + return FALSE; } if (file_gets(line, NETSCREEN_LINE_LENGTH, wth->random_fh) == NULL) { @@ -257,18 +257,18 @@ netscreen_seek_read(wtap *wth, gint64 seek_off, if (*err == 0) { *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } pkt_len = parse_netscreen_rec_hdr(phdr, line, cap_int, &cap_dir, cap_dst, err, err_info); if (pkt_len == -1) - return -1; + return FALSE; if (!parse_netscreen_hex_dump(wth->random_fh, pkt_len, cap_int, cap_dst, phdr, buf, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return FALSE; + return TRUE; } /* Parses a packet record header. There are a few possible formats: diff --git a/wiretap/nettl.c b/wiretap/nettl.c index 0e3c9a9f97..0c6898bbdb 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -175,9 +175,9 @@ typedef struct { gboolean is_hpux_11; } nettl_t; -static int nettl_read(wtap *wth, int *err, gchar **err_info, +static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int nettl_seek_read(wtap *wth, gint64 seek_off, +static gboolean nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, @@ -287,7 +287,7 @@ int nettl_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static int nettl_read(wtap *wth, int *err, gchar **err_info, +static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { /* Read record header. */ @@ -295,7 +295,7 @@ static int nettl_read(wtap *wth, int *err, gchar **err_info, if (!nettl_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) { /* Read error or EOF */ - return -1; + return FALSE; } /* @@ -313,15 +313,15 @@ static int nettl_read(wtap *wth, int *err, gchar **err_info, wth->file_encap = WTAP_ENCAP_PER_PACKET; } - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* Read record header. */ if (!nettl_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) { @@ -330,9 +330,9 @@ nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, /* EOF means "short read" in random-access mode */ *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static gboolean diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index 01ed983932..38abfab2cd 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -94,9 +94,9 @@ static void init_gmt_to_localtime_offset(void) } } -static int observer_read(wtap *wth, int *err, gchar **err_info, +static gboolean observer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int observer_seek_read(wtap *wth, gint64 seek_off, +static gboolean observer_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int read_packet_header(FILE_T fh, union wtap_pseudo_header *pseudo_header, packet_entry_header *packet_header, int *err, gchar **err_info); @@ -258,7 +258,7 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info) } /* Reads the next packet. */ -static int observer_read(wtap *wth, int *err, gchar **err_info, +static gboolean observer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int header_bytes_consumed; @@ -273,7 +273,7 @@ static int observer_read(wtap *wth, int *err, gchar **err_info, header_bytes_consumed = read_packet_header(wth->fh, &wth->phdr.pseudo_header, &packet_header, err, err_info); if (header_bytes_consumed <= 0) - return -1; /* EOF or error */ + return FALSE; /* EOF or error */ if (packet_header.packet_type == PACKET_TYPE_DATA_PACKET) break; @@ -281,32 +281,32 @@ static int observer_read(wtap *wth, int *err, gchar **err_info, /* skip to next packet */ if (!skip_to_next_packet(wth, packet_header.offset_to_next_packet, header_bytes_consumed, err, err_info)) { - return -1; /* EOF or error */ + return FALSE; /* EOF or error */ } } if (!process_packet_header(wth, &packet_header, &wth->phdr, err, err_info)) - return -1; + return FALSE; /* read the frame data */ data_bytes_consumed = read_packet_data(wth->fh, packet_header.offset_to_frame, header_bytes_consumed, wth->frame_buffer, wth->phdr.caplen, err, err_info); if (data_bytes_consumed < 0) { - return -1; + return FALSE; } /* skip over any extra bytes following the frame data */ if (!skip_to_next_packet(wth, packet_header.offset_to_next_packet, header_bytes_consumed + data_bytes_consumed, err, err_info)) { - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } /* Reads a packet at an offset. */ -static int observer_seek_read(wtap *wth, gint64 seek_off, +static gboolean observer_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; @@ -315,25 +315,25 @@ static int observer_seek_read(wtap *wth, gint64 seek_off, int data_bytes_consumed; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* process the packet header, including TLVs */ offset = read_packet_header(wth->random_fh, pseudo_header, &packet_header, err, err_info); if (offset <= 0) - return -1; /* EOF or error */ + return FALSE; /* EOF or error */ if (!process_packet_header(wth, &packet_header, phdr, err, err_info)) - return -1; + return FALSE; /* read the frame data */ data_bytes_consumed = read_packet_data(wth->random_fh, packet_header.offset_to_frame, offset, buf, phdr->caplen, err, err_info); if (data_bytes_consumed < 0) { - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static int diff --git a/wiretap/netxray.c b/wiretap/netxray.c index 782918c921..e6dd704bb3 100644 --- a/wiretap/netxray.c +++ b/wiretap/netxray.c @@ -402,9 +402,9 @@ typedef struct { guint isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */ } netxray_t; -static int netxray_read(wtap *wth, int *err, gchar **err_info, +static gboolean netxray_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int netxray_seek_read(wtap *wth, gint64 seek_off, +static gboolean netxray_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int netxray_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, int *err, gchar **err_info); @@ -989,7 +989,7 @@ netxray_open(wtap *wth, int *err, gchar **err_info) } /* Read the next packet */ -static int +static gboolean netxray_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { @@ -1007,7 +1007,7 @@ reread: if (*data_offset == netxray->end_offset) { /* Yes. */ *err = 0; /* it's just an EOF, not an error */ - return -1; + return FALSE; } /* Read and process record header. */ @@ -1021,7 +1021,7 @@ reread: /* * Error of some sort; give up. */ - return -1; + return FALSE; } /* We're at EOF. Wrap? @@ -1046,7 +1046,7 @@ reread: */ if (netxray->start_offset < netxray->end_offset) { *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } if (!netxray->wrapped) { @@ -1054,12 +1054,12 @@ reread: netxray->wrapped = TRUE; if (file_seek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1) - return -1; + return FALSE; goto reread; } /* We've already wrapped - don't wrap again. */ - return -1; + return FALSE; } /* @@ -1067,13 +1067,13 @@ reread: */ if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen, err, err_info)) - return -1; + return FALSE; /* * If there's extra stuff at the end of the record, skip it. */ if (file_seek(wth->fh, padding, SEEK_CUR, err) == -1) - return -1; + return FALSE; /* * If it's an ATM packet, and we don't have enough information @@ -1081,16 +1081,16 @@ reread: * attempt to guess them from the packet data. */ netxray_guess_atm_type(wth, &wth->phdr, wth->frame_buffer); - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean netxray_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (netxray_process_rec_header(wth, wth->random_fh, phdr, err, err_info) == -1) { @@ -1102,7 +1102,7 @@ netxray_seek_read(wtap *wth, gint64 seek_off, */ *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } /* @@ -1110,7 +1110,7 @@ netxray_seek_read(wtap *wth, gint64 seek_off, */ if (!wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen, err, err_info)) - return -1; + return FALSE; /* * If it's an ATM packet, and we don't have enough information @@ -1118,7 +1118,7 @@ netxray_seek_read(wtap *wth, gint64 seek_off, * attempt to guess them from the packet data. */ netxray_guess_atm_type(wth, phdr, buf); - return REC_TYPE_PACKET; + return TRUE; } static int diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index 1eafa3f150..8138a31f44 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -509,9 +509,9 @@ static int process_rec_header2_v2(wtap *wth, unsigned char *buffer, guint16 length, int *err, gchar **err_info); static int process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length, gint16 maj_vers, int *err, gchar **err_info); -static int ngsniffer_read(wtap *wth, int *err, gchar **err_info, +static gboolean ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int ngsniffer_seek_read(wtap *wth, gint64 seek_off, +static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int ngsniffer_process_record(wtap *wth, gboolean is_random, guint *padding, struct wtap_pkthdr *phdr, Buffer *buf, int *err, @@ -1053,7 +1053,7 @@ process_rec_header2_v145(wtap *wth, unsigned char *buffer, guint16 length, } /* Read the next packet */ -static int +static gboolean ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { ngsniffer_t *ngsniffer; @@ -1075,7 +1075,7 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) &wth->phdr, wth->frame_buffer, err, err_info); if (ret < 0) { /* Read error or short read */ - return -1; + return FALSE; } /* @@ -1093,16 +1093,16 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) if (padding != 0) { if (!ng_file_skip_seq(wth, padding, err, err_info)) - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; case REC_EOF: /* * End of file. Return an EOF indication. */ *err = 0; /* EOF, not error */ - return -1; + return FALSE; default: /* @@ -1114,26 +1114,26 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) if (padding != 0) { if (!ng_file_skip_seq(wth, padding, err, err_info)) - return -1; + return FALSE; } break; } } } -static int +static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { int ret; if (!ng_file_seek_rand(wth, seek_off, err, err_info)) - return -1; + return FALSE; ret = ngsniffer_process_record(wth, TRUE, NULL, phdr, buf, err, err_info); if (ret < 0) { /* Read error or short read */ - return -1; + return FALSE; } /* @@ -1152,10 +1152,10 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off, * "Can't happen". */ g_assert_not_reached(); - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } /* diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c index 5970b00d20..313cf3e5b8 100644 --- a/wiretap/packetlogger.c +++ b/wiretap/packetlogger.c @@ -44,11 +44,11 @@ typedef struct packetlogger_header { guint64 ts; } packetlogger_header_t; -static int packetlogger_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); -static int packetlogger_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, - Buffer *buf, int *err, gchar **err_info); +static gboolean packetlogger_read(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); +static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, + Buffer *buf, int *err, gchar **err_info); static gboolean packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, int *err, gchar **err_info); static gboolean packetlogger_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, @@ -93,31 +93,29 @@ int packetlogger_open(wtap *wth, int *err, gchar **err_info) return 1; /* Our kind of file */ } -static int +static gboolean packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); - if (!packetlogger_read_packet(wth->fh, &wth->phdr, - wth->frame_buffer, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return packetlogger_read_packet(wth->fh, &wth->phdr, + wth->frame_buffer, err, err_info); } -static int +static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if(!packetlogger_read_packet(wth->random_fh, phdr, buf, err, err_info)) { if(*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static gboolean diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index 2132858770..a0be4a9eaa 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -2257,7 +2257,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) /* classic wtap: read packet */ -static int +static gboolean pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { pcapng_t *pcapng = (pcapng_t *)wth->priv; @@ -2282,7 +2282,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) if (bytes_read <= 0) { pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset); pcapng_debug0("pcapng_read: couldn't read packet block"); - return -1; + return FALSE; } switch (wblock.type) { @@ -2292,7 +2292,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) wth->phdr.pkt_encap = WTAP_ENCAP_UNKNOWN; *err = WTAP_ERR_UNSUPPORTED; *err_info = g_strdup_printf("pcapng: multi-section files not currently supported"); - return -1; + return FALSE; case(BLOCK_TYPE_PB): case(BLOCK_TYPE_SPB): @@ -2361,12 +2361,12 @@ got_packet: /*pcapng_debug2("Read length: %u Packet length: %u", bytes_read, wth->phdr.caplen);*/ pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset + bytes_read); - return REC_TYPE_PACKET; + return TRUE; } /* classic wtap: seek to file position and read packet */ -static int +static gboolean pcapng_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) @@ -2380,7 +2380,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, /* seek to the right file position */ bytes_read64 = file_seek(wth->random_fh, seek_off, SEEK_SET, err); if (bytes_read64 <= 0) { - return -1; /* Seek error */ + return FALSE; /* Seek error */ } pcapng_debug1("pcapng_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off); @@ -2393,7 +2393,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, if (bytes_read <= 0) { pcapng_debug3("pcapng_seek_read: couldn't read packet block (err=%d, errno=%d, bytes_read=%d).", *err, errno, bytes_read); - return -1; + return FALSE; } /* block must be a "Packet Block", an "Enhanced Packet Block", @@ -2404,7 +2404,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off, return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c index 3d9e8dc086..a10ae66fd5 100644 --- a/wiretap/peekclassic.c +++ b/wiretap/peekclassic.c @@ -358,7 +358,7 @@ int peekclassic_open(wtap *wth, int *err, gchar **err_info) return 1; } -static int peekclassic_read_v7(wtap *wth, int *err, gchar **err_info, +static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int sliceLength; @@ -369,38 +369,38 @@ static int peekclassic_read_v7(wtap *wth, int *err, gchar **err_info, sliceLength = peekclassic_read_packet_v7(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); if (sliceLength < 0) - return -1; + return FALSE; /* Skip extra ignored data at the end of the packet. */ if ((guint32)sliceLength > wth->phdr.caplen) { if (!file_skip(wth->fh, sliceLength - wth->phdr.caplen, err)) - return -1; + return FALSE; } /* Records are padded to an even length, so if the slice length is odd, read the padding byte. */ if (sliceLength & 0x01) { if (!file_skip(wth->fh, 1, err)) - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } -static int peekclassic_seek_read_v7(wtap *wth, gint64 seek_off, +static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* Read the packet. */ if (peekclassic_read_packet_v7(wth, wth->random_fh, phdr, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, @@ -493,7 +493,7 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, return sliceLength; } -static int peekclassic_read_v56(wtap *wth, int *err, gchar **err_info, +static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { *data_offset = file_tell(wth->fh); @@ -501,29 +501,29 @@ static int peekclassic_read_v56(wtap *wth, int *err, gchar **err_info, /* read the packet */ if (!peekclassic_read_packet_v56(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) - return -1; + return FALSE; /* * XXX - is the captured packet data padded to a multiple * of 2 bytes? */ - return REC_TYPE_PACKET; + return TRUE; } static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* read the packet */ if (!peekclassic_read_packet_v56(wth, wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh, diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c index 3007bdf99a..05dc8beaef 100644 --- a/wiretap/peektagged.c +++ b/wiretap/peektagged.c @@ -123,9 +123,9 @@ typedef struct { gboolean has_fcs; } peektagged_t; -static int peektagged_read(wtap *wth, int *err, gchar **err_info, +static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int peektagged_seek_read(wtap *wth, gint64 seek_off, +static gboolean peektagged_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int wtap_file_read_pattern (wtap *wth, const char *pattern, int *err, @@ -633,7 +633,7 @@ peektagged_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, return skip_len; } -static int peektagged_read(wtap *wth, int *err, gchar **err_info, +static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int skip_len; @@ -644,29 +644,29 @@ static int peektagged_read(wtap *wth, int *err, gchar **err_info, skip_len = peektagged_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); if (skip_len == -1) - return -1; + return FALSE; if (skip_len != 0) { /* Skip extra junk at the end of the packet data. */ if (!file_skip(wth->fh, skip_len, err)) - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean peektagged_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* Read the packet. */ if (peektagged_read_packet(wth, wth->random_fh, phdr, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c index 319ada0feb..6ba142485b 100644 --- a/wiretap/pppdump.c +++ b/wiretap/pppdump.c @@ -95,9 +95,9 @@ typedef enum { DIRECTION_RECV } direction_enum; -static int pppdump_read(wtap *wth, int *err, gchar **err_info, +static gboolean pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int pppdump_seek_read(wtap *wth, gint64 seek_off, +static gboolean pppdump_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); /* @@ -327,7 +327,7 @@ pppdump_set_phdr(struct wtap_pkthdr *phdr, int num_bytes, } /* Find the next packet and parse it; called from wtap_read(). */ -static int +static gboolean pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int num_bytes; @@ -344,7 +344,7 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) pid = g_new(pkt_id, 1); if (!pid) { *err = errno; /* assume a malloc failed and set "errno" */ - return -1; + return FALSE; } pid->offset = 0; } else @@ -357,7 +357,7 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) pid, 0)) { if (pid != NULL) g_free(pid); - return -1; + return FALSE; } if (pid != NULL) @@ -374,7 +374,7 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) wth->phdr.ts.nsecs = state->tenths * 100000000; pppdump_set_phdr(&wth->phdr, num_bytes, direction); - return REC_TYPE_PACKET; + return TRUE; } /* Returns number of bytes copied for record, -1 if failure. @@ -715,7 +715,7 @@ done: /* Used to read packets in random-access fashion */ -static int +static gboolean pppdump_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, @@ -736,11 +736,11 @@ pppdump_seek_read(wtap *wth, if (!pid) { *err = WTAP_ERR_BAD_FILE; /* XXX - better error? */ *err_info = g_strdup("pppdump: PID not found for record"); - return -1; + return FALSE; } if (file_seek(wth->random_fh, pid->offset, SEEK_SET, err) == -1) - return -1; + return FALSE; init_state(state->seek_state); state->seek_state->offset = pid->offset; @@ -763,13 +763,13 @@ pppdump_seek_read(wtap *wth, do { if (!collate(state->seek_state, wth->random_fh, err, err_info, pd, &num_bytes, &direction, NULL, num_bytes_to_skip)) - return -1; + return FALSE; num_bytes_to_skip = 0; } while (direction != pid->dir); pppdump_set_phdr(phdr, num_bytes, pid->dir); - return REC_TYPE_PACKET; + return TRUE; } static void diff --git a/wiretap/radcom.c b/wiretap/radcom.c index 16df1397e7..e056cdd691 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -84,9 +84,9 @@ struct radcomrec_hdr { char xxw[9]; /* unknown */ }; -static int radcom_read(wtap *wth, int *err, gchar **err_info, +static gboolean radcom_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int radcom_seek_read(wtap *wth, gint64 seek_off, +static gboolean radcom_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); @@ -252,8 +252,8 @@ read_error: } /* Read the next packet */ -static int radcom_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) +static gboolean radcom_read(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset) { int bytes_read; char fcs[2]; @@ -264,7 +264,7 @@ static int radcom_read(wtap *wth, int *err, gchar **err_info, if (!radcom_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) { /* Read error or EOF */ - return -1; + return FALSE; } if (wth->file_encap == WTAP_ENCAP_LAPB) { @@ -278,20 +278,20 @@ static int radcom_read(wtap *wth, int *err, gchar **err_info, *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } } - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean radcom_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* Read record. */ if (!radcom_read_rec(wth, wth->random_fh, phdr, buf, err, @@ -301,9 +301,9 @@ radcom_seek_read(wtap *wth, gint64 seek_off, /* EOF means "short read" in random-access mode */ *err = WTAP_ERR_SHORT_READ; } - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static gboolean diff --git a/wiretap/snoop.c b/wiretap/snoop.c index 8001ddf58c..265d23f4a2 100644 --- a/wiretap/snoop.c +++ b/wiretap/snoop.c @@ -84,9 +84,9 @@ struct shomiti_trailer { #define RX_STATUS_FIFO_ERROR 0x0080 /* receive FIFO error */ #define RX_STATUS_TRIGGERED 0x0001 /* frame did trigger */ -static int snoop_read(wtap *wth, int *err, gchar **err_info, +static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int snoop_seek_read(wtap *wth, gint64 seek_off, +static gboolean snoop_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static int snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); @@ -447,7 +447,7 @@ typedef struct { /* Read the next packet */ -static int snoop_read(wtap *wth, int *err, gchar **err_info, +static gboolean snoop_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int padbytes; @@ -460,7 +460,7 @@ static int snoop_read(wtap *wth, int *err, gchar **err_info, padbytes = snoop_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); if (padbytes == -1) - return -1; + return FALSE; /* * Skip over the padding (don't "fseek()", as the standard @@ -482,27 +482,27 @@ static int snoop_read(wtap *wth, int *err, gchar **err_info, *err = file_error(wth->fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } padbytes -= bytes_read; } - return REC_TYPE_PACKET; + return TRUE; } -static int +static gboolean snoop_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; if (snoop_read_packet(wth, wth->random_fh, phdr, buf, err, err_info) == -1) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static int diff --git a/wiretap/stanag4607.c b/wiretap/stanag4607.c index 8c0625c74f..12bc05885c 100644 --- a/wiretap/stanag4607.c +++ b/wiretap/stanag4607.c @@ -48,8 +48,8 @@ static gboolean is_valid_id(guint16 version_id) return TRUE; } -static int stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, - Buffer *buf, int *err, gchar **err_info) +static gboolean stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, + Buffer *buf, int *err, gchar **err_info) { stanag4607_t *stanag4607 = (stanag4607_t *)wth->priv; guint32 millisecs, secs, nsecs; @@ -69,7 +69,7 @@ static int stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, if (!is_valid_id(pntoh16(&stanag_pkt_hdr[0]))) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("Bad version number"); - return -1; + return FALSE; } /* The next 4 bytes are the packet length */ @@ -133,19 +133,16 @@ static int stanag4607_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, /* wind back to the start of the packet ... */ if (file_seek(fh, - offset, SEEK_CUR, err) == -1) - return -1; + goto fail; - if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) - return -1; - - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); fail: *err = file_error(wth->fh, err_info); - return -1; + return FALSE; } -static int stanag4607_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean stanag4607_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -158,12 +155,12 @@ static int stanag4607_read(wtap *wth, int *err, gchar **err_info, gint64 *data_o return stanag4607_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); } -static int stanag4607_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, - Buffer *buf, int *err, gchar **err_info) +static gboolean stanag4607_seek_read(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, + Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; return stanag4607_read_file(wth, wth->random_fh, phdr, buf, err, err_info); } diff --git a/wiretap/tnef.c b/wiretap/tnef.c index a08d42fb2c..5bd2fa1463 100644 --- a/wiretap/tnef.c +++ b/wiretap/tnef.c @@ -30,14 +30,14 @@ #include "buffer.h" #include "tnef.h" -static int tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, - Buffer *buf, int *err, gchar **err_info) +static gboolean tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, + Buffer *buf, int *err, gchar **err_info) { gint64 file_size; int packet_size; if ((file_size = wtap_file_size(wth, err)) == -1) - return -1; + return FALSE; if (file_size > WTAP_MAX_PACKET_SIZE) { /* @@ -47,7 +47,7 @@ static int tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("tnef: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u", file_size, WTAP_MAX_PACKET_SIZE); - return -1; + return FALSE; } packet_size = (int)file_size; @@ -59,12 +59,10 @@ static int tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, phdr->ts.secs = 0; phdr->ts.nsecs = 0; - if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info); } -static int tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -74,25 +72,25 @@ static int tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* there is only ever one packet */ if (offset) - return -1; + return FALSE; *data_offset = offset; return tnef_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); } -static int tnef_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, - Buffer *buf, int *err, gchar **err_info) +static gboolean tnef_seek_read(wtap *wth, gint64 seek_off, + struct wtap_pkthdr *phdr, + Buffer *buf, int *err, gchar **err_info) { /* there is only one packet */ if(seek_off > 0) { *err = 0; - return -1; + return FALSE; } if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; return tnef_read_file(wth, wth->random_fh, phdr, buf, err, err_info); } diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c index 6e8ab1a178..6fcf40270b 100644 --- a/wiretap/toshiba.c +++ b/wiretap/toshiba.c @@ -105,9 +105,9 @@ static const char toshiba_rec_magic[] = { '[', 'N', 'o', '.' }; */ #define TOSHIBA_MAX_PACKET_LEN 16384 -static int toshiba_read(wtap *wth, int *err, gchar **err_info, +static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int toshiba_seek_read(wtap *wth, gint64 seek_off, +static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset); @@ -214,7 +214,7 @@ int toshiba_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static int toshiba_read(wtap *wth, int *err, gchar **err_info, +static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset; @@ -222,31 +222,29 @@ static int toshiba_read(wtap *wth, int *err, gchar **err_info, /* Find the next packet */ offset = toshiba_seek_next_packet(wth, err, err_info); if (offset < 1) - return -1; + return FALSE; *data_offset = offset; /* Parse the packet */ - if (!parse_toshiba_packet(wth->fh, &wth->phdr, wth->frame_buffer, - err, err_info)) - return -1; - return REC_TYPE_PACKET; + return parse_toshiba_packet(wth->fh, &wth->phdr, wth->frame_buffer, + err, err_info); } /* Used to read packets in random-access fashion */ -static int +static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) - return -1; + return FALSE; if (!parse_toshiba_packet(wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } /* Parses a packet. */ diff --git a/wiretap/visual.c b/wiretap/visual.c index 67a7d481f9..cfa03bceac 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -158,9 +158,9 @@ struct visual_write_info /* Local functions to handle file reads and writes */ -static int visual_read(wtap *wth, int *err, gchar **err_info, +static gboolean visual_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int visual_seek_read(wtap *wth, gint64 seek_off, +static gboolean visual_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); @@ -281,7 +281,7 @@ int visual_open(wtap *wth, int *err, gchar **err_info) in a loop to sequentially read the entire file one time. After the file has been read once, any Future access to the packets is done through seek_read. */ -static int visual_read(wtap *wth, int *err, gchar **err_info, +static gboolean visual_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { struct visual_read_info *visual = (struct visual_read_info *)wth->priv; @@ -292,33 +292,31 @@ static int visual_read(wtap *wth, int *err, gchar **err_info, if (visual->current_pkt > visual->num_pkts) { *err = 0; /* it's just an EOF, not an error */ - return -1; + return FALSE; } visual->current_pkt++; *data_offset = file_tell(wth->fh); - if (!visual_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer, - err, err_info)) - return -1; - return REC_TYPE_PACKET; + return visual_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer, + err, err_info); } /* Read packet header and data for random access. */ -static int visual_seek_read(wtap *wth, gint64 seek_off, +static gboolean visual_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { /* Seek to the packet header */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* Read the packet. */ if (!visual_read_packet(wth, wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } static gboolean diff --git a/wiretap/vms.c b/wiretap/vms.c index 90d5e24acc..3684c3bbbe 100644 --- a/wiretap/vms.c +++ b/wiretap/vms.c @@ -139,9 +139,9 @@ to handle them. #define VMS_HEADER_LINES_TO_CHECK 200 #define VMS_LINE_LENGTH 240 -static int vms_read(wtap *wth, int *err, gchar **err_info, +static gboolean vms_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static int vms_seek_read(wtap *wth, gint64 seek_off, +static gboolean vms_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, long byte_offset, int in_off, int remaining_bytes); @@ -255,7 +255,7 @@ int vms_open(wtap *wth, int *err, gchar **err_info) } /* Find the next packet and parse it; called from wtap_read(). */ -static int vms_read(wtap *wth, int *err, gchar **err_info, +static gboolean vms_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { gint64 offset = 0; @@ -268,14 +268,12 @@ static int vms_read(wtap *wth, int *err, gchar **err_info, #endif if (offset < 1) { *err = file_error(wth->fh, err_info); - return -1; + return FALSE; } *data_offset = offset; /* Parse the packet */ - if (!parse_vms_packet(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) - return -1; - return REC_TYPE_PACKET; + return parse_vms_packet(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info); } /* Used to read packets in random-access fashion */ @@ -284,14 +282,14 @@ vms_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) - return -1; + return FALSE; if (!parse_vms_packet(wth->random_fh, phdr, buf, err, err_info)) { if (*err == 0) *err = WTAP_ERR_SHORT_READ; - return -1; + return FALSE; } - return REC_TYPE_PACKET; + return TRUE; } /* isdumpline assumes that dump lines start with some non-alphanumerics diff --git a/wiretap/vwr.c b/wiretap/vwr.c index 518ebaf46c..7d0b291c62 100644 --- a/wiretap/vwr.c +++ b/wiretap/vwr.c @@ -496,8 +496,8 @@ static guint8 get_ofdm_rate(const guint8 *); static guint8 get_cck_rate(const guint8 *plcp); static void setup_defaults(vwr_t *, guint16); -static int vwr_read(wtap *, int *, gchar **, gint64 *); -static int vwr_seek_read(wtap *, gint64, struct wtap_pkthdr *phdr, +static gboolean vwr_read(wtap *, int *, gchar **, gint64 *); +static gboolean vwr_seek_read(wtap *, gint64, struct wtap_pkthdr *phdr, Buffer *, int *, gchar **); static gboolean vwr_read_rec_header(vwr_t *, FILE_T, int *, int *, int *, gchar **); @@ -571,14 +571,14 @@ int vwr_open(wtap *wth, int *err, gchar **err_info) /* frame, and a 64-byte statistics block trailer. */ /* The PLCP frame consists of a 4-byte or 6-byte PLCP header, followed by the MAC frame */ -static int vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) +static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { vwr_t *vwr = (vwr_t *)wth->priv; int rec_size = 0, IS_TX; /* read the next frame record header in the capture file; if no more frames, return */ if (!vwr_read_rec_header(vwr, wth->fh, &rec_size, &IS_TX, err, err_info)) - return -1; /* Read error or EOF */ + return FALSE; /* Read error or EOF */ /* * We're past the header; return the offset of the header, not of @@ -589,7 +589,7 @@ static int vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) /* got a frame record; read and process it */ if (!vwr_process_rec_data(wth->fh, rec_size, &wth->phdr, wth->frame_buffer, vwr, IS_TX, err, err_info)) - return -1; + return FALSE; /* If the per-file encapsulation isn't known, set it to this packet's encapsulation. */ /* If it *is* known, and it isn't this packet's encapsulation, set it to */ @@ -602,12 +602,12 @@ static int vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) wth->file_encap = WTAP_ENCAP_PER_PACKET; } - return REC_TYPE_PACKET; + return TRUE; } /* read a random record in the middle of a file; the start of the record is @ seek_off */ -static int vwr_seek_read(wtap *wth, gint64 seek_off, +static gboolean vwr_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { vwr_t *vwr = (vwr_t *)wth->priv; @@ -615,17 +615,14 @@ static int vwr_seek_read(wtap *wth, gint64 seek_off, /* first seek to the indicated record header */ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return -1; + return FALSE; /* read in the record header */ if (!vwr_read_rec_header(vwr, wth->random_fh, &rec_size, &IS_TX, err, err_info)) - return -1; /* Read error or EOF */ + return FALSE; /* Read error or EOF */ - if (!vwr_process_rec_data(wth->random_fh, rec_size, phdr, buf, - vwr, IS_TX, err, err_info)) - return -1; - - return REC_TYPE_PACKET; + return vwr_process_rec_data(wth->random_fh, rec_size, phdr, buf, + vwr, IS_TX, err, err_info); } /* Scan down in the input capture file to find the next frame header. */ diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index 8291609b73..dfa3441835 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -40,10 +40,10 @@ WS_DLL_PUBLIC int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err); -typedef int (*subtype_read_func)(struct wtap*, int*, char**, gint64*); -typedef int (*subtype_seek_read_func)(struct wtap*, gint64, - struct wtap_pkthdr *, Buffer *, - int *, char **); +typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*); +typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, + struct wtap_pkthdr *, Buffer *buf, + int *, char **); /** * Struct holding data of the currently read file. */ diff --git a/wiretap/wtap.c b/wiretap/wtap.c index f03900cfbf..c32524be80 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -975,11 +975,9 @@ void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6) { wth->add_new_ipv6 = add_new_ipv6; } -int +gboolean wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { - int rectype; - /* * Set the packet encapsulation to the file's encapsulation * value; if that's not WTAP_ENCAP_PER_PACKET, it's the @@ -990,8 +988,7 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) */ wth->phdr.pkt_encap = wth->file_encap; - rectype = wth->subtype_read(wth, err, err_info, data_offset); - if (rectype == -1) { + if (!wth->subtype_read(wth, err, err_info, data_offset)) { /* * If we didn't get an error indication, we read * the last packet. See if there's any deferred @@ -1003,7 +1000,7 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) */ if (*err == 0) *err = file_error(wth->fh, err_info); - return rectype; /* failure */ + return FALSE; /* failure */ } /* @@ -1021,7 +1018,7 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) */ g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET); - return rectype; + return TRUE; /* success */ } /* @@ -1074,15 +1071,12 @@ wtap_buf_ptr(wtap *wth) return buffer_start_ptr(wth->frame_buffer); } -int +gboolean wtap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { - int rectype; - - rectype = wth->subtype_seek_read(wth, seek_off, phdr, buf, err, err_info); - if (rectype == -1) - return rectype; + if (!wth->subtype_seek_read(wth, seek_off, phdr, buf, err, err_info)) + return FALSE; /* * It makes no sense for the captured data length to be bigger @@ -1099,5 +1093,5 @@ wtap_seek_read(wtap *wth, gint64 seek_off, */ g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET); - return rectype; + return TRUE; } diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 3e47b3c8dc..005d748304 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1349,24 +1349,15 @@ typedef void (*wtap_new_ipv6_callback_t) (const void *addrp, const gchar *name); WS_DLL_PUBLIC void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6); -/* - * Values returned by wtap_read() and wtap_seek_read(). They indicate the - * type of record read by that routine. - * - * This list will expand over time, so don't assume everything will be a - * file-type-specific record or a packet record. - */ -#define REC_TYPE_FILE_TYPE_SPECIFIC 0 /* file-type-specific record */ -#define REC_TYPE_PACKET 1 /* packet */ - -/** Returns a REC_TYPE_ value if read was successful, -1 if it failed. - * *data_offset is set to the offset in the file where the data for - * the read packet is located. */ +/** Returns TRUE if read was successful. FALSE if failure. data_offset is + * set to the offset in the file where the data for the read packet is + * located. */ WS_DLL_PUBLIC -int wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); +gboolean wtap_read(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); WS_DLL_PUBLIC -int wtap_seek_read (wtap *wth, gint64 seek_off, +gboolean wtap_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info); /*** get various information snippets about the current packet ***/