/* Parses a record. */ static gboolean read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; guint8 hdr[EYESDN_HDR_LENGTH]; time_t secs; int usecs; int pkt_len; guint8 channel, direction; int bytes_read; guint8 *pd; /* Our file pointer should be at the summary information header * for a packet. Read in that header and extract the useful * information. */ if (esc_read(hdr, EYESDN_HDR_LENGTH, fh) != EYESDN_HDR_LENGTH) { *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; } /* extract information from header */ usecs = pntoh24(&hdr[0]); #ifdef TV64BITS secs = hdr[3]; #else secs = 0; #endif secs = (secs << 8) | hdr[4]; secs = (secs << 8) | hdr[5]; secs = (secs << 8) | hdr[6]; secs = (secs << 8) | hdr[7]; channel = hdr[8]; direction = hdr[9]; pkt_len = pntoh16(&hdr[10]); switch(direction >> 1) { default: case EYESDN_ENCAP_ISDN: /* ISDN */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; if(channel) { /* bearer channels */ phdr->pkt_encap = WTAP_ENCAP_ISDN; /* recognises PPP */ pseudo_header->isdn.uton=!pseudo_header->isdn.uton; /* bug */ } else { /* D channel */ phdr->pkt_encap = WTAP_ENCAP_ISDN; } break; case EYESDN_ENCAP_MSG: /* Layer 1 message */ phdr->pkt_encap = WTAP_ENCAP_LAYER1_EVENT; pseudo_header->l1event.uton = (direction & 1); break; case EYESDN_ENCAP_LAPB: /* X.25 via LAPB */ phdr->pkt_encap = WTAP_ENCAP_LAPB; pseudo_header->x25.flags = (direction & 1) ? 0 : 0x80; break; case EYESDN_ENCAP_ATM: { /* ATM cells */ #define CELL_LEN 53 unsigned char cell[CELL_LEN]; gint64 cur_off; if(pkt_len != CELL_LEN) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf( "eyesdn: ATM cell has a length != 53 (%u)", pkt_len); return FALSE; } cur_off = file_tell(fh); if (esc_read(cell, CELL_LEN, fh) != CELL_LEN) { *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; } if (file_seek(fh, cur_off, SEEK_SET, err) == -1) return FALSE; phdr->pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; pseudo_header->atm.flags=ATM_RAW_CELL; pseudo_header->atm.aal=AAL_UNKNOWN; pseudo_header->atm.type=TRAF_UMTS_FP; pseudo_header->atm.subtype=TRAF_ST_UNKNOWN; pseudo_header->atm.vpi=((cell[0]&0xf)<<4) + (cell[0]&0xf); pseudo_header->atm.vci=((cell[0]&0xf)<<4) + cell[0]; /* from cell */ pseudo_header->atm.channel=direction & 1; } break; case EYESDN_ENCAP_MTP2: /* SS7 frames */ pseudo_header->mtp2.sent = direction & 1; pseudo_header->mtp2.annex_a_used = MTP2_ANNEX_A_USED_UNKNOWN; pseudo_header->mtp2.link_number = channel; phdr->pkt_encap = WTAP_ENCAP_MTP2_WITH_PHDR; break; case EYESDN_ENCAP_DPNSS: /* DPNSS */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; phdr->pkt_encap = WTAP_ENCAP_DPNSS; break; case EYESDN_ENCAP_DASS2: /* DASS2 frames */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; phdr->pkt_encap = WTAP_ENCAP_DPNSS; break; case EYESDN_ENCAP_BACNET: /* BACNET async over HDLC frames */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; phdr->pkt_encap = WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR; break; case EYESDN_ENCAP_V5_EF: /* V5EF */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; phdr->pkt_encap = WTAP_ENCAP_V5_EF; break; } if(pkt_len > EYESDN_MAX_PACKET_LEN) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("eyesdn: File has %u-byte packet, bigger than maximum of %u", pkt_len, EYESDN_MAX_PACKET_LEN); return FALSE; } phdr->presence_flags = WTAP_HAS_TS; phdr->ts.secs = secs; phdr->ts.nsecs = usecs * 1000; phdr->caplen = pkt_len; phdr->len = pkt_len; /* Make sure we have enough room for the packet */ buffer_assure_space(buf, EYESDN_MAX_PACKET_LEN); errno = WTAP_ERR_CANT_READ; pd = buffer_start_ptr(buf); bytes_read = esc_read(pd, pkt_len, fh); if (bytes_read != pkt_len) { if (bytes_read == -2) { *err = file_error(fh, err_info); if (*err == 0) *err = WTAP_ERR_SHORT_READ; } else if (bytes_read == -1) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup("eyesdn: No flag character seen in frame"); } else *err = WTAP_ERR_SHORT_READ; return FALSE; } return TRUE; }
uint32_t Tvbuff::tvb_get_ntoh24(tvbuff_t *tvb,int offset) { const uint8_t *ptr; ptr = ensure_contiguous(tvb,offset,3); return pntoh24(ptr); }