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

Function SetAddr

phxsqlproxy/phxsqlproxyutil.cpp:62–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62int SetAddr(const char * ip_string, const unsigned short port, struct sockaddr_in & addr) {
63 bzero(&addr, sizeof(addr));
64 addr.sin_family = AF_INET;
65 addr.sin_port = htons(port);
66 if (!ip_string || '\0' == *ip_string || 0 == strcmp(ip_string, "0") || 0 == strcmp(ip_string, "0.0.0.0")
67 || 0 == strcmp(ip_string, "*")) {
68 addr.sin_addr.s_addr = htonl(INADDR_ANY);
69 } else {
70 int ret = inet_pton(AF_INET, ip_string, &addr.sin_addr);
71 if (ret <= 0) {
72 LogError("inet_pton failed, ip [%s], ret %d, errno(%d:%s)", ip_string, ret, errno, strerror(errno));
73 return -1;
74 }
75 }
76 return 0;
77}
78
79int SetAddr6(const char * ip_string, const unsigned short port, struct sockaddr_in6 & addr) {
80 bzero(&addr, sizeof(addr));

Callers 3

CreateTcpSocketFunction · 0.85
ParseProxyHeaderV1Method · 0.85
ConnectDestMethod · 0.85

Calls 1

LogErrorFunction · 0.85

Tested by

no test coverage detected