-
Notifications
You must be signed in to change notification settings - Fork 5
/
core_hep.h
213 lines (170 loc) · 5.12 KB
/
core_hep.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* $Id$
*
* captagent - Homer capture agent. Modular
* Duplicate SIP messages in Homer Encapulate Protocol [HEP] [ipv6 version]
*
* Author: Alexandr Dubovikov <[email protected]>
* (C) Homer Project 2012 (http://www.sipcapture.org)
*
* Copyright (c) 2010-2016 <Alexandr Dubovikov>
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the <SIPCAPTURE>. The name of the SIPCAPTURE may not be used to
* endorse or promote products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#define USE_IPV6
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <pthread.h>
#ifdef USE_IPV6
#include <netinet/ip6.h>
#endif /* USE_IPV6 */
#ifdef USE_ZLIB
#include <zlib.h>
#endif /* USE_ZLIB */
#ifdef USE_SSL
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif /* USE_SSL */
int sock;
long initfails = 0;
struct addrinfo *ai;
struct addrinfo hints[1] = {{ 0 }};
char *capt_host = "10.0.0.1";
char *capt_port = "9060";
char *capt_proto = "udp";
char *capt_password;
int capt_id = 101;
int hep_version = 3;
int usessl = 0;
int pl_compress = 0;
static int sendPacketsCount = 0;
#ifdef USE_SSL
SSL *ssl;
SSL_CTX *ctx;
SSL_CTX* initCTX(void);
#endif /* USE_SSL */
void handler(int value);
int send_hepv3 (rc_info_t *rcinfo, unsigned char *data, unsigned int len, unsigned int sendzip);
int send_hepv2 (rc_info_t *rcinfo, unsigned char *data, unsigned int len);
int send_data (void *buf, unsigned int len);
int init_hepsocket_blocking (void);
int init_hepsocket (void);
int sigPipe(void);
/* HEPv3 types */
struct hep_chunk {
u_int16_t vendor_id;
u_int16_t type_id;
u_int16_t length;
} __attribute__((packed));
typedef struct hep_chunk hep_chunk_t;
struct hep_chunk_uint8 {
hep_chunk_t chunk;
u_int8_t data;
} __attribute__((packed));
typedef struct hep_chunk_uint8 hep_chunk_uint8_t;
struct hep_chunk_uint16 {
hep_chunk_t chunk;
u_int16_t data;
} __attribute__((packed));
typedef struct hep_chunk_uint16 hep_chunk_uint16_t;
struct hep_chunk_uint32 {
hep_chunk_t chunk;
u_int32_t data;
} __attribute__((packed));
typedef struct hep_chunk_uint32 hep_chunk_uint32_t;
struct hep_chunk_str {
hep_chunk_t chunk;
char *data;
} __attribute__((packed));
typedef struct hep_chunk_str hep_chunk_str_t;
struct hep_chunk_ip4 {
hep_chunk_t chunk;
struct in_addr data;
} __attribute__((packed));
typedef struct hep_chunk_ip4 hep_chunk_ip4_t;
struct hep_chunk_ip6 {
hep_chunk_t chunk;
struct in6_addr data;
} __attribute__((packed));
typedef struct hep_chunk_ip6 hep_chunk_ip6_t;
struct hep_ctrl {
char id[4];
u_int16_t length;
} __attribute__((packed));
typedef struct hep_ctrl hep_ctrl_t;
struct hep_chunk_payload {
hep_chunk_t chunk;
char *data;
} __attribute__((packed));
typedef struct hep_chunk_payload hep_chunk_payload_t;
/* Structure of HEP */
struct hep_generic {
hep_ctrl_t header;
hep_chunk_uint8_t ip_family;
hep_chunk_uint8_t ip_proto;
hep_chunk_uint16_t src_port;
hep_chunk_uint16_t dst_port;
hep_chunk_uint32_t time_sec;
hep_chunk_uint32_t time_usec;
hep_chunk_uint8_t proto_t;
hep_chunk_uint32_t capt_id;
} __attribute__((packed));
typedef struct hep_generic hep_generic_t;
/*
static hep_generic_t HDR_HEP = {
{0x48455033, 0x0},
{0, 0x0001, 0x00, 0x00},
{0, 0x0002, 0x00, 0x00},
{0, 0x0003, 0x00, 0x00},
{0, 0x0004, 0x00, 0x00},
{0, 0x0005, 0x00, 0x00},
{0, 0x0006, 0x00, 0x00},
{0, 0x0007, 0x00, 0x00},
{0, 0x0008, 0x00, 0x00},
{0, 0x0009, 0x00, 0x00},
{0, 0x000a, 0x00, 0x00},
{0, 0x000b, 0x00, 0x00},
{0, 0x000c, 0x00, 0x00},
{0, 0x000d, 0x00, 0x00},
{0, 0x000e, 0x00, 0x00},
{0, 0x000f, 0x00, 0x00}
};
*/
/* Ethernet / IP / UDP header IPv4 */
const int udp_payload_offset = 14+20+8;
struct hep_hdr{
u_int8_t hp_v; /* version */
u_int8_t hp_l; /* length */
u_int8_t hp_f; /* family */
u_int8_t hp_p; /* protocol */
u_int16_t hp_sport; /* source port */
u_int16_t hp_dport; /* destination port */
};
struct hep_timehdr{
u_int32_t tv_sec; /* seconds */
u_int32_t tv_usec; /* useconds */
u_int16_t captid; /* Capture ID node */
};
struct hep_iphdr{
struct in_addr hp_src;
struct in_addr hp_dst; /* source and dest address */
};
#ifdef USE_IPV6
struct hep_ip6hdr {
struct in6_addr hp6_src; /* source address */
struct in6_addr hp6_dst; /* destination address */
};
#endif