-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.c
161 lines (145 loc) · 3.35 KB
/
Main.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
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
////////////////////////////////////////////////////////////////////////////////
//
// General including files.
//
// Including the files for the system.
//
// These including files are generally used in different operation system.
//
////////////////////////////////////////////////////////////////////////////////
#include "Global.h"
////////////////////////////////////////////////////////////////////////////////
//
// Main function.
//
////////////////////////////////////////////////////////////////////////////////
_INT32 main(_INT32 argc,_STRING argv[])
{
//Path
_PASCALSTRING strPath;
//Directory
_PASCALSTRING strDirectory;
//Tunnel
NetworkTunnel tunnel;
//Get current working directory.
if(!GetFileDirectory(strDirectory))
{
#ifdef _DEBUG
PrintLine(stderr,"Main::main : fail to get current working directory !");
#endif
return _FAILURE;
}
//Set home directory.
SetHomeDirectory(strDirectory);
//Set log directory.
sprintf(strPath,"%s%slog",
strDirectory,GetFileDirectorySplitter());
//Initialize log.
if(!InitializeLog(strPath,LOG_ALL))
{
#ifdef _DEBUG
PrintLine(stderr,"Main::main : fail to initialize log !");
#endif
return _FAILURE;
}
//Initialize socket.
if(!InitializeSocket())
{
#ifdef _DEBUG
LogRequestedEvent("Main::main : fail to initialize socket !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FAILURE;
}
//Initialize tunnel environment.
if(InitializeTunnelEnvironment())
{
//Initialize tunnel.
InitializeNetworkTunnel(&tunnel);
//Set configuration of address.
//Local.
tunnel.ipLocal[0] = 10;tunnel.ipLocal[1] = 7;tunnel.ipLocal[2] = 0;tunnel.ipLocal[3] = 6;
//Netmask.
tunnel.ipNetmask[0] = 255;tunnel.ipNetmask[1] = 0;tunnel.ipNetmask[2] = 0;tunnel.ipNetmask[3] = 0;
//Remote.
tunnel.ipRemote[0] = 10;tunnel.ipRemote[1] = 7;tunnel.ipRemote[2] = 0;tunnel.ipRemote[3] = 5;
//Set configuration of peer.
//Address.
strcpy(tunnel.strPeerAddress,"60.28.160.110");
//Port.
tunnel.nPeerPort = 1701;
//Open tunnel.
if(OpenNetworkTunnel(&tunnel))
{
//Do process.
do
{
#ifdef _MICROSOFT_WINDOWS
//Check keyboard.
if(kbhit())
{
#endif
//Get a char.
_CHAR c = getchar();
//Get a char.
if(c == 'Q')
{
break;
}
else
{
//Print information.
PrintLine(stdout,"Main::main : press \"Q\" for exit !");
}
#ifdef _MICROSOFT_WINDOWS
}
#endif
//Sleep
SleepMilliseconds(MILLISECOND);
}while(_TRUE);
}
else
{
#ifdef _DEBUG
LogRequestedEvent("Main::main : fail to open tunnel !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
}
//Close tunnel.
CloseNetworkTunnel(&tunnel);
//Uninitialize tunnel.
UninitializeNetworkTunnel(&tunnel);
}
else
{
#ifdef _DEBUG
LogRequestedEvent("Main::main : fail to initialize tunnel environments !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FAILURE;
}
//Uninitialize tunnel environment.
UninitializeTunnelEnvironment();
//Uninitialize socket.
if(!UninitializeSocket())
{
#ifdef _DEBUG
LogRequestedEvent("Main::main : fail to uninitialize socket !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
//return _FAILURE;
}
//Uninitialize log.
if(!UninitializeLog())
{
#ifdef _DEBUG
PrintLine(stderr,"Main::main : fail to uninitialize log !");
#endif
//return _FAILURE;
}
#ifdef _DEBUG
PrintLine(stdout,"Main::main : successfully done !");
#endif
//Return success.
return _SUCCESS;
}