include/resolver.h include/ipconfig.h \
include/device.h include/network.h include/inet.h \
include/storage.h include/provision.h \
- include/session.h
+ include/session.h include/ipaddress.h
nodist_include_HEADERS = include/version.h
src/technology.c src/counter.c src/ntp.c \
src/session.c src/tethering.c src/wpad.c src/wispr.c \
src/stats.c src/iptables.c src/dnsproxy.c src/6to4.c \
- src/ippool.c src/bridge.c src/nat.c
+ src/ippool.c src/bridge.c src/nat.c src/ipaddress.c
src_connmand_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ \
@XTABLES_LIBS@ @GNUTLS_LIBS@ -lresolv -ldl -lrt
--- /dev/null
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __CONNMAN_IPADDRESS_H
+#define __CONNMAN_IPADDRESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:ipaddress
+ * @title: IP address premitives
+ * @short_description: Functions for IP address handling
+ */
+
+struct connman_ipaddress;
+
+struct connman_ipaddress *connman_ipaddress_alloc(int family);
+void connman_ipaddress_free(struct connman_ipaddress *ipaddress);
+int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
+ const char *address, const char *netmask,
+ const char *gateway);
+int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
+ const char *address,
+ unsigned char prefix_length,
+ const char *gateway);
+void connman_ipaddress_set_peer(struct connman_ipaddress *ipaddress,
+ const char *peer);
+void connman_ipaddress_clear(struct connman_ipaddress *ipaddress);
+void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
+ struct connman_ipaddress *source);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_IPADDRESS_H */
#ifndef __CONNMAN_IPCONFIG_H
#define __CONNMAN_IPCONFIG_H
+#include <connman/ipaddress.h>
+
#ifdef __cplusplus
extern "C" {
#endif
* @short_description: Functions for IP configuration handling
*/
-struct connman_ipaddress;
-
-struct connman_ipaddress *connman_ipaddress_alloc(int family);
-void connman_ipaddress_free(struct connman_ipaddress *ipaddress);
-int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
- const char *address, const char *netmask,
- const char *gateway);
-int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
- const char *address,
- unsigned char prefix_length,
- const char *gateway);
-void connman_ipaddress_set_peer(struct connman_ipaddress *ipaddress,
- const char *peer);
-void connman_ipaddress_clear(struct connman_ipaddress *ipaddress);
-void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
- struct connman_ipaddress *source);
-
enum connman_ipconfig_type {
CONNMAN_IPCONFIG_TYPE_UNKNOWN = 0,
CONNMAN_IPCONFIG_TYPE_ALL = 0,
int __connman_ipconfig_address_unset(struct connman_ipconfig *ipconfig);
int __connman_ipconfig_gateway_add(struct connman_ipconfig *ipconfig);
void __connman_ipconfig_gateway_remove(struct connman_ipconfig *ipconfig);
-unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask);
+unsigned char __connman_ipaddress_netmask_prefix_len(const char *netmask);
int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig,
const char *url);
if (option != NULL)
gateway = g_strdup(option->data);
- prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
+ prefixlen = __connman_ipaddress_netmask_prefix_len(netmask);
if (prefixlen == 255)
connman_warn("netmask: %s is invalid", netmask);
address = g_dhcp_client_get_address(dhcp_client);
netmask = g_dhcp_client_get_netmask(dhcp_client);
- prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
+ prefixlen = __connman_ipaddress_netmask_prefix_len(netmask);
__connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_DHCP);
__connman_ipconfig_set_local(ipconfig, address);
--- /dev/null
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include <connman/ipaddress.h>
+
+#include "connman.h"
+
+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_ipaddress_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_ipaddress_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);
+}
#endif
#include <gdbus.h>
+#include <connman/ipaddress.h>
#include "connman.h"
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)
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;
}
prefixlen =
- __connman_ipconfig_netmask_prefix_len(subnet_mask);
+ __connman_ipaddress_netmask_prefix_len(subnet_mask);
__connman_nat_enable(BRIDGE_NAME, start_ip, prefixlen);
DBG("tethering started");
server_ip = __connman_ippool_get_start_ip(pn->pool);
peer_ip = __connman_ippool_get_end_ip(pn->pool);
prefixlen =
- __connman_ipconfig_netmask_prefix_len(subnet_mask);
+ __connman_ipaddress_netmask_prefix_len(subnet_mask);
if ((__connman_inet_modify_address(RTM_NEWADDR,
NLM_F_REPLACE | NLM_F_ACK, pn->index, AF_INET,