3 * Transport-Neutral Encapsulation Format (TNEF) file reading
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "file_wrappers.h"
26 #include <wsutil/buffer.h>
29 static gboolean tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
30 Buffer *buf, int *err, gchar **err_info)
35 if ((file_size = wtap_file_size(wth, err)) == -1)
38 if (file_size > WTAP_MAX_PACKET_SIZE) {
40 * Probably a corrupt capture file; don't blow up trying
41 * to allocate space for an immensely-large packet.
43 *err = WTAP_ERR_BAD_FILE;
44 *err_info = g_strdup_printf("tnef: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u",
45 file_size, WTAP_MAX_PACKET_SIZE);
48 packet_size = (int)file_size;
50 phdr->rec_type = REC_TYPE_PACKET;
51 phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */
53 phdr->caplen = packet_size;
54 phdr->len = packet_size;
59 return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
62 static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
68 offset = file_tell(wth->fh);
70 /* there is only ever one packet */
74 *data_offset = offset;
76 return tnef_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info);
79 static gboolean tnef_seek_read(wtap *wth, gint64 seek_off,
80 struct wtap_pkthdr *phdr,
81 Buffer *buf, int *err, gchar **err_info)
83 /* there is only one packet */
89 if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
92 return tnef_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
95 wtap_open_return_val tnef_open(wtap *wth, int *err, gchar **err_info)
99 if (!wtap_read_bytes(wth->fh, &magic, sizeof magic, err, err_info))
100 return (*err != WTAP_ERR_SHORT_READ) ? WTAP_OPEN_ERROR : WTAP_OPEN_NOT_MINE;
102 if (GUINT32_TO_LE(magic) != TNEF_SIGNATURE)
103 /* Not a tnef file */
104 return WTAP_OPEN_NOT_MINE;
106 /* seek back to the start of the file */
107 if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
108 return WTAP_OPEN_ERROR;
110 wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_TNEF;
111 wth->file_encap = WTAP_ENCAP_TNEF;
112 wth->snapshot_length = 0;
114 wth->subtype_read = tnef_read;
115 wth->subtype_seek_read = tnef_seek_read;
116 wth->file_tsprec = WTAP_TSPREC_SEC;
118 return WTAP_OPEN_MINE;
122 * Editor modelines - http://www.wireshark.org/tools/modelines.html
127 * indent-tabs-mode: nil
130 * vi: set shiftwidth=2 tabstop=8 expandtab:
131 * :indentSize=2:tabSize=8:noTabs=true: