MAX_MCS_INDEX is a valid array index.
[metze/wireshark/wip.git] / frame_tvbuff.c
index 2358af2a7eebe4bd6c4a318da6603e0e25f362ed..89c8ab68f043a36eab654ecddfb4d7f06d9b82a2 100644 (file)
@@ -20,7 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "config.h"
+#include <config.h>
 
 #include <glib.h>
 
 #include "frame_tvbuff.h"
 #include "globals.h"
 
-#include "wftap-int.h" /* for ->random_fh */
+#include "wtap-int.h" /* for ->random_fh */
 
 struct tvb_frame {
        struct tvbuff tvb;
 
        Buffer *buf;         /* Packet data */
 
-       wftap *wth;          /**< Wiretap session */
+       wtap *wth;           /**< Wiretap session */
        gint64 file_off;     /**< File offset */
 
        guint offset;
@@ -51,15 +51,15 @@ frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf)
        gchar *err_info;
 
        /* sanity check, capture file was closed? */
-       if (cfile.wfth != frame_tvb->wth)
+       if (cfile.wth != frame_tvb->wth)
                return FALSE;
 
        /* XXX, what if phdr->caplen isn't equal to
         * frame_tvb->tvb.length + frame_tvb->offset?
         */
-       if (!wftap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, &err, &err_info)) {
+       if (!wtap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, &err, &err_info)) {
+               /* XXX - report error! */
                switch (err) {
-                       case WTAP_ERR_UNSUPPORTED_ENCAP:
                        case WTAP_ERR_BAD_FILE:
                                g_free(err_info);
                                break;
@@ -74,19 +74,21 @@ frame_cache(struct tvb_frame *frame_tvb)
 {
        struct wtap_pkthdr phdr; /* Packet header */
 
-       memset(&phdr, 0, sizeof(struct wtap_pkthdr));
+       wtap_phdr_init(&phdr);
 
        if (frame_tvb->buf == NULL) {
                frame_tvb->buf = (struct Buffer *) g_malloc(sizeof(struct Buffer));
 
                /* XXX, register frame_tvb to some list which frees from time to time not used buffers :] */
-               buffer_init(frame_tvb->buf, frame_tvb->tvb.length + frame_tvb->offset);
+               ws_buffer_init(frame_tvb->buf, frame_tvb->tvb.length + frame_tvb->offset);
 
                if (!frame_read(frame_tvb, &phdr, frame_tvb->buf))
                        { /* TODO: THROW(???); */ }
        }
 
-       frame_tvb->tvb.real_data = buffer_start_ptr(frame_tvb->buf) + frame_tvb->offset;
+       frame_tvb->tvb.real_data = ws_buffer_start_ptr(frame_tvb->buf) + frame_tvb->offset;
+
+       wtap_phdr_cleanup(&phdr);
 }
 
 static void
@@ -95,7 +97,7 @@ frame_free(tvbuff_t *tvb)
        struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
 
        if (frame_tvb->buf) {
-               buffer_free(frame_tvb->buf);
+               ws_buffer_free(frame_tvb->buf);
 
                g_free(frame_tvb->buf);
        }
@@ -137,13 +139,13 @@ frame_find_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, guint8 needle)
 }
 
 static gint
-frame_pbrk_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, const guint8 *needles, guchar *found_needle)
+frame_pbrk_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, const ws_mempbrk_pattern* pattern, guchar *found_needle)
 {
        struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
 
        frame_cache(frame_tvb);
 
-       return tvb_pbrk_guint8(tvb, abs_offset, limit, needles, found_needle);
+       return tvb_ws_mempbrk_pattern_guint8(tvb, abs_offset, limit, pattern, found_needle);
 }
 
 static guint
@@ -212,12 +214,12 @@ frame_tvbuff_new(const frame_data *fd, const guint8 *buf)
        frame_tvb = (struct tvb_frame *) tvb;
 
        /* XXX, wtap_can_seek() */
-       if (cfile.wfth && cfile.wfth->random_fh
+       if (cfile.wth && cfile.wth->random_fh
 #ifdef WANT_PACKET_EDITOR
                && fd->file_off != -1 /* generic clone for modified packets */
 #endif
        ) {
-               frame_tvb->wth = cfile.wfth;
+               frame_tvb->wth = cfile.wth;
                frame_tvb->file_off = fd->file_off;
                frame_tvb->offset = 0;
        } else
@@ -231,7 +233,7 @@ frame_tvbuff_new(const frame_data *fd, const guint8 *buf)
 tvbuff_t *
 frame_tvbuff_new_buffer(const frame_data *fd, Buffer *buf)
 {
-       return frame_tvbuff_new(fd, buffer_start_ptr(buf));
+       return frame_tvbuff_new(fd, ws_buffer_start_ptr(buf));
 }
 
 static tvbuff_t *
@@ -317,12 +319,12 @@ file_tvbuff_new(const frame_data *fd, const guint8 *buf)
        frame_tvb = (struct tvb_frame *) tvb;
 
        /* XXX, wtap_can_seek() */
-       if (cfile.wfth && cfile.wfth->random_fh
+       if (cfile.wth && cfile.wth->random_fh
 #ifdef WANT_PACKET_EDITOR
                && fd->file_off != -1 /* generic clone for modified packets */
 #endif
        ) {
-               frame_tvb->wth = cfile.wfth;
+               frame_tvb->wth = cfile.wth;
                frame_tvb->file_off = fd->file_off;
                frame_tvb->offset = 0;
        } else
@@ -336,5 +338,18 @@ file_tvbuff_new(const frame_data *fd, const guint8 *buf)
 tvbuff_t *
 file_tvbuff_new_buffer(const frame_data *fd, Buffer *buf)
 {
-       return frame_tvbuff_new(fd, buffer_start_ptr(buf));
+       return frame_tvbuff_new(fd, ws_buffer_start_ptr(buf));
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */