]> sjero.net Git - dccp2tcp/blobdiff - dccp2tcp.c
Ignore directory of CCID 2 captures
[dccp2tcp] / dccp2tcp.c
index eb913bf9dc23652d84b97774cda2cd5e61dd7a90..651d98bcce0965012b317e0f7e631fb516d4d6f2 100644 (file)
@@ -124,6 +124,7 @@ int main(int argc, char *argv[])
        }
 
        /*process packets*/
+       chead=NULL;
        u_char *user=(u_char*)out;
        pcap_loop(in, -1, handle_packet, user); 
        
@@ -198,6 +199,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
        /*Safety checks*/
        if(!new || !old || !new->data || !old->data || !new->h || !old->h){
                dbgprintf(0,"Error:  Convert Packet Function given bad data!\n");
+               exit(1);
                return 0;
        }
        if(old->length < sizeof(struct dccp_hdr) || new->length < sizeof(struct dccp_hdr)){
@@ -207,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));
@@ -215,11 +216,11 @@ int convert_packet(struct packet *new, const struct const_packet* old)
        dbgprintf(2,"Sequence Number: %llu\n", (unsigned long long)(((unsigned long)ntohs(dccph->dccph_seq)<<32) + ntohl(dccphex->dccph_seq_low)));
 
        /*Get Hosts*/
-       if(get_host(new->src_id, new->dest_id, dccph->dccph_sport, dccph->dccph_dport, h1, h2)){
+       if(get_host(new->src_id, new->dest_id, dccph->dccph_sport, dccph->dccph_dport, &h1, &h2)){
                dbgprintf(0,"Error: Can't Get Hosts!\n");
                return 0;
        }
-       if(!h1 || !h2){
+       if(h1==NULL || h2==NULL){
                dbgprintf(0, "Error: Can't Get Hosts!\n");
                return 0;
        }
@@ -256,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;
@@ -282,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++;
@@ -310,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) );
                        }
                }
 
@@ -343,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) );
                        }
                }
 
@@ -375,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) );
                        }
                }
 
@@ -404,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) );
                        }
                }
 
@@ -432,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) );
                        }
                }
 
@@ -460,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));
                        }
                }
 
@@ -532,8 +535,8 @@ unsigned int interp_ack_vect(u_char* hdr)
                                        bp+= (*cur & 0x3F)+1;
                                }
 
-                               if(((*cur& 0xF0)!= 0xC0) && ((*cur& 0xF0)!= 0x00) && ((*cur& 0xF0)!= 0x40)){
-                                       dbgprintf(1, "Warning: Invalid Ack Vector!! (Linux will handle poorly!)\n");
+                               if(((*cur& 0xC0)!= 0xC0) && ((*cur& 0xC0)!= 0x00) && ((*cur& 0xC0)!= 0x40)){
+                                       dbgprintf(1, "Warning: Invalid Ack Vector!! (Linux will handle poorly!) -- %X\n", *cur);
                                }
                                tmp--;
                                cur++;
@@ -582,6 +585,11 @@ u_int32_t add_new_seq(struct host *seq, __be32 num, int size, enum dccp_pkt_type
                exit(1);
        }
        
+       if(seq->table==NULL){
+               dbgprintf(1, "Warning: Connection uninitialized\n");
+               return initialize_seq(seq, 0, num);
+       }
+
        /*account for missing packets*/
        while(seq->table[seq->cur].old +1 < num && seq->table[seq->cur].old +1 > 0){
                prev=seq->cur;
@@ -624,6 +632,11 @@ u_int32_t convert_ack(struct host *seq, __be32 num)
                exit(1);
        }
 
+       if(seq->table==NULL){
+               dbgprintf(1, "Warning: Connection uninitialized\n");
+               initialize_seq(seq, 0, num);
+       }
+
        /*loop through table looking for the DCCP ack number*/
        for(int i=0; i < seq->size; i++){
                if(seq->table[i].old==num){
@@ -644,6 +657,11 @@ int acked_packet_size(struct host *seq, __be32 num)
                exit(1);
        }
 
+       if(seq->table==NULL){
+               dbgprintf(1, "Warning: Connection uninitialized\n");
+               initialize_seq(seq, 0, num);
+       }
+
        /*loop through table looking for the DCCP ack number*/
        for(int i=0; i < seq->size; i++){
                if(seq->table[i].old==num){