forked from RakshaBangera/dpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sip.c
112 lines (78 loc) · 2.8 KB
/
sip.c
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<regex.h>
#include<netinet/in.h>
#include"types.h"
int check_sip_over_udp(unsigned char *p_current, unsigned int payload_len)
{
regex_t regex;
const char *pattern = "^(ACK|BYE|CANCEL|INFO|INVITE|MESSAGE|NOTIFY|OPTIONS|PRACK|PUBLISH|REFER|REGISTER|SUBSCRIBE|UPDATE.*SIP/[0-9][.][0.9])|^(SIP/[0-9][.][0-9].*)";
char *payload = (char *)malloc(payload_len + 1);
int sip = 0;
if ( payload == NULL) {
printf("Out of memory\n");
} else {
memcpy(payload, p_current, payload_len);
payload[payload_len] = '\0';
if (debug_verbose) {
printf("Matching signature for SIP...\n");
}
if (!regcomp(®ex, pattern, REG_EXTENDED)) {
if (!regexec(®ex, payload, 0,0,0)) {
sip = 1;
}
}
}
if (debug_verbose && sip) {
printf("Signature match succeeded\n\n");
}
if (debug_verbose && !sip) {
printf("Signature match failed\n\n");
}
regfree(®ex);
free(payload);
payload = NULL;
return sip;
}
int check_sip_over_tcp(unsigned char *p_current, unsigned int payload_len,
unsigned long bigger_ip, unsigned long smaller_ip,
unsigned char ip_protocol, unsigned short bigger_port,
unsigned short smaller_port)
{
regex_t regex;
NODE p_tuple = NULL;
const char *pattern = "^(ACK|BYE|CANCEL|INFO|INVITE|MESSAGE|NOTIFY|OPTIONS|PRACK|PUBLISH|REFER|REGISTER|SUBSCRIBE|UPDATE.*SIP/[0-9][.][0.9])|^(SIP/[0-9][.][0-9].*)";
char *payload = (char *)malloc(payload_len + 1);
int sip = 0;
if ( payload == NULL) {
printf("Out of memory\n");
} else {
memcpy(payload, p_current, payload_len);
payload[payload_len] = '\0';
if (debug_verbose) {
printf("Matching signature for SIP...\n");
}
if (!regcomp(®ex, pattern, REG_EXTENDED)) {
if (!regexec(®ex, payload, 0,0,0)) {
sip = 1;
p_tuple = search(bigger_ip, smaller_ip, ip_protocol, bigger_port, smaller_port);
if (p_tuple != NULL) {
/* Update protocol type field in the tuple */
p_tuple->protocol_type = SIP;
}
}
}
}
if (debug_verbose && sip) {
printf("Signature match succeeded\n\n");
}
if (debug_verbose && !sip) {
printf("Signature match failed\n\n");
}
regfree(®ex);
free(payload);
payload = NULL;
return sip;
}