diff options
Diffstat (limited to 'cryptot.c')
-rw-r--r-- | cryptot.c | 52 |
1 files changed, 26 insertions, 26 deletions
@@ -41,7 +41,7 @@ static void connect_to_dist(int sock, struct cryptot_st *data, int verbose) if(!recv(sock,buf,2,0)){ fprintf(stderr,"%s : rejected (because of -S option ?).\n",PROG_NAME); exit(1); } - if(strncmp(buf,"OK",2)) { + if(strncmp(buf,"OK",2)) { fprintf(stderr,"%s : protocol error (middle man ?).\n",PROG_NAME); exit(1); } if(verbose)fprintf(stderr,"%s : connected.\n",PROG_NAME); @@ -67,7 +67,7 @@ static int wait_connection(int sock, struct cryptot_st *data, int verbose) PROG_NAME, NIPQUAD(data->local_ip),data->local_port); client = socket_accept4(sock,peer_ip,&peer_port); if(client<0){ fprintf(stderr,"%s socket_accept error : ",PROG_NAME); perror(""); exit(1); } - + if(data->check_accept){ if(peer_port != data->src_port || memcmp(data->src_ip,peer_ip,4)){ fprintf(stderr,"%s : REFUSE connection from %03d.%03d.%03d.%03d:%d.\n", @@ -100,7 +100,7 @@ static void do_stats(struct cryptot_st *data, struct timespec *s0, struct timesp if(nbr> 1024){ nbr/=1024; unit=kb;} if(nbr> 1024){ nbr/=1024; unit=mb;} if(nbr> 1024){ nbr/=1024; unit=gb;} - + time = (float)(s1->tv_sec - s0->tv_sec)+((float)(s1->tv_nsec-s0->tv_nsec))/1E9; if (data->cipher & BLOWFISH) { cipher ="blowfish"; size = data->blocks*BF_BLOCK_SIZE;} else if (data->cipher & TWOFISH) { cipher ="twofish"; size = data->blocks*TF_BLOCK_SIZE; } @@ -123,8 +123,8 @@ static void usage(void) fprintf(stderr,"\tThis program is distributed in the hope that it will be useful,\n"); fprintf(stderr,"\tbut WITHOUT ANY WARRANTY; without even the implied warranty of\n"); fprintf(stderr,"\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); - fprintf(stderr,"\tGNU General Public License for more details.\n\n"); - + fprintf(stderr,"\tGNU General Public License for more details.\n\n"); + fprintf(stderr,"usage : %s [-v] [-x] [-c cipher] [-n nbr_blocks]\n" " [-s [ip]:[port]] [-d [ip]:[port]] [-b [ip]:[port]] [-S [ip]:[port]] key\n",PROG_NAME); fprintf(stderr,"\t\t-v : verbose mode (statistics)\n"); @@ -206,14 +206,14 @@ static void resolve_ip(char *ip) fprintf(stderr,"%s error ",PROG_NAME); perror("gethostname "); exit(1); } - if((hp = gethostbyname(hostname))==NULL){ + if((hp = gethostbyname(hostname))==NULL){ fprintf(stderr,"%s : can't resolve %s, ",PROG_NAME,hostname); herror("\tgethostbyname "); exit(1); } memcpy(ip,hp->h_addr,4); } } - + /* if ip is 0:0:0:0 use localhost, bind to ip/port call listen if required */ static int bind_to(char *ip, int port, int listen) @@ -221,16 +221,16 @@ static int bind_to(char *ip, int port, int listen) int socket; if((socket = socket_tcp(1))==-1) { fprintf(stderr,"%s error in ",PROG_NAME); perror("socket_tcp "); exit(1); } - + if(socket_bind4(socket,ip,port)==-1) { fprintf(stderr,"%s : unable to bind to %03d.%03d.%03d.%03d:%d",PROG_NAME,NIPQUAD(*ip),port); perror("\tsocket_bind "); exit(1); } - + if(listen) if(socket_listen(socket,20)==-1) { fprintf(stderr,"%s error in ",PROG_NAME); perror("socket_listen "); exit(1); } - + return socket; } @@ -239,7 +239,7 @@ static char* allocate_buffer(unsigned int cipher, unsigned int *blocks, unsigned { char *buffer = NULL; int tmp = *blocks; - + if(tmp==-1){ if(cipher & BLOWFISH) tmp = BUFFER_LENGTH/BF_BLOCK_SIZE; else if(cipher & TWOFISH) tmp = BUFFER_LENGTH/TF_BLOCK_SIZE; @@ -270,7 +270,7 @@ static void c_encrypt(struct cryptot_st *data, int verbose) register unsigned int reg = 0; register unsigned int size = data->size; register u8 *buffer = (u8*)data->buffer; - + operation op; int input, output; crypto_buffer c_buffer; @@ -325,7 +325,7 @@ static void c_encrypt(struct cryptot_st *data, int verbose) } } shutdown(reg,SHUT_RDWR); - close(reg); /* close client socket */ + close(reg); /* close client socket */ } crypto_buffer_flush(&c_buffer); if(ret==-1){ fprintf(stderr,"%s read error ",PROG_NAME); perror(""); exit(1); } @@ -342,7 +342,7 @@ static void c_decrypt(struct cryptot_st *data, int verbose) register unsigned int reg = 0; register unsigned int size = data->size; register u8 *buffer = (u8*)data->buffer; - + operation op; int input, output; crypto_buffer c_buffer; @@ -392,7 +392,7 @@ static void c_decrypt(struct cryptot_st *data, int verbose) fprintf(stderr,"%s send error ",PROG_NAME); perror(""); exit(1); } } - + } if(input!=0) { shutdown(input,SHUT_RDWR); close(input); } /* close client socket */ if(ret==-1){ fprintf(stderr,"%s read error ",PROG_NAME); perror(""); exit(1); } @@ -418,20 +418,20 @@ int main(int argc, char **argv) unsigned int verbose = 0; char bind_ip[4]; unsigned int bind_port; - + /* crypto */ struct cryptot_st data; init_data(&data); bind_ip[0] = bind_ip[1] = bind_ip[2] = bind_ip[3] = 0; bind_port = DEFAULT_PORT; - + if(!--argc) usage(); ++argv; while(argc--){ if((*argv)[0]=='-'){ if((*argv)[1]=='v') verbose = 1; - + else if((*argv)[1]=='x') data.cipher|=DECRYPT; else if((*argv)[1]=='n') { @@ -440,7 +440,7 @@ int main(int argc, char **argv) if(!ret || (*argv)[ret]) argument_error('n',1); data.blocks = (unsigned int)param; } - + else if((*argv)[1]=='c') { if(!argc--) argument_error('c',0); if(*(*(++argv))=='h') usage_cipher(); @@ -448,7 +448,7 @@ int main(int argc, char **argv) if(!ret || (*argv)[ret])argument_error('c',1); change_cipher(&data.cipher,param); } - + else if((*argv)[1]=='s') { if(!argc--) argument_error('s',0); ret=ipv4_scan(*(++argv),data.local_ip); @@ -459,7 +459,7 @@ int main(int argc, char **argv) if(*(tmp+ret)) argument_error('s',1); data.in_fd = -1; } - + else if((*argv)[1]=='b') { if(!argc--) argument_error('b',0); ret=ipv4_scan(*(++argv),bind_ip); @@ -469,7 +469,7 @@ int main(int argc, char **argv) if(ret) bind_port = (unsigned int)param; if(*(tmp+ret)) argument_error('b',1); } - + else if((*argv)[1]=='d') { if(!argc--) argument_error('d',0); ret=ipv4_scan(*(++argv),data.dist_ip); @@ -480,7 +480,7 @@ int main(int argc, char **argv) if(*(tmp+ret)) argument_error('d',1); data.out_fd = -1; } - + else if((*argv)[1]=='S') { if(!argc--) argument_error('S',0); ret=ipv4_scan(*(++argv),data.src_ip); @@ -502,7 +502,7 @@ int main(int argc, char **argv) if(data.in_fd != 0) resolve_ip(data.local_ip); if(data.out_fd != 1){ resolve_ip(data.dist_ip); resolve_ip(bind_ip); } if(data.in_fd != 0 && data.check_accept) resolve_ip(data.src_ip); - + /* if input AND output have been changed, check that local != bind AND local != distant */ if(data.in_fd != 0 && data.out_fd != 1){ if(data.local_port == bind_port && !memcmp(data.local_ip,bind_ip,4)){ @@ -517,7 +517,7 @@ int main(int argc, char **argv) if(data.in_fd != 0) data.in_fd = bind_to(data.local_ip, data.local_port, 1); /* bind and listen */ if(data.out_fd != 1) data.out_fd = bind_to(bind_ip, bind_port, 0); /* bind */ - + data.buffer = allocate_buffer(data.cipher, &data.blocks, &data.size); /* allocate buffer and set blocks & size */ #ifdef _DEBUG_ @@ -554,7 +554,7 @@ int main(int argc, char **argv) } else fprintf(stderr,"%s : writing to stdout\n",PROG_NAME); } - + if(data.cipher&DECRYPT){ c_decrypt(&data,verbose); } |