Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use libpcap time instead of gettimeofday() in receive thread #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/probe_modules/probe_modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,20 @@ void fs_add_ipv6_fields(fieldset_t *fs, struct ip6_hdr *ipv6_hdr)

#define TIMESTR_LEN 55

void fs_add_system_fields(fieldset_t *fs, int is_repeat, int in_cooldown)
void fs_add_system_fields(fieldset_t *fs, int is_repeat, int in_cooldown, const struct timespec ts)
{
fs_add_bool(fs, "repeat", is_repeat);
fs_add_bool(fs, "cooldown", in_cooldown);

char *timestr = xmalloc(TIMESTR_LEN + 1);
char *timestr_ms = xmalloc(TIMESTR_LEN + 1);
struct timeval t;
gettimeofday(&t, NULL);
struct tm *ptm = localtime(&t.tv_sec);
struct tm *ptm = localtime(&ts.tv_sec);
strftime(timestr, TIMESTR_LEN, "%Y-%m-%dT%H:%M:%S.%%03d%z", ptm);
snprintf(timestr_ms, TIMESTR_LEN, timestr, t.tv_usec / 1000);
snprintf(timestr_ms, TIMESTR_LEN, timestr, ts.tv_nsec / 1000000);
free(timestr);
fs_add_string(fs, "timestamp_str", timestr_ms, 1);
fs_add_uint64(fs, "timestamp_ts", (uint64_t)t.tv_sec);
fs_add_uint64(fs, "timestamp_us", (uint64_t)t.tv_usec);
fs_add_uint64(fs, "timestamp_ts", (uint64_t)ts.tv_sec);
fs_add_uint64(fs, "timestamp_us", (uint64_t)(ts.tv_nsec/1000));
}

int ip_fields_len = 6;
Expand Down Expand Up @@ -161,4 +159,4 @@ fielddef_t sys_fields[] = {
{.name = "timestamp_us",
.type = "int",
.desc =
"microsecond part of timestamp (e.g. microseconds since 'timestamp-ts')"}};
"microsecond part of timestamp (e.g. microseconds since 'timestamp-ts')"}};
2 changes: 1 addition & 1 deletion src/probe_modules/probe_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ probe_module_t *get_probe_module_by_name(const char *);

void fs_add_ip_fields(fieldset_t *fs, struct ip *ip);
void fs_add_ipv6_fields(fieldset_t *fs, struct ip6_hdr *ipv6_hdr);
void fs_add_system_fields(fieldset_t *fs, int is_repeat, int in_cooldown);
void fs_add_system_fields(fieldset_t *fs, int is_repeat, int in_cooldown, const struct timespec ts);
void print_probe_modules(void);

extern int ip_fields_len;
Expand Down
2 changes: 1 addition & 1 deletion src/recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void handle_packet(uint32_t buflen, const u_char *bytes,
bytes = fake_eth_hdr;
}
zconf.probe_module->process_packet(bytes, buflen, fs, validation, ts);
fs_add_system_fields(fs, is_repeat, zsend.complete);
fs_add_system_fields(fs, is_repeat, zsend.complete, ts);
int success_index = zconf.fsconf.success_index;
assert(success_index < fs->len);
int is_success = fs_get_uint64_by_index(fs, success_index);
Expand Down