Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "server_setup.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifdef HAVE_SIGNAL_H
00035 #include <signal.h>
00036 #endif
00037 #ifdef HAVE_NETINET_IN_H
00038 #include <netinet/in.h>
00039 #endif
00040 #ifdef _XOPEN_SOURCE_EXTENDED
00041
00042 #include <arpa/inet.h>
00043 #endif
00044 #ifdef HAVE_NETDB_H
00045 #include <netdb.h>
00046 #endif
00047
00048 #define ENABLE_CURLX_PRINTF
00049
00050
00051 #include "curlx.h"
00052 #include "util.h"
00053
00054
00055 #include "memdebug.h"
00056
00057 static bool use_ipv6 = FALSE;
00058 static const char *ipv_inuse = "IPv4";
00059
00060 const char *serverlogfile="";
00061
00062 int main(int argc, char *argv[])
00063 {
00064 int arg=1;
00065 const char *host = NULL;
00066 int rc = 0;
00067
00068 while(argc>arg) {
00069 if(!strcmp("--version", argv[arg])) {
00070 printf("resolve IPv4%s\n",
00071 #ifdef ENABLE_IPV6
00072 "/IPv6"
00073 #else
00074 ""
00075 #endif
00076 );
00077 return 0;
00078 }
00079 else if(!strcmp("--ipv6", argv[arg])) {
00080 ipv_inuse = "IPv6";
00081 use_ipv6 = TRUE;
00082 arg++;
00083 }
00084 else if(!strcmp("--ipv4", argv[arg])) {
00085
00086 ipv_inuse = "IPv4";
00087 use_ipv6 = FALSE;
00088 arg++;
00089 }
00090 else {
00091 host = argv[arg++];
00092 }
00093 }
00094 if(!host) {
00095 puts("Usage: resolve [option] <host>\n"
00096 " --version\n"
00097 " --ipv4"
00098 #ifdef ENABLE_IPV6
00099 "\n --ipv6"
00100 #endif
00101 );
00102 return 1;
00103 }
00104
00105 #ifdef WIN32
00106 win32_init();
00107 atexit(win32_cleanup);
00108 #endif
00109
00110 if(!use_ipv6) {
00111
00112 struct hostent *he;
00113
00114 he = gethostbyname(host);
00115
00116 rc = !he;
00117 }
00118 else {
00119 #ifdef ENABLE_IPV6
00120
00121 curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
00122 if(s == CURL_SOCKET_BAD)
00123
00124 rc = -1;
00125 else {
00126 sclose(s);
00127 }
00128
00129 if(rc == 0) {
00130
00131 struct addrinfo *ai;
00132 struct addrinfo hints;
00133
00134 memset(&hints, 0, sizeof(hints));
00135 hints.ai_family = PF_INET6;
00136 hints.ai_socktype = SOCK_STREAM;
00137 hints.ai_flags = AI_CANONNAME;
00138
00139
00140 rc = (getaddrinfo)(host, "80", &hints, &ai);
00141 if(rc == 0)
00142 (freeaddrinfo)(ai);
00143 }
00144
00145 #else
00146 puts("IPv6 support has been disabled in this program");
00147 return 1;
00148 #endif
00149 }
00150 if(rc)
00151 printf("Resolving %s '%s' didn't work\n", ipv_inuse, host);
00152
00153 return !!rc;
00154 }