-
Notifications
You must be signed in to change notification settings - Fork 45
/
util.h
133 lines (116 loc) · 5.35 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* nProbe - a Netflow v5/v9/IPFIX probe for IPv4/v6
*
* Copyright (C) 2002-2010 Luca Deri <[email protected]>
*
* http://www.ntop.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* ********************** */
#define MAX_NUM_NETWORKS 64
#define CONST_INVALIDNETMASK -1
/* ********************************************** */
#ifdef WIN32
#define nprobe_sleep(a /* sec */) waitForNextEvent(1000*a /* ms */)
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
extern void initWinsock32();
extern short isWinNT();
#define close(fd) closesocket(fd)
#else
int nprobe_sleep(int secs);
#endif
extern void traceEvent(const int eventTraceLevel, const char* file, const int line, const char * format, ...);
extern void daemonize(void);
/*
#ifndef WIN32
extern int snprintf(char *string, size_t maxlen, const char *format, ...);
#endif
*/
extern u_int8_t ip2mask(IpAddress ip);
extern void readASs(char *path);
extern void readCities(char *path);
extern V9V10TemplateElementId ver9_templates[];
extern void printTemplateInfo(V9V10TemplateElementId *templates, u_char show_private_elements);
extern void dumpPluginHelp(void);
extern void dumpPluginTemplates(void);
extern void enablePlugins(void);
extern void setupPlugins(void);
extern void initAS(void);
extern void flowPrintf(V9V10TemplateElementId **templateList,
u_int8_t ipv4_template, char *outBuffer,
uint *outBufferBegin, uint *outBufferMax,
int *numElements, char buildTemplate,
FlowHashBucket *theFlow, FlowDirection direction,
int addTypeLen, int optionTemplate);
extern void flowFilePrintf(V9V10TemplateElementId **templateList,
FILE *stream, FlowHashBucket *theFlow,
FlowDirection direction);
extern void compileTemplate(char *_fmt, V9V10TemplateElementId **templateList, int templateElements);
extern double toMs(struct timeval theTime);
extern u_int32_t msTimeDiff(struct timeval *end, struct timeval *begin);
extern unsigned int ntop_sleep(unsigned int secs);
extern FlowHashBucket* getListHead(FlowHashBucket **list);
extern void addToList(FlowHashBucket *bkt, FlowHashBucket **list);
extern void parseInterfaceAddressLists(char* _addresses);
extern void parseLocalAddressLists(char* _addresses);
extern unsigned short isLocalAddress(struct in_addr *addr);
extern u_int32_t str2addr(char *address);
extern char* etheraddr_string(const u_char *ep, char *buf);
extern void setPayloadLength(int len);
extern char* getStandardFieldId(u_int id);
extern u_int16_t ifIdx(FlowHashBucket *theFlow, FlowDirection direction, int inputIf);
extern void bitmask_set(u_int32_t n, bitmask_selector* p);
extern void bitmask_clr(u_int32_t n, bitmask_selector* p);
extern u_int8_t bitmask_isset(u_int32_t n, bitmask_selector* p);
extern void loadApplProtocols(void);
extern u_int16_t port2ApplProtocol(u_int8_t proto, u_int16_t port);
extern void copyInt8(u_int8_t t8, char *outBuffer, uint *outBufferBegin, uint *outBufferMax);
extern void copyInt16(u_int16_t _t16, char *outBuffer, uint *outBufferBegin, uint *outBufferMax);
extern void copyInt32(u_int32_t _t32, char *outBuffer, uint *outBufferBegin, uint *outBufferMax);
extern void copyInt64(u_int64_t _t64, char *outBuffer, uint *outBufferBegin, uint *outBufferMax);
extern void copyLen(u_char *str, int strLen, char *outBuffer, uint *outBufferBegin, uint *outBufferMax);
extern int32_t gmt2local(time_t t);
extern void resetBucketStats(FlowHashBucket* bkt,
const struct pcap_pkthdr *h,
uint len, FlowDirection direction,
u_char *payload, int payloadLen);
extern void maximize_socket_buffer(int sock_fd, int buf_type);
/* bitmask */
extern void reset_bitmask(bitmask_selector *selector);
extern int alloc_bitmask(u_int32_t tot_bits, bitmask_selector *selector);
extern void free_bitmask(bitmask_selector *selector);
/* nprobe.c */
extern int exportBucketToNetflow(FlowHashBucket *myBucket, FlowDirection direction,
u_char free_memory);
extern void parseBlacklistNetworks(char* _addresses);
extern u_short isBlacklistedAddress(struct in_addr *addr) ;
#ifndef min
#define min(a, b) ((a > b) ? b : a)
#endif
#ifndef max
#define max(a, b) ((a > b) ? a : b)
#endif
#ifdef linux
extern void setCpuAffinity(char *dev_name, char *cpuId);
#endif
extern u_int32_t queuedPkts(PacketQueue *queue);
extern u_int32_t numFreeSlots(PacketQueue *queue);
extern int mkdir_p(char *path);
extern void dropPrivileges(void);
extern void dumpLogEvent(LogEventType event_type, LogEventSeverity severity, char *message);
extern char* CollectorAddress2Str(CollectorAddress *collector, char *buf, u_int buf_len);
extern u_int32_t to_msec(struct timeval *tv);
/* ****************************************************** */