suricata
util-time.h File Reference

Go to the source code of this file.

Macros

#define FROM_TIMEVAL(timev)   { .tv_sec = (timev).tv_sec, .tv_nsec = (timev).tv_usec * 1000 }
 intialize a 'struct timespec' from a 'struct timeval'. More...
 
#define TIMEVAL_DIFF_SEC(tv_new, tv_old)
 compare two 'struct timeval' and return the difference in seconds More...
 
#define TIMEVAL_EARLIER(tv_first, tv_second)
 compare two 'struct timeval' and return if the first is earlier than the second More...
 

Functions

void TimeInit (void)
 
void TimeDeinit (void)
 
void TimeSetByThread (const int thread_id, const struct timeval *tv)
 
void TimeGet (struct timeval *)
 
void TimeSet (struct timeval *)
 
void TimeSetToCurrentTime (void)
 set the time to "gettimeofday" meant for testing More...
 
void TimeSetIncrementTime (uint32_t)
 increment the time in the engine More...
 
bool TimeModeIsReady (void)
 
void TimeModeSetLive (void)
 
void TimeModeSetOffline (void)
 
bool TimeModeIsLive (void)
 
struct tm * SCLocalTime (time_t timep, struct tm *result)
 
void CreateTimeString (const struct timeval *ts, char *str, size_t size)
 
void CreateIsoTimeString (const struct timeval *ts, char *str, size_t size)
 
void CreateUtcIsoTimeString (const struct timeval *ts, char *str, size_t size)
 
void CreateFormattedTimeString (const struct tm *t, const char *fmt, char *str, size_t size)
 
time_t SCMkTimeUtc (struct tm *tp)
 Convert broken-down time to seconds since Unix epoch. More...
 
int SCStringPatternToTime (char *string, const char **patterns, int num_patterns, struct tm *time)
 Parse a date string based on specified patterns. More...
 
int SCTimeToStringPattern (time_t epoch, const char *pattern, char *str, size_t size)
 Convert epoch time to string pattern. More...
 
uint64_t SCParseTimeSizeString (const char *str)
 Parse string containing time size (1m, 1h, etc). More...
 
uint64_t SCGetSecondsUntil (const char *str, time_t epoch)
 Get seconds until a time unit changes. More...
 
uint64_t SCTimespecAsEpochMillis (const struct timespec *ts)
 

Detailed Description

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

Definition in file util-time.h.

Macro Definition Documentation

◆ FROM_TIMEVAL

#define FROM_TIMEVAL (   timev)    { .tv_sec = (timev).tv_sec, .tv_nsec = (timev).tv_usec * 1000 }

intialize a 'struct timespec' from a 'struct timeval'.

Definition at line 34 of file util-time.h.

◆ TIMEVAL_DIFF_SEC

#define TIMEVAL_DIFF_SEC (   tv_new,
  tv_old 
)
Value:
(uint64_t)((((uint64_t)(tv_new).tv_sec * 1000000 + (tv_new).tv_usec) - \
((uint64_t)(tv_old).tv_sec * 1000000 + (tv_old).tv_usec)) / \
1000000)

compare two 'struct timeval' and return the difference in seconds

Definition at line 37 of file util-time.h.

◆ TIMEVAL_EARLIER

#define TIMEVAL_EARLIER (   tv_first,
  tv_second 
)
Value:
(((tv_first).tv_sec < (tv_second).tv_sec) || \
((tv_first).tv_sec == (tv_second).tv_sec && (tv_first).tv_usec < (tv_second).tv_usec))

compare two 'struct timeval' and return if the first is earlier than the second

Definition at line 43 of file util-time.h.

Function Documentation

◆ CreateFormattedTimeString()

void CreateFormattedTimeString ( const struct tm *  t,
const char *  fmt,
char *  str,
size_t  size 
)

Definition at line 226 of file util-time.c.

References likely, and str.

Referenced by LogCustomFormatWriteTimestamp().

Here is the caller graph for this function:

◆ CreateIsoTimeString()

void CreateIsoTimeString ( const struct timeval *  ts,
char *  str,
size_t  size 
)

Definition at line 194 of file util-time.c.

References likely, SCLocalTime(), str, and ts.

Referenced by CreateJSONHeader(), and JsonAddFlow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateTimeString()

void CreateTimeString ( const struct timeval *  ts,
char *  str,
size_t  size 
)

Definition at line 252 of file util-time.c.

References likely, SCLocalTime(), str, and ts.

Referenced by AlertFastLogger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateUtcIsoTimeString()

void CreateUtcIsoTimeString ( const struct timeval *  ts,
char *  str,
size_t  size 
)

Definition at line 210 of file util-time.c.

References likely, SCUtcTime(), str, and ts.

Here is the call graph for this function:

◆ SCGetSecondsUntil()

uint64_t SCGetSecondsUntil ( const char *  str,
time_t  epoch 
)

Get seconds until a time unit changes.

Parameters
strString containing time type (minute, hour, etc).
epochEpoch time.
Return values
seconds.

Definition at line 604 of file util-time.c.

References SCLocalTime(), and str.

Here is the call graph for this function:

◆ SCLocalTime()

struct tm* SCLocalTime ( time_t  timep,
struct tm *  result 
)

Definition at line 247 of file util-time.c.

Referenced by CreateIsoTimeString(), CreateTimeString(), LogCustomFormatWriteTimestamp(), SCGetSecondsUntil(), and SCTimeToStringPattern().

Here is the caller graph for this function:

◆ SCMkTimeUtc()

time_t SCMkTimeUtc ( struct tm *  tp)

Convert broken-down time to seconds since Unix epoch.

This function is based on: http://www.catb.org/esr/time-programming (released to the public domain).

Parameters
tpPointer to broken-down time.
Return values
Secondssince Unix epoch.

Definition at line 425 of file util-time.c.

References MONTHSPERYEAR.

◆ SCParseTimeSizeString()

uint64_t SCParseTimeSizeString ( const char *  str)

Parse string containing time size (1m, 1h, etc).

Parameters
strString to parse.
Return values
sizeon success.
0on failure.

Definition at line 553 of file util-time.c.

References str.

◆ SCStringPatternToTime()

int SCStringPatternToTime ( char *  string,
const char **  patterns,
int  num_patterns,
struct tm *  tp 
)

Parse a date string based on specified patterns.

This function is based on GNU C library getdate.

Parameters
stringDate string to parse.
patternsString array containing patterns.
num_patternsNumber of patterns to check.
tpPointer to broken-down time.
Return values
0on success.
1on failure.

Definition at line 468 of file util-time.c.

References strptime().

Here is the call graph for this function:

◆ SCTimespecAsEpochMillis()

uint64_t SCTimespecAsEpochMillis ( const struct timespec *  ts)

Definition at line 622 of file util-time.c.

References ts.

◆ SCTimeToStringPattern()

int SCTimeToStringPattern ( time_t  epoch,
const char *  pattern,
char *  str,
size_t  size 
)

Convert epoch time to string pattern.

This function converts epoch time to a string based on a pattern.

Parameters
epochEpoch time.
patternString pattern.
strFormated string.
sizeSize of allocated string.
Return values
0on success.
1on failure.

Definition at line 524 of file util-time.c.

References SCLocalTime(), str, strlcpy(), and unlikely.

Here is the call graph for this function:

◆ TimeDeinit()

void TimeDeinit ( void  )

Definition at line 85 of file util-time.c.

References SCSpinDestroy.

◆ TimeGet()

void TimeGet ( struct timeval *  )

Definition at line 153 of file util-time.c.

References tv.

Referenced by TimeSetIncrementTime(), UTHBuildPacketIPV6Real(), and UTHBuildPacketReal().

Here is the caller graph for this function:

◆ TimeInit()

void TimeInit ( void  )

Definition at line 77 of file util-time.c.

References SCSpinInit.

Referenced by GlobalsInitPreConfig().

Here is the caller graph for this function:

◆ TimeModeIsLive()

bool TimeModeIsLive ( void  )

Definition at line 109 of file util-time.c.

◆ TimeModeIsReady()

bool TimeModeIsReady ( void  )

Definition at line 90 of file util-time.c.

◆ TimeModeSetLive()

◆ TimeModeSetOffline()

void TimeModeSetOffline ( void  )

Definition at line 103 of file util-time.c.

Referenced by RunModeErfFileAutoFp(), RunModeErfFileSingle(), RunModeFilePcapAutoFp(), and RunModeFilePcapSingle().

Here is the caller graph for this function:

◆ TimeSet()

void TimeSet ( struct timeval *  )

Definition at line 123 of file util-time.c.

Referenced by TimeSetIncrementTime(), and TimeSetToCurrentTime().

Here is the caller graph for this function:

◆ TimeSetByThread()

void TimeSetByThread ( const int  thread_id,
const struct timeval *  tv 
)

Definition at line 114 of file util-time.c.

◆ TimeSetIncrementTime()

void TimeSetIncrementTime ( uint32_t  tv_sec)

increment the time in the engine

Parameters
tv_secseconds to increment the time with

Definition at line 182 of file util-time.c.

References TimeGet(), TimeSet(), and tv.

Here is the call graph for this function:

◆ TimeSetToCurrentTime()

void TimeSetToCurrentTime ( void  )

set the time to "gettimeofday" meant for testing

Definition at line 142 of file util-time.c.

References TimeSet(), and tv.

Here is the call graph for this function: