suricata
util-time.c File Reference
#include "suricata-common.h"
#include "detect.h"
#include "threads.h"
#include "tm-threads.h"
#include "util-debug.h"
Include dependency graph for util-time.c:

Go to the source code of this file.

Macros

#define MONTHSPERYEAR   12
 

Functions

struct tm * SCLocalTime (time_t timep, struct tm *result)
 
struct tm * SCUtcTime (time_t timep, struct tm *result)
 
void TimeInit (void)
 
void TimeDeinit (void)
 
void TimeModeSetLive (void)
 
void TimeModeSetOffline (void)
 
int TimeModeIsLive (void)
 
void TimeSetByThread (const int thread_id, const struct timeval *tv)
 
void TimeSet (struct timeval *tv)
 
void TimeSetToCurrentTime (void)
 set the time to "gettimeofday" meant for testing More...
 
void TimeGet (struct timeval *tv)
 
void TimeSetIncrementTime (uint32_t tv_sec)
 increment the time in the engine More...
 
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)
 
void CreateTimeString (const struct timeval *ts, 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 *tp)
 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
Ken Steele suric.nosp@m.ata@.nosp@m.tiler.nosp@m.a.co.nosp@m.m

Time keeping for offline (non-live) packet handling (pcap files). And time string generation for alerts.

Definition in file util-time.c.

Macro Definition Documentation

#define MONTHSPERYEAR   12

Referenced by SCMkTimeUtc().

Function Documentation

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

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

References likely.

Referenced by LogCustomFormatWriteTimestamp().

Here is the caller graph for this function:

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

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

References likely, and SCLocalTime().

Referenced by AlertJsonHeader(), CreateJSONHeader(), JsonAddFlow(), SCProfilingRulesGlobalInit(), SCProfilingSghsGlobalInit(), and StatsToJSON().

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

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

Referenced by AlertFastLogger(), CreateTimeString(), and TLSGetIPInformations().

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

References likely, and SCUtcTime().

Referenced by TLSGetIPInformations().

Here is the call graph for this function:

Here is the caller graph for this function:

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 597 of file util-time.c.

References SCLocalTime().

Referenced by SCConfLogOpenGeneric().

Here is the call graph for this function:

Here is the caller graph for this function:

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 418 of file util-time.c.

References MONTHSPERYEAR.

Referenced by DetectTlsValidityRegister().

Here is the caller graph for this function:

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 546 of file util-time.c.

Referenced by SCConfLogOpenGeneric().

Here is the caller graph for this function:

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 461 of file util-time.c.

References strptime().

Referenced by DetectTlsValidityRegister().

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t SCTimespecAsEpochMillis ( const struct timespec *  ts)

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

Referenced by PcapDetermineDirectoryOrFile(), PcapDirectoryDispatch(), and RunModeUnixSocketGetDefaultMode().

Here is the caller graph for this function:

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 517 of file util-time.c.

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

Here is the call graph for this function:

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

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

Referenced by CreateUtcIsoTimeString().

Here is the caller graph for this function:

void TimeDeinit ( void  )

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

References SCSpinDestroy.

Referenced by GlobalsInitPreConfig().

Here is the caller graph for this function:

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:

int TimeModeIsLive ( void  )

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

void TimeModeSetOffline ( void  )

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

References FALSE, and SCLogDebug.

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

Here is the caller graph for this function:

void TimeSet ( struct timeval *  tv)

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

References SCLogDebug, SCSpinLock, SCSpinUnlock, and TRUE.

Referenced by TimeSetIncrementTime(), and TimeSetToCurrentTime().

Here is the caller graph for this function:

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

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

References TmThreadsSetThreadTimestamp(), and TRUE.

Here is the call graph for this function:

void TimeSetIncrementTime ( uint32_t  tv_sec)

increment the time in the engine

Parameters
tv_secseconds to increment the time with

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

References TimeGet(), and TimeSet().

Referenced by DetectDetectionFilterRegister(), DetectThresholdRegister(), FlowUpdateState(), SCThresholdConfParseFile(), TagTimeoutCheck(), TmModuleFlowRecyclerRegister(), and Unified2AlertInitCtx().

Here is the call graph for this function:

Here is the caller graph for this function:

void TimeSetToCurrentTime ( void  )

set the time to "gettimeofday" meant for testing

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

References TimeSet().

Referenced by UtRunTests().

Here is the call graph for this function:

Here is the caller graph for this function: