X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=tunprotocol.cpp;h=f455e20ce7aeed31b4218619a8846c309e3bc09f;hb=HEAD;hp=b8b63a3736f02dfd1d5c84259a97050b59d1e70c;hpb=5b611332f020c9fc94b5992188dd0701fdf4f327;p=greproxy diff --git a/tunprotocol.cpp b/tunprotocol.cpp index b8b63a3..f455e20 100644 --- a/tunprotocol.cpp +++ b/tunprotocol.cpp @@ -1,9 +1,10 @@ -#include #include -#include -#include #include -#include +#include +#include +#include +#include +#include #include #include @@ -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) +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) 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)); + ++received_packets; + sender->send_packet(proto, string(ptr, buf + ret), seq++); }