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

@@ -1,3 +1,10 @@
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()
2005-12-01 Robert Love <rml@novell.com>
* gnome/applet/main.c, gnome/vpn-properties/nm-vpn-properties.c: We

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));
}

View File

@@ -102,4 +102,8 @@ gboolean nm_completion_boolean_function2_test(int tries,
gchar* nm_utils_inet_ip4_address_as_string (guint32 ip);
struct nl_addr * nm_utils_ip4_addr_to_nl_addr (guint32 ip4_addr);
int nm_utils_ip4_netmask_to_prefix (guint32 ip4_netmask);
#endif

View File

@@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
#include "NetworkManager.h"
#include "NetworkManagerUtils.h"
#include "nm-ip4-config.h"
#include <netlink/route/addr.h>
@@ -238,24 +239,6 @@ guint32 nm_ip4_config_get_num_domains (NMIP4Config *config)
extern void rtnl_addr_set_prefixlen (struct rtnl_addr *, int);
/*
* ip4_netmask_to_prefix
*
* Figure out the network prefix from a netmask. Netmask
* MUST be in network byte order.
*
*/
static int 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));
}
static int ip4_addr_to_rtnl_local (guint32 ip4_address, struct rtnl_addr *addr)
{
struct nl_addr * local = NULL;
@@ -263,13 +246,10 @@ static int ip4_addr_to_rtnl_local (guint32 ip4_address, struct rtnl_addr *addr)
g_return_val_if_fail (addr != NULL, -1);
local = nl_addr_alloc (sizeof (in_addr_t));
nl_addr_set_family (local, AF_INET);
nl_addr_set_binary_addr (local, &ip4_address, sizeof (guint32));
local = nm_utils_ip4_addr_to_nl_addr (ip4_address);
err = rtnl_addr_set_local (addr, local);
nl_addr_put (local);
return err;
}
@@ -280,13 +260,10 @@ static int ip4_addr_to_rtnl_peer (guint32 ip4_address, struct rtnl_addr *addr)
g_return_val_if_fail (addr != NULL, -1);
peer = nl_addr_alloc (sizeof (in_addr_t));
nl_addr_set_family (peer, AF_INET);
nl_addr_set_binary_addr (peer, &ip4_address, sizeof (guint32));
peer = nm_utils_ip4_addr_to_nl_addr (ip4_address);
err = rtnl_addr_set_peer (addr, peer);
nl_addr_put (peer);
return err;
}
@@ -294,7 +271,7 @@ static void ip4_addr_to_rtnl_prefixlen (guint32 ip4_netmask, struct rtnl_addr *a
{
g_return_if_fail (addr != NULL);
rtnl_addr_set_prefixlen (addr,ip4_netmask_to_prefix (ip4_netmask));
rtnl_addr_set_prefixlen (addr, nm_utils_ip4_netmask_to_prefix (ip4_netmask));
}
static int ip4_addr_to_rtnl_broadcast (guint32 ip4_broadcast, struct rtnl_addr *addr)
@@ -304,13 +281,10 @@ static int ip4_addr_to_rtnl_broadcast (guint32 ip4_broadcast, struct rtnl_addr *
g_return_val_if_fail (addr != NULL, -1);
local = nl_addr_alloc (sizeof (in_addr_t));
nl_addr_set_family (local, AF_INET);
nl_addr_set_binary_addr (local, &ip4_broadcast, sizeof (guint32));
local = nm_utils_ip4_addr_to_nl_addr (ip4_broadcast);
err = rtnl_addr_set_broadcast (addr, local);
nl_addr_put (local);
return err;
}