From 30302c66bd47220f6fa65f32bc510d3e679ec3d9 Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Wed, 9 Aug 2023 17:46:33 +0100 Subject: QUIC DDD: Allow target host:port to be set from command line Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/21715) --- doc/designs/ddd/ddd-01-conn-blocking.c | 13 +++++++++++-- doc/designs/ddd/ddd-02-conn-nonblocking.c | 15 ++++++++++++--- doc/designs/ddd/ddd-03-fd-blocking.c | 16 ++++++++++++---- doc/designs/ddd/ddd-04-fd-nonblocking.c | 16 ++++++++++++---- doc/designs/ddd/ddd-05-mem-nonblocking.c | 17 +++++++++++++---- doc/designs/ddd/ddd-06-mem-uv.c | 17 +++++++++++++---- 6 files changed, 73 insertions(+), 21 deletions(-) diff --git a/doc/designs/ddd/ddd-01-conn-blocking.c b/doc/designs/ddd/ddd-01-conn-blocking.c index 8ed79e5147..4dae5f48de 100644 --- a/doc/designs/ddd/ddd-01-conn-blocking.c +++ b/doc/designs/ddd/ddd-01-conn-blocking.c @@ -121,19 +121,28 @@ void teardown_ctx(SSL_CTX *ctx) */ int main(int argc, char **argv) { - const char msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n"; + static char msg[384], host_port[300]; SSL_CTX *ctx = NULL; BIO *b = NULL; char buf[2048]; int l, res = 1; + if (argc < 3) { + fprintf(stderr, "usage: %s host port\n", argv[0]); + goto fail; + } + + snprintf(host_port, sizeof(host_port), "%s:%s\n", argv[1], argv[2]); + snprintf(msg, sizeof(msg), + "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]); + ctx = create_ssl_ctx(); if (ctx == NULL) { fprintf(stderr, "could not create context\n"); goto fail; } - b = new_conn(ctx, "www.openssl.org:443"); + b = new_conn(ctx, host_port); if (b == NULL) { fprintf(stderr, "could not create conn\n"); goto fail; diff --git a/doc/designs/ddd/ddd-02-conn-nonblocking.c b/doc/designs/ddd/ddd-02-conn-nonblocking.c index fa508afc7c..30e7e33f1a 100644 --- a/doc/designs/ddd/ddd-02-conn-nonblocking.c +++ b/doc/designs/ddd/ddd-02-conn-nonblocking.c @@ -222,13 +222,22 @@ void teardown_ctx(SSL_CTX *ctx) */ int main(int argc, char **argv) { - const char tx_msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n"; + static char tx_msg[384], host_port[300]; const char *tx_p = tx_msg; char rx_buf[2048]; int res = 1, l, tx_len = sizeof(tx_msg)-1; int timeout = 2000 /* ms */; APP_CONN *conn = NULL; - SSL_CTX *ctx; + SSL_CTX *ctx = NULL; + + if (argc < 3) { + fprintf(stderr, "usage: %s host port\n", argv[0]); + goto fail; + } + + snprintf(host_port, sizeof(host_port), "%s:%s", argv[1], argv[2]); + snprintf(tx_msg, sizeof(tx_msg), + "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]); ctx = create_ssl_ctx(); if (ctx == NULL) { @@ -236,7 +245,7 @@ int main(int argc, char **argv) goto fail; } - conn = new_conn(ctx, "www.openssl.org:443"); + conn = new_conn(ctx, host_port); if (conn == NULL) { fprintf(stderr, "cannot establish connection\n"); goto fail; diff --git a/doc/designs/ddd/ddd-03-fd-blocking.c b/doc/designs/ddd/ddd-03-fd-blocking.c index f4aaf35a1e..6d9f8e87eb 100644 --- a/doc/designs/ddd/ddd-03-fd-blocking.c +++ b/doc/designs/ddd/ddd-03-fd-blocking.c @@ -121,12 +121,20 @@ void teardown_ctx(SSL_CTX *ctx) int main(int argc, char **argv) { int rc, fd = -1, l, res = 1; - const char msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n"; + static char msg[300]; struct addrinfo hints = {0}, *result = NULL; SSL *ssl = NULL; - SSL_CTX *ctx; + SSL_CTX *ctx = NULL; char buf[2048]; + if (argc < 3) { + fprintf(stderr, "usage: %s host port\n", argv[0]); + goto fail; + } + + snprintf(msg, sizeof(msg), + "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]); + ctx = create_ssl_ctx(); if (ctx == NULL) { fprintf(stderr, "cannot create context\n"); @@ -136,7 +144,7 @@ int main(int argc, char **argv) hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; - rc = getaddrinfo("www.openssl.org", "443", &hints, &result); + rc = getaddrinfo(argv[1], argv[2], &hints, &result); if (rc < 0) { fprintf(stderr, "cannot resolve\n"); goto fail; @@ -156,7 +164,7 @@ int main(int argc, char **argv) goto fail; } - ssl = new_conn(ctx, fd, "www.openssl.org"); + ssl = new_conn(ctx, fd, argv[1]); if (ssl == NULL) { fprintf(stderr, "cannot create connection\n"); goto fail; diff --git a/doc/designs/ddd/ddd-04-fd-nonblocking.c b/doc/designs/ddd/ddd-04-fd-nonblocking.c index 2e9606b921..f8a5162a2e 100644 --- a/doc/designs/ddd/ddd-04-fd-nonblocking.c +++ b/doc/designs/ddd/ddd-04-fd-nonblocking.c @@ -223,14 +223,22 @@ void teardown_ctx(SSL_CTX *ctx) int main(int argc, char **argv) { int rc, fd = -1, res = 1; - const char tx_msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n"; + static char tx_msg[300]; const char *tx_p = tx_msg; char rx_buf[2048]; int l, tx_len = sizeof(tx_msg)-1; int timeout = 2000 /* ms */; APP_CONN *conn = NULL; struct addrinfo hints = {0}, *result = NULL; - SSL_CTX *ctx; + SSL_CTX *ctx = NULL; + + if (argc < 3) { + fprintf(stderr, "usage: %s host port\n", argv[0]); + goto fail; + } + + snprintf(tx_msg, sizeof(tx_msg), + "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]); ctx = create_ssl_ctx(); if (ctx == NULL) { @@ -241,7 +249,7 @@ int main(int argc, char **argv) hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; - rc = getaddrinfo("www.openssl.org", "443", &hints, &result); + rc = getaddrinfo(argv[1], argv[2], &hints, &result); if (rc < 0) { fprintf(stderr, "cannot resolve\n"); goto fail; @@ -267,7 +275,7 @@ int main(int argc, char **argv) goto fail; } - conn = new_conn(ctx, fd, "www.openssl.org"); + conn = new_conn(ctx, fd, argv[1]); if (conn == NULL) { fprintf(stderr, "cannot establish connection\n"); goto fail; diff --git a/doc/designs/ddd/ddd-05-mem-nonblocking.c b/doc/designs/ddd/ddd-05-mem-nonblocking.c index 206ca7a6f7..532cf877a3 100644 --- a/doc/designs/ddd/ddd-05-mem-nonblocking.c +++ b/doc/designs/ddd/ddd-05-mem-nonblocking.c @@ -315,14 +315,23 @@ static int pump(APP_CONN *conn, int fd, int events, int timeout) int main(int argc, char **argv) { int rc, fd = -1, res = 1; - const char tx_msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n"; + static char tx_msg[300]; const char *tx_p = tx_msg; char rx_buf[2048]; int l, tx_len = sizeof(tx_msg)-1; int timeout = 2000 /* ms */; APP_CONN *conn = NULL; struct addrinfo hints = {0}, *result = NULL; - SSL_CTX *ctx; + SSL_CTX *ctx = NULL; + + if (argc < 3) { + fprintf(stderr, "usage: %s host port\n", argv[0]); + goto fail; + } + + snprintf(tx_msg, sizeof(tx_msg), + "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", + argv[1]); ctx = create_ssl_ctx(); if (ctx == NULL) { @@ -333,7 +342,7 @@ int main(int argc, char **argv) hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; - rc = getaddrinfo("www.openssl.org", "443", &hints, &result); + rc = getaddrinfo(argv[1], argv[2], &hints, &result); if (rc < 0) { fprintf(stderr, "cannot resolve\n"); goto fail; @@ -359,7 +368,7 @@ int main(int argc, char **argv) goto fail; } - conn = new_conn(ctx, "www.openssl.org"); + conn = new_conn(ctx, argv[1]); if (conn == NULL) { fprintf(stderr, "cannot establish connection\n"); goto fail; diff --git a/doc/designs/ddd/ddd-06-mem-uv.c b/doc/designs/ddd/ddd-06-mem-uv.c index 7af5a11105..59184399ea 100644 --- a/doc/designs/ddd/ddd-06-mem-uv.c +++ b/doc/designs/ddd/ddd-06-mem-uv.c @@ -547,10 +547,11 @@ static void post_write_get(APP_CONN *conn, int status, void *arg) app_read_start(conn, post_read, NULL); } +char tx_msg[300]; + static void post_connect(APP_CONN *conn, int status, void *arg) { int wr; - const char tx_msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n"; if (status < 0) { fprintf(stderr, "failed to connect: %d\n", status); @@ -568,10 +569,18 @@ static void post_connect(APP_CONN *conn, int status, void *arg) int main(int argc, char **argv) { int rc = 1; - SSL_CTX *ctx; + SSL_CTX *ctx = NULL; APP_CONN *conn = NULL; struct addrinfo hints = {0}, *result = NULL; + if (argc < 3) { + fprintf(stderr, "usage: %s host port\n", argv[0]); + goto fail; + } + + snprintf(tx_msg, sizeof(tx_msg), + "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]); + ctx = create_ssl_ctx(); if (!ctx) goto fail; @@ -579,13 +588,13 @@ int main(int argc, char **argv) hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; - rc = getaddrinfo("www.openssl.org", "443", &hints, &result); + rc = getaddrinfo(argv[1], argv[2], &hints, &result); if (rc < 0) { fprintf(stderr, "cannot resolve\n"); goto fail; } - conn = new_conn(ctx, "www.openssl.org", result->ai_addr, result->ai_addrlen, post_connect, NULL); + conn = new_conn(ctx, argv[1], result->ai_addr, result->ai_addrlen, post_connect, NULL); if (!conn) goto fail; -- cgit v1.2.3