ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/network_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/network_stats.c (file contents):
Revision 1.33 by pajs, Fri Feb 13 15:29:16 2004 UTC vs.
Revision 1.58 by tdb, Sun Apr 4 21:54:48 2004 UTC

# Line 32 | Line 32
32   #ifdef SOLARIS
33   #include <kstat.h>
34   #include <sys/sysinfo.h>
35 + #include <sys/types.h>
36 + #include <sys/socket.h>
37 + #include <sys/ioctl.h>
38 + #include <net/if.h>
39 + #include <netinet/in.h>
40 + #include <sys/sockio.h>
41   #endif
42   #ifdef LINUX
43   #include <stdio.h>
# Line 48 | Line 54
54   typedef __uint8_t u8;
55   typedef __uint16_t u16;
56   typedef __uint32_t u32;
57 + typedef __uint64_t u64;
58   #include <linux/ethtool.h>
59   #include <linux/sockios.h>
60   #include <unistd.h>
# Line 59 | Line 66 | typedef __uint32_t u32;
66   #include <net/if.h>
67   #include <net/if_media.h>
68   #include <sys/ioctl.h>
69 + #include <unistd.h>
70   #endif
71  
72   static network_stat_t *network_stats=NULL;
# Line 70 | Line 78 | void network_stat_init(int start, int end, network_sta
78                  net_stats->interface_name=NULL;
79                  net_stats->tx=0;
80                  net_stats->rx=0;
81 +                net_stats->ipackets=0;
82 +                net_stats->opackets=0;
83 +                net_stats->ierrors=0;
84 +                net_stats->oerrors=0;
85 +                net_stats->collisions=0;
86                  net_stats++;
87          }
88   }
# Line 117 | Line 130 | network_stat_t *get_network_stats(int *entries){
130          /* Horrible big enough, but it should be easily big enough */
131          char line[8096];
132          regex_t regex;
133 <        regmatch_t line_match[4];
133 >        regmatch_t line_match[9];
134   #endif
135   #ifdef ALLBSD
136          struct ifaddrs *net, *net_ptr;
# Line 144 | Line 157 | network_stat_t *get_network_stats(int *entries){
157                  if(network_stat_ptr->interface_name==NULL) return NULL;
158                  net_data=(struct if_data *)net_ptr->ifa_data;
159                  network_stat_ptr->rx=net_data->ifi_ibytes;
160 <                network_stat_ptr->tx=net_data->ifi_obytes;                      
160 >                network_stat_ptr->tx=net_data->ifi_obytes;
161 >                network_stat_ptr->ipackets=net_data->ifi_ipackets;
162 >                network_stat_ptr->opackets=net_data->ifi_opackets;
163 >                network_stat_ptr->ierrors=net_data->ifi_ierrors;
164 >                network_stat_ptr->oerrors=net_data->ifi_oerrors;
165 >                network_stat_ptr->collisions=net_data->ifi_collisions;
166                  network_stat_ptr->systime=time(NULL);
167                  interfaces++;
168          }
# Line 163 | Line 181 | network_stat_t *get_network_stats(int *entries){
181                          kstat_read(kc, ksp, NULL);
182  
183   #ifdef SOL7
184 < #define RLOOKUP "rbytes"
185 < #define WLOOKUP "obytes"
184 > #define LRX "rbytes"
185 > #define LTX "obytes"
186 > #define LIPACKETS "ipackets"
187 > #define LOPACKETS "opackets"
188   #define VALTYPE value.ui32
189   #else
190 < #define RLOOKUP "rbytes64"
191 < #define WLOOKUP "obytes64"
190 > #define LRX "rbytes64"
191 > #define LTX "obytes64"
192 > #define LIPACKETS "ipackets64"
193 > #define LOPACKETS "opackets64"
194   #define VALTYPE value.ui64
195   #endif
196  
197 <                        if((knp=kstat_data_lookup(ksp, RLOOKUP))==NULL){
198 <                                /* Not a network interface, so skip to the next entry */
197 >                        /* Read rx */
198 >                        if((knp=kstat_data_lookup(ksp, LRX))==NULL){
199 >                                /* This is a network interface, but it doesn't
200 >                                 * have the rbytes/obytes values; for instance,
201 >                                 * the loopback devices have this behaviour
202 >                                 * (although they do track packets in/out). */
203 >                                /* FIXME: Show packet counts when byte counts
204 >                                 * not available. */
205                                  continue;
206                          }
207  
208 +                        /* Create new network_stats */
209                          network_stats=network_stat_malloc((interfaces+1), &sizeof_network_stats, network_stats);
210                          if(network_stats==NULL){
211                                  return NULL;
212                          }
213                          network_stat_ptr=network_stats+interfaces;
214 +
215 +                        /* Finish reading rx */
216                          network_stat_ptr->rx=knp->VALTYPE;
217  
218 <                        if((knp=kstat_data_lookup(ksp, WLOOKUP))==NULL){
219 <                                /* Not a network interface, so skip to the next entry */
218 >                        /* Read tx */
219 >                        if((knp=kstat_data_lookup(ksp, LTX))==NULL){
220                                  continue;
221                          }
222                          network_stat_ptr->tx=knp->VALTYPE;
223 +
224 +                        /* Read ipackets */
225 +                        if((knp=kstat_data_lookup(ksp, LIPACKETS))==NULL){
226 +                                continue;
227 +                        }
228 +                        network_stat_ptr->ipackets=knp->VALTYPE;
229 +
230 +                        /* Read opackets */
231 +                        if((knp=kstat_data_lookup(ksp, LOPACKETS))==NULL){
232 +                                continue;
233 +                        }
234 +                        network_stat_ptr->opackets=knp->VALTYPE;
235 +
236 +                        /* Read ierrors */
237 +                        if((knp=kstat_data_lookup(ksp, "ierrors"))==NULL){
238 +                                continue;
239 +                        }
240 +                        network_stat_ptr->ierrors=knp->value.ui32;
241 +
242 +                        /* Read oerrors */
243 +                        if((knp=kstat_data_lookup(ksp, "oerrors"))==NULL){
244 +                                continue;
245 +                        }
246 +                        network_stat_ptr->oerrors=knp->value.ui32;
247 +
248 +                        /* Read collisions */
249 +                        if((knp=kstat_data_lookup(ksp, "collisions"))==NULL){
250 +                                continue;
251 +                        }
252 +                        network_stat_ptr->collisions=knp->value.ui32;
253 +
254 +                        /* Read interface name */
255                          if(network_stat_ptr->interface_name!=NULL){
256                                  free(network_stat_ptr->interface_name);
257                          }
258                          network_stat_ptr->interface_name=strdup(ksp->ks_name);
259  
260 +                        /* Store systime */
261                          network_stat_ptr->systime=time(NULL);
262 +
263                          interfaces++;
264                  }
265          }
# Line 211 | Line 276 | network_stat_t *get_network_stats(int *entries){
276          fgets(line, sizeof(line), f);
277  
278  
279 <        if((regcomp(&regex, "^[[:space:]]*([^:]+):[[:space:]]*([[:digit:]]+)[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+([[:digit:]]+)", REG_EXTENDED))!=0){
279 >        if((regcomp(&regex, "^ *([^:]+): *([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+ +[0-9]+ +([0-9]+)", REG_EXTENDED))!=0){
280                  return NULL;
281          }
282  
283          interfaces=0;
284  
285          while((fgets(line, sizeof(line), f)) != NULL){
286 <                if((regexec(&regex, line, 4, line_match, 0))!=0){
286 >                if((regexec(&regex, line, 9, line_match, 0))!=0){
287                          continue;
288                  }
289                  network_stats=network_stat_malloc((interfaces+1), &sizeof_network_stats, network_stats);
# Line 233 | Line 298 | network_stat_t *get_network_stats(int *entries){
298  
299                  network_stat_ptr->interface_name=get_string_match(line, &line_match[1]);
300                  network_stat_ptr->rx=get_ll_match(line, &line_match[2]);
301 <                network_stat_ptr->tx=get_ll_match(line, &line_match[3]);
301 >                network_stat_ptr->tx=get_ll_match(line, &line_match[5]);
302 >                network_stat_ptr->ipackets=get_ll_match(line, &line_match[3]);
303 >                network_stat_ptr->opackets=get_ll_match(line, &line_match[6]);
304 >                network_stat_ptr->ierrors=get_ll_match(line, &line_match[4]);
305 >                network_stat_ptr->oerrors=get_ll_match(line, &line_match[7]);
306 >                network_stat_ptr->collisions=get_ll_match(line, &line_match[8]);
307                  network_stat_ptr->systime=time(NULL);
308  
309                  interfaces++;
# Line 253 | Line 323 | network_stat_t *get_network_stats(int *entries){
323   }
324  
325   long long transfer_diff(long long new, long long old){
326 < #if defined(SOL7) || defined(LINUX) || defined(FREEBSD)
327 < #define MAXVAL 4294967296LL
326 > #if defined(SOL7) || defined(LINUX) || defined(FREEBSD) || defined(DFBSD) || defined(OPENBSD)
327 >        /* 32-bit quantities, so we must explicitly deal with wraparound. */
328 > #define MAXVAL 0x100000000LL
329 >        if (new >= old) {
330 >                return new - old;
331 >        } else {
332 >                return MAXVAL + new - old;
333 >        }
334   #else
335 < #define MAXVAL 18446744073709551616LL
335 >        /* 64-bit quantities, so plain subtraction works. */
336 >        return new - old;
337   #endif
261        long long result;
262        if(new>=old){
263                result = (new-old);
264        }else{
265                result = (MAXVAL+(new-old));
266        }
267
268        return result;
269
338   }
339  
340   network_stat_t *get_network_stats_diff(int *entries) {
341          static network_stat_t *diff = NULL;
342          static int diff_count = 0;
343 <        network_stat_t *src, *dest;
343 >        network_stat_t *src = NULL, *dest;
344          int i, j, new_count;
345  
346          if (network_stats == NULL) {
# Line 297 | Line 365 | network_stat_t *get_network_stats_diff(int *entries) {
365                  dest->interface_name = strdup(src->interface_name);
366                  dest->rx = src->rx;
367                  dest->tx = src->tx;
368 +                dest->ipackets = src->ipackets;
369 +                dest->opackets = src->opackets;
370 +                dest->ierrors = src->ierrors;
371 +                dest->oerrors = src->oerrors;
372 +                dest->collisions = src->collisions;
373                  dest->systime = src->systime;
374          }
375  
# Line 327 | Line 400 | network_stat_t *get_network_stats_diff(int *entries) {
400                     difference. */
401                  dest->rx = transfer_diff(src->rx, dest->rx);
402                  dest->tx = transfer_diff(src->tx, dest->tx);
403 +                dest->ipackets = transfer_diff(src->ipackets, dest->ipackets);
404 +                dest->opackets = transfer_diff(src->opackets, dest->opackets);
405 +                dest->ierrors = transfer_diff(src->ierrors, dest->ierrors);
406 +                dest->oerrors = transfer_diff(src->oerrors, dest->oerrors);
407 +                dest->collisions = transfer_diff(src->collisions, dest->collisions);
408                  dest->systime = src->systime - dest->systime;
409          }
410  
# Line 375 | Line 453 | network_iface_stat_t *get_network_iface_stats(int *ent
453          static network_iface_stat_t *network_iface_stats;
454          network_iface_stat_t *network_iface_stat_ptr;
455          static int sizeof_network_iface_stats=0;        
456 <        static int ifaces;
456 >        int ifaces = 0;
457  
458   #ifdef SOLARIS
459          kstat_ctl_t *kc;
460          kstat_t *ksp;
461          kstat_named_t *knp;
462 +        int sock;
463   #endif
464   #ifdef ALLBSD
465          struct ifaddrs *net, *net_ptr;
466          struct ifmediareq ifmed;
467 <        int s;
467 >        struct ifreq ifr;
468 >        int sock;
469          int x;
470   #endif
471   #ifdef LINUX
472          FILE *f;
473          /* Horrible big enough, but it should be easily big enough */
474          char line[8096];
395        void *eth_tool_cmd_buf;
396        int buf_size;
475          int sock;
476   #endif
477 <        ifaces = 0;
477 >
478   #ifdef ALLBSD
479          if(getifaddrs(&net) != 0){
480                  return NULL;
481          }
482  
483 <        if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == NULL) return NULL;
483 >        if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == 0) return NULL;
484  
485          for(net_ptr=net; net_ptr!=NULL; net_ptr=net_ptr->ifa_next){
486                  if(net_ptr->ifa_addr->sa_family != AF_LINK) continue;
# Line 412 | Line 490 | network_iface_stat_t *get_network_iface_stats(int *ent
490                  }
491                  network_iface_stat_ptr = network_iface_stats + ifaces;
492  
493 +                memset(&ifr, 0, sizeof(ifr));
494 +                strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name));
495 +
496 +                if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){
497 +                        continue;
498 +                }      
499 +                if((ifr.ifr_flags & IFF_UP) != 0){
500 +                        network_iface_stat_ptr->up = 1;
501 +                }else{
502 +                        network_iface_stat_ptr->up = 0;
503 +                }
504 +
505 +                if (network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
506 +                network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name);
507 +                if (network_iface_stat_ptr->interface_name == NULL) return NULL;
508 +
509 +                network_iface_stat_ptr->speed = 0;
510 +                network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
511 +                ifaces++;
512 +
513                  memset(&ifmed, 0, sizeof(struct ifmediareq));
514                  strlcpy(ifmed.ifm_name, net_ptr->ifa_name, sizeof(ifmed.ifm_name));
515 <                if(ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){
515 >                if(ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){
516 >                        /* Not all interfaces support the media ioctls. */
517                          continue;
518                  }
519  
# Line 424 | Line 523 | network_iface_stat_t *get_network_iface_stats(int *ent
523                          continue;
524                  }
525  
427                if(network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
428                network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name);
429                if(network_iface_stat_ptr->interface_name == NULL) return NULL;
430
526                  /* Only intrested in the first 4 bits)  - Assuming only ETHER devices */
527                  x = ifmed.ifm_active & 0x0f;    
528                  switch(x){
# Line 451 | Line 546 | network_iface_stat_t *get_network_iface_stats(int *ent
546                          case(IFM_1000_SX):
547                          case(IFM_1000_LX):
548                          case(IFM_1000_CX):
549 < #if defined(FREEBSD) && !defined(FREEBSD5)
550 <                        case(IFM_1000_TX):
456 <                        case(IFM_1000_FX):
457 < #else
458 <                        case(IFM_1000_T):
549 > #if defined(IFM_1000_TX) && !defined(OPENBSD)
550 >                        case(IFM_1000_TX): /* FreeBSD 4 and others (but NOT OpenBSD)? */
551   #endif
552 + #ifdef IFM_1000_FX
553 +                        case(IFM_1000_FX): /* FreeBSD 4 */
554 + #endif
555 + #ifdef IFM_1000_T
556 +                        case(IFM_1000_T): /* FreeBSD 5 */
557 + #endif
558                                  network_iface_stat_ptr->speed = 1000;
559                                  break;
560                          /* We don't know what it is */
# Line 472 | Line 570 | network_iface_stat_t *get_network_iface_stats(int *ent
570                  }else{
571                          network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
572                  }
573 <                ifaces++;
573 >
574          }      
575          freeifaddrs(net);
576 <        close(s);
576 >        close(sock);
577   #endif
578  
579   #ifdef SOLARIS
580 <        if ((kc = kstat_open()) == NULL) {
581 <                return NULL;
582 <        }
580 >        if ((kc = kstat_open()) == NULL) {
581 >                return NULL;
582 >        }
583  
584 <        for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
585 <                if (!strcmp(ksp->ks_class, "net")) {
586 <                        kstat_read(kc, ksp, NULL);
587 <                        if((knp=kstat_data_lookup(ksp, "ifspeed"))==NULL){
588 <                                /* Not a network interface, so skip to the next entry */
584 >        if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) {
585 >                return NULL;
586 >        }
587 >
588 >        for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
589 >                if (!strcmp(ksp->ks_class, "net")) {
590 >                        struct ifreq ifr;
591 >
592 >                        kstat_read(kc, ksp, NULL);
593 >
594 >                        strncpy(ifr.ifr_name, ksp->ks_name, sizeof ifr.ifr_name);
595 >                        if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
596 >                                /* Not a network interface. */
597                                  continue;
598                          }
599 <                        network_iface_stats=network_iface_stat_malloc((ifaces+1), &sizeof_network_iface_stats, network_iface_stats);
600 <                        if(network_iface_stats==NULL){
599 >
600 >                        network_iface_stats = network_iface_stat_malloc(ifaces + 1, &sizeof_network_iface_stats, network_iface_stats);
601 >                        if (network_iface_stats == NULL) {
602                                  return NULL;
603                          }
604                          network_iface_stat_ptr = network_iface_stats + ifaces;
605 <                        network_iface_stat_ptr->speed = knp->value.ui64 / (1000*1000);
605 >                        ifaces++;
606  
607 <                        if((knp=kstat_data_lookup(ksp, "link_duplex"))==NULL){
608 <                                /* Not a network interface, so skip to the next entry */
609 <                                continue;
607 >                        if (network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
608 >                        network_iface_stat_ptr->interface_name = strdup(ksp->ks_name);
609 >                        if (network_iface_stat_ptr->interface_name == NULL) return NULL;
610 >
611 >                        if ((ifr.ifr_flags & IFF_UP) != 0) {
612 >                                network_iface_stat_ptr->up = 1;
613 >                        } else {
614 >                                network_iface_stat_ptr->up = 1;
615                          }
616  
617 <                        network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
618 <                        if(knp->value.ui64 == 2){
619 <                                network_iface_stat_ptr->dup = FULL_DUPLEX;
617 >                        if ((knp = kstat_data_lookup(ksp, "ifspeed")) != NULL) {
618 >                                network_iface_stat_ptr->speed = knp->value.ui64 / (1000 * 1000);
619 >                        } else {
620 >                                network_iface_stat_ptr->speed = 0;
621                          }
509                        if(knp->value.ui64 == 1){
510                                network_iface_stat_ptr->dup = HALF_DUPLEX;
511                        }
622  
623 <                        if(network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
624 <                        network_iface_stat_ptr->interface_name = strdup(ksp->ks_name);
625 <                        if(network_iface_stat_ptr->interface_name == NULL) return NULL;
626 <                        ifaces++;
623 >                        network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
624 >                        if ((knp = kstat_data_lookup(ksp, "link_duplex")) != NULL) {
625 >                                switch (knp->value.ui32) {
626 >                                case 1:
627 >                                        network_iface_stat_ptr->dup = HALF_DUPLEX;
628 >                                        break;
629 >                                case 2:
630 >                                        network_iface_stat_ptr->dup = FULL_DUPLEX;
631 >                                        break;
632 >                                }
633 >                        }
634                  }
635          }
636 +
637 +        close(sock);
638          kstat_close(kc);
520        
639   #endif  
640   #ifdef LINUX
523
641          f = fopen("/proc/net/dev", "r");
642          if(f == NULL){
643                  return NULL;
# Line 531 | Line 648 | network_iface_stat_t *get_network_iface_stats(int *ent
648                  return NULL;
649          }
650  
534        buf_size = sizeof(struct ethtool_cmd);
535        eth_tool_cmd_buf = malloc(buf_size);
536        if(eth_tool_cmd_buf == NULL) return NULL;
537
651          /* Ignore first 2 lines.. Just headings */
652          if((fgets(line, sizeof(line), f)) == NULL) return NULL;
653          if((fgets(line, sizeof(line), f)) == NULL) return NULL;
# Line 542 | Line 655 | network_iface_stat_t *get_network_iface_stats(int *ent
655          while((fgets(line, sizeof(line), f)) != NULL){
656                  char *name, *ptr;
657                  struct ifreq ifr;
658 <                struct ethtool_cmd *ethcmd;
658 >                struct ethtool_cmd ethcmd;
659                  int err;
660  
661                  /* Get the interface name */
# Line 554 | Line 667 | network_iface_stat_t *get_network_iface_stats(int *ent
667                          name++;
668                  }
669  
670 <                memset(&ifr, 0, sizeof(ifr));
671 <                memset(eth_tool_cmd_buf, 0, buf_size);
559 <                ifr.ifr_data = (caddr_t) eth_tool_cmd_buf;
560 <                strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
670 >                memset(&ifr, 0, sizeof ifr);
671 >                strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
672  
673 <                ethcmd = (struct ethtool_cmd *) ifr.ifr_data;
674 <                ethcmd->cmd = ETHTOOL_GSET;
673 >                if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
674 >                        continue;
675 >                }
676  
565                err = ioctl(sock, SIOCETHTOOL, &ifr);
566                if(err < 0){
567                        /* This could fail if the interface doesn't support the command. Carry
568                         * on to the next :)
569                         */
570                        continue;
571                }
572
677                  /* We have a good interface to add */
678                  network_iface_stats=network_iface_stat_malloc((ifaces+1), &sizeof_network_iface_stats, network_iface_stats);
679                  if(network_iface_stats==NULL){
# Line 577 | Line 681 | network_iface_stat_t *get_network_iface_stats(int *ent
681                  }
682                  network_iface_stat_ptr = network_iface_stats + ifaces;
683                  network_iface_stat_ptr->interface_name = strdup(name);
684 <                network_iface_stat_ptr->speed = ethcmd->speed;
685 <                network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
686 <                if(ethcmd->duplex == 0x00){
687 <                        network_iface_stat_ptr->dup = FULL_DUPLEX;
684 >                if ((ifr.ifr_flags & IFF_UP) != 0) {
685 >                        network_iface_stat_ptr->up = 1;
686 >                } else {
687 >                        network_iface_stat_ptr->up = 0;
688                  }
689 <                if(ethcmd->duplex == 0x01){
690 <                        network_iface_stat_ptr->dup = HALF_DUPLEX;
689 >
690 >                memset(&ethcmd, 0, sizeof ethcmd);
691 >                ethcmd.cmd = ETHTOOL_GSET;
692 >                ifr.ifr_data = (caddr_t) &ethcmd;
693 >
694 >                err = ioctl(sock, SIOCETHTOOL, &ifr);
695 >                if (err == 0) {
696 >                        network_iface_stat_ptr->speed = ethcmd.speed;
697 >
698 >                        switch (ethcmd.duplex) {
699 >                        case 0x00:
700 >                                network_iface_stat_ptr->dup = FULL_DUPLEX;
701 >                                break;
702 >                        case 0x01:
703 >                                network_iface_stat_ptr->dup = HALF_DUPLEX;
704 >                                break;
705 >                        default:
706 >                                network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
707 >                        }
708 >                } else {
709 >                        /* Not all interfaces support the ethtool ioctl. */
710 >                        network_iface_stat_ptr->speed = 0;
711 >                        network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
712                  }
713 +
714                  ifaces++;
715          }
716          close(sock);
717 <        free(eth_tool_cmd_buf);
717 >        fclose(f);
718   #endif
719          *entries = ifaces;
720          return network_iface_stats;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines