3 * JPEG/JFIF file format decoder for the Wiretap library.
4 * Written by Marton Nemeth <nm127@freemail.hu>
5 * Copyright 2009 Marton Nemeth
9 * The JPEG and JFIF specification can be found at:
10 * http://www.jpeg.org/public/jfif.pdf
11 * http://www.w3.org/Graphics/JPEG/itu-t81.pdf
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
47 #include "file_wrappers.h"
49 #include "jpeg_jfif.h"
51 static const guchar jpeg_jfif_magic[] = { 0xFF, 0xD8, /* SOF */
52 0xFF /* start of the next marker */
56 jpeg_jfif_read(wtap *wth, int *err, gchar **err_info,
66 /* interpret the file as one packet only */
70 *data_offset = wth->data_offset;
72 if ((file_size = wtap_file_size(wth, err)) == -1)
75 /* Read maximum possible packet size */
76 if (file_size <= WTAP_MAX_PACKET_SIZE) {
77 capture_size = file_size;
79 capture_size = WTAP_MAX_PACKET_SIZE;
81 packet_size = (int)capture_size;
83 buffer_assure_space(wth->frame_buffer, packet_size);
84 buf = buffer_start_ptr(wth->frame_buffer);
86 wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err);
88 wth->data_offset += packet_size;
90 wth->phdr.caplen = packet_size;
91 wth->phdr.len = (int)file_size;
93 wth->phdr.ts.secs = 0;
94 wth->phdr.ts.nsecs = 0;
101 jpeg_jfif_seek_read(wtap *wth, gint64 seek_off,
102 union wtap_pseudo_header *pseudo_header _U_, guchar *pd, int length,
103 int *err, gchar **err_info)
105 int packet_size = length;
107 /* interpret the file as one packet only */
114 if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
119 wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err);
127 jpeg_jfif_open(wtap *wth, int *err, gchar **err_info)
133 errno = WTAP_ERR_CANT_READ;
134 bytes_read = file_read(magic_buf, 1, sizeof(magic_buf), wth->fh);
135 if (bytes_read != (int) sizeof(magic_buf)) {
136 *err = file_error(wth->fh);
142 if (memcmp(magic_buf, jpeg_jfif_magic, sizeof(magic_buf)) == 0) {
145 wth->file_type = WTAP_FILE_JPEG_JFIF;
146 wth->file_encap = WTAP_ENCAP_JPEG_JFIF;
147 wth->tsprecision = WTAP_FILE_TSPREC_SEC;
148 wth->subtype_read = jpeg_jfif_read;
149 wth->subtype_seek_read = jpeg_jfif_seek_read;
150 wth->snapshot_length = 0;
154 /* Seek to the start of the file */
155 if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) {