Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Functions
time_util.h File Reference
#include <wireshark.h>
#include <time.h>

Go to the source code of this file.

Functions

WS_DLL_PUBLIC time_t mktime_utc (struct tm *tm)
 Converts a UTC-based broken-down time to a timestamp.
 
WS_DLL_PUBLIC bool tm_is_valid (struct tm *tm)
 Validates the fields of a broken-down time structure.
 
WS_DLL_PUBLIC void get_resource_usage (double *user_time, double *sys_time)
 Retrieves the current process CPU usage.
 
WS_DLL_PUBLIC void log_resource_usage (bool reset_delta, const char *format,...)
 Logs the process CPU usage along with a formatted message.
 
WS_DLL_PUBLIC uint64_t create_timestamp (void)
 Fetches the number of microseconds since the Unix epoch.
 
WS_DLL_PUBLIC void ws_tzset (void)
 Initializes or updates timezone settings.
 
WS_DLL_PUBLIC struct timespec * ws_clock_get_realtime (struct timespec *ts)
 Retrieves the current real-time clock value.
 
WS_DLL_PUBLIC struct tm * ws_localtime_r (const time_t *timep, struct tm *result)
 Converts a time value to local time.
 
WS_DLL_PUBLIC struct tm * ws_gmtime_r (const time_t *timep, struct tm *result)
 Converts a time value to UTC (GMT).
 

Detailed Description

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

SPDX-License-Identifier: GPL-2.0-or-later

Function Documentation

◆ create_timestamp()

WS_DLL_PUBLIC uint64_t create_timestamp ( void  )

Fetches the number of microseconds since the Unix epoch.

Returns the current time as a 64-bit unsigned integer representing microseconds since midnight (00:00:00), January 1, 1970 (UTC).

Returns
The current timestamp in microseconds since the epoch.

◆ get_resource_usage()

WS_DLL_PUBLIC void get_resource_usage ( double *  user_time,
double *  sys_time 
)

Retrieves the current process CPU usage.

Fetches the amount of time the process has spent in user and system (kernel) mode, and stores the values in seconds.

Parameters
user_timePointer to receive user-mode CPU time in seconds.
sys_timePointer to receive system-mode CPU time in seconds.

◆ log_resource_usage()

WS_DLL_PUBLIC void log_resource_usage ( bool  reset_delta,
const char *  format,
  ... 
)

Logs the process CPU usage along with a formatted message.

Prints the current user and system CPU times, and optionally resets the delta used for tracking elapsed time between measurements.

Parameters
reset_deltaIf true, resets the delta timer after logging.
formatPrintf-style format string for the log message.
...Arguments for the format string.

◆ mktime_utc()

WS_DLL_PUBLIC time_t mktime_utc ( struct tm *  tm)

Converts a UTC-based broken-down time to a timestamp.

Converts a struct tm representing a UTC time into a time_t value. This is similar to mktime() but assumes the input is in UTC rather than local time.

Parameters
tmPointer to a struct tm representing UTC time.
Returns
The corresponding time_t value.

◆ tm_is_valid()

WS_DLL_PUBLIC bool tm_is_valid ( struct tm *  tm)

Validates the fields of a broken-down time structure.

Checks whether the values in a struct tm are within valid ranges. Only tm_year, tm_mon, tm_mday, tm_hour, tm_min, and tm_sec are validated. Fields tm_wday, tm_yday, and tm_isdst are ignored.

Parameters
tmPointer to the struct tm to validate.
Returns
true if the structure contains valid values, false otherwise.

◆ ws_clock_get_realtime()

WS_DLL_PUBLIC struct timespec * ws_clock_get_realtime ( struct timespec *  ts)

Retrieves the current real-time clock value.

Fills the provided timespec structure with the current time from the system clock.

Parameters
tsPointer to a struct timespec to receive the current time.
Returns
Pointer to the same ts structure, or NULL on failure.

◆ ws_gmtime_r()

WS_DLL_PUBLIC struct tm * ws_gmtime_r ( const time_t *  timep,
struct tm *  result 
)

Converts a time value to UTC (GMT).

Thread-safe version of gmtime(). Converts a time_t value to a struct tm representing UTC time. The result is stored in the caller-provided buffer.

Parameters
timepPointer to the time value to convert.
resultPointer to a struct tm to receive the result.
Returns
Pointer to result, or NULL on failure.

◆ ws_localtime_r()

WS_DLL_PUBLIC struct tm * ws_localtime_r ( const time_t *  timep,
struct tm *  result 
)

Converts a time value to local time.

Thread-safe version of localtime(). Converts a time_t value to a struct tm representing local time. The result is stored in the caller-provided buffer.

Parameters
timepPointer to the time value to convert.
resultPointer to a struct tm to receive the result.
Returns
Pointer to result, or NULL on failure.

◆ ws_tzset()

WS_DLL_PUBLIC void ws_tzset ( void  )

Initializes or updates timezone settings.

Calls the system-specific timezone setup routine (e.g., tzset()) to ensure local time conversions reflect the current environment.