MCPcopy Create free account
hub / github.com/RsyncProject/rsync / gethostnameinfo

Function gethostnameinfo

lib/getaddrinfo.c:398–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396}
397
398static int gethostnameinfo(const struct sockaddr *sa,
399 char *node,
400 size_t nodelen,
401 int flags)
402{
403 int ret = -1;
404 char *p = NULL;
405
406 if (!(flags & NI_NUMERICHOST)) {
407 struct hostent *hp = gethostbyaddr(
408 (void *)&((struct sockaddr_in *)sa)->sin_addr,
409 sizeof (struct in_addr),
410 sa->sa_family);
411 ret = check_hostent_err(hp);
412 if (ret == 0) {
413 /* Name looked up successfully. */
414 ret = snprintf(node, nodelen, "%s", hp->h_name);
415 if (ret < 0 || (size_t)ret >= nodelen) {
416 return EAI_MEMORY;
417 }
418 if (flags & NI_NOFQDN) {
419 p = strchr(node,'.');
420 if (p) {
421 *p = '\0';
422 }
423 }
424 return 0;
425 }
426
427 if (flags & NI_NAMEREQD) {
428 /* If we require a name and didn't get one,
429 * automatically fail. */
430 return ret;
431 }
432 /* Otherwise just fall into the numeric host code... */
433 }
434 p = inet_ntoa(((struct sockaddr_in *)sa)->sin_addr);
435 ret = snprintf(node, nodelen, "%s", p);
436 if (ret < 0 || (size_t)ret >= nodelen) {
437 return EAI_MEMORY;
438 }
439 return 0;
440}
441
442static int getservicenameinfo(const struct sockaddr *sa,
443 char *service,

Callers 1

getnameinfoFunction · 0.85

Calls 1

check_hostent_errFunction · 0.85

Tested by

no test coverage detected