-
Notifications
You must be signed in to change notification settings - Fork 203
/
sendmsg.cpp
36 lines (33 loc) · 1.05 KB
/
sendmsg.cpp
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
#include "config.h"
#include <string>
#if WIN32
#include <windows.h>
#else
#include <arpa/inet.h>
#include <errno.h>
typedef long long __int64;
#endif
#include "sendmsg.h"
#include <stdlib.h>
using namespace std;
char *rand_str(char *str, const int len)
{
int i;
for (i = 0; i < len; ++i)
str[i] = 'A' + rand() % 26;
str[++i] = '\0';
return str;
}
int SendReqTunnel(int sock, ssl_context *ssl, TunnelInfo *tunnelInfo)
{
char guid[20] = {0};
rand_str(guid, 5);
char str[1024];
memset(str, 0, 1024);
memset(tunnelInfo->ReqId, 0, 20);
//copy
memcpy(tunnelInfo->ReqId, guid, strlen(guid));
sprintf(str, "{\"Type\":\"ReqTunnel\",\"Payload\":{\"Protocol\":\"%s\",\"ReqId\":\"%s\",\"Hostname\": \"%s\",\"Subdomain\":\"%s\",\"HttpAuth\":\"%s\",\"RemotePort\":%d,\"authtoken\":\"%s\"}}", tunnelInfo->protocol, tunnelInfo->ReqId, tunnelInfo->hostname, tunnelInfo->subdomain, tunnelInfo->httpauth, tunnelInfo->remoteport, mainInfo.authtoken);
tunnelInfo->regtime = getUnixTime(); //已发
return sendpack(sock, ssl, str, 1);
}