#include "config.h"
#include <string.h>
-#include <glib.h>
-#include <wtap.h>
-#include <wtap-int.h>
-#include <file_wrappers.h>
-#include <wsutil/buffer.h>
+#include "wtap-int.h"
+#include "file_wrappers.h"
#include "camins.h"
#define DVB_CI_PSEUDO_HDR_HOST_TO_CAM 0xFE
-/* read a block of data from the camins file and handle the errors */
-static gboolean
-read_block(FILE_T fh, guint8 *buf, guint16 buf_len, int *err, gchar **err_info)
-{
- int bytes_read;
-
- bytes_read = file_read((void *)buf, buf_len, fh);
- if (bytes_read != buf_len) {
- *err = file_error(fh, err_info);
- /* bytes_read==0 is end of file */
- if (bytes_read>0 && *err == 0) {
- *err = WTAP_ERR_SHORT_READ;
- }
- return FALSE;
- }
-
- return TRUE;
-}
-
-
/* find the transaction type for the data bytes of the next packet
and the number of data bytes in that packet
the fd is moved such that it can be used in a subsequent call
RESET_STAT_VALS;
do {
- if (read_block(fh, block, sizeof(block), err, err_info) == FALSE) {
+ if (!wtap_read_bytes_or_eof(fh, block, sizeof(block), err, err_info)) {
RESET_STAT_VALS;
return FALSE;
}
p = buf;
while (bytes_count < dat_len) {
- if (read_block(fh, block, sizeof(block), err, err_info) == FALSE)
+ if (!wtap_read_bytes_or_eof(fh, block, sizeof(block), err, err_info))
break;
if (block[1] == dat_trans_type) {
if (!find_next_pkt_dat_type_len(fh, &dat_trans_type, &dat_len, err, err_info))
return FALSE;
+ /*
+ * The maximum value of length is 65535, which, even after
+ * DVB_CI_PSEUDO_HDR_LEN is added to it, is less than
+ * WTAP_MAX_PACKET_SIZE will ever be, so we don't need to check
+ * it.
+ */
ws_buffer_assure_space(buf, DVB_CI_PSEUDO_HDR_LEN+dat_len);
p = ws_buffer_start_ptr(buf);
-int camins_open(wtap *wth, int *err, gchar **err_info _U_)
+wtap_open_return_val camins_open(wtap *wth, int *err, gchar **err_info)
{
guint8 found_start_blocks = 0;
guint8 count = 0;
guint8 block[2];
- int bytes_read;
/* all CAM Inspector files I've looked at have at least two blocks of
0x00 0xE1 within the first 20 bytes */
do {
- bytes_read = file_read(block, sizeof(block), wth->fh);
- if (bytes_read != sizeof(block))
- break;
+ if (!wtap_read_bytes(wth->fh, block, sizeof(block), err, err_info)) {
+ if (*err == WTAP_ERR_SHORT_READ)
+ break;
+ return WTAP_OPEN_ERROR;
+ }
if (block[0]==0x00 && block[1] == 0xE1)
found_start_blocks++;
} 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;
}