TUT:Header files
From Net-SNMP Wiki
The package provides a number of include files that may be used by the general application programmer when writing applications against the Net-SNMP package APIs.
Contents |
High-level headers
There are three high-level header files, which are the only Net-SNMP includes required in a typical application. These are as follows:
net-snmp/net-snmp-config.h
- This file contains a number of configuration directives which are used to define whether other include files are included by the rest of the include files. this file is installed for convenience purposes and may be used by simple packages when possible. However, certain package authors may find it problematic to use if the package it is being used in also has its own configuration file generated by the autoconf mechanisms. Please see below for details on dealing with these issues.
net-snmp/net-snmp-includes.h
- This file is a high level wrapper around the rest of the more detailed include files. Generally speaking, if an application which is to include functionality from the base SNMP library it should include this file. At the die-hard developers may wish to include each sub-include file only as needed, as it will ease the burden on the C preprocessor.
net-snmp/agent/net-snmp-agent-includes.h
- This file is a high level wrapper around the agent specific include files. Specifically, this fall should be included by developers who are developing modules to be used within an SNMP agent. Again, hard-core developers who wish to speed up the work of the C processor can be more selective than this, however this fall is here for easiest use.
Most management application code will simply contain the two include lines:
#include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h>
Agent developers will also need to add one further line to their code files:
#include <net-snmp/agent/net-snmp-agent-includes.h>
Public API headers
Describe the seven <net-snmp/*_api.h> header files
Internal API headers
Describe the important <net-snmp/{library,agent}/*.h> header files
Autoconf
Problems may arise when an application needs to combine the Net-SNMP libraries with those from another package also uses autoconf generated configuration files. Generally, these configuration files conflict with each other due to special package symbols that autoconf inserts into the configuration files. Thus, including our particular configuration file (net-snmp/net-snmp-config.h) ahead of or below your own package's configuration file will cause conflicts.
To get around this problem, your package should probably not be including our generated configuration file but should be instead using its own. A minimal template for how to accomplish this safely is included below:
#include <stdio.h>
#include <netinet/in.h>
#include <sys/types.h>
/* If you have sys/time.h on your machine: */
#include <sys/time.h>
/* Else pick one of these instead:
#include <time.h>
#include <sys/timeb.h>
*/
/* if on windows: */
#ifdef WIN32
#include <winsock.h>
#endif
/* put a proper extern in front of certain functions */
#define NETSNMP_IMPORT extern
/* don't use inline constructs (define to inline if you want them) */
#define NETSNMP_INLINE
/* run man signal and see what the user function is supposed to return
to avoid warnings, or leave as "void" below if you don't care about
any warnings you might be seeing */
#define RETSIGTYPE void
/* tell the Net-SNMP core functionality headers that we've done the
minimal requirements */
#define NET_SNMP_CONFIG_H
/* include the core Net-SNMP functionality headers */
#include <net-snmp/net-snmp-includes.h>
Tutorial Sections
- Command Line Applications
- snmptranslate: learning about the MIB tree.
- snmpget: retrieving data from a host.
- snmpgetnext: retrieving unknown indexed data.
- snmpwalk: retrieving lots of data at once!
- snmptable: displaying a table.
- snmpset: peforming write operations.
- snmpbulkget: communicates with a network entity using SNMP GETBULK request
- snmpbulkwalk: retrieve a sub-tree of management values using SNMP GETBULK requests.
- snmptrap: Sending and receiving traps, and acting upon them.
- Traps/informs with SNMPv3: Sending and receiving SNMPv3 TRAPs and INFORMs
- Common command line options:
- Writing mib2c config files
- SNMP Daemons
- SNMP Agent (snmpd) Configuration
- SNMP Notification Receiver (snmptrapd)
- Agent Monitoring
- Coding Tutorials
- Client / Manager Coding Tutorials
- Agent Coding Tutorials
- Writing a mib module to serve information described by an SNMP MIB, and how to compile it into the net-snmp snmpd agent.
- Writing a Dynamically Loadable Object that can be loaded into the SNMP agent.
- Writing a Subagent that can be run to attach to the snmpd master agent.
- Writing a perl plugin to extend the agent using the NetSNMP::agent module.
- Using mib2c to help write an agent code template for you
- Header files and autoconf
- Building With Visual Studio 2005 Express
- Debugging SNMP Applications and Agent's
