core: const-ify nm_device_wired_get_hwaddr()

This commit is contained in:
Dan Williams 2012-02-21 15:03:46 -06:00
parent 74ec56d956
commit 0109ed62e9
6 changed files with 52 additions and 23 deletions

View file

@ -92,7 +92,8 @@ device_state_changed (NMDevice *device,
static void
real_update_hw_address (NMDevice *dev)
{
guint8 *hw_addr, old_addr[NM_UTILS_HWADDR_LEN_MAX];
const guint8 *hw_addr;
guint8 old_addr[NM_UTILS_HWADDR_LEN_MAX];
int addrtype, addrlen;
addrtype = nm_device_wired_get_hwaddr_type (NM_DEVICE_WIRED (dev));
@ -329,7 +330,7 @@ static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
guint8 *current_addr;
const guint8 *current_addr;
switch (prop_id) {
case PROP_HW_ADDRESS:

View file

@ -397,14 +397,13 @@ nm_device_ethernet_new (const char *udi,
static void
_update_hw_addr (NMDeviceEthernet *self, const guint8 *addr)
{
guint8 *current_addr;
const guint8 *current_addr;
g_return_if_fail (addr != NULL);
current_addr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (self));
if (memcmp (current_addr, addr, ETH_ALEN)) {
memcpy (current_addr, addr, ETH_ALEN);
nm_device_wired_set_hwaddr (NM_DEVICE_WIRED (self), addr, ETH_ALEN);
g_object_notify (G_OBJECT (self), NM_DEVICE_ETHERNET_HW_ADDRESS);
}
}
@ -413,7 +412,7 @@ static gboolean
_set_hw_addr (NMDeviceEthernet *self, const guint8 *addr, const char *detail)
{
NMDevice *dev = NM_DEVICE (self);
guint8 *current_addr;
const guint8 *current_addr;
const char *iface;
char *mac_str = NULL;
gboolean success = FALSE;
@ -454,7 +453,8 @@ _set_hw_addr (NMDeviceEthernet *self, const guint8 *addr, const char *detail)
static void
real_update_hw_address (NMDevice *dev)
{
guint8 *hw_addr, old_addr[ETH_ALEN];
const guint8 *hw_addr;
guint8 old_addr[ETH_ALEN];
hw_addr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (dev));
memcpy (old_addr, hw_addr, ETH_ALEN);
@ -493,7 +493,7 @@ real_update_permanent_hw_address (NMDevice *dev)
errno = 0;
ret = ioctl (fd, SIOCETHTOOL, &req);
if ((ret < 0) || !nm_ethernet_address_is_valid ((struct ether_addr *) epaddr->data)) {
guint8 *current_addr;
const guint8 *current_addr;
nm_log_err (LOGD_HW | LOGD_ETHER, "(%s): unable to read permanent MAC address (error %d)",
nm_device_get_iface (dev), errno);
@ -515,7 +515,7 @@ real_update_initial_hw_address (NMDevice *dev)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
guint8 *current_addr;
const guint8 *current_addr;
char *mac_str = NULL;
guint8 *addr = priv->initial_hw_addr;
guint8 zero[ETH_ALEN] = {0,0,0,0,0,0};
@ -1564,7 +1564,7 @@ get_property (GObject *object, guint prop_id,
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (object);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
guint8 *current_addr;
const guint8 *current_addr;
switch (prop_id) {
case PROP_HW_ADDRESS:

View file

@ -124,7 +124,8 @@ nm_device_infiniband_new (const char *udi,
static void
real_update_hw_address (NMDevice *dev)
{
guint8 *hw_addr, old_addr[INFINIBAND_ALEN];
const guint8 *hw_addr;
guint8 old_addr[INFINIBAND_ALEN];
hw_addr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (dev));
memcpy (old_addr, hw_addr, INFINIBAND_ALEN);
@ -167,7 +168,7 @@ real_get_best_auto_connection (NMDevice *dev,
continue;
if (s_infiniband) {
guint8 *hwaddr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (dev));
const guint8 *hwaddr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (dev));
const GByteArray *mac;
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
@ -270,7 +271,7 @@ real_check_connection_compatible (NMDevice *device,
}
if (s_infiniband) {
guint8 *hwaddr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (device));
const guint8 *hwaddr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (device));
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
if (mac && memcmp (mac->data, hwaddr, INFINIBAND_ALEN)) {
@ -294,7 +295,7 @@ real_complete_connection (NMDevice *device,
{
NMSettingInfiniband *s_infiniband;
const GByteArray *setting_mac;
guint8 *hwaddr;
const guint8 *hwaddr;
nm_utils_complete_generic (connection,
NM_SETTING_INFINIBAND_SETTING_NAME,
@ -424,7 +425,7 @@ static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
guint8 *current_addr;
const guint8 *current_addr;
switch (prop_id) {
case PROP_HW_ADDRESS:

View file

@ -564,9 +564,9 @@ nm_device_wired_class_init (NMDeviceWiredClass *klass)
*
* Get a device's hardware address
*
* Return value: (transfer none): @dev's hardware address
* Returns: (transfer none): @dev's hardware address
*/
guint8 *
const guint8 *
nm_device_wired_get_hwaddr (NMDeviceWired *dev)
{
NMDeviceWiredPrivate *priv;
@ -577,13 +577,37 @@ nm_device_wired_get_hwaddr (NMDeviceWired *dev)
return priv->hw_addr;
}
/**
* nm_device_wired_set_hwaddr:
* @dev: an #NMDeviceWired
* @addr: the new hardware address, @addrlen bytes in length
* @addrlen: the length in bytes of @addr
*
* Sets the device's hardware address.
*/
void
nm_device_wired_set_hwaddr (NMDeviceWired *dev,
const guint8 *addr,
guint addrlen)
{
NMDeviceWiredPrivate *priv;
g_return_if_fail (dev != NULL);
g_return_if_fail (addr != NULL);
priv = NM_DEVICE_WIRED_GET_PRIVATE (dev);
g_return_if_fail (addrlen == priv->hw_addr_len);
memcpy (priv->hw_addr, addr, priv->hw_addr_len);
}
/**
* nm_device_wired_get_hwaddr_type:
* @dev: an #NMDeviceWired
*
* Get the type of a device's hardware address
*
* Return value: the type of @dev's hardware address
* Returns: the type of @dev's hardware address
*/
int
nm_device_wired_get_hwaddr_type (NMDeviceWired *dev)

View file

@ -46,10 +46,13 @@ typedef struct {
GType nm_device_wired_get_type (void);
guint8 *nm_device_wired_get_hwaddr (NMDeviceWired *dev);
int nm_device_wired_get_hwaddr_type (NMDeviceWired *dev);
gboolean nm_device_wired_get_carrier (NMDeviceWired *dev);
guint32 nm_device_wired_get_speed (NMDeviceWired *dev);
const guint8 *nm_device_wired_get_hwaddr (NMDeviceWired *dev);
void nm_device_wired_set_hwaddr (NMDeviceWired *dev,
const guint8 *addr,
guint addrlen);
int nm_device_wired_get_hwaddr_type (NMDeviceWired *dev);
gboolean nm_device_wired_get_carrier (NMDeviceWired *dev);
guint32 nm_device_wired_get_speed (NMDeviceWired *dev);
G_END_DECLS

View file

@ -1508,7 +1508,7 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GByteArray *mac = NULL;
guint8 *hwaddr;
const guint8 *hwaddr;
int hwaddr_type;
NMDefaultWiredConnection *wired;
gboolean read_only = TRUE;