/* 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;
/*
* 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;
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
* 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;
/* 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;
/*
* 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;
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
* 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;
/* 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;
/*
* 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;
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
* 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;
#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;
/*
* 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;
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
* 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;
#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;
/*
* 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;
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
* 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;
/*
* 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;
/*
* 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;
L<BIO_closesocket(3)>, L<BIO_ADDRINFO_next(3)>, L<BIO_ADDRINFO_address(3)> and
L<BIO_ADDRINFO_free(3)> for further information on the functions used here. In
the above example code the B<hostname> and B<port> variables are strings, e.g.
-"www.example.com" and "443".
+"www.example.com" and "443". Note also the use of the family variable, which
+can take the values of AF_INET or AF_INET6 based on the command line -6 option,
+to allow specific connections to an ipv4 or ipv6 enabled host.
Sockets created using the methods described above will automatically be blocking
sockets - which is exactly what we want for this example.