Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

util.c File Reference

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <syslog.h>
#include <errno.h>
#include <sys/stat.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <grp.h>
#include <pwd.h>
#include <netdb.h>
#include <limits.h>
#include <fcntl.h>
#include "snort.h"
#include "mstring.h"
#include "debug.h"
#include "util.h"
#include "parser.h"
#include "inline.h"

Go to the source code of this file.

Defines

#define PATH_MAX_UTIL   1024

Functions

void GenHomenet (char *netdata)
void GenObfuscationMask (char *netdata)
void DefineIfaceVar (char *iname, u_char *network, u_char *netmask)
float CalcPct (float cnt, float total)
int DisplayBanner ()
void ts_print (register const struct timeval *tvp, char *timebuf)
int gmt2local (time_t t)
char * copy_argv (char **argv)
int strip (char *data)
void InitNetmasks ()
void PrintError (char *str)
void ErrorMessage (const char *format,...)
void LogMessage (const char *format,...)
void FatalError (const char *format,...)
void FatalPrintError (char *msg)
void CreatePidFile (char *intf)
void SetUidGid (void)
void DropStats (int iParamIgnored)
void InitProtoNames ()
void CleanupProtoNames ()
char * read_infile (char *fname)
void CheckLogDir (void)
void GoDaemon (void)
void * SPAlloc (unsigned long size, struct _SPMemControl *spmc)
void * SnortAlloc (unsigned long size)
void SetChroot (char *directory, char **logstore)
char * CurrentWorkingDir (void)
char * GetAbsolutePath (char *dir)

Variables

u_long netmasks [33]


Define Documentation

#define PATH_MAX_UTIL   1024
 

Definition at line 64 of file util.c.

Referenced by CurrentWorkingDir(), and GetAbsolutePath().


Function Documentation

float CalcPct float  cnt,
float  total
 

Definition at line 242 of file util.c.

Referenced by DropStats().

void CheckLogDir void   ) 
 

Definition at line 1296 of file util.c.

References access, FatalError(), _progvars::log_dir, pv, S_ISDIR, snprintf, STD_BUF, and W_OK.

Referenced by CreatePidFile(), and SnortMain().

void CleanupProtoNames  ) 
 

Definition at line 1213 of file util.c.

References NULL, and protocol_names.

char* copy_argv char **  argv  ) 
 

Definition at line 413 of file util.c.

References errno, FatalError(), and NULL.

Referenced by ParseCmdLine().

void CreatePidFile char *  intf  ) 
 

Definition at line 719 of file util.c.

References _PATH_VARRUN, access, CheckLogDir(), ErrorMessage(), FatalError(), int(), _progvars::log_dir, LogMessage(), NULL, _progvars::pid_filename, _progvars::pid_path, _progvars::pidfile_suffix, pv, _progvars::quiet_flag, _progvars::readmode_flag, S_ISDIR, snprintf, STD_BUF, strlcpy, and W_OK.

Referenced by SnortMain().

char* CurrentWorkingDir void   ) 
 

Return a ptr to the absolute pathname of snort. This memory must be copied to another region if you wish to save it for later use.

Definition at line 1538 of file util.c.

References NULL, and PATH_MAX_UTIL.

Referenced by GetAbsolutePath(), and SetChroot().

void DefineIfaceVar char *  iname,
u_char *  network,
u_char *  netmask
 

Definition at line 214 of file util.c.

References snprintf, and VarDefine().

Referenced by OpenPcap().

int DisplayBanner  ) 
 

Definition at line 268 of file util.c.

References BUILD, and VERSION.

Referenced by ParseCmdLine(), and SnortMain().

void DropStats int  iParamIgnored  ) 
 

Definition at line 998 of file util.c.

References _PacketCount::alert_pkts, _PacketCount::arp, CalcPct(), datalink, _PacketCount::discards, DLT_IEEE802_11, _PacketCount::eapol, _PacketCount::ethloopback, _PacketCount::frag_incomp, _PacketCount::frag_mem_faults, _PacketCount::frag_timeout, _PacketCount::frag_trackers, _PacketCount::frags, _PacketCount::icmp, InlineMode(), _PacketCount::ipv6, _PacketCount::ipx, _PacketCount::log_pkts, LogMessage(), _PacketCount::other, _PacketCount::pass_pkts, pc, pcap_perror(), pcap_stats(), pd, pcap_stat::ps_drop, pcap_stat::ps_recv, pv, _progvars::quiet_flag, _progvars::readmode_flag, _PacketCount::rebuild_element, _PacketCount::rebuilt_frags, _PacketCount::rebuilt_segs, _PacketCount::rebuilt_tcp, _PacketCount::str_mem_faults, _PacketCount::tcp, _PacketCount::tcp_stream_pkts, _PacketCount::tcp_streams, _PacketCount::udp, _PacketCount::wifi_control, _PacketCount::wifi_data, and _PacketCount::wifi_mgmt.

Referenced by CleanExit(), Restart(), and SigUsrHandler().

void ErrorMessage const char *  format,
  ...
 

Definition at line 570 of file util.c.

References _progvars::daemon_flag, LOG_CONS, LOG_DAEMON, LOG_ERR, pv, STD_BUF, syslog(), and vsnprintf.

Referenced by AddReference(), base64(), Connect(), CreatePidFile(), Database(), DatabaseInit(), DecodeARP(), DecodeChdlcPkt(), DecodeEapol(), DecodeEthPkt(), DecodeFDDIPkt(), DecodeICMP(), DecodeIEEE80211Pkt(), DecodeIP(), DecodeIPOnly(), DecodeNullPkt(), DecodeOldPflog(), DecodePflog(), DecodePPPoEPkt(), DecodePppPkt(), DecodePppPktEncapsulated(), DecodePppSerialPkt(), DecodeSlipPkt(), DecodeTCP(), DecodeTRPkt(), DecodeUDP(), DecodeVlan(), ExpandVars(), FlowPreprocessor(), Frag3RemoveTracker(), HttpInspectInit(), InitIgnoreHosts(), InitIgnorePorts(), Insert(), InterfaceThread(), OpenAlertSock(), OpenPcap(), ParseClassificationConfig(), ParseConfig(), ParseDatabaseArgs(), ParseMessage(), ParseOutputPlugin(), ParseStream4Args(), Print2ndHeader(), ReferenceSystemAdd(), ScanParseIp(), Select(), SetPktProcessor(), SetUidGid(), and vsyslog().

void FatalError const char *  format,
  ...
 

Definition at line 677 of file util.c.

References _progvars::daemon_flag, LOG_CONS, LOG_DAEMON, LOG_ERR, pv, STD_BUF, syslog(), and vsnprintf.

void FatalPrintError char *  msg  ) 
 

Definition at line 702 of file util.c.

References PrintError().

void GenHomenet char *  netdata  ) 
 

Definition at line 82 of file util.c.

References DEBUG_INIT, DEBUG_WRAP, FatalError(), _progvars::homenet, mSplit(), mSplitFree(), _progvars::netmask, netmasks, and pv.

Referenced by ParseCmdLine(), and ParseConfig().

void GenObfuscationMask char *  netdata  ) 
 

Definition at line 143 of file util.c.

References DEBUG_INIT, DEBUG_WRAP, FatalError(), mSplit(), mSplitFree(), netmasks, _progvars::obfuscation_mask, _progvars::obfuscation_net, and pv.

Referenced by ParseCmdLine().

char* GetAbsolutePath char *  dir  ) 
 

Given a directory name, return a ptr to a static

Definition at line 1555 of file util.c.

References CurrentWorkingDir(), LogMessage(), NULL, and PATH_MAX_UTIL.

Referenced by SetChroot().

int gmt2local time_t  t  ) 
 

Definition at line 372 of file util.c.

References NULL.

Referenced by SnortMain().

void GoDaemon void   ) 
 

Definition at line 1330 of file util.c.

References LogMessage().

Referenced by SnortMain().

void InitNetmasks  ) 
 

Definition at line 505 of file util.c.

References netmasks.

Referenced by SnortMain().

void InitProtoNames  ) 
 

Definition at line 1174 of file util.c.

References char(), protocol_names, and snprintf.

Referenced by SnortMain().

void LogMessage const char *  format,
  ...
 

Definition at line 599 of file util.c.

References _progvars::daemon_flag, LOG_DAEMON, LOG_NOTICE, pv, _progvars::quiet_flag, STD_BUF, syslog(), and vsnprintf.

Referenced by ActivateAction(), ActivateOutputPlugin(), ascii(), BuildMultiPatGroup(), CleanExit(), CommitTransaction(), ConvInit(), CreatePidFile(), DisplayBasePerfStatsConsole(), DisplayEventPerfStats(), DisplayFlowConfig(), DisplayFlowStats(), DisplayStream4Config(), DropStats(), FlowBitsInit(), FlowBitsVerify(), FlowCleanExit(), fpSetDetectSearchMethod(), Frag2Defrag(), Frag3Defrag(), Frag3Expire(), Frag3GlobalInit(), Frag3Init(), Frag3NewTracker(), Frag3ParseArgs(), Frag3ParseGlobalArgs(), Frag3PrintEngineConfig(), Frag3PrintGlobalConfig(), Frag3PrintStats(), Frag3Prune(), GetAbsolutePath(), GetUniqueName(), GoDaemon(), InitOutputPlugins(), InitPlugIns(), InitPreprocessors(), Insert(), InsertFrag(), IpAddrSetPrint(), LoadStateTable(), NewFragTracker(), OpenPcap(), OrderRuleLists(), ParseClassType(), ParseCmdLine(), ParseConfig(), ParseFrag2Args(), ParsePerfMonitorArgs(), ParsePriority(), ParseReference(), ParseRev(), ParseRulesFile(), ParseScanmungeArgs(), ParseSID(), ParseStream4Args(), ParseSyslogArgs(), PortscanInit(), print_thd_local(), print_thd_node(), print_thresholding(), PrintConfig(), PrintConfOpt(), PrintGlobalConf(), PrintPortscanConf(), printRuleListOrder(), PrintServerConf(), ProcessHeadNode(), ProcessUniqueServerConf(), ReadLine(), RebuildFrag(), Restart(), RollbackTransaction(), Scan2Init(), SetPktProcessor(), SetRpcPorts(), SetTags(), SetTelnetPorts(), SetUseDoePtr(), sfRotatePerformanceStatisticsFile(), SigCantHupHandler(), SnortMain(), StoreStreamPkt(), Stream4InitReassembler(), UnifiedLogData(), UnifiedParseArgs(), and XLINK2STATE_ParseArgs().

void PrintError char *  str  ) 
 

Definition at line 551 of file util.c.

References _progvars::daemon_flag, LOG_CONS, LOG_DAEMON, LOG_ERR, pv, and syslog().

Referenced by FatalPrintError(), and SnortMain().

char* read_infile char *  fname  ) 
 

Definition at line 1238 of file util.c.

References errno, FatalError(), int(), NULL, and pcap_strerror().

Referenced by ParseCmdLine(), and ParseConfig().

void SetChroot char *  directory,
char **  logstore
 

Chroot and adjust the pv.log_dir reference

Parameters:
directory directory to chroot to
logdir ptr to pv.log_dir

Definition at line 1435 of file util.c.

References CurrentWorkingDir(), DEBUG_INIT, DEBUG_WRAP, errno, FatalError(), GetAbsolutePath(), NULL, SigCantHupHandler(), and SIGHUP.

Referenced by SnortMain().

void SetUidGid void   ) 
 

just to be on a safe side...

Definition at line 813 of file util.c.

References DEBUG_INIT, DEBUG_WRAP, ErrorMessage(), FatalError(), groupid, groupname, InlineMode(), NULL, userid, and username.

Referenced by SnortMain().

void* SnortAlloc unsigned long  size  ) 
 

Definition at line 1415 of file util.c.

References FatalError(), and NULL.

Referenced by AddFragNode(), AlertCSVParseArgs(), ARPspoofHostInit(), Asn1Init(), CheckDBVersion(), CSVEscape(), Database(), DatabaseInit(), DsizeCheckInit(), DupFragNode(), FlowBitsInit(), FlowBitsParse(), Frag3GlobalInit(), Frag3HandleIPOptions(), Frag3Init(), Frag3InitPkt(), Frag3NewTracker(), Frag3ParseArgs(), FragBitsInit(), GetLastCid(), IcmpCodeCheckInit(), IcmpIdCheckInit(), IcmpSeqCheckInit(), IcmpTypeCheckInit(), IpAddrSetCreate(), IpAddrSetParse(), IpIdCheckInit(), IpOptionInit(), IpProtoInit(), IpSameCheckInit(), IpTosCheckInit(), IsDataAtInit(), NewQueryNode(), ParseAlertFastArgs(), ParseAlertFullArgs(), ParseARPspoofHostArgs(), ParseDatabaseArgs(), ParseSyslogArgs(), RpcCheckInit(), SessionInit(), snort_escape_string(), SnortPcreInit(), TcpAckCheckInit(), TCPFlagCheckInit(), TcpSeqCheckInit(), TcpWinCheckInit(), TemplateInit(), TtlCheckInit(), and UpdateLastCid().

void* SPAlloc unsigned long  size,
struct _SPMemControl spmc
 

Definition at line 1392 of file util.c.

References FatalError(), _SPMemControl::mem_usage, _SPMemControl::memcap, NULL, and _SPMemControl::sp_func.

Referenced by InsertFrag(), and NewFragTracker().

int strip char *  data  ) 
 

Definition at line 461 of file util.c.

Referenced by ParseContentListFile(), and ParseRule().

void ts_print register const struct timeval *  tvp,
char *  timebuf
 

Definition at line 310 of file util.c.

References bzero, gettimeofday(), _progvars::include_year, pv, snprintf, thiszone, TIMEBUF_SIZE, and _progvars::use_utc.

Referenced by AlertFast(), AlertFull(), LogPortscanAlert(), PrintArpHeader(), PrintEapolPkt(), PrintIPPkt(), PrintWifiPkt(), RealAlertCSV(), and SLog().


Variable Documentation

u_long netmasks[33]
 

Definition at line 151 of file snort.c.


Generated on Sun May 14 14:51:27 2006 by  doxygen 1.4.2