move environment setting to separate function
authorDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 6 Oct 2008 21:01:09 +0000 (22:01 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 6 Oct 2008 21:01:48 +0000 (22:01 +0100)
tun.c

diff --git a/tun.c b/tun.c
index c27480a..961a458 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -94,15 +94,10 @@ static int appendenv(const char *opt, const char *new)
        return setenv(opt, buf, 1);
 }
 
-static int script_config_tun(struct openconnect_info *vpninfo)
+static void set_script_env(struct openconnect_info *vpninfo)
 {
        struct sockaddr_in *sin = (void *)vpninfo->peer_addr;
 
-       if (vpninfo->peer_addr->sa_family != AF_INET) {
-               vpninfo->progress(vpninfo, PRG_ERR, "Script cannot handle anything but Legacy IP\n");
-               return -EINVAL;
-       }
-
        setenv("VPNGATEWAY", inet_ntoa(sin->sin_addr), 1);
        setenv("TUNDEV", vpninfo->ifname, 1);
        setenv("reason", "connect", 1);
@@ -135,6 +130,16 @@ static int script_config_tun(struct openconnect_info *vpninfo)
        if (vpninfo->vpn_domain)
                setenv("CISCO_DEF_DOMAIN", vpninfo->vpn_domain, 1);
        else unsetenv ("CISCO_DEF_DOMAIN");
+}
+
+static int script_config_tun(struct openconnect_info *vpninfo)
+{
+       if (vpninfo->peer_addr->sa_family != AF_INET) {
+               vpninfo->progress(vpninfo, PRG_ERR, "Script cannot handle anything but Legacy IP\n");
+               return -EINVAL;
+       }
+
+       set_script_env(vpninfo);
 
        system(vpninfo->vpnc_script);
        return 0;