X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=apps%2Fs_time.c;h=dfe8df70fac83bf56076c4768400a3ab1b71c42b;hp=187c09d12e9a33bff5a4b8f9d9a0149089ac4fb5;hb=6d23cf97443bfedf755341b4f2d0d7fce254e020;hpb=ec577822f95a8bca0023c5c77cef1a4916822d4a diff --git a/apps/s_time.c b/apps/s_time.c index 187c09d12e..dfe8df70fa 100644 --- a/apps/s_time.c +++ b/apps/s_time.c @@ -67,73 +67,25 @@ #include #include -#ifdef NO_STDIO -#define APPS_WIN16 -#endif +#define USE_SOCKETS +#include "apps.h" #include #include #include -#define USE_SOCKETS -#include "apps.h" #include "s_apps.h" #include #ifdef WIN32_STUFF #include "winmain.h" #include "wintext.h" #endif - -#ifndef MSDOS -#define TIMES -#endif - -#ifndef VMS -#ifndef _IRIX -#include -#endif -#ifdef TIMES -#include -#include -#endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } -#endif -#ifndef TIMES -#include -#endif - -#ifdef _AIX -#include -#endif - -#if defined(sun) || defined(__ultrix) -#define _POSIX_SOURCE -#include -#include -#endif - -/* The following if from times(3) man page. It may need to be changed -*/ -#ifndef HZ -#ifndef CLK_TCK -#ifndef VMS -#define HZ 100.0 -#else /* VMS */ -#define HZ 100.0 -#endif -#else /* CLK_TCK */ -#define HZ ((double)CLK_TCK) -#endif +#if !defined(OPENSSL_SYS_MSDOS) +#include OPENSSL_UNISTD #endif #undef PROG #define PROG s_time_main +#undef ioctl #define ioctl ioctlsocket #define SSL_CONNECT_NAME "localhost:4433" @@ -143,6 +95,10 @@ struct tms { #undef BUFSIZZ #define BUFSIZZ 1024*10 +#define MYBUFSIZ 1024*8 + +#undef min +#undef max #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b)) @@ -151,18 +107,10 @@ struct tms { extern int verify_depth; extern int verify_error; -#ifndef NOPROTO static void s_time_usage(void); static int parseArgs( int argc, char **argv ); static SSL *doConnection( SSL *scon ); static void s_time_init(void); -#else -static void s_time_usage(); -static int parseArgs(); -static SSL *doConnection(); -static void s_time_init(); -#endif - /*********************************************************************** * Static data declarations @@ -178,7 +126,7 @@ static char *tm_cipher=NULL; static int tm_verify = SSL_VERIFY_NONE; static int maxTime = SECONDS; static SSL_CTX *tm_ctx=NULL; -static SSL_METHOD *s_time_meth=NULL; +static const SSL_METHOD *s_time_meth=NULL; static char *s_www_path=NULL; static long bytes_read=0; static int st_bugs=0; @@ -186,7 +134,7 @@ static int perform=0; #ifdef FIONBIO static int t_nbio=0; #endif -#ifdef WIN32 +#ifdef OPENSSL_SYS_WIN32 static int exitNow = 0; /* Set when it's time to exit main */ #endif @@ -210,7 +158,7 @@ static void s_time_init(void) #ifdef FIONBIO t_nbio=0; #endif -#ifdef WIN32 +#ifdef OPENSSL_SYS_WIN32 exitNow = 0; /* Set when it's time to exit main */ #endif } @@ -228,16 +176,15 @@ static void s_time_usage(void) file if not specified by this option\n\ -CApath arg - PEM format directory of CA's\n\ -CAfile arg - PEM format file of CA's\n\ --cipher - prefered cipher to use, play with 'openssl ciphers'\n\n"; +-cipher - preferred cipher to use, play with 'openssl ciphers'\n\n"; printf( "usage: s_time \n\n" ); printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME); #ifdef FIONBIO printf("-nbio - Run with non-blocking IO\n"); - printf("-ssl2 - Just use SSLv2\n"); printf("-ssl3 - Just use SSLv3\n"); - printf("-bugs - Turn on SSL bug compatability\n"); + printf("-bugs - Turn on SSL bug compatibility\n"); printf("-new - Just time new connections\n"); printf("-reuse - Just time connection reuse\n"); printf("-www page - Retrieve 'page' from the site\n"); @@ -256,15 +203,6 @@ static int parseArgs(int argc, char **argv) verify_depth=0; verify_error=X509_V_OK; -#ifdef FIONBIO - t_nbio=0; -#endif - - apps_startup(); - s_time_init(); - - if (bio_err == NULL) - bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); argc--; argv++; @@ -332,14 +270,15 @@ static int parseArgs(int argc, char **argv) { if (--argc < 1) goto bad; s_www_path= *(++argv); + if(strlen(s_www_path) > MYBUFSIZ-100) + { + BIO_printf(bio_err,"-www option too long\n"); + badop=1; + } } else if(strcmp(*argv,"-bugs") == 0) st_bugs=1; -#ifndef NO_SSL2 - else if(strcmp(*argv,"-ssl2") == 0) - s_time_meth=SSLv2_client_method(); -#endif -#ifndef NO_SSL3 +#ifndef OPENSSL_NO_SSL3 else if(strcmp(*argv,"-ssl3") == 0) s_time_meth=SSLv3_client_method(); #endif @@ -377,38 +316,15 @@ bad: static double tm_Time_F(int s) { - static double ret; -#ifdef TIMES - static struct tms tstart,tend; - - if(s == START) { - times(&tstart); - return(0); - } else { - times(&tend); - ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; - return((ret == 0.0)?1e-6:ret); - } -#else /* !times() */ - static struct timeb tstart,tend; - long i; - - if(s == START) { - ftime(&tstart); - return(0); - } else { - ftime(&tend); - i=(long)tend.millitm-(long)tstart.millitm; - ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; - return((ret == 0.0)?1e-6:ret); + return app_tminterval(s,1); } -#endif -} /*********************************************************************** * MAIN - main processing area for client * real name depends on MONOLITH */ +int MAIN(int, char **); + int MAIN(int argc, char **argv) { double totalTime = 0.0; @@ -419,19 +335,19 @@ int MAIN(int argc, char **argv) MS_STATIC char buf[1024*8]; int ver; -#if !defined(NO_SSL2) && !defined(NO_SSL3) + apps_startup(); + s_time_init(); + + if (bio_err == NULL) + bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); + s_time_meth=SSLv23_client_method(); -#elif !defined(NO_SSL3) - s_time_meth=SSLv3_client_method(); -#elif !defined(NO_SSL2) - s_time_meth=SSLv2_client_method(); -#endif /* parse the command line arguments */ if( parseArgs( argc, argv ) < 0 ) goto end; - SSLeay_add_ssl_algorithms(); + OpenSSL_add_ssl_algorithms(); if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1); SSL_CTX_set_quiet_shutdown(tm_ctx,1); @@ -446,7 +362,7 @@ int MAIN(int argc, char **argv) if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) || (!SSL_CTX_set_default_verify_paths(tm_ctx))) { - /* BIO_printf(bio_err,"error seting default verify locations\n"); */ + /* BIO_printf(bio_err,"error setting default verify locations\n"); */ ERR_print_errors(bio_err); /* goto end; */ } @@ -456,7 +372,6 @@ int MAIN(int argc, char **argv) if (tm_cipher == NULL ) { fprintf( stderr, "No CIPHER specified\n" ); -/* EXIT(1); */ } if (!(perform & 1)) goto next; @@ -469,7 +384,7 @@ int MAIN(int argc, char **argv) tm_Time_F(START); for (;;) { - if (finishtime < time(NULL)) break; + if (finishtime < (long)time(NULL)) break; #ifdef WIN32_STUFF if( flushWinMsgs(0) == -1 ) @@ -484,7 +399,7 @@ int MAIN(int argc, char **argv) if (s_www_path != NULL) { - sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); + BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while ((i=SSL_read(scon,buf,sizeof(buf))) > 0) bytes_read+=i; @@ -507,8 +422,6 @@ int MAIN(int argc, char **argv) ver='t'; else if (ver == SSL3_VERSION) ver='3'; - else if (ver == SSL2_VERSION) - ver='2'; else ver='*'; } @@ -520,9 +433,9 @@ int MAIN(int argc, char **argv) } totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ - i=(int)(time(NULL)-finishtime+maxTime); + i=(int)((long)time(NULL)-finishtime+maxTime); printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read); - printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn); + printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn); /* Now loop and time connections using the same session id over and over */ @@ -539,7 +452,7 @@ next: if (s_www_path != NULL) { - sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); + BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while (SSL_read(scon,buf,sizeof(buf)) > 0) ; @@ -554,7 +467,7 @@ next: nConn = 0; totalTime = 0.0; - finishtime=time(NULL)+maxTime; + finishtime=(long)time(NULL)+maxTime; printf( "starting\n" ); bytes_read=0; @@ -562,7 +475,7 @@ next: for (;;) { - if (finishtime < time(NULL)) break; + if (finishtime < (long)time(NULL)) break; #ifdef WIN32_STUFF if( flushWinMsgs(0) == -1 ) @@ -577,7 +490,7 @@ next: if (s_www_path) { - sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); + BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while ((i=SSL_read(scon,buf,sizeof(buf))) > 0) bytes_read+=i; @@ -600,8 +513,6 @@ next: ver='t'; else if (ver == SSL3_VERSION) ver='3'; - else if (ver == SSL2_VERSION) - ver='2'; else ver='*'; } @@ -612,7 +523,7 @@ next: printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read); - printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn); + printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn); ret=0; end: @@ -623,7 +534,8 @@ end: SSL_CTX_free(tm_ctx); tm_ctx=NULL; } - EXIT(ret); + apps_shutdown(); + OPENSSL_EXIT(ret); } /*********************************************************************** @@ -647,7 +559,7 @@ static SSL *doConnection(SSL *scon) BIO_set_conn_hostname(conn,host); if (scon == NULL) - serverCon=(SSL *)SSL_new(tm_ctx); + serverCon=SSL_new(tm_ctx); else { serverCon=scon; @@ -671,8 +583,14 @@ static SSL *doConnection(SSL *scon) i=SSL_get_fd(serverCon); width=i+1; FD_ZERO(&readfds); - FD_SET(i,&readfds); - select(width,&readfds,NULL,NULL,NULL); + openssl_fdset(i,&readfds); + /* Note: under VMS with SOCKETSHR the 2nd parameter + * is currently of type (int *) whereas under other + * systems it is (void *) if you don't have a cast it + * will choke the compiler: if you do have a cast then + * you can either go for (int *) or (void *). + */ + select(width,(void *)&readfds,NULL,NULL,NULL); continue; } break;