diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2011-07-28 13:20:27 +0300 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2011-08-09 13:19:07 +0200 |
commit | d7f9c1d864581aeba3a45b1ddb0e1ad46f5184d1 (patch) | |
tree | d9f38cd70725e95e726b175081c151c2b3b811ac /src/ipconfig.c | |
parent | 9366a5c28b82e35804e678e885db3f98feb68cf6 (diff) | |
download | connman-d7f9c1d864581aeba3a45b1ddb0e1ad46f5184d1.tar.gz connman-d7f9c1d864581aeba3a45b1ddb0e1ad46f5184d1.tar.bz2 connman-d7f9c1d864581aeba3a45b1ddb0e1ad46f5184d1.zip |
ipconfig: Remember last DHCP IP address.
Diffstat (limited to 'src/ipconfig.c')
-rw-r--r-- | src/ipconfig.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/ipconfig.c b/src/ipconfig.c index 9f73b656..aa8274c0 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -54,6 +54,7 @@ struct connman_ipconfig { struct connman_ipaddress *system; int ipv6_privacy_config; + char *last_dhcp_address; }; struct connman_ipdevice { @@ -1286,6 +1287,7 @@ void connman_ipconfig_unref(struct connman_ipconfig *ipconfig) connman_ipaddress_free(ipconfig->system); connman_ipaddress_free(ipconfig->address); + g_free(ipconfig->last_dhcp_address); g_free(ipconfig); } } @@ -1518,6 +1520,24 @@ const char *__connman_ipconfig_get_proxy_autoconfig(struct connman_ipconfig *ipc return ipdevice->pac; } +void __connman_ipconfig_set_dhcp_address(struct connman_ipconfig *ipconfig, + const char *address) +{ + if (ipconfig == NULL) + return; + + g_free(ipconfig->last_dhcp_address); + ipconfig->last_dhcp_address = g_strdup(address); +} + +char *__connman_ipconfig_get_dhcp_address(struct connman_ipconfig *ipconfig) +{ + if (ipconfig == NULL) + return NULL; + + return ipconfig->last_dhcp_address; +} + static void disable_ipv6(struct connman_ipconfig *ipconfig) { struct connman_ipdevice *ipdevice; @@ -2080,6 +2100,7 @@ int __connman_ipconfig_load(struct connman_ipconfig *ipconfig, { char *method; char *key; + char *str; DBG("ipconfig %p identifier %s", ipconfig, identifier); @@ -2140,6 +2161,14 @@ int __connman_ipconfig_load(struct connman_ipconfig *ipconfig, keyfile, identifier, key, NULL); g_free(key); + key = g_strdup_printf("%sDHCP.LastAddress", prefix); + str = g_key_file_get_string(keyfile, identifier, key, NULL); + if (str != NULL) { + g_free(ipconfig->last_dhcp_address); + ipconfig->last_dhcp_address = str; + } + g_free(key); + return 0; } @@ -2169,9 +2198,18 @@ int __connman_ipconfig_save(struct connman_ipconfig *ipconfig, case CONNMAN_IPCONFIG_METHOD_FIXED: case CONNMAN_IPCONFIG_METHOD_MANUAL: break; + case CONNMAN_IPCONFIG_METHOD_DHCP: + key = g_strdup_printf("%sDHCP.LastAddress", prefix); + if (ipconfig->last_dhcp_address != NULL && + strlen(ipconfig->last_dhcp_address) > 0) + g_key_file_set_string(keyfile, identifier, key, + ipconfig->last_dhcp_address); + else + g_key_file_remove_key(keyfile, identifier, key, NULL); + g_free(key); + /* fall through */ case CONNMAN_IPCONFIG_METHOD_UNKNOWN: case CONNMAN_IPCONFIG_METHOD_OFF: - case CONNMAN_IPCONFIG_METHOD_DHCP: case CONNMAN_IPCONFIG_METHOD_AUTO: return 0; } |