Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / man / snmp_agent_api.3.def
1 .TH SNMP_AGENT_API 3 "02 Apr 2001" VVERSIONINFO "Net-SNMP"
2 .UC 5
3 .SH NAME
4 snmp_agent_api \- embedding an agent into a external application
5 .SH SYNOPSIS
6 .nf
7 #include <net-snmp/net-snmp-config.h>
8 #include <net-snmp/net-snmp-includes.h>
9 #include <net-snmp/agent/net-snmp-agent-includes.h>
10
11 int
12 main (int argc, char *argv[])
13 {
14   int agentx_subagent = 1;  /* Change this if you're a master agent.  */
15
16   snmp_enable_stderrlog();
17
18   /*  If we're an AgentX subagent...  */
19   if (agentx_subagent) {
20       /* ...make us an AgentX client.  */
21       netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
22                              NETSNMP_DS_AGENT_ROLE, 1);
23   }
24
25   init_agent("yourappname");
26
27   /*  Initialize your MIB code here.  */
28   init_my_mib_code();
29
30   /*  `yourappname' will be used to read yourappname.conf files.  */
31   init_snmp("yourappname");
32
33   /*  If we're going to be a SNMP master agent...  */
34   if (!agentx_subagent)
35       init_master_agent();  /*  Listen on default port (161).  */
36
37   /*  Your main loop here...  */
38   while (whatever) {
39       /* if you use select(), see snmp_api(3) */
40       /*     --- OR ---  */
41       agent_check_and_process(0); /* 0 == don't block */
42   }
43
44   /*  At shutdown time:  */
45   snmp_shutdown("yourappname");
46 }
47
48 Then:
49 $(CC) ... `net-snmp-config --agent-libs`
50
51 .fi
52 .SH DESCRIPTION
53 .PP
54 Our goal is to create a easy to use interface to the Net-SNMP package
55 such that you can take code that you have written that has been
56 designed to be a Net-SNMP MIB module and embed it into an external
57 application where you can either chose to be a SNMP master agent or an
58 AgentX sub-agent using the same MIB module code.  Our suggestion is
59 that you use our (or another) SNMP agent as the AgentX master agent
60 and chose to become an AgentX subagent which then attaches to the
61 master.
62 .PP
63 The Net-SNMP package provides a pair of libraries that enables easy
64 embedding of an SNMP or AgentX agent into an external software
65 package. AgentX is an extensible protocol designed to allow multiple
66 SNMP sub-agents all run on one machine under a single SNMP master
67 agent.  It is defined in RFC 2741.
68 .PP
69 You will need to perform a few tasks in order to accomplish
70 this. First off, you will need to initialize both the SNMP library and
71 the SNMP agent library. As indicated above, this is done slightly
72 differently depending on whether or not you are going to perform as a
73 master agent or an AgentX sub-agent.
74 .SH CONFIGURATION
75 .PP
76 If you intend to operate as an AgentX sub-agent, you will have to
77 configured the Net-SNMP package with agentx support (which is turned
78 on by default, so just don't turn it off)
79 .PP
80 Additionally, you will need to link against the net-snmp libraries
81 (use the output of "net-snmp-config --agent-libs" to get a library
82 list) and call subagent_pre_init() as indicated above.
83 .SH COMPILING
84 .PP
85 In order to make use of any of the above API, you will need to link
86 against at least the four libraries listed above.
87 .SH FUNCTIONS
88 .PP This is a brief description of the functions called above and
89 where to find out more information on them.  It is certainly not a
90 complete list of what is available within all the net-snmp libraries. 
91 .IP "snmp_enable_stderrlog()"
92 Logs error output from the SNMP agent to the standard error stream.
93 .IP "netsnmp_ds_set_boolean()"
94 Please see the
95 .IR default_store(3)
96 manual page for more information
97 about this API.
98 .IP "init_agent(char *name)"
99 Initializes the embedded agent.  This should be called before the
100 .BR "init_snmp()"
101 call.  
102 .I name
103 is used to dictate what .conf file to read when
104 .BR "init_snmp()"
105 is called later.
106 .IP "init_snmp(char *name)"
107 Initializes the SNMP library.  Note that one of the things this will
108 do will be to read configuration files in an effort to configure your
109 application. It will attempt to read the configuration files named by
110 the
111 .I name
112 string that you passed in.  It can be used to configure access
113 control, for instance.   Please see the
114 .IR read_config(3) ", " snmp_config(5) ", and " snmpd.conf(5)
115 manual pages for further details on this subject.
116 .IP "init_master_agent(void)"
117 Initializes the master agent and causes it to listen for SNMP requests 
118 on its default UDP port of 161.
119 .IP "agent_check_and_process(int block)"
120 This checks for packets arriving on the SNMP port and processes them
121 if some are found.  If 
122 .I block
123 is non-zero, the function call will block until a packet arrives or an 
124 alarm must be run (see
125 .IR snmp_alarm(3) ).
126 The return value from this function is a positive integer if packets
127 were processed, zero if an alarm occurred and -1 if an error occured.
128 .IP "snmp_shutdown(char *name);"
129 This shuts down the agent, saving any needed persistent storage, etc.
130 .SH "SEE ALSO"
131 http://www.net-snmp.org/tutorial-5/toolkit/, select(2), snmp_api(3),
132 default_store(3), snmp_alarm(3), read_config(3), snmp_config(5),
133 snmpd.conf(5)