[PATCH v4 3/3] list supported protocols in --version or --help output, using API functions

Daniel Lenski dlenski at gmail.com
Sun Apr 9 02:05:47 PDT 2017


Signed-off-by: Daniel Lenski <dlenski at gmail.com>
---
 main.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/main.c b/main.c
index 71be303..405cf00 100644
--- a/main.c
+++ b/main.c
@@ -631,10 +631,45 @@ static void print_build_opts(void)
 	}
 
 #ifdef HAVE_DTLS
-	printf("%sDTLS\n", sep);
-#else
-	printf(_("\nWARNING: No DTLS support in this binary. Performance will be impaired.\n"));
+	printf("%sDTLS", sep);
 #endif
+#ifdef HAVE_ESP
+	printf("%sESP", sep);
+#endif
+	printf("\n");
+
+#if !defined(HAVE_DTLS) || !defined(HAVE_ESP)
+	printf(_("WARNING: This binary lacks DTLS and/or ESP support. Performance will be impaired.\n"));
+#endif
+}
+
+static void print_supported_protocols(void)
+{
+	const char *comma = ", ", *sep = comma + 1;
+	struct oc_vpn_proto *protos, *p;
+
+	if (openconnect_get_supported_protocols(&protos)>=0) {
+		printf(_("Supported protocols:"));
+		for (p=protos; p->name; p++) {
+			printf("%s%s%s", sep, p->name, p==protos ? _(" (default)") : "");
+			sep = comma;
+		}
+		printf("\n");
+		free(protos);
+	}
+}
+
+static void print_supported_protocols_usage(void)
+{
+	struct oc_vpn_proto *protos, *p;
+
+	if (openconnect_get_supported_protocols(&protos)>=0) {
+		printf(_("\n    Set VPN protocol:\n"));
+		for (p=protos; p->name; p++)
+			printf("      --protocol=%-16s %s%s\n",
+				   p->name, p->description, p==protos ? _(" (default)") : "");
+		openconnect_free_supported_protocols(protos);
+	}
 }
 
 #ifndef _WIN32
@@ -750,7 +785,7 @@ static int gai_override_cb(void *cbdata, const char *node,
 static void usage(void)
 {
 	printf(_("Usage:  openconnect [options] <server>\n"));
-	printf(_("Open client for Cisco AnyConnect VPN, version %s\n\n"), openconnect_version_str);
+	printf(_("Open client for multiple VPN protocols, version %s\n\n"), openconnect_version_str);
 	print_build_opts();
 	printf("      --config=CONFIGFILE         %s\n", _("Read options from config file"));
 #ifndef _WIN32
@@ -832,6 +867,8 @@ static void usage(void)
 	printf("      --resolve=HOST:IP           %s\n", _("Use IP when connecting to HOST"));
 	printf("      --os=STRING                 %s\n", _("OS type (linux,linux-64,win,...) to report"));
 	printf("      --dtls-local-port=PORT      %s\n", _("Set local port for DTLS datagrams"));
+	print_supported_protocols_usage();
+
 	printf("\n");
 
 	helpmessage();
@@ -1334,6 +1371,7 @@ int main(int argc, char **argv)
 		case 'V':
 			printf(_("OpenConnect version %s\n"), openconnect_version_str);
 			print_build_opts();
+			print_supported_protocols();
 			exit(0);
 		case 'x':
 			vpninfo->xmlconfig = keep_config_arg();
-- 
2.7.4




More information about the openconnect-devel mailing list