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

Method FakeClientIPInAuthBuf

phxsqlproxy/io_channel.cpp:205–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205int IOChannel::FakeClientIPInAuthBuf(char * buf, size_t buf_len) {
206 if (buf_len < 36) {
207 LOG_ERR("buf len less than 36");
208 return -__LINE__;
209 }
210 char * reserverd_begin = buf + 14;
211 char ip_buf[INET6_ADDRSTRLEN] = { 0 };
212
213 uint32_t ip = 0;
214 memcpy(&ip, reserverd_begin, sizeof(uint32_t));
215 if (ip) {
216 if (inet_ntop(AF_INET, reserverd_begin, ip_buf, INET6_ADDRSTRLEN) != NULL) {
217 if (!group_status_cache_->IsMember(client_ip_)) {
218 LOG_ERR("receive fake ip package from [%s], fake ip [%s]", client_ip_.c_str(), ip_buf);
219 return -__LINE__;
220 }
221 } else
222 return -__LINE__;
223 } else {
224 int ret = inet_pton(AF_INET, client_ip_.c_str(), reserverd_begin);
225 if (ret <= 0) {
226 LOG_ERR("ret %d errno (%d:%s)", ret, errno, strerror(errno));
227 return -__LINE__;
228 }
229 }
230 return 0;
231}
232
233void IOChannel::GetDBNameFromAuthBuf(const char * buf, int buf_size) {
234 if (buf_size < 36) {

Callers

nothing calls this directly

Calls 1

IsMemberMethod · 0.80

Tested by

no test coverage detected