4 * routines for importing tektronix k12xx *.rf5 files
6 * Copyright (c) 2005, Luis E. Garia Ontanon <luis.ontanon@gmail.com>
11 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 char* env_file = NULL;
37 static unsigned debug_level = 0;
39 void k12_dbg(unsigned level, char* fmt, ...) {
42 if (level > debug_level) return;
45 vfprintf(dbg_out, fmt, ap);
48 fprintf(dbg_out,"\n");
53 void k12_hexdump(unsigned offset, char* label, unsigned char* b, unsigned len) {
54 static const char* c2t[] = {
55 "00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f",
56 "10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f",
57 "20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f",
58 "30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f",
59 "40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f",
60 "50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f",
61 "60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f",
62 "70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f",
63 "80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f",
64 "90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f",
65 "a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af",
66 "b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf",
67 "c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf",
68 "d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df",
69 "e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef",
70 "f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"
74 if (debug_level < 2) return;
76 fprintf(dbg_out,"%s(%.4x,%.4x): ",label,offset,len);
78 for (i=0 ; i<len ; i++) {
80 fprintf(dbg_out,"\n");
84 fprintf(dbg_out,c2t[b[i]]);
86 fprintf(dbg_out,"\n");
99 #include "file_wrappers.h"
104 * the 32 bits .rf5 file contains:
105 * an 8 byte magic number
107 * 32bit number of records
108 * other 0x200 bytes bytes of uncharted territory
109 * 1 or more copies of the num_of_records in there
110 * the records whose first 32bits word is the length
111 * they are stuffed by one to four words every 0x2000 bytes
112 * and a 2 byte terminator FFFF
115 static const guint8 k12_file_magic[] = { 0x00, 0x00, 0x02, 0x00 ,0x12, 0x05, 0x00, 0x10 };
119 guint32 num_of_records; /* XXX: not sure about this */
121 GHashTable* src_by_id; /* k12_srcdsc_recs by input */
122 GHashTable* src_by_name; /* k12_srcdsc_recs by stack_name */
125 typedef struct _k12_src_desc_t {
130 k12_input_info_t input_info;
134 /* so far we've seen only 7 types of records */
135 #define K12_REC_PACKET 0x00010020
136 #define K12_REC_SRCDSC 0x00070041 /* port-stack mapping + more, the key of the whole thing */
137 #define K12_REC_SCENARIO 0x00070040 /* what appears as the window's title */
138 #define K12_REC_70042 0x00070042 /* XXX: ??? */
139 #define K12_REC_70044 0x00070044 /* text with a grammar (conditions/responses) */
140 #define K12_REC_20030 0x00020030 /* human readable start time */
141 #define K12_REC_20032 0x00020031 /* human readable stop time */
143 #define K12_MASK_PACKET 0xfffffff0
146 #define K12_RECORD_LEN 0x0
147 #define K12_RECORD_TYPE 0x4
148 #define K12_RECORD_FRAME_LEN 0x8
149 #define K12_RECORD_INPUT 0xc
151 #define K12_PACKET_TIMESTAMP 0x18
152 #define K12_PACKET_FRAME 0x20
154 #define K12_PACKET_OFFSET_VP 0x08
155 #define K12_PACKET_OFFSET_VC 0x0a
156 #define K12_PACKET_OFFSET_CID 0x0c
158 #define K12_SRCDESC_EXTRALEN 0x1e
159 #define K12_SRCDESC_NAMELEN 0x20
160 #define K12_SRCDESC_STACKLEN 0x22
162 #define K12_SRCDESC_EXTRATYPE 0x24
163 #define K12_SRCDESC_ATM_VPI 0x38
164 #define K12_SRCDESC_ATM_VCI 0x3a
165 #define K12_SRCDESC_DS0_MASK 0x3c
169 * get_record: Get the next record into a buffer
170 * Every about 0x2000 bytes 0x10 bytes are inserted in the file,
171 * even in the middle of a record.
172 * This reads the next record without the eventual 0x10 bytes.
173 * returns the lenght of the record + the stuffing (if any)
175 * XXX: works at most with 0x1FFF bytes per record
177 static gint get_record(guint8* buffer, FILE* fh, guint file_offset) {
181 long junky_offset = 0x2000 - ( (file_offset - 0x200) % 0x2000 );
184 k12_dbg(5,"k12:get_record: ENTER offset=%u",file_offset);
187 if ( junky_offset != 0x2000 ) {
190 read = file_read(buffer,1, 0x4,fh);
192 if (read == 2 && buffer[0] == 0xff && buffer[1] == 0xff) {
194 k12_dbg(1,"k12:get_record: EOF");
198 } else if ( read != 0x4 ) {
200 k12_dbg(1,"k12:get_record: SHORT READ");
206 len = pntohl(buffer) & 0x00001FFF;
208 if (junky_offset > len) {
210 if (len - 0x4 <= 0) {
212 k12_dbg(1,"k12:get_record: TOO SHORT");
217 if ( file_read(buffer+0x4, 1, len - 0x4, fh) < len - 0x4 ) {
219 k12_dbg(1,"k12:get_record: SHORT READ");
225 k12_hexdump(file_offset, "GOT record", buffer, len);
231 if ( file_read(buffer+0x4, 1, len + 0xC, fh) < len ) {
235 for (i = junky_offset; i < len; i++) {
236 buffer[i] = buffer[i+0x10];
239 k12_hexdump(file_offset, "GOT record", buffer, len);
247 read = file_read(buffer,1,0x14,fh);
249 if (read == 2 && buffer[0] == 0xff && buffer[1] == 0xff) {
251 k12_dbg(1,"k12:get_record: EOF");
255 } else if ( read < 0x14 ){
257 k12_dbg(1,"k12:get_record: SHORT READ");
263 for (i = 0; i < 0x10; i++) {
264 buffer[i] = buffer[i+0x10];
267 len = pntohl(buffer) & 0x00001FFF;
269 if (len - 0x4 <= 0) {
271 k12_dbg(1,"k12:get_record: SHORT RECORD");
276 if ( file_read(buffer + 0x4, 1, len - 0x4,fh) < len - 0x4 ) {
278 k12_dbg(1,"k12:get_record: READ ERROR");
284 k12_hexdump(file_offset, "GOT stuffed record", buffer, len);
292 static gboolean k12_read(wtap *wth, int *err, gchar **err_info _U_, long *data_offset) {
293 k12_src_desc_t* src_desc;
294 guint8 buffer[0x2000];
300 offset = wth->data_offset;
303 k12_dbg(5,"k12_read: offset=%i",offset);
306 /* ignore the record if it isn't a packet */
308 *data_offset = offset;
310 len = get_record(buffer, wth->fh, offset);
313 *err = WTAP_ERR_SHORT_READ;
315 } else if (len == 0) {
320 type = pntohl(buffer + K12_RECORD_TYPE);
323 k12_dbg(5,"k12_read: record type=%i",offset);
328 } while ( (type & K12_MASK_PACKET) != K12_REC_PACKET );
330 wth->data_offset = offset;
332 ts = pntohll(buffer + K12_PACKET_TIMESTAMP);
335 wth->phdr.ts.secs = (guint32) ((ts / 2000000) + 631152000);
336 wth->phdr.ts.nsecs = (guint32) ( (ts % 2000000) * 500 );
339 k12_dbg(5,"k12_read: secs=%u nsecs=%u", wth->phdr.ts.secs,wth->phdr.ts.nsecs);
342 wth->phdr.len = wth->phdr.caplen = pntohl(buffer + K12_RECORD_FRAME_LEN) & 0x00001FFF;
345 buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
346 memcpy(buffer_start_ptr(wth->frame_buffer), buffer + K12_PACKET_FRAME, wth->phdr.caplen);
348 wth->pseudo_header.k12.input = pntohl(buffer + K12_RECORD_INPUT);
351 k12_dbg(5,"k12_read: wth->pseudo_header.k12.input=%x wth->phdr.len=%i",wth->pseudo_header.k12.input,wth->phdr.len);
354 src_desc = g_hash_table_lookup(wth->capture.k12->src_by_id,GUINT_TO_POINTER(wth->pseudo_header.k12.input));
359 k12_dbg(5,"k12_read: input_name='%s' stack_file='%s' type=%x",src_desc->input_name,src_desc->stack_file,src_desc->input_type);
361 wth->pseudo_header.k12.input_name = src_desc->input_name;
362 wth->pseudo_header.k12.stack_file = src_desc->stack_file;
363 wth->pseudo_header.k12.input_type = src_desc->input_type;
365 switch(src_desc->input_type) {
366 case K12_PORT_ATMPVC:
367 wth->pseudo_header.k12.input_info.atm.vp = pntohs(buffer + (K12_PACKET_FRAME + wth->phdr.caplen + K12_PACKET_OFFSET_VP));
368 wth->pseudo_header.k12.input_info.atm.vc = pntohs(buffer + (K12_PACKET_FRAME + wth->phdr.caplen + K12_PACKET_OFFSET_VC));
369 wth->pseudo_header.k12.input_info.atm.cid = *((unsigned char*)(buffer + K12_PACKET_FRAME + wth->phdr.len + K12_PACKET_OFFSET_CID));
372 memcpy(&(wth->pseudo_header.k12.input_info),&(src_desc->input_info),sizeof(src_desc->input_info));
379 k12_dbg(5,"k12_read: NO RECORD FOUND");
382 memset(&(wth->pseudo_header),0,sizeof(wth->pseudo_header));
383 wth->pseudo_header.k12.input_name = "unknown port";
384 wth->pseudo_header.k12.stack_file = "unknown stack file";
387 wth->pseudo_header.k12.stuff = wth->capture.k12;
393 static gboolean k12_seek_read(wtap *wth, long seek_off, union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err _U_, gchar **err_info _U_) {
394 k12_src_desc_t* src_desc;
395 guint8 buffer[0x2000];
399 k12_dbg(5,"k12_seek_read: ENTER");
402 if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
404 k12_dbg(5,"k12_seek_read: SEEK ERROR");
409 if (get_record(buffer, wth->random_fh, seek_off) < 1) {
411 k12_dbg(5,"k12_seek_read: READ ERROR");
416 memcpy(pd, buffer + K12_PACKET_FRAME, length);
418 input = pntohl(buffer + K12_RECORD_INPUT);
420 k12_dbg(5,"k12_seek_read: input=%.8x",input);
423 src_desc = g_hash_table_lookup(wth->capture.k12->src_by_id,GUINT_TO_POINTER(input));
428 k12_dbg(5,"k12_seek_read: input_name='%s' stack_file='%s' type=%x",src_desc->input_name,src_desc->stack_file,src_desc->input_type);
431 pseudo_header->k12.input_name = src_desc->input_name;
432 pseudo_header->k12.stack_file = src_desc->stack_file;
433 pseudo_header->k12.input_type = src_desc->input_type;
435 switch(src_desc->input_type) {
436 case K12_PORT_ATMPVC:
437 pseudo_header->k12.input_info.atm.vp = pntohs(buffer + K12_PACKET_FRAME + length + K12_PACKET_OFFSET_VP);
438 pseudo_header->k12.input_info.atm.vc = pntohs(buffer + K12_PACKET_FRAME + length + K12_PACKET_OFFSET_VC);
439 pseudo_header->k12.input_info.atm.cid = *((unsigned char*)(buffer + K12_PACKET_FRAME + length + K12_PACKET_OFFSET_CID));
442 memcpy(&(pseudo_header->k12.input_info),&(src_desc->input_info),sizeof(src_desc->input_info));
448 wth->pseudo_header.k12.input_name = src_desc->input_name;
449 wth->pseudo_header.k12.stack_file = src_desc->stack_file;
450 wth->pseudo_header.k12.input_type = src_desc->input_type;
452 switch(src_desc->input_type) {
453 case K12_PORT_ATMPVC:
454 wth->pseudo_header.k12.input_info.atm.vp = pntohs(buffer + K12_PACKET_FRAME + length + K12_PACKET_OFFSET_VP);
455 wth->pseudo_header.k12.input_info.atm.vc = pntohs(buffer + K12_PACKET_FRAME + length + K12_PACKET_OFFSET_VC);
456 wth->pseudo_header.k12.input_info.atm.cid = *((unsigned char*)(buffer + K12_PACKET_FRAME + length + K12_PACKET_OFFSET_CID));
459 memcpy(&(wth->pseudo_header.k12.input_info),&(src_desc->input_info),sizeof(src_desc->input_info));
466 k12_dbg(5,"k12_seek_read: NO SRC_RECORD FOUND");
470 memset(&(pseudo_header->k12),0,sizeof(pseudo_header->k12));
471 pseudo_header->k12.input_name = "unknown port";
472 pseudo_header->k12.stack_file = "unknown stack file";
475 memset(&(wth->pseudo_header.k12),0,sizeof(wth->pseudo_header.k12));
476 wth->pseudo_header.k12.input_name = "unknown port";
477 wth->pseudo_header.k12.stack_file = "unknown stack file";
482 pseudo_header->k12.input = input;
483 pseudo_header->k12.stuff = wth->capture.k12;
486 wth->pseudo_header.k12.input = input;
487 wth->pseudo_header.k12.stuff = wth->capture.k12;
490 k12_dbg(5,"k12_seek_read: DONE OK");
497 static k12_t* new_k12_file_data() {
498 k12_t* fd = g_malloc(sizeof(k12_t));
501 fd->num_of_records = 0;
502 fd->src_by_name = g_hash_table_new(g_str_hash,g_str_equal);
503 fd->src_by_id = g_hash_table_new(g_direct_hash,g_direct_equal);
508 static gboolean destroy_srcdsc(gpointer k _U_, gpointer v, gpointer p _U_) {
509 k12_src_desc_t* rec = v;
512 g_free(rec->input_name);
515 g_free(rec->stack_file);
522 static void destroy_k12_file_data(k12_t* fd) {
523 g_hash_table_destroy(fd->src_by_id);
524 g_hash_table_foreach_remove(fd->src_by_name,destroy_srcdsc,NULL);
525 g_hash_table_destroy(fd->src_by_name);
529 static void k12_close(wtap *wth) {
530 destroy_k12_file_data(wth->capture.k12);
532 k12_dbg(5,"k12_close: CLOSED");
533 if (env_file) fclose(dbg_out);
538 int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
540 guint8 read_buffer[0x2000];
552 gchar* env_level = getenv("K12_DEBUG_LEVEL");
553 env_file = getenv("K12_DEBUG_FILENAME");
554 if ( env_file ) dbg_out = fopen(env_file,"w");
555 else dbg_out = stderr;
556 if ( env_level ) debug_level = strtoul(env_level,NULL,10);
557 k12_dbg(1,"k12_open: ENTER debug_level=%u",debug_level);
560 if ( file_read(read_buffer,1,0x200,wth->fh) != 0x200 ) {
563 k12_dbg(1,"k12_open: FILE HEADER TOO SHORT");
568 if ( memcmp(read_buffer,k12_file_magic,8) != 0 ) {
570 k12_dbg(1,"k12_open: BAD MAGIC");
578 file_data = new_k12_file_data();
580 file_data->file_len = pntohl( read_buffer + 0x8);
581 file_data->num_of_records = pntohl( read_buffer + 0xC );
584 k12_dbg(5,"k12_open: FILE_HEADER OK: offset=%x file_len=%i records=%i",
587 file_data->num_of_records );
592 len = get_record(read_buffer, wth->fh, offset);
596 k12_dbg(1,"k12_open: BAD HEADER RECORD");
602 type = pntohl( read_buffer + K12_RECORD_TYPE );
604 if ( (type & K12_MASK_PACKET) == K12_REC_PACKET) {
606 * we are at the first packet record, rewind and leave.
608 if (file_seek(wth->fh, offset, SEEK_SET, err) == -1) {
609 destroy_k12_file_data(file_data);
613 k12_dbg(5,"k12_open: FIRST PACKET offset=%x",offset);
616 } else if (type == K12_REC_SRCDSC) {
617 rec = g_malloc0(sizeof(k12_src_desc_t));
619 rec_len = pntohl( read_buffer + K12_RECORD_LEN );
620 extra_len = pntohs( read_buffer + K12_SRCDESC_EXTRALEN );
621 name_len = pntohs( read_buffer + K12_SRCDESC_NAMELEN );
622 stack_len = pntohs( read_buffer + K12_SRCDESC_STACKLEN );
624 rec->input = pntohl( read_buffer + K12_RECORD_INPUT );
627 k12_dbg(5,"k12_open: INTERFACE RECORD offset=%x interface=%x",offset,rec->input);
630 if (extra_len == 0 || name_len == 0 || stack_len == 0
631 || 0x20 + extra_len + name_len + stack_len > rec_len ) {
634 k12_dbg(5,"k12_open: failed (extra_len == 0 || name_len == 0 || stack_len == 0 "
635 "|| 0x20 + extra_len + name_len + stack_len > rec_len) extra_len=%i name_len=%i stack_len=%i");
641 switch(( rec->input_type = pntohl( read_buffer + K12_SRCDESC_EXTRATYPE ) )) {
643 rec->input_info.ds0mask = 0x00000000;
645 for (i = 0; i < 32; i++) {
646 rec->input_info.ds0mask |= ( *(read_buffer + K12_SRCDESC_DS0_MASK + i) == 0xff ) ? 0x1<<(31-i) : 0x0;
650 case K12_PORT_ATMPVC:
651 rec->input_info.atm.vp = pntohs( read_buffer + K12_SRCDESC_ATM_VPI );
652 rec->input_info.atm.vc = pntohs( read_buffer + K12_SRCDESC_ATM_VCI );
658 rec->input_name = g_memdup(read_buffer + K12_SRCDESC_EXTRATYPE + extra_len, name_len);
659 rec->stack_file = g_memdup(read_buffer + K12_SRCDESC_EXTRATYPE + extra_len + name_len, stack_len);
661 g_strdown(rec->stack_file);
663 g_hash_table_insert(file_data->src_by_id,GUINT_TO_POINTER(rec->input),rec);
664 g_hash_table_insert(file_data->src_by_name,rec->stack_file,rec);
674 wth->data_offset = offset;
675 wth->file_type = WTAP_FILE_K12;
676 wth->file_encap = WTAP_ENCAP_K12;
677 wth->snapshot_length = 0;
678 wth->subtype_read = k12_read;
679 wth->subtype_seek_read = k12_seek_read;
680 wth->subtype_close = k12_close;
681 wth->capture.k12 = file_data;
682 wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
687 int k12_dump_can_write_encap(int encap) {
689 if (encap == WTAP_ENCAP_PER_PACKET)
690 return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
692 if (encap != WTAP_ENCAP_K12)
693 return WTAP_ERR_UNSUPPORTED_ENCAP;
698 static const gchar dumpy_junk[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
700 static void k12_dump_record(wtap_dumper *wdh, long len, guint8* buffer) {
701 long junky_offset = (0x2000 - ( (wdh->dump.k12->file_offset - 0x200) % 0x2000 )) % 0x2000;
703 if (len > junky_offset) {
706 fwrite(buffer, 1, junky_offset, wdh->fh);
708 fwrite(dumpy_junk, 1, 0x10, wdh->fh);
710 fwrite(buffer+junky_offset, 1, len - junky_offset, wdh->fh);
712 wdh->dump.k12->file_offset += len + 0x10;
714 fwrite(buffer, 1, len, wdh->fh);
715 wdh->dump.k12->file_offset += len;
718 wdh->dump.k12->num_of_records++;
721 static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) {
722 k12_src_desc_t* src_desc = v;
723 wtap_dumper *wdh = p;
729 guint8 buffer[0x2000];
756 guint8 unk_data[0x10];
767 obj.record.type = g_htonl(K12_REC_SRCDSC);
768 obj.record.unk32_1 = g_htonl(0x00000001);
769 obj.record.input = g_htonl(src_desc->input);
771 obj.record.unk32_2 = g_htonl(0x0000060f);
772 obj.record.unk32_3 = g_htonl(0x00000003);
773 obj.record.unk32_4 = g_htonl(0x01000100);
775 obj.record.unk16_1 = g_htons(0x0000);
776 obj.record.name_len = strlen(src_desc->input_name) + 1;
777 obj.record.stack_len = strlen(src_desc->stack_file) + 1;
779 obj.record.extra.type = g_htonl(src_desc->input_type);
781 switch (src_desc->input_type) {
782 case K12_PORT_ATMPVC:
783 obj.record.extra_len = g_htons(0x18);
784 obj.record.extra.desc.atm.vp = g_htons(src_desc->input_info.atm.vp);
785 obj.record.extra.desc.atm.vc = g_htons(src_desc->input_info.atm.vc);
789 obj.record.extra_len = g_htons(0x18);
790 for( i=0; i<32; i++ ) {
791 obj.record.extra.desc.ds0mask.mask[i] =
792 (src_desc->input_info.ds0mask & (1 << i)) ? 0xff : 0x00;
797 obj.record.extra_len = g_htons(0x08);
802 memcpy(obj.buffer + offset,
803 src_desc->input_name,
804 obj.record.name_len);
806 memcpy(obj.buffer + offset + obj.record.name_len,
807 src_desc->stack_file,
808 obj.record.stack_len);
810 len = offset + obj.record.name_len + obj.record.stack_len;
811 len += (len % 4) ? 4 - (len % 4) : 0;
813 obj.record.len = g_htonl(len);
814 obj.record.name_len = g_htons(obj.record.name_len);
815 obj.record.stack_len = g_htons(obj.record.stack_len);
817 k12_dump_record(wdh,len,obj.buffer);
820 static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
821 const union wtap_pseudo_header *pseudo_header,
822 const guchar *pd, int *err _U_) {
825 guint8 buffer[0x2000];
836 guint8 frame[0x1fc0];
840 if (wdh->dump.k12->num_of_records == 0) {
841 k12_t* file_data = pseudo_header->k12.stuff;
842 g_hash_table_foreach(file_data->src_by_id,k12_dump_src_setting,wdh);
845 obj.record.len = 0x20 + phdr->len;
846 obj.record.len += (obj.record.len % 4) ? 4 - obj.record.len % 4 : 0;
848 len = obj.record.len;
850 obj.record.len = g_htonl(obj.record.len);
852 obj.record.type = g_htonl(K12_REC_PACKET);
853 obj.record.frame_len = g_htonl(phdr->len);
854 obj.record.input = g_htonl(pseudo_header->k12.input);
856 obj.record.ts = GUINT64_TO_BE((((guint64)phdr->ts.secs - 631152000) * 2000000) + (phdr->ts.nsecs / 1000 * 2));
858 memcpy(obj.record.frame,pd,phdr->len);
860 k12_dump_record(wdh,len,obj.buffer);
866 static const guint8 k12_eof[] = {0xff,0xff};
868 static gboolean k12_dump_close(wtap_dumper *wdh, int *err) {
870 guint8 b[sizeof(guint32)];
874 fwrite(k12_eof, 1, 2, wdh->fh);
876 if (fseek(wdh->fh, 8, SEEK_SET) == -1) {
881 d.u = g_htonl(wdh->dump.k12->file_len);
883 fwrite(d.b, 1, 4, wdh->fh);
885 d.u = g_htonl(wdh->dump.k12->num_of_records);
887 fwrite(d.b, 1, 4, wdh->fh);
893 gboolean k12_dump_open(wtap_dumper *wdh, gboolean cant_seek, int *err) {
896 *err = WTAP_ERR_CANT_WRITE_TO_PIPE;
900 if ( fwrite(k12_file_magic, 1, 8, wdh->fh) != 8 ) {
905 if (fseek(wdh->fh, 0x200, SEEK_SET) == -1) {
910 wdh->subtype_write = k12_dump;
911 wdh->subtype_close = k12_dump_close;
913 wdh->dump.k12 = g_malloc(sizeof(k12_dump_t));
914 wdh->dump.k12->file_len = 0x200;
915 wdh->dump.k12->num_of_records = 0;
916 wdh->dump.k12->file_offset = 0x200;