Example #1
0
/* new file arrived */
gboolean capture_info_new_file(const char *new_filename)
{
    int err;
    gchar *err_info;
    gchar *err_msg;


    if(info_data.wtap != NULL) {
        wtap_close(info_data.wtap);
    }

    info_data.wtap = wtap_open_offline(new_filename, &err, &err_info, FALSE);
    if (!info_data.wtap) {
        err_msg = g_strdup_printf(cf_open_error_message(err, err_info, FALSE, WTAP_FILE_PCAP),
                                  new_filename);
        g_warning("capture_info_new_file: %d (%s)", err, err_msg);
        g_free (err_msg);
        return FALSE;
    } else
        return TRUE;
}
Example #2
0
/* new file arrived */
gboolean capture_info_new_file(const char *new_filename, info_data_t* cap_info)
{
    int err;
    gchar *err_info;
    gchar *err_msg;


    if(cap_info->wtap != NULL) {
        wtap_close(cap_info->wtap);
    }

    cap_info->wtap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
    if (!cap_info->wtap) {
        err_msg = g_strdup_printf(cf_open_error_message(err, err_info, FALSE, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN),
                                  new_filename);
        g_warning("capture_info_new_file: %d (%s)", err, err_msg);
        g_free (err_msg);
        return FALSE;
    } else
        return TRUE;
}
Example #3
0
cf_status_t cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
{
  wtap       *wth;
  gchar       *err_info;
  //char        err_msg[2048+1];

  dprintf("%s: fname =  %s\n", __FUNCTION__, fname);
  dprintf("%s: is_tempfile = %d  err = %p\n", __FUNCTION__, is_tempfile, err);
  wth = wtap_open_offline(fname, err, &err_info, FALSE);
  dprintf("wth = %p\n", wth);
  if (wth == NULL)
    goto fail;

  /* The open succeeded.  Fill in the information for this file. */

#if WIRESHARK_1_4_0
  /* Cleanup all data structures used for dissection. */
  cleanup_dissection();
#endif

  /* Initialize all data structures used for dissection. */
  init_dissection();

  cf->wth = wth;
  cf->f_datalen = 0; /* not used, but set it anyway */

  /* Set the file name because we need it to set the follow stream filter.
     XXX - is that still true?  We need it for other reasons, though,
     in any case. */
  cf->filename = g_strdup(fname);

  /* Indicate whether it's a permanent or temporary file. */
  cf->is_tempfile = is_tempfile;

  /* If it's a temporary capture buffer file, mark it as not saved. */
  cf->user_saved = !is_tempfile;

  cf->cd_t      = wtap_file_type(cf->wth);
  cf->count     = 0;
  cf->drops_known = FALSE;
  cf->drops     = 0;
  cf->snap      = wtap_snapshot_length(cf->wth);
  if (cf->snap == 0)
    {
      /* Snapshot length not known. */
      cf->has_snap = FALSE;
      cf->snap = WTAP_MAX_PACKET_SIZE;
    }
  else
    cf->has_snap = TRUE;
  nstime_set_zero(&cf->elapsed_time);
  nstime_set_unset(&first_ts);
  nstime_set_unset(&prev_dis_ts);
  nstime_set_unset(&prev_cap_ts);

  dprintf("%s: exiting\n", __FUNCTION__);

  return CF_OK;

fail:
  g_snprintf(sharktools_errmsg, sizeof(sharktools_errmsg),
             cf_open_error_message(*err, err_info, cf->cd_t), fname);
  return CF_ERROR;
}