]> sjero.net Git - dccp2tcp/commitdiff
IP->Total_Length encapsulation fix and DCCP options fix
authorSamuel Jero <sj323707@ohio.edu>
Wed, 16 Nov 2011 23:05:52 +0000 (18:05 -0500)
committerSamuel Jero <sj323707@ohio.edu>
Wed, 16 Nov 2011 23:05:52 +0000 (18:05 -0500)
dccp2tcp.c
encap.c

index 62b0910f7bb65e2beabec1de7109ba0967922449..651d98bcce0965012b317e0f7e631fb516d4d6f2 100644 (file)
@@ -209,7 +209,6 @@ int convert_packet(struct packet *new, const struct const_packet* old)
 
        /*cast header pointers*/
        tcph=(struct tcphdr*)new->data;
-       tcpopt=new->data + sizeof(struct tcphdr);
        dccph=(struct dccp_hdr*)old->data;
        dccphex=(struct dccp_hdr_ext*)(old->data+sizeof(struct dccp_hdr));
        dccphack=(struct dccp_hdr_ack_bits*)(old->data+ sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext));
@@ -258,6 +257,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
 
                        /* add Sack-permitted option, if relevant*/
                        if(sack){
+                               tcpopt=(u_char*)(new->data + tcph->doff*4);
                                *tcpopt=4;
                                tcpopt++;
                                *tcpopt=2;
@@ -284,6 +284,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
 
                        /* add Sack-permitted option, if relevant*/
                        if(sack){
+                               tcpopt=(u_char*)(new->data + tcph->doff*4);
                                *tcpopt=4;
                                *(tcpopt+1)=2;
                                tcph->doff++;
@@ -312,7 +313,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
                }
                if(sack){
                        if(sack!=2 || interp_ack_vect((u_char*)dccph)){
-                               ack_vect2sack(h2, tcph, tcpopt, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
+                               ack_vect2sack(h2, tcph, (u_char*)tcph + tcph->doff*4, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
                        }
                }
 
@@ -345,7 +346,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
                }
                if(sack){
                        if(sack!=2 || interp_ack_vect((u_char*)dccph)){
-                               ack_vect2sack(h2, tcph, tcpopt, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
+                               ack_vect2sack(h2, tcph, (u_char*)tcph + tcph->doff*4, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
                        }
                }
 
@@ -377,7 +378,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
                }
                if(sack){
                        if(sack!=2 || interp_ack_vect((u_char*)dccph)){
-                               ack_vect2sack(h2, tcph, tcpopt, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
+                               ack_vect2sack(h2, tcph, (u_char*)tcph + tcph->doff*4, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
                        }
                }
 
@@ -406,7 +407,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
                }
                if(sack){
                        if(sack!=2 || interp_ack_vect((u_char*)dccph)){
-                               ack_vect2sack(h2, tcph, tcpopt, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
+                               ack_vect2sack(h2, tcph, (u_char*)tcph + tcph->doff*4, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
                        }
                }
 
@@ -434,7 +435,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
                }
                if(sack){
                        if(sack!=2 || interp_ack_vect((u_char*)dccph)){
-                               ack_vect2sack(h2, tcph, tcpopt, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
+                               ack_vect2sack(h2, tcph, (u_char*)tcph + tcph->doff*4, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low) );
                        }
                }
 
@@ -462,7 +463,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
                }
                if(sack){
                        if(sack!=2 || interp_ack_vect((u_char*)dccph)){
-                               ack_vect2sack(h2, tcph, tcpopt, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low));
+                               ack_vect2sack(h2, tcph, (u_char*)tcph + tcph->doff*4, (u_char*)dccph, ntohl(dccphack->dccph_ack_nr_low));
                        }
                }
 
diff --git a/encap.c b/encap.c
index beafa6814466b57b5887e13e445f9cae730bdcc9..71255ecaaf5070fe68cc8a1674de4e19cc8f44ab 100644 (file)
--- a/encap.c
+++ b/encap.c
@@ -74,12 +74,12 @@ int ethernet_encap(struct packet *new, const struct const_packet *old)
                nnew.data= new->data + sizeof(struct ether_header);
                nold.length= old->length - sizeof(struct ether_header);
                nnew.length= new->length - sizeof(struct ether_header);
+               nnew.h=new->h;
+               nold.h=old->h;
 
                /*Select Next Protocol*/
                switch(ntohs(ethh->ether_type)){
                        case ETHERTYPE_IP:
-                                       nnew.h=new->h;
-                                       nold.h=old->h;
                                        if(!ipv4_encap(&nnew, &nold)){
                                                        return 0;
                                        }
@@ -123,6 +123,8 @@ int ipv4_encap(struct packet *new, const struct const_packet *old)
                nnew.data= new->data +iph->ihl*4;
                nold.length= old->length -iph->ihl*4;
                nnew.length= new->length -iph->ihl*4;
+               nnew.h=new->h;
+               nold.h=old->h;
 
                /*Confirm that this is IPv4*/
                if(iph->version!=4){
@@ -134,8 +136,6 @@ int ipv4_encap(struct packet *new, const struct const_packet *old)
                switch(iph->protocol){
                        case 0x21:
                                        /*DCCP*/
-                                       nnew.h=new->h;
-                                       nold.h=old->h;
                                        nnew.src_id=iph->saddr;
                                        nnew.dest_id=iph->daddr;
                                        if(!convert_packet(&nnew, &nold)){
@@ -162,7 +162,7 @@ int ipv4_encap(struct packet *new, const struct const_packet *old)
                }
 
                /*Adjust IPv4 header to account for packet's total length*/
-               iph->tot_len=htons(nnew.length);
+               iph->tot_len=htons(new->length);
 return 1;
 }
 
@@ -194,6 +194,8 @@ int linux_cooked_encap(struct packet *new, const struct const_packet *old)
        nnew.data= new->data + sizeof(struct sll_header);
        nold.length= old->length - sizeof(struct sll_header);
        nnew.length= new->length- sizeof(struct sll_header);
+       nnew.h=new->h;
+       nold.h=old->h;
 
        /*Confirm that this is SLL*/
        if(ntohs(slh->sll_pkttype) > 4){
@@ -204,8 +206,6 @@ int linux_cooked_encap(struct packet *new, const struct const_packet *old)
        /*Select Next Protocol*/
        switch(ntohs(slh->sll_protocol)){
                case ETHERTYPE_IP:
-                               nnew.h=new->h;
-                               nold.h=old->h;
                                if(!ipv4_encap(&nnew, &nold)){
                                                return 0;
                                }