1 diff -ubr wget-1.8.1/src/connect.c wget-1.8.1_ipv6/src/connect.c
2 --- wget-1.8.1/src/connect.c Tue Nov 27 14:55:40 2001
3 +++ wget-1.8.1_ipv6/src/connect.c Tue Jan 15 01:09:23 2002
10 /* Variables shared by bindport and acceptport: */
11 static int msock = -1;
12 static struct sockaddr *addr;
15 connect_to_one (const unsigned char *addr, unsigned short port, int silent)
17 - struct sockaddr_in sock_name;
18 + SOCKADDR_IN sock_name;
21 /* Set port and protocol */
22 - sock_name.sin_family = AF_INET;
24 + sock_name.sin6_family = family;
25 + sock_name.sin6_port = htons (port);
26 + memcpy ((unsigned char *)&sock_name.sin6_addr, addr, sizeof(ip_address));
28 + sock_name.sin_family = family;
29 sock_name.sin_port = htons (port);
30 - memcpy ((unsigned char *)&sock_name.sin_addr, addr, 4);
31 + memcpy ((unsigned char *)&sock_name.sin_addr, addr, sizeof(ip_address));
39 /* Make an internet socket, stream type. */
40 - sock = socket (AF_INET, SOCK_STREAM, 0);
41 + sock = socket (family, SOCK_STREAM, 0);
46 address_list_get_bounds (al, &start, &end);
47 for (i = start; i < end; i++)
49 - unsigned char addr[4];
52 address_list_copy_one (al, i, addr);
55 bindport (unsigned short *port)
58 - static struct sockaddr_in srv;
59 + static SOCKADDR_IN srv={0};
62 addr = (struct sockaddr *) &srv;
63 - if ((msock = socket (AF_INET, SOCK_STREAM, 0)) < 0)
64 + if ((msock = socket (family, SOCK_STREAM, 0)) < 0)
66 if (setsockopt (msock, SOL_SOCKET, SO_REUSEADDR,
67 (char *)&optval, sizeof (optval)) < 0)
70 if (opt.bind_address == NULL)
72 - srv.sin_family = AF_INET;
74 + srv.sin6_family = family;
76 + srv.sin_family = family;
77 srv.sin_addr.s_addr = htonl (INADDR_ANY);
81 srv = *opt.bind_address;
84 + srv.sin6_port = htons (*port);
86 srv.sin_port = htons (*port);
87 - if (bind (msock, addr, sizeof (struct sockaddr_in)) < 0)
89 + if (bind (msock, addr, sizeof (SOCKADDR_IN)) < 0)
94 /* #### addrlen should be a 32-bit type, which int is not
95 guaranteed to be. Oh, and don't try to make it a size_t,
96 because that can be 64-bit. */
97 - int addrlen = sizeof (struct sockaddr_in);
98 + int addrlen = sizeof (SOCKADDR_IN);
99 if (getsockname (msock, addr, &addrlen) < 0)
106 + *port = ntohs (srv.sin6_port);
108 *port = ntohs (srv.sin_port);
111 if (listen (msock, 1) < 0)
115 acceptport (int *sock)
117 - int addrlen = sizeof (struct sockaddr_in);
118 + int addrlen = sizeof (SOCKADDR_IN);
121 if (select_fd (msock, opt.timeout, 0) <= 0)
126 - static unsigned char res[4];
127 - struct sockaddr_in mysrv;
128 + static ip_address res;
130 struct sockaddr *myaddr;
131 int addrlen = sizeof (mysrv); /* see bindport() for discussion of
134 myaddr = (struct sockaddr *) (&mysrv);
135 if (getsockname (fd, myaddr, (int *)&addrlen) < 0)
137 - memcpy (res, &mysrv.sin_addr, 4);
139 + memcpy (res, &mysrv.sin6_addr, sizeof(ip_address));
141 + memcpy (res, &mysrv.sin_addr, sizeof(ip_address));
146 diff -ubr wget-1.8.1/src/host.c wget-1.8.1_ipv6/src/host.c
147 --- wget-1.8.1/src/host.c Tue Dec 11 08:32:57 2001
148 +++ wget-1.8.1_ipv6/src/host.c Tue Jan 15 01:14:05 2002
150 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
161 -/* An IPv4 address is simply a 4-byte quantity. */
162 -typedef unsigned char ipv4_address[4];
164 +int family = AF_INET6;
166 +int family = AF_INET;
171 /* Mapping between known hosts and to lists of their addresses. */
175 struct address_list {
176 int count; /* number of adrresses */
177 - ipv4_address *addresses; /* pointer to the string of addresses */
178 + ip_address *addresses; /* pointer to the string of addresses */
180 int faulty; /* number of addresses known not to
183 unsigned char *ip_store)
185 assert (index >= al->faulty && index < al->count);
186 - memcpy (ip_store, al->addresses + index, sizeof (ipv4_address));
187 + memcpy (ip_store, al->addresses + index, sizeof (ip_address));
190 /* Check whether two address lists have all their IPs in common. */
192 if (al1->count != al2->count)
194 return 0 == memcmp (al1->addresses, al2->addresses,
195 - al1->count * sizeof (ipv4_address));
196 + al1->count * sizeof (ip_address));
199 /* Mark the INDEXth element of AL as faulty, so that the next time
200 @@ -152,11 +158,11 @@
204 - al->addresses = xmalloc (count * sizeof (ipv4_address));
205 + al->addresses = xmalloc (count * sizeof (ip_address));
208 for (i = 0; i < count; i++)
209 - memcpy (al->addresses + i, h_addr_list[i], sizeof (ipv4_address));
210 + memcpy (al->addresses + i, h_addr_list[i], sizeof (ip_address));
215 struct address_list *al = xmalloc (sizeof (struct address_list));
218 - al->addresses = xmalloc (sizeof (ipv4_address));
219 + al->addresses = xmalloc (sizeof (ip_address));
221 - memcpy (al->addresses, addr, sizeof (ipv4_address));
222 + memcpy (al->addresses, addr, sizeof (ip_address));
226 @@ -233,13 +239,12 @@
227 lookup_host (const char *host, int silent)
229 struct address_list *al = NULL;
230 - unsigned long addr;
232 struct hostent *hptr;
234 - /* If the address is of the form d.d.d.d, no further lookup is
236 - addr = (unsigned long)inet_addr (host);
237 - if ((int)addr != -1)
238 + /* If the address is of the form that if valid for <family>,
239 + no further lookup is needed. */
240 + if(0>=inet_pton(family,host,addr))
242 /* ADDR is defined to be in network byte order, which is what
243 this returns, so we can just copy it to STORE_IP. However,
244 @@ -248,15 +253,15 @@
245 we copy the correct four bytes. */
247 #ifdef WORDS_BIGENDIAN
248 - offset = sizeof (unsigned long) - sizeof (ipv4_address);
249 + offset = sizeof (unsigned long) - sizeof (ip_address);
253 return address_list_new_one ((char *)&addr + offset);
256 - /* By now we know that the host name we got is not of the form
257 - d.d.d.d. Try to find it in our cache of host names. */
258 + /* By now we know that the host name we got is not numerialcal represantation
259 + for <family>. Try to find it in our cache of host names. */
260 if (host_name_addresses_map)
261 al = hash_table_get (host_name_addresses_map, host);
265 logprintf (LOG_VERBOSE, _("Resolving %s... "), host);
267 - /* Look up the host using gethostbyname(). */
268 - hptr = gethostbyname (host);
269 + /* Look up the host using getipnodebyname(). */
270 + hptr = gethostbyname2(host, family);
274 diff -ubr wget-1.8.1/src/host.h wget-1.8.1_ipv6/src/host.h
275 --- wget-1.8.1/src/host.h Tue Dec 11 08:32:58 2001
276 +++ wget-1.8.1_ipv6/src/host.h Tue Jan 15 01:37:06 2002
279 void host_cleanup PARAMS ((void));
284 + IPv6 support added by Thomas Lussnig <lussnig@bewegungsmelder.de>
285 + Date: 15.01.2001 02:36:05
286 + If there are mistakes please inform me, but i will not work till the
292 +/* An IPv6 address is simply a 16-byte quantity. */
293 +typedef unsigned char ip_address[16];
294 +typedef struct sockaddr_in6 SOCKADDR_IN;
296 +/* An IPv4 address is simply a 4-byte quantity. */
297 +typedef unsigned char ip_address[4];
298 +typedef struct sockaddr_in SOCKADDR_IN;
300 +extern int family; /* defined in host.c */
304 Only in wget-1.8.1_ipv6/src: host.h~
305 diff -ubr wget-1.8.1/src/init.c wget-1.8.1_ipv6/src/init.c
306 --- wget-1.8.1/src/init.c Thu Dec 13 19:19:03 2001
307 +++ wget-1.8.1_ipv6/src/init.c Tue Jan 15 01:34:06 2002
309 cmd_address (const char *com, const char *val, void *closure)
311 struct address_list *al;
312 - struct sockaddr_in sin;
313 - struct sockaddr_in **target = (struct sockaddr_in **)closure;
315 + SOCKADDR_IN **target = (SOCKADDR_IN **)closure;
317 memset (&sin, '\0', sizeof (sin));
319 @@ -538,11 +538,16 @@
320 exec_name, com, val);
324 + sin.sin6_family = family;
326 + address_list_copy_one (al, 0, (unsigned char *)&sin.sin6_addr);
328 + sin.sin_family = family;
330 address_list_copy_one (al, 0, (unsigned char *)&sin.sin_addr);
332 address_list_release (al);
334 - sin.sin_family = AF_INET;
337 FREE_MAYBE (*target);
339 diff -ubr wget-1.8.1/src/options.h wget-1.8.1_ipv6/src/options.h
340 --- wget-1.8.1/src/options.h Fri Nov 30 07:39:08 2001
341 +++ wget-1.8.1_ipv6/src/options.h Tue Jan 15 01:05:44 2002
344 /* Needed for FDP. */
351 int page_requisites; /* Whether we need to download all files
352 necessary to display a page properly. */
354 - struct sockaddr_in *bind_address; /* What local IP address to bind to. */
355 + SOCKADDR_IN *bind_address; /* What local IP address to bind to. */
358 char *sslcertfile; /* external client cert to use. */