diff options
Diffstat (limited to 'src/mbimcli/mbimcli-helpers.c')
-rw-r--r-- | src/mbimcli/mbimcli-helpers.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/mbimcli/mbimcli-helpers.c b/src/mbimcli/mbimcli-helpers.c index aa37d5a..21aea9b 100644 --- a/src/mbimcli/mbimcli-helpers.c +++ b/src/mbimcli/mbimcli-helpers.c @@ -47,3 +47,145 @@ mbimcli_read_uint_from_string (const gchar *str, } return FALSE; } + + +gboolean +mbimcli_print_ip_config (MbimDevice *device, + MbimMessage *response, + GError **error) +{ + MbimIPConfigurationAvailableFlag ipv4configurationavailable; + MbimIPConfigurationAvailableFlag ipv6configurationavailable; + guint32 ipv4addresscount; + MbimIPv4Element **ipv4address; + guint32 ipv6addresscount; + MbimIPv6Element **ipv6address; + const MbimIPv4 *ipv4gateway; + const MbimIPv6 *ipv6gateway; + guint32 ipv4dnsservercount; + MbimIPv4 *ipv4dnsserver; + guint32 ipv6dnsservercount; + MbimIPv6 *ipv6dnsserver; + guint32 ipv4mtu; + guint32 ipv6mtu; + gchar *str; + GInetAddress *addr; + + if (!mbim_message_ip_configuration_response_parse ( + response, + NULL, /* sessionid */ + &ipv4configurationavailable, + &ipv6configurationavailable, + &ipv4addresscount, + &ipv4address, + &ipv6addresscount, + &ipv6address, + &ipv4gateway, + &ipv6gateway, + &ipv4dnsservercount, + &ipv4dnsserver, + &ipv6dnsservercount, + &ipv6dnsserver, + &ipv4mtu, + &ipv6mtu, + error)) + return FALSE; + + /* IPv4 info */ + + str = mbim_ip_configuration_available_flag_build_string_from_mask (ipv4configurationavailable); + g_print ("\n[%s] IPv4 configuration available: '%s'\n", mbim_device_get_path_display (device), str); + g_free (str); + + if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) { + guint i; + + for (i = 0; i < ipv4addresscount; i++) { + addr = g_inet_address_new_from_bytes ((guint8 *)&ipv4address[i]->ipv4_address, G_SOCKET_FAMILY_IPV4); + str = g_inet_address_to_string (addr); + g_print (" IP [%u]: '%s/%u'\n", + i, + str, + ipv4address[i]->on_link_prefix_length); + g_free (str); + g_object_unref (addr); + } + } + + if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) { + addr = g_inet_address_new_from_bytes ((guint8 *)ipv4gateway, G_SOCKET_FAMILY_IPV4); + str = g_inet_address_to_string (addr); + g_print (" Gateway: '%s'\n", str); + g_free (str); + g_object_unref (addr); + } + + if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) { + guint i; + + for (i = 0; i < ipv4dnsservercount; i++) { + addr = g_inet_address_new_from_bytes ((guint8 *)&ipv4dnsserver[i], G_SOCKET_FAMILY_IPV4); + if (!g_inet_address_get_is_any (addr)) { + str = g_inet_address_to_string (addr); + g_print (" DNS [%u]: '%s'\n", i, str); + g_free (str); + } + g_object_unref (addr); + } + } + + if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) + g_print (" MTU: '%u'\n", ipv4mtu); + + /* IPv6 info */ + str = mbim_ip_configuration_available_flag_build_string_from_mask (ipv6configurationavailable); + g_print ("\n[%s] IPv6 configuration available: '%s'\n", mbim_device_get_path_display (device), str); + g_free (str); + + if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) { + guint i; + + for (i = 0; i < ipv6addresscount; i++) { + addr = g_inet_address_new_from_bytes ((guint8 *)&ipv6address[i]->ipv6_address, G_SOCKET_FAMILY_IPV6); + str = g_inet_address_to_string (addr); + g_print (" IP [%u]: '%s/%u'\n", + i, + str, + ipv6address[i]->on_link_prefix_length); + g_free (str); + g_object_unref (addr); + } + } + + if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) { + addr = g_inet_address_new_from_bytes ((guint8 *)ipv6gateway, G_SOCKET_FAMILY_IPV6); + str = g_inet_address_to_string (addr); + g_print (" Gateway: '%s'\n", str); + g_free (str); + g_object_unref (addr); + } + + if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) { + guint i; + + for (i = 0; i < ipv6dnsservercount; i++) { + addr = g_inet_address_new_from_bytes ((guint8 *)&ipv6dnsserver[i], G_SOCKET_FAMILY_IPV6); + if (!g_inet_address_get_is_any (addr)) { + str = g_inet_address_to_string (addr); + g_print (" DNS [%u]: '%s'\n", i, str); + g_free (str); + } + g_object_unref (addr); + } + } + + if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) + g_print (" MTU: '%u'\n", ipv6mtu); + + mbim_ipv4_element_array_free (ipv4address); + mbim_ipv6_element_array_free (ipv6address); + g_free (ipv4dnsserver); + g_free (ipv6dnsserver); + return TRUE; +} + |