View | Details | Raw Unified | Return to bug 202247
Collapse All | Expand All

(-)files/patch-print_eth_info.c (+45 lines)
Line 0 Link Here
1
--- src/print_eth_info.c.orig	2015-08-11 09:37:31.470359000 -0700
2
+++ src/print_eth_info.c	2015-08-11 10:12:38.744033000 -0700
3
@@ -21,8 +21,6 @@
4
 
5
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
6
 #include <net/if_media.h>
7
-#define IFM_TYPE_MATCH(dt, t)                       \
8
-        (IFM_TYPE((dt)) == 0 || IFM_TYPE((dt)) == IFM_TYPE((t)))
9
 
10
 #define PART_ETHSPEED  "E: %s (%s)"
11
 #endif
12
@@ -52,19 +50,29 @@
13
         struct ifmediareq ifm;
14
         (void)memset(&ifm, 0, sizeof(ifm));
15
         (void)strncpy(ifm.ifm_name, interface, sizeof(ifm.ifm_name));
16
-        int ret = ioctl(general_socket, SIOCGIFMEDIA, (caddr_t)&ifm);
17
+        int ret;
18
+#ifdef SIOCGIFXMEDIA
19
+        ret = ioctl(general_socket, SIOCGIFXMEDIA, (caddr_t)&ifm);
20
+        if (ret < 0)
21
+#endif
22
+            ret = ioctl(general_socket, SIOCGIFMEDIA, (caddr_t)&ifm);
23
+        if (ret < 0)
24
+            return sprintf(outwalk, "?");
25
 
26
         /* Get the description of the media type, partially taken from
27
          * FreeBSD's ifconfig */
28
         const struct ifmedia_description *desc;
29
-        struct ifmedia_description ifm_subtype_descriptions[] =
30
+        static struct ifmedia_description ifm_subtype_descriptions[] =
31
                 IFM_SUBTYPE_ETHERNET_DESCRIPTIONS;
32
 
33
+        if (IFM_TYPE(ifm.ifm_active) != IFM_ETHER)
34
+            return sprintf(outwalk, "?");
35
+        if (ifm.ifm_status & IFM_AVALID && !(ifm.ifm_status & IFM_ACTIVE))
36
+            return sprintf(outwalk, "no carrier");
37
         for (desc = ifm_subtype_descriptions;
38
              desc->ifmt_string != NULL;
39
              desc++) {
40
-            if (IFM_TYPE_MATCH(desc->ifmt_word, ifm.ifm_active) &&
41
-                IFM_SUBTYPE(desc->ifmt_word) == IFM_SUBTYPE(ifm.ifm_active))
42
+            if (desc->ifmt_word == IFM_SUBTYPE(ifm.ifm_active))
43
                 break;
44
         }
45
         ethspeed = (desc->ifmt_string != NULL ? desc->ifmt_string : "?");

Return to bug 202247