TUT:Header files

From Net-SNMP Wiki
Jump to: navigation, search

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.

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!

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.

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.

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:

Operating System Specific Tutorials

Personal tools