1 | /* |
1 | /* |
2 | vpn_tcp.C -- handle the tcp part of the protocol. |
2 | vpn_tcp.C -- handle the tcp part of the protocol. |
|
|
3 | Copyright (C) 2003 Marc Lehmann <pcg@goof.com> |
3 | |
4 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
27 | |
28 | |
28 | #include <cstring> |
29 | #include <cstring> |
29 | |
30 | |
30 | #include <sys/types.h> |
31 | #include <sys/types.h> |
31 | #include <sys/socket.h> |
32 | #include <sys/socket.h> |
32 | #include <sys/poll.h> |
|
|
33 | #include <sys/wait.h> |
33 | #include <sys/wait.h> |
34 | #include <netinet/in.h> |
|
|
35 | #include <sys/uio.h> |
34 | #include <sys/uio.h> |
36 | #include <arpa/inet.h> |
|
|
37 | #include <errno.h> |
35 | #include <errno.h> |
38 | #include <time.h> |
36 | #include <time.h> |
39 | #include <unistd.h> |
37 | #include <unistd.h> |
|
|
38 | #include <fcntl.h> |
40 | |
39 | |
41 | #include <map> |
40 | #include <map> |
42 | #include <unistd.h> |
41 | |
43 | #include <fcntl.h> |
42 | #include "netcompat.h" |
44 | #include <sys/poll.h> |
|
|
45 | |
43 | |
46 | #include "vpn.h" |
44 | #include "vpn.h" |
47 | |
45 | |
48 | #if ENABLE_HTTP_PROXY |
46 | #if ENABLE_HTTP_PROXY |
49 | # include "conf.h" |
47 | # include "conf.h" |
… | |
… | |
169 | if (w_ofs < 2) |
167 | if (w_ofs < 2) |
170 | { |
168 | { |
171 | u16 plen = htons (w_pkt->len); |
169 | u16 plen = htons (w_pkt->len); |
172 | |
170 | |
173 | iovec vec[2]; |
171 | iovec vec[2]; |
|
|
172 | //TODO: char* is the right type? hardly... |
174 | vec[0].iov_base = ((u8 *)&plen) + w_ofs; |
173 | vec[0].iov_base = (char *)((u8 *)&plen) + w_ofs; |
175 | vec[0].iov_len = 2 - w_ofs; |
174 | vec[0].iov_len = 2 - w_ofs; |
176 | vec[1].iov_base = &((*w_pkt)[0]); |
175 | vec[1].iov_base = (char *)&((*w_pkt)[0]); |
177 | vec[1].iov_len = w_len - 2; |
176 | vec[1].iov_len = w_len - 2; |
178 | |
177 | |
179 | len = writev (fd, vec, 2); |
178 | len = writev (fd, vec, 2); |
180 | } |
179 | } |
181 | else |
180 | else |
… | |
… | |
320 | |
319 | |
321 | fcntl (fd, F_SETFL, O_NONBLOCK); |
320 | fcntl (fd, F_SETFL, O_NONBLOCK); |
322 | |
321 | |
323 | if (i < 12) |
322 | if (i < 12) |
324 | { |
323 | { |
325 | slog (L_ERR, _("unable to do proxy-forwarding, short response")); |
324 | slog (L_ERR, _("(%s): unable to do proxy-forwarding, short response"), |
|
|
325 | (const char *)si); |
326 | error (); |
326 | error (); |
327 | } |
327 | } |
328 | else if (r[0] != 'H' || r[1] != 'T' || r[2] != 'T' || r[3] != 'P' || r[4] != '/' |
328 | else if (r[0] != 'H' || r[1] != 'T' || r[2] != 'T' || r[3] != 'P' || r[4] != '/' |
329 | || r[5] != '1' // http-major |
329 | || r[5] != '1' // http-major |
330 | || r[9] != '2') // response |
330 | || r[9] != '2') // response |
331 | { |
331 | { |
332 | slog (L_ERR, _("malformed or unexpected proxy response (%.12s)"), r); |
332 | slog (L_ERR, _("(%s): malformed or unexpected proxy response (%.12s)"), |
|
|
333 | (const char *)si, r); |
333 | error (); |
334 | error (); |
334 | } |
335 | } |
335 | else |
336 | else |
336 | state = ESTABLISHED; |
337 | state = ESTABLISHED; |
337 | } |
338 | } |
… | |
… | |
399 | // right thing to do, not using tcp *is* the right thing to do. |
400 | // right thing to do, not using tcp *is* the right thing to do. |
400 | if (!w_pkt) |
401 | if (!w_pkt) |
401 | { |
402 | { |
402 | // how this maps to the underlying tcp packets we don't know |
403 | // how this maps to the underlying tcp packets we don't know |
403 | // and we don't care. at least we tried ;) |
404 | // and we don't care. at least we tried ;) |
|
|
405 | #if defined(SOL_IP) && defined(IP_TOS) |
404 | setsockopt (fd, SOL_IP, IP_TOS, &tos, sizeof tos); |
406 | setsockopt (fd, SOL_IP, IP_TOS, &tos, sizeof tos); |
|
|
407 | #endif |
405 | |
408 | |
406 | w_pkt = pkt; |
409 | w_pkt = pkt; |
407 | w_ofs = 0; |
410 | w_ofs = 0; |
408 | w_len = pkt->len + 2; // length + size header |
411 | w_len = pkt->len + 2; // length + size header |
409 | |
412 | |