3 * 13 Jun 91 wsak (wk0x@andrew) added mips support
6 #include <net-snmp/net-snmp-config.h>
10 #include <sys/types.h>
26 #include <netinet/in.h>
32 #include <net-snmp/net-snmp-includes.h>
35 #include <net-snmp/agent/ds_agent.h>
46 init_kmem(const char *file)
48 #if HAVE_KVM_OPENFILES
50 kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, err);
51 if (kd == NULL && !netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
52 NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) {
53 snmp_log(LOG_CRIT, "init_kmem: kvm_openfiles failed: %s\n", err);
57 kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
58 if (!kd && !netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
59 NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) {
60 snmp_log(LOG_CRIT, "init_kmem: kvm_open failed: %s\n",
64 #endif /* HAVE_KVM_OPENFILES */
71 * It seeks to the location off in kmem
72 * It does a read into target of siz bytes.
74 * Return 0 on failure and 1 on sucess.
80 klookup(unsigned long off, char *target, int siz)
85 result = kvm_read(kd, off, target, siz);
87 #if HAVE_KVM_OPENFILES
88 snmp_log(LOG_ERR, "kvm_read(*, %lx, %p, %d) = %d: %s\n", off,
89 target, siz, result, kvm_geterr(kd));
91 snmp_log(LOG_ERR, "kvm_read(*, %lx, %p, %d) = %d: ", off, target,
93 snmp_log_perror("klookup");
100 #else /* HAVE_KVM_H */
102 static off_t klseek(off_t);
103 static int klread(char *, int);
107 init_kmem(const char *file)
109 kmem = open(file, O_RDONLY);
110 if (kmem < 0 && !netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
111 NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) {
112 snmp_log_perror(file);
115 fcntl(kmem, F_SETFD, 1);
116 mem = open("/dev/mem", O_RDONLY);
117 if (mem < 0 && !netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
118 NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) {
119 snmp_log_perror("/dev/mem");
122 fcntl(mem, F_SETFD, 1);
124 swap = open(DMEM_LOC, O_RDONLY);
125 if (swap < 0 && !netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
126 NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) {
127 snmp_log_perror(DMEM_LOC);
130 fcntl(swap, F_SETFD, 1);
136 * Seek into the kernel for a value.
141 return (lseek(kmem, (off_t) base, SEEK_SET));
146 * Read from the kernel
149 klread(char *buf, int buflen)
151 return (read(kmem, buf, buflen));
158 * It seeks to the location off in kmem
159 * It does a read into target of siz bytes.
161 * Return 0 on failure and 1 on sucess.
167 klookup(unsigned long off, char *target, int siz)
174 if ((retsiz = klseek((off_t) off)) != off) {
175 snmp_log(LOG_ERR, "klookup(%lx, %p, %d): ", off, target, siz);
176 snmp_log_perror("klseek");
177 #ifdef EXIT_ON_BAD_KLREAD
182 if ((retsiz = klread(target, siz)) != siz) {
183 if (snmp_get_do_debugging()) {
185 * these happen too often on too many architectures to print them
186 * unless we're in debugging mode. People get very full log files.
188 snmp_log(LOG_ERR, "klookup(%lx, %p, %d): ", off, target, siz);
189 snmp_log_perror("klread");
191 #ifdef EXIT_ON_BAD_KLREAD
199 #endif /* HAVE_KVM_H */
201 #endif /* CAN_USE_NLIST */