1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
25 * Resolve the given name, using system name resolve functions (NOT any
26 * function provided by libcurl). Used to see if the name exists and thus if
27 * we can allow a test case to use it for testing.
29 * Like if 'localhost' actual exists etc.
33 #define CURL_NO_OLDIES
35 #include "setup.h" /* portability help from the lib directory */
43 #ifdef HAVE_SYS_TYPES_H
44 #include <sys/types.h>
46 #ifdef HAVE_SYS_SOCKET_H
47 #include <sys/socket.h>
49 #ifdef HAVE_NETINET_IN_H
50 #include <netinet/in.h>
52 #ifdef _XOPEN_SOURCE_EXTENDED
53 /* This define is "almost" required to build on HPUX 11 */
54 #include <arpa/inet.h>
60 #define ENABLE_CURLX_PRINTF
61 /* make the curlx header define all printf() functions to use the curlx_*
63 #include "curlx.h" /* from the private lib dir */
66 /* include memdebug.h last */
69 static bool use_ipv6 = FALSE;
70 static const char *ipv_inuse = "IPv4";
72 const char *serverlogfile=""; /* for a util.c function we don't use */
74 int main(int argc, char *argv[])
77 const char *host = NULL;
81 if(!strcmp("--version", argv[arg])) {
82 printf("resolve IPv4%s\n",
91 else if(!strcmp("--ipv6", argv[arg])) {
96 else if(!strcmp("--ipv4", argv[arg])) {
97 /* for completeness, we support this option as well */
107 puts("Usage: resolve [option] <host>\n"
119 atexit(win32_cleanup);
123 /* gethostbyname() resolve */
126 he = gethostbyname(host);
132 /* Check that the system has IPv6 enabled before checking the resolver */
133 curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
134 if(s == CURL_SOCKET_BAD)
135 /* an ipv6 address was requested and we can't get/use one */
142 /* getaddrinfo() resolve */
144 struct addrinfo hints;
146 memset(&hints, 0, sizeof(hints));
147 hints.ai_family = PF_INET6;
148 hints.ai_socktype = SOCK_STREAM;
149 hints.ai_flags = AI_CANONNAME;
150 /* Use parenthesis around function to stop it from being replaced by
151 the macro in memdebug.h */
152 rc = (getaddrinfo)(host, "80", &hints, &ai);
156 puts("IPv6 support has been disabled in this program");
161 printf("Resolving %s '%s' didn't work\n", ipv_inuse, host);