/[machmon]/machmon/linux/source/kernel.c
ViewVC logotype

Diff of /machmon/linux/source/kernel.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by clorets, Mon Jul 8 16:19:55 2002 UTC revision 1.4 by pbastos, Tue Jul 9 12:38:59 2002 UTC
# Line 29  Line 29 
29   *   *
30   */   */
31    
 #include <kvm.h>  
   
32  #include <sys/param.h>  #include <sys/param.h>
33  #include <sys/file.h>  #include <sys/file.h>
 #include <sys/protosw.h>  
34  #include <sys/cdefs.h>  #include <sys/cdefs.h>
 #include <sys/mbuf.h>  
   
 #ifdef OPENBSD  
   
 #include <sys/socket.h>  
 #include <sys/pool.h>  
35  #include <sys/sysctl.h>  #include <sys/sysctl.h>
36    #include <sys/types.h>
37    #include <sys/socket.h>
38    #include <sys/ioctl.h>
39    
 #include <net/if.h>  
 #include <net/if_dl.h>  
 #include <net/if_types.h>  
40  #include <netinet/in.h>  #include <netinet/in.h>
41  #include <netinet/in_var.h>  #include <net/if.h>
 #include <netinet/if_ether.h>  
 #include <netns/ns.h>  
 #include <netns/ns_if.h>  
 #include <netipx/ipx.h>  
 #include <netipx/ipx_if.h>  
 #include <netiso/iso.h>  
 #include <netiso/iso_var.h>  
 #include <arpa/inet.h>  
   
 #include <fcntl.h>  
 #include <limits.h>  
 #include <unistd.h>  
 #include <paths.h>  
 #include <stdio.h>  
 #include <stdlib.h>  
 #include <string.h>  
 #include <err.h>  
   
 #endif  
   
 #ifdef FREEBSD  
   
 #include <sys/sysctl.h>  
42    
43  #include <fcntl.h>  #include <fcntl.h>
44  #include <limits.h>  #include <limits.h>
# Line 79  Line 47 
47  #include <stdio.h>  #include <stdio.h>
48  #include <stdlib.h>  #include <stdlib.h>
49  #include <string.h>  #include <string.h>
50    #include <ctype.h>
51  #include <err.h>  #include <err.h>
52    
 #endif  
   
53  #include "extern.h"  #include "extern.h"
54  #include "global.h"  #include "global.h"
55  #include "kernel.h"  #include "kernel.h"
56  #include "lncurses.h"  #include "lncurses.h"
57  #include "machmon.h"  #include "machmon.h"
58    
 kvm_t *kd;  
   
59  #ifdef _E_DEBUG  #ifdef _E_DEBUG
60  void debug_inf_w(char *, ...);  void debug_inf_w(char *, ...);
61  #endif  #endif
# Line 110  static int kernel_read(u_long, char *, s Line 75  static int kernel_read(u_long, char *, s
75    
76  #endif  #endif
77    
 /*  
  * kernel_read() uses the kernel descriptor kd to transfer size bytes of data  
  * beginning at the address addr to the buffer pointed by buff.  
  */  
   
 #ifdef OPENBSD  
   
 static int  
 kernel_read(u_long addr, char *buff, size_t size)  
 {  
         if (kvm_read(kd, addr, buff, size) != size)  
                 return (0);  
   
         return (1);  
 }  
   
 #endif  
   
 /*  
  * kernel_start() attempts to open a kernel descriptor which will be used for  
  * further conversations between we and the kernel, and a meta-symbol table  
  * for referencing objects common to both sides of the communication channel.  
  */  
   
 int  
 kernel_start(void)  
 {  
         char buff[_POSIX2_LINE_MAX];  
   
         if ((kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, buff)) == NULL)  
                 return (0);  
   
         if (kvm_nlist(kd, mm_nl) < 0 || mm_nl[0].n_type == 0)  
                 return (0);  
   
         return (1);  
 }  
   
 #ifdef OPENBSD  
   
 int  
 d_ifs(void)  
 {  
         int ifs_n = 0;  
   
         struct ifnet_head ifhead;  
         struct ifnet ifnet;  
   
         u_long *ifnetaddr = NULL;  
   
         if (!kernel_read(mm_nl[N_IFNET].n_value, (char *) &ifhead,  
                 sizeof(ifhead)))  
                 return (1);  
   
         ifnetaddr = (u_long *) ifhead.tqh_first;  
   
         output("~WInterfaces:\n");  
   
         while (ifnetaddr) {  
                 if (!kernel_read((u_long) ifnetaddr, (char *) &ifnet,  
                         sizeof(ifnet))) {  
                         free(ifnetaddr);  
                         return (1);  
                 }  
   
                 output("~G%d: ~w%s\t", ifs_n, ifnet.if_xname);  
   
                 if ((ifnet.if_flags & IFF_UP) == 0) {  
                         output("~RDOWN\n");  
                 } else {  
                         output("~GUP ");  
                         output("~C%.2f~w pkt/s in, ", (float) (((float)  
                         ifnet.if_data.ifi_ipackets - (float)  
                         l_pkt[ifs_n].packs_in) / (float) synctime));  
                         output("~R%.2f~w pkt/s out\n", (float) (((float)  
                         ifnet.if_data.ifi_opackets - (float)  
                         l_pkt[ifs_n].packs_out) / (float) synctime));  
   
                         l_pkt[ifs_n].packs_in = ifnet.if_data.ifi_ipackets;  
                         l_pkt[ifs_n].packs_out = ifnet.if_data.ifi_opackets;  
                 }  
   
                 ifs_n++;  
                 ifnetaddr = (u_long *) ifnet.if_list.tqe_next;  
         }  
   
         free(ifnetaddr);  
         return (0);  
 }  
   
 #endif  
   
 #ifdef FREEBSD  
   
78  int  int
79  d_ifs(void)  d_ifs(void)
80  {  {
81          return (1);     int ifs_n = 0;
82       char buff[512];
83       FILE *iff;
84      
85       if ((iff = (FILE *) fopen("/proc/net/dev", "r")) == NULL)
86         err(1, "d_ifs");
87      
88       (void) memset(&buff, 0x0, sizeof buff);
89       (void) fgets(buff, sizeof buff, iff);
90       (void) fgets(buff, sizeof buff, iff);
91      
92       while (fgets(buff, sizeof buff, iff)) {
93          ifs_n++;
94       }    
95       return (0);
96  }  }
97    
 #endif  
   
98  int  int
99  d_mbufs(void)  d_mbufs(void)
100  {  {
101          int mib[4], totmem;          int totmem;
102          int totpct, totused;          int totpct, totused;
         size_t size;  
103    
104  #ifdef OPENBSD  #ifdef OPENBSD
105          char poolname[32];          char poolname[32];
# Line 344  d_mbufs(void) Line 226  d_mbufs(void)
226  int  int
227  d_procs(void)  d_procs(void)
228  {  {
229          int proc_total = 0; /* total number of processes */     return (1);
         int proc_user = 0; /* processes matching u_uid */  
         struct kinfo_proc *p_inf; /* ptr to get kvm_getprocs return value */  
   
         if ((p_inf = (struct kinfo_proc *) kvm_getprocs(kd, KERN_PROC_ALL, 0,  
                  &proc_total)) == NULL || (p_inf = (struct kinfo_proc *)  
                      kvm_getprocs(kd, KERN_PROC_UID, 0,  
                          &proc_user)) == NULL)  
                 return (0);  
   
         output("~WProcesses: ~R%d~w effectively running with uid ~G%d~w, ~G%d~w total\n",  
             proc_user, 0, proc_total);  
   
         return (1);  
230  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26