Clean up some things we ran across while making those changes.
Change-Id: Ic0d8943d36e6e120d7af0a6148fad98015d1e83e
Reviewed-on: https://code.wireshark.org/review/4581
Reviewed-by: Guy Harris <guy@alum.mit.edu>
* If the routine handles this type of file, it should set the "file_type"
* field in the "struct wtap" to the type of the file.
*/
-static int
+static wtap_open_return_val
wslua_filehandler_open(wtap *wth, int *err, gchar **err_info)
{
FileHandler fh = (FileHandler)(wth->wslua_data);
- int retval = 0;
+ wtap_open_return_val retval = WTAP_OPEN_NOT_MINE;
lua_State* L = NULL;
File *fp = NULL;
CaptureInfo *fc = NULL;
(*fp)->expired = TRUE;
(*fc)->expired = TRUE;
- if (retval == 1) {
+ if (retval == WTAP_OPEN_MINE) {
/* this is our file type - set the routines and settings into wtap */
if (fh->read_ref != LUA_NOREF) {
wth->file_type_subtype = fh->file_type;
}
- else if (retval == -1) {
+ else if (retval == WTAP_OPEN_ERROR) {
/* open error - we *must* return an error code! */
if (err) {
*err = WTAP_ERR_CANT_OPEN;
}
}
- else if (retval == 0) {
+ else if (retval == WTAP_OPEN_NOT_MINE) {
/* not our file type */
remove_wth_priv(L, wth);
}
if (err) {
*err = WTAP_ERR_INTERNAL;
}
- retval = -1;
+ retval = WTAP_OPEN_ERROR;
}
lua_settop(L,0);
static gboolean _5views_dump_close(wtap_dumper *wdh, int *err);
-int _5views_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val
+_5views_open(wtap *wth, int *err, gchar **err_info)
{
t_5VW_Capture_Header Capture_Header;
int encap = WTAP_ENCAP_UNKNOWN;
if (!wtap_read_bytes(wth->fh, &Capture_Header.Info_Header,
sizeof(t_5VW_Info_Header), err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* Check whether that's 5Views format or not */
if(Capture_Header.Info_Header.Signature != CST_5VW_INFO_HEADER_KEY)
{
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Check Version */
default:
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("5views: header version %u unsupported", Capture_Header.Info_Header.Version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* Check File Type */
{
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("5views: file is not a capture file (filetype is %u)", Capture_Header.Info_Header.Version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* Check possible Encap */
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("5views: network type %u unknown or unsupported",
Capture_Header.Info_Header.FileType);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* read the remaining header information */
if (!wtap_read_bytes(wth->fh, &Capture_Header.HeaderDateCreation,
sizeof (t_5VW_Capture_Header) - sizeof(t_5VW_Info_Header), err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
/* This is a 5views capture file */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_5VIEWS;
wth->snapshot_length = 0; /* not available in header */
wth->file_tsprec = WTAP_TSPREC_NSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Read the next packet */
static gboolean aethra_read_rec_header(wtap *wth, FILE_T fh, struct aethrarec_hdr *hdr,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
-int aethra_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val aethra_open(wtap *wth, int *err, gchar **err_info)
{
struct aethra_hdr hdr;
struct tm tm;
if (!wtap_read_bytes(wth->fh, hdr.magic, sizeof hdr.magic, err,
err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(hdr.magic, aethra_magic, sizeof aethra_magic) != 0)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
/* Read the rest of the header. */
if (!wtap_read_bytes(wth->fh, (char *)&hdr + sizeof hdr.magic,
sizeof hdr - sizeof hdr.magic, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_AETHRA;
aethra = (aethra_t *)g_malloc(sizeof(aethra_t));
wth->priv = (void *)aethra;
wth->file_encap = WTAP_ENCAP_ISDN;
wth->snapshot_length = 0; /* not available in header */
wth->file_tsprec = WTAP_TSPREC_MSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
#if 0
return packet_off;
}
-int ascend_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info)
{
gint64 offset;
ws_statb64 statbuf;
offset = ascend_seek(wth, err, err_info);
if (offset == -1) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* Do a trial parse of the first packet just found to see if we might really have an Ascend file */
init_parse_ascend();
if (!check_ascend(wth->fh, &wth->phdr)) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ASCEND;
offset that we can apply to each packet.
*/
if (wtap_fstat(wth, &statbuf, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
ascend->inittime = statbuf.st_ctime;
ascend->adjusted = FALSE;
init_parse_ascend();
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Read the next packet; called from wtap_read(). */
return ber_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
}
-int ber_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val ber_open(wtap *wth, int *err, gchar **err_info)
{
#define BER_BYTES_TO_CHECK 8
guint8 bytes[BER_BYTES_TO_CHECK];
if (!wtap_read_bytes(wth->fh, &bytes, BER_BYTES_TO_CHECK, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
ber_id = bytes[offset++];
if(!(ber_pc &&
(((ber_class == BER_CLASS_UNI) && ((ber_tag == BER_UNI_TAG_SET) || (ber_tag == BER_UNI_TAG_SEQ))) ||
((ber_class == BER_CLASS_CON) && (ber_tag < 32)))))
- return 0;
+ return WTAP_OPEN_NOT_MINE;
/* now check the length */
oct = bytes[offset++];
file_size = wtap_file_size(wth, err);
if(len != file_size) {
- return 0; /* not ASN.1 */
+ return WTAP_OPEN_NOT_MINE; /* not ASN.1 */
}
} else {
/* Indefinite length encoded - assume it is BER */
/* seek back to the start of the file */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_BER;
wth->file_encap = WTAP_ENCAP_BER;
wth->subtype_seek_read = ber_seek_read;
wth->file_tsprec = WTAP_TSPREC_SEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
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)
+wtap_open_return_val btsnoop_open(wtap *wth, int *err, gchar **err_info)
{
char magic[sizeof btsnoop_magic];
struct btsnoop_hdr hdr;
/* Read in the string that should be at the start of a "btsnoop" file */
if (!wtap_read_bytes(wth->fh, magic, sizeof magic, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(magic, btsnoop_magic, sizeof btsnoop_magic) != 0) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Read the rest of the header. */
if (!wtap_read_bytes(wth->fh, &hdr, sizeof hdr, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
/*
* Make sure it's a version we support.
if (hdr.version != 1) {
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("btsnoop: version %u unsupported", hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
hdr.datalink = g_ntohl(hdr.datalink);
case KHciLoggerDatalinkTypeBCSP:
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("btsnoop: BCSP capture logs unsupported");
- return -1;
+ return WTAP_OPEN_ERROR;
case KHciLoggerDatalinkTypeH5:
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("btsnoop: H5 capture logs unsupported");
- return -1;
+ return WTAP_OPEN_ERROR;
case KHciLoggerDatalinkLinuxMonitor:
file_encap=WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR;
break;
case KHciLoggerDatalinkBlueZ5Simulator:
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("btsnoop: BlueZ 5 Simulator capture logs unsupported");
- return -1;
+ return WTAP_OPEN_ERROR;
default:
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("btsnoop: datalink type %u unknown or unsupported", hdr.datalink);
- return -1;
+ return WTAP_OPEN_ERROR;
}
wth->subtype_read = btsnoop_read;
wth->snapshot_length = 0; /* not available in header */
wth->file_tsprec = WTAP_TSPREC_USEC;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_BTSNOOP;
- return 1;
+ return WTAP_OPEN_MINE;
}
static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
-int camins_open(wtap *wth, int *err, gchar **err_info _U_)
+wtap_open_return_val camins_open(wtap *wth, int *err, gchar **err_info _U_)
{
guint8 found_start_blocks = 0;
guint8 count = 0;
if (!wtap_read_bytes(wth->fh, block, sizeof(block), err, err_info)) {
if (*err == WTAP_ERR_SHORT_READ)
break;
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (block[0]==0x00 && block[1] == 0xE1)
} while (count<20);
if (found_start_blocks < 2)
- return 0; /* no CAM Inspector file */
+ return WTAP_OPEN_NOT_MINE; /* no CAM Inspector file */
/* rewind the fh so we re-read from the beginning */
if (-1 == file_seek(wth->fh, 0, SEEK_SET, err))
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_encap = WTAP_ENCAP_DVBCI;
wth->snapshot_length = 0;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_CAMINS;
*err = 0;
- return 1;
+ return WTAP_OPEN_MINE;
}
/********************************************/
/* Open file (for reading) */
/********************************************/
-int
+wtap_open_return_val
catapult_dct2000_open(wtap *wth, int *err, gchar **err_info)
{
gint64 offset = 0;
if (!read_new_line(wth->fh, &offset, &firstline_length, linebuff,
sizeof linebuff, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (((size_t)firstline_length < strlen(catapult_dct2000_magic)) ||
firstline_length >= MAX_FIRST_LINE_LENGTH) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* This file is not for us if it doesn't match our signature */
if (memcmp(catapult_dct2000_magic, linebuff, strlen(catapult_dct2000_magic)) != 0) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Make sure table is ready for use */
linebuff, sizeof linebuff, err, err_info)) {
g_free(file_externals);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if ((file_externals->secondline_length >= MAX_TIMESTAMP_LINE_LENGTH) ||
(!get_file_time_stamp(linebuff, ×tamp, &usecs))) {
/* Give up if file time line wasn't valid */
g_free(file_externals);
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Fill in timestamp */
wth->priv = (void*)file_externals;
*err = errno;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Ugly, but much faster than using g_snprintf! */
static gboolean commview_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
-int commview_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val commview_open(wtap *wth, int *err, gchar **err_info)
{
commview_header_t cv_hdr;
if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* If any of these fields do not match what we expect, bail out. */
((cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_ETHERNET &&
(cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_WIFI &&
(cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_TOKEN_RING))
- return 0; /* Not our kind of file */
+ return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
/* No file header. Reset the fh to 0 so we can read the first packet */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
/* Set up the pointers to the handlers for this file type */
wth->subtype_read = commview_read;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1; /* Our kind of file */
+ return WTAP_OPEN_MINE; /* Our kind of file */
}
static int
}
-int cosine_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val cosine_open(wtap *wth, int *err, gchar **err_info)
{
/* Look for CoSine header */
if (!cosine_check_file_type(wth, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) /* rewind */
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_encap = WTAP_ENCAP_COSINE;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_COSINE;
wth->subtype_seek_read = cosine_seek_read;
wth->file_tsprec = WTAP_TSPREC_CSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Find the next packet and parse it; called from wtap_read(). */
guint16 caplen; /* the capture length */
};
-/* XXX - return -1 on I/O error and actually do something with 'err'. */
-int csids_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val csids_open(wtap *wth, int *err, gchar **err_info)
{
/* There is no file header. There is only a header for each packet
* so we read a packet header and compare the caplen with iplen. They
/* check the file to make sure it is a csids file. */
if( !wtap_read_bytes( wth->fh, &hdr, sizeof( struct csids_header), err, err_info ) ) {
if( *err != WTAP_ERR_SHORT_READ ) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if( hdr.zeropad != 0 || hdr.caplen == 0 ) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
hdr.seconds = pntoh32( &hdr.seconds );
hdr.caplen = pntoh16( &hdr.caplen );
if( !wtap_read_bytes( wth->fh, &tmp, 2, err, err_info ) ) {
if( *err != WTAP_ERR_SHORT_READ ) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if( !wtap_read_bytes(wth->fh, &iplen, 2, err, err_info ) ) {
if( *err != WTAP_ERR_SHORT_READ ) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
iplen = pntoh16(&iplen);
if ( iplen == 0 )
- return 0;
+ return WTAP_OPEN_NOT_MINE;
/* if iplen and hdr.caplen are equal, default to no byteswap. */
if( iplen > hdr.caplen ) {
byteswap = TRUE;
} else {
/* don't know this one */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
} else {
byteswap = FALSE;
/* no file header. So reset the fh to 0 so we can read the first packet */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
csids = (csids_t *)g_malloc(sizeof(csids_t));
wth->priv = (void *)csids;
wth->subtype_seek_read = csids_seek_read;
wth->file_tsprec = WTAP_TSPREC_SEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Find the next packet and parse it; called from wtap_read(). */
Buffer *buf, char *readData, int *err, gchar **err_info);
/* Open a file and determine if it's a Daintree file */
-int daintree_sna_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val daintree_sna_open(wtap *wth, int *err, gchar **err_info)
{
char readLine[DAINTREE_MAX_LINE_SIZE];
- guint i;
/* get first line of file header */
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) {
*err = file_error(wth->fh, err_info);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* check magic text */
- i = 0;
- while (i < DAINTREE_MAGIC_TEXT_SIZE) {
- if (readLine[i] != daintree_magic_text[i]) return 0; /* not daintree format */
- i++;
- }
+ if (memcmp(readLine, daintree_magic_text, DAINTREE_MAGIC_TEXT_SIZE) != 0)
+ return WTAP_OPEN_NOT_MINE; /* not daintree format */
/* read second header line */
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) {
*err = file_error(wth->fh, err_info);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
- if (readLine[0] != COMMENT_LINE) return 0; /* daintree files have a two line header */
+ if (readLine[0] != COMMENT_LINE)
+ return WTAP_OPEN_NOT_MINE; /* daintree files have a two line header */
/* set up the pointers to the handlers for this file type */
wth->subtype_read = daintree_sna_read;
wth->file_tsprec = WTAP_TSPREC_USEC;
wth->snapshot_length = 0; /* not available in header */
- return 1; /* it's a Daintree file */
+ return WTAP_OPEN_MINE; /* it's a Daintree file */
}
/* Read the capture file sequentially
}
-int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info)
{
/* Look for DBS ETHERWATCH header */
if (!dbs_etherwatch_check_file_type(wth, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
wth->file_encap = WTAP_ENCAP_ETHERNET;
wth->subtype_seek_read = dbs_etherwatch_seek_read;
wth->file_tsprec = WTAP_TSPREC_CSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Find the next packet and parse it; called from wtap_read(). */
}
-int dct3trace_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val dct3trace_open(wtap *wth, int *err, gchar **err_info)
{
char line1[64], line2[64];
{
*err = file_error(wth->fh, err_info);
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* Don't compare line endings */
if( strncmp(dct3trace_magic_line1, line1, strlen(dct3trace_magic_line1)) != 0 ||
strncmp(dct3trace_magic_line2, line2, strlen(dct3trace_magic_line2)) != 0)
{
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
wth->file_encap = WTAP_ENCAP_GSM_UM;
wth->subtype_seek_read = dct3trace_seek_read;
wth->file_tsprec = WTAP_TSPREC_SEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
#define NUM_ERF_ENCAPS (sizeof erf_to_wtap_map / sizeof erf_to_wtap_map[0])
-extern int erf_open(wtap *wth, int *err, gchar **err_info)
+extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info)
{
int i, n, records_for_erf_check = RECORDS_FOR_ERF_CHECK;
int valid_prev = 0;
/* ERF header too short accept the file,
only if the very first records have been successfully checked */
if (i < MIN_RECORDS_FOR_ERF_CHECK) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
} else {
/* BREAK, the last record is too short, and will be ignored */
break;
}
} else {
- return -1;
+ return WTAP_OPEN_ERROR;
}
}
/* Test valid rlen >= 16 */
if (rlen < 16) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
packet_size = rlen - (guint32)sizeof(header);
* Probably a corrupt capture file or a file that's not an ERF file
* but that passed earlier tests.
*/
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Skip PAD records, timestamps may not be set */
if ((header.type & 0x7F) == ERF_TYPE_PAD) {
if (file_seek(wth->fh, packet_size, SEEK_CUR, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
continue;
}
/* fail on invalid record type, decreasing timestamps or non-zero pad-bits */
/* Not all types within this range are decoded, but it is a first filter */
if ((header.type & 0x7F) == 0 || (header.type & 0x7F) > ERF_TYPE_MAX ) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* The ERF_TYPE_MAX is the PAD record, but the last used type is ERF_TYPE_INFINIBAND_LINK */
if ((header.type & 0x7F) > ERF_TYPE_INFINIBAND_LINK) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if ((ts = pletoh64(&header.ts)) < prevts) {
/* reassembled AALx records may not be in time order, also records are not in strict time order between physical interfaces, so allow 1 sec fudge */
if ( ((prevts-ts)>>32) > 1 ) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
}
/* Check to see if timestamp increment is > 1 week */
if ( (valid_prev) && (ts > prevts) && (((ts-prevts)>>32) > 3600*24*7) ) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
memcpy(&prevts, &ts, sizeof(prevts));
if (!wtap_read_bytes(wth->fh,&erf_ext_header,sizeof(erf_ext_header),err,err_info)) {
if (*err == WTAP_ERR_SHORT_READ) {
/* Extension header missing, not an ERF file */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
- return -1;
+ return WTAP_OPEN_ERROR;
}
packet_size -= (guint32)sizeof(erf_ext_header);
memcpy(&type, &erf_ext_header, sizeof(type));
if (!wtap_read_bytes(wth->fh,&mc_hdr,sizeof(mc_hdr),err,err_info)) {
if (*err == WTAP_ERR_SHORT_READ) {
/* Subheader missing, not an ERF file */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
- return -1;
+ return WTAP_OPEN_ERROR;
}
packet_size -= (guint32)sizeof(mc_hdr);
break;
if (!wtap_read_bytes(wth->fh,ð_hdr,sizeof(eth_hdr),err,err_info)) {
if (*err == WTAP_ERR_SHORT_READ) {
/* Subheader missing, not an ERF file */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
- return -1;
+ return WTAP_OPEN_ERROR;
}
packet_size -= (guint32)sizeof(eth_hdr);
break;
* Probably a corrupt capture file or a file that's not an ERF file
* but that passed earlier tests.
*/
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
buffer=(gchar *)g_malloc(packet_size);
r = wtap_read_bytes(wth->fh, buffer, packet_size, err, err_info);
if (!r) {
if (*err != WTAP_ERR_SHORT_READ) {
/* A real error */
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* ERF record too short, accept the file,
only if the very first records have been successfully checked */
if (i < MIN_RECORDS_FOR_ERF_CHECK) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
}
} /* records_for_erf_check */
if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) { /* rewind */
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* This is an ERF file */
erf_populate_interfaces(wth);
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Read the next packet */
return -1;
}
-int eyesdn_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val eyesdn_open(wtap *wth, int *err, gchar **err_info)
{
char magic[EYESDN_HDR_MAGIC_SIZE];
/* Look for eyesdn header */
if (!wtap_read_bytes(wth->fh, &magic, sizeof magic, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(magic, eyesdn_hdr_magic, EYESDN_HDR_MAGIC_SIZE) != 0)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_EYESDN;
wth->subtype_seek_read = eyesdn_seek_read;
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Find the next packet and parse it; called from wtap_read(). */
result = (*open_routines[type - 1].open_routine)(wth, err, err_info);
switch (result) {
- case -1:
- /* I/O error - give up */
+ case WTAP_OPEN_ERROR:
+ /* Error - give up */
wtap_close(wth);
return NULL;
- case 0:
- /* No I/O error, but not that type of file */
+ case WTAP_OPEN_NOT_MINE:
+ /* No error, but not that type of file */
goto fail;
- case 1:
+ case WTAP_OPEN_MINE:
/* We found the file type */
goto success;
}
Initialize the data offset while we're at it. */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
- /* I/O error - give up */
+ /* Error - give up */
wtap_close(wth);
return NULL;
}
switch ((*open_routines[i].open_routine)(wth, err, err_info)) {
- case -1:
- /* I/O error - give up */
+ case WTAP_OPEN_ERROR:
+ /* Error - give up */
wtap_close(wth);
return NULL;
- case 0:
- /* No I/O error, but not that type of file */
+ case WTAP_OPEN_NOT_MINE:
+ /* No error, but not that type of file */
break;
- case 1:
+ case WTAP_OPEN_MINE:
/* We found the file type */
goto success;
}
if (heuristic_uses_extension(i, extension)) {
/* Yes. */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
- /* I/O error - give up */
+ /* Error - give up */
g_free(extension);
wtap_close(wth);
return NULL;
switch ((*open_routines[i].open_routine)(wth,
err, err_info)) {
- case -1:
- /* I/O error - give up */
+ case WTAP_OPEN_ERROR:
+ /* Error - give up */
g_free(extension);
wtap_close(wth);
return NULL;
- case 0:
- /* No I/O error, but not that type of file */
+ case WTAP_OPEN_NOT_MINE:
+ /* No error, but not that type of file */
break;
- case 1:
+ case WTAP_OPEN_MINE:
/* We found the file type */
g_free(extension);
goto success;
if (!heuristic_uses_extension(i, extension)) {
/* No. */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
- /* I/O error - give up */
+ /* Error - give up */
g_free(extension);
wtap_close(wth);
return NULL;
switch ((*open_routines[i].open_routine)(wth,
err, err_info)) {
- case -1:
- /* I/O error - give up */
+ case WTAP_OPEN_ERROR:
+ /* Error - give up */
g_free(extension);
wtap_close(wth);
return NULL;
- case 0:
- /* No I/O error, but not that type of file */
+ case WTAP_OPEN_NOT_MINE:
+ /* No error, but not that type of file */
break;
- case 1:
+ case WTAP_OPEN_MINE:
/* We found the file type */
g_free(extension);
goto success;
for (i = heuristic_open_routine_idx; i < open_info_arr->len; i++) {
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
- /* I/O error - give up */
+ /* Error - give up */
wtap_close(wth);
return NULL;
}
switch ((*open_routines[i].open_routine)(wth, err, err_info)) {
- case -1:
- /* I/O error - give up */
+ case WTAP_OPEN_ERROR:
+ /* Error - give up */
wtap_close(wth);
return NULL;
- case 0:
- /* No I/O error, but not that type of file */
+ case WTAP_OPEN_NOT_MINE:
+ /* No error, but not that type of file */
break;
- case 1:
+ case WTAP_OPEN_MINE:
/* We found the file type */
goto success;
}
return hcidump_process_packet(wth->random_fh, phdr, buf, err, err_info);
}
-int hcidump_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val hcidump_open(wtap *wth, int *err, gchar **err_info)
{
struct dump_hdr dh;
guint8 type;
if (!wtap_read_bytes(wth->fh, &dh, DUMP_HDR_SIZE, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if ((dh.in != 0 && dh.in != 1) || dh.pad != 0
|| GUINT16_FROM_LE(dh.len) < 1)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
if (!wtap_read_bytes(wth->fh, &type, 1, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (type < 1 || type > 4)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_HCIDUMP;
wth->file_encap = WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR;
wth->subtype_seek_read = hcidump_seek_read;
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
(unsigned int)hdr.unit > 4 || (unsigned int)hdr.type > 4 || \
(unsigned int)hdr.dir > 2 || (unsigned int)hdr.trunc > 2048))
-int i4btrace_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info)
{
i4b_trace_hdr_t hdr;
gboolean byte_swapped = FALSE;
/* I4B trace files have no magic in the header... Sigh */
if (!wtap_read_bytes(wth->fh, &hdr, sizeof(hdr), err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* Silly heuristic... */
/*
* It doesn't look valid in either byte order.
*/
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
}
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
/* Get capture start time */
wth->file_encap = WTAP_ENCAP_ISDN;
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Read the next packet */
static gboolean
ipfix_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
-static void
-ipfix_close(wtap *wth);
#define IPFIX_VERSION 10
-/* classic wtap: open capture file. Return 1 on success, 0 on normal failure
- * like malformed format, -1 on bad error like file system
+/* classic wtap: open capture file. Return WTAP_OPEN_MINE on success,
+ * WTAP_OPEN_NOT_MINE on normal failure like malformed format,
+ * WTAP_OPEN_ERROR on bad error like file system
*/
-int
+wtap_open_return_val
ipfix_open(wtap *wth, int *err, gchar **err_info)
{
gint i, n, records_for_ipfix_check = RECORDS_FOR_IPFIX_CHECK;
*err = 0; /* not actually an error in this case */
g_free(*err_info);
*err_info = NULL;
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1; /* real failure */
+ return WTAP_OPEN_ERROR; /* real failure */
/* else it's EOF */
if (i < 1) {
/* we haven't seen enough to prove this is a ipfix file */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
* If we got here, it's EOF and we haven't yet seen anything
if (file_seek(wth->fh, IPFIX_MSG_HDR_SIZE, SEEK_CUR, err) == -1) {
ipfix_debug1("ipfix_open: failed seek to next message in file, %d bytes away",
msg_hdr.message_length);
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
checked_len = IPFIX_MSG_HDR_SIZE;
if (*err == WTAP_ERR_SHORT_READ) {
/* Not a valid IPFIX Set, so not an IPFIX file. */
ipfix_debug1("ipfix_open: error %d reading set", *err);
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* A real I/O error; fail. */
- return -1;
+ return WTAP_OPEN_ERROR;
}
set_hdr.set_length = g_ntohs(set_hdr.set_length);
if ((set_hdr.set_length < IPFIX_SET_HDR_SIZE) ||
((set_hdr.set_length + checked_len) > msg_hdr.message_length)) {
ipfix_debug1("ipfix_open: found invalid set_length of %d",
set_hdr.set_length);
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if (file_seek(wth->fh, set_hdr.set_length - IPFIX_SET_HDR_SIZE,
{
ipfix_debug1("ipfix_open: failed seek to next set in file, %d bytes away",
set_hdr.set_length - IPFIX_SET_HDR_SIZE);
- return -1;
+ return WTAP_OPEN_ERROR;
}
checked_len += set_hdr.set_length;
}
}
+ /* go back to beginning of file */
+ if (file_seek (wth->fh, 0, SEEK_SET, err) != 0)
+ {
+ return WTAP_OPEN_ERROR;
+ }
+
/* all's good, this is a IPFIX file */
wth->file_encap = WTAP_ENCAP_RAW_IPFIX;
wth->snapshot_length = 0;
wth->file_tsprec = WTAP_TSPREC_SEC;
wth->subtype_read = ipfix_read;
wth->subtype_seek_read = ipfix_seek_read;
- wth->subtype_close = ipfix_close;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPFIX;
- /* go back to beginning of file */
- if (file_seek (wth->fh, 0, SEEK_SET, err) != 0)
- {
- return -1;
- }
- return 1;
+ return WTAP_OPEN_MINE;
}
}
return TRUE;
}
-
-
-/* classic wtap: close capture file */
-static void
-ipfix_close(wtap *wth _U_)
-{
- ipfix_debug0("ipfix_close: closing file");
-}
#define NAME_SIZE 11
-int iptrace_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val iptrace_open(wtap *wth, int *err, gchar **err_info)
{
char name[NAME_SIZE+1];
if (!wtap_read_bytes(wth->fh, name, NAME_SIZE, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
name[NAME_SIZE] = '\0';
wth->file_tsprec = WTAP_TSPREC_NSEC;
}
else {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
- return 1;
+ return WTAP_OPEN_MINE;
}
/***********************************************************
static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf,
size_t len);
-int
+wtap_open_return_val
iseries_open (wtap * wth, int *err, gchar ** err_info)
{
gint offset;
if (!wtap_read_bytes (wth->fh, &magic, sizeof magic, err, err_info))
{
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/*
if (memcmp (magic + offset, unicodemagic, sizeof unicodemagic) == 0) {
if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)
{
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
* Do some basic sanity checking to ensure we can handle the
if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_UNICODE))
{
if (*err == 0)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
else
- return -1;
+ return WTAP_OPEN_ERROR;
}
wth->file_encap = WTAP_ENCAP_ETHERNET;
if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)
{
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
- return 1;
+ return WTAP_OPEN_MINE;
}
offset += 1;
}
{
if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)
{
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
* Do some basic sanity checking to ensure we can handle the
if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_ASCII))
{
if (*err == 0)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
else
- return -1;
+ return WTAP_OPEN_ERROR;
}
wth->file_encap = WTAP_ENCAP_ETHERNET;
if (file_seek (wth->fh, 0, SEEK_SET, err) == -1)
{
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
- return 1;
+ return WTAP_OPEN_MINE;
}
offset += 1;
}
/* Neither ASCII or UNICODE so not supported */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
}
-int k12_open(wtap *wth, int *err, gchar **err_info) {
+wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) {
k12_src_desc_t* rec;
guint8 header_buffer[K12_FILE_HDR_LEN];
guint8* read_buffer;
if ( !wtap_read_bytes(wth->fh,header_buffer,K12_FILE_HDR_LEN,err,err_info) ) {
K12_DBG(1,("k12_open: FILE HEADER TOO SHORT OR READ ERROR"));
if (*err != WTAP_ERR_SHORT_READ) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if ( memcmp(header_buffer,k12_file_magic,8) != 0 ) {
K12_DBG(1,("k12_open: BAD MAGIC"));
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
offset = K12_FILE_HDR_LEN;
if ( len < 0 ) {
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
destroy_k12_file_data(file_data);
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (len == 0) {
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
*err = WTAP_ERR_SHORT_READ;
destroy_k12_file_data(file_data);
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (len == 0) {
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
*err = WTAP_ERR_SHORT_READ;
destroy_k12_file_data(file_data);
- return -1;
+ return WTAP_OPEN_ERROR;
}
read_buffer = file_data->seq_read_buff;
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("k12_open: record length %u < %u",
rec_len, K12_RECORD_TYPE + 4);
- return -1;
+ return WTAP_OPEN_ERROR;
}
type = pntoh32( read_buffer + K12_RECORD_TYPE );
*/
if (file_seek(wth->fh, offset, SEEK_SET, err) == -1) {
destroy_k12_file_data(file_data);
- return -1;
+ return WTAP_OPEN_ERROR;
}
K12_DBG(5,("k12_open: FIRST PACKET offset=%x",offset));
break;
rec_len, K12_SRCDESC_STACKLEN + 2);
destroy_k12_file_data(file_data);
g_free(rec);
- return -1;
+ return WTAP_OPEN_ERROR;
}
extra_len = pntoh16( read_buffer + K12_SRCDESC_EXTRALEN );
name_len = pntoh16( read_buffer + K12_SRCDESC_NAMELEN );
"|| 0x20 + extra_len + name_len + stack_len > rec_len) extra_len=%i name_len=%i stack_len=%i"));
destroy_k12_file_data(file_data);
g_free(rec);
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if (extra_len) {
rec_len, K12_SRCDESC_EXTRATYPE + 4);
destroy_k12_file_data(file_data);
g_free(rec);
- return -1;
+ return WTAP_OPEN_ERROR;
}
switch(( rec->input_type = pntoh32( read_buffer + K12_SRCDESC_EXTRATYPE ) )) {
case K12_PORT_DS0S:
rec_len, K12_SRCDESC_DS0_MASK + 12);
destroy_k12_file_data(file_data);
g_free(rec);
- return -1;
+ return WTAP_OPEN_ERROR;
}
rec->input_info.ds0mask = 0x00000000;
rec_len, K12_SRCDESC_DS0_MASK + 12);
destroy_k12_file_data(file_data);
g_free(rec);
- return -1;
+ return WTAP_OPEN_ERROR;
}
rec->input_info.atm.vp = pntoh16( read_buffer + K12_SRCDESC_ATM_VPI );
rec_len, K12_SRCDESC_DS0_MASK + 12);
destroy_k12_file_data(file_data);
g_free(rec);
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (read_buffer[K12_SRCDESC_PORT_TYPE] >= 0x14
&& read_buffer[K12_SRCDESC_PORT_TYPE] <= 0x17) {
rec_len, K12_SRCDESC_EXTRATYPE + extra_len + name_len + stack_len);
destroy_k12_file_data(file_data);
g_free(rec);
- return -1;
+ return WTAP_OPEN_ERROR;
}
rec->input_name = (gchar *)g_memdup(read_buffer + K12_SRCDESC_EXTRATYPE + extra_len, name_len);
rec->stack_file = (gchar *)g_memdup(read_buffer + K12_SRCDESC_EXTRATYPE + extra_len + name_len, stack_len);
wth->priv = (void *)file_data;
wth->file_tsprec = WTAP_TSPREC_NSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
typedef struct {
return TRUE;
}
-int
+wtap_open_return_val
k12text_open(wtap *wth, int *err, gchar **err_info _U_)
{
k12text_t *k12text;
BEGIN(MAGIC);
yylex();
- if (! is_k12text) return 0;
+ if (! is_k12text) return WTAP_OPEN_NOT_MINE;
if ( file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
k12text = (k12text_t *)g_malloc(sizeof(k12text_t));
wth->subtype_seek_read = k12text_seek_read;
wth->file_tsprec = WTAP_TSPREC_NSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err);
-int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val lanalyzer_open(wtap *wth, int *err, gchar **err_info)
{
LA_RecordHeader rec_header;
char header_fixed[2];
if (!wtap_read_bytes(wth->fh, &rec_header, LA_RecordHeaderSize,
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
record_type = pletoh16(rec_header.record_type);
record_length = pletoh16(rec_header.record_length); /* make sure to do this for while() loop */
if (record_type != RT_HeaderRegular && record_type != RT_HeaderCyclic) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Read the major and minor version numbers */
* Not enough room for the major and minor version numbers.
* Just treat that as a "not a LANalyzer file" indication.
*/
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if (!wtap_read_bytes(wth->fh, &header_fixed, sizeof header_fixed,
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
record_length -= sizeof header_fixed;
if (!wtap_read_bytes(wth->fh, comment, record_length,
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
comment[record_length] = '\0';
wth->shb_hdr.opt_comment = comment;
* End of file and no packets;
* accept this file.
*/
- return 1;
+ return WTAP_OPEN_MINE;
}
- return -1;
+ return WTAP_OPEN_ERROR;
}
record_type = pletoh16(rec_header.record_type);
case RT_Summary:
if (!wtap_read_bytes(wth->fh, summary,
sizeof summary, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
/* Assume that the date of the creation of the trace file
* is the same date of the trace. Lanalyzer doesn't
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("lanalyzer: board type %u unknown",
board_type);
- return -1;
+ return WTAP_OPEN_ERROR;
}
break;
/* Go back header number of bytes so that lanalyzer_read
* can read this header */
if (file_seek(wth->fh, -LA_RecordHeaderSize, SEEK_CUR, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
- return 1;
+ return WTAP_OPEN_MINE;
default:
if (file_seek(wth->fh, record_length, SEEK_CUR, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
break;
}
static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
struct pcaprec_ss990915_hdr *hdr);
-int libpcap_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info)
{
guint32 magic;
struct pcap_hdr hdr;
/* Read in the number that should be at the start of a "libpcap" file */
if (!wtap_read_bytes(wth->fh, &magic, sizeof magic, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
switch (magic) {
default:
/* Not a "libpcap" type we know about. */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Read the rest of the header. */
if (!wtap_read_bytes(wth->fh, &hdr, sizeof hdr, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
if (byte_swapped) {
/* Byte-swap the header fields about which we care. */
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("pcap: major version %u unsupported",
hdr.version_major);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/*
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("pcap: network type %u unknown or unsupported",
hdr.network);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* This is a libpcap file */
*/
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX;
wth->file_tsprec = WTAP_TSPREC_NSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/*
* Well, we couldn't even read it.
* Give up.
*/
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (figures_of_merit[i] == 0) {
/*
* Put the seek pointer back, and finish.
*/
if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
goto done;
}
* go back to the first packet and try the next one.
*/
if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
}
*/
erf_populate_interfaces(wth);
}
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Try to read the first two records of the capture file. */
return TRUE;
}
-int logcat_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val logcat_open(wtap *wth, int *err, gchar **err_info)
{
gint version;
gint tmp_version;
/* check first 3 packets (or 2 or 1 if EOF) versions to check file format is correct */
version = detect_version(wth->fh, err, err_info); /* first packet */
if (version == -1)
- return -1; /* I/O error */
+ return WTAP_OPEN_ERROR; /* I/O error */
if (version == 0)
- return 0; /* not a logcat file */
+ return WTAP_OPEN_NOT_MINE; /* not a logcat file */
if (version == -2)
- return 0; /* empty file, so not any type of file */
+ return WTAP_OPEN_NOT_MINE; /* empty file, so not any type of file */
tmp_version = detect_version(wth->fh, err, err_info); /* second packet */
if (tmp_version == -1)
- return -1; /* I/O error */
+ return WTAP_OPEN_ERROR; /* I/O error */
if (tmp_version == 0)
- return 0; /* not a logcat file */
+ return WTAP_OPEN_NOT_MINE; /* not a logcat file */
if (tmp_version != -2) {
/* we've read two packets; do they have the same version? */
if (tmp_version != version) {
/* no, so this is presumably not a logcat file */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
tmp_version = detect_version(wth->fh, err, err_info); /* third packet */
if (tmp_version < 0)
- return -1; /* I/O error */
+ return WTAP_OPEN_ERROR; /* I/O error */
if (tmp_version == 0)
- return 0; /* not a logcat file */
+ return WTAP_OPEN_NOT_MINE; /* not a logcat file */
if (tmp_version != -2) {
/*
* we've read three packets and the first two have the same
*/
if (tmp_version != version) {
/* no, so this is presumably not a logcat file */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
}
}
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
logcat = (struct logcat_phdr *) g_malloc(sizeof(struct logcat_phdr));
logcat->version = version;
wth->subtype_seek_read = logcat_seek_read;
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
int logcat_dump_can_write_encap(int encap)
return TRUE;
}
-int logcat_text_open(wtap *wth, int *err, gchar **err_info _U_) {
+wtap_open_return_val logcat_text_open(wtap *wth, int *err, gchar **err_info _U_) {
gchar cbuff[WTAP_MAX_PACKET_SIZE];
gchar *ret = NULL;
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
do {
ret = file_gets(cbuff, WTAP_MAX_PACKET_SIZE, wth->fh);
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG;
wth->file_encap = WTAP_ENCAP_LOGCAT_LONG;
} else {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
wth->snapshot_length = 0;
wth->subtype_read = logcat_text_read;
wth->subtype_seek_read = logcat_text_seek_read;
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
int logcat_text_brief_dump_can_write_encap(int encap) {
return mime_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
}
-int
+wtap_open_return_val
mime_file_open(wtap *wth, int *err, gchar **err_info)
{
char magic_buf[128]; /* increase buffer size when needed */
if (bytes_read < 0) {
*err = file_error(wth->fh, err_info);
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (bytes_read == 0)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
found_file = FALSE;
for (i = 0; i < N_MAGIC_TYPES; i++) {
found_file = TRUE;
/* file_ok = i; */
} else
- return 0; /* many files matched, bad file */
+ return WTAP_OPEN_NOT_MINE; /* many files matched, bad file */
}
}
if (!found_file)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MIME;
wth->file_encap = WTAP_ENCAP_MIME;
wth->subtype_seek_read = mime_seek_read;
wth->snapshot_length = 0;
- return 1;
+ return WTAP_OPEN_MINE;
}
return TRUE;
}
-int
+wtap_open_return_val
mp2t_open(wtap *wth, int *err, gchar **err_info)
{
guint8 buffer[MP2T_SIZE+TRAILER_LEN_MAX];
if (!wtap_read_bytes(wth->fh, buffer, MP2T_SIZE, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
first = -1;
}
}
if (-1 == first) {
- return 0; /* wrong file type - not an mpeg2 ts file */
+ return WTAP_OPEN_NOT_MINE; /* wrong file type - not an mpeg2 ts file */
}
if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* read some packets and make sure they all start with a sync byte */
do {
if (!wtap_read_bytes(wth->fh, buffer, MP2T_SIZE+trailer_len, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1; /* read error */
- if(sync_steps<2) return 0; /* wrong file type - not an mpeg2 ts file */
+ return WTAP_OPEN_ERROR; /* read error */
+ if(sync_steps<2) return WTAP_OPEN_NOT_MINE; /* wrong file type - not an mpeg2 ts file */
break; /* end of file, that's ok if we're still in sync */
}
if (buffer[0] == MP2T_SYNC_BYTE) {
/* if we've already detected a trailer field, we must remain in sync
another mismatch means we have no mpeg2 ts file */
if (trailer_len>0)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
/* check if a trailer is appended to the packet */
for (i=0; i<TRAILER_LEN_MAX; i++) {
if (buffer[i] == MP2T_SYNC_BYTE) {
trailer_len = i;
if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
sync_steps = 0;
break;
}
/* no sync byte found in the vicinity, this is no mpeg2 ts file */
if (i==TRAILER_LEN_MAX)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
} while (sync_steps < SYNC_STEPS);
if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MPEG_2_TS;
wth->snapshot_length = 0;
mp2t = (mp2t_filetype_t*) g_malloc(sizeof(mp2t_filetype_t));
- if (NULL == mp2t) {
- return -1;
- }
wth->priv = mp2t;
mp2t->start_offset = first;
mp2t->trailer_len = trailer_len;
- return 1;
+ return WTAP_OPEN_MINE;
}
{ 0, NULL }
};
-int
+wtap_open_return_val
mpeg_open(wtap *wth, int *err, gchar **err_info)
{
char magic_buf[16];
if (!wtap_read_bytes(wth->fh, magic_buf, sizeof magic_buf,
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
for (m=magic; m->match; m++) {
goto good_magic;
}
- return 0;
+ return WTAP_OPEN_NOT_MINE;
good_magic:
/* This appears to be a file with MPEG data. */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MPEG;
wth->file_encap = WTAP_ENCAP_MPEG;
mpeg->now.nsecs = 0;
mpeg->t0 = mpeg->now.secs;
- return 1;
+ return WTAP_OPEN_MINE;
}
const guint8 *pd, int *err);
static gboolean netmon_dump_close(wtap_dumper *wdh, int *err);
-int netmon_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info)
{
char magic[MAGIC_SIZE];
struct netmon_hdr hdr;
* Monitor file */
if (!wtap_read_bytes(wth->fh, magic, MAGIC_SIZE, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(magic, netmon_1_x_magic, MAGIC_SIZE) != 0 &&
memcmp(magic, netmon_2_x_magic, MAGIC_SIZE) != 0) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Read the rest of the header. */
if (!wtap_read_bytes(wth->fh, &hdr, sizeof hdr, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
switch (hdr.ver_major) {
default:
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("netmon: major version %u unsupported", hdr.ver_major);
- return -1;
+ return WTAP_OPEN_ERROR;
}
hdr.network = pletoh16(&hdr.network);
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("netmon: network type %u unknown or unsupported",
hdr.network);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* This is a netmon file */
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("netmon: frame table length is %u, which is not a multiple of the size of an entry",
frame_table_length);
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (frame_table_size == 0) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("netmon: frame table length is %u, which means it's less than one entry in size",
frame_table_length);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/*
* XXX - clamp the size of the frame table, so that we don't
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("netmon: frame table length is %u, which is larger than we support",
frame_table_length);
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (file_seek(wth->fh, frame_table_offset, SEEK_SET, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
frame_table = (guint32 *)g_try_malloc(frame_table_length);
if (frame_table_length != 0 && frame_table == NULL) {
*err = ENOMEM; /* we assume we're out of memory */
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (!wtap_read_bytes(wth->fh, frame_table, frame_table_length,
err, err_info)) {
g_free(frame_table);
- return -1;
+ return WTAP_OPEN_ERROR;
}
netmon->frame_table_size = frame_table_size;
netmon->frame_table = frame_table;
/*
** Netscaler trace format open routines
*/
-int nstrace_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info)
{
gchar *nstrace_buf;
gint64 file_size;
if ((file_size = wtap_file_size(wth, err)) == -1)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
nstrace_buf = (gchar *)g_malloc(NSPR_PAGESIZE);
page_size = GET_READ_PAGE_SIZE(file_size);
default:
/* No known signature found, assume it's not NetScaler */
g_free(nstrace_buf);
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
if ((file_seek(wth->fh, 0, SEEK_SET, err)) == -1)
{
- *err = file_error(wth->fh, err_info);
g_free(nstrace_buf);
- return 0;
+ return WTAP_OPEN_ERROR;
}
if (!wtap_read_bytes(wth->fh, nstrace_buf, page_size, err, err_info))
{
g_free(nstrace_buf);
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
switch (wth->file_type_subtype)
{
g_free(nstrace->pnstrace_buf);
g_free(nstrace);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* Read the first page of data */
{
g_free(nstrace->pnstrace_buf);
g_free(nstrace);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* reset the buffer offset */
wth->phdr.ts.nsecs = 0;
*err = 0;
- return 1;
+ return WTAP_OPEN_MINE;
}
}
-int netscreen_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val netscreen_open(wtap *wth, int *err, gchar **err_info)
{
/* Look for a NetScreen snoop header line */
if (!netscreen_check_file_type(wth, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) /* rewind */
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_encap = WTAP_ENCAP_UNKNOWN;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_NETSCREEN;
wth->subtype_seek_read = netscreen_seek_read;
wth->file_tsprec = WTAP_TSPREC_DSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Find the next packet and parse it; called from wtap_read(). */
static gboolean nettl_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
-int nettl_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info)
{
struct nettl_file_hdr file_hdr;
guint16 dummy[2];
/* Read in the string that should be at the start of a HP file */
if (!wtap_read_bytes(wth->fh, file_hdr.magic, MAGIC_SIZE, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(file_hdr.magic, nettl_magic_hpux9, MAGIC_SIZE) &&
memcmp(file_hdr.magic, nettl_magic_hpux10, MAGIC_SIZE)) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Read the rest of the file header */
if (!wtap_read_bytes(wth->fh, file_hdr.file_name, FILE_HDR_SIZE - MAGIC_SIZE,
err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
/* This is an nettl file */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_NETTL;
if (!wtap_read_bytes_or_eof(wth->fh, dummy, 4, err, err_info)) {
if (*err == 0) {
/* EOF, so no records */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
- return -1;
+ return WTAP_OPEN_ERROR;
}
subsys = g_ntohs(dummy[1]);
}
if (file_seek(wth->fh, FILE_HDR_SIZE, SEEK_SET, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Read the next packet */
static gint observer_to_wtap_encap(int observer_encap);
static gint wtap_to_observer_encap(int wtap_encap);
-int network_instruments_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val network_instruments_open(wtap *wth, int *err, gchar **err_info)
{
int offset;
capture_file_header file_header;
if (!wtap_read_bytes(wth->fh, &file_header, sizeof file_header,
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
offset += (int)sizeof file_header;
CAPTURE_FILE_HEADER_FROM_LE_IN_PLACE(file_header);
/* check if version info is present */
if (memcmp(file_header.observer_version, network_instruments_magic, true_magic_length)!=0) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* initialize the private state */
/* read the TLV header */
if (!wtap_read_bytes(wth->fh, &tlvh, sizeof tlvh, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
offset += (int)sizeof tlvh;
TLV_HEADER_FROM_LE_IN_PLACE(tlvh);
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("Observer: bad record (TLV length %u < %lu)",
tlvh.length, (unsigned long)sizeof tlvh);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* process (or skip over) the current TLV */
if (!wtap_read_bytes(wth->fh, &private_state->time_format,
sizeof private_state->time_format,
err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
private_state->time_format = GUINT32_FROM_LE(private_state->time_format);
offset += (int)sizeof private_state->time_format;
break;
seek_increment = tlvh.length - (int)sizeof tlvh;
if (seek_increment > 0) {
if (file_seek(wth->fh, seek_increment, SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
}
offset += seek_increment;
}
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("Observer: bad record (offset to first packet %d < %d)",
header_offset, offset);
- return -1;
+ return WTAP_OPEN_ERROR;
}
seek_increment = header_offset - offset;
if (seek_increment > 0) {
if (file_seek(wth->fh, seek_increment, SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* pull off the packet header */
if (!wtap_read_bytes(wth->fh, &packet_header, sizeof packet_header,
err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
PACKET_ENTRY_HEADER_FROM_LE_IN_PLACE(packet_header);
/* check the packet's magic number */
if (packet_header.packet_magic != observer_packet_magic) {
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("Observer: unsupported packet version %ul", packet_header.packet_magic);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* check the data link type */
if (observer_to_wtap_encap(packet_header.network_type) == WTAP_ENCAP_UNKNOWN) {
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("Observer: network type %u unknown or unsupported", packet_header.network_type);
- return -1;
+ return WTAP_OPEN_ERROR;
}
wth->file_encap = observer_to_wtap_encap(packet_header.network_type);
/* reset the pointer to the first packet */
if (file_seek(wth->fh, header_offset, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
init_gmt_to_localtime_offset();
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Reads the next packet. */
const guint8 *pd, int *err);
static gboolean netxray_dump_close_2_0(wtap_dumper *wdh, int *err);
-int
+wtap_open_return_val
netxray_open(wtap *wth, int *err, gchar **err_info)
{
char magic[MAGIC_SIZE];
* file */
if (!wtap_read_bytes(wth->fh, magic, MAGIC_SIZE, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(magic, netxray_magic, MAGIC_SIZE) == 0) {
} else if (memcmp(magic, old_netxray_magic, MAGIC_SIZE) == 0) {
is_old = TRUE;
} else {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Read the rest of the header. */
if (!wtap_read_bytes(wth->fh, &hdr, sizeof hdr, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
if (is_old) {
version_major = 0;
} else {
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("netxray: version \"%.8s\" unsupported", hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
}
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("netxray: the byte after the network type has the value %u, which I don't understand",
hdr.network_plus);
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (network_type >= NUM_NETXRAY_ENCAPS
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("netxray: network type %u (%u) unknown or unsupported",
network_type, hdr.network_plus);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/*
*err_info = g_strdup_printf(
"netxray: Unknown timeunit %u for Ethernet/CAPTYPE_NDIS version %.8s capture",
hdr.timeunit, hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/*
XXX: 05/29/07: Use 'realtick' instead of TpS table if timeunit=2;
*err_info = g_strdup_printf(
"netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_GIGPOD version %.8s capture",
hdr.timeunit, hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
ticks_per_sec = TpS_gigpod[hdr.timeunit];
*err_info = g_strdup_printf(
"netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_OTHERPOD version %.8s capture",
hdr.timeunit, hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
ticks_per_sec = TpS_otherpod[hdr.timeunit];
*err_info = g_strdup_printf(
"netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_OTHERPOD2 version %.8s capture",
hdr.timeunit, hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
ticks_per_sec = TpS_otherpod2[hdr.timeunit];
/*
*err_info = g_strdup_printf(
"netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_GIGPOD2 version %.8s capture",
hdr.timeunit, hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
ticks_per_sec = TpS_gigpod2[hdr.timeunit];
/*
*err_info = g_strdup_printf(
"netxray: Unknown capture type %u for Ethernet version %.8s capture",
hdr.captype, hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
break;
"netxray: Unknown timeunit %u for %u/%u version %.8s capture",
hdr.timeunit, network_type, hdr.captype,
hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
ticks_per_sec = TpS[hdr.timeunit];
break;
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("netxray: WAN HDLC capture subsubtype 0x%02x unknown or unsupported",
hdr.wan_hdlc_subsub_captype);
- return -1;
+ return WTAP_OPEN_ERROR;
}
break;
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("netxray: WAN capture subtype 0x%02x unknown or unsupported",
hdr.captype);
- return -1;
+ return WTAP_OPEN_ERROR;
}
} else
file_encap = WTAP_ENCAP_ETHERNET;
/* Seek to the beginning of the data records. */
if (file_seek(wth->fh, netxray->start_offset, SEEK_SET, err) == -1) {
- return -1;
+ return WTAP_OPEN_ERROR;
}
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Read the next packet */
static gboolean ng_file_seek_rand(wtap *wth, gint64 offset, int *err,
gchar **err_info);
-int
+wtap_open_return_val
ngsniffer_open(wtap *wth, int *err, gchar **err_info)
{
char magic[sizeof ngsniffer_magic];
/* Read in the string that should be at the start of a Sniffer file */
if (!wtap_read_bytes(wth->fh, magic, sizeof magic, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(magic, ngsniffer_magic, sizeof ngsniffer_magic)) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
* record.
*/
if (!wtap_read_bytes(wth->fh, record_type, 2, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
if (!wtap_read_bytes(wth->fh, record_length, 4, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
type = pletoh16(record_type);
if (type != REC_VERS) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("ngsniffer: Sniffer file doesn't start with a version record");
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (!wtap_read_bytes(wth->fh, &version, sizeof version, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
/* Check the data link type. */
if (version.network >= NUM_NGSNIFF_ENCAPS
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("ngsniffer: network type %u unknown or unsupported",
version.network);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* Check the time unit */
if (version.timeunit >= NUM_NGSNIFF_TIMEUNITS) {
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("ngsniffer: Unknown timeunit %u", version.timeunit);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* compressed or uncompressed Sniffer file? */
maj_vers = pletoh16(&version.maj_vers);
if (process_header_records(wth, err, err_info, maj_vers,
version.network) < 0)
- return -1;
+ return WTAP_OPEN_ERROR;
if ((version.network == NETWORK_SYNCHRO ||
version.network == NETWORK_ASYNC) &&
wth->file_encap == WTAP_ENCAP_PER_PACKET) {
*/
if (wth->random_fh != NULL) {
if (file_seek(wth->random_fh, current_offset, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* This is a ngsniffer file */
wth->file_tsprec = WTAP_TSPREC_NSEC; /* XXX */
- return 1;
+ return WTAP_OPEN_MINE;
}
static int
Buffer *buf, int *err,
gchar **err_info);
-int packetlogger_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val packetlogger_open(wtap *wth, int *err, gchar **err_info)
{
packetlogger_header_t pl_hdr;
guint8 type;
if(!packetlogger_read_header(&pl_hdr, wth->fh, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (!wtap_read_bytes(wth->fh, &type, 1, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* Verify this file belongs to us */
if (!((8 <= pl_hdr.len) && (pl_hdr.len < 65536) &&
(type < 0x04 || type == 0xFB || type == 0xFC || type == 0xFE || type == 0xFF)))
- return 0;
+ return WTAP_OPEN_NOT_MINE;
/* No file header. Reset the fh to 0 so we can read the first packet */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
/* Set up the pointers to the handlers for this file type */
wth->subtype_read = packetlogger_read;
wth->file_encap = WTAP_ENCAP_PACKETLOGGER;
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1; /* Our kind of file */
+ return WTAP_OPEN_MINE; /* Our kind of file */
}
static gboolean
}
/* classic wtap: open capture file */
-int
+wtap_open_return_val
pcapng_open(wtap *wth, int *err, gchar **err_info)
{
int bytes_read;
pcapng_free_wtapng_block_data(&wblock);
if (bytes_read == -2) {
pcapng_debug0("pcapng_open: doesn't begin with SHB, probably not a pcap-ng file");
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
pcapng_debug0("pcapng_open: couldn't read first SHB");
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* first block must be a "Section Header Block" */
*/
pcapng_debug1("pcapng_open: first block type %u not SHB", wblock.type);
pcapng_free_wtapng_block_data(&wblock);
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
pn.shb_read = TRUE;
break;
}
pcapng_debug1("pcapng_open: Check for more IDB:s, wtap_read_bytes_or_eof() failed, err = %d.", *err);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* go back to where we were */
pcapng_free_wtapng_block_data(&wblock);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return WTAP_OPEN_ERROR;
}
pcapng_process_idb(wth, pcapng, &wblock);
pcapng_debug2("pcapng_open: Read IDB number_of_interfaces %u, wtap_encap %i",
wth->interface_data->len, wth->file_encap);
}
- return 1;
+ return WTAP_OPEN_MINE;
}
static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
-int peekclassic_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info)
{
peekclassic_header_t ep_hdr;
struct timeval reference_time;
if (!wtap_read_bytes(wth->fh, &ep_hdr.master,
(int)sizeof(ep_hdr.master), err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/*
if (!wtap_read_bytes(wth->fh, &ep_hdr.secondary.v567,
(int)sizeof(ep_hdr.secondary.v567), err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if ((0 != ep_hdr.secondary.v567.reserved[0]) ||
(0 != ep_hdr.secondary.v567.reserved[1]) ||
(0 != ep_hdr.secondary.v567.reserved[2])) {
/* still unknown */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
/*
* Assume this isn't a Peek classic file.
*/
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
break;
/*
* Assume this isn't a Peek classic file.
*/
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
break;
/*
* Assume this isn't a Peek classic file.
*/
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
* Assume this isn't a Peek classic file.
*/
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/*
wth->snapshot_length = 0; /* not available in header */
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
}
-int peektagged_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val peektagged_open(wtap *wth, int *err, gchar **err_info)
{
peektagged_section_header_t ap_hdr;
int ret;
if (!wtap_read_bytes(wth->fh, &ap_hdr, (int)sizeof(ap_hdr), err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp (ap_hdr.section_id, "\177ver", sizeof(ap_hdr.section_id)) != 0)
- return 0; /* doesn't begin with a "\177ver" section */
+ return WTAP_OPEN_NOT_MINE; /* doesn't begin with a "\177ver" section */
/*
* XXX - we should get the length of the "\177ver" section, check
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("peektagged: version %u unsupported",
fileVersion);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/*
*/
ret = wtap_file_read_pattern (wth, "<MediaType>", err, err_info);
if (ret == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
if (ret == 0) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("peektagged: <MediaType> tag not found");
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* XXX - this appears to be 0 in both the EtherPeek and AiroPeek
files we've seen; should we require it to be 0? */
ret = wtap_file_read_number (wth, &mediaType, err, err_info);
if (ret == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
if (ret == 0) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("peektagged: <MediaType> value not found");
- return -1;
+ return WTAP_OPEN_ERROR;
}
ret = wtap_file_read_pattern (wth, "<MediaSubType>", err, err_info);
if (ret == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
if (ret == 0) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("peektagged: <MediaSubType> tag not found");
- return -1;
+ return WTAP_OPEN_ERROR;
}
ret = wtap_file_read_number (wth, &mediaSubType, err, err_info);
if (ret == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
if (ret == 0) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("peektagged: <MediaSubType> value not found");
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (mediaSubType >= NUM_PEEKTAGGED_ENCAPS
|| peektagged_encap[mediaSubType] == WTAP_ENCAP_UNKNOWN) {
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("peektagged: network type %u unknown or unsupported",
mediaSubType);
- return -1;
+ return WTAP_OPEN_ERROR;
}
ret = wtap_file_read_pattern (wth, "pkts", err, err_info);
if (ret == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
if (ret == 0) {
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* skip 8 zero bytes */
if (file_seek (wth->fh, 8L, SEEK_CUR, err) == -1)
- return 0;
+ return WTAP_OPEN_NOT_MINE;
/*
* This is an Peek tagged file.
wth->snapshot_length = 0; /* not available in header */
- return 1;
+ return WTAP_OPEN_MINE;
}
typedef struct {
}
-int
+wtap_open_return_val
pppdump_open(wtap *wth, int *err, gchar **err_info)
{
guint8 buffer[6]; /* Looking for: 0x07 t3 t2 t1 t0 ID */
if (!wtap_read_bytes(wth->fh, buffer, sizeof(buffer),
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (buffer[0] == PPPD_RESET_TIME &&
goto my_file_type;
}
else {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
my_file_type:
if (file_seek(wth->fh, 5, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
state = (pppdump_t *)g_malloc(sizeof(pppdump_t));
wth->priv = (void *)state;
state->pids = NULL;
state->pkt_cnt = 0;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Set part of the struct wtap_pkthdr. */
static gboolean radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info);
-int radcom_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val radcom_open(wtap *wth, int *err, gchar **err_info)
{
guint8 r_magic[8], t_magic[11], search_encap[7];
struct frame_date start_date;
/* Read in the string that should be at the start of a RADCOM file */
if (!wtap_read_bytes(wth->fh, r_magic, 8, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* XXX: bytes 2 and 3 of the "magic" header seem to be different in some
r_magic[1] = 0xD2;
r_magic[2] = 0x00;
if (memcmp(r_magic, radcom_magic, 8) != 0) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Look for the "Active Time" string. The "frame_date" structure should
* be located 32 bytes before the beginning of this string */
if (!wtap_read_bytes(wth->fh, t_magic, 11, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
while (memcmp(t_magic, active_time_magic, 11) != 0)
{
if (file_seek(wth->fh, -10, SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
if (!wtap_read_bytes(wth->fh, t_magic, 11, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
}
- if (file_seek(wth->fh, -43, SEEK_CUR, err) == -1) return -1;
+ if (file_seek(wth->fh, -43, SEEK_CUR, err) == -1)
+ return WTAP_OPEN_ERROR;
/* Get capture start time */
if (!wtap_read_bytes(wth->fh, &start_date, sizeof(struct frame_date),
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (file_seek(wth->fh, sizeof(struct frame_date), SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
for (;;) {
if (!wtap_read_bytes(wth->fh, search_encap, 4,
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(encap_magic, search_encap, 4) == 0)
* try the 4 bytes at that offset.
*/
if (file_seek(wth->fh, -3, SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
}
if (file_seek(wth->fh, 12, SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
if (!wtap_read_bytes(wth->fh, search_encap, 4, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
/* This is a radcom file */
else {
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("radcom: network type \"%.4s\" unknown", search_encap);
- return -1;
+ return WTAP_OPEN_ERROR;
}
#if 0
if (!wtap_read_bytes(wth->fh, &next_date, sizeof(struct frame_date),
err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
while (memcmp(&start_date, &next_date, 4)) {
if (file_seek(wth->fh, 1-sizeof(struct frame_date), SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
if (!wtap_read_bytes(wth->fh, &next_date, sizeof(struct frame_date),
err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
}
#endif
if (wth->file_encap == WTAP_ENCAP_ETHERNET) {
if (file_seek(wth->fh, 294, SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
} else if (wth->file_encap == WTAP_ENCAP_LAPB) {
if (file_seek(wth->fh, 297, SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
} else if (wth->file_encap == WTAP_ENCAP_ATM_RFC1483) {
if (file_seek(wth->fh, 504, SEEK_CUR, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
}
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Read the next packet */
* 4MB from 16MB Token Ring, and distinguishing both of them from the
* "Shomiti" versions of same.
*/
-int snoop_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val snoop_open(wtap *wth, int *err, gchar **err_info)
{
char magic[sizeof snoop_magic];
struct snoop_hdr hdr;
/* Read in the string that should be at the start of a "snoop" file */
if (!wtap_read_bytes(wth->fh, magic, sizeof magic, err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(magic, snoop_magic, sizeof snoop_magic) != 0) {
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Read the rest of the header. */
if (!wtap_read_bytes(wth->fh, &hdr, sizeof hdr, err, err_info))
- return -1;
+ return WTAP_OPEN_ERROR;
/*
* Make sure it's a version we support.
default:
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("snoop: version %u unsupported", hdr.version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/*
saved_offset = file_tell(wth->fh);
if (!wtap_read_bytes_or_eof(wth->fh, &rec_hdr, sizeof rec_hdr, err, err_info)) {
if (*err != 0)
- return -1;
+ return WTAP_OPEN_ERROR;
/*
* The file ends after the record header, which means this
* Seek back to the beginning of the first record.
*/
if (file_seek(wth->fh, saved_offset, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
hdr.network = g_ntohl(hdr.network);
if (is_shomiti) {
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("snoop: Shomiti network type %u unknown or unsupported",
hdr.network);
- return -1;
+ return WTAP_OPEN_ERROR;
}
file_encap = shomiti_encap[hdr.network];
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("snoop: private network type %u unknown or unsupported",
hdr.network);
- return -1;
+ return WTAP_OPEN_ERROR;
}
file_encap = snoop_private_encap[hdr.network^SNOOP_PRIVATE_BIT];
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("snoop: network type %u unknown or unsupported",
hdr.network);
- return -1;
+ return WTAP_OPEN_ERROR;
}
file_encap = snoop_encap[hdr.network];
wth->file_encap = file_encap;
wth->snapshot_length = 0; /* not available in header */
wth->file_tsprec = WTAP_TSPREC_USEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
typedef struct {
return stanag4607_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
}
-int stanag4607_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val stanag4607_open(wtap *wth, int *err, gchar **err_info)
{
guint16 version_id;
stanag4607_t *stanag4607;
if (!wtap_read_bytes(wth->fh, &version_id, sizeof version_id, err, err_info))
- return (*err != WTAP_ERR_SHORT_READ) ? -1 : 0;
+ return (*err != WTAP_ERR_SHORT_READ) ? WTAP_OPEN_ERROR : WTAP_OPEN_NOT_MINE;
if (!is_valid_id(GUINT16_TO_BE(version_id)))
/* Not a stanag4607 file */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
/* seek back to the start of the file */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_STANAG_4607;
wth->file_encap = WTAP_ENCAP_STANAG_4607;
wth->subtype_seek_read = stanag4607_seek_read;
wth->file_tsprec = WTAP_TSPREC_MSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
guint32 magic;
if (!wtap_read_bytes(wth->fh, &magic, sizeof magic, err, err_info))
- return (*err != WTAP_ERR_SHORT_READ) ? -1 : 0;
+ return (*err != WTAP_ERR_SHORT_READ) ? WTAP_OPEN_ERROR : WTAP_OPEN_NOT_MINE;
if (GUINT32_TO_LE(magic) != TNEF_SIGNATURE)
/* Not a tnef file */
- return 0;
+ return WTAP_OPEN_NOT_MINE;
/* seek back to the start of the file */
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
- return -1;
+ return WTAP_OPEN_ERROR;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_TNEF;
wth->file_encap = WTAP_ENCAP_TNEF;
wth->subtype_seek_read = tnef_seek_read;
wth->file_tsprec = WTAP_TSPREC_SEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
}
-int toshiba_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val toshiba_open(wtap *wth, int *err, gchar **err_info)
{
/* Look for Toshiba header */
if (!toshiba_check_file_type(wth, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->subtype_seek_read = toshiba_seek_read;
wth->file_tsprec = WTAP_TSPREC_CSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Find the next packet and parse it; called from wtap_read(). */
/* Open a file for reading */
-int visual_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info)
{
char magic[sizeof visual_magic];
struct visual_file_hdr vfile_hdr;
if (!wtap_read_bytes(wth->fh, magic, sizeof magic, err, err_info))
{
if (*err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
if (memcmp(magic, visual_magic, sizeof visual_magic) != 0)
{
- return 0;
+ return WTAP_OPEN_NOT_MINE;
}
/* Read the rest of the file header. */
if (!wtap_read_bytes(wth->fh, &vfile_hdr, sizeof vfile_hdr, err, err_info))
{
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* Verify the file version is known */
{
*err = WTAP_ERR_UNSUPPORTED;
*err_info = g_strdup_printf("visual: file version %u unsupported", vfile_hdr.file_version);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* Translate the encapsulation type; these values are SNMP ifType
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
*err_info = g_strdup_printf("visual: network type %u unknown or unsupported",
vfile_hdr.media_type);
- return -1;
+ return WTAP_OPEN_ERROR;
}
/* Fill in the wiretap struct with data from the file header */
visual->start_time = ((double) pletoh32(&vfile_hdr.start_time)) * 1000000;
visual->current_pkt = 1;
- return 1;
+ return WTAP_OPEN_MINE;
}
}
-int vms_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val vms_open(wtap *wth, int *err, gchar **err_info)
{
/* Look for VMS header */
if (!vms_check_file_type(wth, err, err_info)) {
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
}
wth->file_encap = WTAP_ENCAP_RAW_IP;
wth->subtype_seek_read = vms_seek_read;
wth->file_tsprec = WTAP_TSPREC_CSEC;
- return 1;
+ return WTAP_OPEN_MINE;
}
/* Find the next packet and parse it; called from wtap_read(). */
/* This does very little, except setting the wiretap header for a VWR file type */
/* and setting the timestamp precision to microseconds. */
-int vwr_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val vwr_open(wtap *wth, int *err, gchar **err_info)
{
int fpgaVer;
vwr_t *vwr;
fpgaVer = vwr_get_fpga_version(wth, err, err_info);
if (fpgaVer == -1) {
- return -1; /* I/O error */
+ return WTAP_OPEN_ERROR; /* I/O error */
}
if (fpgaVer == UNKNOWN_FPGA) {
- return 0; /* not a VWR file */
+ return WTAP_OPEN_NOT_MINE; /* not a VWR file */
}
/* This is a vwr file */
else if (fpgaVer == vVW510012_E_FPGA || fpgaVer == vVW510024_E_FPGA)
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_VWR_ETH;
- return 1;
+ return WTAP_OPEN_MINE;
}
*
* The open routine should return:
*
- * -1 on an I/O error;
+ * WTAP_OPEN_ERROR on an I/O error;
*
- * 1 if the file it's reading is one of the types it handles;
+ * WTAP_OPEN_MINE if the file it's reading is one of the types
+ * it handles;
*
- * 0 if the file it's reading isn't the type it handles.
+ * WTAP_OPEN_NOT_MINE if the file it's reading isn't one of the
+ * types it handles.
*
* If the routine handles this type of file, it should set the "file_type"
* field in the "struct wtap" to the type of the file.
* (See https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8518)
*
* However, the caller does have to free the private data pointer when
- * returning 0, since the next file type will be called and will likely
- * just overwrite the pointer.
+ * returning WTAP_OPEN_NOT_MINE, since the next file type will be called
+ * and will likely just overwrite the pointer.
*/
+typedef enum {
+ WTAP_OPEN_NOT_MINE = 0,
+ WTAP_OPEN_MINE = 1,
+ WTAP_OPEN_ERROR = -1
+} wtap_open_return_val;
+
+typedef wtap_open_return_val (*wtap_open_routine_t)(struct wtap*, int *,
+ char **);
/*
* Some file formats have defined magic numbers at fixed offsets from
* Those file formats do not require a file name extension in order
* to recognize them or to avoid recognizing other file types as that
* type, and have no extensions specified for them.
- */
-typedef int (*wtap_open_routine_t)(struct wtap*, int *, char **);
-
-/*
- * Some file formats don't have defined magic numbers at fixed offsets,
+ *
+ * Other file formats don't have defined magic numbers at fixed offsets,
* so a heuristic is required. If that file format has any file name
* extensions used for it, a list of those extensions should be
* specified, so that, if the name of the file being opened has an