Mercurial > pidgin.yaz
comparison src/proxy.c @ 664:5cb19972df52
[gaim-migrate @ 674]
socks4 works now :-P
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 11 Aug 2000 00:21:36 +0000 |
parents | b402a23f35df |
children | 9e51c1a4abba |
comparison
equal
deleted
inserted
replaced
663:18e147714c4b | 664:5cb19972df52 |
---|---|
175 free(inputline); | 175 free(inputline); |
176 } | 176 } |
177 | 177 |
178 return ret; | 178 return ret; |
179 break; | 179 break; |
180 case PROXY_SOCKS4: /* Socks v4 proxy (? I'm not a proxy hacker) */ | 180 case PROXY_SOCKS4: |
181 /* this is going to be a cross between the HTTP proxy code | 181 /* code shamelessly stolen from everybuddy */ |
182 * above and the TiK proxy code, translated from tcl->C */ | 182 { |
183 { | 183 struct sockaddr_in sa; |
184 struct hostent *hostinfo; | 184 unsigned char packet[12]; |
185 unsigned short shortport = proxy_port; | 185 struct hostent *hp; |
186 | 186 |
187 memset(&name, 0, sizeof (name)); | 187 debug_print("connecting with socks4.\n"); |
188 name.sin_family = AF_INET; | 188 |
189 name.sin_port = htons (shortport); | 189 if (!(hp = gethostbyname(proxy_host))) |
190 hostinfo = gethostbyname (proxy_host); | 190 return -1; |
191 if (hostinfo == NULL) { | 191 |
192 fprintf (stderr, "Unknown host %s.\n", proxy_host); | 192 bzero(&sa, sizeof(sa)); |
193 return (-1); | 193 sa.sin_family = AF_INET; |
194 sa.sin_port = htons(proxy_port); | |
195 bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length); | |
196 | |
197 if (connect(sockfd, (struct sockaddr *) &sa, sizeof (sa)) != -1) { | |
198 unsigned short realport = htons(((struct sockaddr_in *)serv_addr)->sin_port); | |
199 | |
200 if (!(hp = gethostbyname(proxy_realhost))) | |
201 return -1; | |
202 packet[0] = 4; | |
203 packet[1] = 1; | |
204 packet[2] = (((unsigned short) realport) >> 8); | |
205 packet[3] = (((unsigned short) realport) & 0xff); | |
206 packet[4] = (unsigned char) (hp->h_addr_list[0])[0]; | |
207 packet[5] = (unsigned char) (hp->h_addr_list[0])[1]; | |
208 packet[6] = (unsigned char) (hp->h_addr_list[0])[2]; | |
209 packet[7] = (unsigned char) (hp->h_addr_list[0])[3]; | |
210 packet[8] = 0; | |
211 if (write(sockfd, packet, 9) == 9) { | |
212 bzero(packet, sizeof(packet)); | |
213 if (read(sockfd, packet, 9) >= 4 && packet[1] == 90) | |
214 return 0; | |
194 } | 215 } |
195 name.sin_addr = *(struct in_addr *) hostinfo->h_addr; | 216 close(sockfd); |
196 } | 217 } |
197 sprintf(debug_buff,"Trying to connect ...\n"); | 218 return -1; |
198 debug_print(debug_buff); | 219 } |
199 if ((ret = connect(sockfd,(struct sockaddr *)&name,sizeof(name)))<0) | 220 break; |
200 return(ret); | |
201 | |
202 /* here's where it's no longer http proxy and is now tik */ | |
203 { | |
204 char cmd[80]; | |
205 char *inputline; | |
206 unsigned short realport=((struct sockaddr_in *)serv_addr)->sin_port; | |
207 unsigned long realhost=((struct sockaddr_in *)serv_addr)->sin_addr.s_addr; | |
208 | |
209 cmd[0] = 4; cmd[0] = 1; | |
210 memcpy(cmd + 2, &realport, 2); | |
211 memcpy(cmd + 4, &realhost, 4); | |
212 cmd[8] = 0; | |
213 if (send(sockfd,cmd,8,0)<0) | |
214 return(-1); | |
215 if (proxy_recv_line(sockfd,&inputline) < 0) { | |
216 return(-1); | |
217 } | |
218 if (inputline[1] != 90) { | |
219 sprintf(debug_buff, "request failed: %d\n", | |
220 inputline[1]); | |
221 debug_print(debug_buff); | |
222 if (inputline[1] == 91) | |
223 do_error_dialog("The SOCKS proxy denied" | |
224 "your request.", | |
225 "Gaim - Proxy Error"); | |
226 else | |
227 do_error_dialog("Unknown SOCKS error.", | |
228 "Gaim - Proxy Error"); | |
229 return -1; | |
230 } | |
231 } | |
232 return ret; | |
233 break; | |
234 case PROXY_SOCKS5: | 221 case PROXY_SOCKS5: |
235 return -1; | 222 return -1; |
236 break; | 223 break; |
237 default: | 224 default: |
238 fprintf(stderr,"Unknown proxy type : %d.\n",proxy_type); | 225 fprintf(stderr,"Unknown proxy type : %d.\n",proxy_type); |