From 55c388bacaff0cff07ddebc423a16c7d728acba3 Mon Sep 17 00:00:00 2001 From: Samuel Jero Date: Sun, 27 Nov 2011 15:36:34 -0500 Subject: [PATCH] Connection closing improvements and explicit cleanup code --- connections.c | 20 ++++++++++++++++++-- dccp2tcp.c | 3 +++ dccp2tcp.h | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/connections.c b/connections.c index b5eb112..b5d04ca 100644 --- a/connections.c +++ b/connections.c @@ -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; +} diff --git a/dccp2tcp.c b/dccp2tcp.c index bbf7299..dbd90df 100644 --- a/dccp2tcp.c +++ b/dccp2tcp.c @@ -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; } diff --git a/dccp2tcp.h b/dccp2tcp.h index 2a1dbfa..64c8dd2 100644 --- a/dccp2tcp.h +++ b/dccp2tcp.h @@ -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 -- 2.39.2