Re: something about reading kenel information ?

"Dave Shield" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
2008/4/25 qugjie <[email protected]>:
>  #ifdef UDPSTAT_SYMBOL
>         (this macro is define in file include/net-snmp/system/generic.h )
>     auto_nlist(UDPSTAT_SYMBOL, 0, 0);
>  #endif
>
>  what has done this routine ?

This locates the UDPSTAT_SYMBOL within the running kernel,
ready for when it will be needed later.   It does not retreive the
contents of this structure - just finds where the data is.


>  UDP_STAT_STRUCTURE udpstat;
>     here define a variable udpstat, this variable is used below.
>  but what type is it?

It is of type 'UDP_STAT_STRUCTURE'
What type this actually is depends on the O/S

On HP-UX, this is a simple integer.
On Linux, it's an internally defined structure
On Solaris it's "mib2_udp_t"
On Windows it's MIB_UDPSTATS
On Irix (?and some other) systems it's "struct kna"
On BSD-like systems it's  "struct udpstat"

Not all of these will actually use the auto_nlist mechanism.
This is probably mainly used for "struct udpstat".

That's one of the problems of having a single code base
that runs on a wide variety of kit, and delves deep into
the (O/S-specific) internals.   This was an attempt to
simplify the code - ultimately unsuccessful.

  More recently, we've tended to move away from this
#define / #ifdef  approach, and have a separate code
file for each architecture - loading the underlying data
into a single common format.
   (See 'mibgroup/hardware' for one set of examples)



>  The macro UDP_STAT_STRUCTURE is defined above,
>  #define UDP_STAT_STRUCTURE  struct udpstat
>  I cann't fine the struct udpstat where defined.

That will be defined in the system header files.
Assuming that you're using a relevant O/S.



>  If i want to get the disk size, which step i must to do?
>  In the linex kenel the struct statfs can know this, but
>  i don't know how to relate net-snmp to kernel.

That's by far the hardest part of implementing a MIB module.
In general, you're better off avoiding the kernel whenever
possible.   Linux in particular provides most information via
the /proc filesystem.   Very little of the Linux support in the
Net-SNMP agent will dig directly into the kernel.   I'd
forget all about auto_nlist if I were you.




>  I know the disk size can also get form /proc/ file system.
>  if i get this info from the /proc/file, can it be or not?

That's a better approach - yes.
Although the size of disks wouldn't typically be read from
either the kernel or /proc.   The current Net-SNMP code
for reporting on disks uses 'ioctl()' calls on the disk devices
themselves.


>  Is there some example?

See
        mibgroup/ucd-snmp/disk.c
   (which actually works with filesystems, not disks)
and
        mibgroup/host/hr_disk.c

Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.