]> git.pld-linux.org Git - packages/snarf.git/blame - snarf-ipv6.patch
- perl -pi -e "s/^automake -a -c$/automake -a -c -f/"
[packages/snarf.git] / snarf-ipv6.patch
CommitLineData
dafb3f33
MM
1diff -ur snarf-7.0/ftp.c snarf-7.0-/ftp.c
2--- snarf-7.0/ftp.c Wed Aug 9 01:27:24 2000
3+++ snarf-7.0-/ftp.c Wed Jun 13 19:38:51 2001
4@@ -28,6 +28,8 @@
5 #include "ftp.h"
6 #include "options.h"
7
8+extern int tcp_v6;
9+
10 void
11 close_quit(int sock)
12 {
13@@ -166,24 +168,37 @@
14 {
15 unsigned char *addr;
16 struct sockaddr_in sa;
17- int sock;
18+ int sock = 0;
19 int x;
20 char *line, *orig_line;
21
22- send_control(control, "PASV\r\n", NULL);
23+ send_control(control, tcp_v6 ? "EPSV\r\n" : "PASV\r\n", NULL);
24
25 if( !((line = get_line(rsrc, control)) &&
26- check_numeric("227", line)) ) {
27+ check_numeric(tcp_v6 ? "229" : "227", line)) ) {
28 safe_free(line);
29 return 0;
30 }
31
32 orig_line = line;
33-
34+
35 if( strlen(line) < 4 ) {
36 safe_free(line);
37 return 0;
38 }
39+
40+ if (tcp_v6) {
41+ line += 4;
42+ while (*line && *line != '(')
43+ line++;
44+ if (*line == 0 || *++line == 0)
45+ goto oops;
46+ if (line[1] != line[0] || line[2] != line[0])
47+ goto oops;
48+ sock = tcp_connect(rsrc->url->host, atoi(line+3));
49+ goto oops;
50+ }
51+
52
53 if( !(sock = sock_init(&sa, control)) )
54 return -1;
55@@ -217,6 +232,7 @@
56 return -1;
57 }
58
59+oops:
60 safe_free(orig_line);
61 return sock;
62 }
63diff -ur snarf-7.0/url.c snarf-7.0-/url.c
64--- snarf-7.0/url.c Mon Nov 16 02:29:44 1998
65+++ snarf-7.0-/url.c Thu Jun 14 12:38:24 2001
66@@ -153,10 +153,24 @@
67 get_hostname(char *url, Url *u)
68 {
69 char *hostname;
70- int i;
71+ int i, n;
72
73- /* skip to end, slash, or port colon */
74- for( i = 0; url[i] && url[i] != '/' && url[i] != ':'; i++ );
75+#define IPV6_PORT_CHAR '#'
76+
77+ /* check if it can be a v6 address */
78+ n = 0;
79+ for (i = 0; url[i] && url[i] != '/'; i++)
80+ if (url[i] == ':')
81+ n++;
82+ if (n >= 2) {
83+ /* we got ipv6 address */
84+ n = IPV6_PORT_CHAR;
85+ } else {
86+ n = ':';
87+ }
88+
89+ /* skip to end, slash, or port colon */
90+ for( i = 0; url[i] && url[i] != '/' && url[i] != n; i++ );
91
92 hostname = malloc(i + 1);
93
94@@ -165,7 +179,7 @@
95 hostname[i] = '\0';
96
97 /* if there's a port */
98- if(url[i] == ':')
99+ if(url[i] == n)
100 url += i + 1;
101 else
102 url += i;
103diff -ur snarf-7.0/util.c snarf-7.0-/util.c
104--- snarf-7.0/util.c Wed Aug 9 02:12:39 2000
105+++ snarf-7.0-/util.c Thu Jun 14 13:05:09 2001
106@@ -498,34 +498,55 @@
107 }
108 }
109
30145ddd 110+#if defined(__UCLIBC__) && !defined(__UCLIBC_HAS_IPV6__)
dafb3f33
MM
111+#define gethostbyname2(host,af) gethostbyname(host)
112+#endif
113+
114+int tcp_v6;
115
116 int
117 tcp_connect(char *remote_host, int port)
118 {
119 struct hostent *host;
120 struct sockaddr_in sa;
121+ struct sockaddr_in6 sa6;
122 int sock_fd;
123
124- if((host = (struct hostent *)gethostbyname(remote_host)) == NULL) {
125+ if((host = (struct hostent *)gethostbyname2(remote_host, AF_INET)) == NULL &&
126+ (host = (struct hostent *)gethostbyname2(remote_host, AF_INET6)) == NULL) {
127 herror(remote_host);
128 return 0;
129 }
130
131+ tcp_v6 = host->h_length == sizeof(sa6.sin6_addr);
132+
133 /* get the socket */
134- if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
135+ if((sock_fd = socket(tcp_v6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0)) < 0) {
136 perror("socket");
137 return 0;
138 }
139
140- /* connect the socket, filling in the important stuff */
141- sa.sin_family = AF_INET;
142- sa.sin_port = htons(port);
143- memcpy(&sa.sin_addr, host->h_addr,host->h_length);
144-
145- if(connect(sock_fd, (struct sockaddr *)&sa, sizeof(sa)) < 0){
146- perror(remote_host);
147- return 0;
148- }
149+ if (tcp_v6) {
150+ /* connect the socket, filling in the important stuff */
151+ sa6.sin6_family = AF_INET6;
152+ sa6.sin6_port = htons(port);
153+ memcpy(&sa6.sin6_addr, host->h_addr, sizeof(sa6.sin6_addr));
154+
155+ if(connect(sock_fd, (struct sockaddr *)&sa6, sizeof(sa6)) < 0){
156+ perror(remote_host);
157+ return 0;
158+ }
159+ } else {
160+ /* connect the socket, filling in the important stuff */
161+ sa.sin_family = AF_INET;
162+ sa.sin_port = htons(port);
163+ memcpy(&sa.sin_addr, host->h_addr,sizeof(sa.sin_addr));
164+
165+ if(connect(sock_fd, (struct sockaddr *)&sa, sizeof(sa)) < 0){
166+ perror(remote_host);
167+ return 0;
168+ }
169+ }
170
171 return sock_fd;
172 }
This page took 0.4302 seconds and 4 git commands to generate.