Compare commits
1
Commits
befee319b4
...
beeos
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d00f3ccde2
|
@@ -24,6 +24,58 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static gboolean
|
||||
read_sysfs_int (const gchar *path,
|
||||
gint *value)
|
||||
{
|
||||
g_autofree gchar *contents = NULL;
|
||||
gchar *end = NULL;
|
||||
gint64 parsed;
|
||||
|
||||
if (!g_file_get_contents (path, &contents, NULL, NULL))
|
||||
return FALSE;
|
||||
parsed = g_ascii_strtoll (contents, &end, 10);
|
||||
if (end == contents)
|
||||
return FALSE;
|
||||
*value = (gint) parsed;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Net devices stacked by drivers that create no lower_* adjacency links (e.g. rmnet on Android vendor
|
||||
* kernels) still report the parent's interface index in 'iflink'. */
|
||||
static gchar *
|
||||
get_lower_device_name_by_iflink (const gchar *sysfs_path)
|
||||
{
|
||||
g_autofree gchar *ifindex_path = NULL;
|
||||
g_autofree gchar *iflink_path = NULL;
|
||||
g_autoptr(GDir) dir = NULL;
|
||||
const gchar *name;
|
||||
gint ifindex;
|
||||
gint iflink;
|
||||
|
||||
ifindex_path = g_build_filename (sysfs_path, "ifindex", NULL);
|
||||
iflink_path = g_build_filename (sysfs_path, "iflink", NULL);
|
||||
if (!read_sysfs_int (ifindex_path, &ifindex) ||
|
||||
!read_sysfs_int (iflink_path, &iflink) ||
|
||||
iflink == ifindex || iflink <= 0)
|
||||
return NULL;
|
||||
|
||||
dir = g_dir_open ("/sys/class/net", 0, NULL);
|
||||
if (!dir)
|
||||
return NULL;
|
||||
|
||||
while ((name = g_dir_read_name (dir)) != NULL) {
|
||||
g_autofree gchar *path = NULL;
|
||||
gint index;
|
||||
|
||||
path = g_build_filename ("/sys/class/net", name, "ifindex", NULL);
|
||||
if (read_sysfs_int (path, &index) && index == iflink)
|
||||
return g_strdup (name);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar *
|
||||
mm_kernel_device_get_lower_device_name (const gchar *sysfs_path)
|
||||
{
|
||||
@@ -60,7 +112,7 @@ mm_kernel_device_get_lower_device_name (const gchar *sysfs_path)
|
||||
return g_path_get_basename (real_path);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return get_lower_device_name_by_iflink (sysfs_path);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user