diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-01-25 21:55:17 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-01-25 21:55:17 +0000 |
commit | d6cd61061efe7207b298b5ac40a92e7b86b00b3e (patch) | |
tree | 392720e018248f9cf2b46db00a4a9740ff7d1fca /wiretap/network_instruments.c | |
parent | 34bddb3c1a932632fd0515f7999ed96ef9974611 (diff) | |
download | wireshark-d6cd61061efe7207b298b5ac40a92e7b86b00b3e.tar.gz wireshark-d6cd61061efe7207b298b5ac40a92e7b86b00b3e.tar.bz2 wireshark-d6cd61061efe7207b298b5ac40a92e7b86b00b3e.zip |
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
Diffstat (limited to 'wiretap/network_instruments.c')
-rw-r--r-- | wiretap/network_instruments.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index 594945eebd..4bd41fda4e 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -1,5 +1,5 @@ /* - * $Id: network_instruments.c,v 1.6 2004/01/05 17:33:28 ulfl Exp $ + * $Id: network_instruments.c,v 1.7 2004/01/25 21:55:16 guy Exp $ */ /*************************************************************************** @@ -96,14 +96,16 @@ static void init_time_offset(void) } static gboolean fill_time_struct(guint64 ns_since2000, observer_time* time_conversion); -static gboolean observer_read(wtap *wth, int *err, long *data_offset); +static gboolean observer_read(wtap *wth, int *err, gchar **err_info, + long *data_offset); static gboolean observer_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err); + union wtap_pseudo_header *pseudo_header, guchar *pd, int length, + int *err, gchar **err_info); static gboolean observer_dump_close(wtap_dumper *wdh, int *err); static gboolean observer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err); -int network_instruments_open(wtap *wth, int *err) +int network_instruments_open(wtap *wth, int *err, gchar **err_info) { int bytes_read; @@ -128,8 +130,8 @@ int network_instruments_open(wtap *wth, int *err) /* check the version */ if (strncmp(network_instruments_magic, file_header.observer_version, 30)!=0) { - g_message("Observer: unsupported file version %s", file_header.observer_version); *err = WTAP_ERR_UNSUPPORTED_ENCAP; + *err_info = g_strdup_printf("Observer: unsupported file version %s", file_header.observer_version); return -1; } @@ -155,15 +157,15 @@ int network_instruments_open(wtap *wth, int *err) /* check the packet's magic number; the magic number is all 8's, so the byte order doesn't matter */ if (packet_header.packet_magic != observer_packet_magic) { - g_message("Observer: unsupported packet version %ul", packet_header.packet_magic); *err = WTAP_ERR_UNSUPPORTED_ENCAP; + *err_info = g_strdup_printf("Observer: unsupported packet version %ul", packet_header.packet_magic); return -1; } /* Check the data link type. */ if (packet_header.network_type >= NUM_OBSERVER_ENCAPS) { - g_message("observer: network type %u unknown or unsupported", packet_header.network_type); *err = WTAP_ERR_UNSUPPORTED_ENCAP; + *err_info = g_strdup_printf("observer: network type %u unknown or unsupported", packet_header.network_type); return -1; } wth->file_encap = observer_encap[packet_header.network_type]; @@ -192,7 +194,8 @@ int network_instruments_open(wtap *wth, int *err) } /* reads the next packet */ -static gboolean observer_read(wtap *wth, int *err, long *data_offset) +static gboolean observer_read(wtap *wth, int *err, gchar **err_info, + long *data_offset) { int bytes_read; long seek_increment; @@ -217,8 +220,8 @@ static gboolean observer_read(wtap *wth, int *err, long *data_offset) /* check the packet's magic number; the magic number is all 8's, so the byte order doesn't matter */ if (packet_header.packet_magic != observer_packet_magic) { - g_message("Observer: bad record"); *err = WTAP_ERR_BAD_RECORD; + *err_info = g_strdup("Observer: bad record"); return FALSE; } @@ -244,10 +247,10 @@ static gboolean observer_read(wtap *wth, int *err, long *data_offset) packet_header.offset_to_frame = GUINT16_FROM_LE(packet_header.offset_to_frame); if (packet_header.offset_to_frame < sizeof(packet_header)) { - g_message("Observer: bad record (offset to frame %u < %lu)", + *err = WTAP_ERR_BAD_RECORD; + *err_info = g_strdup_printf("Observer: bad record (offset to frame %u < %lu)", packet_header.offset_to_frame, (unsigned long)sizeof(packet_header)); - *err = WTAP_ERR_BAD_RECORD; return FALSE; } seek_increment = packet_header.offset_to_frame - sizeof(packet_header); @@ -276,7 +279,8 @@ static gboolean observer_read(wtap *wth, int *err, long *data_offset) /* reads a packet at an offset */ static gboolean observer_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err) + union wtap_pseudo_header *pseudo_header, guchar *pd, int length, + int *err, gchar **err_info) { packet_entry_header packet_header; @@ -296,8 +300,8 @@ static gboolean observer_seek_read(wtap *wth, long seek_off, /* check the packets magic number */ if (packet_header.packet_magic != observer_packet_magic) { - g_message("Observer: bad record in observer_seek_read"); *err = WTAP_ERR_BAD_RECORD; + *err_info = g_strdup("Observer: bad magic number for record in observer_seek_read"); return FALSE; } @@ -305,7 +309,6 @@ static gboolean observer_seek_read(wtap *wth, long seek_off, bytes_read = file_read(pd, 1, length, wth->random_fh); if (bytes_read != length) { *err = file_error(wth->fh); - g_message("Observer: read error in observer_seek_read"); return FALSE; } |