int ascend_open(wtap *wth, int *err, gchar **err_info) { gint64 offset; ws_statb64 statbuf; ascend_t *ascend; /* We haven't yet allocated a data structure for our private stuff; set the pointer to null, so that "ascend_seek()" knows not to fill it in. */ wth->priv = NULL; offset = ascend_seek(wth, err, err_info); if (offset == -1) { if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } /* Do a trial parse of the first packet just found to see if we might really have an Ascend file */ init_parse_ascend(); if (!check_ascend(wth->fh, &wth->phdr)) { return 0; } wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ASCEND; switch(wth->phdr.pseudo_header.ascend.type) { case ASCEND_PFX_ISDN_X: case ASCEND_PFX_ISDN_R: wth->file_encap = WTAP_ENCAP_ISDN; break; case ASCEND_PFX_ETHER: wth->file_encap = WTAP_ENCAP_ETHERNET; break; default: wth->file_encap = WTAP_ENCAP_ASCEND; } wth->snapshot_length = ASCEND_MAX_PKT_LEN; wth->subtype_read = ascend_read; wth->subtype_seek_read = ascend_seek_read; ascend = (ascend_t *)g_malloc(sizeof(ascend_t)); wth->priv = (void *)ascend; /* The first packet we want to read is the one that "ascend_seek()" just found; start searching for it at the offset at which it found it. */ ascend->next_packet_seek_start = offset; /* MAXen and Pipelines report the time since reboot. In order to keep from reporting packet times near the epoch, we subtract the first packet's timestamp from the capture file's ctime, which gives us an offset that we can apply to each packet. */ if (wtap_fstat(wth, &statbuf, err) == -1) { return -1; } ascend->inittime = statbuf.st_ctime; ascend->adjusted = FALSE; wth->tsprecision = WTAP_FILE_TSPREC_USEC; init_parse_ascend(); return 1; }
wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info) { gint64 offset; guint8 buf[ASCEND_MAX_PKT_LEN]; ascend_state_t parser_state; ws_statb64 statbuf; ascend_t *ascend; /* We haven't yet allocated a data structure for our private stuff; set the pointer to null, so that "ascend_seek()" knows not to fill it in. */ wth->priv = NULL; offset = ascend_seek(wth, err, err_info); if (offset == -1) { if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return WTAP_OPEN_ERROR; return WTAP_OPEN_NOT_MINE; } /* Do a trial parse of the first packet just found to see if we might really have an Ascend file. If it fails with an actual error, fail; those will be I/O errors. */ if (run_ascend_parser(wth->fh, &wth->phdr, buf, &parser_state, err, err_info) != 0 && *err != 0) { /* An I/O error. */ return WTAP_OPEN_ERROR; } /* Either the parse succeeded, or it failed but didn't get an I/O error. If we got at least some data, return success even if the parser reported an error. This is because the debug header gives the number of bytes on the wire, not actually how many bytes are in the trace. We won't know where the data ends until we run into the next packet. */ if (parser_state.caplen == 0) { /* We read no data, so this presumably isn't an Ascend file. */ return WTAP_OPEN_NOT_MINE; } wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ASCEND; switch(wth->phdr.pseudo_header.ascend.type) { case ASCEND_PFX_ISDN_X: case ASCEND_PFX_ISDN_R: wth->file_encap = WTAP_ENCAP_ISDN; break; case ASCEND_PFX_ETHER: wth->file_encap = WTAP_ENCAP_ETHERNET; break; default: wth->file_encap = WTAP_ENCAP_ASCEND; } wth->snapshot_length = ASCEND_MAX_PKT_LEN; wth->subtype_read = ascend_read; wth->subtype_seek_read = ascend_seek_read; ascend = (ascend_t *)g_malloc(sizeof(ascend_t)); wth->priv = (void *)ascend; /* The first packet we want to read is the one that "ascend_seek()" just found; start searching for it at the offset at which it found it. */ ascend->next_packet_seek_start = offset; /* MAXen and Pipelines report the time since reboot. In order to keep from reporting packet times near the epoch, we subtract the first packet's timestamp from the capture file's ctime, which gives us an offset that we can apply to each packet. */ if (wtap_fstat(wth, &statbuf, err) == -1) { return WTAP_OPEN_ERROR; } ascend->inittime = statbuf.st_ctime; ascend->adjusted = FALSE; wth->file_tsprec = WTAP_TSPREC_USEC; return WTAP_OPEN_MINE; }