QUIC DDD: Allow target host:port to be set from command line
authorHugo Landau <hlandau@openssl.org>
Wed, 9 Aug 2023 16:46:33 +0000 (17:46 +0100)
committerHugo Landau <hlandau@openssl.org>
Fri, 1 Sep 2023 09:45:34 +0000 (10:45 +0100)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21715)

doc/designs/ddd/ddd-01-conn-blocking.c
doc/designs/ddd/ddd-02-conn-nonblocking.c
doc/designs/ddd/ddd-03-fd-blocking.c
doc/designs/ddd/ddd-04-fd-nonblocking.c
doc/designs/ddd/ddd-05-mem-nonblocking.c
doc/designs/ddd/ddd-06-mem-uv.c

index 8ed79e514745be911b5b267cd03b220a76f07a70..4dae5f48de72e5a28b2dc00d63661cf2e15c4eab 100644 (file)
@@ -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;
index fa508afc7cd1b2ae50b2704f5de240cd92d39293..30e7e33f1a1e1fa23fc03fe1056f977d255de281 100644 (file)
@@ -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;
index f4aaf35a1e915cedd628c675ab204fe474463412..6d9f8e87eb110cecfa4f28f4fc6571db0fc57e54 100644 (file)
@@ -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;
index 2e9606b921b78c13508440bbf0673c2a04170f34..f8a5162a2e7a50518f064635dab59bf0e21b7592 100644 (file)
@@ -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;
index 206ca7a6f79491fecb210569f8831caeb1737818..532cf877a32443377e36b530672d2902a9f7f681 100644 (file)
@@ -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;
index 7af5a111054c8aba247672b836c83a82806671e0..59184399ea2132ef08b97e77e1b4ad26f1be4ed0 100644 (file)
@@ -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;