core: add nm_utils_ip4_property_path()
This commit is contained in:
@@ -2156,6 +2156,32 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/"
|
||||||
|
#define IPV4_PROPERTY_DIR "/proc/sys/net/ipv4/conf/"
|
||||||
|
G_STATIC_ASSERT (sizeof (IPV4_PROPERTY_DIR) == sizeof (IPV6_PROPERTY_DIR));
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
_get_property_path (const char *ifname,
|
||||||
|
const char *property,
|
||||||
|
gboolean ipv6)
|
||||||
|
{
|
||||||
|
static char path[sizeof (IPV6_PROPERTY_DIR) + IFNAMSIZ + 32];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
ifname = ASSERT_VALID_PATH_COMPONENT (ifname);
|
||||||
|
property = ASSERT_VALID_PATH_COMPONENT (property);
|
||||||
|
|
||||||
|
len = g_snprintf (path,
|
||||||
|
sizeof (path),
|
||||||
|
"%s%s/%s",
|
||||||
|
ipv6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR,
|
||||||
|
ifname,
|
||||||
|
property);
|
||||||
|
g_assert (len < sizeof (path) - 1);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_utils_ip6_property_path:
|
* nm_utils_ip6_property_path:
|
||||||
* @ifname: an interface name
|
* @ifname: an interface name
|
||||||
@@ -2167,18 +2193,21 @@ out:
|
|||||||
const char *
|
const char *
|
||||||
nm_utils_ip6_property_path (const char *ifname, const char *property)
|
nm_utils_ip6_property_path (const char *ifname, const char *property)
|
||||||
{
|
{
|
||||||
#define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/"
|
return _get_property_path (ifname, property, TRUE);
|
||||||
static char path[sizeof (IPV6_PROPERTY_DIR) + IFNAMSIZ + 32];
|
}
|
||||||
int len;
|
|
||||||
|
|
||||||
ifname = ASSERT_VALID_PATH_COMPONENT (ifname);
|
/**
|
||||||
property = ASSERT_VALID_PATH_COMPONENT (property);
|
* nm_utils_ip4_property_path:
|
||||||
|
* @ifname: an interface name
|
||||||
len = g_snprintf (path, sizeof (path), IPV6_PROPERTY_DIR "%s/%s",
|
* @property: a property name
|
||||||
ifname, property);
|
*
|
||||||
g_assert (len < sizeof (path) - 1);
|
* Returns the path to IPv4 property @property on @ifname. Note that
|
||||||
|
* this uses a static buffer.
|
||||||
return path;
|
*/
|
||||||
|
const char *
|
||||||
|
nm_utils_ip4_property_path (const char *ifname, const char *property)
|
||||||
|
{
|
||||||
|
return _get_property_path (ifname, property, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@@ -168,6 +168,7 @@ gint32 nm_utils_get_monotonic_timestamp_s (void);
|
|||||||
|
|
||||||
const char *ASSERT_VALID_PATH_COMPONENT (const char *name) G_GNUC_WARN_UNUSED_RESULT;
|
const char *ASSERT_VALID_PATH_COMPONENT (const char *name) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
const char *nm_utils_ip6_property_path (const char *ifname, const char *property);
|
const char *nm_utils_ip6_property_path (const char *ifname, const char *property);
|
||||||
|
const char *nm_utils_ip4_property_path (const char *ifname, const char *property);
|
||||||
|
|
||||||
gboolean nm_utils_is_specific_hostname (const char *name);
|
gboolean nm_utils_is_specific_hostname (const char *name);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user