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.50 by ats, Sat Mar 6 22:30:54 2004 UTC vs.
Revision 1.58 by tdb, Sun Apr 4 21:54:48 2004 UTC

# Line 66 | Line 66 | typedef __uint64_t u64;
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 180 | 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){
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){
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 237 | Line 283 | network_stat_t *get_network_stats(int *entries){
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 277 | 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) || defined(DFBSD)
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
285        long long result;
286        if(new>=old){
287                result = (new-old);
288        }else{
289                result = (MAXVAL+(new-old));
290        }
291
292        return result;
293
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 502 | 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 < #ifdef IFM_1000_TX
550 <                        case(IFM_1000_TX): /* FreeBSD 4 and others? */
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 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines