-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathSipCallDump.cpp
More file actions
147 lines (121 loc) · 3.52 KB
/
SipCallDump.cpp
File metadata and controls
147 lines (121 loc) · 3.52 KB
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
/*
* Copyright (C) 2012 Yee Young Han <websearch@naver.com> (http://blog.naver.com/websearch)
*
* 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "SipCallDump.h"
#include "SipCallDumpVersion.h"
#include "ServerService.h"
#include "ServerUtility.h"
#include "PcapUtility.h"
#include "SipCallMap.h"
#include "RtpMap.h"
#include "TcpMap.h"
#include "IpFragmentMap.h"
#include "PacketDump.h"
#include "MemoryDebug.h"
std::string gstrPcapFileName;
/**
* @ingroup SipCallDump
* @brief SIP 통화별 패킷 덤프하는 서비스
* @returns 정상 종료하면 0 을 리턴하고 오류가 발생하면 -1 를 리턴한다.
*/
int ServiceMain( )
{
#ifdef WIN32
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );
#endif
if( gclsSetup.Read( GetConfigFileName() ) == false && gclsSetup.Read( CONFIG_FILENAME ) == false )
{
printf( "config filename(%s) read error\n", GetConfigFileName() );
return -1;
}
CLog::Print( LOG_SYSTEM, "SipCallDump is started" );
Fork( true );
SetCoreDumpEnable();
ServerSignal();
int iSecond = 0;
StartPacketDumpThread();
while( gbStop == false )
{
++iSecond;
if( iSecond == 60 )
{
// timeout 된 RTP 세션이 존재하면 해당 통화 정보를 삭제한다.
STRING_LIST clsSipCallIdList;
STRING_LIST::iterator itSL;
gclsRtpMap.SelectTimeout( clsSipCallIdList );
for( itSL = clsSipCallIdList.begin(); itSL != clsSipCallIdList.end(); ++itSL )
{
gclsCallMap.Delete( itSL->c_str() );
}
gclsIpFragmentMap.DeleteTimeout();
gclsTcpMap.DeleteTimeout();
iSecond = 0;
}
if( gclsSetup.IsChange() )
{
gclsSetup.Read();
}
sleep(1);
}
// PacketDumpThread 가 종료할 때까지 대기한다.
sleep(1);
gclsCallMap.DeleteAll();
gclsIpFragmentMap.DeleteAll();
CLog::Print( LOG_SYSTEM, "SipCallDump is terminated" );
CLog::Release();
return 0;
}
/**
* @ingroup SipCallDump
* @brief SIP 통화별 패킷 덤프하는 서비스
* @param argc
* @param argv
* @returns 정상 종료하면 0 을 리턴하고 오류가 발생하면 -1 를 리턴한다.
*/
int main( int argc, char * argv[] )
{
CServerService clsService;
clsService.m_strName = SERVICE_NAME;
clsService.m_strDisplayName = SERVICE_DISPLAY_NAME;
clsService.m_strDescription = SERVICE_DESCRIPTION_STRING;
clsService.m_strConfigFileName = CONFIG_FILENAME;
clsService.m_strVersion = SERVER_VERSION;
clsService.SetBuildDate( __DATE__, __TIME__ );
if( argc == 2 )
{
if( !strcmp( argv[1], "-l" ) )
{
PrintDeviceName();
return 0;
}
}
else if( argc == 3 )
{
gstrPcapFileName = argv[2];
}
ServerMain( argc, argv, clsService, ServiceMain );
if( argc == 2 )
{
if( !strcmp( argv[1], "-h" ) || !strcmp( argv[1], "-v" ) )
{
#ifdef WIN32
printf( " %s -l : list all network device\n", argv[0] );
#endif
}
}
return 0;
}