/* Find the next packet and parse it; called from wtap_read(). */ static gboolean csids_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { csids_t *csids = (csids_t *)wth->priv; guint8 *buf; int bytesRead = 0; struct csids_header hdr; *data_offset = file_tell(wth->fh); bytesRead = file_read( &hdr, sizeof( struct csids_header) , wth->fh ); if( bytesRead != sizeof( struct csids_header) ) { *err = file_error( wth->fh, err_info ); if (*err == 0 && bytesRead != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; } hdr.seconds = pntohl(&hdr.seconds); hdr.caplen = pntohs(&hdr.caplen); /* Make sure we have enough room for the packet */ buffer_assure_space(wth->frame_buffer, hdr.caplen); buf = buffer_start_ptr(wth->frame_buffer); bytesRead = file_read( buf, hdr.caplen, wth->fh ); if( bytesRead != hdr.caplen ) { *err = file_error( wth->fh, err_info ); if (*err == 0) *err = WTAP_ERR_SHORT_READ; return FALSE; } wth->phdr.presence_flags = WTAP_HAS_TS; wth->phdr.len = hdr.caplen; wth->phdr.caplen = hdr.caplen; wth->phdr.ts.secs = hdr.seconds; wth->phdr.ts.nsecs = 0; if( csids->byteswapped ) { if( hdr.caplen >= 2 ) { PBSWAP16(buf); /* the ip len */ if( hdr.caplen >= 4 ) { PBSWAP16(buf+2); /* ip id */ if( hdr.caplen >= 6 ) PBSWAP16(buf+4); /* ip flags and fragoff */ } } } return TRUE; }
static gboolean csids_read_packet(FILE_T fh, csids_t *csids, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { struct csids_header hdr; int bytesRead = 0; guint8 *pd; bytesRead = file_read( &hdr, sizeof( struct csids_header), fh ); if( bytesRead != sizeof( struct csids_header) ) { *err = file_error( fh, err_info ); if (*err == 0 && bytesRead != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; } hdr.seconds = pntohl(&hdr.seconds); hdr.caplen = pntohs(&hdr.caplen); phdr->presence_flags = WTAP_HAS_TS; phdr->len = hdr.caplen; phdr->caplen = hdr.caplen; phdr->ts.secs = hdr.seconds; phdr->ts.nsecs = 0; if( !wtap_read_packet_bytes( fh, buf, phdr->caplen, err, err_info ) ) return FALSE; pd = buffer_start_ptr( buf ); if( csids->byteswapped ) { if( phdr->caplen >= 2 ) { PBSWAP16(pd); /* the ip len */ if( phdr->caplen >= 4 ) { PBSWAP16(pd+2); /* ip id */ if( phdr->caplen >= 6 ) PBSWAP16(pd+4); /* ip flags and fragoff */ } } } return TRUE; }
static gboolean csids_read_packet(FILE_T fh, csids_t *csids, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct csids_header hdr; guint8 *pd; if( !wtap_read_bytes_or_eof( fh, &hdr, sizeof( struct csids_header), err, err_info ) ) return FALSE; hdr.seconds = pntoh32(&hdr.seconds); hdr.caplen = pntoh16(&hdr.caplen); /* * The maximum value of hdr.caplen is 65535, which is less than * WTAP_MAX_PACKET_SIZE_STANDARD will ever be, so we don't need to check * it. */ rec->rec_type = REC_TYPE_PACKET; rec->presence_flags = WTAP_HAS_TS; rec->rec_header.packet_header.len = hdr.caplen; rec->rec_header.packet_header.caplen = hdr.caplen; rec->ts.secs = hdr.seconds; rec->ts.nsecs = 0; if( !wtap_read_packet_bytes( fh, buf, rec->rec_header.packet_header.caplen, err, err_info ) ) return FALSE; pd = ws_buffer_start_ptr( buf ); if( csids->byteswapped ) { if( rec->rec_header.packet_header.caplen >= 2 ) { PBSWAP16(pd); /* the ip len */ if( rec->rec_header.packet_header.caplen >= 4 ) { PBSWAP16(pd+2); /* ip id */ if( rec->rec_header.packet_header.caplen >= 6 ) PBSWAP16(pd+4); /* ip flags and fragoff */ } } } return TRUE; }