1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2005, 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.
22 ***************************************************************************/
26 * Resolve the given name, using system name resolve functions (NOT any
27 * function provided by libcurl). Used to see if the name exists and thus if
28 * we can allow a test case to use it for testing.
30 * Like if 'localhost' actual exists etc.
33 #include "setup.h" /* portability help from the lib directory */
43 #include <sys/types.h>
48 #ifdef HAVE_SYS_SOCKET_H
49 #include <sys/socket.h>
51 #ifdef HAVE_NETINET_IN_H
52 #include <netinet/in.h>
54 #ifdef _XOPEN_SOURCE_EXTENDED
55 /* This define is "almost" required to build on HPUX 11 */
56 #include <arpa/inet.h>
62 #define ENABLE_CURLX_PRINTF
63 /* make the curlx header define all printf() functions to use the curlx_*
65 #include "curlx.h" /* from the private lib dir */
68 /* include memdebug.h last */
73 const char *serverlogfile=""; /* for a util.c function we don't use */
75 int main(int argc, char *argv[])
82 if(!strcmp("--version", argv[arg])) {
83 printf("resolve IPv4%s\n",
92 else if(!strcmp("--ipv6", argv[arg])) {
98 else if(!strcmp("--ipv4", argv[arg])) {
99 /* for completeness, we support this option as well */
108 puts("Usage: resolve [option] <host>\n"
115 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
117 atexit(win32_cleanup);
124 /* gethostbyname() resolve */
127 he = gethostbyname(host);
133 /* getaddrinfo() resolve */
135 struct addrinfo hints;
137 memset(&hints, 0, sizeof(hints));
138 hints.ai_family = PF_INET6;
139 hints.ai_socktype = SOCK_STREAM;
140 hints.ai_flags = AI_CANONNAME;
141 rc = (getaddrinfo)(host, "80", &hints, &ai);
146 printf("Resolving '%s' FAILED\n", host);