代码拉取完成,页面将自动刷新
同步操作将从 lrioxh/tls_proxy 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// socket in block mode without epoll
#include "include/proxy_lib.h"
#include <ctype.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#define CLIENT_PORT 9527
#define SERVER_PORT 9528
#define SERVER_IP "192.168.144.1"
const char *const certificate_path = "ssl/agent.crt";
const char *const private_key_path = "ssl/agent.key";
int SocketInitClnt(int *fd)
{
int tfd = 0;
tfd = socket(AF_INET, SOCK_STREAM, 0); //创建一个监听的套接字
if (tfd == -1) return 0;
struct sockaddr_in ServeraAddr;
ServeraAddr.sin_family = AF_INET;
ServeraAddr.sin_port = htons(SERVER_PORT);
ServeraAddr.sin_addr.s_addr = htonl(INADDR_ANY);
socklen_t serverAddrLen = sizeof(ServeraAddr);
if (bind(tfd, (struct sockaddr *)&ServeraAddr, serverAddrLen) == -1 || listen(tfd, 128) == -1)
{
return 0;
}
int cfd = 0;
struct sockaddr_in ClientAddr;
socklen_t clientLen = sizeof(ClientAddr);
cfd = accept(tfd, (struct sockaddr *)&ClientAddr, &clientLen);
if (cfd == -1)
{
return 0;
}
else
{
*fd = cfd;
return 1;
}
}
int SocketInitServ(int *fd)
{
*fd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in Agentaddr;
Agentaddr.sin_family = AF_INET;
Agentaddr.sin_port = htons(CLIENT_PORT);
inet_pton(AF_INET, SERVER_IP, &Agentaddr.sin_addr.s_addr);
socklen_t agentAddrLen = sizeof(Agentaddr);
if (connect(*fd, (struct sockaddr *)&Agentaddr, agentAddrLen) == -1)
{
return 0;
}
else
{
return 1;
}
}
int main()
{
ProxyStates *states = InitProxyStates();
if ( // load cert
!loadCertFile(states, certificate_path) || !loadKeyFile(states, private_key_path))
{
return 0;
}
int clientFd = -1, serverFd = -1;
if (!SocketInitClnt(&clientFd) || !SocketInitServ(&serverFd))
{
handle_error("socket connect failed");
return 0;
}
while (1)
{
unsigned char *recvData = NULL;
recvData = (unsigned char *)malloc(BUFSIZ);
int recvBytes = 0;
recvBytes = read(clientFd, recvData, BUFSIZ);
if (recvBytes > 0)
{
if (!HandleMsg(states, recvData, &recvBytes, C2S))
{
FreeProxyStates(states);
break;
}
int ret = write(serverFd, recvData, recvBytes);
if (ret < 0)
{
handle_error("client write failed");
break;
}
}
else if (recvBytes == 0)
{
}
else
{
}
recvBytes = read(serverFd, recvData, BUFSIZ);
if (recvBytes > 0)
{
if (!HandleMsg(states, recvData, &recvBytes, S2C))
{
FreeProxyStates(states);
break;
}
int ret = write(clientFd, recvData, recvBytes);
if (ret < 0)
{
handle_error("server write failed");
break;
}
}
else if (recvBytes == 0)
{
}
else
{
}
free(recvData);
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。