*
* XXX: works at most with 0x1FFF bytes per record
*/
-static gint get_record(guint8** bufferp, FILE* fh, gint64 file_offset,
+static gint get_record(guint8** bufferp, FILE_T fh, gint64 file_offset,
int *err, gchar **err_info) {
static guint8* buffer = NULL;
static guint buffer_len = 0x2000 ;
guint bytes_read;
guint last_read;
- guint actual_len, left;
+ guint left;
guint8 junk[0x14];
guint8* writep;
+#ifdef DEBUG_K12
+ guint actual_len;
+#endif
/* where the next unknown 0x10 bytes are stuffed to the file */
guint junky_offset = 0x2000 - (gint) ( (file_offset - 0x200) % 0x2000 );
if ( junky_offset == 0x2000 ) {
/* the length of the record is 0x10 bytes ahead from we are reading */
- bytes_read = file_read(junk,1,0x14,fh);
+ bytes_read = file_read(junk,0x14,fh);
if (bytes_read == 2 && junk[0] == 0xff && junk[1] == 0xff) {
K12_DBG(1,("get_record: EOF"));
return 0;
} else if ( bytes_read < 0x14 ){
K12_DBG(1,("get_record: SHORT READ OR ERROR"));
- *err = file_error(fh);
+ *err = file_error(fh, err_info);
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
memcpy(buffer,&(junk[0x10]),4);
} else {
/* the length of the record is right where we are reading */
- bytes_read = file_read(buffer,1, 0x4, fh);
+ bytes_read = file_read(buffer, 0x4, fh);
if (bytes_read == 2 && buffer[0] == 0xff && buffer[1] == 0xff) {
K12_DBG(1,("get_record: EOF"));
return 0;
} else if ( bytes_read != 0x4 ) {
K12_DBG(1,("get_record: SHORT READ OR ERROR"));
- *err = file_error(fh);
+ *err = file_error(fh, err_info);
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
}
}
- actual_len = left = pntohl(buffer);
+ left = pntohl(buffer);
+#ifdef DEBUG_K12
+ actual_len = left;
+#endif
junky_offset -= 0x4;
K12_DBG(5,("get_record: GET length=%u",left));
/* XXX - Is WTAP_MAX_PACKET_SIZE */
if (left < 4 || left > WTAP_MAX_PACKET_SIZE) {
K12_DBG(1,("get_record: Invalid GET length=%u",left));
- *err = WTAP_ERR_BAD_RECORD;
+ *err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("get_record: Invalid GET length=%u",left);
return -1;
}
K12_DBG(6,("get_record: looping left=%d junky_offset=%" G_GINT64_MODIFIER "d",left,junky_offset));
if (junky_offset > left) {
- bytes_read += last_read = file_read(writep,1, left, fh);
+ bytes_read += last_read = file_read(writep, left, fh);
if ( last_read != left ) {
K12_DBG(1,("get_record: SHORT READ OR ERROR"));
- *err = file_error(fh);
+ *err = file_error(fh, err_info);
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
return bytes_read;
}
} else {
- bytes_read += last_read = file_read(writep,1, junky_offset, fh);
+ bytes_read += last_read = file_read(writep, junky_offset, fh);
if ( last_read != junky_offset ) {
K12_DBG(1,("get_record: SHORT READ OR ERROR, read=%d expected=%d",last_read, junky_offset));
- *err = file_error(fh);
+ *err = file_error(fh, err_info);
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
writep += last_read;
- bytes_read += last_read = file_read(junk,1, 0x10, fh);
+ bytes_read += last_read = file_read(junk, 0x10, fh);
if ( last_read != 0x10 ) {
K12_DBG(1,("get_record: SHORT READ OR ERROR"));
- *err = file_error(fh);
+ *err = file_error(fh, err_info);
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
wth->data_offset = offset;
+ wth->phdr.presence_flags = WTAP_HAS_TS;
+
ts = pntohll(buffer + K12_PACKET_TIMESTAMP);
wth->phdr.ts.secs = (guint32) ((ts / 2000000) + 631152000);
}
-static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err _U_, gchar **err_info) {
+static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guint8 *pd, int length, int *err _U_, gchar **err_info) {
k12_t *k12 = (k12_t *)wth->priv;
k12_src_desc_t* src_desc;
guint8* buffer;
K12_DBG(1,("k12_open: ENTER debug_level=%u",debug_level));
#endif
- if ( file_read(header_buffer,1,0x200,wth->fh) != 0x200 ) {
+ if ( file_read(header_buffer,0x200,wth->fh) != 0x200 ) {
K12_DBG(1,("k12_open: FILE HEADER TOO SHORT OR READ ERROR"));
- *err = file_error(wth->fh);
+ *err = file_error(wth->fh, err_info);
if (*err != 0) {
return -1;
}
static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const union wtap_pseudo_header *pseudo_header,
- const guchar *pd, int *err) {
+ const guint8 *pd, int *err) {
k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
guint32 len;
union {
}
-gboolean k12_dump_open(wtap_dumper *wdh, gboolean cant_seek, int *err) {
+gboolean k12_dump_open(wtap_dumper *wdh, int *err) {
k12_dump_t *k12;
- if (cant_seek) {
- *err = WTAP_ERR_CANT_WRITE_TO_PIPE;
- return FALSE;
- }
-
if ( ! wtap_dump_file_write(wdh, k12_file_magic, 8, err)) {
return FALSE;
}