suricata
util-time.h File Reference

Go to the source code of this file.

Data Structures

struct  SCTime_t
 

Macros

#define SCTIME_INIT(t)
 
#define SCTIME_USECS(t)   ((uint64_t)(t).usecs)
 
#define SCTIME_SECS(t)   ((uint64_t)(t).secs)
 
#define SCTIME_MSECS(t)   (SCTIME_SECS(t) * 1000 + SCTIME_USECS(t) / 1000)
 
#define SCTIME_ADD_SECS(ts, s)   SCTIME_FROM_SECS((ts).secs + (s))
 
#define SCTIME_ADD_USECS(ts, us)   SCTIME_FROM_USECS((ts).usecs + (us))
 
#define SCTIME_FROM_SECS(s)
 
#define SCTIME_FROM_USECS(us)
 
#define SCTIME_FROM_TIMEVAL(tv)
 
#define SCTIME_FROM_TIMESPEC(ts)
 
#define SCTIME_TO_TIMEVAL(tv, t)
 
#define SCTIME_CMP(a, b, CMP)
 
#define SCTIME_CMP_GTE(a, b)   SCTIME_CMP((a), (b), >=)
 
#define SCTIME_CMP_GT(a, b)   SCTIME_CMP((a), (b), >)
 
#define SCTIME_CMP_LT(a, b)   SCTIME_CMP((a), (b), <)
 
#define SCTIME_CMP_LTE(a, b)   SCTIME_CMP((a), (b), <=)
 
#define FROM_TIMEVAL(timev)   { .tv_sec = (timev).tv_sec, .tv_nsec = (timev).tv_usec * 1000 }
 initialize a 'struct timespec' from a 'struct timeval'. More...
 
#define timeradd(a, b, r)
 

Functions

void TimeInit (void)
 
void TimeDeinit (void)
 
void TimeSetByThread (const int thread_id, SCTime_t tv)
 
SCTime_t TimeGet (void)
 
void TimeSet (SCTime_t)
 
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 SCTime_t ts, char *str, size_t size)
 
void CreateIsoTimeString (const SCTime_t ts, char *str, size_t size)
 
void CreateUtcIsoTimeString (const SCTime_t 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)
 
uint64_t TimeDifferenceMicros (struct timeval t0, struct timeval t1)
 

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 }

initialize a 'struct timespec' from a 'struct timeval'.

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

◆ SCTIME_ADD_SECS

#define SCTIME_ADD_SECS (   ts,
 
)    SCTIME_FROM_SECS((ts).secs + (s))

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

◆ SCTIME_ADD_USECS

#define SCTIME_ADD_USECS (   ts,
  us 
)    SCTIME_FROM_USECS((ts).usecs + (us))

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

◆ SCTIME_CMP

#define SCTIME_CMP (   a,
  b,
  CMP 
)
Value:
((SCTIME_SECS(a) == SCTIME_SECS(b)) ? (SCTIME_USECS(a) CMP SCTIME_USECS(b)) \
: (SCTIME_SECS(a) CMP SCTIME_SECS(b)))

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

◆ SCTIME_CMP_GT

#define SCTIME_CMP_GT (   a,
 
)    SCTIME_CMP((a), (b), >)

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

◆ SCTIME_CMP_GTE

#define SCTIME_CMP_GTE (   a,
 
)    SCTIME_CMP((a), (b), >=)

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

◆ SCTIME_CMP_LT

#define SCTIME_CMP_LT (   a,
 
)    SCTIME_CMP((a), (b), <)

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

◆ SCTIME_CMP_LTE

#define SCTIME_CMP_LTE (   a,
 
)    SCTIME_CMP((a), (b), <=)

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

◆ SCTIME_FROM_SECS

#define SCTIME_FROM_SECS (   s)
Value:
{ \
.secs = (s), .usecs = 0 \
}

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

◆ SCTIME_FROM_TIMESPEC

#define SCTIME_FROM_TIMESPEC (   ts)
Value:
{ \
.secs = (ts)->tv_sec, .usecs = (ts)->tv_nsec * 1000 \
}

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

◆ SCTIME_FROM_TIMEVAL

#define SCTIME_FROM_TIMEVAL (   tv)
Value:
{ \
.secs = (tv)->tv_sec, .usecs = (tv)->tv_usec \
}

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

◆ SCTIME_FROM_USECS

#define SCTIME_FROM_USECS (   us)
Value:
{ \
.secs = 0, .usecs = (us) \
}

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

◆ SCTIME_INIT

#define SCTIME_INIT (   t)
Value:
{ \
(t).secs = 0; \
(t).usecs = 0; \
}

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

◆ SCTIME_MSECS

#define SCTIME_MSECS (   t)    (SCTIME_SECS(t) * 1000 + SCTIME_USECS(t) / 1000)

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

◆ SCTIME_SECS

#define SCTIME_SECS (   t)    ((uint64_t)(t).secs)

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

◆ SCTIME_TO_TIMEVAL

#define SCTIME_TO_TIMEVAL (   tv,
 
)
Value:
(tv)->tv_sec = SCTIME_SECS((t)); \
(tv)->tv_usec = SCTIME_USECS((t));

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

◆ SCTIME_USECS

#define SCTIME_USECS (   t)    ((uint64_t)(t).usecs)

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

◆ timeradd

#define timeradd (   a,
  b,
 
)
Value:
do { \
(r)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(r)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
if ((r)->tv_usec >= 1000000) { \
(r)->tv_sec++; \
(r)->tv_usec -= 1000000; \
} \
} while (0)

Definition at line 121 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 246 of file util-time.c.

References likely, and str.

Referenced by LogCustomFormatWriteTimestamp().

Here is the caller graph for this function:

◆ CreateIsoTimeString()

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

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

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

Referenced by CreateEveHeader(), and EveAddFlow().

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

◆ CreateTimeString()

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

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

References likely, SCLocalTime(), SCTIME_SECS, SCTIME_USECS, 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 SCTime_t  ts,
char *  str,
size_t  size 
)

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

References likely, SCTIME_SECS, SCTIME_USECS, 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 621 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 267 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 442 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 570 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 485 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 639 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 541 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 87 of file util-time.c.

References SCSpinDestroy.

◆ TimeDifferenceMicros()

uint64_t TimeDifferenceMicros ( struct timeval  t0,
struct timeval  t1 
)

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

◆ TimeGet()

SCTime_t TimeGet ( void  )

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

References tv.

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

Here is the caller graph for this function:

◆ TimeInit()

void TimeInit ( void  )

Definition at line 79 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 111 of file util-time.c.

◆ TimeModeIsReady()

bool TimeModeIsReady ( void  )

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

◆ TimeModeSetLive()

◆ TimeModeSetOffline()

void TimeModeSetOffline ( void  )

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

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

Here is the caller graph for this function:

◆ TimeSet()

void TimeSet ( SCTime_t  )

Definition at line 125 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,
SCTime_t  tv 
)

Definition at line 116 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 180 of file util-time.c.

References SCTIME_ADD_SECS, TimeGet(), TimeSet(), and ts.

Here is the call graph for this function:

◆ TimeSetToCurrentTime()

void TimeSetToCurrentTime ( void  )

set the time to "gettimeofday" meant for testing

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

References SCTIME_FROM_TIMEVAL, TimeSet(), ts, and tv.

Here is the call graph for this function:
ts
uint64_t ts
Definition: source-erf-file.c:55
SCTime_t
Definition: util-time.h:40
SCTIME_SECS
#define SCTIME_SECS(t)
Definition: util-time.h:51
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
SCTIME_USECS
#define SCTIME_USECS(t)
Definition: util-time.h:50