2005-12-03 Dan Williams <dcbw@redhat.com>

* src/NetworkManagerUtils.[ch]
	  src/nm-ip4-config.c
		- move ip4_netmask_to_prefix() to NetworkManagerUtils.c
		- consolidate code into nm_utils_ip4_addr_to_nl_addr()


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1116 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2005-12-04 02:23:29 +00:00
parent cafa5878fc
commit 1d8201cb9e
4 changed files with 54 additions and 35 deletions

View File

@@ -37,6 +37,9 @@
#include "NetworkManagerUtils.h"
#include "nm-utils.h"
#include <netlink/addr.h>
#include <netinet/in.h>
struct NMSock
{
@@ -661,3 +664,34 @@ gchar *nm_utils_inet_ip4_address_as_string (guint32 ip)
return g_strdup (ip_string);
}
struct nl_addr * nm_utils_ip4_addr_to_nl_addr (guint32 ip4_addr)
{
struct nl_addr * nla = NULL;
if (!(nla = nl_addr_alloc (sizeof (in_addr_t))))
return NULL;
nl_addr_set_family (nla, AF_INET);
nl_addr_set_binary_addr (nla, &ip4_addr, sizeof (guint32));
return nla;
}
/*
* nm_utils_ip4_netmask_to_prefix
*
* Figure out the network prefix from a netmask. Netmask
* MUST be in network byte order.
*
*/
int nm_utils_ip4_netmask_to_prefix (guint32 ip4_netmask)
{
int i = 1;
/* Just count how many bit shifts we need */
ip4_netmask = ntohl (ip4_netmask);
while (!(ip4_netmask & 0x1) && ++i)
ip4_netmask = ip4_netmask >> 1;
return (32 - (i-1));
}