]> granicus.if.org Git - libevent/commitdiff
https-client: add -4/-6 switches
authorAzat Khuzhin <azat@libevent.org>
Mon, 26 Oct 2020 22:17:44 +0000 (01:17 +0300)
committerAzat Khuzhin <azat@libevent.org>
Mon, 26 Oct 2020 22:18:52 +0000 (01:18 +0300)
sample/https-client.c

index bfb405e0433710ec048e21af44d752ed5ab86265..aa7f8eab650a722aeeff2c9386c69252c78f0127 100644 (file)
@@ -56,6 +56,8 @@
 #endif
 
 static int ignore_cert = 0;
+static int ipv6 = 0;
+static int ipv4 = 0;
 
 static void
 http_request_done(struct evhttp_request *req, void *ctx)
@@ -110,7 +112,7 @@ static void
 syntax(void)
 {
        fputs("Syntax:\n", stderr);
-       fputs("   https-client -url <https-url> [-data data-file.bin] [-ignore-cert] [-retries num] [-timeout sec] [-crt crt]\n", stderr);
+       fputs("   https-client -url <https-url> [-data data-file.bin] [-ignore-cert] [-4] [-6] [-retries num] [-timeout sec] [-crt crt]\n", stderr);
        fputs("Example:\n", stderr);
        fputs("   https-client -url https://ip.appspot.com/\n", stderr);
 }
@@ -305,6 +307,10 @@ main(int argc, char **argv)
                        }
                } else if (!strcmp("-ignore-cert", argv[i])) {
                        ignore_cert = 1;
+               } else if (!strcmp("-4", argv[i])) {
+                       ipv4 = 1;
+               } else if (!strcmp("-6", argv[i])) {
+                       ipv6 = 1;
                } else if (!strcmp("-data", argv[i])) {
                        if (i < argc - 1) {
                                data_file = argv[i + 1];
@@ -542,6 +548,13 @@ main(int argc, char **argv)
                goto error;
        }
 
+       if (ipv4) {
+               evhttp_connection_set_family(evcon, AF_INET);
+       }
+       if (ipv6) {
+               evhttp_connection_set_family(evcon, AF_INET6);
+       }
+
        if (retries > 0) {
                evhttp_connection_set_retries(evcon, retries);
        }