Hi, i worked on it :-) The good thing is http works not with IPv4 and IPv6 sites if commpiled with IPv6.
3 things have to be done now: 1. make command line siwtch to change the default 4/6 2. if IPv6 enabled and IPv4 address found make an IPv6 address from whem ( clean caching ) 3. Make the ftp protocol part. I think 1+2 i can handle. Cu Thomas Lußnig
Only in wget-1.8.1_ipv6/src: .libs Only in wget-1.8.1_ipv6/src: Makefile Only in wget-1.8.1_ipv6/src: cmpt.o Only in wget-1.8.1_ipv6/src: config.h diff -ubr wget-1.8.1/src/connect.c wget-1.8.1_ipv6/src/connect.c --- wget-1.8.1/src/connect.c Tue Nov 27 14:55:40 2001 +++ wget-1.8.1_ipv6/src/connect.c Tue Jan 15 11:17:18 2002 @@ -55,6 +55,8 @@ extern int errno; #endif +#define IPV6 + /* Variables shared by bindport and acceptport: */ static int msock = -1; static struct sockaddr *addr; @@ -78,14 +80,11 @@ int connect_to_one (const unsigned char *addr, unsigned short port, int silent) { - struct sockaddr_in sock_name; + SOCKADDR_IN sock_name; int sock, save_errno; - + int sockaddr_len=get_socklen(ip_default_family); /* Set port and protocol */ - sock_name.sin_family = AF_INET; - sock_name.sin_port = htons (port); - memcpy ((unsigned char *)&sock_name.sin_addr, addr, 4); - + set_ip_address(ip_default_family,port,addr,(struct sockaddr *)&sock_name); if (!silent) { char *pretty_addr = pretty_print_address (addr); @@ -99,15 +98,14 @@ } /* Make an internet socket, stream type. */ - sock = socket (AF_INET, SOCK_STREAM, 0); + sock = socket (ip_default_family, SOCK_STREAM, 0); if (sock < 0) goto out; if (opt.bind_address) { /* Bind the client side to the requested address. */ - if (bind (sock, (struct sockaddr *)opt.bind_address, - sizeof (*opt.bind_address))) + if (bind (sock, (struct sockaddr *)opt.bind_address,sockaddr_len)) { close (sock); sock = -1; @@ -116,7 +114,7 @@ } /* Connect the socket to the remote host. */ - if (connect (sock, (struct sockaddr *)&sock_name, sizeof (sock_name)) < 0) + if (connect (sock, (struct sockaddr *)&sock_name,sockaddr_len) < 0) { close (sock); sock = -1; @@ -151,7 +149,7 @@ address_list_get_bounds (al, &start, &end); for (i = start; i < end; i++) { - unsigned char addr[4]; + ip_address addr; int sock; address_list_copy_one (al, i, addr); @@ -210,11 +208,13 @@ bindport (unsigned short *port) { int optval = 1; - static struct sockaddr_in srv; + static SOCKADDR_IN srv={0}; + int sockaddr_len=get_socklen(ip_default_family); + msock = -1; addr = (struct sockaddr *) &srv; - if ((msock = socket (AF_INET, SOCK_STREAM, 0)) < 0) + if ((msock = socket (ip_default_family, SOCK_STREAM, 0)) < 0) return CONSOCKERR; if (setsockopt (msock, SOL_SOCKET, SO_REUSEADDR, (char *)&optval, sizeof (optval)) < 0) @@ -222,14 +222,13 @@ if (opt.bind_address == NULL) { - srv.sin_family = AF_INET; - srv.sin_addr.s_addr = htonl (INADDR_ANY); + set_ip_address(ip_default_family,htons(*port),NULL,(struct sockaddr*)&srv); } else srv = *opt.bind_address; - srv.sin_port = htons (*port); - if (bind (msock, addr, sizeof (struct sockaddr_in)) < 0) + set_port(*port,(struct sockaddr*)&srv); + if (bind (msock, addr, sockaddr_len) < 0) { CLOSE (msock); msock = -1; @@ -241,14 +240,14 @@ /* #### addrlen should be a 32-bit type, which int is not guaranteed to be. Oh, and don't try to make it a size_t, because that can be 64-bit. */ - int addrlen = sizeof (struct sockaddr_in); + int addrlen = sockaddr_len; if (getsockname (msock, addr, &addrlen) < 0) { CLOSE (msock); msock = -1; return CONPORTERR; } - *port = ntohs (srv.sin_port); + *port=get_port((struct sockaddr*)&srv); } if (listen (msock, 1) < 0) { @@ -292,7 +291,7 @@ uerr_t acceptport (int *sock) { - int addrlen = sizeof (struct sockaddr_in); + int addrlen = get_socklen(ip_default_family); #ifdef HAVE_SELECT if (select_fd (msock, opt.timeout, 0) <= 0) @@ -322,8 +321,8 @@ unsigned char * conaddr (int fd) { - static unsigned char res[4]; - struct sockaddr_in mysrv; + static ip_address res; + SOCKADDR_IN mysrv; struct sockaddr *myaddr; int addrlen = sizeof (mysrv); /* see bindport() for discussion of using `int' here. */ @@ -331,7 +330,11 @@ myaddr = (struct sockaddr *) (&mysrv); if (getsockname (fd, myaddr, (int *)&addrlen) < 0) return NULL; - memcpy (res, &mysrv.sin_addr, 4); +#ifdef IPV6 + memcpy (res, &mysrv.sin6_addr, sizeof(ip_address)); +#else + memcpy (res, &mysrv.sin_addr, sizeof(ip_address)); +#endif return res; } Only in wget-1.8.1_ipv6/src: connect.o Only in wget-1.8.1_ipv6/src: cookies.o Only in wget-1.8.1_ipv6/src: err Only in wget-1.8.1_ipv6/src: fnmatch.o Only in wget-1.8.1_ipv6/src: ftp-basic.o Only in wget-1.8.1_ipv6/src: ftp-ls.o Only in wget-1.8.1_ipv6/src: ftp-opie.o Only in wget-1.8.1_ipv6/src: ftp.o Only in wget-1.8.1_ipv6/src: gen-md5.o Only in wget-1.8.1_ipv6/src: gen_sslfunc.o Only in wget-1.8.1_ipv6/src: hash.o Only in wget-1.8.1_ipv6/src: headers.o diff -ubr wget-1.8.1/src/host.c wget-1.8.1_ipv6/src/host.c --- wget-1.8.1/src/host.c Tue Dec 11 08:32:57 2001 +++ wget-1.8.1_ipv6/src/host.c Tue Jan 15 11:18:12 2002 @@ -18,6 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <config.h> +#include <netdb.h> #include <stdio.h> #include <stdlib.h> @@ -65,8 +66,13 @@ # endif #endif -/* An IPv4 address is simply a 4-byte quantity. */ -typedef unsigned char ipv4_address[4]; +#ifdef IPV6 +int ip_default_family = AF_INET6; +#else +int ip_default_family = AF_INET; +#endif + + /* Mapping between known hosts and to lists of their addresses. */ @@ -77,7 +83,8 @@ struct address_list { int count; /* number of adrresses */ - ipv4_address *addresses; /* pointer to the string of addresses */ + int ip_family; + ip_address *addresses; /* pointer to the string of addresses */ int faulty; /* number of addresses known not to work. */ @@ -85,6 +92,105 @@ not. */ }; +void +set_ip_address(int ip_family,unsigned short port,const unsigned char*addr,struct +sockaddr *sock_name) +{ + if(ip_family==AF_INET) + { + struct sockaddr_in *ip_sock=(struct sockaddr_in *)sock_name; + ip_sock->sin_family=ip_family; + ip_sock->sin_port=htons(port); + if(addr==NULL) memset((unsigned char*)&ip_sock->sin_addr,0 ,4); + else memcpy((unsigned char*)&ip_sock->sin_addr,addr,4); + } +#ifdef IPV6 + if(ip_family==AF_INET6) + { + struct sockaddr_in6 *ip_sock=(struct sockaddr_in6*)sock_name; + ip_sock->sin6_family=ip_family; + ip_sock->sin6_port=htons(port); + if(addr==NULL) memset(ip_sock->sin6_addr.in6_u.u6_addr8,0 ,4); + else memcpy(ip_sock->sin6_addr.in6_u.u6_addr8,addr,4); + } +#endif +} +void set_port(unsigned short port,struct sockaddr *sock_name) +{ + if(sock_name->sa_family==AF_INET) + { + struct sockaddr_in *ip_sock=(struct sockaddr_in *)&sock_name; + ip_sock->sin_port=htons(port); + } +#ifdef IPV6 + if(sock_name->sa_family==AF_INET6) + { + struct sockaddr_in6 *ip_sock=(struct sockaddr_in6*)&sock_name; + ip_sock->sin6_port=htons(port); + } +#endif +} +void set_family(int ip_family,struct sockaddr *sock_name) +{ + if(ip_family==AF_INET) + { + struct sockaddr_in *ip_sock=(struct sockaddr_in *)&sock_name; + ip_sock->sin_family=ip_family; + } +#ifdef IPV6 + if(ip_family==AF_INET6) + { + struct sockaddr_in6 *ip_sock=(struct sockaddr_in6*)&sock_name; + ip_sock->sin6_family=ip_family; + } +#endif +} + +const unsigned char *get_addr(struct sockaddr *sock_name) +{ + if(sock_name->sa_family==AF_INET) + { + struct sockaddr_in *ip_sock=(struct sockaddr_in *)&sock_name; + return (unsigned char*)&ip_sock->sin_addr; + } +#ifdef IPV6 + if(sock_name->sa_family==AF_INET6) + { + struct sockaddr_in6 *ip_sock=(struct sockaddr_in6*)&sock_name; + return ip_sock->sin6_addr.in6_u.u6_addr8; + } +#endif + return NULL; +} + +unsigned short get_port(struct sockaddr *sock_name) +{ + if(sock_name->sa_family==AF_INET) + { + struct sockaddr_in *ip_sock=(struct sockaddr_in *)&sock_name; + return ntohs(ip_sock->sin_port); + } +#ifdef IPV6 + if(sock_name->sa_family==AF_INET6) + { + struct sockaddr_in6 *ip_sock=(struct sockaddr_in6*)&sock_name; + return ntohs(ip_sock->sin6_port); + } +#endif + return -1; +} +int get_socklen(int ip_family) +{ + if(ip_family==AF_INET) return sizeof(struct sockaddr_in); +#ifdef IPV6 + if(ip_family==AF_INET6) return sizeof(struct sockaddr_in); +#endif + return 0; +} + + + + + /* Get the bounds of the address list. */ void @@ -101,7 +207,7 @@ unsigned char *ip_store) { assert (index >= al->faulty && index < al->count); - memcpy (ip_store, al->addresses + index, sizeof (ipv4_address)); + memcpy (ip_store, al->addresses + index, sizeof (ip_address)); } /* Check whether two address lists have all their IPs in common. */ @@ -114,7 +220,7 @@ if (al1->count != al2->count) return 0; return 0 == memcmp (al1->addresses, al2->addresses, - al1->count * sizeof (ipv4_address)); + al1->count * sizeof (ip_address)); } /* Mark the INDEXth element of AL as faulty, so that the next time @@ -152,11 +258,11 @@ assert (count > 0); al->count = count; al->faulty = 0; - al->addresses = xmalloc (count * sizeof (ipv4_address)); + al->addresses = xmalloc (count * sizeof (ip_address)); al->refcount = 1; for (i = 0; i < count; i++) - memcpy (al->addresses + i, h_addr_list[i], sizeof (ipv4_address)); + memcpy (al->addresses + i, h_addr_list[i], sizeof (ip_address)); return al; } @@ -169,9 +275,9 @@ struct address_list *al = xmalloc (sizeof (struct address_list)); al->count = 1; al->faulty = 0; - al->addresses = xmalloc (sizeof (ipv4_address)); + al->addresses = xmalloc (sizeof (ip_address)); al->refcount = 1; - memcpy (al->addresses, addr, sizeof (ipv4_address)); + memcpy (al->addresses, addr, sizeof (ip_address)); return al; } @@ -233,14 +339,20 @@ lookup_host (const char *host, int silent) { struct address_list *al = NULL; - unsigned long addr; + ip_address addr; struct hostent *hptr; - /* If the address is of the form d.d.d.d, no further lookup is - needed. */ - addr = (unsigned long)inet_addr (host); - if ((int)addr != -1) + /* If the address is of the form that if valid for <family>, + no further lookup is needed. */ +#ifdef IPV6 + if(0>=inet_pton(ip_default_family,host,addr)) { +#else + long tmp_ipv4=(long)inet_addr (host); + if(int(tmp_ipv4)!=-1) + { + memcpy(addr,&tmp_ipv4,4); +#endif /* ADDR is defined to be in network byte order, which is what this returns, so we can just copy it to STORE_IP. However, on big endian 64-bit architectures the value will be stored @@ -248,15 +360,13 @@ we copy the correct four bytes. */ int offset; #ifdef WORDS_BIGENDIAN - offset = sizeof (unsigned long) - sizeof (ipv4_address); + offset = sizeof (unsigned long) - sizeof (ip_address); #else offset = 0; #endif return address_list_new_one ((char *)&addr + offset); } - /* By now we know that the host name we got is not of the form - d.d.d.d. Try to find it in our cache of host names. */ if (host_name_addresses_map) al = hash_table_get (host_name_addresses_map, host); @@ -270,8 +380,8 @@ if (!silent) logprintf (LOG_VERBOSE, _("Resolving %s... "), host); - /* Look up the host using gethostbyname(). */ - hptr = gethostbyname (host); + /* Look up the host using getipnodebyname(). */ + hptr = gethostbyname2(host, ip_default_family); if (!hptr) { if (!silent) diff -ubr wget-1.8.1/src/host.h wget-1.8.1_ipv6/src/host.h --- wget-1.8.1/src/host.h Tue Dec 11 08:32:58 2001 +++ wget-1.8.1_ipv6/src/host.h Tue Jan 15 11:17:10 2002 @@ -19,6 +19,7 @@ #ifndef HOST_H #define HOST_H +#include <netdb.h> struct url; struct address_list; @@ -43,5 +44,31 @@ int sufmatch PARAMS ((const char **, const char *)); void host_cleanup PARAMS ((void)); +void set_ip_address(int ip_family,unsigned short port, + const unsigned char*addr,struct sockaddr *sock_name); +void set_port (unsigned short port,struct sockaddr *sock_name); +void set_family(int ip_family,struct sockaddr *sock_name); + +const unsigned char *get_addr(struct sockaddr *sock_name); +unsigned short get_port(struct sockaddr *sock_name); +#define IPV6 +/* + IPv6 support added by Thomas Lussnig <[EMAIL PROTECTED]> + Date: 15.01.2001 02:36:05 + If there are mistakes please inform me, but i will not work till the + morning on it. +*/ + +#ifdef IPV6 +/* An IPv6 address is simply a 16-byte quantity. */ +typedef unsigned char ip_address[16]; +typedef struct sockaddr_in6 SOCKADDR_IN; +#else +/* An IPv4 address is simply a 4-byte quantity. */ +typedef unsigned char ip_address[4]; +typedef struct sockaddr_in SOCKADDR_IN; +#endif +extern int ip_default_family; /* defined in host.c */ + #endif /* HOST_H */ Only in wget-1.8.1_ipv6/src: host.o Only in wget-1.8.1_ipv6/src: html-parse.o Only in wget-1.8.1_ipv6/src: html-url.o Only in wget-1.8.1_ipv6/src: http.o diff -ubr wget-1.8.1/src/init.c wget-1.8.1_ipv6/src/init.c --- wget-1.8.1/src/init.c Thu Dec 13 19:19:03 2001 +++ wget-1.8.1_ipv6/src/init.c Tue Jan 15 11:18:29 2002 @@ -526,8 +526,8 @@ cmd_address (const char *com, const char *val, void *closure) { struct address_list *al; - struct sockaddr_in sin; - struct sockaddr_in **target = (struct sockaddr_in **)closure; + SOCKADDR_IN sin; + SOCKADDR_IN **target = (SOCKADDR_IN **)closure; memset (&sin, '\0', sizeof (sin)); @@ -538,11 +538,10 @@ exec_name, com, val); return 0; } - address_list_copy_one (al, 0, (unsigned char *)&sin.sin_addr); + set_family(ip_default_family, (struct sockaddr*)&sin); + set_port (0,(struct sockaddr*)&sin); + address_list_copy_one(al, 0,get_addr((struct sockaddr*)&sin)); address_list_release (al); - - sin.sin_family = AF_INET; - sin.sin_port = 0; FREE_MAYBE (*target); Only in wget-1.8.1_ipv6/src: init.o Only in wget-1.8.1_ipv6/src: log.o Only in wget-1.8.1_ipv6/src: main.o Only in wget-1.8.1_ipv6/src: netrc.o diff -ubr wget-1.8.1/src/options.h wget-1.8.1_ipv6/src/options.h --- wget-1.8.1/src/options.h Fri Nov 30 07:39:08 2001 +++ wget-1.8.1_ipv6/src/options.h Tue Jan 15 01:05:44 2002 @@ -19,6 +19,7 @@ /* Needed for FDP. */ #include <stdio.h> +#include "host.h" struct options { @@ -153,7 +154,7 @@ int page_requisites; /* Whether we need to download all files necessary to display a page properly. */ - struct sockaddr_in *bind_address; /* What local IP address to bind to. */ + SOCKADDR_IN *bind_address; /* What local IP address to bind to. */ #ifdef HAVE_SSL char *sslcertfile; /* external client cert to use. */ Only in wget-1.8.1_ipv6/src: progress.o Only in wget-1.8.1_ipv6/src: rbuf.o Only in wget-1.8.1_ipv6/src: recur.o Only in wget-1.8.1_ipv6/src: res.o Only in wget-1.8.1_ipv6/src: retr.o Only in wget-1.8.1_ipv6/src: safe-ctype.o Only in wget-1.8.1_ipv6/src: snprintf.o Only in wget-1.8.1_ipv6/src: url.o Only in wget-1.8.1_ipv6/src: utils.o Only in wget-1.8.1_ipv6/src: version.o Only in wget-1.8.1_ipv6/src: wget
smime.p7s
Description: S/MIME Cryptographic Signature