]> git.sesse.net Git - greproxy/blobdiff - tunprotocol.cpp
Merge branch 'master' of /srv/git.sesse.net/www/greproxy
[greproxy] / tunprotocol.cpp
index cc1065169b2235dff022abe2ba883829be0e0a25..f455e20ce7aeed31b4218619a8846c309e3bc09f 100644 (file)
@@ -1,9 +1,10 @@
-#include <string.h>
 #include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
 #include <linux/if.h>
 #include <linux/if_tun.h>
 
@@ -38,10 +39,10 @@ int tun_open(const char *name) {
 }  // namespace
 
 TUNProtocol::TUNProtocol(const char *devname)
-       : tunfd(tun_open(devname)) {
+       : tunfd(tun_open(devname)), seq(0) {
 }
 
-void TUNProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
+void TUNProtocol::send_packet(uint16_t proto, const string &data, uint32_t incoming_seq)
 {
        char buf[4096];
 
@@ -61,6 +62,8 @@ void TUNProtocol::send_packet(uint16_t proto, const string &data, int incoming_s
                perror("write");
                return;
        }
+
+       ++sent_packets;
 }
 
 int TUNProtocol::fd() const
@@ -68,7 +71,7 @@ int TUNProtocol::fd() const
        return tunfd;
 }
 
-void TUNProtocol::read_packet(Protocol *sender)
+void TUNProtocol::read_packet(Sender *sender)
 {
        char buf[4096];
        int ret = read(tunfd, buf, sizeof(buf));
@@ -88,6 +91,7 @@ void TUNProtocol::read_packet(Protocol *sender)
        ptr += 2;
        //fprintf(stderr, "tun packet: flags=%x proto=%x len=%d\n",
        //      flags, proto, ret - 4);
-       sender->send_packet(proto, string(ptr, buf + ret), -1);
+       ++received_packets;
+       sender->send_packet(proto, string(ptr, buf + ret), seq++);
 }