forked from voipmonitor/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sniff.h
177 lines (154 loc) · 4.27 KB
/
sniff.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* Martin Vit [email protected]
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2.
*/
#ifndef SNIFF_H
#define SNIFF_H
#include <queue>
#include <map>
#include "voipmonitor.h"
#include "calltable.h"
#define MAXPACKETLENQRING 1600
#ifdef QUEUE_NONBLOCK
extern "C" {
#include "liblfds.6/inc/liblfds.h"
}
#endif
#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
#define IP_MF 0x2000 /* Flag: "More Fragments" */
#define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
struct iphdr2 {
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int ihl:4;
unsigned int version:4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int version:4;
unsigned int ihl:4;
#else
# error "Please fix <bits/endian.h>"
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
/*The options start here. */
#ifdef PACKED
} __attribute__((packed));
#else
};
#endif
void *rtp_read_thread_func(void *arg);
void *pcap_read_thread_func(void *arg);
//void process_packet(unsigned int saddr, int source, unsigned int daddr, int dest, char *data, int datalen,
// pcap_t *handle, pcap_pkthdr *header, const u_char *packet, int can_thread, int *was_rtp);
void readdump_libnids(pcap_t *handle);
void readdump_libpcap(pcap_t *handle);
inline void save_packet(Call *call, struct pcap_pkthdr *header, const u_char *packet, unsigned int saddr, int source, unsigned int daddr, int dest, int istcp, char *data, int datalen, int type);
typedef std::map<in_addr_t, in_addr_t> nat_aliases_t; //!<
void clean_tcpstreams();
void ipfrag_prune(unsigned int tv_sec, int all);
/* this is copied from libpcap sll.h header file, which is not included in debian distribution */
#define SLL_ADDRLEN 8 /* length of address field */
struct sll_header {
u_int16_t sll_pkttype; /* packet type */
u_int16_t sll_hatype; /* link-layer address type */
u_int16_t sll_halen; /* link-layer address length */
u_int8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */
u_int16_t sll_protocol; /* protocol */
};
struct udphdr2 {
uint16_t source;
uint16_t dest;
uint16_t len;
uint16_t check;
};
typedef struct {
Call *call;
#if defined(QUEUE_MUTEX) || defined(QUEUE_NONBLOCK)
unsigned char *data;
#endif
#ifdef QUEUE_NONBLOCK2
unsigned char data[MAXPACKETLENQRING];
#endif
int datalen;
u_int32_t saddr;
u_int32_t daddr;
unsigned short port;
char iscaller;
char is_rtcp;
struct pcap_pkthdr header;
volatile char free;
} rtp_packet;
typedef struct {
pthread_t thread; // ID of worker storing CDR thread
#ifdef QUEUE_MUTEX
queue<rtp_packet*> pqueue;
pthread_mutex_t qlock;
sem_t semaphore;
#endif
#ifdef QUEUE_NONBLOCK
struct queue_state *pqueue;
#endif
#ifdef QUEUE_NONBLOCK2
rtp_packet *vmbuffer;
int vmbuffermax;
volatile int readit;
volatile int writeit;
#endif
} read_thread;
#if defined(QUEUE_MUTEX) || defined(QUEUE_NONBLOCK)
typedef struct {
struct pcap_pkthdr header;
u_char *packet;
int offset;
} pcap_packet;
#endif
#if defined(QUEUE_NONBLOCK2)
typedef struct {
struct pcap_pkthdr header;
u_char packet[MAXPACKETLENQRING];
u_char *packet2;
int offset;
volatile char free;
} pcap_packet;
#endif
#define MAXLIVEFILTERS 10
#define MAXLIVEFILTERSCHARS 32
typedef struct livesnifferfilter_s {
struct state_s {
bool all_saddr;
bool all_daddr;
bool all_bothaddr;
bool all_addr;
bool all_srcnum;
bool all_dstnum;
bool all_bothnum;
bool all_num;
bool all_siptypes;
bool all_all;
};
unsigned int lv_saddr[MAXLIVEFILTERS];
unsigned int lv_daddr[MAXLIVEFILTERS];
unsigned int lv_bothaddr[MAXLIVEFILTERS];
char lv_srcnum[MAXLIVEFILTERS][MAXLIVEFILTERSCHARS];
char lv_dstnum[MAXLIVEFILTERS][MAXLIVEFILTERSCHARS];
char lv_bothnum[MAXLIVEFILTERS][MAXLIVEFILTERSCHARS];
unsigned char lv_siptypes[MAXLIVEFILTERS];
int uid;
time_t created_at;
state_s state;
void updateState();
} livesnifferfilter_t;
struct livesnifferfilter_use_siptypes_s {
bool u_invite;
bool u_register;
bool u_options;
bool u_subscribe;
bool u_message;
};
#endif