Skip to content

Instantly share code, notes, and snippets.

@pridybailo-n
Last active July 19, 2018 11:48
Show Gist options
  • Save pridybailo-n/2f8d2f76ef6a2be6fa6c861862573c35 to your computer and use it in GitHub Desktop.
Save pridybailo-n/2f8d2f76ef6a2be6fa6c861862573c35 to your computer and use it in GitHub Desktop.
get IPv4 configuration via connman dbus
int main()
{
ConnmanProxyService *sproxy;
GError *error;
error = NULL;
sproxy = connman_proxy_service_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
"net.connman", "/net/connman/service/ethernet_bcaec5b96673_cable", NULL, &error);
GVariant *props;
connman_proxy_service_call_get_properties_sync(sproxy, &props, NULL, &error);
GVariantIter *iter;
iter = g_variant_iter_new (props);
GVariant *opt;
GVariant *val;
while (g_variant_iter_loop (iter, "{sv}", &opt,
&val))
{
GVariant *opt_ip = g_variant_new("s", "IPv4");
GVariant *sopt = g_variant_new("s", opt);
if (!g_variant_compare((gconstpointer)opt_ip, (gconstpointer)sopt)) {
const gchar *v_option;
GVariant *v_value;
GVariantIter *v_iter = g_variant_iter_new(val);
gchar *result;
g_variant_get (sopt, "s", &result);
g_print ("'%s' \n", result);
while (g_variant_iter_loop (v_iter, "{sv}", &v_option,
&v_value)) {
gchar* value;
g_variant_get(v_value, "&s", &value);
g_print("\t%s: ", v_option);
g_print("%s \n", value);
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment