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 |
… | |
… | |
401 | // 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. |
402 | if (!w_pkt) |
401 | if (!w_pkt) |
403 | { |
402 | { |
404 | // 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 |
405 | // 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) |
406 | setsockopt (fd, SOL_IP, IP_TOS, &tos, sizeof tos); |
406 | setsockopt (fd, SOL_IP, IP_TOS, &tos, sizeof tos); |
|
|
407 | #endif |
407 | |
408 | |
408 | w_pkt = pkt; |
409 | w_pkt = pkt; |
409 | w_ofs = 0; |
410 | w_ofs = 0; |
410 | w_len = pkt->len + 2; // length + size header |
411 | w_len = pkt->len + 2; // length + size header |
411 | |
412 | |