Пример #1
0
/* Read the next packet; called from wtap_read(). */
static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
	gint64 *data_offset)
{
  ascend_t *ascend = (ascend_t *)wth->priv;
  gint64 offset;

  /* parse_ascend() will advance the point at which to look for the next
     packet's header, to just after the last packet's header (ie. at the
     start of the last packet's data). We have to get past the last
     packet's header because we might mistake part of it for a new header. */
  if (file_seek(wth->fh, ascend->next_packet_seek_start,
                SEEK_SET, err) == -1)
    return FALSE;

  offset = ascend_seek(wth, err, err_info);
  if (offset == -1)
    return FALSE;
  if (parse_ascend(ascend, wth->fh, &wth->phdr, wth->frame_buffer,
                   wth->snapshot_length) != PARSED_RECORD) {
    *err = WTAP_ERR_BAD_FILE;
    *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error");
    return FALSE;
  }

  *data_offset = offset;
  return TRUE;
}
Пример #2
0
/* Read the next packet; called from wtap_read(). */
static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
	gint64 *data_offset)
{
  ascend_t *ascend = (ascend_t *)wth->priv;
  gint64 offset;
  guint8 *buf = buffer_start_ptr(wth->frame_buffer);
  ascend_pkthdr header;

  /* parse_ascend() will advance the point at which to look for the next
     packet's header, to just after the last packet's header (ie. at the
     start of the last packet's data). We have to get past the last
     packet's header because we might mistake part of it for a new header. */
  if (file_seek(wth->fh, ascend->next_packet_seek_start,
                SEEK_SET, err) == -1)
    return FALSE;

    offset = ascend_seek(wth, err, err_info);
    if (offset == -1)
      return FALSE;
  if (parse_ascend(wth->fh, buf, &wth->phdr.pseudo_header.ascend, &header,
      &(ascend->next_packet_seek_start)) != PARSED_RECORD) {
    *err = WTAP_ERR_BAD_FILE;
    *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error");
    return FALSE;
  }

  buffer_assure_space(wth->frame_buffer, wth->snapshot_length);

  config_pseudo_header(&wth->phdr.pseudo_header);

  if (! ascend->adjusted) {
    ascend->adjusted = 1;
    if (header.start_time != 0) {
      /*
       * Capture file contained a date and time.
       * We do this only if this is the very first packet we've seen -
       * i.e., if "ascend->adjusted" is false - because
       * if we get a date and time after the first packet, we can't
       * go back and adjust the time stamps of the packets we've already
       * processed, and basing the time stamps of this and following
       * packets on the time stamp from the file text rather than the
       * ctime of the capture file means times before this and after
       * this can't be compared.
       */
      ascend->inittime = header.start_time;
    }
    if (ascend->inittime > header.secs)
      ascend->inittime -= header.secs;
  }
  wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
  wth->phdr.ts.secs = header.secs + ascend->inittime;
  wth->phdr.ts.nsecs = header.usecs * 1000;
  wth->phdr.caplen = header.caplen;
  wth->phdr.len = header.len;

  *data_offset = offset;
  return TRUE;
}
Пример #3
0
static gboolean ascend_seek_read(wtap *wth, gint64 seek_off,
        struct wtap_pkthdr *phdr, Buffer *buf,
        int *err, gchar **err_info)
{
  ascend_t *ascend = (ascend_t *)wth->priv;

  if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
    return FALSE;
  if (!parse_ascend(ascend, wth->random_fh, phdr, buf,
                   wth->snapshot_length, err, err_info))
    return FALSE;

  return TRUE;
}
Пример #4
0
static gboolean ascend_seek_read(wtap *wth, gint64 seek_off,
	struct wtap_pkthdr *phdr, Buffer *buf,
	int *err, gchar **err_info)
{
  ascend_t *ascend = (ascend_t *)wth->priv;

  if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
    return FALSE;
  if (parse_ascend(ascend, wth->random_fh, phdr, buf,
                   wth->snapshot_length) != PARSED_RECORD) {
    *err = WTAP_ERR_BAD_FILE;
    *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error");
    return FALSE;
  }

  return TRUE;
}
Пример #5
0
static gboolean ascend_seek_read(wtap *wth, gint64 seek_off,
	struct wtap_pkthdr *phdr, guint8 *pd, int len _U_,
	int *err, gchar **err_info)
{
  union wtap_pseudo_header *pseudo_head = &phdr->pseudo_header;
  ascend_t *ascend = (ascend_t *)wth->priv;

  if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
    return FALSE;
  if (parse_ascend(wth->random_fh, pd, &pseudo_head->ascend, NULL,
      &(ascend->next_packet_seek_start)) != PARSED_RECORD) {
    *err = WTAP_ERR_BAD_FILE;
    *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error");
    return FALSE;
  }

  config_pseudo_header(pseudo_head);
  return TRUE;
}
Пример #6
0
int ascend_open(wtap *wth, int *err, gchar **err_info)
{
  gint64 offset;
  ws_statb64 statbuf;
  guint8 buf[ASCEND_MAX_PKT_LEN];
  ascend_pkthdr header;
  gint64 dummy_seek_start;
  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)
      return 0;
    else
      return -1;
  }

  /* Do a trial parse of the first packet just found to see if we might really have an Ascend file */
  init_parse_ascend();
  if (parse_ascend(wth->fh, buf, &wth->phdr.pseudo_header.ascend, &header,
      &dummy_seek_start) != PARSED_RECORD) {
    return 0;
  }

  wth->file_type = WTAP_FILE_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) {
    g_free(ascend);
    return -1;
  }
  ascend->inittime = statbuf.st_ctime;
  ascend->adjusted = 0;
  wth->tsprecision = WTAP_FILE_TSPREC_USEC;

  init_parse_ascend();

  return 1;
}