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.44 by ats, Sat Feb 14 16:58:19 2004 UTC vs.
Revision 1.52 by tdb, Mon Mar 8 11:58:53 2004 UTC

# Line 77 | Line 77 | void network_stat_init(int start, int end, network_sta
77                  net_stats->interface_name=NULL;
78                  net_stats->tx=0;
79                  net_stats->rx=0;
80 +                net_stats->ipackets=0;
81 +                net_stats->opackets=0;
82 +                net_stats->ierrors=0;
83 +                net_stats->oerrors=0;
84 +                net_stats->collisions=0;
85                  net_stats++;
86          }
87   }
# Line 124 | Line 129 | network_stat_t *get_network_stats(int *entries){
129          /* Horrible big enough, but it should be easily big enough */
130          char line[8096];
131          regex_t regex;
132 <        regmatch_t line_match[4];
132 >        regmatch_t line_match[9];
133   #endif
134   #ifdef ALLBSD
135          struct ifaddrs *net, *net_ptr;
# Line 151 | Line 156 | network_stat_t *get_network_stats(int *entries){
156                  if(network_stat_ptr->interface_name==NULL) return NULL;
157                  net_data=(struct if_data *)net_ptr->ifa_data;
158                  network_stat_ptr->rx=net_data->ifi_ibytes;
159 <                network_stat_ptr->tx=net_data->ifi_obytes;                      
159 >                network_stat_ptr->tx=net_data->ifi_obytes;
160 >                network_stat_ptr->ipackets=net_data->ifi_ipackets;
161 >                network_stat_ptr->opackets=net_data->ifi_opackets;
162 >                network_stat_ptr->ierrors=net_data->ifi_ierrors;
163 >                network_stat_ptr->oerrors=net_data->ifi_oerrors;
164 >                network_stat_ptr->collisions=net_data->ifi_collisions;
165                  network_stat_ptr->systime=time(NULL);
166                  interfaces++;
167          }
# Line 220 | Line 230 | network_stat_t *get_network_stats(int *entries){
230          fgets(line, sizeof(line), f);
231  
232  
233 <        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){
233 >        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){
234                  return NULL;
235          }
236  
237          interfaces=0;
238  
239          while((fgets(line, sizeof(line), f)) != NULL){
240 <                if((regexec(&regex, line, 4, line_match, 0))!=0){
240 >                if((regexec(&regex, line, 9, line_match, 0))!=0){
241                          continue;
242                  }
243                  network_stats=network_stat_malloc((interfaces+1), &sizeof_network_stats, network_stats);
# Line 242 | Line 252 | network_stat_t *get_network_stats(int *entries){
252  
253                  network_stat_ptr->interface_name=get_string_match(line, &line_match[1]);
254                  network_stat_ptr->rx=get_ll_match(line, &line_match[2]);
255 <                network_stat_ptr->tx=get_ll_match(line, &line_match[3]);
255 >                network_stat_ptr->tx=get_ll_match(line, &line_match[5]);
256 >                network_stat_ptr->ipackets=get_ll_match(line, &line_match[3]);
257 >                network_stat_ptr->opackets=get_ll_match(line, &line_match[6]);
258 >                network_stat_ptr->ierrors=get_ll_match(line, &line_match[4]);
259 >                network_stat_ptr->oerrors=get_ll_match(line, &line_match[7]);
260 >                network_stat_ptr->collisions=get_ll_match(line, &line_match[8]);
261                  network_stat_ptr->systime=time(NULL);
262  
263                  interfaces++;
# Line 262 | Line 277 | network_stat_t *get_network_stats(int *entries){
277   }
278  
279   long long transfer_diff(long long new, long long old){
280 < #if defined(SOL7) || defined(LINUX) || defined(FREEBSD)
281 < #define MAXVAL 4294967296LL
280 > #if defined(SOL7) || defined(LINUX) || defined(FREEBSD) || defined(DFBSD)
281 > #define MAXVAL 0xffffffffLL
282   #else
283 < #define MAXVAL 18446744073709551616LL
283 > #define MAXVAL 0xffffffffffffffffLL
284   #endif
285          long long result;
286          if(new>=old){
# Line 306 | Line 321 | network_stat_t *get_network_stats_diff(int *entries) {
321                  dest->interface_name = strdup(src->interface_name);
322                  dest->rx = src->rx;
323                  dest->tx = src->tx;
324 +                dest->ipackets = src->ipackets;
325 +                dest->opackets = src->opackets;
326 +                dest->ierrors = src->ierrors;
327 +                dest->oerrors = src->oerrors;
328 +                dest->collisions = src->collisions;
329                  dest->systime = src->systime;
330          }
331  
# Line 336 | Line 356 | network_stat_t *get_network_stats_diff(int *entries) {
356                     difference. */
357                  dest->rx = transfer_diff(src->rx, dest->rx);
358                  dest->tx = transfer_diff(src->tx, dest->tx);
359 +                dest->ipackets = transfer_diff(src->ipackets, dest->ipackets);
360 +                dest->opackets = transfer_diff(src->opackets, dest->opackets);
361 +                dest->ierrors = transfer_diff(src->ierrors, dest->ierrors);
362 +                dest->oerrors = transfer_diff(src->oerrors, dest->oerrors);
363 +                dest->collisions = transfer_diff(src->collisions, dest->collisions);
364                  dest->systime = src->systime - dest->systime;
365          }
366  
# Line 477 | Line 502 | network_iface_stat_t *get_network_iface_stats(int *ent
502                          case(IFM_1000_SX):
503                          case(IFM_1000_LX):
504                          case(IFM_1000_CX):
505 < #if defined(FREEBSD) && !defined(FREEBSD5)
506 <                        case(IFM_1000_TX):
507 <                        case(IFM_1000_FX):
508 < #else
509 <                        case(IFM_1000_T):
505 > #ifdef IFM_1000_TX
506 >                        case(IFM_1000_TX): /* FreeBSD 4 and others? */
507 > #endif
508 > #ifdef IFM_1000_FX
509 >                        case(IFM_1000_FX): /* FreeBSD 4 */
510 > #endif
511 > #ifdef IFM_1000_T
512 >                        case(IFM_1000_T): /* FreeBSD 5 */
513   #endif
514                                  network_iface_stat_ptr->speed = 1000;
515                                  break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines