summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorNeil Horman <nhorman@openssl.org>2023-10-31 11:54:03 -0400
committerRichard Levitte <levitte@openssl.org>2023-11-21 13:01:54 +0100
commit5091aadc223315ce115ee12f62df2af173bf5efb (patch)
tree850952514ebcd1d96e96a58e1617c79a1812e66d /demos
parentcf6342bc024868f5a55f2225f2e083415fb1329a (diff)
augment quic demos to support ipv4/6 connections
Because the quicserver utility supports expressly listening in ipv4/6 mode, its possible/likely that the server will listen on an ipv4 address, while the clients will connect via ipv6, leading to connection failures. Augment quic demo clients to afford them the same -6 option that the server has so that connection family can be co-ordinated Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22577)
Diffstat (limited to 'demos')
-rw-r--r--demos/guide/quic-client-block.c24
-rw-r--r--demos/guide/quic-client-non-block.c25
-rw-r--r--demos/guide/quic-multi-stream.c24
-rw-r--r--demos/guide/tls-client-block.c24
-rw-r--r--demos/guide/tls-client-non-block.c25
5 files changed, 87 insertions, 35 deletions
diff --git a/demos/guide/quic-client-block.c b/demos/guide/quic-client-block.c
index 782f571559..baf5292c47 100644
--- a/demos/guide/quic-client-block.c
+++ b/demos/guide/quic-client-block.c
@@ -27,7 +27,7 @@
/* Helper function to create a BIO connected to the server */
static BIO *create_socket_bio(const char *hostname, const char *port,
- BIO_ADDR **peer_addr)
+ int family, BIO_ADDR **peer_addr)
{
int sock = -1;
BIO_ADDRINFO *res;
@@ -37,7 +37,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
/*
* Lookup IP address info for the server.
*/
- if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, 0, SOCK_DGRAM, 0,
+ if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, family, SOCK_DGRAM, 0,
&res))
return NULL;
@@ -128,14 +128,24 @@ int main(int argc, char *argv[])
char buf[160];
BIO_ADDR *peer_addr = NULL;
char *hostname, *port;
+ int argnext = 1;
+ int ipv6 = 0;
- if (argc != 3) {
- printf("Usage: quic-client-block hostname port\n");
+ if (argc < 3) {
+ printf("Usage: quic-client-block [-6] hostname port\n");
goto end;
}
- hostname = argv[1];
- port = argv[2];
+ if (!strcmp(argv[argnext], "-6")) {
+ if (argc < 4) {
+ printf("Usage: quic-client-block [-6] hostname port\n");
+ goto end;
+ }
+ ipv6 = 1;
+ argnext++;
+ }
+ hostname = argv[argnext++];
+ port = argv[argnext];
/*
* Create an SSL_CTX which we can use to create SSL objects from. We
@@ -172,7 +182,7 @@ int main(int argc, char *argv[])
* Create the underlying transport socket/BIO and associate it with the
* connection.
*/
- bio = create_socket_bio(hostname, port, &peer_addr);
+ bio = create_socket_bio(hostname, port, ipv6 ? AF_INET6 : AF_INET, &peer_addr);
if (bio == NULL) {
printf("Failed to crete the BIO\n");
goto end;
diff --git a/demos/guide/quic-client-non-block.c b/demos/guide/quic-client-non-block.c
index 31596d84c5..a6c1802fcd 100644
--- a/demos/guide/quic-client-non-block.c
+++ b/demos/guide/quic-client-non-block.c
@@ -28,7 +28,7 @@
/* Helper function to create a BIO connected to the server */
static BIO *create_socket_bio(const char *hostname, const char *port,
- BIO_ADDR **peer_addr)
+ int family, BIO_ADDR **peer_addr)
{
int sock = -1;
BIO_ADDRINFO *res;
@@ -38,7 +38,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
/*
* Lookup IP address info for the server.
*/
- if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, 0, SOCK_DGRAM, 0,
+ if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, family, SOCK_DGRAM, 0,
&res))
return NULL;
@@ -236,14 +236,24 @@ int main(int argc, char *argv[])
BIO_ADDR *peer_addr = NULL;
int eof = 0;
char *hostname, *port;
+ int ipv6 = 0;
+ int argnext = 1;
- if (argc != 3) {
- printf("Usage: quic-client-non-block hostname port\n");
+ if (argc < 3) {
+ printf("Usage: quic-client-non-block [-6] hostname port\n");
goto end;
}
- hostname = argv[1];
- port = argv[2];
+ if (!strcmp(argv[argnext], "-6")) {
+ if (argc < 4) {
+ printf("Usage: quic-client-non-block [-6] hostname port\n");
+ goto end;
+ }
+ ipv6 = 1;
+ argnext++;
+ }
+ hostname = argv[argnext++];
+ port = argv[argnext];
/*
* Create an SSL_CTX which we can use to create SSL objects from. We
@@ -280,7 +290,8 @@ int main(int argc, char *argv[])
* Create the underlying transport socket/BIO and associate it with the
* connection.
*/
- bio = create_socket_bio(hostname, port, &peer_addr);
+ bio = create_socket_bio(hostname, port, ipv6 ? AF_INET6 : AF_INET,
+ &peer_addr);
if (bio == NULL) {
printf("Failed to crete the BIO\n");
goto end;
diff --git a/demos/guide/quic-multi-stream.c b/demos/guide/quic-multi-stream.c
index 469c5ba4b2..d31ea245c8 100644
--- a/demos/guide/quic-multi-stream.c
+++ b/demos/guide/quic-multi-stream.c
@@ -27,7 +27,7 @@
/* Helper function to create a BIO connected to the server */
static BIO *create_socket_bio(const char *hostname, const char *port,
- BIO_ADDR **peer_addr)
+ int family, BIO_ADDR **peer_addr)
{
int sock = -1;
BIO_ADDRINFO *res;
@@ -37,7 +37,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
/*
* Lookup IP address info for the server.
*/
- if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, 0, SOCK_DGRAM, 0,
+ if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, family, SOCK_DGRAM, 0,
&res))
return NULL;
@@ -148,14 +148,24 @@ int main(int argc, char *argv[])
char buf[160];
BIO_ADDR *peer_addr = NULL;
char *hostname, *port;
+ int argnext = 1;
+ int ipv6 = 0;
- if (argc != 3) {
- printf("Usage: quic-client-non-block hostname port\n");
+ if (argc < 3) {
+ printf("Usage: quic-client-non-block [-6] hostname port\n");
goto end;
}
- hostname = argv[1];
- port = argv[2];
+ if (!strcmp(argv[argnext], "-6")) {
+ if (argc < 4) {
+ printf("Usage: quic-client-non-block [-6] hostname port\n");
+ goto end;
+ }
+ ipv6 = 1;
+ argnext++;
+ }
+ hostname = argv[argnext++];
+ port = argv[argnext];
/*
* Create an SSL_CTX which we can use to create SSL objects from. We
@@ -201,7 +211,7 @@ int main(int argc, char *argv[])
* Create the underlying transport socket/BIO and associate it with the
* connection.
*/
- bio = create_socket_bio(hostname, port, &peer_addr);
+ bio = create_socket_bio(hostname, port, ipv6 ? AF_INET6 : AF_INET, &peer_addr);
if (bio == NULL) {
printf("Failed to crete the BIO\n");
goto end;
diff --git a/demos/guide/tls-client-block.c b/demos/guide/tls-client-block.c
index ea7d68467a..c6ba5850f7 100644
--- a/demos/guide/tls-client-block.c
+++ b/demos/guide/tls-client-block.c
@@ -26,7 +26,7 @@
#include <openssl/err.h>
/* Helper function to create a BIO connected to the server */
-static BIO *create_socket_bio(const char *hostname, const char *port)
+static BIO *create_socket_bio(const char *hostname, const char *port, int family)
{
int sock = -1;
BIO_ADDRINFO *res;
@@ -36,7 +36,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port)
/*
* Lookup IP address info for the server.
*/
- if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, 0, SOCK_STREAM, 0,
+ if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, family, SOCK_STREAM, 0,
&res))
return NULL;
@@ -109,14 +109,24 @@ int main(int argc, char *argv[])
size_t written, readbytes;
char buf[160];
char *hostname, *port;
+ int argnext = 1;
+ int ipv6 = 0;
- if (argc != 3) {
- printf("Usage: tls-client-block hostname port\n");
+ if (argc < 3) {
+ printf("Usage: tls-client-block [-6] hostname port\n");
goto end;
}
- hostname = argv[1];
- port = argv[2];
+ if (!strcmp(argv[argnext], "-6")) {
+ if (argc < 4) {
+ printf("Usage: tls-client-block [-6] hostname port\n");
+ goto end;
+ }
+ ipv6 = 1;
+ argnext++;
+ }
+ hostname = argv[argnext++];
+ port = argv[argnext];
/*
* Create an SSL_CTX which we can use to create SSL objects from. We
@@ -162,7 +172,7 @@ int main(int argc, char *argv[])
* Create the underlying transport socket/BIO and associate it with the
* connection.
*/
- bio = create_socket_bio(hostname, port);
+ bio = create_socket_bio(hostname, port, ipv6 ? AF_INET6 : AF_INET);
if (bio == NULL) {
printf("Failed to crete the BIO\n");
goto end;
diff --git a/demos/guide/tls-client-non-block.c b/demos/guide/tls-client-non-block.c
index 8748e4fffc..0b19d67762 100644
--- a/demos/guide/tls-client-non-block.c
+++ b/demos/guide/tls-client-non-block.c
@@ -27,7 +27,7 @@
#include <openssl/err.h>
/* Helper function to create a BIO connected to the server */
-static BIO *create_socket_bio(const char *hostname, const char *port)
+static BIO *create_socket_bio(const char *hostname, const char *port, int family)
{
int sock = -1;
BIO_ADDRINFO *res;
@@ -37,7 +37,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port)
/*
* Lookup IP address info for the server.
*/
- if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, 0, SOCK_STREAM, 0,
+ if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, family, SOCK_STREAM, 0,
&res))
return NULL;
@@ -187,14 +187,25 @@ int main(int argc, char *argv[])
char buf[160];
int eof = 0;
char *hostname, *port;
+ int argnext = 1;
+ int ipv6 = 0;
- if (argc != 3) {
- printf("Usage: tls-client-non-block hostname port\n");
+ if (argc < 3) {
+ printf("Usage: tls-client-non-block [-6] hostname port\n");
goto end;
}
- hostname = argv[1];
- port = argv[2];
+ if (!strcmp(argv[argnext], "-6")) {
+ if (argc < 4) {
+ printf("Usage: tls-client-non-block [-6] hostname port\n");
+ goto end;
+ }
+ ipv6 = 1;
+ argnext++;
+ }
+
+ hostname = argv[argnext++];
+ port = argv[argnext];
/*
* Create an SSL_CTX which we can use to create SSL objects from. We
@@ -240,7 +251,7 @@ int main(int argc, char *argv[])
* Create the underlying transport socket/BIO and associate it with the
* connection.
*/
- bio = create_socket_bio(hostname, port);
+ bio = create_socket_bio(hostname, port, ipv6 ? AF_INET6 : AF_INET);
if (bio == NULL) {
printf("Failed to crete the BIO\n");
goto end;