| | 1982 | |
| | 1983 | int |
| | 1984 | dns_resolve_host(const char *host, evdns_callback_type callback, void *arg, int ipv6) |
| | 1985 | { |
| | 1986 | ilog(L_DEBUG, "Request to resolve host %s to IP%s", host, ipv6 ? "V6" : ""); |
| | 1987 | |
| | 1988 | if(ipv6) |
| | 1989 | { |
| | 1990 | return evdns_resolve_ipv6(host, 0, callback, arg); |
| | 1991 | } |
| | 1992 | else |
| | 1993 | { |
| | 1994 | return evdns_resolve_ipv4(host, 0, callback, arg); |
| | 1995 | } |
| | 1996 | } |
| | 1997 | |
| | 1998 | int |
| | 1999 | dns_resolve_ip(const char *ip, evdns_callback_type callback, void *arg) |
| | 2000 | { |
| | 2001 | struct addrinfo hints, *res; |
| | 2002 | |
| | 2003 | ilog(L_DEBUG, "Request to resolve IP %s to host", ip); |
| | 2004 | |
| | 2005 | memset(&hints, 0, sizeof(hints)); |
| | 2006 | |
| | 2007 | hints.ai_family = AF_UNSPEC; |
| | 2008 | hints.ai_socktype = SOCK_STREAM; |
| | 2009 | hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; |
| | 2010 | |
| | 2011 | if(irc_getaddrinfo(ip, NULL, &hints, &res)) |
| | 2012 | { |
| | 2013 | return -1; |
| | 2014 | } |
| | 2015 | |
| | 2016 | if(res->ai_family == AF_INET) |
| | 2017 | { |
| | 2018 | evdns_resolve_reverse(&((struct sockaddr_in *)res->ai_addr)->sin_addr, 0, |
| | 2019 | callback, arg); |
| | 2020 | } |
| | 2021 | else if(res->ai_family == AF_INET6) |
| | 2022 | { |
| | 2023 | evdns_resolve_reverse_ipv6(&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr, |
| | 2024 | 0, callback, arg); |
| | 2025 | } |
| | 2026 | else |
| | 2027 | ilog(L_WARN, "Unknown AF returned when trying to resolve IP"); |
| | 2028 | |
| | 2029 | irc_freeaddrinfo(res); |
| | 2030 | } |