]> sjero.net Git - dccp2tcp/blobdiff - connections.c
Multiple connection support segfault fixes
[dccp2tcp] / connections.c
index 511692fc48ecca9cfc9049c5236c76888fae69cf..b5eb11287c71bfea62b3d9fdc7437badd177f47b 100644 (file)
@@ -9,7 +9,7 @@ Description: Functions for differentiating different DCCP connections.
 #include "dccp2tcp.h"
 
 /*Lookup a connection. If it doesn't exist, add a new connection and return it.*/
-int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, struct host *fwd, struct host *rev){
+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 *ptr;
 
        /*Empty list*/
@@ -17,8 +17,8 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
                if(add_connection(src_id, dest_id, src_port, dest_port)==NULL){
                        return 1;
                }
-               fwd=&chead->A;
-               rev=&chead->B;
+               *fwd=&chead->A;
+               *rev=&chead->B;
                return 0;
        }
 
@@ -26,13 +26,13 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
        ptr=chead;
        while(ptr!=NULL){
                if(ptr->A.id==src_id && ptr->A.port==src_port && ptr->A.state!=CLOSE){
-                       fwd=&ptr->A;
-                       rev=&ptr->B;
+                       *fwd=&ptr->A;
+                       *rev=&ptr->B;
                        return 0;
                }
                if(ptr->B.id==src_id && ptr->B.port==src_port && ptr->B.state!=CLOSE){
-                       fwd=&ptr->B;
-                       rev=&ptr->A;
+                       *fwd=&ptr->B;
+                       *rev=&ptr->A;
                        return 0;
                }
                ptr=ptr->next;
@@ -43,8 +43,8 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
        if(ptr==NULL){
                return 1;
        }
-       fwd=&ptr->A;
-       rev=&ptr->B;
+       *fwd=&ptr->A;
+       *rev=&ptr->B;
        return 0;
 }
 
@@ -54,7 +54,7 @@ struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_por
        struct connection *prev;
 
        /*Allocate memory*/
-       if(chead){
+       if(chead==NULL){
                ptr=chead=malloc(sizeof(struct connection));
        }else{
                ptr=chead;
@@ -73,6 +73,7 @@ struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_por
 
        /*Initialize*/
        ptr->A.id=src_id;
+       ptr->A.port=src_port;
        ptr->A.state=INIT;
        ptr->B.id=dest_id;
        ptr->B.port=dest_port;