aboutsummaryrefslogtreecommitdiffstats
path: root/capture_ifinfo.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-06-28 20:16:39 +0000
committerGuy Harris <guy@alum.mit.edu>2012-06-28 20:16:39 +0000
commitc51a19cc43332bd033edf17dd2207a35452b599c (patch)
tree636005b583bc5ee96393071c85bcff92b2430db8 /capture_ifinfo.c
parent8381581aa1d4862cf235ddd96c60e0648c034067 (diff)
get_interface_type() contains no GUI code, so just move it up to
capture_ifinfo.c. svn path=/trunk/; revision=43532
Diffstat (limited to 'capture_ifinfo.c')
-rw-r--r--capture_ifinfo.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/capture_ifinfo.c b/capture_ifinfo.c
index be57f02ebd..8b18346771 100644
--- a/capture_ifinfo.c
+++ b/capture_ifinfo.c
@@ -336,4 +336,128 @@ void add_interface_to_remote_list(if_info_t *if_info)
remote_interface_list = g_list_append(remote_interface_list, temp);
}
#endif
+
+guint
+get_interface_type(gchar *name, gchar *description)
+{
+#if defined(__linux__)
+ ws_statb64 statb;
+ char *wireless_path;
+#endif
+#if defined(_WIN32)
+ /*
+ * Much digging failed to reveal any obvious way to get something such
+ * as the SNMP MIB-II ifType value for an interface:
+ *
+ * http://www.iana.org/assignments/ianaiftype-mib
+ *
+ * by making some NDIS request.
+ */
+ if (description && (strstr(description,"generic dialup") != NULL ||
+ strstr(description,"PPP/SLIP") != NULL )) {
+ return IF_DIALUP;
+ } else if (description && (strstr(description,"Wireless") != NULL ||
+ strstr(description,"802.11") != NULL)) {
+ return IF_WIRELESS;
+ } else if (description && strstr(description,"AirPcap") != NULL ||
+ strstr(name,"airpcap")) {
+ return IF_AIRPCAP;
+ } else if (description && strstr(description, "Bluetooth") != NULL ) {
+ return IF_BLUETOOTH;
+ }
+#elif defined(__APPLE__)
+ /*
+ * XXX - yes, fetching all the network addresses for an interface
+ * gets you an AF_LINK address, of type "struct sockaddr_dl", and,
+ * yes, that includes an SNMP MIB-II ifType value.
+ *
+ * However, it's IFT_ETHER, i.e. Ethernet, for AirPort interfaces,
+ * not IFT_IEEE80211 (which isn't defined in OS X in any case).
+ *
+ * Perhaps some other BSD-flavored OSes won't make this mistake;
+ * however, FreeBSD 7.0 and OpenBSD 4.2, at least, appear to have
+ * made the same mistake, at least for my Belkin ZyDAS stick.
+ *
+ * XXX - this is wrong on a MacBook Air, as en0 is the AirPort
+ * interface, and it's also wrong on a Mac that has no AirPort
+ * interfaces and has multiple Ethernet interfaces.
+ *
+ * The SystemConfiguration framework is your friend here.
+ * SCNetworkInterfaceGetInterfaceType() will get the interface
+ * type. SCNetworkInterfaceCopyAll() gets all network-capable
+ * interfaces on the system; SCNetworkInterfaceGetBSDName()
+ * gets the "BSD name" of the interface, so we look for
+ * an interface with the specified "BSD name" and get its
+ * interface type. The interface type is a CFString, and:
+ *
+ * kSCNetworkInterfaceTypeIEEE80211 means IF_WIRELESS;
+ * kSCNetworkInterfaceTypeBluetooth means IF_BLUETOOTH;
+ * kSCNetworkInterfaceTypeModem or
+ * kSCNetworkInterfaceTypePPP or
+ * maybe kSCNetworkInterfaceTypeWWAN means IF_DIALUP
+ */
+ if (strcmp(name, "en1") == 0) {
+ return IF_WIRELESS;
+ }
+ /*
+ * XXX - PPP devices have names beginning with "ppp" and an IFT_ of
+ * IFT_PPP, but they could be dial-up, or PPPoE, or mobile phone modem,
+ * or VPN, or... devices. One might have to dive into the bowels of
+ * IOKit to find out.
+ */
+
+ /*
+ * XXX - there's currently no support for raw Bluetooth capture,
+ * and IP-over-Bluetooth devices just look like fake Ethernet
+ * devices. There's also Bluetooth modem support, but that'll
+ * probably just give you a device that looks like a PPP device.
+ */
+#elif defined(__linux__)
+ /*
+ * Look for /sys/class/net/{device}/wireless.
+ */
+ wireless_path = g_strdup_printf("/sys/class/net/%s/wireless", name);
+ if (wireless_path != NULL) {
+ if (ws_stat64(wireless_path, &statb) == 0) {
+ g_free(wireless_path);
+ return IF_WIRELESS;
+ }
+ }
+ /*
+ * Bluetooth devices.
+ *
+ * XXX - this is for raw Bluetooth capture; what about IP-over-Bluetooth
+ * devices?
+ */
+ if ( strstr(name,"bluetooth") != NULL) {
+ return IF_BLUETOOTH;
+ }
+
+ /*
+ * USB devices.
+ */
+ if ( strstr(name,"usbmon") != NULL ) {
+ return IF_USB;
+ }
+#endif
+ /*
+ * Bridge, NAT, or host-only interfaces on VMWare hosts have the name
+ * vmnet[0-9]+ or VMnet[0-9+ on Windows. Guests might use a native
+ * (LANCE or E1000) driver or the vmxnet driver. These devices have an
+ * IFT_ of IFT_ETHER, so we have to check the name.
+ */
+ if ( g_ascii_strncasecmp(name, "vmnet", 5) == 0) {
+ return IF_VIRTUAL;
+ }
+
+ if ( g_ascii_strncasecmp(name, "vmxnet", 6) == 0) {
+ return IF_VIRTUAL;
+ }
+
+ if (description && strstr(description, "VMware") != NULL ) {
+ return IF_VIRTUAL;
+ }
+
+ return IF_WIRED;
+}
#endif /* HAVE_LIBPCAP */