MCPcopy Create free account
hub / github.com/Tencent/phxsql / MakeProxyHeaderV1

Method MakeProxyHeaderV1

phxsqlproxy/proxy_protocol_handler.cpp:291–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291int ProxyProtocolHandler::MakeProxyHeaderV1(std::string & header) {
292 if (src_addr_.ss_family == AF_INET && dst_addr_.ss_family == AF_INET) {
293 header = "PROXY TCP4 ";
294 } else if (src_addr_.ss_family == AF_INET6 && dst_addr_.ss_family == AF_INET6) {
295 header = "PROXY TCP6 ";
296 } else {
297 header = "PROXY UNKNOWN\r\n";
298 return 0;
299 }
300
301 std::string src_ip;
302 std::string dst_ip;
303 int src_port;
304 int dst_port;
305
306 if (SockAddrToIPPort((struct sockaddr *) &src_addr_, src_ip, src_port) < 0) {
307 return -__LINE__;
308 }
309 if (SockAddrToIPPort((struct sockaddr *) &dst_addr_, dst_ip, dst_port) < 0) {
310 return -__LINE__;
311 }
312
313 header += src_ip + " " + dst_ip + " " + UIntToStr(src_port) + " " + UIntToStr(dst_port) + "\r\n";
314 LOG_DEBUG("make v1 proxy header: %s", header.c_str());
315 return 0;
316}
317
318int ProxyProtocolHandler::MakeProxyHeaderV2(std::string & header) {
319 ProxyHdr hdr;

Callers

nothing calls this directly

Calls 2

SockAddrToIPPortFunction · 0.85
UIntToStrFunction · 0.85

Tested by

no test coverage detected