summaryrefslogtreecommitdiffstats
path: root/apps/s_socket.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2017-04-20 09:56:56 +0100
committerMatt Caswell <matt@openssl.org>2017-04-25 11:13:39 +0100
commit72d0bc84de394e93f7d756a997c0d42a4ae35058 (patch)
treec91160175ec3833e4058bf27102483789221fdcc /apps/s_socket.c
parent5114d8227e0516fffc0c8653f5118290709f6494 (diff)
Add a -sctp option to s_server
Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3286)
Diffstat (limited to 'apps/s_socket.c')
-rw-r--r--apps/s_socket.c31
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)