NetworkManager r3458 - trunk/src
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: NetworkManager r3458 - trunk/src
- Date: Fri, 14 Mar 2008 20:37:48 +0000 (GMT)
Author: dcbw
Date: Fri Mar 14 20:37:48 2008
New Revision: 3458
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3458&view=rev
Log:
Cleanup ioctl handling
Modified:
trunk/src/nm-device-802-3-ethernet.c
trunk/src/nm-device.c
Modified: trunk/src/nm-device-802-3-ethernet.c
==============================================================================
--- trunk/src/nm-device-802-3-ethernet.c (original)
+++ trunk/src/nm-device-802-3-ethernet.c Fri Mar 14 20:37:48 2008
@@ -29,6 +29,9 @@
#include <stdlib.h>
#include <linux/sockios.h>
#include <linux/ethtool.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <net/if.h>
#include "nm-device-802-3-ethernet.h"
#include "nm-device-interface.h"
@@ -344,10 +347,10 @@
{
int fd;
struct ifreq ifr;
- struct ethtool_cmd edata;
- const char *iface;
+ struct ethtool_cmd edata = {
+ .cmd = ETHTOOL_GSET,
+ };
guint32 speed = 0;
- size_t len;
g_return_val_if_fail (self != NULL, 0);
@@ -357,13 +360,10 @@
return 0;
}
- iface = nm_device_get_iface (NM_DEVICE (self));
- len = MIN (sizeof (ifr.ifr_name) - 1, strlen (iface));
memset (&ifr, 0, sizeof (struct ifreq));
- strncpy (ifr.ifr_name, iface, len);
-
- edata.cmd = ETHTOOL_GSET;
+ strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
ifr.ifr_data = (char *) &edata;
+
if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
goto out;
@@ -380,8 +380,6 @@
NMDevice8023Ethernet *self = NM_DEVICE_802_3_ETHERNET (dev);
struct ifreq req;
int ret, fd;
- const char *iface;
- size_t len;
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
@@ -389,10 +387,8 @@
return;
}
- iface = nm_device_get_iface (dev);
- len = MIN (sizeof (req.ifr_name) - 1, strlen (iface));
memset (&req, 0, sizeof (struct ifreq));
- strncpy (req.ifr_name, iface, len);
+ strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
ret = ioctl (fd, SIOCGIFHWADDR, &req);
if (ret == 0) {
@@ -826,8 +822,6 @@
struct ifreq ifr;
gboolean supports_ethtool = FALSE;
struct ethtool_cmd edata;
- const char *iface;
- size_t len;
g_return_val_if_fail (self != NULL, FALSE);
@@ -837,10 +831,8 @@
return FALSE;
}
- iface = nm_device_get_iface (NM_DEVICE (self));
- len = MIN (sizeof (ifr.ifr_name) - 1, strlen (iface));
memset (&ifr, 0, sizeof (struct ifreq));
- strncpy (ifr.ifr_name, iface, len);
+ strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
edata.cmd = ETHTOOL_GLINK;
ifr.ifr_data = (char *) &edata;
@@ -890,8 +882,6 @@
int err, fd, bmsr;
struct ifreq ifr;
gboolean supports_mii = FALSE;
- const char *iface;
- size_t len;
g_return_val_if_fail (self != NULL, FALSE);
@@ -901,10 +891,8 @@
return 0;
}
- iface = nm_device_get_iface (NM_DEVICE (self));
- len = MIN (sizeof (ifr.ifr_name) - 1, strlen (iface));
memset (&ifr, 0, sizeof (struct ifreq));
- strncpy (ifr.ifr_name, iface, len);
+ strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
err = ioctl (fd, SIOCGMIIPHY, &ifr);
if (err < 0)
Modified: trunk/src/nm-device.c
==============================================================================
--- trunk/src/nm-device.c (original)
+++ trunk/src/nm-device.c Fri Mar 14 20:37:48 2008
@@ -25,6 +25,10 @@
#include <dbus/dbus.h>
#include <netinet/in.h>
#include <string.h>
+#include <net/if.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/ioctl.h>
#include "nm-device-interface.h"
#include "nm-device.h"
@@ -194,7 +198,6 @@
struct ifreq ifr;
const char *iface;
int err, fd;
- size_t len;
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
@@ -204,9 +207,7 @@
/* Get device's flags */
iface = nm_device_get_iface (self);
- len = MIN (sizeof (ifr.ifr_name) - 1, strlen (iface));
- strncpy (ifr.ifr_name, iface, len);
-
+ strncpy (ifr.ifr_name, iface, IFNAMSIZ);
err = ioctl (fd, SIOCGIFFLAGS, &ifr);
close (fd);
@@ -1472,10 +1473,8 @@
nm_device_update_ip4_address (NMDevice *self)
{
struct ifreq req;
- const char *iface;
guint32 new_address;
int fd, err;
- size_t len;
g_return_if_fail (self != NULL);
@@ -1485,15 +1484,11 @@
return;
}
- iface = nm_device_get_iface (self);
- len = MIN (sizeof (req.ifr_name) - 1, strlen (iface));
-
memset (&req, 0, sizeof (struct ifreq));
- strncpy (req.ifr_name, iface, len);
-
+ strncpy (req.ifr_name, nm_device_get_iface (self), IFNAMSIZ);
err = ioctl (fd, SIOCGIFADDR, &req);
-
close (fd);
+
if (err != 0)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]