Exemplo n.º 1
0
static gboolean
i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
    guint8 *pd, int length, int *err, gchar **err_info)
{
	int	ret;

	if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
		return FALSE;

	/* Read and process the record header. */
	ret = i4b_process_rec_header(wth, wth->random_fh, phdr, err, err_info);
	if (ret <= 0) {
		/* Read error or EOF */
		if (ret == 0) {
			/* EOF means "short read" in random-access mode */
			*err = WTAP_ERR_SHORT_READ;
		}
		return FALSE;
	}

	/*
	 * Read the packet data.
	 */
	return i4b_read_rec_data(wth->random_fh, pd, length, err, err_info);
}
Exemplo n.º 2
0
static gboolean
i4btrace_seek_read(wtap *wth, gint64 seek_off,
    union wtap_pseudo_header *pseudo_header, guint8 *pd, int length,
    int *err, gchar **err_info)
{
	int	ret;
	i4b_trace_hdr_t hdr;

	if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
		return FALSE;

	/* Read record header. */
	ret = i4b_read_rec_header(wth->random_fh, &hdr, err, err_info);
	if (ret <= 0) {
		/* Read error or EOF */
		if (ret == 0) {
			/* EOF means "short read" in random-access mode */
			*err = WTAP_ERR_SHORT_READ;
		}
		return FALSE;
	}
	i4b_byte_swap_header(wth, &hdr);

	i4b_set_pseudo_header(&hdr, pseudo_header);

	/*
	 * Read the packet data.
	 */
	return i4b_read_rec_data(wth->random_fh, pd, length, err, err_info);
}
Exemplo n.º 3
0
/* Read the next packet */
static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
    gint64 *data_offset)
{
	int	ret;
	void *bufp;

	*data_offset = file_tell(wth->fh);

	/* Read and process the record header. */
	ret = i4b_process_rec_header(wth, wth->fh, &wth->phdr, err, err_info);
	if (ret <= 0) {
		/* Read error or EOF */
		return FALSE;
	}

	/*
	 * Read the packet data.
	 */
	buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
	bufp = buffer_start_ptr(wth->frame_buffer);
	if (!i4b_read_rec_data(wth->fh, (guint8 *)bufp, wth->phdr.caplen, err, err_info))
		return FALSE;	/* Read error */

	return TRUE;
}
Exemplo n.º 4
0
/* Read the next packet */
static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
    gint64 *data_offset)
{
	int	ret;
	i4b_trace_hdr_t hdr;
	guint32 length;
	void *bufp;

	/* Read record header. */
	*data_offset = file_tell(wth->fh);
	ret = i4b_read_rec_header(wth->fh, &hdr, err, err_info);
	if (ret <= 0) {
		/* Read error or EOF */
		return FALSE;
	}
	i4b_byte_swap_header(wth, &hdr);
	if (hdr.length < sizeof(hdr)) {
		*err = WTAP_ERR_BAD_FILE;	/* record length < header! */
		*err_info = g_strdup_printf("i4btrace: record length %u < header length %lu",
		    hdr.length, (unsigned long)sizeof(hdr));
		return FALSE;
	}
	length = hdr.length - (guint32)sizeof(hdr);
	if (length > WTAP_MAX_PACKET_SIZE) {
		/*
		 * Probably a corrupt capture file; don't blow up trying
		 * to allocate space for an immensely-large packet.
		 */
		*err = WTAP_ERR_BAD_FILE;
		*err_info = g_strdup_printf("i4btrace: File has %u-byte packet, bigger than maximum of %u",
		    length, WTAP_MAX_PACKET_SIZE);
		return FALSE;
	}

	wth->phdr.presence_flags = WTAP_HAS_TS;

	wth->phdr.len = length;
	wth->phdr.caplen = length;

	wth->phdr.ts.secs = hdr.ts_sec;
	wth->phdr.ts.nsecs = hdr.ts_usec * 1000;

	/*
	 * Read the packet data.
	 */
	buffer_assure_space(wth->frame_buffer, length);
	bufp = buffer_start_ptr(wth->frame_buffer);
	if (!i4b_read_rec_data(wth->fh, bufp, length, err, err_info))
		return FALSE;	/* Read error */

	switch (hdr.type) {

	case TRC_CH_I:
		/*
		 * XXX - what is it?  It's probably not WTAP_ENCAP_NULL,
		 * as that means it has a 4-byte AF_ type as the
		 * encapsulation header.
		 */
		wth->phdr.pkt_encap = WTAP_ENCAP_NULL;
		break;

	case TRC_CH_D:
	case TRC_CH_B1:
	case TRC_CH_B2:
		/*
		 * D or B channel.
		 */
		wth->phdr.pkt_encap = WTAP_ENCAP_ISDN;
		break;
	}

	i4b_set_pseudo_header(&hdr, &wth->pseudo_header);

	return TRUE;
}