-#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>
} // 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)
+void TUNProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
{
char buf[4096];
perror("write");
return;
}
+
+ ++sent_packets;
}
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));
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));
+ ++received_packets;
+ sender->send_packet(proto, string(ptr, buf + ret), seq++);
}