| 674 | } |
| 675 | |
| 676 | int 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 | |
| 709 | static int parse_int(int *out, const char **str) |
| 710 | { |
no test coverage detected