From Marton Nemeth:
Add the ability to open JPEG/JFIF files directly. From me: Some code cleanup + add new file to cmake. svn path=/trunk/; revision=30588
This commit is contained in:
parent
80424e5ced
commit
b7d116667f
|
@ -1187,4 +1187,6 @@ proto_reg_handoff_jfif(void)
|
|||
dissector_add_string("media_type", "image/jfif", jfif_handle);
|
||||
dissector_add_string("media_type", "image/jpg", jfif_handle);
|
||||
dissector_add_string("media_type", "image/jpeg", jfif_handle);
|
||||
|
||||
dissector_add("wtap_encap", WTAP_ENCAP_JPEG_JFIF, jfif_handle);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ set(WIRETAP_FILES
|
|||
i4btrace.c
|
||||
iptrace.c
|
||||
iseries.c
|
||||
jpeg_jfif.c
|
||||
k12.c
|
||||
lanalyzer.c
|
||||
libpcap.c
|
||||
|
|
|
@ -52,6 +52,7 @@ NONGENERATED_C_FILES = \
|
|||
i4btrace.c \
|
||||
iptrace.c \
|
||||
iseries.c \
|
||||
jpeg_jfif.c \
|
||||
k12.c \
|
||||
lanalyzer.c \
|
||||
libpcap.c \
|
||||
|
@ -101,6 +102,7 @@ NONGENERATED_HEADER_FILES = \
|
|||
i4b_trace.h \
|
||||
iptrace.h \
|
||||
iseries.h \
|
||||
jpeg_jfif.h \
|
||||
k12.h \
|
||||
lanalyzer.h \
|
||||
libpcap.h \
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#include "packetlogger.h"
|
||||
#include "daintree-sna.h"
|
||||
#include "netscaler.h"
|
||||
#include "jpeg_jfif.h"
|
||||
|
||||
|
||||
/* The open_file_* routines should return:
|
||||
|
@ -131,6 +132,7 @@ static wtap_open_routine_t open_routines_base[] = {
|
|||
tnef_open,
|
||||
dct3trace_open,
|
||||
daintree_sna_open,
|
||||
jpeg_jfif_open,
|
||||
/* Files that don't have magic bytes at a fixed location,
|
||||
* but that instead require a heuristic of some sort to
|
||||
* identify them. This includes the ASCII trace files that
|
||||
|
@ -619,6 +621,9 @@ static const struct file_type_info dump_open_table_base[] = {
|
|||
{ "NetScaler Trace (Version 2.0)", "nstrace20", "*.cap", "*.cap", FALSE,
|
||||
nstrace_20_dump_can_write_encap, nstrace_dump_open },
|
||||
|
||||
/* WTAP_FILE_JPEG_JFIF */
|
||||
{ "JPEG/JFIF", "jpeg", "*.jpg;*.jpeg;*.jfif", ".jpg", FALSE, NULL, NULL },
|
||||
|
||||
};
|
||||
|
||||
gint wtap_num_file_types = sizeof(dump_open_table_base) / sizeof(struct file_type_info);
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
/* jpeg_jfif.c
|
||||
*
|
||||
* JPEG/JFIF file format decoder for the Wiretap library.
|
||||
* Written by Márton Németh <nm127@freemail.hu>
|
||||
* Copyright 2009 Márton Németh
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* The JPEG and JFIF specification can be found at:
|
||||
* http://www.jpeg.org/public/jfif.pdf
|
||||
* http://www.w3.org/Graphics/JPEG/itu-t81.pdf
|
||||
*
|
||||
* Wiretap Library
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "wtap-int.h"
|
||||
#include "file_wrappers.h"
|
||||
#include "buffer.h"
|
||||
#include "jpeg_jfif.h"
|
||||
|
||||
static const guchar jpeg_jfif_magic[] = { 0xFF, 0xD8, /* SOF */
|
||||
0xFF /* start of the next marker */
|
||||
};
|
||||
|
||||
static gboolean
|
||||
jpeg_jfif_read(wtap *wth, int *err, gchar **err_info,
|
||||
gint64 *data_offset)
|
||||
{
|
||||
guint8 *buf;
|
||||
gint64 file_size;
|
||||
int packet_size;
|
||||
gint64 capture_size;
|
||||
|
||||
*err = 0;
|
||||
|
||||
/* interpret the file as one packet only */
|
||||
if (wth->data_offset)
|
||||
return FALSE;
|
||||
|
||||
*data_offset = wth->data_offset;
|
||||
|
||||
if ((file_size = wtap_file_size(wth, err)) == -1)
|
||||
return FALSE;
|
||||
|
||||
/* Read maximum possible packet size */
|
||||
if (file_size <= WTAP_MAX_PACKET_SIZE) {
|
||||
capture_size = file_size;
|
||||
} else {
|
||||
capture_size = WTAP_MAX_PACKET_SIZE;
|
||||
}
|
||||
packet_size = (int)capture_size;
|
||||
|
||||
buffer_assure_space(wth->frame_buffer, packet_size);
|
||||
buf = buffer_start_ptr(wth->frame_buffer);
|
||||
|
||||
wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err);
|
||||
|
||||
wth->data_offset += packet_size;
|
||||
|
||||
wth->phdr.caplen = packet_size;
|
||||
wth->phdr.len = (int)file_size;
|
||||
|
||||
wth->phdr.ts.secs = 0;
|
||||
wth->phdr.ts.nsecs = 0;
|
||||
|
||||
*err_info = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
jpeg_jfif_seek_read(wtap *wth, gint64 seek_off,
|
||||
union wtap_pseudo_header *pseudo_header _U_, guchar *pd, int length,
|
||||
int *err, gchar **err_info)
|
||||
{
|
||||
int packet_size = length;
|
||||
|
||||
/* interpret the file as one packet only */
|
||||
if (0 < seek_off) {
|
||||
*err = 0;
|
||||
*err_info = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
|
||||
*err_info = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err);
|
||||
|
||||
*err = 0;
|
||||
*err_info = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
jpeg_jfif_open(wtap *wth, int *err, gchar **err_info)
|
||||
{
|
||||
int bytes_read;
|
||||
char magic_buf[3];
|
||||
int ret = 0;
|
||||
|
||||
errno = WTAP_ERR_CANT_READ;
|
||||
bytes_read = file_read(magic_buf, 1, sizeof(magic_buf), wth->fh);
|
||||
if (bytes_read != (int) sizeof(magic_buf)) {
|
||||
*err = file_error(wth->fh);
|
||||
if (*err != 0) {
|
||||
*err_info = NULL;
|
||||
ret = -1;
|
||||
}
|
||||
} else {
|
||||
if (memcmp(magic_buf, jpeg_jfif_magic, sizeof(magic_buf)) == 0) {
|
||||
ret = 1;
|
||||
|
||||
wth->file_type = WTAP_FILE_JPEG_JFIF;
|
||||
wth->file_encap = WTAP_ENCAP_JPEG_JFIF;
|
||||
wth->tsprecision = WTAP_FILE_TSPREC_SEC;
|
||||
wth->subtype_read = jpeg_jfif_read;
|
||||
wth->subtype_seek_read = jpeg_jfif_seek_read;
|
||||
wth->subtype_close = NULL;
|
||||
wth->snapshot_length = 0;
|
||||
|
||||
wth->capture.generic = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Seek to the start of the file */
|
||||
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
|
||||
*err = -1;
|
||||
*err_info = NULL;
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* jpeg_jfif.h
|
||||
*
|
||||
* JPEG/JFIF file format decoder for the Wiretap library.
|
||||
* Written by Márton Németh <nm127@freemail.hu>
|
||||
* Copyright 2009 Márton Németh
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Wiretap Library
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __W_JPEG_JFIF_H__
|
||||
#define __W_JPEG_JFIF_H__
|
||||
|
||||
#include "wtap-int.h"
|
||||
|
||||
int jpeg_jfif_open(wtap *wth, int *err, gchar **err_info);
|
||||
|
||||
#endif
|
|
@ -451,7 +451,10 @@ static struct encap_type_info encap_table_base[] = {
|
|||
{ "Fibre Channel FC-2", "fc2" },
|
||||
|
||||
/* WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS */
|
||||
{ "Fibre Channel FC-2 With Frame Delimiter", "fc2sof"}
|
||||
{ "Fibre Channel FC-2 With Frame Delimiter", "fc2sof"},
|
||||
|
||||
/* WTAP_ENCAP_JPEG_JFIF */
|
||||
{ "JPEG/JFIF", "jfif" }
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -212,6 +212,7 @@ extern "C" {
|
|||
#define WTAP_ENCAP_NSTRACE_2_0 120
|
||||
#define WTAP_ENCAP_FIBRE_CHANNEL_FC2 121
|
||||
#define WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS 122
|
||||
#define WTAP_ENCAP_JPEG_JFIF 123
|
||||
|
||||
#define WTAP_NUM_ENCAP_TYPES wtap_get_num_encap_types()
|
||||
|
||||
|
@ -277,6 +278,7 @@ extern "C" {
|
|||
#define WTAP_FILE_DAINTREE_SNA 56
|
||||
#define WTAP_FILE_NETSCALER_1_0 57
|
||||
#define WTAP_FILE_NETSCALER_2_0 58
|
||||
#define WTAP_FILE_JPEG_JFIF 59
|
||||
|
||||
#define WTAP_NUM_FILE_TYPES wtap_get_num_file_types()
|
||||
|
||||
|
|
Loading…
Reference in New Issue