]> sjero.net Git - dccp2tcp/blobdiff - connections.c
IPv6 support!
[dccp2tcp] / connections.c
index 0edc451ba60c4209d50eaeaede55c6210a658848..4bc60f04f3684d989bc19b5bd309956252944f7e 100644 (file)
@@ -1,7 +1,7 @@
 /******************************************************************************
 Author: Samuel Jero
 
-Date: 11/2011
+Date: 11/2012
 
 Description: Functions for differentiating different DCCP connections.
 
@@ -9,12 +9,13 @@ 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(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port,
+               struct host **fwd, struct host **rev){
        struct connection *ptr;
 
        /*Empty list*/
        if(chead==NULL){
-               if(add_connection(src_id, dest_id, src_port, dest_port)==NULL){
+               if(add_connection(src_id, dest_id, id_len, src_port, dest_port)==NULL){
                        return 1;
                }
                *fwd=&chead->A;
@@ -25,13 +26,13 @@ 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 &&
+               if(memcmp(ptr->A.id,src_id,id_len)==0 && 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 &&
+               if(memcmp(ptr->B.id,src_id,id_len)==0 && ptr->B.port==src_port &&
                                !(ptr->B.state==CLOSE && ptr->A.state==CLOSE)){
                        *fwd=&ptr->B;
                        *rev=&ptr->A;
@@ -41,7 +42,7 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
        }
 
        /*Add new connection*/
-       ptr=add_connection(src_id, dest_id, src_port, dest_port);
+       ptr=add_connection(src_id, dest_id, id_len, src_port, dest_port);
        if(ptr==NULL){
                return 1;
        }
@@ -51,7 +52,7 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
 }
 
 /*Add a connection. Return it. On failure, return NULL*/
-struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port){
+struct connection *add_connection(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port){
        struct connection *ptr;
        struct connection *prev;
 
@@ -74,10 +75,16 @@ struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_por
        }
 
        /*Initialize*/
-       ptr->A.id=src_id;
+       ptr->A.id=malloc(id_len);
+       ptr->B.id=malloc(id_len);
+       if(ptr->A.id==NULL||ptr->B.id==NULL){
+               dbgprintf(0,"Error: Couldn't allocate Memory\n");
+               exit(1);
+       }
+       memcpy(ptr->A.id,src_id,id_len);
        ptr->A.port=src_port;
        ptr->A.state=INIT;
-       ptr->B.id=dest_id;
+       memcpy(ptr->B.id,dest_id,id_len);
        ptr->B.port=dest_port;
        ptr->B.state=INIT;
 
@@ -101,6 +108,8 @@ void cleanup_connections(){
 
        while(ptr!=NULL){
                prev=ptr;
+               free(ptr->A.id);
+               free(ptr->B.id);
                ptr=ptr->next;
                free(prev);
        }