+2008-10-30 Dan Williams <dcbw@redhat.com>
+
+ * src/nm-device-ethernet.c
+ src/nm-device-wifi.c
+ src/nm-device.c
+ src/ppp-manager/nm-ppp-manager.c
+ - Harmonize return checking of ioctl
+
+ * system-settings/plugins/ifcfg-fedora/reader.c
+ - (is_wireless_device): fall back to SIOCGIWNAME (rh #466340)
+
2008-10-30 Dan Williams <dcbw@redhat.com>
* src/ppp-manager/nm-ppp-manager.c
strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
ifr.ifr_data = (char *) &edata;
- if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
+ if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
goto out;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
struct ifreq req;
- int ret, fd;
+ int fd;
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
memset (&req, 0, sizeof (struct ifreq));
strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
- ret = ioctl (fd, SIOCGIFHWADDR, &req);
- if (ret) {
+ if (ioctl (fd, SIOCGIFHWADDR, &req) < 0) {
nm_warning ("%s: (%s) error getting hardware address: %d",
__func__, nm_device_get_iface (dev), errno);
goto out;
edata.cmd = ETHTOOL_GLINK;
ifr.ifr_data = (char *) &edata;
- if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
+ if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
goto out;
supports_ethtool = TRUE;
mii = (struct mii_ioctl_data *) &ifr->ifr_ifru;
mii->reg_num = location;
- if (ioctl (fd, SIOCGMIIREG, ifr) >= 0)
+ if (ioctl (fd, SIOCGMIIREG, ifr) == 0)
val = mii->val_out;
return val;
static gboolean
supports_mii_carrier_detect (NMDeviceEthernet *self)
{
- int err, fd, bmsr;
+ int fd, bmsr;
struct ifreq ifr;
gboolean supports_mii = FALSE;
memset (&ifr, 0, sizeof (struct ifreq));
strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
- err = ioctl (fd, SIOCGMIIPHY, &ifr);
- if (err < 0)
+ if (ioctl (fd, SIOCGMIIPHY, &ifr) < 0)
goto out;
/* If we can read the BMSR register, we assume that the card supports MII link detection */
struct iw_range *range,
guint32 *response_len)
{
- int fd, err, i = 26;
+ int fd, i = 26;
gboolean success = FALSE;
const char *iface;
struct iwreq wrq;
* see rh bz#362421)
*/
while (i-- > 0) {
- err = ioctl (fd, SIOCGIWRANGE, &wrq);
- if (err == 0) {
+ if (ioctl (fd, SIOCGIWRANGE, &wrq) == 0) {
if (response_len)
*response_len = wrq.u.data.length;
success = TRUE;
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
err = ioctl (fd, SIOCSIWSCAN, &wrq);
close (fd);
-
- if ((err == -1) && (errno == EOPNOTSUPP))
+ if ((err < 0) && (errno == EOPNOTSUPP))
caps = NM_DEVICE_CAP_NONE;
else
caps |= NM_DEVICE_CAP_NM_SUPPORTED;
iface = nm_device_get_iface (NM_DEVICE (self));
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
- if (ioctl (fd, SIOCSIWMODE, &wrq) == 0)
- success = TRUE;
- else {
+ if (ioctl (fd, SIOCSIWMODE, &wrq) < 0) {
if (errno != ENODEV) {
nm_warning ("error setting card %s to mode %d: %s",
iface, mode, strerror (errno));
}
- }
+ } else
+ success = TRUE;
close (fd);
out:
static guint32
nm_device_wifi_get_frequency (NMDeviceWifi *self)
{
- int err, fd;
+ int fd;
guint32 freq = 0;
const char *iface;
struct iwreq wrq;
iface = nm_device_get_iface (NM_DEVICE (self));
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
- err = ioctl (fd, SIOCGIWFREQ, &wrq);
- if (err >= 0)
- freq = iw_freq_to_uint32 (&wrq.u.freq);
- else if (err == -1)
+ if (ioctl (fd, SIOCGIWFREQ, &wrq) < 0)
nm_warning ("(%s): error getting frequency: %s", iface, strerror (errno));
+ else
+ freq = iw_freq_to_uint32 (&wrq.u.freq);
close (fd);
return freq;
err = ioctl (fd, SIOCGIWRATE, &wrq);
close (fd);
- return ((err >= 0) ? wrq.u.bitrate.value / 1000 : 0);
+ return ((err == 0) ? wrq.u.bitrate.value / 1000 : 0);
}
/*
memset (&wrq, 0, sizeof (wrq));
strncpy (wrq.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
- if (ioctl (fd, SIOCGIWAP, &wrq) >= 0)
+ if (ioctl (fd, SIOCGIWAP, &wrq) == 0)
memcpy (bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
close (fd);
iface = nm_device_get_iface (NM_DEVICE (self));
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
- if (ioctl (fd, SIOCSIWENCODE, &wrq) == -1) {
+ if (ioctl (fd, SIOCSIWENCODE, &wrq) < 0) {
if (errno != ENODEV) {
nm_warning ("error setting key for device %s: %s",
iface, strerror (errno));
NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
struct ifreq req;
- int ret, fd;
+ int fd;
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
memset (&req, 0, sizeof (struct ifreq));
strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
- ret = ioctl (fd, SIOCGIFHWADDR, &req);
- if (ret) {
+ if (ioctl (fd, SIOCGIFHWADDR, &req) < 0) {
nm_warning ("%s: (%s) error getting hardware address: %d",
__func__, nm_device_get_iface (dev), errno);
goto out;
{
struct ifreq req;
guint32 new_address;
- int fd, err;
+ int fd;
g_return_if_fail (self != NULL);
memset (&req, 0, sizeof (struct ifreq));
strncpy (req.ifr_name, nm_device_get_ip_iface (self), IFNAMSIZ);
- err = ioctl (fd, SIOCGIFADDR, &req);
+ if (ioctl (fd, SIOCGIFADDR, &req) == 0) {
+ new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
+ if (new_address != nm_device_get_ip4_address (self))
+ self->priv->ip4_address = new_address;
+ }
close (fd);
-
- if (err != 0)
- return;
-
- new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
- if (new_address != nm_device_get_ip4_address (self))
- self->priv->ip4_address = new_address;
}
static gboolean
req.stats_ptr = (caddr_t) &req.stats;
strncpy (req.ifr__name, priv->ip_iface, sizeof (req.ifr__name));
- if (!ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0)
+ if (ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0)
nm_warning ("Could not read ppp stats: %s", strerror (errno));
else
g_signal_emit (manager, signals[STATS], 0,
}
static gboolean
-is_wireless_device (const char *iface, gboolean *is_wireless)
+is_wireless_device (const char *iface)
{
int fd;
struct iw_range range;
struct iwreq wrq;
- gboolean success = FALSE;
+ gboolean is_wireless = FALSE;
g_return_val_if_fail (iface != NULL, FALSE);
- g_return_val_if_fail (is_wireless != NULL, FALSE);
-
- *is_wireless = FALSE;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (!fd)
wrq.u.data.pointer = (caddr_t) ⦥
wrq.u.data.length = sizeof (struct iw_range);
- if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0) {
+ if (ioctl (fd, SIOCGIWRANGE, &wrq) == 0)
+ is_wireless = TRUE;
+ else {
if (errno == EOPNOTSUPP)
- success = TRUE;
- goto out;
+ is_wireless = FALSE;
+ else {
+ /* Sigh... some wired devices (kvm/qemu) return EINVAL when the
+ * device is down even though it's not a wireless device. So try
+ * IWNAME as a fallback.
+ */
+ memset (&wrq, 0, sizeof (struct iwreq));
+ strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+ if (ioctl (fd, SIOCGIWNAME, &wrq) == 0)
+ is_wireless = TRUE;
+ }
}
- *is_wireless = TRUE;
- success = TRUE;
-
-out:
close (fd);
- return success;
+ return is_wireless;
}
NMConnection *
type = svGetValue (parsed, "TYPE");
if (!type) {
char *device;
- gboolean is_wireless = FALSE;
/* If no type, if the device has wireless extensions, it's wifi,
* otherwise it's ethernet.
}
/* Test wireless extensions */
- if (!is_wireless_device (device, &is_wireless)) {
- g_set_error (error, ifcfg_plugin_error_quark (), 0,
- "File '%s' specified device '%s', but the device's "
- "type could not be determined.", filename, device);
- g_free (device);
- goto done;
- }
-
- if (is_wireless)
+ if (is_wireless_device (device))
type = g_strdup (TYPE_WIRELESS);
else
type = g_strdup (TYPE_ETHERNET);