]> git.sesse.net Git - greproxy/blobdiff - greprotocol.cpp
Make GREProtocol no longer make its own sequence numbers.
[greproxy] / greprotocol.cpp
index b826a521d7828c4e18421250f07c8a3ee8d09d9d..5fd4e4b8262a69be62098fb41524a2b228b7602f 100644 (file)
@@ -1,9 +1,11 @@
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 
 #include "greprotocol.h"
-#include "reorderer.h"
 
 using namespace std;
 
@@ -22,7 +24,6 @@ struct gre_header {
 
 
 GREProtocol::GREProtocol(const in6_addr &src, const in6_addr &dst)
-       : seq(0)
 {
        memset(&dstaddr, 0, sizeof(dstaddr));
        dstaddr.sin6_family = AF_INET6;
@@ -44,7 +45,7 @@ GREProtocol::GREProtocol(const in6_addr &src, const in6_addr &dst)
        }
 }
 
-void GREProtocol::send_packet(uint16_t proto, const string &data)
+void GREProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
 {
        char buf[4096];
        gre_header *gre = (gre_header *)buf;
@@ -55,7 +56,7 @@ void GREProtocol::send_packet(uint16_t proto, const string &data)
        gre->protocol_type = htons(proto);
 
        char *ptr = buf + sizeof(*gre);
-       int seq_be = htonl(seq++);
+       int seq_be = htonl(incoming_seq);
        memcpy(ptr, &seq_be, sizeof(seq_be));
        ptr += sizeof(seq_be);
 
@@ -72,7 +73,7 @@ int GREProtocol::fd() const
        return sock;
 }
 
-void GREProtocol::read_packet(Reorderer *sender)
+void GREProtocol::read_packet(Sender *sender)
 {
        struct sockaddr_storage addr;
        socklen_t addrlen = sizeof(addr);
@@ -107,6 +108,6 @@ void GREProtocol::read_packet(Reorderer *sender)
 
        //printf("gre packet: proto=%x\n", ntohs(gre->protocol_type));
 
-       sender->handle_packet(ntohs(gre->protocol_type), string(ptr, buf + ret), seq);
+       sender->send_packet(ntohs(gre->protocol_type), string(ptr, buf + ret), seq);
 }