Date: Sat, 30 Nov 1996 22:47:53 -0500 From: "Brian J. McGovern" <mcgovern@spoon.beta.com> To: questions@freebsd.org Subject: tinkering with nlist.... Message-ID: <199612010347.WAA28596@spoon.beta.com>
next in thread | raw e-mail | index | archive | help
I've been playing around with nlist() with some mixed results. Although I've been able to pull out things like _boottime with no problem, I haven't been been able to pull _loadav out (returns all 0's). I've then gone on to try to pull out IP interface names using struct ifnet's. The code I'm playing with is down below. Could anyone give me some pointers why its not working? (I'm hoping that its something stupid and easy). What I'm assuming I have to do is look up _ifnet in the kernel (via nlist), read the ifnet structure from kmem at that memory location, then lseek to the location in ifnet.if_name, and read the string thats there. Also, should I assume that _ifnet points only to the first interface structure, and have to use ifnet.ifnext, or can I just do subsequest reads from the nlist material? Eventually, I'd like to pull out some more detailed information, like packets in/out, etc, so the more information that you can give me on how to manipulate these structures (and what they are), the more I'd appreciate it. Thanks. -Brian PS - Some of the assumptions I'm working with (like the size of the interface name entity (16 bytes) are based on some simple sample code I have to sucking out boot time and load averages). The code I'm tinkering with... (nlist.c) #include <sys/param.h> #include <sys/time.h> #include <sys/file.h> #include <sys/socket.h> #include <net/if.h> #include <nlist.h> #include <stdio.h> #define NL_IFNET 0 #define IFNET_NAME my_ifnet.ifnet_name void main(void) { unsigned char name_buffer[16]; int kmem; struct nlist nl[] = { { "_ifnet" }, { 0 } }; struct ifnet my_ifnet; if ((kmem = open("/dev/kmem", O_RDONLY)) < 0) { perror("/dev/kmem"); exit(1); } if ((nlist("/kernel",nl) < 0) || (nl[0].n_type == 0)) { fprintf(stderr,"/kernel: no namelist\n"); exit(1); } lseek(kmem,(long)nl[0].n_value,L_SET); read(kmem,(char *)&my_ifnet,sizeof(struct ifnet)); lseek(kmem,my_ifnet.if_name, L_SET); read(kmem,(char *)&name_buffer,16); printf("%s\n",name_buffer); close(kmem); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612010347.WAA28596>