mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-05-07 23:19:39 +00:00
openssl s_server: print the accepting address and socket
The line saying ACCEPT is extended with a space followed by the the address and port combination on which s_server accepts connections. The address is written in such a way that s_client should be able to accepts as argument for the '-connect' option. Reviewed-by: Andy Polyakov <appro@openssl.org> (Merged from https://github.com/openssl/openssl/pull/5843)
This commit is contained in:
parent
8e2bec9b8a
commit
5540eb7040
@ -22,9 +22,8 @@
|
|||||||
|
|
||||||
typedef int (*do_server_cb)(int s, int stype, int prot, unsigned char *context);
|
typedef int (*do_server_cb)(int s, int stype, int prot, unsigned char *context);
|
||||||
int do_server(int *accept_sock, const char *host, const char *port,
|
int do_server(int *accept_sock, const char *host, const char *port,
|
||||||
int family, int type, int protocol,
|
int family, int type, int protocol, do_server_cb cb,
|
||||||
do_server_cb cb,
|
unsigned char *context, int naccept, BIO *bio_s_out);
|
||||||
unsigned char *context, int naccept);
|
|
||||||
#ifdef HEADER_X509_H
|
#ifdef HEADER_X509_H
|
||||||
int verify_callback(int ok, X509_STORE_CTX *ctx);
|
int verify_callback(int ok, X509_STORE_CTX *ctx);
|
||||||
#endif
|
#endif
|
||||||
|
@ -2095,8 +2095,6 @@ int s_server_main(int argc, char *argv[])
|
|||||||
if (max_early_data >= 0)
|
if (max_early_data >= 0)
|
||||||
SSL_CTX_set_max_early_data(ctx, max_early_data);
|
SSL_CTX_set_max_early_data(ctx, max_early_data);
|
||||||
|
|
||||||
BIO_printf(bio_s_out, "ACCEPT\n");
|
|
||||||
(void)BIO_flush(bio_s_out);
|
|
||||||
if (rev)
|
if (rev)
|
||||||
server_cb = rev_body;
|
server_cb = rev_body;
|
||||||
else if (www)
|
else if (www)
|
||||||
@ -2109,7 +2107,7 @@ int s_server_main(int argc, char *argv[])
|
|||||||
unlink(host);
|
unlink(host);
|
||||||
#endif
|
#endif
|
||||||
do_server(&accept_socket, host, port, socket_family, socket_type, protocol,
|
do_server(&accept_socket, host, port, socket_family, socket_type, protocol,
|
||||||
server_cb, context, naccept);
|
server_cb, context, naccept, bio_s_out);
|
||||||
print_stats(bio_s_out, ctx);
|
print_stats(bio_s_out, ctx);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
end:
|
end:
|
||||||
@ -2673,9 +2671,6 @@ static int sv_body(int s, int stype, int prot, unsigned char *context)
|
|||||||
}
|
}
|
||||||
BIO_printf(bio_s_out, "CONNECTION CLOSED\n");
|
BIO_printf(bio_s_out, "CONNECTION CLOSED\n");
|
||||||
OPENSSL_clear_free(buf, bufsize);
|
OPENSSL_clear_free(buf, bufsize);
|
||||||
if (ret >= 0)
|
|
||||||
BIO_printf(bio_s_out, "ACCEPT\n");
|
|
||||||
(void)BIO_flush(bio_s_out);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3284,8 +3279,6 @@ static int www_body(int s, int stype, int prot, unsigned char *context)
|
|||||||
SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
|
SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ret >= 0)
|
|
||||||
BIO_printf(bio_s_out, "ACCEPT\n");
|
|
||||||
OPENSSL_free(buf);
|
OPENSSL_free(buf);
|
||||||
BIO_free_all(io);
|
BIO_free_all(io);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -204,7 +204,7 @@ out:
|
|||||||
*/
|
*/
|
||||||
int do_server(int *accept_sock, const char *host, const char *port,
|
int do_server(int *accept_sock, const char *host, const char *port,
|
||||||
int family, int type, int protocol, do_server_cb cb,
|
int family, int type, int protocol, do_server_cb cb,
|
||||||
unsigned char *context, int naccept)
|
unsigned char *context, int naccept, BIO *bio_s_out)
|
||||||
{
|
{
|
||||||
int asock = 0;
|
int asock = 0;
|
||||||
int sock;
|
int sock;
|
||||||
@ -283,6 +283,34 @@ int do_server(int *accept_sock, const char *host, const char *port,
|
|||||||
BIO_ADDRINFO_free(res);
|
BIO_ADDRINFO_free(res);
|
||||||
res = NULL;
|
res = NULL;
|
||||||
|
|
||||||
|
{
|
||||||
|
union BIO_sock_info_u info;
|
||||||
|
char *hostname = NULL;
|
||||||
|
char *service = NULL;
|
||||||
|
int success = 0;
|
||||||
|
|
||||||
|
if ((info.addr = BIO_ADDR_new()) != NULL
|
||||||
|
&& BIO_sock_info(asock, BIO_SOCK_INFO_ADDRESS, &info)
|
||||||
|
&& (hostname = BIO_ADDR_hostname_string(info.addr, 1)) != NULL
|
||||||
|
&& (service = BIO_ADDR_service_string(info.addr, 1)) != NULL
|
||||||
|
&& BIO_printf(bio_s_out,
|
||||||
|
strchr(hostname, ':') == NULL
|
||||||
|
? /* IPv4 */ "ACCEPT %s:%s\n"
|
||||||
|
: /* IPv6 */ "ACCEPT [%s]:%s\n",
|
||||||
|
hostname, service) > 0)
|
||||||
|
success = 1;
|
||||||
|
|
||||||
|
(void)BIO_flush(bio_s_out);
|
||||||
|
OPENSSL_free(hostname);
|
||||||
|
OPENSSL_free(service);
|
||||||
|
BIO_ADDR_free(info.addr);
|
||||||
|
if (!success) {
|
||||||
|
BIO_closesocket(asock);
|
||||||
|
ERR_print_errors(bio_err);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (accept_sock != NULL)
|
if (accept_sock != NULL)
|
||||||
*accept_sock = asock;
|
*accept_sock = asock;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user