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(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, struct host **fwd, struct host **rev){
13 struct connection *ptr;
17 if(add_connection(src_id, dest_id, src_port, dest_port)==NULL){
25 /*Loop list looking for connection*/
28 if(ptr->A.id==src_id && ptr->A.port==src_port &&
29 !(ptr->A.state==CLOSE && ptr->B.state==CLOSE)){
34 if(ptr->B.id==src_id && ptr->B.port==src_port &&
35 !(ptr->B.state==CLOSE && ptr->A.state==CLOSE)){
43 /*Add new connection*/
44 ptr=add_connection(src_id, dest_id, src_port, dest_port);
53 /*Add a connection. Return it. On failure, return NULL*/
54 struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port){
55 struct connection *ptr;
56 struct connection *prev;
60 ptr=chead=malloc(sizeof(struct connection));
68 ptr=prev->next=malloc(sizeof(struct connection));
72 dbgprintf(0,"Error: Couldn't allocate Memory\n");
81 ptr->B.port=dest_port;
87 /*Update the state on a host*/
88 int update_state(struct host* hst, enum con_state st){
96 /*Free all connections*/
97 void cleanup_connections(){
98 struct connection *ptr;
99 struct connection *prev;