diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2012-11-12 14:07:18 +0200 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-11-23 12:58:50 +0200 |
commit | 68dde4bb2c3e90a6f48dc48609636228dd186c8c (patch) | |
tree | 319e4787674daa49b939916769611f0770a32e91 /src/ipconfig.c | |
parent | d20247d3b3074b7c5937540ce5dbc8f020c79907 (diff) | |
download | connman-68dde4bb2c3e90a6f48dc48609636228dd186c8c.tar.gz connman-68dde4bb2c3e90a6f48dc48609636228dd186c8c.tar.bz2 connman-68dde4bb2c3e90a6f48dc48609636228dd186c8c.zip |
ipconfig: Move IP address API into separate ipaddress.c file
Done so that connman_ipaddress_* functions can be used from
separate vpn daemon.
Diffstat (limited to 'src/ipconfig.c')
-rw-r--r-- | src/ipconfig.c | 167 |
1 files changed, 1 insertions, 166 deletions
diff --git a/src/ipconfig.c b/src/ipconfig.c index aa7a03db..3cb0d9bb 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -36,6 +36,7 @@ #endif #include <gdbus.h> +#include <connman/ipaddress.h> #include "connman.h" @@ -91,150 +92,6 @@ static GHashTable *ipdevice_hash = NULL; static GList *ipconfig_list = NULL; static connman_bool_t is_ipv6_supported = FALSE; -struct connman_ipaddress *connman_ipaddress_alloc(int family) -{ - struct connman_ipaddress *ipaddress; - - ipaddress = g_try_new0(struct connman_ipaddress, 1); - if (ipaddress == NULL) - return NULL; - - ipaddress->family = family; - ipaddress->prefixlen = 0; - ipaddress->local = NULL; - ipaddress->peer = NULL; - ipaddress->broadcast = NULL; - ipaddress->gateway = NULL; - - return ipaddress; -} - -void connman_ipaddress_free(struct connman_ipaddress *ipaddress) -{ - if (ipaddress == NULL) - return; - - g_free(ipaddress->broadcast); - g_free(ipaddress->peer); - g_free(ipaddress->local); - g_free(ipaddress->gateway); - g_free(ipaddress); -} - -unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask) -{ - unsigned char bits; - in_addr_t mask; - in_addr_t host; - - if (netmask == NULL) - return 32; - - mask = inet_network(netmask); - host = ~mask; - - /* a valid netmask must be 2^n - 1 */ - if ((host & (host + 1)) != 0) - return -1; - - bits = 0; - for (; mask; mask <<= 1) - ++bits; - - return bits; -} - -static gboolean check_ipv6_address(const char *address) -{ - unsigned char buf[sizeof(struct in6_addr)]; - int err; - - if (address == NULL) - return FALSE; - - err = inet_pton(AF_INET6, address, buf); - if (err > 0) - return TRUE; - - return FALSE; -} - -int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress, - const char *address, - unsigned char prefix_length, - const char *gateway) -{ - if (ipaddress == NULL) - return -EINVAL; - - if (check_ipv6_address(address) == FALSE) - return -EINVAL; - - DBG("prefix_len %d address %s gateway %s", - prefix_length, address, gateway); - - ipaddress->family = AF_INET6; - - ipaddress->prefixlen = prefix_length; - - g_free(ipaddress->local); - ipaddress->local = g_strdup(address); - - g_free(ipaddress->gateway); - ipaddress->gateway = g_strdup(gateway); - - return 0; -} - -int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress, - const char *address, const char *netmask, const char *gateway) -{ - if (ipaddress == NULL) - return -EINVAL; - - ipaddress->family = AF_INET; - - ipaddress->prefixlen = __connman_ipconfig_netmask_prefix_len(netmask); - - g_free(ipaddress->local); - ipaddress->local = g_strdup(address); - - g_free(ipaddress->gateway); - ipaddress->gateway = g_strdup(gateway); - - return 0; -} - -void connman_ipaddress_set_peer(struct connman_ipaddress *ipaddress, - const char *peer) -{ - if (ipaddress == NULL) - return; - - g_free(ipaddress->peer); - ipaddress->peer = g_strdup(peer); -} - -void connman_ipaddress_clear(struct connman_ipaddress *ipaddress) -{ - if (ipaddress == NULL) - return; - - ipaddress->prefixlen = 0; - - g_free(ipaddress->local); - ipaddress->local = NULL; - - g_free(ipaddress->peer); - ipaddress->peer = NULL; - - g_free(ipaddress->broadcast); - ipaddress->broadcast = NULL; - - g_free(ipaddress->gateway); - ipaddress->gateway = NULL; -} - void __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig) { if (ipconfig == NULL) @@ -243,28 +100,6 @@ void __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig) connman_ipaddress_clear(ipconfig->address); } -void connman_ipaddress_copy(struct connman_ipaddress *ipaddress, - struct connman_ipaddress *source) -{ - if (ipaddress == NULL || source == NULL) - return; - - ipaddress->family = source->family; - ipaddress->prefixlen = source->prefixlen; - - g_free(ipaddress->local); - ipaddress->local = g_strdup(source->local); - - g_free(ipaddress->peer); - ipaddress->peer = g_strdup(source->peer); - - g_free(ipaddress->broadcast); - ipaddress->broadcast = g_strdup(source->broadcast); - - g_free(ipaddress->gateway); - ipaddress->gateway = g_strdup(source->gateway); -} - static void free_address_list(struct connman_ipdevice *ipdevice) { GSList *list; |