From c0c480d08c175eed4524ea9e73ec86298f468cf4 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 22 May 2014 20:01:31 -0700 Subject: Allow wtap_read() and wtap_seek_read() to return non-packet records. This is the first step towards implementing the mechanisms requestd in bug 8590; currently, we don't return any records other than packet records from libwiretap, and just ignore non-packet records in the rest of Wireshark, but this at least gets the ball rolling. Change-Id: I34a45b54dd361f69fdad1a758d8ca4f42d67d574 Reviewed-on: https://code.wireshark.org/review/1736 Reviewed-by: Guy Harris --- wiretap/network_instruments.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'wiretap/network_instruments.c') diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index 38abfab2cd..01ed983932 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -94,9 +94,9 @@ static void init_gmt_to_localtime_offset(void) } } -static gboolean observer_read(wtap *wth, int *err, gchar **err_info, +static int observer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); -static gboolean observer_seek_read(wtap *wth, gint64 seek_off, +static int 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 gboolean observer_read(wtap *wth, int *err, gchar **err_info, +static int observer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { int header_bytes_consumed; @@ -273,7 +273,7 @@ static gboolean 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 FALSE; /* EOF or error */ + return -1; /* EOF or error */ if (packet_header.packet_type == PACKET_TYPE_DATA_PACKET) break; @@ -281,32 +281,32 @@ static gboolean 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 FALSE; /* EOF or error */ + return -1; /* EOF or error */ } } if (!process_packet_header(wth, &packet_header, &wth->phdr, err, err_info)) - return FALSE; + return -1; /* 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 FALSE; + return -1; } /* 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 FALSE; + return -1; } - return TRUE; + return REC_TYPE_PACKET; } /* Reads a packet at an offset. */ -static gboolean observer_seek_read(wtap *wth, gint64 seek_off, +static int 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 gboolean 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 FALSE; + return -1; /* process the packet header, including TLVs */ offset = read_packet_header(wth->random_fh, pseudo_header, &packet_header, err, err_info); if (offset <= 0) - return FALSE; /* EOF or error */ + return -1; /* EOF or error */ if (!process_packet_header(wth, &packet_header, phdr, err, err_info)) - return FALSE; + return -1; /* 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 FALSE; + return -1; } - return TRUE; + return REC_TYPE_PACKET; } static int -- cgit v1.2.3