]> sjero.net Git - dccp2tcp/commitdiff
Connection closing improvements and explicit cleanup code
authorSamuel Jero <sj323707@ohio.edu>
Sun, 27 Nov 2011 20:36:34 +0000 (15:36 -0500)
committerSamuel Jero <sj323707@ohio.edu>
Sun, 27 Nov 2011 20:36:34 +0000 (15:36 -0500)
connections.c
dccp2tcp.c
dccp2tcp.h

index b5eb11287c71bfea62b3d9fdc7437badd177f47b..b5d04ca4a9c9591e6ea6133607fb285d0f473da1 100644 (file)
@@ -25,12 +25,14 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
        /*Loop list looking for connection*/
        ptr=chead;
        while(ptr!=NULL){
-               if(ptr->A.id==src_id && ptr->A.port==src_port && ptr->A.state!=CLOSE){
+               if(ptr->A.id==src_id && ptr->A.port==src_port &&
+                               !(ptr->A.state==CLOSE && ptr->B.state==CLOSE)){
                        *fwd=&ptr->A;
                        *rev=&ptr->B;
                        return 0;
                }
-               if(ptr->B.id==src_id && ptr->B.port==src_port && ptr->B.state!=CLOSE){
+               if(ptr->B.id==src_id && ptr->B.port==src_port &&
+                               !(ptr->B.state==CLOSE && ptr->A.state==CLOSE)){
                        *fwd=&ptr->B;
                        *rev=&ptr->A;
                        return 0;
@@ -90,3 +92,17 @@ int update_state(struct host* hst, enum con_state st){
        hst->state=st;
        return 0;
 }
+
+/*Free all connections*/
+void cleanup_connections(){
+       struct connection *ptr;
+       struct connection *prev;
+       prev=ptr=chead;
+
+       while(ptr!=NULL){
+               prev=ptr;
+               ptr=ptr->next;
+               free(prev);
+       }
+return;
+}
index bbf729973186f8c7c08b80a79074936c73f08c13..dbd90dfc39832683cacbefdefdd7202add5f7f63 100644 (file)
@@ -131,6 +131,9 @@ int main(int argc, char *argv[])
        /*close files*/
        pcap_close(in);
        pcap_dump_close(out);
+
+       /*Delete all connections*/
+       cleanup_connections();
 return 0;
 }
 
index 2a1dbfa18458f2f8c71a3db423b07e975fb88cd3..64c8dd29ba09067c5105c54cd0da75c9d9d2b3fc 100644 (file)
@@ -122,5 +122,6 @@ int do_encap(int link, struct packet *new, const struct const_packet *old);
 int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, struct host **fwd, struct host **rev);
 struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port);
 int update_state(struct host* hst, enum con_state st);
+void cleanup_connections();
 
 #endif