From owner-freebsd-questions Sat Nov 30 19:48:00 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id TAA28998 for questions-outgoing; Sat, 30 Nov 1996 19:48:00 -0800 (PST) Received: from spoon.beta.com ([199.165.180.33]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id TAA28993 for ; Sat, 30 Nov 1996 19:47:56 -0800 (PST) Received: from spoon.beta.com (localhost [127.0.0.1]) by spoon.beta.com (8.8.2/8.6.9) with ESMTP id WAA28596 for ; Sat, 30 Nov 1996 22:47:54 -0500 (EST) Message-Id: <199612010347.WAA28596@spoon.beta.com> To: questions@freebsd.org Subject: tinkering with nlist.... Date: Sat, 30 Nov 1996 22:47:53 -0500 From: "Brian J. McGovern" Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 #include #include #include #include #include #include #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); }