platform: add wrappers for if_nametoindex() and if_indextoname()

This commit is contained in:
Thomas Haller 2016-12-26 11:54:30 +01:00
parent d481489804
commit e8d5a8356c
4 changed files with 44 additions and 0 deletions

View file

@ -38,7 +38,29 @@
#include "nm-core-utils.h"
/******************************************************************
* utils
******************************************************************/
extern char *if_indextoname (unsigned int __ifindex, char *__ifname);
unsigned int if_nametoindex (const char *__ifname);
const char *
nmp_utils_if_indextoname (int ifindex, char *out_ifname/*IFNAMSIZ*/)
{
g_return_val_if_fail (ifindex > 0, NULL);
g_return_val_if_fail (out_ifname, NULL);
return if_indextoname (ifindex, out_ifname);
}
int
nmp_utils_if_nametoindex (const char *ifname)
{
g_return_val_if_fail (ifname, 0);
return if_nametoindex (ifname);
}
/******************************************************************
* ethtool

View file

@ -74,6 +74,9 @@ NMIPConfigSource nmp_utils_ip_config_source_coerce_from_rtprot (NMIPConfigSource
NMIPConfigSource nmp_utils_ip_config_source_round_trip_rtprot (NMIPConfigSource source) _nm_const;
const char * nmp_utils_ip_config_source_to_string (NMIPConfigSource source, char *buf, gsize len);
const char *nmp_utils_if_indextoname (int ifindex, char *out_ifname/*IFNAMSIZ*/);
int nmp_utils_if_nametoindex (const char *ifname);
int nmp_utils_sysctl_open_netdir (int ifindex,
const char *ifname_guess,
char *out_ifname);

View file

@ -770,6 +770,22 @@ nm_platform_link_get_ifindex (NMPlatform *self, const char *name)
return pllink ? pllink->ifindex : 0;
}
const char *
nm_platform_if_indextoname (NMPlatform *self, int ifindex, char *out_ifname/* of size IFNAMSIZ */)
{
_CHECK_SELF_NETNS (self, klass, netns, FALSE);
return nmp_utils_if_indextoname (ifindex, out_ifname);
}
int
nm_platform_if_nametoindex (NMPlatform *self, const char *ifname)
{
_CHECK_SELF_NETNS (self, klass, netns, FALSE);
return nmp_utils_if_nametoindex (ifname);
}
/**
* nm_platform_link_get_name:
* @self: platform instance

View file

@ -738,6 +738,9 @@ gint64 nm_platform_sysctl_get_int_checked (NMPlatform *self, const char *pathid,
gboolean nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char *iface, int value);
const char *nm_platform_if_indextoname (NMPlatform *self, int ifindex, char *out_ifname/* of size IFNAMSIZ */);
int nm_platform_if_nametoindex (NMPlatform *self, const char *ifname);
const NMPlatformLink *nm_platform_link_get (NMPlatform *self, int ifindex);
const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const char *ifname);
const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length);