MCPcopy Create free account
hub / github.com/chenshuo/muduo / onServerMessage

Function onServerMessage

examples/socks4a/socks4a.cc:32–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32void onServerMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp)
33{
34 LOG_DEBUG << conn->name() << " " << buf->readableBytes();
35 if (g_tunnels.find(conn->name()) == g_tunnels.end())
36 {
37 if (buf->readableBytes() > 128)
38 {
39 conn->shutdown();
40 }
41 else if (buf->readableBytes() > 8)
42 {
43 const char* begin = buf->peek() + 8;
44 const char* end = buf->peek() + buf->readableBytes();
45 const char* where = std::find(begin, end, '\0');
46 if (where != end)
47 {
48 char ver = buf->peek()[0];
49 char cmd = buf->peek()[1];
50 const void* port = buf->peek() + 2;
51 const void* ip = buf->peek() + 4;
52
53 sockaddr_in addr;
54 memZero(&addr, sizeof addr);
55 addr.sin_family = AF_INET;
56 addr.sin_port = *static_cast<const in_port_t*>(port);
57 addr.sin_addr.s_addr = *static_cast<const uint32_t*>(ip);
58
59 bool socks4a = sockets::networkToHost32(addr.sin_addr.s_addr) < 256;
60 bool okay = false;
61 if (socks4a)
62 {
63 const char* endOfHostName = std::find(where+1, end, '\0');
64 if (endOfHostName != end)
65 {
66 string hostname = where+1;
67 where = endOfHostName;
68 LOG_INFO << "Socks4a host name " << hostname;
69 InetAddress tmp;
70 if (InetAddress::resolve(hostname, &tmp))
71 {
72 addr.sin_addr.s_addr = tmp.ipv4NetEndian();
73 okay = true;
74 }
75 }
76 else
77 {
78 return;
79 }
80 }
81 else
82 {
83 okay = true;
84 }
85
86 InetAddress serverAddr(addr);
87 if (ver == 4 && cmd == 1 && okay)
88 {
89 TunnelPtr tunnel(new Tunnel(g_eventLoop, serverAddr, conn));

Callers

nothing calls this directly

Calls 13

memZeroFunction · 0.85
networkToHost32Function · 0.85
resolveFunction · 0.85
readableBytesMethod · 0.80
shutdownMethod · 0.80
peekMethod · 0.80
ipv4NetEndianMethod · 0.80
setupMethod · 0.80
retrieveUntilMethod · 0.80
endMethod · 0.45
connectMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected