/* Initialize a timestat_t struct */ void time_stat_init(timestat_t *stats) { stats->num = 0; stats->min_num = 0; stats->max_num = 0; nstime_set_zero(&stats->min); nstime_set_zero(&stats->max); nstime_set_zero(&stats->tot); stats->variance = 0.0; }
WSLUA_METAMETHOD NSTime__unm(lua_State* L) { /* Calculates the negative NSTime */ NSTime time1 = checkNSTime(L,1); NSTime time2 = g_malloc (sizeof (nstime_t)); nstime_set_zero (time2); nstime_subtract (time2, time1); pushNSTime (L, time2); return 1; }
void frame_delta_abs_time(const frame_data *fdata, const frame_data *prev, nstime_t *delta) { if (prev) { nstime_delta(delta, &fdata->abs_ts, &prev->abs_ts); } else { /* If we don't have the time stamp of the previous packet, it's because we have no displayed/captured packets prior to this. Set the delta time to zero. */ nstime_set_zero(delta); } }
void frame_data_set_before_dissect(frame_data *fdata, nstime_t *elapsed_time, nstime_t *first_ts, nstime_t *prev_dis_ts, nstime_t *prev_cap_ts) { /* If we don't have the time stamp of the first packet in the capture, it's because this is the first packet. Save the time stamp of this packet as the time stamp of the first packet. */ if (nstime_is_unset(first_ts)) *first_ts = fdata->abs_ts; /* if this frames is marked as a reference time frame, reset firstsec and firstusec to this frame */ if(fdata->flags.ref_time) *first_ts = fdata->abs_ts; /* If we don't have the time stamp of the previous captured packet, it's because this is the first packet. Save the time stamp of this packet as the time stamp of the previous captured packet. */ if (nstime_is_unset(prev_cap_ts)) *prev_cap_ts = fdata->abs_ts; /* Get the time elapsed between the first packet and this packet. */ nstime_delta(&fdata->rel_ts, &fdata->abs_ts, first_ts); /* If it's greater than the current elapsed time, set the elapsed time to it (we check for "greater than" so as not to be confused by time moving backwards). */ if ((gint32)elapsed_time->secs < fdata->rel_ts.secs || ((gint32)elapsed_time->secs == fdata->rel_ts.secs && (gint32)elapsed_time->nsecs < fdata->rel_ts.nsecs)) { *elapsed_time = fdata->rel_ts; } /* Get the time elapsed between the previous displayed packet and this packet. */ if (nstime_is_unset(prev_dis_ts)) /* If we don't have the time stamp of the previous displayed packet, it's because we have no displayed packets prior to this. Set the delta time to zero. */ nstime_set_zero(&fdata->del_dis_ts); else nstime_delta(&fdata->del_dis_ts, &fdata->abs_ts, prev_dis_ts); /* Get the time elapsed between the previous captured packet and this packet. */ nstime_delta(&fdata->del_cap_ts, &fdata->abs_ts, prev_cap_ts); *prev_cap_ts = fdata->abs_ts; }
void frame_delta_abs_time(const struct epan_session *epan, const frame_data *fdata, guint32 prev_num, nstime_t *delta) { const nstime_t *prev_abs_ts = (prev_num) ? epan_get_frame_ts(epan, prev_num) : NULL; if (prev_abs_ts) { nstime_delta(delta, &fdata->abs_ts, prev_abs_ts); } else { /* If we don't have the time stamp of the previous packet, it's because we have no displayed/captured packets prior to this. Set the delta time to zero. */ nstime_set_zero(delta); } }
static void modify_time_perform(frame_data *fd, int neg, nstime_t *offset, int settozero) { /* The actual shift */ if (settozero == SHIFT_SETTOZERO) { nstime_subtract(&(fd->abs_ts), &(fd->shift_offset)); nstime_set_zero(&(fd->shift_offset)); } if (neg == SHIFT_POS) { nstime_add(&(fd->abs_ts), offset); nstime_add(&(fd->shift_offset), offset); } else if (neg == SHIFT_NEG) { nstime_subtract(&(fd->abs_ts), offset); nstime_subtract(&(fd->shift_offset), offset); } else { fprintf(stderr, "Modify_time_perform: neg = %d?\n", neg); } }
void nvme_add_cmd_to_pending_list(packet_info *pinfo, struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx, void *ctx, guint16 cmd_id) { wmem_tree_key_t cmd_key[3]; guint32 key = cmd_id; cmd_ctx->cmd_pkt_num = pinfo->num; cmd_ctx->cqe_pkt_num = 0; cmd_ctx->cmd_start_time = pinfo->abs_ts; nstime_set_zero(&cmd_ctx->cmd_end_time); cmd_ctx->remote_key = 0; /* this is a new cmd, create a new command context and map it to the unmatched table */ nvme_build_pending_cmd_key(cmd_key, &key); wmem_tree_insert32_array(q_ctx->pending_cmds, cmd_key, (void *)ctx); }
const gchar * time_shift_all(capture_file *cf, const gchar *offset_text) { nstime_t offset; long double offset_float = 0; guint32 i; frame_data *fd; gboolean neg; int h, m; long double f; const gchar *err_str; if (!cf || !offset_text) return "Nothing to work with."; if ((err_str = time_string_parse(offset_text, NULL, NULL, NULL, &neg, &h, &m, &f)) != NULL) return err_str; offset_float = h * 3600 + m * 60 + f; if (offset_float == 0) return "Offset is zero."; nstime_set_zero(&offset); offset.secs = (time_t)floorl(offset_float); offset_float -= offset.secs; offset.nsecs = (int)(offset_float * 1000000000); if ((fd = frame_data_sequence_find(cf->frames, 1)) == NULL) return "No frames found."; /* Shouldn't happen */ modify_time_init(fd); for (i = 1; i <= cf->count; i++) { if ((fd = frame_data_sequence_find(cf->frames, i)) == NULL) continue; /* Shouldn't happen */ modify_time_perform(fd, neg ? SHIFT_NEG : SHIFT_POS, &offset, SHIFT_KEEPOFFSET); } packet_list_queue_draw(); return NULL; }
/* From packet-dvbci.c read a utc_time field in an apdu and write it to utc_time the encoding of the field is according to DVB-SI specification, section 5.2.5 16bit modified julian day (MJD), 24bit 6*4bit BCD digits hhmmss return the length in bytes or -1 for error */ gint packet_mpeg_sect_mjd_to_utc_time(tvbuff_t *tvb, gint offset, nstime_t *utc_time) { gint bcd_time_offset; /* start offset of the bcd time in the tvbuff */ guint8 hour, min, sec; if (!utc_time) return -1; nstime_set_zero(utc_time); utc_time->secs = (tvb_get_ntohs(tvb, offset) - 40587) * 86400; bcd_time_offset = offset+2; hour = MPEG_SECT_BCD44_TO_DEC(tvb_get_guint8(tvb, bcd_time_offset)); min = MPEG_SECT_BCD44_TO_DEC(tvb_get_guint8(tvb, bcd_time_offset+1)); sec = MPEG_SECT_BCD44_TO_DEC(tvb_get_guint8(tvb, bcd_time_offset+2)); if (hour>23 || min>59 || sec>59) return -1; utc_time->secs += hour*3600 + min*60 + sec; return 5; }
bool CaptureFile::open() { //wtap *wth; gchar *err_info; int err; resetState(); wth = wtap_open_offline(filename.c_str(), &err, &err_info, TRUE); if (wth == NULL) { if (err != 0) { /* Print a message noting that the read failed somewhere along the line. */ switch (err) { case WTAP_ERR_UNSUPPORTED_ENCAP: { ostringstream s; s << "File " << filename << " has a packet with a network type that is not supported. (" << err_info << ")"; g_free(err_info); errorMessage = s.str(); break; } case WTAP_ERR_CANT_READ: { ostringstream s; s << "An attempt to read from file " << filename << " failed for some unknown reason."; errorMessage = s.str(); break; } case WTAP_ERR_SHORT_READ: { ostringstream s; s << "File " << filename << " appears to have been cut short in the middle of a packet."; errorMessage = s.str(); break; } case WTAP_ERR_BAD_RECORD: { ostringstream s; s << "File " << filename << " appears to be damaged or corrupt."; errorMessage = s.str(); g_free(err_info); break; } default: { ostringstream s; s << "An error occurred while reading" << " file " << filename << ": " << wtap_strerror(err); errorMessage = s.str(); break; } } } return false; } /* Initialize all data structures used for dissection. */ init_dissection(); /* We're about to start reading the file. */ state = FILE_READ_IN_PROGRESS; //wth = wth; f_datalen = 0; cd_t = wtap_file_type(wth); count = 0; displayed_count = 0; marked_count = 0; drops_known = FALSE; drops = 0; snap = wtap_snapshot_length(wth); if (snap == 0) { /* Snapshot length not known. */ has_snap = FALSE; snap = WTAP_MAX_PACKET_SIZE; } else has_snap = TRUE; nstime_set_zero(&elapsed_time); nstime_set_unset(&first_ts); nstime_set_unset(&prev_dis_ts); #if GLIB_CHECK_VERSION(2,10,0) #else /* memory chunks have been deprecated in favor of the slice allocator, * which has been added in 2.10 */ plist_chunk = g_mem_chunk_new("frame_data_chunk", sizeof (frame_data), FRAME_DATA_CHUNK_SIZE * sizeof (frame_data), G_ALLOC_AND_FREE); g_assert(plist_chunk); #endif /* change the time formats now, as we might have a new precision */ //cf_change_time_formats(cf);//FIXME ?? return true; }
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; }
const gchar * time_shift_adjtime(capture_file *cf, guint packet1_num, const gchar *time1_text, guint packet2_num, const gchar *time2_text) { nstime_t nt1, nt2, ot1, ot2, nt3; nstime_t dnt, dot, d3t; frame_data *fd, *packet1fd, *packet2fd; guint32 i; const gchar *err_str; if (!cf || !time1_text || !time2_text) return "Nothing to work with."; if (packet1_num < 1 || packet1_num > cf->count || packet2_num < 1 || packet2_num > cf->count) return "Packet out of range."; /* * The following time format is allowed: * [YYYY-MM-DD] hh:mm:ss(.decimals)? * * Since Wireshark doesn't support regular expressions (please prove me * wrong :-) we will have to figure it out ourselves in the * following order: * * 1. YYYY-MM-DD hh:mm:ss.decimals * 2. hh:mm:ss.decimals * */ /* * Get a copy of the real time (abs_ts - shift_offset) do we can find out the * difference between the specified time and the original packet */ if ((packet1fd = frame_data_sequence_find(cf->frames, packet1_num)) == NULL) return "No frames found."; nstime_copy(&ot1, &(packet1fd->abs_ts)); nstime_subtract(&ot1, &(packet1fd->shift_offset)); if ((err_str = time_string_to_nstime(time1_text, &ot1, &nt1)) != NULL) return err_str; /* * Get a copy of the real time (abs_ts - shift_offset) do we can find out the * difference between the specified time and the original packet */ if ((packet2fd = frame_data_sequence_find(cf->frames, packet2_num)) == NULL) return "No frames found."; nstime_copy(&ot2, &(packet2fd->abs_ts)); nstime_subtract(&ot2, &(packet2fd->shift_offset)); if ((err_str = time_string_to_nstime(time2_text, &ot2, &nt2)) != NULL) return err_str; nstime_copy(&dot, &ot2); nstime_subtract(&dot, &ot1); nstime_copy(&dnt, &nt2); nstime_subtract(&dnt, &nt1); /* Up to here nothing is changed */ if (!frame_data_sequence_find(cf->frames, 1)) return "No frames found."; /* Shouldn't happen */ for (i = 1; i <= cf->count; i++) { if ((fd = frame_data_sequence_find(cf->frames, i)) == NULL) continue; /* Shouldn't happen */ /* Set everything back to the original time */ nstime_subtract(&(fd->abs_ts), &(fd->shift_offset)); nstime_set_zero(&(fd->shift_offset)); /* Add the difference to each packet */ calcNT3(&ot1, &(fd->abs_ts), &nt1, &nt3, &dot, &dnt); nstime_copy(&d3t, &nt3); nstime_subtract(&d3t, &(fd->abs_ts)); modify_time_perform(fd, SHIFT_POS, &d3t, SHIFT_SETTOZERO); } packet_list_queue_draw(); return NULL; }