Commit 92bbbbbd authored by nanamicat's avatar nanamicat

fix

parent bccd05d2
......@@ -10,12 +10,16 @@
#include <unistd.h>
#include <arpa/inet.h>
in_addr_t remote;
// internet -> tun
void inbound(int raw, int tun) {
char buf[ETH_DATA_LEN];
sockaddr_in addr{AF_INET};
socklen_t addrlen;
size_t nread;
while ((nread = recvfrom(raw, buf, sizeof(buf), 0, (sockaddr *)&addr, nullptr)) >= 0) {
while ((nread = recvfrom(raw, buf, sizeof(buf), 0, (sockaddr *) &addr, &addrlen)) >= 0) {
std::cout << nread << std::endl;
if (write(tun, buf, nread) < 0) {
perror("outbound write");
}
......@@ -23,7 +27,6 @@ void inbound(int raw, int tun) {
perror("outbound read");
}
in_addr_t remote;
// tun -> internet
void outbound(int raw, int tun) {
char buf[ETH_DATA_LEN];
......@@ -31,14 +34,14 @@ void outbound(int raw, int tun) {
addr.sin_addr.s_addr = remote;
size_t nread;
while ((nread = read(tun, buf, sizeof(buf))) >= 0) {
if (sendto(raw, buf, nread, 0, (sockaddr *) &addr, sizeof(addr)) < 0) {
if (sendto(raw, buf, nread, 0, (sockaddr *) &addr, sizeof(addr)) < 0) {
perror("inbound write");
}
}
perror("inbound read");
}
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
ifreq ifr{};
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment