MCPcopy Create free account
hub / github.com/apache/brpc / hostname2endpoint

Function hostname2endpoint

src/butil/endpoint.cpp:317–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315}
316
317int hostname2endpoint(const char* str, EndPoint* point) {
318 // Should be enough to hold ip address
319 // The definitive descriptions of the rules for forming domain names appear in RFC 1035, RFC 1123, RFC 2181,
320 // and RFC 5892. The full domain name may not exceed the length of 253 characters in its textual representation
321 // (Domain Names - Domain Concepts and Facilities. IETF. doi:10.17487/RFC1034. RFC 1034.).
322 // For cacheline optimize, use buf size as 256;
323 char buf[256];
324 size_t i = 0;
325 for (; i < MAX_DOMAIN_LENGTH && str[i] != '\0' && str[i] != ':'; ++i) {
326 buf[i] = str[i];
327 }
328
329 if (i >= MAX_DOMAIN_LENGTH || str[i] != ':') {
330 return -1;
331 }
332
333 buf[i] = '\0';
334 if (hostname2ip(buf, &point->ip) != 0) {
335 return -1;
336 }
337 if (str[i] == ':') {
338 ++i;
339 }
340 char* end = NULL;
341 point->port = strtol(str + i, &end, 10);
342 if (end == str + i) {
343 return -1;
344 } else if (*end) {
345 for (; isspace(*end); ++end);
346 if (*end) {
347 return -1;
348 }
349 }
350 if (point->port < 0 || point->port > 65535) {
351 return -1;
352 }
353 return 0;
354}
355
356int hostname2endpoint(const char* name_str, int port, EndPoint* point) {
357 if (hostname2ip(name_str, &point->ip) != 0) {

Callers 12

mainFunction · 0.85
TESTFunction · 0.85
TestConnectInterruptImplFunction · 0.85
TESTFunction · 0.85
TestConnectInterruptImplFunction · 0.85
TEST_FFunction · 0.85
InitMethod · 0.85
StartMethod · 0.85
ParseHttpServerAddressFunction · 0.85
ParseServerListFunction · 0.85
GetServersMethod · 0.85
GetServersMethod · 0.85

Calls 1

hostname2ipFunction · 0.85

Tested by 5

TESTFunction · 0.68
TestConnectInterruptImplFunction · 0.68
TESTFunction · 0.68
TestConnectInterruptImplFunction · 0.68
TEST_FFunction · 0.68