static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err) { const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; k12_dump_t *k12 = (k12_dump_t *)wdh->priv; guint32 len; union { guint8 buffer[8192]; struct { guint32 len; guint32 type; guint32 frame_len; guint32 input; guint32 datum_1; guint32 datum_2; guint64 ts; guint8 frame[0x1fc0]; } record; } obj; /* We can only write packet records. */ if (phdr->rec_type != REC_TYPE_PACKET) { *err = WTAP_ERR_REC_TYPE_UNSUPPORTED; return FALSE; } if (k12->num_of_records == 0) { k12_t* file_data = (k12_t*)pseudo_header->k12.stuff; /* XXX: We'll assume that any fwrite errors in k12_dump_src_setting will */ /* repeat during the final k12_dump_record at the end of k12_dump */ /* (and thus cause an error return from k12_dump). */ /* (I don't see a reasonably clean way to handle any fwrite errors */ /* encountered in k12_dump_src_setting). */ g_hash_table_foreach(file_data->src_by_id,k12_dump_src_setting,wdh); } obj.record.len = 0x20 + phdr->caplen; obj.record.len += (obj.record.len % 4) ? 4 - obj.record.len % 4 : 0; len = obj.record.len; obj.record.len = g_htonl(obj.record.len); obj.record.type = g_htonl(K12_REC_PACKET); obj.record.frame_len = g_htonl(phdr->caplen); obj.record.input = g_htonl(pseudo_header->k12.input); obj.record.ts = GUINT64_TO_BE((((guint64)phdr->ts.secs - 631152000) * 2000000) + (phdr->ts.nsecs / 1000 * 2)); memcpy(obj.record.frame,pd,phdr->caplen); return k12_dump_record(wdh,len,obj.buffer, err); }
static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) { k12_src_desc_t* src_desc = (k12_src_desc_t*)v; wtap_dumper *wdh = (wtap_dumper *)p; guint32 len; guint offset; guint i; int errxxx; /* dummy */ union { guint8 buffer[8192]; struct { guint32 len; guint32 type; guint32 unk32_1; guint32 input; guint16 unk32_2; guint16 color; guint32 unk32_3; guint32 unk32_4; guint16 unk16_1; guint16 hwpart_len; guint16 name_len; guint16 stack_len; struct { guint32 type; union { struct { guint32 unk32; guint8 mask[32]; } ds0mask; struct { guint8 unk_data[16]; guint16 vp; guint16 vc; } atm; guint32 unk; } desc; } extra; } record; } obj; obj.record.type = g_htonl(K12_REC_SRCDSC); obj.record.unk32_1 = g_htonl(0x00000001); obj.record.input = g_htonl(src_desc->input); obj.record.unk32_2 = g_htons(0x0000); obj.record.color = g_htons(0x060f); obj.record.unk32_3 = g_htonl(0x00000003); switch (src_desc->input_type) { case K12_PORT_ATMPVC: obj.record.unk32_4 = g_htonl(0x01001400); break; default: obj.record.unk32_4 = g_htonl(0x01000100); } obj.record.unk16_1 = g_htons(0x0000); obj.record.name_len = (guint16) strlen(src_desc->input_name) + 1; obj.record.stack_len = (guint16) strlen(src_desc->stack_file) + 1; obj.record.extra.type = g_htonl(src_desc->input_type); switch (src_desc->input_type) { case K12_PORT_ATMPVC: obj.record.hwpart_len = g_htons(0x18); obj.record.extra.desc.atm.vp = g_htons(src_desc->input_info.atm.vp); obj.record.extra.desc.atm.vc = g_htons(src_desc->input_info.atm.vc); offset = 0x3c; break; case K12_PORT_DS0S: obj.record.hwpart_len = g_htons(0x18); for( i=0; i<32; i++ ) { obj.record.extra.desc.ds0mask.mask[i] = (src_desc->input_info.ds0mask & (1UL << i)) ? 0xff : 0x00; } offset = 0x3c; break; default: obj.record.hwpart_len = g_htons(0x08); offset = 0x2c; break; } memcpy(obj.buffer + offset, src_desc->input_name, obj.record.name_len); memcpy(obj.buffer + offset + obj.record.name_len, src_desc->stack_file, obj.record.stack_len); len = offset + obj.record.name_len + obj.record.stack_len; len += (len % 4) ? 4 - (len % 4) : 0; obj.record.len = g_htonl(len); obj.record.name_len = g_htons(obj.record.name_len); obj.record.stack_len = g_htons(obj.record.stack_len); k12_dump_record(wdh,len,obj.buffer, &errxxx); /* fwrite errs ignored: see k12_dump below */ }