Thus it is possible to know our local IP as well as the Peer's remote IP to start contacting it directly. --- src/peer.c | 67 +++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 25 deletions(-)
diff --git a/src/peer.c b/src/peer.c index 81fc1d2..8a9844b 100644 --- a/src/peer.c +++ b/src/peer.c @@ -66,9 +66,12 @@ struct connman_peer { bool connection_master; struct connman_ippool *ip_pool; GDHCPServer *dhcp_server; + uint32_t lease_ip; GSList *services; }; +static void settings_changed(struct connman_peer *peer); + static void stop_dhcp_server(struct connman_peer *peer) { DBG(""); @@ -88,6 +91,24 @@ static void dhcp_server_debug(const char *str, void *data) connman_info("%s: %s\n", (const char *) data, str); } +static void lease_added(unsigned char *mac, uint32_t ip) +{ + GList *list, *start; + + start = list = g_hash_table_get_values(peers_table); + for (; list; list = list->next) { + struct connman_peer *temp = list->data; + + if (!memcmp(temp->iface_address, mac, ETH_ALEN)) { + temp->lease_ip = ip; + settings_changed(temp); + break; + } + } + + g_list_free(start); +} + static gboolean dhcp_server_started(gpointer data) { struct connman_peer *peer = data; @@ -148,6 +169,8 @@ static int start_dhcp_server(struct connman_peer *peer) g_dhcp_server_set_option(peer->dhcp_server, G_DHCP_DNS_SERVER, NULL); g_dhcp_server_set_ip_range(peer->dhcp_server, start_ip, end_ip); + g_dhcp_server_set_lease_added_cb(peer->dhcp_server, lease_added); + err = g_dhcp_server_start(peer->dhcp_server); if (err < 0) goto error; @@ -255,39 +278,33 @@ static bool allow_property_changed(struct connman_peer *peer) return true; } -static void append_dhcp_server_ipv4(DBusMessageIter *iter, void *user_data) +static void append_ipv4(DBusMessageIter *iter, void *user_data) { struct connman_peer *peer = user_data; - const char *str = "dhcp"; - const char *gateway; - const char *subnet; + const char *local = ""; + const char *remote = ""; - if (!peer->ip_pool) + if (!is_connected(peer)) return; - gateway = __connman_ippool_get_gateway(peer->ip_pool); - subnet = __connman_ippool_get_subnet_mask(peer->ip_pool); + if (peer->connection_master) { + char trans[INET_ADDRSTRLEN+1] = {}; + struct in_addr addr; - connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str); - connman_dbus_dict_append_basic(iter, "Address", - DBUS_TYPE_STRING, &gateway); - connman_dbus_dict_append_basic(iter, "Netmask", - DBUS_TYPE_STRING, &subnet); - connman_dbus_dict_append_basic(iter, "Gateway", - DBUS_TYPE_STRING, &gateway); -} + addr.s_addr = peer->lease_ip; + inet_ntop(AF_INET, &addr, trans, INET_ADDRSTRLEN); -static void append_ipv4(DBusMessageIter *iter, void *user_data) -{ - struct connman_peer *peer = user_data; - - if (!is_connected(peer)) - return; + local = __connman_ippool_get_gateway(peer->ip_pool); + remote = trans; + } else if (peer->ipconfig) { + local = __connman_ipconfig_get_local(peer->ipconfig); + remote = __connman_ipconfig_get_gateway(peer->ipconfig); + } - if (peer->connection_master) - append_dhcp_server_ipv4(iter, peer); - else if (peer->ipconfig) - __connman_ipconfig_append_ipv4(peer->ipconfig, iter); + connman_dbus_dict_append_basic(iter, "Local", + DBUS_TYPE_STRING, &local); + connman_dbus_dict_append_basic(iter, "Remote", + DBUS_TYPE_STRING, &remote); } static void append_peer_service(DBusMessageIter *iter, -- 2.0.4 _______________________________________________ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman