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.39 by ats, Sat Feb 14 00:29:29 2004 UTC vs.
Revision 1.40 by ats, Sat Feb 14 00:47:24 2004 UTC

# Line 411 | Line 411 | network_iface_stat_t *get_network_iface_stats(int *ent
411                  }
412                  network_iface_stat_ptr = network_iface_stats + ifaces;
413  
414 +                memset(&ifr, 0, sizeof(ifr));
415 +                strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name));
416 +
417 +                if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){
418 +                        continue;
419 +                }      
420 +                if((ifr.ifr_flags & IFF_UP) != 0){
421 +                        network_iface_stat_ptr->up = 1;
422 +                }else{
423 +                        network_iface_stat_ptr->up = 0;
424 +                }
425 +
426 +                if (network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
427 +                network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name);
428 +                if (network_iface_stat_ptr->interface_name == NULL) return NULL;
429 +
430 +                network_iface_stat_ptr->speed = 0;
431 +                network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
432 +                ifaces++;
433 +
434                  memset(&ifmed, 0, sizeof(struct ifmediareq));
435                  strlcpy(ifmed.ifm_name, net_ptr->ifa_name, sizeof(ifmed.ifm_name));
436                  if(ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmed) == -1){
437 +                        /* Not all interfaces support the media ioctls. */
438                          continue;
439                  }
440  
# Line 423 | Line 444 | network_iface_stat_t *get_network_iface_stats(int *ent
444                          continue;
445                  }
446  
426                if(network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
427                network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name);
428                if(network_iface_stat_ptr->interface_name == NULL) return NULL;
429
447                  /* Only intrested in the first 4 bits)  - Assuming only ETHER devices */
448                  x = ifmed.ifm_active & 0x0f;    
449                  switch(x){
# Line 472 | Line 489 | network_iface_stat_t *get_network_iface_stats(int *ent
489                          network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
490                  }
491  
475                memset(&ifr, 0, sizeof(ifr));
476                strncpy(ifr.ifr_name, net_ptr->ifa_name, sizeof(ifr.ifr_name));
477
478                if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0){
479                        continue;
480                }      
481                if((ifr.ifr_flags & IFF_UP) != 0){
482                        network_iface_stat_ptr->up = 1;
483                }else{
484                        network_iface_stat_ptr->up = 0;
485                }
486
487                ifaces++;
492          }      
493          freeifaddrs(net);
494          close(sock);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines