Commit 92bbbbbd authored by nanamicat's avatar nanamicat

fix

parent bccd05d2
...@@ -10,12 +10,16 @@ ...@@ -10,12 +10,16 @@
#include <unistd.h> #include <unistd.h>
#include <arpa/inet.h> #include <arpa/inet.h>
in_addr_t remote;
// internet -> tun // internet -> tun
void inbound(int raw, int tun) { void inbound(int raw, int tun) {
char buf[ETH_DATA_LEN]; char buf[ETH_DATA_LEN];
sockaddr_in addr{AF_INET}; sockaddr_in addr{AF_INET};
socklen_t addrlen;
size_t nread; 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) { if (write(tun, buf, nread) < 0) {
perror("outbound write"); perror("outbound write");
} }
...@@ -23,7 +27,6 @@ void inbound(int raw, int tun) { ...@@ -23,7 +27,6 @@ void inbound(int raw, int tun) {
perror("outbound read"); perror("outbound read");
} }
in_addr_t remote;
// tun -> internet // tun -> internet
void outbound(int raw, int tun) { void outbound(int raw, int tun) {
char buf[ETH_DATA_LEN]; char buf[ETH_DATA_LEN];
...@@ -38,7 +41,7 @@ void outbound(int raw, int tun) { ...@@ -38,7 +41,7 @@ void outbound(int raw, int tun) {
perror("inbound read"); perror("inbound read");
} }
int main(int argc, char* argv[]) { int main(int argc, char *argv[]) {
ifreq ifr{}; ifreq ifr{};
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; 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