device: don't call ioctl to update priv->ip4_address

Just take the first address in priv->ip4_config.

(cherry picked from commit bfb459f8ed)
This commit is contained in:
Beniamino Galvani 2015-08-07 09:33:46 +02:00 committed by Thomas Haller
parent c5569a4e11
commit 97076260ae

View file

@ -75,6 +75,7 @@ _LOG_DECLARE_SELF (NMDevice);
static void impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context);
static void impl_device_delete (NMDevice *self, DBusGMethodInvocation *context);
static void ip_check_ping_watch_cb (GPid pid, gint status, gpointer user_data);
static gboolean ip_config_valid (NMDeviceState state);
static void nm_device_update_metered (NMDevice *self);
#include "nm-device-glue.h"
@ -5940,26 +5941,18 @@ static void
_update_ip4_address (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
struct ifreq req;
guint32 new_address;
int fd;
guint32 addr;
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_DEVICE (self));
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
_LOGE (LOGD_IP4, "couldn't open control socket.");
return;
if ( ip_config_valid (priv->state)
&& nm_ip4_config_get_num_addresses (priv->ip4_config)) {
addr = nm_ip4_config_get_address (priv->ip4_config, 0)->address;
if (addr != priv->ip4_address) {
priv->ip4_address = addr;
g_object_notify (G_OBJECT (self), NM_DEVICE_IP4_ADDRESS);
}
}
memset (&req, 0, sizeof (struct ifreq));
strncpy (req.ifr_name, nm_device_get_ip_iface (self), IFNAMSIZ);
if (ioctl (fd, SIOCGIFADDR, &req) == 0) {
new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
if (new_address != priv->ip4_address)
priv->ip4_address = new_address;
}
close (fd);
}
gboolean