add -naccept <n> option to s_server to automatically exit after <n> connections
This commit is contained in:
@@ -148,7 +148,7 @@ typedef fd_mask fd_set;
|
|||||||
#define PORT_STR "4433"
|
#define PORT_STR "4433"
|
||||||
#define PROTOCOL "tcp"
|
#define PROTOCOL "tcp"
|
||||||
|
|
||||||
int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
|
int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context, int naccept);
|
||||||
#ifdef HEADER_X509_H
|
#ifdef HEADER_X509_H
|
||||||
int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
|
int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -454,13 +454,13 @@ int ssl_print_curves(BIO *out, SSL *s, int noshared)
|
|||||||
}
|
}
|
||||||
if (ncurves == 0)
|
if (ncurves == 0)
|
||||||
BIO_puts(out, "NONE");
|
BIO_puts(out, "NONE");
|
||||||
|
OPENSSL_free(curves);
|
||||||
if (noshared)
|
if (noshared)
|
||||||
{
|
{
|
||||||
BIO_puts(out, "\n");
|
BIO_puts(out, "\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
BIO_puts(out, "\nShared Elliptic curves: ");
|
BIO_puts(out, "\nShared Elliptic curves: ");
|
||||||
OPENSSL_free(curves);
|
|
||||||
ncurves = SSL_get_shared_curve(s, -1);
|
ncurves = SSL_get_shared_curve(s, -1);
|
||||||
for (i = 0; i < ncurves; i++)
|
for (i = 0; i < ncurves; i++)
|
||||||
{
|
{
|
||||||
|
@@ -979,7 +979,7 @@ int MAIN(int argc, char *argv[])
|
|||||||
STACK_OF(X509) *s_chain = NULL, *s_dchain = NULL;
|
STACK_OF(X509) *s_chain = NULL, *s_dchain = NULL;
|
||||||
EVP_PKEY *s_key = NULL, *s_dkey = NULL;
|
EVP_PKEY *s_key = NULL, *s_dkey = NULL;
|
||||||
int no_cache = 0, ext_cache = 0;
|
int no_cache = 0, ext_cache = 0;
|
||||||
int rev = 0;
|
int rev = 0, naccept = -1;
|
||||||
#ifndef OPENSSL_NO_TLSEXT
|
#ifndef OPENSSL_NO_TLSEXT
|
||||||
EVP_PKEY *s_key2 = NULL;
|
EVP_PKEY *s_key2 = NULL;
|
||||||
X509 *s_cert2 = NULL;
|
X509 *s_cert2 = NULL;
|
||||||
@@ -1040,6 +1040,17 @@ int MAIN(int argc, char *argv[])
|
|||||||
if (!extract_port(*(++argv),&port))
|
if (!extract_port(*(++argv),&port))
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
else if (strcmp(*argv,"-naccept") == 0)
|
||||||
|
{
|
||||||
|
if (--argc < 1) goto bad;
|
||||||
|
naccept = atol(*(++argv));
|
||||||
|
if (naccept <= 0)
|
||||||
|
{
|
||||||
|
BIO_printf(bio_err, "bad accept value %s\n",
|
||||||
|
*argv);
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (strcmp(*argv,"-verify") == 0)
|
else if (strcmp(*argv,"-verify") == 0)
|
||||||
{
|
{
|
||||||
s_server_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
|
s_server_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
|
||||||
@@ -2000,11 +2011,11 @@ bad:
|
|||||||
BIO_printf(bio_s_out,"ACCEPT\n");
|
BIO_printf(bio_s_out,"ACCEPT\n");
|
||||||
(void)BIO_flush(bio_s_out);
|
(void)BIO_flush(bio_s_out);
|
||||||
if (rev)
|
if (rev)
|
||||||
do_server(port,socket_type,&accept_socket,rev_body, context);
|
do_server(port,socket_type,&accept_socket,rev_body, context, naccept);
|
||||||
else if (www)
|
else if (www)
|
||||||
do_server(port,socket_type,&accept_socket,www_body, context);
|
do_server(port,socket_type,&accept_socket,www_body, context, naccept);
|
||||||
else
|
else
|
||||||
do_server(port,socket_type,&accept_socket,sv_body, context);
|
do_server(port,socket_type,&accept_socket,sv_body, context, naccept);
|
||||||
print_stats(bio_s_out,ctx);
|
print_stats(bio_s_out,ctx);
|
||||||
ret=0;
|
ret=0;
|
||||||
end:
|
end:
|
||||||
|
@@ -280,7 +280,7 @@ static int init_client_ip(int *sock, const unsigned char ip[4], int port,
|
|||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
|
int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context, int naccept)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
@@ -310,7 +310,9 @@ int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, uns
|
|||||||
if (name != NULL) OPENSSL_free(name);
|
if (name != NULL) OPENSSL_free(name);
|
||||||
if (type==SOCK_STREAM)
|
if (type==SOCK_STREAM)
|
||||||
SHUTDOWN2(sock);
|
SHUTDOWN2(sock);
|
||||||
if (i < 0)
|
if (naccept != -1)
|
||||||
|
naccept--;
|
||||||
|
if (i < 0 || naccept == 0)
|
||||||
{
|
{
|
||||||
SHUTDOWN2(accept_socket);
|
SHUTDOWN2(accept_socket);
|
||||||
return(i);
|
return(i);
|
||||||
|
Reference in New Issue
Block a user