diff options
Diffstat (limited to 'demos/guide/tls-client-block.c')
-rw-r--r-- | demos/guide/tls-client-block.c | 24 |
1 files changed, 17 insertions, 7 deletions
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; |