Add some ipconfig helpers
authorMartin Xu <martin.xu@intel.com>
Tue, 9 Feb 2010 09:29:49 +0000 (10:29 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 11 Feb 2010 04:27:57 +0000 (05:27 +0100)
__connman_ipconfig_get_method(): Returns the selected ipconfig method.
__connman_ipconfig_set_address(): Sets the device's IP address according
to the selected method. Only the manual method is supported.
__connman_ipconfig_clear_address(): Clears the device's IP address. Again,
only the manual method is supported for now.

src/connman.h
src/ipconfig.c

index 593a517..ff38ad5 100644 (file)
@@ -151,6 +151,10 @@ void __connman_ipconfig_append_proxy(struct connman_ipconfig *ipconfig,
                                                        DBusMessageIter *iter);
 void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
                                                        DBusMessageIter *iter);
+enum connman_ipconfig_method __connman_ipconfig_get_method(
+                               struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_set_address(struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig);
 
 int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
                GKeyFile *keyfile, const char *identifier, const char *prefix);
index 38c317b..5d626e2 100644 (file)
@@ -888,6 +888,15 @@ int connman_ipconfig_set_method(struct connman_ipconfig *ipconfig,
        return 0;
 }
 
+enum connman_ipconfig_method __connman_ipconfig_get_method(
+                               struct connman_ipconfig *ipconfig)
+{
+       if (ipconfig == NULL)
+               return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+
+       return ipconfig->method;
+}
+
 /**
  * connman_ipconfig_bind:
  * @ipconfig: ipconfig structure
@@ -907,6 +916,42 @@ void connman_ipconfig_bind(struct connman_ipconfig *ipconfig,
        connman_inet_set_address(origin->index, origin->address);
 }
 
+int __connman_ipconfig_set_address(struct connman_ipconfig *ipconfig)
+{
+       DBG("");
+
+       switch (ipconfig->method) {
+       case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+       case CONNMAN_IPCONFIG_METHOD_OFF:
+       case CONNMAN_IPCONFIG_METHOD_FIXED:
+       case CONNMAN_IPCONFIG_METHOD_DHCP:
+               break;
+       case CONNMAN_IPCONFIG_METHOD_MANUAL:
+               return connman_inet_set_address(ipconfig->index,
+                                               ipconfig->address);
+       }
+
+       return 0;
+}
+
+int __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig)
+{
+       DBG("");
+
+       switch (ipconfig->method) {
+       case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+       case CONNMAN_IPCONFIG_METHOD_OFF:
+       case CONNMAN_IPCONFIG_METHOD_FIXED:
+       case CONNMAN_IPCONFIG_METHOD_DHCP:
+               break;
+       case CONNMAN_IPCONFIG_METHOD_MANUAL:
+               return connman_inet_clear_address(ipconfig->index);
+       }
+
+       return 0;
+
+}
+
 int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig)
 {
        struct connman_ipdevice *ipdevice;