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:
@@ -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>
|
2005-12-01 Robert Love <rml@novell.com>
|
||||||
|
|
||||||
* gnome/applet/main.c, gnome/vpn-properties/nm-vpn-properties.c: We
|
* gnome/applet/main.c, gnome/vpn-properties/nm-vpn-properties.c: We
|
||||||
|
@@ -37,6 +37,9 @@
|
|||||||
#include "NetworkManagerUtils.h"
|
#include "NetworkManagerUtils.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
|
||||||
|
#include <netlink/addr.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
|
||||||
struct NMSock
|
struct NMSock
|
||||||
{
|
{
|
||||||
@@ -661,3 +664,34 @@ gchar *nm_utils_inet_ip4_address_as_string (guint32 ip)
|
|||||||
return g_strdup (ip_string);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -100,6 +100,10 @@ gboolean nm_completion_boolean_function2_test(int tries,
|
|||||||
nm_completion_args args);
|
nm_completion_args args);
|
||||||
#define nm_completion_boolean_function_test nm_completion_boolean_function1_test
|
#define nm_completion_boolean_function_test nm_completion_boolean_function1_test
|
||||||
|
|
||||||
gchar* nm_utils_inet_ip4_address_as_string (guint32 ip);
|
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
|
#endif
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "NetworkManager.h"
|
#include "NetworkManager.h"
|
||||||
|
#include "NetworkManagerUtils.h"
|
||||||
#include "nm-ip4-config.h"
|
#include "nm-ip4-config.h"
|
||||||
|
|
||||||
#include <netlink/route/addr.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);
|
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)
|
static int ip4_addr_to_rtnl_local (guint32 ip4_address, struct rtnl_addr *addr)
|
||||||
{
|
{
|
||||||
struct nl_addr * local = NULL;
|
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);
|
g_return_val_if_fail (addr != NULL, -1);
|
||||||
|
|
||||||
local = nl_addr_alloc (sizeof (in_addr_t));
|
local = nm_utils_ip4_addr_to_nl_addr (ip4_address);
|
||||||
nl_addr_set_family (local, AF_INET);
|
|
||||||
nl_addr_set_binary_addr (local, &ip4_address, sizeof (guint32));
|
|
||||||
|
|
||||||
err = rtnl_addr_set_local (addr, local);
|
err = rtnl_addr_set_local (addr, local);
|
||||||
|
|
||||||
nl_addr_put (local);
|
nl_addr_put (local);
|
||||||
|
|
||||||
return err;
|
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);
|
g_return_val_if_fail (addr != NULL, -1);
|
||||||
|
|
||||||
peer = nl_addr_alloc (sizeof (in_addr_t));
|
peer = nm_utils_ip4_addr_to_nl_addr (ip4_address);
|
||||||
nl_addr_set_family (peer, AF_INET);
|
|
||||||
nl_addr_set_binary_addr (peer, &ip4_address, sizeof (guint32));
|
|
||||||
|
|
||||||
err = rtnl_addr_set_peer (addr, peer);
|
err = rtnl_addr_set_peer (addr, peer);
|
||||||
|
|
||||||
nl_addr_put (peer);
|
nl_addr_put (peer);
|
||||||
|
|
||||||
return err;
|
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);
|
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)
|
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);
|
g_return_val_if_fail (addr != NULL, -1);
|
||||||
|
|
||||||
local = nl_addr_alloc (sizeof (in_addr_t));
|
local = nm_utils_ip4_addr_to_nl_addr (ip4_broadcast);
|
||||||
nl_addr_set_family (local, AF_INET);
|
|
||||||
nl_addr_set_binary_addr (local, &ip4_broadcast, sizeof (guint32));
|
|
||||||
|
|
||||||
err = rtnl_addr_set_broadcast (addr, local);
|
err = rtnl_addr_set_broadcast (addr, local);
|
||||||
|
|
||||||
nl_addr_put (local);
|
nl_addr_put (local);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user