diff options
author | Richard Levitte <levitte@openssl.org> | 2018-03-30 21:13:25 +0200 |
---|---|---|
committer | Andy Polyakov <appro@openssl.org> | 2018-04-04 20:24:26 +0200 |
commit | 5540eb7040839b0075a2b7651b6a95264d025e15 (patch) | |
tree | 7028752431911dd7ad388c63afc535c9d15d909d /apps/s_socket.c | |
parent | 8e2bec9b8aaba602af6fda2523a15238aa49aade (diff) |
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)
Diffstat (limited to 'apps/s_socket.c')
-rw-r--r-- | apps/s_socket.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/apps/s_socket.c b/apps/s_socket.c index 4b82011acd..e3cfda98ae 100644 --- a/apps/s_socket.c +++ b/apps/s_socket.c @@ -204,7 +204,7 @@ out: */ int do_server(int *accept_sock, const char *host, const char *port, 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 sock; @@ -283,6 +283,34 @@ int do_server(int *accept_sock, const char *host, const char *port, BIO_ADDRINFO_free(res); 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) *accept_sock = asock; for (;;) { |