Difference between revisions of "TUT:Header files"
(Wikification of HTML Tutorial page) |
m (Use general tasks, not important ones) |
||
Line 27: | Line 27: | ||
== Public API headers == | == Public API headers == | ||
− | ''<tasks>[ | + | ''<tasks>[ ]Describe the seven <net-snmp/*_api.h> header files</tasks>'' |
== Internal API headers == | == Internal API headers == | ||
− | ''<tasks>[ | + | ''<tasks>[ ]Describe the important <net-snmp/{library,agent}/*.h> header files</tasks>'' |
== Autoconf == | == Autoconf == |
Latest revision as of 15:50, 31 October 2007
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
<tasks>[ ]Describe the seven <net-snmp/*_api.h> header files</tasks>
Internal API headers
<tasks>[ ]Describe the important <net-snmp/{library,agent}/*.h> header files</tasks>
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
About the SNMP Protocol
These tutorial links talk about SNMP generically and how the protocol itself works. They are good introductory reading material and the concepts are important to understand before diving into the later tutorials about Net-SNMP itself.
- How SNMP Works: About the protocol itself (GETs, GETNEXTs, etc)
- What data is in SNMP: All about SNMP Management Information Bases (MIBs)
- Securing SNMP: How to use the SNMP protocol securely
Net-SNMP Command Line Applications
These tutorial pages discuss the command line tools provided in the Net-SNMP suite of tools. Nearly all the example commands in these tutorials works if you try it yourself, as they're all examples that talk to our online Net-SNMP test agent. Given them a shot!
- 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/USM: Sending and receiving SNMPv3/USM TRAPs and INFORMs
- Sending Traps/Informs via AgentX: Sending notifications from the command line through snmpd
- Common command line options:
- Writing mib2c config files
Application Configuration
All of our applications support configuration to allow you to customize how they behave.
Net-SNMP Daemons
Net-SNMP comes with two long-running daemons: a SNMP agent (snmpd) for responding to management requests and a notification receiver (snmptrapd) for receiving SNMP notifications.
- SNMP Agent (snmpd) Configuration
- SNMP Notification Receiver (snmptrapd)
- Agent Monitoring
Coding Tutorials
Net-SNMP comes with a highly flexible and extensible API. The API allows you to create your own commands, add extensions to the agent to support your own MIBs and perform specialized processing of notifications.
- Client / Manager Coding Tutorials
- Agent Coding Tutorials
- The Agent Architecture page might be worth reading before or after the agent coding tutorials, and describes how the Agent Helpers work under the hood.
- 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.
- Writing shell scripts to extend the agent
- Using mib2c to help write an agent code template for you
- Header files and autoconf
Debugging SNMP Applications and Agents
All our tools and applications have extensive debugging output. These tutorials talk about how the debugging system works and how you can add your own debugging statements to you code:
- Debugging output printed using the -D command line option
- Using -Ddump to display packet breakdowns
- Debugging using GDB
Operating System Specific Tutorials
- Building With Visual Studio 2005 Express
- Building Net-SNMP 64-bit with Visual C++ 2010 Express
- Net-Snmp on Ubuntu
- Net-SNMP and lm-sensors on Ubuntu 10.04
- Net-SNMP for windows: