diff options
author | Dan Williams <dcbw@redhat.com> | 2014-10-30 18:59:10 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2014-11-07 12:18:33 -0600 |
commit | 7df18cba5bfae1ae1ccd87d574dfd2acd9c86e83 (patch) | |
tree | 9b637d86c5e2213c2f5c0a2ca194f57efe1a2965 | |
parent | 49cac9f32f5eb31698687216dd8e26b4b49629d8 (diff) | |
download | NetworkManager-7df18cba5bfae1ae1ccd87d574dfd2acd9c86e83.tar.gz |
core: add nm_utils_ip4_property_path()
-rw-r--r-- | src/NetworkManagerUtils.c | 51 | ||||
-rw-r--r-- | src/NetworkManagerUtils.h | 1 |
2 files changed, 41 insertions, 11 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 538295a10c..0dcd643bf3 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -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: * @ifname: an interface name @@ -2167,18 +2193,21 @@ out: const char * nm_utils_ip6_property_path (const char *ifname, const char *property) { -#define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/" - 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), IPV6_PROPERTY_DIR "%s/%s", - ifname, property); - g_assert (len < sizeof (path) - 1); + return _get_property_path (ifname, property, TRUE); +} - return path; +/** + * nm_utils_ip4_property_path: + * @ifname: an interface name + * @property: a property name + * + * Returns the path to IPv4 property @property on @ifname. Note that + * this uses a static buffer. + */ +const char * +nm_utils_ip4_property_path (const char *ifname, const char *property) +{ + return _get_property_path (ifname, property, FALSE); } const char * diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index 492edd133e..0ed7587a63 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -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 *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); |