factor out print_connection_info()
authorDaniel Lenski <dlenski@gmail.com>
Wed, 20 May 2020 05:04:23 +0000 (22:04 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Wed, 20 May 2020 06:31:30 +0000 (23:31 -0700)
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
main.c

diff --git a/main.c b/main.c
index 682afacf05a9a143fd5282f5e6a377ffc6abd83a..8080defb53cfe67e9cda09c258578519e9ccd6c6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1376,16 +1376,48 @@ static int autocomplete(int argc, char **argv)
        return 0;
 }
 
+static void print_connection_info(struct openconnect_info *vpninfo)
+{
+       const struct oc_ip_info *ip_info;
+       const char *ssl_compr, *udp_compr, *dtls_state;
+
+       openconnect_get_ip_info(vpninfo, &ip_info, NULL, NULL);
+
+       switch (vpninfo->dtls_state) {
+       case DTLS_NOSECRET:
+               dtls_state = _("unsuccessful");
+               break;
+       case DTLS_SLEEPING:
+       case DTLS_SECRET:
+               dtls_state = _("in progress");
+               break;
+       case DTLS_DISABLED:
+               dtls_state = _("disabled");
+               break;
+       default:
+               dtls_state = _("connected");
+       }
+
+       ssl_compr = openconnect_get_cstp_compression(vpninfo);
+       udp_compr = openconnect_get_dtls_compression(vpninfo);
+       vpn_progress(vpninfo, PRG_INFO,
+                    _("Connected as %s%s%s, using SSL%s%s, with %s%s%s %s\n"),
+                    ip_info->addr?:"",
+                    (ip_info->netmask6 && ip_info->addr) ? " + " : "",
+                    ip_info->netmask6 ? : "",
+                    ssl_compr ? " + " : "", ssl_compr ? : "",
+                    vpninfo->proto->udp_protocol ? : "UDP", udp_compr ? " + " : "", udp_compr ? : "",
+                    dtls_state);
+}
+
 int main(int argc, char **argv)
 {
        struct openconnect_info *vpninfo;
        char *urlpath = NULL;
        struct oc_vpn_option *gai;
        char *ip;
-       const char *ssl_compr, *udp_compr;
        char *proxy = getenv("https_proxy");
        char *vpnc_script = NULL;
-       const struct oc_ip_info *ip_info;
        int autoproxy = 0;
        int opt;
        char *pidfile = NULL;
@@ -1932,18 +1964,7 @@ int main(int argc, char **argv)
                fprintf(stderr, _("Set up UDP failed; using SSL instead\n"));
        }
 
-       openconnect_get_ip_info(vpninfo, &ip_info, NULL, NULL);
-
-       ssl_compr = openconnect_get_cstp_compression(vpninfo);
-       udp_compr = openconnect_get_dtls_compression(vpninfo);
-       vpn_progress(vpninfo, PRG_INFO,
-                    _("Connected as %s%s%s, using SSL%s%s, with %s%s%s %s\n"),
-                    ip_info->addr?:"",
-                    (ip_info->netmask6 && ip_info->addr) ? " + " : "",
-                    ip_info->netmask6 ? : "",
-                    ssl_compr ? " + " : "", ssl_compr ? : "",
-                    vpninfo->proto->udp_protocol ? : "UDP", udp_compr ? " + " : "", udp_compr ? : "",
-                    (vpninfo->dtls_state == DTLS_DISABLED || vpninfo->dtls_state == DTLS_NOSECRET ? _("disabled") : _("in progress")));
+       print_connection_info(vpninfo);
 
        if (!vpninfo->vpnc_script) {
                vpn_progress(vpninfo, PRG_INFO,