⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s_time.c

📁 mediastreamer2是开源的网络传输媒体流的库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* apps/s_time.c *//* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. *  * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to.  The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code.  The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). *  * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *    "This product includes cryptographic software written by *     Eric Young (eay@cryptsoft.com)" *    The word 'cryptographic' can be left out if the rouines from the library *    being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from  *    the apps directory (application code) you must include an acknowledgement: *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" *  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *  * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed.  i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */#define NO_SHUTDOWN/*-----------------------------------------   s_time - SSL client connection timer program   Written and donated by Larry Streepy <streepy@healthcare.com>  -----------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <string.h>#define USE_SOCKETS#include "apps.h"#ifdef OPENSSL_NO_STDIO#define APPS_WIN16#endif#include <openssl/x509.h>#include <openssl/ssl.h>#include <openssl/pem.h>#include "s_apps.h"#include <openssl/err.h>#ifdef WIN32_STUFF#include "winmain.h"#include "wintext.h"#endif#if !defined(OPENSSL_SYS_MSDOS)#include OPENSSL_UNISTD#endif#if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))#define TIMES#endif#ifndef _IRIX#include <time.h>#endif#ifdef TIMES#include <sys/types.h>#include <sys/times.h>#endif/* Depending on the VMS version, the tms structure is perhaps defined.   The __TMS macro will show if it was.  If it wasn't defined, we should   undefine TIMES, since that tells the rest of the program how things   should be handled.				-- Richard Levitte */#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)#undef TIMES#endif#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)#include <sys/timeb.h>#endif#if defined(sun) || defined(__ultrix)#define _POSIX_SOURCE#include <limits.h>#include <sys/param.h>#endif/* The following if from times(3) man page.  It may need to be changed*/#ifndef HZ# ifdef _SC_CLK_TCK#  define HZ ((double)sysconf(_SC_CLK_TCK))# else#  ifndef CLK_TCK#   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */#    define HZ	100.0#   else /* _BSD_CLK_TCK_ */#    define HZ ((double)_BSD_CLK_TCK_)#   endif#  else /* CLK_TCK */#   define HZ ((double)CLK_TCK)#  endif# endif#endif#undef PROG#define PROG s_time_main#undef ioctl#define ioctl ioctlsocket#define SSL_CONNECT_NAME	"localhost:4433"/*#define TEST_CERT "client.pem" */ /* no default cert. */#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))#undef SECONDS#define SECONDS	30extern int verify_depth;extern int verify_error;static void s_time_usage(void);static int parseArgs( int argc, char **argv );static SSL *doConnection( SSL *scon );static void s_time_init(void);/*********************************************************************** * Static data declarations *//* static char *port=PORT_STR;*/static char *host=SSL_CONNECT_NAME;static char *t_cert_file=NULL;static char *t_key_file=NULL;static char *CApath=NULL;static char *CAfile=NULL;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 char *s_www_path=NULL;static long bytes_read=0; static int st_bugs=0;static int perform=0;#ifdef FIONBIOstatic int t_nbio=0;#endif#ifdef OPENSSL_SYS_WIN32static int exitNow = 0;		/* Set when it's time to exit main */#endifstatic void s_time_init(void)	{	host=SSL_CONNECT_NAME;	t_cert_file=NULL;	t_key_file=NULL;	CApath=NULL;	CAfile=NULL;	tm_cipher=NULL;	tm_verify = SSL_VERIFY_NONE;	maxTime = SECONDS;	tm_ctx=NULL;	s_time_meth=NULL;	s_www_path=NULL;	bytes_read=0; 	st_bugs=0;	perform=0;#ifdef FIONBIO	t_nbio=0;#endif#ifdef OPENSSL_SYS_WIN32	exitNow = 0;		/* Set when it's time to exit main */#endif	}/*********************************************************************** * usage - display usage message */static void s_time_usage(void){	static char umsg[] = "\-time arg     - max number of seconds to collect data, default %d\n\-verify arg   - turn on peer certificate verification, arg == depth\n\-cert arg     - certificate file to use, PEM format assumed\n\-key arg      - RSA file to use, PEM format assumed, key is in cert file\n\                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       - preferred cipher to use, play with 'openssl ciphers'\n\n";	printf( "usage: s_time <args>\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 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");#endif	printf( umsg,SECONDS );}/*********************************************************************** * parseArgs - Parse command line arguments and initialize data * * Returns 0 if ok, -1 on bad args */static int parseArgs(int argc, char **argv){    int badop = 0;    verify_depth=0;    verify_error=X509_V_OK;    argc--;    argv++;    while (argc >= 1) {	if (strcmp(*argv,"-connect") == 0)		{		if (--argc < 1) goto bad;		host= *(++argv);		}#if 0	else if( strcmp(*argv,"-host") == 0)		{		if (--argc < 1) goto bad;		host= *(++argv);		}	else if( strcmp(*argv,"-port") == 0)		{		if (--argc < 1) goto bad;		port= *(++argv);		}#endif	else if (strcmp(*argv,"-reuse") == 0)		perform=2;	else if (strcmp(*argv,"-new") == 0)		perform=1;	else if( strcmp(*argv,"-verify") == 0) {	    tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;	    if (--argc < 1) goto bad;	    verify_depth=atoi(*(++argv));	    BIO_printf(bio_err,"verify depth is %d\n",verify_depth);	} else if( strcmp(*argv,"-cert") == 0) {	    if (--argc < 1) goto bad;	    t_cert_file= *(++argv);	} else if( strcmp(*argv,"-key") == 0) {	    if (--argc < 1) goto bad;	    t_key_file= *(++argv);	} else if( strcmp(*argv,"-CApath") == 0) {	    if (--argc < 1) goto bad;	    CApath= *(++argv);	} else if( strcmp(*argv,"-CAfile") == 0) {	    if (--argc < 1) goto bad;	    CAfile= *(++argv);	} else if( strcmp(*argv,"-cipher") == 0) {	    if (--argc < 1) goto bad;	    tm_cipher= *(++argv);	}#ifdef FIONBIO	else if(strcmp(*argv,"-nbio") == 0) {	    t_nbio=1;	}#endif	else if(strcmp(*argv,"-www") == 0)		{		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 OPENSSL_NO_SSL2	else if(strcmp(*argv,"-ssl2") == 0)	    s_time_meth=SSLv2_client_method();#endif#ifndef OPENSSL_NO_SSL3	else if(strcmp(*argv,"-ssl3") == 0)	    s_time_meth=SSLv3_client_method();#endif	else if( strcmp(*argv,"-time") == 0) {	    if (--argc < 1) goto bad;	    maxTime= atoi(*(++argv));	}	else {	    BIO_printf(bio_err,"unknown option %s\n",*argv);	    badop=1;	    break;	}	argc--;	argv++;    }    if (perform == 0) perform=3;    if(badop) {bad:		s_time_usage();		return -1;    }	return 0;			/* Valid args */}/*********************************************************************** * TIME - time functions

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -