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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #ifdef HAVE_SYS_STAT_H
31 #include "file_wrappers.h"
35 static gboolean
tnef_read_file(wtap
*wth
, FILE_T fh
, struct wtap_pkthdr
*phdr
,
36 Buffer
*buf
, int *err
, gchar
**err_info
)
41 if ((file_size
= wtap_file_size(wth
, err
)) == -1)
44 if (file_size
> WTAP_MAX_PACKET_SIZE
) {
46 * Probably a corrupt capture file; don't blow up trying
47 * to allocate space for an immensely-large packet.
49 *err
= WTAP_ERR_BAD_FILE
;
50 *err_info
= g_strdup_printf("tnef: File has %" G_GINT64_MODIFIER
"d-byte packet, bigger than maximum of %u",
51 file_size
, WTAP_MAX_PACKET_SIZE
);
54 packet_size
= (int)file_size
;
56 phdr
->presence_flags
= 0; /* yes, we have no bananas^Wtime stamp */
58 phdr
->caplen
= packet_size
;
59 phdr
->len
= packet_size
;
64 return wtap_read_packet_bytes(fh
, buf
, packet_size
, err
, err_info
);
67 static gboolean
tnef_read(wtap
*wth
, int *err
, gchar
**err_info
, gint64
*data_offset
)
73 offset
= file_tell(wth
->fh
);
75 /* there is only ever one packet */
79 *data_offset
= offset
;
81 return tnef_read_file(wth
, wth
->fh
, &wth
->phdr
, wth
->frame_buffer
, err
, err_info
);
84 static gboolean
tnef_seek_read(wtap
*wth
, gint64 seek_off
,
85 struct wtap_pkthdr
*phdr
,
86 Buffer
*buf
, int length _U_
, int *err
, gchar
**err_info
)
88 /* there is only one packet */
94 if (file_seek(wth
->random_fh
, seek_off
, SEEK_SET
, err
) == -1)
97 return tnef_read_file(wth
, wth
->random_fh
, phdr
, buf
, err
, err_info
);
100 int tnef_open(wtap
*wth
, int *err
, gchar
**err_info
)
105 bytes_read
= file_read(&magic
, sizeof magic
, wth
->fh
);
106 if (bytes_read
!= sizeof magic
) {
107 *err
= file_error(wth
->fh
, err_info
);
108 return (*err
!= 0) ? -1 : 0;
111 if (htolel(magic
) != TNEF_SIGNATURE
)
112 /* Not a tnef file */
115 /* seek back to the start of the file */
116 if (file_seek(wth
->fh
, 0, SEEK_SET
, err
) == -1)
119 wth
->file_type_subtype
= WTAP_FILE_TYPE_SUBTYPE_TNEF
;
120 wth
->file_encap
= WTAP_ENCAP_TNEF
;
121 wth
->snapshot_length
= 0;
123 wth
->subtype_read
= tnef_read
;
124 wth
->subtype_seek_read
= tnef_seek_read
;
125 wth
->tsprecision
= WTAP_FILE_TSPREC_SEC
;