3 * Transport-Neutral Encapsulation Format (TNEF) file reading
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #ifdef HAVE_SYS_STAT_H
33 #include "file_wrappers.h"
38 static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
47 /* there is only ever one packet */
51 *data_offset = wth->data_offset;
53 if ((file_size = wtap_file_size(wth, err)) == -1)
56 if (file_size > WTAP_MAX_PACKET_SIZE) {
58 * Probably a corrupt capture file; don't blow up trying
59 * to allocate space for an immensely-large packet.
61 *err = WTAP_ERR_BAD_RECORD;
62 *err_info = g_strdup_printf("tnef: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u",
63 file_size, WTAP_MAX_PACKET_SIZE);
66 packet_size = (int)file_size;
68 buffer_assure_space(wth->frame_buffer, packet_size);
69 buf = buffer_start_ptr(wth->frame_buffer);
71 wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err, err_info);
73 wth->data_offset += packet_size;
75 wth->phdr.caplen = packet_size;
76 wth->phdr.len = packet_size;
78 if (wtap_fstat(wth, &statb, err) == -1)
81 wth->phdr.ts.secs = statb.st_mtime;
82 wth->phdr.ts.nsecs = 0;
87 static gboolean tnef_seek_read(wtap *wth, gint64 seek_off,
88 union wtap_pseudo_header *pseudo_header _U_,
89 guint8 *pd, int length, int *err, gchar **err_info)
91 int packet_size = length;
93 /* there is only one packet */
99 if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
102 wtap_file_read_expected_bytes(pd, packet_size, wth->random_fh, err, err_info);
107 int tnef_open(wtap *wth, int *err, gchar **err_info)
112 bytes_read = file_read(&magic, sizeof magic, wth->fh);
113 if (bytes_read != sizeof magic) {
114 *err = file_error(wth->fh, err_info);
115 return (*err != 0) ? -1 : 0;
118 if (htolel(magic) != TNEF_SIGNATURE)
119 /* Not a tnef file */
122 /* seek back to the start of the file */
123 if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
126 wth->file_type = WTAP_FILE_TNEF;
127 wth->file_encap = WTAP_ENCAP_TNEF;
128 wth->snapshot_length = 0;
130 wth->subtype_read = tnef_read;
131 wth->subtype_seek_read = tnef_seek_read;
132 wth->tsprecision = WTAP_FILE_TSPREC_SEC;