Browse code

sipcapture: fix spelling errors

Bastian Triller authored on 12/03/2020 16:53:02 • Henning Westerholt committed on 13/03/2020 10:35:17
Showing 1 changed files
... ...
@@ -481,7 +481,7 @@ int parsing_hepv3_message(char *buf, unsigned int len)
481 481
 	si->addr_info_lst = 0;
482 482
 
483 483
 	si->address_str.s = ip_addr2a(&si->address);
484
-	;
484
+
485 485
 	si->address_str.len = strlen(si->address_str.s);
486 486
 
487 487
 	si->port_no_str.s = int2str(si->port_no, &tmp_len);
Browse code

sipcapture: declare extern heptime in hep.c and init it to null

Daniel-Constantin Mierla authored on 03/03/2020 08:11:59
Showing 1 changed files
... ...
@@ -37,7 +37,7 @@
37 37
 
38 38
 static int count = 0;
39 39
 
40
-struct hep_timeinfo *heptime;
40
+extern struct hep_timeinfo *heptime;
41 41
 
42 42
 /* HEPv2 HEPv3 */
43 43
 int hepv2_received(char *buf, unsigned int len, struct receive_info *ri);
Browse code

sipcapture: fix typo

Bastian Triller authored on 06/02/2020 14:28:18 • Henning Westerholt committed on 21/02/2020 16:18:21
Showing 1 changed files
... ...
@@ -493,7 +493,7 @@ int parsing_hepv3_message(char *buf, unsigned int len)
493 493
 	ri.bind_address = si;
494 494
 
495 495
 	if(payload != NULL) {
496
-		/* and now recieve message */
496
+		/* and now receive message */
497 497
 		if(hg->proto_t->data == 5)
498 498
 			receive_logging_json_msg(payload, payload_len, hg, "rtcp_capture");
499 499
 		else if(hg->proto_t->data == 32)
Browse code

modules:sipcapture Fixed wrong pointer for payload buffer.

Alexandr Dubovikov authored on 16/04/2019 11:28:23
Showing 1 changed files
... ...
@@ -739,7 +739,11 @@ int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t *msg)
739 739
 		msg->rcv.proto = PROTO_UDP;
740 740
 
741 741
 	if(payload != NULL)
742
+	{
742 743
 		ret = len - payload_len;
744
+		msg->buf = payload;
745
+                msg->len = payload_len;
746
+	}
743 747
 
744 748
 
745 749
 done:
Browse code

sipcapture: clang format the code, added missing copyright header

Daniel-Constantin Mierla authored on 01/11/2017 08:28:28
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * hep related functions
3 3
  *
4
- * Copyright (C) 2011-14 Alexandr Dubovikov <alexandr.dubovikov@gmail.com>
4
+ * Copyright (C) 2011-2014 Alexandr Dubovikov <alexandr.dubovikov@gmail.com>
5 5
  *
6 6
  * This file is part of Kamailio, a free SIP server.
7 7
  *
... ...
@@ -35,10 +35,9 @@
35 35
 #include "sipcapture.h"
36 36
 
37 37
 
38
-
39 38
 static int count = 0;
40 39
 
41
-struct hep_timeinfo* heptime;
40
+struct hep_timeinfo *heptime;
42 41
 
43 42
 /* HEPv2 HEPv3 */
44 43
 int hepv2_received(char *buf, unsigned int len, struct receive_info *ri);
... ...
@@ -51,162 +50,170 @@ int parsing_hepv3_message(char *buf, unsigned int len);
51 50
 /* int hep_msg_received(char * buf, unsigned int len, struct receive_info * ri) */
52 51
 int hep_msg_received(sr_event_param_t *evp)
53 52
 {
54
-        void **srevp;
55
-        char *buf;
56
-        unsigned *len;
57
-        struct receive_info *ri;
58
-
59
-        if(!hep_capture_on) {
60
-                LOG(L_ERR, "sipcapture:hep_msg_received HEP is not enabled\n");
61
-                return -1;
62
-        }
53
+	void **srevp;
54
+	char *buf;
55
+	unsigned *len;
56
+	struct receive_info *ri;
57
+
58
+	if(!hep_capture_on) {
59
+		LOG(L_ERR, "sipcapture:hep_msg_received HEP is not enabled\n");
60
+		return -1;
61
+	}
63 62
 
64
-        srevp = (void**)evp->data;
63
+	srevp = (void **)evp->data;
65 64
 
66
-        buf = (char *)srevp[0];
67
-        len = (unsigned *)srevp[1];
68
-        ri = (struct receive_info *)srevp[2];
65
+	buf = (char *)srevp[0];
66
+	len = (unsigned *)srevp[1];
67
+	ri = (struct receive_info *)srevp[2];
69 68
 
70 69
 	correlation_id = NULL;
71 70
 	authkey = NULL;
72 71
 
73 72
 	count++;
74
-        struct hep_hdr *heph;
75
-        /* hep_hdr */
76
-        heph = (struct hep_hdr*) buf;
73
+	struct hep_hdr *heph;
74
+	/* hep_hdr */
75
+	heph = (struct hep_hdr *)buf;
77 76
 
78
-        /* Check version */
79
-        if(heph->hp_v == 1 || heph->hp_v == 2)  {
77
+	/* Check version */
78
+	if(heph->hp_v == 1 || heph->hp_v == 2) {
80 79
 
81
-                return hepv2_received(buf, *len, ri);
82
-        }
83
-        else if(!memcmp(buf, "\x48\x45\x50\x33",4)) {
80
+		return hepv2_received(buf, *len, ri);
81
+	} else if(!memcmp(buf, "\x48\x45\x50\x33", 4)) {
84 82
 
85
-                return hepv3_received(buf, *len, ri);
86
-        }
87
-        else {
83
+		return hepv3_received(buf, *len, ri);
84
+	} else {
88 85
 
89
-                LOG(L_ERR, "ERROR: sipcapture:hep_msg_received: not supported version or bad length: v:[%d] l:[%d]\n",
90
-                                                heph->hp_v, heph->hp_l);
91
-                return -1;
92
-        }
86
+		LOG(L_ERR, "ERROR: sipcapture:hep_msg_received: not supported version "
87
+				   "or bad length: v:[%d] l:[%d]\n",
88
+				heph->hp_v, heph->hp_l);
89
+		return -1;
90
+	}
93 91
 }
94 92
 
95
-int hepv2_received(char *buf, unsigned int len, struct receive_info *ri){
93
+int hepv2_received(char *buf, unsigned int len, struct receive_info *ri)
94
+{
96 95
 
97 96
 	int hl;
98
-        struct hep_hdr *heph;
99
-        struct ip_addr dst_ip, src_ip;
100
-        char *hep_payload, *end, *hep_ip;
101
-        struct hep_iphdr *hepiph = NULL;
97
+	struct hep_hdr *heph;
98
+	struct ip_addr dst_ip, src_ip;
99
+	char *hep_payload, *end, *hep_ip;
100
+	struct hep_iphdr *hepiph = NULL;
101
+
102
+	struct hep_timehdr *heptime_tmp = NULL;
103
+	memset(heptime, 0, sizeof(struct hep_timeinfo));
102 104
 
103
-	struct hep_timehdr* heptime_tmp = NULL;
104
-        memset(heptime, 0, sizeof(struct hep_timeinfo));
105
+	struct hep_ip6hdr *hepip6h = NULL;
105 106
 
106
-        struct hep_ip6hdr *hepip6h = NULL;
107
-            	        
108 107
 	correlation_id = NULL;
109 108
 	authkey = NULL;
110 109
 
111
-	hep_offset = 0; 
112
-	
110
+	hep_offset = 0;
111
+
113 112
 	hl = hep_offset = sizeof(struct hep_hdr);
114
-        end = buf + len;
115
-        if (unlikely(len<hep_offset)) {
116
-        	LOG(L_ERR, "ERROR: sipcapture:hep_msg_received len less than offset [%i] vs [%i]\n", len, hep_offset);
117
-                return -1;
118
-        }
113
+	end = buf + len;
114
+	if(unlikely(len < hep_offset)) {
115
+		LOG(L_ERR, "ERROR: sipcapture:hep_msg_received len less than offset "
116
+				   "[%i] vs [%i]\n",
117
+				len, hep_offset);
118
+		return -1;
119
+	}
119 120
 
120 121
 	/* hep_hdr */
121
-        heph = (struct hep_hdr*) buf;
122
+	heph = (struct hep_hdr *)buf;
122 123
 
123
-        switch(heph->hp_f){
124
-        	case AF_INET:
125
-                	hl += sizeof(struct hep_iphdr);
126
-                        break;
124
+	switch(heph->hp_f) {
125
+		case AF_INET:
126
+			hl += sizeof(struct hep_iphdr);
127
+			break;
127 128
 		case AF_INET6:
128
-                	hl += sizeof(struct hep_ip6hdr);
129
-                        break;
129
+			hl += sizeof(struct hep_ip6hdr);
130
+			break;
130 131
 		default:
131
-                        LOG(L_ERR, "ERROR: sipcapture:hep_msg_received:  unsupported family [%d]\n", heph->hp_f);
132
-                        return -1;
132
+			LOG(L_ERR, "ERROR: sipcapture:hep_msg_received:  unsupported "
133
+					   "family [%d]\n",
134
+					heph->hp_f);
135
+			return -1;
133 136
 	}
134 137
 
135
-        /* PROTO */
136
-        if(heph->hp_p == IPPROTO_UDP) ri->proto=PROTO_UDP;
137
-        else if(heph->hp_p == IPPROTO_TCP) ri->proto=PROTO_TCP;
138
-        else if(heph->hp_p == IPPROTO_IDP) ri->proto=PROTO_TLS; /* fake protocol */
138
+	/* PROTO */
139
+	if(heph->hp_p == IPPROTO_UDP)
140
+		ri->proto = PROTO_UDP;
141
+	else if(heph->hp_p == IPPROTO_TCP)
142
+		ri->proto = PROTO_TCP;
143
+	else if(heph->hp_p == IPPROTO_IDP)
144
+		ri->proto = PROTO_TLS; /* fake protocol */
139 145
 #ifdef USE_SCTP
140
-        else if(heph->hp_p == IPPROTO_SCTP) ri->proto=PROTO_SCTP;
146
+	else if(heph->hp_p == IPPROTO_SCTP)
147
+		ri->proto = PROTO_SCTP;
141 148
 #endif
142
-        else {
143
-        	LOG(L_ERR, "ERROR: sipcapture:hep_msg_received: unknown protocol [%d]\n",heph->hp_p);
144
-                ri->proto = PROTO_NONE;
149
+	else {
150
+		LOG(L_ERR,
151
+				"ERROR: sipcapture:hep_msg_received: unknown protocol [%d]\n",
152
+				heph->hp_p);
153
+		ri->proto = PROTO_NONE;
145 154
 	}
146 155
 
147
-        hep_ip = buf + sizeof(struct hep_hdr);
156
+	hep_ip = buf + sizeof(struct hep_hdr);
148 157
 
149
-        if (unlikely(hep_ip>end)){
150
-                LOG(L_ERR,"hep_ip is over buf+len\n");
151
-                return -1;
152
-        }
158
+	if(unlikely(hep_ip > end)) {
159
+		LOG(L_ERR, "hep_ip is over buf+len\n");
160
+		return -1;
161
+	}
153 162
 
154
-	switch(heph->hp_f){
163
+	switch(heph->hp_f) {
155 164
 		case AF_INET:
156
-                	hep_offset+=sizeof(struct hep_iphdr);
157
-                        hepiph = (struct hep_iphdr*) hep_ip;
158
-                        break;
165
+			hep_offset += sizeof(struct hep_iphdr);
166
+			hepiph = (struct hep_iphdr *)hep_ip;
167
+			break;
159 168
 
160 169
 		case AF_INET6:
161
-                	hep_offset+=sizeof(struct hep_ip6hdr);
162
-                        hepip6h = (struct hep_ip6hdr*) hep_ip;
163
-                        break;
164
-
170
+			hep_offset += sizeof(struct hep_ip6hdr);
171
+			hepip6h = (struct hep_ip6hdr *)hep_ip;
172
+			break;
165 173
 	}
166 174
 
167 175
 	/* VOIP payload */
168
-        hep_payload = buf + hep_offset;
176
+	hep_payload = buf + hep_offset;
169 177
 
170
-        if (unlikely(hep_payload>end)){
171
-        	LOG(L_ERR,"hep_payload is over buf+len\n");
172
-                return -1;
178
+	if(unlikely(hep_payload > end)) {
179
+		LOG(L_ERR, "hep_payload is over buf+len\n");
180
+		return -1;
173 181
 	}
174 182
 
175 183
 	/* timming */
176
-        if(heph->hp_v == 2) {
177
-                hep_offset+=sizeof(struct hep_timehdr);
178
-                heptime_tmp = (struct hep_timehdr*) hep_payload;
184
+	if(heph->hp_v == 2) {
185
+		hep_offset += sizeof(struct hep_timehdr);
186
+		heptime_tmp = (struct hep_timehdr *)hep_payload;
179 187
 
180
-                heptime->tv_sec = to_le(heptime_tmp->tv_sec);
181
-                heptime->tv_usec = to_le(heptime_tmp->tv_usec);
182
-                heptime->captid = heptime_tmp->captid;
183
-        }
188
+		heptime->tv_sec = to_le(heptime_tmp->tv_sec);
189
+		heptime->tv_usec = to_le(heptime_tmp->tv_usec);
190
+		heptime->captid = heptime_tmp->captid;
191
+	}
184 192
 
185 193
 
186 194
 	/* fill ip from the packet to dst_ip && to */
187
-        switch(heph->hp_f){
195
+	switch(heph->hp_f) {
188 196
 
189 197
 		case AF_INET:
190
-                	dst_ip.af = src_ip.af = AF_INET;
191
-                        dst_ip.len = src_ip.len = 4 ;
192
-                        memcpy(&dst_ip.u.addr, &hepiph->hp_dst, 4);
193
-                        memcpy(&src_ip.u.addr, &hepiph->hp_src, 4);
194
-                        break;
198
+			dst_ip.af = src_ip.af = AF_INET;
199
+			dst_ip.len = src_ip.len = 4;
200
+			memcpy(&dst_ip.u.addr, &hepiph->hp_dst, 4);
201
+			memcpy(&src_ip.u.addr, &hepiph->hp_src, 4);
202
+			break;
195 203
 
196 204
 		case AF_INET6:
197
-                	dst_ip.af = src_ip.af = AF_INET6;
198
-                        dst_ip.len = src_ip.len = 16 ;
199
-                        memcpy(&dst_ip.u.addr, &hepip6h->hp6_dst, 16);
200
-                        memcpy(&src_ip.u.addr, &hepip6h->hp6_src, 16);
201
-                        break;
202
-
205
+			dst_ip.af = src_ip.af = AF_INET6;
206
+			dst_ip.len = src_ip.len = 16;
207
+			memcpy(&dst_ip.u.addr, &hepip6h->hp6_dst, 16);
208
+			memcpy(&src_ip.u.addr, &hepip6h->hp6_src, 16);
209
+			break;
203 210
 	}
204 211
 
205
-        ri->src_ip = src_ip;
206
-        ri->src_port = ntohs(heph->hp_sport);
212
+	ri->src_ip = src_ip;
213
+	ri->src_port = ntohs(heph->hp_sport);
207 214
 
208
-        ri->dst_ip = dst_ip;
209
-        ri->dst_port = ntohs(heph->hp_dport);
215
+	ri->dst_ip = dst_ip;
216
+	ri->dst_port = ntohs(heph->hp_dport);
210 217
 
211 218
 	/* cut off the offset */
212 219
 	/* 
... ...
@@ -215,10 +222,10 @@ int hepv2_received(char *buf, unsigned int len, struct receive_info *ri){
215 222
 	 *  memmove(buf, p, BUF_SIZE+1); 
216 223
 	*/
217 224
 
218
-        hep_payload = buf + hep_offset;
225
+	hep_payload = buf + hep_offset;
226
+
227
+	receive_msg(hep_payload, (unsigned int)(len - hep_offset), ri);
219 228
 
220
-        receive_msg(hep_payload,(unsigned int)(len - hep_offset), ri);
221
-	
222 229
 	return -1;
223 230
 }
224 231
 
... ...
@@ -230,44 +237,45 @@ int hepv3_received(char *buf, unsigned int len, struct receive_info *ri)
230 237
 {
231 238
 	if(!parsing_hepv3_message(buf, len)) {
232 239
 		LM_ERR("couldn't parse hepv3 message\n");
233
-        	return -2;
234
-        }
240
+		return -2;
241
+	}
235 242
 
236 243
 	return -1;
237 244
 }
238 245
 
239
-int parsing_hepv3_message(char *buf, unsigned int len) {
246
+int parsing_hepv3_message(char *buf, unsigned int len)
247
+{
240 248
 
241 249
 	union sockaddr_union from;
242 250
 	union sockaddr_union to;
243
-        struct receive_info ri;
251
+	struct receive_info ri;
244 252
 	char *tmp;
245 253
 	struct ip_addr dst_ip, src_ip;
246
-	struct socket_info* si = 0;
254
+	struct socket_info *si = 0;
247 255
 	int tmp_len, i;
248 256
 	char *payload = NULL;
249 257
 	unsigned int payload_len = 0;
250
-        struct hep_chunk *chunk;	
251
-        struct hep_generic_recv *hg;
252
-        int totelem = 0;
253
-        int chunk_vendor=0, chunk_type=0, chunk_length=0;
254
-        int total_length = 0;
255
-
256
-
257
-	hg = (struct hep_generic_recv*)pkg_malloc(sizeof(struct hep_generic_recv));
258
-	if(hg==NULL) {
259
-	        LM_ERR("no more pkg memory left for hg\n");
260
-	        return -1;
261
-        }
262
-	                                                 		
258
+	struct hep_chunk *chunk;
259
+	struct hep_generic_recv *hg;
260
+	int totelem = 0;
261
+	int chunk_vendor = 0, chunk_type = 0, chunk_length = 0;
262
+	int total_length = 0;
263
+
264
+
265
+	hg = (struct hep_generic_recv *)pkg_malloc(sizeof(struct hep_generic_recv));
266
+	if(hg == NULL) {
267
+		LM_ERR("no more pkg memory left for hg\n");
268
+		return -1;
269
+	}
270
+
263 271
 	memset(hg, 0, sizeof(struct hep_generic_recv));
264 272
 
265
-	
266
-        memset(heptime, 0, sizeof(struct hep_timeinfo));	
267
-	        
273
+
274
+	memset(heptime, 0, sizeof(struct hep_timeinfo));
275
+
268 276
 
269 277
 	/* HEADER */
270
-	hg->header  = (hep_ctrl_t *) (buf);
278
+	hg->header = (hep_ctrl_t *)(buf);
271 279
 
272 280
 	/*Packet size */
273 281
 	total_length = ntohs(hg->header->length);
... ...
@@ -275,761 +283,796 @@ int parsing_hepv3_message(char *buf, unsigned int len) {
275 283
 	ri.src_port = 0;
276 284
 	ri.dst_port = 0;
277 285
 	dst_ip.af = 0;
278
-        src_ip.af = 0;
279
-                	        
286
+	src_ip.af = 0;
287
+
280 288
 	payload = NULL;
281 289
 	correlation_id = NULL;
282 290
 	authkey = NULL;
283 291
 
284
-	i = sizeof(hep_ctrl_t);	        
285
-	        
292
+	i = sizeof(hep_ctrl_t);
293
+
286 294
 	while(i < total_length) {
287
-                
288
-	        /*OUR TMP DATA */                                  
289
-                tmp = buf+i;
290
-
291
-                chunk = (struct hep_chunk*) tmp;
292
-                             
293
-                chunk_vendor = ntohs(chunk->vendor_id);                             
294
-                chunk_type = ntohs(chunk->type_id);
295
-                chunk_length = ntohs(chunk->length);
296
-                       
297
-
298
-
299
-                /* if chunk_length */
300
-                if(chunk_length == 0) {
301
-                        /* BAD LEN we drop this packet */
302
-                        goto error;
303
-                }
304
-
305
-                /* SKIP not general Chunks */
306
-                if(chunk_vendor != 0) {
307
-                        i+=chunk_length;
308
-                }
309
-                else {                                                                                                                               
310
-                        switch(chunk_type) {
311
-                                     
312
-                                case 0:
313
-                                        goto error;
314
-                                        break;
315
-                                     
316
-                                case 1:                                                                          
317
-                                        hg->ip_family  = (hep_chunk_uint8_t *) (tmp);
318
-                                        i+=chunk_length;
319
-                                        totelem++;
320
-                                        break;
321
-                                case 2:
322
-                                        hg->ip_proto  = (hep_chunk_uint8_t *) (tmp);
323
-                                        i+=chunk_length;
324
-                                        totelem++;
325
-                                        break;                                                     
326
-                                case 3:
327
-                                        hg->hep_src_ip4  = (hep_chunk_ip4_t *) (tmp);
328
-                                        i+=chunk_length;
329
-                                        src_ip.af=AF_INET;
330
-				        src_ip.len=4;
331
-				        src_ip.u.addr32[0] = hg->hep_src_ip4->data.s_addr;
332
-				        totelem++;
333
-				        break;
334
-                                case 4:
335
-                                        hg->hep_dst_ip4  = (hep_chunk_ip4_t *) (tmp);
336
-                                        i+=chunk_length;                                                     
337
-					dst_ip.af=AF_INET;
338
-				        dst_ip.len=4;
339
-				        dst_ip.u.addr32[0] = hg->hep_dst_ip4->data.s_addr;
340
-                                        totelem++;
341
-
342
-                                        break;
343
-                                case 5:
344
-                                        hg->hep_src_ip6  = (hep_chunk_ip6_t *) (tmp);
345
-                                        i+=chunk_length;
346
-                                        src_ip.af=AF_INET6;
347
-				        src_ip.len=16;
348
-				        memcpy(src_ip.u.addr, &hg->hep_src_ip6->data, 16);
349
-				        totelem++;
350
-                                        break;
351
-                                case 6:
352
-                                        hg->hep_dst_ip6  = (hep_chunk_ip6_t *) (tmp);
353
-                                        i+=chunk_length;                                                     
354
-                                        dst_ip.af=AF_INET6;
355
-				        dst_ip.len=16;
356
-				        memcpy(dst_ip.u.addr, &hg->hep_dst_ip6->data, 16);
357
-				        totelem++;
358
-                                        break;
359
-        
360
-                                case 7:
361
-                                        hg->src_port  = (hep_chunk_uint16_t *) (tmp);
362
-                                        ri.src_port = ntohs(hg->src_port->data);
363
-                                        i+=chunk_length;                      
364
-                                        totelem++;
365
-                                        break;
366
-
367
-                                case 8:
368
-                                        hg->dst_port  = (hep_chunk_uint16_t *) (tmp);
369
-                                        ri.dst_port = ntohs(hg->dst_port->data);
370
-                                        i+=chunk_length;
371
-                                        totelem++;
372
-                                        break;
373
-                                case 9:
374
-                                        hg->time_sec  = (hep_chunk_uint32_t *) (tmp);
375
-                                        heptime->tv_sec = ntohl(hg->time_sec->data);
376
-                                        i+=chunk_length;
377
-                                        totelem++;
378
-                                        break;
379
-
380
-                                case 10:
381
-                                        hg->time_usec  = (hep_chunk_uint32_t *) (tmp);
382
-                                        heptime->tv_usec = ntohl(hg->time_usec->data);
383
-                                        i+=chunk_length;
384
-                                        totelem++;
385
-                                        break;      
386
-
387
-                                case 11:
388
-                                        hg->proto_t  = (hep_chunk_uint8_t *) (tmp);
389
-                                        i+=chunk_length;
390
-                                        totelem++;
391
-                                        break;                                                                                                                                                         
392
-
393
-                                case 12:
394
-                                        hg->capt_id  = (hep_chunk_uint32_t *) (tmp);
395
-                                        heptime->captid = ntohl(hg->capt_id->data);
396
-                                        i+=chunk_length;
397
-                                        totelem++;
398
-                                        break;
399
-
400
-                                case 13:
401
-                                        hg->keep_tm  = (hep_chunk_uint16_t *) (tmp);
402
-                                        i+=chunk_length;
403
-                                        break;                                                     
404
-
405
-                                case 14:
406
-                                        authkey = (char *) tmp + sizeof(hep_chunk_t);
407
-                                        i+=chunk_length;                                                                             
408
-                                        break;
409
-                                                     
410
-                                case 15:
411
-                                        hg->payload_chunk  = (hep_chunk_t *) (tmp);
412
-                                        payload = (char *) tmp+sizeof(hep_chunk_t);
413
-                                        payload_len = chunk_length - sizeof(hep_chunk_t);
414
-                                        i+=chunk_length;
415
-                                        totelem++;
416
-                                        break;
417
-                                case 17:
418
-                                
419
-                                        correlation_id = (char *) tmp + sizeof(hep_chunk_t);
420
-                                        i+=chunk_length;                                                                            
295
+
296
+		/*OUR TMP DATA */
297
+		tmp = buf + i;
298
+
299
+		chunk = (struct hep_chunk *)tmp;
300
+
301
+		chunk_vendor = ntohs(chunk->vendor_id);
302
+		chunk_type = ntohs(chunk->type_id);
303
+		chunk_length = ntohs(chunk->length);
304
+
305
+
306
+		/* if chunk_length */
307
+		if(chunk_length == 0) {
308
+			/* BAD LEN we drop this packet */
309
+			goto error;
310
+		}
311
+
312
+		/* SKIP not general Chunks */
313
+		if(chunk_vendor != 0) {
314
+			i += chunk_length;
315
+		} else {
316
+			switch(chunk_type) {
317
+
318
+				case 0:
319
+					goto error;
320
+					break;
321
+
322
+				case 1:
323
+					hg->ip_family = (hep_chunk_uint8_t *)(tmp);
324
+					i += chunk_length;
325
+					totelem++;
421 326
 					break;
327
+				case 2:
328
+					hg->ip_proto = (hep_chunk_uint8_t *)(tmp);
329
+					i += chunk_length;
330
+					totelem++;
331
+					break;
332
+				case 3:
333
+					hg->hep_src_ip4 = (hep_chunk_ip4_t *)(tmp);
334
+					i += chunk_length;
335
+					src_ip.af = AF_INET;
336
+					src_ip.len = 4;
337
+					src_ip.u.addr32[0] = hg->hep_src_ip4->data.s_addr;
338
+					totelem++;
339
+					break;
340
+				case 4:
341
+					hg->hep_dst_ip4 = (hep_chunk_ip4_t *)(tmp);
342
+					i += chunk_length;
343
+					dst_ip.af = AF_INET;
344
+					dst_ip.len = 4;
345
+					dst_ip.u.addr32[0] = hg->hep_dst_ip4->data.s_addr;
346
+					totelem++;
422 347
 
423
-                                                     
424
-                                default:
425
-                                        i+=chunk_length;
426
-                                        break;
427
-                        }                                        
428
-                }
429
-        }	                                                                                                          
430
-                        
431
-        /* CHECK how much elements */
432
-        if(totelem < 9) {                        
433
-                LM_ERR("Not all elements [%d]\n", totelem);                        
434
-                goto done;
435
-        }                 
436
-
437
-        if ( dst_ip.af == 0 || src_ip.af == 0)  {
438
-                LM_ERR("NO IP's set\n");
439
-                goto done;
440
-        }
441
-
442
-                        
443
-        ip_addr2su(&to, &dst_ip, ri.dst_port);
444
-        ip_addr2su(&from, &src_ip, ri.src_port);
445
-                        
446
-        ri.src_su=from;
447
-        su2ip_addr(&ri.src_ip, &from);
448
-        su2ip_addr(&ri.dst_ip, &to);
449
-
450
-	if(hg->ip_proto->data == IPPROTO_TCP) ri.proto=PROTO_TCP;
451
-	else if(hg->ip_proto->data == IPPROTO_UDP) ri.proto=PROTO_UDP;
348
+					break;
349
+				case 5:
350
+					hg->hep_src_ip6 = (hep_chunk_ip6_t *)(tmp);
351
+					i += chunk_length;
352
+					src_ip.af = AF_INET6;
353
+					src_ip.len = 16;
354
+					memcpy(src_ip.u.addr, &hg->hep_src_ip6->data, 16);
355
+					totelem++;
356
+					break;
357
+				case 6:
358
+					hg->hep_dst_ip6 = (hep_chunk_ip6_t *)(tmp);
359
+					i += chunk_length;
360
+					dst_ip.af = AF_INET6;
361
+					dst_ip.len = 16;
362
+					memcpy(dst_ip.u.addr, &hg->hep_dst_ip6->data, 16);
363
+					totelem++;
364
+					break;
365
+
366
+				case 7:
367
+					hg->src_port = (hep_chunk_uint16_t *)(tmp);
368
+					ri.src_port = ntohs(hg->src_port->data);
369
+					i += chunk_length;
370
+					totelem++;
371
+					break;
372
+
373
+				case 8:
374
+					hg->dst_port = (hep_chunk_uint16_t *)(tmp);
375
+					ri.dst_port = ntohs(hg->dst_port->data);
376
+					i += chunk_length;
377
+					totelem++;
378
+					break;
379
+				case 9:
380
+					hg->time_sec = (hep_chunk_uint32_t *)(tmp);
381
+					heptime->tv_sec = ntohl(hg->time_sec->data);
382
+					i += chunk_length;
383
+					totelem++;
384
+					break;
385
+
386
+				case 10:
387
+					hg->time_usec = (hep_chunk_uint32_t *)(tmp);
388
+					heptime->tv_usec = ntohl(hg->time_usec->data);
389
+					i += chunk_length;
390
+					totelem++;
391
+					break;
392
+
393
+				case 11:
394
+					hg->proto_t = (hep_chunk_uint8_t *)(tmp);
395
+					i += chunk_length;
396
+					totelem++;
397
+					break;
398
+
399
+				case 12:
400
+					hg->capt_id = (hep_chunk_uint32_t *)(tmp);
401
+					heptime->captid = ntohl(hg->capt_id->data);
402
+					i += chunk_length;
403
+					totelem++;
404
+					break;
405
+
406
+				case 13:
407
+					hg->keep_tm = (hep_chunk_uint16_t *)(tmp);
408
+					i += chunk_length;
409
+					break;
410
+
411
+				case 14:
412
+					authkey = (char *)tmp + sizeof(hep_chunk_t);
413
+					i += chunk_length;
414
+					break;
415
+
416
+				case 15:
417
+					hg->payload_chunk = (hep_chunk_t *)(tmp);
418
+					payload = (char *)tmp + sizeof(hep_chunk_t);
419
+					payload_len = chunk_length - sizeof(hep_chunk_t);
420
+					i += chunk_length;
421
+					totelem++;
422
+					break;
423
+				case 17:
424
+
425
+					correlation_id = (char *)tmp + sizeof(hep_chunk_t);
426
+					i += chunk_length;
427
+					break;
428
+
429
+
430
+				default:
431
+					i += chunk_length;
432
+					break;
433
+			}
434
+		}
435
+	}
436
+
437
+	/* CHECK how much elements */
438
+	if(totelem < 9) {
439
+		LM_ERR("Not all elements [%d]\n", totelem);
440
+		goto done;
441
+	}
442
+
443
+	if(dst_ip.af == 0 || src_ip.af == 0) {
444
+		LM_ERR("NO IP's set\n");
445
+		goto done;
446
+	}
447
+
448
+
449
+	ip_addr2su(&to, &dst_ip, ri.dst_port);
450
+	ip_addr2su(&from, &src_ip, ri.src_port);
451
+
452
+	ri.src_su = from;
453
+	su2ip_addr(&ri.src_ip, &from);
454
+	su2ip_addr(&ri.dst_ip, &to);
455
+
456
+	if(hg->ip_proto->data == IPPROTO_TCP)
457
+		ri.proto = PROTO_TCP;
458
+	else if(hg->ip_proto->data == IPPROTO_UDP)
459
+		ri.proto = PROTO_UDP;
452 460
 
453 461
 	/* a little bit memory */
454
-        si=(struct socket_info*) pkg_malloc(sizeof(struct socket_info));
455
-        if (si==0) {
456
-                LOG(L_ERR, "ERROR: new_sock_info: memory allocation error\n");
457
-                goto error;
458
-        }
462
+	si = (struct socket_info *)pkg_malloc(sizeof(struct socket_info));
463
+	if(si == 0) {
464
+		LOG(L_ERR, "ERROR: new_sock_info: memory allocation error\n");
465
+		goto error;
466
+	}
459 467
 
460 468
 	memset(si, 0, sizeof(struct socket_info));
461
-        si->address = ri.dst_ip;
462
-        si->socket=-1;
463
-
464
-        /* set port & proto */
465
-        si->port_no = ri.dst_port;
469
+	si->address = ri.dst_ip;
470
+	si->socket = -1;
466 471
 
467
-        if(hg->ip_proto->data == IPPROTO_TCP) si->proto=PROTO_TCP;
468
-        else if(hg->ip_proto->data == IPPROTO_UDP) si->proto=PROTO_UDP;
472
+	/* set port & proto */
473
+	si->port_no = ri.dst_port;
469 474
 
470
-        si->flags=0;
471
-        si->addr_info_lst=0;
475
+	if(hg->ip_proto->data == IPPROTO_TCP)
476
+		si->proto = PROTO_TCP;
477
+	else if(hg->ip_proto->data == IPPROTO_UDP)
478
+		si->proto = PROTO_UDP;
472 479
 
473
-        si->address_str.s = ip_addr2a(&si->address);;
474
-        si->address_str.len = strlen(si->address_str.s);                                                
480
+	si->flags = 0;
481
+	si->addr_info_lst = 0;
475 482
 
476
-        si->port_no_str.s = int2str(si->port_no, &tmp_len);
477
-        si->port_no_str.len = tmp_len;
483
+	si->address_str.s = ip_addr2a(&si->address);
484
+	;
478 485
 	si->address_str.len = strlen(si->address_str.s);
479 486
 
480
-        si->name.len = si->address_str.len;
481
-        si->name.s = si->address_str.s;
482
-        ri.bind_address=si;
487
+	si->port_no_str.s = int2str(si->port_no, &tmp_len);
488
+	si->port_no_str.len = tmp_len;
489
+	si->address_str.len = strlen(si->address_str.s);
483 490
 
484
-        if(payload != NULL ) {
485
-                /* and now recieve message */
486
-                if (hg->proto_t->data == 5) receive_logging_json_msg(payload, payload_len, hg, "rtcp_capture");
487
-                else if (hg->proto_t->data == 32) receive_logging_json_msg(payload, payload_len, hg, "report_capture");
488
-                else if (hg->proto_t->data == 99) receive_logging_json_msg(payload, payload_len, hg, "report_capture");
489
-                else if (hg->proto_t->data == 100) receive_logging_json_msg(payload, payload_len, hg, "logs_capture");
490
-                else receive_msg(payload, payload_len, &ri);
491
-        }
491
+	si->name.len = si->address_str.len;
492
+	si->name.s = si->address_str.s;
493
+	ri.bind_address = si;
494
+
495
+	if(payload != NULL) {
496
+		/* and now recieve message */
497
+		if(hg->proto_t->data == 5)
498
+			receive_logging_json_msg(payload, payload_len, hg, "rtcp_capture");
499
+		else if(hg->proto_t->data == 32)
500
+			receive_logging_json_msg(
501
+					payload, payload_len, hg, "report_capture");
502
+		else if(hg->proto_t->data == 99)
503
+			receive_logging_json_msg(
504
+					payload, payload_len, hg, "report_capture");
505
+		else if(hg->proto_t->data == 100)
506
+			receive_logging_json_msg(payload, payload_len, hg, "logs_capture");
507
+		else
508
+			receive_msg(payload, payload_len, &ri);
509
+	}
492 510
 
493 511
 done:
494
-        if(si) pkg_free(si);
495
-        if(hg) pkg_free(hg);                     
512
+	if(si)
513
+		pkg_free(si);
514
+	if(hg)
515
+		pkg_free(hg);
516
+
517
+	return 1;
496 518
 
497
-        return 1;
498
-        
499 519
 error:
500 520
 
501
-        if(si) pkg_free(si);
502
-        if(hg) pkg_free(hg);
503
-                
504
-        return -1;           
505
-        
521
+	if(si)
522
+		pkg_free(si);
523
+	if(hg)
524
+		pkg_free(hg);
525
+
526
+	return -1;
506 527
 }
507 528
 
508 529
 
509
-int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t* msg) {
530
+int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t *msg)
531
+{
510 532
 
511 533
 	union sockaddr_union from;
512 534
 	union sockaddr_union to;
513 535
 	char *tmp;
514 536
 	struct ip_addr dst_ip, src_ip;
515
-	struct socket_info* si = 0;
537
+	struct socket_info *si = 0;
516 538
 	int i;
517 539
 	char *payload = NULL;
518 540
 	unsigned int payload_len = 0;
519
-        struct hep_chunk *chunk;	
520
-        struct hep_generic_recv *hg;
521
-        int totelem = 0;
522
-        int chunk_vendor=0, chunk_type=0, chunk_length=0;
523
-        int total_length = 0;
524
-        int ret = 0;
525
-        
526
-	hg = (struct hep_generic_recv*)pkg_malloc(sizeof(struct hep_generic_recv));
527
-	if(hg==NULL) {
528
-	        LM_ERR("no more pkg memory left for hg\n");
529
-	        return -1;
530
-        }
531
-	                                                 		
541
+	struct hep_chunk *chunk;
542
+	struct hep_generic_recv *hg;
543
+	int totelem = 0;
544
+	int chunk_vendor = 0, chunk_type = 0, chunk_length = 0;
545
+	int total_length = 0;
546
+	int ret = 0;
547
+