summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-07-04 10:19:18 -0700
committerMarcel Holtmann <marcel@holtmann.org>2009-07-04 10:19:18 -0700
commitadbfb7fa9c750f394939d10733cff6f29f150f71 (patch)
tree98837ac82c2c45b5a0754f88b707e69e63b72c16
parent3e71ee312dbae17777ad584823c3dba2826128be (diff)
downloadconnman-adbfb7fa9c750f394939d10733cff6f29f150f71.tar.gz
connman-adbfb7fa9c750f394939d10733cff6f29f150f71.tar.bz2
connman-adbfb7fa9c750f394939d10733cff6f29f150f71.zip
Move the network device type detection into its own function
-rw-r--r--src/connman.h2
-rw-r--r--src/inet.c62
2 files changed, 44 insertions, 20 deletions
diff --git a/src/connman.h b/src/connman.h
index d778cc1d..50e5d664 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -102,6 +102,8 @@ int __connman_ipconfig_save(struct connman_ipconfig *ipconfig,
#include <connman/inet.h>
+enum connman_device_type __connman_inet_get_device_type(int index);
+
#include <connman/rfkill.h>
int __connman_rfkill_init(void);
diff --git a/src/inet.c b/src/inet.c
index 680c095b..6105344c 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -288,28 +288,30 @@ static char *index2ident(int index, const char *prefix)
return str;
}
-struct connman_device *connman_inet_create_device(int index)
+enum connman_device_type __connman_inet_get_device_type(int index)
{
enum connman_device_type devtype = CONNMAN_DEVICE_TYPE_UNKNOWN;
- enum connman_device_mode mode = CONNMAN_DEVICE_MODE_UNKNOWN;
- struct connman_device *device;
unsigned short type = index2type(index);
- char *addr, *name, *devname, *ident = NULL;
+ const char *devname;
+ struct ifreq ifr;
+ int sk;
- if (index < 0)
- return NULL;
+ sk = socket(PF_INET, SOCK_DGRAM, 0);
+ if (sk < 0)
+ return devtype;
- devname = connman_inet_ifname(index);
- if (devname == NULL)
- return NULL;
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_ifindex = index;
- __connman_udev_get_devtype(devname);
+ if (ioctl(sk, SIOCGIFNAME, &ifr) < 0)
+ goto done;
+
+ devname = ifr.ifr_name;
if (type == ARPHRD_ETHER) {
char bridge_path[PATH_MAX], wimax_path[PATH_MAX];
struct stat st;
struct iwreq iwr;
- int sk;
snprintf(bridge_path, PATH_MAX,
"/sys/class/net/%s/bridge", devname);
@@ -319,11 +321,8 @@ struct connman_device *connman_inet_create_device(int index)
memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_ifrn.ifrn_name, devname, IFNAMSIZ);
- sk = socket(PF_INET, SOCK_DGRAM, 0);
-
if (g_str_has_prefix(devname, "vmnet") == TRUE ||
- g_str_has_prefix(devname, "vboxnet") == TRUE) {
- connman_info("Ignoring network interface %s", devname);
+ g_str_has_prefix(ifr.ifr_name, "vboxnet") == TRUE) {
devtype = CONNMAN_DEVICE_TYPE_UNKNOWN;
} else if (g_str_has_prefix(devname, "bnep") == TRUE)
devtype = CONNMAN_DEVICE_TYPE_UNKNOWN;
@@ -339,15 +338,38 @@ struct connman_device *connman_inet_create_device(int index)
devtype = CONNMAN_DEVICE_TYPE_WIFI;
else
devtype = CONNMAN_DEVICE_TYPE_ETHERNET;
-
- close(sk);
} else if (type == ARPHRD_NONE) {
if (g_str_has_prefix(devname, "hso") == TRUE)
devtype = CONNMAN_DEVICE_TYPE_HSO;
}
- switch (devtype) {
+done:
+ close(sk);
+
+ return devtype;
+}
+
+struct connman_device *connman_inet_create_device(int index)
+{
+ enum connman_device_mode mode = CONNMAN_DEVICE_MODE_UNKNOWN;
+ enum connman_device_type type;
+ struct connman_device *device;
+ char *addr, *name, *devname, *ident = NULL;
+
+ if (index < 0)
+ return NULL;
+
+ devname = connman_inet_ifname(index);
+ if (devname == NULL)
+ return NULL;
+
+ __connman_udev_get_devtype(devname);
+
+ type = __connman_inet_get_device_type(index);
+
+ switch (type) {
case CONNMAN_DEVICE_TYPE_UNKNOWN:
+ connman_info("Ignoring network interface %s", devname);
g_free(devname);
return NULL;
case CONNMAN_DEVICE_TYPE_ETHERNET:
@@ -369,7 +391,7 @@ struct connman_device *connman_inet_create_device(int index)
break;
}
- device = connman_device_create(name, devtype);
+ device = connman_device_create(name, type);
if (device == NULL) {
g_free(devname);
g_free(name);
@@ -377,7 +399,7 @@ struct connman_device *connman_inet_create_device(int index)
return NULL;
}
- switch (devtype) {
+ switch (type) {
case CONNMAN_DEVICE_TYPE_UNKNOWN:
case CONNMAN_DEVICE_TYPE_VENDOR:
case CONNMAN_DEVICE_TYPE_NOZOMI: