]> sjero.net Git - dccp2tcp/blobdiff - dccp2tcp.c
Cleanup types throughout code
[dccp2tcp] / dccp2tcp.c
index db9ca53181241d0e9a4461778ee8ed2edacef554..6697681b99636008dc3472262720f6ac472fc51b 100644 (file)
@@ -56,7 +56,7 @@ int handle_data(struct packet* new, const struct const_packet* old, struct hcon*
 int parse_options(const u_char* opt_start, int len, struct hcon* A, struct hcon* B);
 int process_feature(const u_char* feat, int len, int confirm, int L, struct hcon* A, struct hcon* B);
 void ack_vect2sack(struct hcon *seq, struct tcphdr *tcph, u_char* tcpopts, u_char* dccphdr,
-                               __be32 dccpack, struct hcon* o_hcn);
+                               d_seq_num dccpack, struct hcon* o_hcn);
 void version();
 void usage();
 
@@ -248,8 +248,8 @@ int convert_packet(struct packet *new, const struct const_packet* old)
        }
 
        /*Get Hosts*/
-       if(get_host(new->src_id, new->dest_id, new->id_len,
-                       dccph->dccph_sport, dccph->dccph_dport, &h1, &h2)){
+       if(get_host(new->src_id, new->dest_id, new->id_len, dccph->dccph_sport,
+                       dccph->dccph_dport, dccph->dccph_type,&h1, &h2)){
                dbgprintf(0,"Error: Can't Get Hosts!\n");
                return 0;
        }
@@ -257,6 +257,11 @@ int convert_packet(struct packet *new, const struct const_packet* old)
                dbgprintf(0, "Error: Can't Get Hosts!\n");
                return 0;
        }
+       if(h1->state==IGNORE || h2->state==IGNORE){
+               dbgprintf(2, "Ignoring packet between %i and %i\n",
+                                               ntohs(dccph->dccph_sport), ntohs(dccph->dccph_dport));
+               return 0;
+       }
 
        /*set TCP standard features*/
        tcph->source=dccph->dccph_sport;
@@ -954,12 +959,20 @@ int parse_options(const u_char* opt_start, int len, struct hcon* A, struct hcon*
 
                /*Ack Vector Option*/
                if(*opt==38 || *opt==39){
-
+                       if(B->type==UNKNOWN){
+                               B->type=CCID2;
+                               dbgprintf(1,"Half-connection from port %i to %i probably using CCID 2\n",
+                                                                                       ntohs(B->port),ntohs(A->port));
+                       }
                }
 
                /*NDP Count Option*/
                if(*opt==37){
-
+                       if(B->type==UNKNOWN){
+                               B->type=CCID3;
+                               dbgprintf(1,"Half-connection from port %i to %i probably using CCID 3\n",
+                                                                                       ntohs(B->port),ntohs(A->port));
+                       }
                }
 
                /*Feature negotation*/
@@ -1005,7 +1018,7 @@ int process_feature(const u_char* feat, int len, int confirm, int L, struct hcon
        switch(*feat){
                case 1:
                        /*CCID*/
-                       if(confirm==FALSE){
+                       if(confirm==TRUE){
                                switch(*val){
                                        case 2:
                                                ccid=CCID2;
@@ -1019,16 +1032,24 @@ int process_feature(const u_char* feat, int len, int confirm, int L, struct hcon
                                }
                                if(L==TRUE){
                                        B->type=ccid;
+                                       dbgprintf(1,"Half-connection from port %i to %i using CCID %i\n",
+                                                       ntohs(B->port),ntohs(A->port), *val);
                                }else{
                                        A->type=ccid;
+                                       dbgprintf(1,"Half-connection from port %i to %i using CCID %i\n",
+                                                       ntohs(A->port),ntohs(B->port), *val);
                                }
                        }
                        break;
                case 2:
                        /*Short sequence nums*/
-                       if(confirm==FALSE && *val==1){
-                               dbgprintf(0,"Error! DCCP is trying to turn on short sequence numbers! We do not support this!!\n");
-                               exit(1);
+                       if(confirm==TRUE && *val==1){
+                               B->type=IGNORE;
+                               A->type=IGNORE;
+                               dbgprintf(0,"Error: DCCP is trying to turn on short sequence numbers\n"
+                                               "  for the connection between %i and %i. We do not support this.\n"
+                                               "  This connection will be ignored.",ntohs(A->port),ntohs(B->port));
+                               return 0;
                        }
                        break;
        }
@@ -1037,13 +1058,13 @@ int process_feature(const u_char* feat, int len, int confirm, int L, struct hcon
 
 /*Ack Vector to SACK Option*/
 void ack_vect2sack(struct hcon *hcn, struct tcphdr *tcph, u_char* tcpopts, u_char* dccphdr,
-                                                                                                                               __be32 dccpack, struct hcon* o_hcn)
+                                                                                                                               d_seq_num dccpack, struct hcon* o_hcn)
 {
        int hdrlen=((struct dccp_hdr*)dccphdr)->dccph_doff*4;
        int optlen;
        int len;
        int tmp;
-       __be32 bp;
+       d_seq_num bp;
        u_char* temp;
        u_char* opt;
        u_char* cur;
@@ -1157,9 +1178,11 @@ return;
 
 void version()
 {
-       dbgprintf(0, "dccp2tcp version %.1f\nCopyright (C) %i Samuel Jero <sj323707@ohio.edu>\n", DCCP2TCP_VERSION,COPYRIGHT_YEAR);
+       dbgprintf(0, "dccp2tcp version %.1f\n",DCCP2TCP_VERSION);
+       dbgprintf(0, "Copyright (C) %i Samuel Jero <sj323707@ohio.edu>\n",COPYRIGHT_YEAR);
        dbgprintf(0, "This program comes with ABSOLUTELY NO WARRANTY.\n");
-       dbgprintf(0, "This is free software, and you are welcome to\nredistribute it under certain conditions.\n");
+       dbgprintf(0, "This is free software, and you are welcome to\n");
+       dbgprintf(0, "redistribute it under certain conditions.\n");
        exit(0);
 }