components/net-snmp-57/sun/sdk/demo/demo_module_8/demo_module_8.c
changeset 5867 445e2cf1c845
parent 252 ee0fb1eabcbf
equal deleted inserted replaced
5866:683c5c035a79 5867:445e2cf1c845
       
     1 /*
       
     2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
       
     3  *
       
     4  * U.S. Government Rights - Commercial software. Government users are subject
       
     5  * to the Sun Microsystems, Inc. standard license agreement and applicable
       
     6  * provisions of the FAR and its supplements.
       
     7  *
       
     8  *
       
     9  * This distribution may include materials developed by third parties. Sun,
       
    10  * Sun Microsystems, the Sun logo and Solaris are trademarks or registered
       
    11  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
       
    12  *
       
    13  */
       
    14  
       
    15 #include <net-snmp/net-snmp-config.h>
       
    16 #include <net-snmp/net-snmp-includes.h>
       
    17 #include <net-snmp/agent/net-snmp-agent-includes.h>
       
    18 #include <signal.h>
       
    19 
       
    20 #include <me1LoadGroup.h>
       
    21 
       
    22 static int keep_running;
       
    23 
       
    24 RETSIGTYPE
       
    25 stop_server(int a)
       
    26 {
       
    27 	keep_running = 0;
       
    28 }
       
    29 
       
    30 int
       
    31 main(int argc, char **argv)
       
    32 {
       
    33 	int agentx_subagent = 1;
       
    34 	//Change to make an SNMP master agent
       
    35 
       
    36 	/* print log errors to stderr */
       
    37 		snmp_enable_stderrlog();
       
    38 
       
    39 	/* we're an agentx subagent? */
       
    40 	if (agentx_subagent) {
       
    41 		/*
       
    42 		 * This is an agentx client. Specify 0 for
       
    43 		 * NETSNMP_DS_AGENT_ROLE if the agent is master agent.
       
    44 		 * Specify 1 for NETSNMP_DS_AGENT_ROLE, if the agent is a
       
    45 		 * client.
       
    46 		 */
       
    47 		netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
       
    48 				NETSNMP_DS_AGENT_ROLE, 1);
       
    49 		DEBUGMSGTL(("demo_module_8",
       
    50 				"NETSNMP_DS_APPLICATION_ID = %s:\n",
       
    51 				NETSNMP_DS_APPLICATION_ID));
       
    52 		DEBUGMSGTL(("demo_module_8", "NETSNMP_DS_AGENT_ROLE = %s:\n",
       
    53 				NETSNMP_DS_AGENT_ROLE));
       
    54 	}
       
    55 	/*
       
    56 	 * Initializes the embedded agent.  Call this function before the
       
    57 	 * init_snmp() call. The string name specifies which .conf file to
       
    58 	 * read when init_snmp() is called later.
       
    59 	 */
       
    60 	init_agent("demo_module_8");
       
    61 	DEBUGMSGTL(("demo_module_8", "CALLING init_agent\n"));
       
    62 
       
    63 	/* initialize mib code here */
       
    64 
       
    65 	/* mib code: init_me1LoadGroup from me1LoadGroup.c */
       
    66 	init_me1LoadGroup();
       
    67 
       
    68 	/*
       
    69 	 * Initializes the SNMP library, which causes the agent to read your
       
    70 	 * application's configuration files. The agent first tries to read
       
    71 	 * the configuration files named by the string passed as an argument.
       
    72 	 * You might use this to configure  access  control, for example.
       
    73 	 */
       
    74 	init_snmp("demo_module_8");
       
    75 
       
    76 	/*
       
    77 	 * Initializes the master agent and causes it to listen for SNMP
       
    78 	 * requests on its default UDP port of 161. Open the port to listen
       
    79 	 * (defaults to udp: 161)
       
    80 	 */
       
    81 	if (!agentx_subagent)
       
    82 		init_master_agent();
       
    83 
       
    84 	/* In case we get a request to stop (kill -TERM or kill -INT) */
       
    85 	keep_running = 1;
       
    86 	signal(SIGTERM, stop_server);
       
    87 	signal(SIGINT, stop_server);
       
    88 
       
    89 	/*
       
    90 	 * The main loop. If you use select(), see snmp_select_info() in
       
    91 	 * snmp_api(3). This checks for packets arriving on the SNMP port and
       
    92 	 * processes them if some are found. If block is non zero, the
       
    93 	 * function call blocks until a packet arrives or an alarm must be
       
    94 	 * run (see snmp_alarm(3)).
       
    95 	 *
       
    96 	 * The return value from this function is a positive integer if packets
       
    97 	 * were processed, zero if an alarm occurre, and -1 if an error
       
    98 	 * occured.
       
    99 	 */
       
   100 
       
   101 	while (keep_running) {
       
   102 		/* OR */
       
   103 		agent_check_and_process(1);	/* 0 == don't block */
       
   104 	}
       
   105 	/*
       
   106 	 * Shuts down the agent, saving any needed persistent storage.
       
   107 	 */
       
   108 	snmp_shutdown("demo_module_8");
       
   109 }