From e70482b21708ed411b4403c8a155f345a4868fdf Mon Sep 17 00:00:00 2001 From: Samuel Jero Date: Tue, 5 Feb 2013 21:12:55 -0500 Subject: [PATCH] Cleanup types throughout code --- connections.c | 14 +++++++------- dccp2tcp.c | 6 +++--- dccp2tcp.h | 17 ++++++++++------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/connections.c b/connections.c index 732399e..afe6fd8 100644 --- a/connections.c +++ b/connections.c @@ -22,11 +22,11 @@ Date: 02/2013 ******************************************************************************/ #include "dccp2tcp.h" -int isClosed(struct hcon *A, struct hcon *B, int pkt_type); +int isClosed(struct hcon *A, struct hcon *B, enum dccp_pkt_type pkt_type); /*Lookup a connection. If it doesn't exist, add a new connection and return it.*/ int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port, - int pkt_type, struct hcon **fwd, struct hcon **rev){ + enum dccp_pkt_type pkt_type, struct hcon **fwd, struct hcon **rev){ struct connection *ptr; /*Empty list*/ @@ -69,7 +69,7 @@ int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest /*Returns true if the connection is closed and any packets should go to * a new connection with the same four-tuple*/ -int isClosed(struct hcon *A, struct hcon *B, int pkt_type){ +int isClosed(struct hcon *A, struct hcon *B, enum dccp_pkt_type pkt_type){ if(pkt_type==DCCP_PKT_REQUEST || pkt_type==DCCP_PKT_RESPONSE){ if(A->state==CLOSE && B->state==CLOSE){ /*We're opening a new connection on hosts/ports we've used before, mark @@ -154,7 +154,7 @@ return; } /* Setup Half Connection Structure*/ -u_int32_t initialize_hcon(struct hcon *hcn, __be32 initial) +u_int32_t initialize_hcon(struct hcon *hcn, d_seq_num initial) { /*set default values*/ hcn->cur=0; @@ -178,7 +178,7 @@ return initial; } /*Convert Sequence Numbers*/ -u_int32_t add_new_seq(struct hcon *hcn, __be32 num, int size, enum dccp_pkt_type type) +u_int32_t add_new_seq(struct hcon *hcn, d_seq_num num, int size, enum dccp_pkt_type type) { int prev; if(hcn==NULL){ @@ -230,7 +230,7 @@ return hcn->table[hcn->cur].new +1; } /*Convert Ack Numbers*/ -u_int32_t convert_ack(struct hcon *hcn, __be32 num, struct hcon *o_hcn) +u_int32_t convert_ack(struct hcon *hcn, d_seq_num num, struct hcon *o_hcn) { if(hcn==NULL){ dbgprintf(0,"ERROR NULL POINTER!\n"); @@ -255,7 +255,7 @@ return o_hcn->high_ack; } /* Get size of packet being acked*/ -int acked_packet_size(struct hcon *hcn, __be32 num) +int acked_packet_size(struct hcon *hcn, d_seq_num num) { if(hcn==NULL){ dbgprintf(0,"ERROR NULL POINTER!\n"); diff --git a/dccp2tcp.c b/dccp2tcp.c index 488b6f3..6697681 100644 --- a/dccp2tcp.c +++ b/dccp2tcp.c @@ -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(); @@ -1058,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; diff --git a/dccp2tcp.h b/dccp2tcp.h index 3a071a6..23b5af0 100644 --- a/dccp2tcp.h +++ b/dccp2tcp.h @@ -56,8 +56,11 @@ Notes: #define MAX_PACKET 1600 /*Maximum size of TCP packet */ #define TBL_SZ 40000 /*Size of Sequence Number Table*/ + #define TRUE 1 #define FALSE 0 +typedef __be16 dccp_port; +typedef __be32 d_seq_num; /*Packet structure*/ struct packet{ @@ -99,7 +102,7 @@ enum con_type{ struct hcon{ int id_len; /*Length of ID*/ u_char *id; /*Host ID*/ - __be16 port; /*Host DCCP port*/ + dccp_port port; /*Host DCCP port*/ struct tbl *table; /*Host Sequence Number Table*/ int size; /*Size of Sequence Number Table*/ int cur; /*Current TCP Sequence Number*/ @@ -117,7 +120,7 @@ struct connection{ /*sequence number table structure */ struct tbl{ - __be32 old; /*DCCP sequence number */ + d_seq_num old; /*DCCP sequence number */ u_int32_t new; /*TCP sequence number */ int size; /*packet size*/ enum dccp_pkt_type type; /*packet type*/ @@ -144,17 +147,17 @@ int do_encap(int link, struct packet *new, const struct const_packet *old); /*Connection functions*/ int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port, - int pkt_type, struct hcon **fwd, struct hcon **rev); + enum dccp_pkt_type pkt_type, struct hcon **fwd, struct hcon **rev); struct connection *add_connection(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port); int update_state(struct hcon* hst, enum con_state st); void cleanup_connections(); /*Half Connection/Sequence number functions*/ -u_int32_t initialize_hcon(struct hcon *hcn, __be32 initial); -u_int32_t add_new_seq(struct hcon *hcn, __be32 num, int size, enum dccp_pkt_type type); -u_int32_t convert_ack(struct hcon *hcn, __be32 num, struct hcon *o_hcn); -int acked_packet_size(struct hcon *hcn, __be32 num); +u_int32_t initialize_hcon(struct hcon *hcn, d_seq_num initial); +u_int32_t add_new_seq(struct hcon *hcn, d_seq_num num, int size, enum dccp_pkt_type type); +u_int32_t convert_ack(struct hcon *hcn, d_seq_num num, struct hcon *o_hcn); +int acked_packet_size(struct hcon *hcn, d_seq_num num); unsigned int interp_ack_vect(u_char* hdr); #endif -- 2.39.2