diff options
Diffstat (limited to 'apps/s_socket.c')
-rw-r--r-- | apps/s_socket.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/apps/s_socket.c b/apps/s_socket.c index d16f5ad817..97dc9afffb 100644 --- a/apps/s_socket.c +++ b/apps/s_socket.c @@ -128,7 +128,7 @@ int init_client(int *sock, const char *host, const char *port, * 0 on failure, something other on success. */ int do_server(int *accept_sock, const char *host, const char *port, - int family, int type, do_server_cb cb, + int family, int type, int protocol, do_server_cb cb, unsigned char *context, int naccept) { int asock = 0; @@ -140,7 +140,8 @@ int do_server(int *accept_sock, const char *host, const char *port, if (!BIO_sock_init()) return 0; - if (!BIO_lookup(host, port, BIO_LOOKUP_SERVER, family, type, &res)) { + if (!BIO_lookup_ex(host, port, BIO_LOOKUP_SERVER, family, type, protocol, + &res)) { ERR_print_errors(bio_err); return 0; } @@ -148,7 +149,8 @@ int do_server(int *accept_sock, const char *host, const char *port, /* Admittedly, these checks are quite paranoid, we should not get * anything in the BIO_ADDRINFO chain that we haven't asked for */ OPENSSL_assert((family == AF_UNSPEC || family == BIO_ADDRINFO_family(res)) - && (type == 0 || type == BIO_ADDRINFO_socktype(res))); + && (type == 0 || type == BIO_ADDRINFO_socktype(res)) + && (protocol == 0 || protocol == BIO_ADDRINFO_protocol(res))); asock = BIO_socket(BIO_ADDRINFO_family(res), BIO_ADDRINFO_socktype(res), BIO_ADDRINFO_protocol(res), 0); @@ -161,6 +163,25 @@ int do_server(int *accept_sock, const char *host, const char *port, goto end; } +#ifndef OPENSSL_NO_SCTP + if (protocol == IPPROTO_SCTP) { + /* + * For SCTP we have to set various options on the socket prior to + * accepting. This is done automatically by BIO_new_dgram_sctp(). + * We don't actually need the created BIO though so we free it again + * immediately. + */ + BIO *tmpbio = BIO_new_dgram_sctp(asock, BIO_NOCLOSE); + + if (tmpbio == NULL) { + BIO_closesocket(asock); + ERR_print_errors(bio_err); + goto end; + } + BIO_free(tmpbio); + } +#endif + BIO_ADDRINFO_free(res); res = NULL; @@ -176,10 +197,10 @@ int do_server(int *accept_sock, const char *host, const char *port, BIO_closesocket(asock); break; } - i = (*cb)(sock, type, context); + i = (*cb)(sock, type, protocol, context); BIO_closesocket(sock); } else { - i = (*cb)(asock, type, context); + i = (*cb)(asock, type, protocol, context); } if (naccept != -1) |