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.59 by ats, Sun Apr 4 22:52:16 2004 UTC vs.
Revision 1.61 by tdb, Mon Apr 5 00:17:40 2004 UTC

# Line 29 | Line 29
29   #include <string.h>
30   #include "statgrab.h"
31   #include "vector.h"
32 + #include "tools.h"
33   #include <time.h>
34   #ifdef SOLARIS
35   #include <kstat.h>
# Line 39 | Line 40
40   #include <net/if.h>
41   #include <netinet/in.h>
42   #include <sys/sockio.h>
43 + #include <unistd.h>
44   #endif
45   #ifdef LINUX
46   #include <stdio.h>
# Line 48 | Line 50
50   #include <sys/socket.h>
51   #include <net/if.h>
52   #include <ctype.h>
51 #include "tools.h"
53   /* Stuff which could be defined by defining KERNEL, but
54   * that would be a bad idea, so we'll just declare it here
55   */
# Line 125 | Line 126 | network_stat_t *get_network_stats(int *entries){
126                  }
127                  network_stat_ptr=network_stats+interfaces;
128                  
129 <                if(network_stat_ptr->interface_name!=NULL) free(network_stat_ptr->interface_name);
130 <                network_stat_ptr->interface_name=strdup(net_ptr->ifa_name);
131 <                if(network_stat_ptr->interface_name==NULL) return NULL;
129 >                if (update_string(&network_stat_ptr->interface_name,
130 >                                  net_ptr->ifa_name) == NULL) {
131 >                        return NULL;
132 >                }
133                  net_data=(struct if_data *)net_ptr->ifa_data;
134                  network_stat_ptr->rx=net_data->ifi_ibytes;
135                  network_stat_ptr->tx=net_data->ifi_obytes;
# Line 224 | Line 226 | network_stat_t *get_network_stats(int *entries){
226                          network_stat_ptr->collisions=knp->value.ui32;
227  
228                          /* Read interface name */
229 <                        if(network_stat_ptr->interface_name!=NULL){
230 <                                free(network_stat_ptr->interface_name);
229 >                        if (update_string(&network_stat_ptr->interface_name,
230 >                                          ksp->ks_name) == NULL) {
231 >                                return NULL;
232                          }
230                        network_stat_ptr->interface_name=strdup(ksp->ks_name);
233  
234                          /* Store systime */
235                          network_stat_ptr->systime=time(NULL);
# Line 331 | Line 333 | network_stat_t *get_network_stats_diff(int *entries) {
333                  src = &network_stats[i];
334                  dest = &diff[i];
335  
336 <                if (dest->interface_name != NULL) {
337 <                        free(dest->interface_name);
336 >                if (update_string(&dest->interface_name,
337 >                                  src->interface_name) == NULL) {
338 >                        return NULL;
339                  }
337                dest->interface_name = strdup(src->interface_name);
340                  dest->rx = src->rx;
341                  dest->tx = src->tx;
342                  dest->ipackets = src->ipackets;
# Line 449 | Line 451 | network_iface_stat_t *get_network_iface_stats(int *ent
451                          network_iface_stat_ptr->up = 0;
452                  }
453  
454 <                if (network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
455 <                network_iface_stat_ptr->interface_name = strdup(net_ptr->ifa_name);
456 <                if (network_iface_stat_ptr->interface_name == NULL) return NULL;
454 >                if (update_string(&network_iface_stat_ptr->interface_name,
455 >                                  net_ptr->ifa_name) == NULL) {
456 >                        return NULL;
457 >                }
458  
459                  network_iface_stat_ptr->speed = 0;
460                  network_iface_stat_ptr->dup = UNKNOWN_DUPLEX;
# Line 550 | Line 553 | network_iface_stat_t *get_network_iface_stats(int *ent
553                          network_iface_stat_ptr = network_iface_stats + ifaces;
554                          ifaces++;
555  
556 <                        if (network_iface_stat_ptr->interface_name != NULL) free(network_iface_stat_ptr->interface_name);
557 <                        network_iface_stat_ptr->interface_name = strdup(ksp->ks_name);
558 <                        if (network_iface_stat_ptr->interface_name == NULL) return NULL;
556 >                        if (update_string(&network_iface_stat_ptr->interface_name,
557 >                                          ksp->ks_name) == NULL) {
558 >                                return NULL;
559 >                        }
560  
561                          if ((ifr.ifr_flags & IFF_UP) != 0) {
562                                  network_iface_stat_ptr->up = 1;
# Line 625 | Line 629 | network_iface_stat_t *get_network_iface_stats(int *ent
629                          return NULL;
630                  }
631                  network_iface_stat_ptr = network_iface_stats + ifaces;
632 <                network_iface_stat_ptr->interface_name = strdup(name);
632 >                
633 >                if (update_string(&network_iface_stat_ptr->interface_name,
634 >                                  name) == NULL) {
635 >                        return NULL;
636 >                }
637                  if ((ifr.ifr_flags & IFF_UP) != 0) {
638                          network_iface_stat_ptr->up = 1;
639                  } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines