MCPcopy Create free account
hub / github.com/cppla/ServerStatus / net_host_lookup

Function net_host_lookup

server/src/system.c:676–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

674}
675
676int net_host_lookup(const char *hostname, NETADDR *addr, int types)
677{
678 struct addrinfo hints;
679 struct addrinfo *result;
680 int e;
681 char host[256];
682 int port = 0;
683
684 if(priv_net_extract(hostname, host, sizeof(host), &port))
685 return -1;
686 /*
687 dbg_msg("host lookup", "host='%s' port=%d %d", host, port, types);
688 */
689
690 mem_zero(&hints, sizeof(hints));
691
692 hints.ai_family = AF_UNSPEC;
693
694 if(types == NETTYPE_IPV4)
695 hints.ai_family = AF_INET;
696 else if(types == NETTYPE_IPV6)
697 hints.ai_family = AF_INET6;
698
699 e = getaddrinfo(host, NULL, &hints, &result);
700 if(e != 0 || !result)
701 return -1;
702
703 sockaddr_to_netaddr(result->ai_addr, addr);
704 freeaddrinfo(result);
705 addr->port = port;
706 return 0;
707}
708
709static int parse_int(int *out, const char **str)
710{

Callers 2

InitMethod · 0.85
InitMethod · 0.85

Calls 3

priv_net_extractFunction · 0.85
mem_zeroFunction · 0.85
sockaddr_to_netaddrFunction · 0.85

Tested by

no test coverage detected