From 97076260ae15698535de37f6a4e30b1917876ccb Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 7 Aug 2015 09:33:46 +0200 Subject: [PATCH] device: don't call ioctl to update priv->ip4_address Just take the first address in priv->ip4_config. (cherry picked from commit bfb459f8edd1b5ff42768fc91cb8cc652ed6012d) --- src/devices/nm-device.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3f5edd06ee..294456de1b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -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