#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*/
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;
}
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;
if(ptr==NULL){
return 1;
}
- fwd=&ptr->A;
- rev=&ptr->B;
+ *fwd=&ptr->A;
+ *rev=&ptr->B;
return 0;
}
struct connection *prev;
/*Allocate memory*/
- if(chead){
+ if(chead==NULL){
ptr=chead=malloc(sizeof(struct connection));
}else{
ptr=chead;
/*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;
}
/*process packets*/
+ chead=NULL;
u_char *user=(u_char*)out;
pcap_loop(in, -1, handle_packet, user);
/*Safety checks*/
if(!new || !old || !new->data || !old->data || !new->h || !old->h){
dbgprintf(0,"Error: Convert Packet Function given bad data!\n");
+ exit(1);
return 0;
}
if(old->length < sizeof(struct dccp_hdr) || new->length < sizeof(struct dccp_hdr)){
dbgprintf(2,"Sequence Number: %llu\n", (unsigned long long)(((unsigned long)ntohs(dccph->dccph_seq)<<32) + ntohl(dccphex->dccph_seq_low)));
/*Get Hosts*/
- if(get_host(new->src_id, new->dest_id, dccph->dccph_sport, dccph->dccph_dport, h1, h2)){
+ if(get_host(new->src_id, new->dest_id, dccph->dccph_sport, dccph->dccph_dport, &h1, &h2)){
dbgprintf(0,"Error: Can't Get Hosts!\n");
return 0;
}
- if(!h1 || !h2){
+ if(h1==NULL || h2==NULL){
dbgprintf(0, "Error: Can't Get Hosts!\n");
return 0;
}
exit(1);
}
+ if(seq->table==NULL){
+ dbgprintf(1, "Warning: Connection initialization incorrect\n");
+ return 0;
+ }
+
/*account for missing packets*/
while(seq->table[seq->cur].old +1 < num && seq->table[seq->cur].old +1 > 0){
prev=seq->cur;
int do_encap(int link, struct packet *new, const struct const_packet *old);
/*Connection functions*/
-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 *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);
/*Select Next Protocol*/
switch(ntohs(ethh->ether_type)){
case ETHERTYPE_IP:
+ nnew.h=new->h;
+ nold.h=old->h;
if(!ipv4_encap(&nnew, &nold)){
return 0;
}
switch(iph->protocol){
case 0x21:
/*DCCP*/
+ nnew.h=new->h;
+ nold.h=old->h;
nnew.src_id=iph->saddr;
nnew.dest_id=iph->daddr;
if(!convert_packet(&nnew, &nold)){
/*Select Next Protocol*/
switch(ntohs(slh->sll_protocol)){
case ETHERTYPE_IP:
+ nnew.h=new->h;
+ nold.h=old->h;
if(!ipv4_encap(&nnew, &nold)){
return 0;
}