1 /******************************************************************************
6 Description: Functions for differentiating different DCCP connections.
8 ******************************************************************************/
11 /*Lookup a connection. If it doesn't exist, add a new connection and return it.*/
12 int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port,
13 struct host **fwd, struct host **rev){
14 struct connection *ptr;
18 if(add_connection(src_id, dest_id, id_len, src_port, dest_port)==NULL){
26 /*Loop list looking for connection*/
29 if(memcmp(ptr->A.id,src_id,id_len)==0 && ptr->A.port==src_port &&
30 !(ptr->A.state==CLOSE && ptr->B.state==CLOSE)){
35 if(memcmp(ptr->B.id,src_id,id_len)==0 && ptr->B.port==src_port &&
36 !(ptr->B.state==CLOSE && ptr->A.state==CLOSE)){
44 /*Add new connection*/
45 ptr=add_connection(src_id, dest_id, id_len, src_port, dest_port);
54 /*Add a connection. Return it. On failure, return NULL*/
55 struct connection *add_connection(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port){
56 struct connection *ptr;
57 struct connection *prev;
61 ptr=chead=malloc(sizeof(struct connection));
69 ptr=prev->next=malloc(sizeof(struct connection));
73 dbgprintf(0,"Error: Couldn't allocate Memory\n");
78 ptr->A.id=malloc(id_len);
79 ptr->B.id=malloc(id_len);
80 if(ptr->A.id==NULL||ptr->B.id==NULL){
81 dbgprintf(0,"Error: Couldn't allocate Memory\n");
84 memcpy(ptr->A.id,src_id,id_len);
87 memcpy(ptr->B.id,dest_id,id_len);
88 ptr->B.port=dest_port;
94 /*Update the state on a host*/
95 int update_state(struct host* hst, enum con_state st){
103 /*Free all connections*/
104 void cleanup_connections(){
105 struct connection *ptr;
106 struct connection *prev;