- 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;
-
- if (check_ipv6_address(gateway) == 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_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);