Make the IPv4 NRB code's comments match the IPv6 NRB code's comments.
[metze/wireshark/wip.git] / wiretap / camins.c
index d5aafe9fccc3a5ed82b083558fd3900f6f962e73..4923ac49e8b7c0fb117a19ba5969ea44c41007e2 100644 (file)
 #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"
 
@@ -107,26 +104,6 @@ typedef enum {
 #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
@@ -146,7 +123,7 @@ find_next_pkt_dat_type_len(FILE_T fh,
     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;
         }
@@ -212,7 +189,7 @@ read_packet_data(FILE_T fh, guint8 dat_trans_type, guint8 *buf, guint16 dat_len,
 
     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) {
@@ -267,6 +244,12 @@ camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
 
     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);
@@ -319,19 +302,20 @@ camins_seek_read(wtap *wth, gint64 seek_off,
 
 
 
-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++;
@@ -340,11 +324,11 @@ int camins_open(wtap *wth, int *err, gchar **err_info _U_)
     } 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;
@@ -357,7 +341,7 @@ int camins_open(wtap *wth, int *err, gchar **err_info _U_)
    wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_CAMINS;
 
    *err = 0;
-   return 1;
+   return WTAP_OPEN_MINE;
 }