diff -urN darkbot/source/comm.c darkbot-new/source/comm.c --- darkbot/source/comm.c 2003-06-20 17:56:44.000000000 +0200 +++ darkbot-new/source/comm.c 2004-04-25 02:59:20.000000000 +0200 @@ -300,7 +300,12 @@ int create_connection (char *server, char *virtualhost, long port) { - struct sockaddr_in name; +#ifdef IPV6 + struct sockaddr_in6 name; + char v6addr[256]; +#else + struct sockaddr_in name; +#endif struct hostent *hostname; struct timeval timeout; fd_set set; @@ -310,31 +315,57 @@ if ((!virtualhost) || (strlen (virtualhost) < 1)) vhost = 0; - if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) - return -1; - - memset (&name, 0, sizeof (struct sockaddr_in)); +#ifdef IPV6 + if ((sock = socket (AF_INET6, SOCK_STREAM, 0)) < 0) + return -1; + + memset (&name, 0, sizeof (struct sockaddr_in6)); + name.sin6_family = AF_INET6; + inet_pton(AF_INET6, "0::0", &name.sin6_addr); +#else + if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) + return -1; + + memset (&name, 0, sizeof (struct sockaddr_in)); + name.sin_family = AF_INET; + name.sin_addr.s_addr = (vhost ? inet_addr (virtualhost) : INADDR_ANY); +#endif setsockopt (sock, SOL_SOCKET, SO_LINGER, 0, 0); setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, 0, 0); setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, 0, 0); - name.sin_family = AF_INET; - name.sin_addr.s_addr = (vhost ? inet_addr (virtualhost) : INADDR_ANY); - if ((name.sin_addr.s_addr == -1) && vhost) - { - hostname = gethostbyname (virtualhost); - if (hostname) +#ifdef IPV6 + if (vhost) { - name.sin_addr = *(struct in_addr *) hostname->h_addr; + if ((hostname = gethostbyname2(virtualhost, AF_INET6)) != NULL) + { + inet_ntop(AF_INET6, (struct in6_addr *)( hostname->h_addr_list[0] ), v6addr, 256); + printf("VirtualHost resolved to : %s", v6addr); + inet_pton(AF_INET6, v6addr, &name.sin6_addr); + } + else + { + inet_pton(AF_INET6, "0::0", &name.sin6_addr); + } } - else +#else + if ((name.sin_addr.s_addr == -1) && vhost) { - name.sin_addr.s_addr = INADDR_ANY; + hostname = gethostbyname (virtualhost); + if (hostname) + { + name.sin_addr = *(struct in_addr *) hostname->h_addr; + } + else + { + name.sin_addr.s_addr = INADDR_ANY; + } } - } - if (bind (sock, (struct sockaddr *) &name, sizeof (struct sockaddr_in)) < 0) +#endif + + if (bind (sock, (struct sockaddr *) &name, sizeof(name)) < 0) { printf ("\n"); perror ("bind"); @@ -342,18 +373,31 @@ exit (EXIT_FAILURE); } - memset (&name, 0, sizeof (struct sockaddr_in)); - name.sin_family = AF_INET; - name.sin_port = htons (port); + memset (&name, 0, sizeof (name)); +#ifdef IPV6 + name.sin6_family = AF_INET6; + name.sin6_port = htons (port); - if(!(hostname = gethostbyname (server))) - { - printf ("\n"); - herror ("hostname"); - exit (EXIT_FAILURE); - } + if ((hostname = gethostbyname2(server, AF_INET6)) != NULL) + { + inet_ntop(AF_INET6, (struct in6_addr *)( hostname->h_addr_list[0] ), v6addr, 256); + printf("Server resolved to : %s", v6addr); + inet_pton(AF_INET6, v6addr, &name.sin6_addr); + } +#else + name.sin_family = AF_INET; + name.sin_port = htons (port); + + if(!(hostname = gethostbyname (server))) + { + printf ("\n"); + herror ("hostname"); + exit (EXIT_FAILURE); + } + + name.sin_addr = *(struct in_addr *) hostname->h_addr; +#endif - name.sin_addr = *(struct in_addr *) hostname->h_addr; /* set the file descriptor to non blocking mode so that connect() returns immediately. diff -urN darkbot/source/defines.h darkbot-new/source/defines.h --- darkbot/source/defines.h 2004-04-04 02:11:08.000000000 +0200 +++ darkbot-new/source/defines.h 2004-04-25 03:14:02.000000000 +0200 @@ -35,6 +35,14 @@ // ================ SYSTEM REQUIREMENTS ================ +/* This sets weather or not you want the darkbot to be ipv6 based + * or not. Note that if you want it to use the other protocol + * you will have to recompile + * (#define IPV6 = on) + * (#undef IPV6 = off) + */ +#define IPV6 + /* * Change the Ansi C signal handling below if it's not in the standard place, * usually on include/. Leave it as is if you don't know what that is. Type