Beispiel #1
0
int
v1_init(void)
{
   v1sock = (SOCKTYPE)INVALID_SOCKET;
#ifdef IP_V6
   v1sock6 = (SOCKTYPE)INVALID_SOCKET;
#endif

   /* by default, enable SNMP traps - increment value from 0 to 1 */
   SNMP_MIB_CTR(snmpEnableAuthenTraps);  /* 1=enabled, 2=disabled. */

#if (defined(INCLUDE_SNMPV1) || defined(INCLUDE_SNMPV2C))
#ifdef ENABLE_SNMP_TRAPS

   /* NOTE: the basic MIB-II, V1 agent can safely use the snmpbuf[] 
    * to build traps. If this is NOT the case for a particular port, 
    * then a separate trap buffer should be provided.
    */
   trap_buffer = snmpbuf;
   trap_buffer_len = SNMPSIZ;
   MEMSET(trap_buffer, 0, trap_buffer_len);

#else   /* not ENABLE_SNMP_TRAPS */
   /* disable SNMP traps - increment value from 1 to 2 */
   SNMP_MIB_CTR(snmpEnableAuthenTraps);  /* 1=enabled, 2=disabled. */
#endif /* not ENABLE_SNMP_TRAPS */
#endif /* INCLUDE_SNMPV1 or INCLUDE_SNMPV2C */

   /* If SNMPv3 is enabled, it will listen on port SNMP_PORT and 
    * receive all the packets. Hence no need to bind over here .
    */
#ifndef INCLUDE_SNMPV3
   /* open UDP connections (or sockets, or whatever) here */
   snmp_listen_sock(SNMP_PORT,&v1sock);
   agent_on = TRUE;

#ifdef IP_V6
   /* open IPv6 socket for listening */
   snmp_listen_sock6(SNMP_PORT, &v1sock6);
#endif /* IP_V6 */
   
#ifdef SNMP_TEST_SP_TRAP
   /* Trap uses 1 buffer to send a trap. So if there are multiple
    * traps, we need to send them at intervals */
   snmp_test_sp_trap(SNMP_VERSION_1);
#else    /* Test generic trap */
   /* NOT warmstart, see rfc1175, pg28 */
   snmp_trap(SNMP_TRAP_COLDSTART, 0, 0, NULL, SNMP_VERSION_1);
#endif /* SNMP_TEST_SP_TRAP */

#endif /* not INCLUDE_SNMPV3 */

   return (0);   /* return OK code */
}
Beispiel #2
0
int main()
{
	auto snmp_parms _p;
	auto snmp_parms * p;
	auto word tt;
	auto word trapindices[2];
	auto word monindex;

	// Set the community passwords
	snmp_set_dflt_communities("public", "private", "trap");

	// Set p to be a pointer to _p, for calling convenience.
	p = &_p;

	// Set parameter structure to default initial state (required).
	snmp_init_parms(p);

	// Create the MIB tree.  The following functions all operate on the parameter structure.
	// "p" is passed to all functions, and also set to the return value.  This is the recommended
	// way of doing the MIB tree setup, since if any step fails it will return NULL.  Passing the
	// NULL on to subsequent functions is harmless, and avoids the need to do error checking
	// after each call.  Only at the end of sequence sould "p" be tested for NULL.

	// Set the "root" of the MIB tree for following calls.  Note that the entire MIB
	// tree can be rooted at a different point simply by changing this one call.
	p = snmp_append_parse_stem(p, "3.1.1");	// Set to SNMP_ENTERPRISE.oemExperiments.demos
	
	// Read/write access - the following is set by default so no need to call.
	p = snmp_set_access(p, SNMP_PUBLIC_MASK|SNMP_PRIVATE_MASK, SNMP_PRIVATE_MASK);
	
	p = snmp_add_int(p, "1.1.0", &rw_int);
	monindex = snmp_last_index(p);		// Save index for later monitor call
	
	p = snmp_set_callback(p, scale);
	p = snmp_add_long(p, "1.2.0", &rw_long);	// This variable has a callback function, scale().
	p = snmp_set_callback(p, NULL);
	
	p = snmp_add_foct(p, "1.3.0", rw_fixed, 20);
	
	p = snmp_add_str(p, "1.4.0", rw_str, 20);
	
	p = snmp_add_oct(p, "1.5.0", rw_oct, 22);
	
	p = snmp_add_objectID(p, "1.6.0", &rw_oid);
	
	p = snmp_add_ipaddr(p, "1.7.0", &trapdest_ip);
	
	p = snmp_add_timeticks(p, "1.8.0", &rw_tt);

	// Read-only access for following additions
	p = snmp_set_access(p, SNMP_PUBLIC_MASK|SNMP_PRIVATE_MASK, 0);
	
	p = snmp_add_int(p, "2.1.0", &r_int);
	trapindices[0] = snmp_last_index(p);
	
	p = snmp_add_long(p, "2.2.0", &r_long);
	
	p = snmp_add_foct(p, "2.3.0", r_fixed, 20);
	
	p = snmp_add_str(p, "2.4.0", r_str, 20);
	
	p = snmp_add_oct(p, "2.5.0", r_oct, 22);
	trapindices[1] = snmp_last_index(p);
	
	p = snmp_add_objectID(p, "2.6.0", &r_oid);

	// Initialize the variables.
	rw_int = 1001;
	rw_long = 1000002;
	memcpy(rw_fixed, "rw_fixed abcdefghijk", 20);
	strcpy(rw_str, "rw_str");
	memcpy(rw_oct, "\x06\x00rw_oct", 8);
	memcpy(&rw_oid, &_p, sizeof(snmp_oid));
	trapdest_ip = aton(MANAGER_IP);
	rw_tt = snmp_timeticks();	// Set base epoch
	
	r_int = 2001;
	r_long = 2000002;
	memcpy(r_fixed, "r_fixed abcdefghijkl", 20);
	strcpy(r_str, "r_str");
	memcpy(r_oct, "\x05\x00r_oct", 7);
	memcpy(&r_oid, &_p, sizeof(snmp_oid));

	// Finally, we check that the MIB tree was constructed without error.
	// If there was any error, p will be set to NULL.
	if (!p) {
		printf("There was an error constructing the MIB.\n");
		exit(1);
	}

	// Monitor the rw_int variable (whose MIB tree index was saved in monindex).
	// trapindices was set up with the indices for r_int and r_oct.
	snmp_monitor(monindex, 0, 3000, 1, 16, 6, &trapdest_ip, SNMP_TRAPDEST, 30, 2, trapindices);

	// See what we've got.
	snmp_print_tree();
	printf("MIB tree: used %ld out of %ld bytes\n", snmp_used(), (long)SNMP_MIB_SIZE);

	// Now start up the network
	sock_init();

	// Print interfaces
	ip_print_ifs();
	
	// Print routers
	router_printall();
	

	tt = _SET_SHORT_TIMEOUT(5000);
	
	for (;;) {
		if (_CHK_SHORT_TIMEOUT(tt)) {
#ifdef SEND_TRAPS
			snmp_trap(trapdest_ip, SNMP_TRAPDEST, 20, 2, trapindices);
#endif
			tt = _SET_SHORT_TIMEOUT(5000);
			
		}
		tcp_tick(NULL);
	}
}
Beispiel #3
0
//-----------------------------------------------
void snmp_trap_send(char* str, unsigned short in)
{
U16 obj[3];
U8 temp_ip[4];
char i,ii;

for(i=0;(i<100);i++)
	{
	snmp_spc_trap_message[i]=0;
	}


obj[0] = 0;
ii=1;
if(str!=0)
	{
	obj[0]++;
	for(i=0;(i<100)&&(str[i]);i++)
		{
		snmp_spc_trap_message[i]=str[i];
		}
	obj[ii] = 38;
	ii++;
	}
if(in!=0xffff)
	{
	obj[0]++;
	snmp_spc_trap_value=in;
	obj[ii] = 39;
	}



if((ETH_TRAP1_IP_1!=255)&&(ETH_TRAP1_IP_2!=255)&&(ETH_TRAP1_IP_3!=255)&&(ETH_TRAP1_IP_4!=255))
	{
	temp_ip[0]= ETH_TRAP1_IP_1;
	temp_ip[1]= ETH_TRAP1_IP_2;
	temp_ip[2]= ETH_TRAP1_IP_3;
	temp_ip[3]= ETH_TRAP1_IP_4;
	snmp_trap (temp_ip, 6, 3, obj);
	}
if((ETH_TRAP2_IP_1!=255)&&(ETH_TRAP2_IP_2!=255)&&(ETH_TRAP1_IP_3!=255)&&(ETH_TRAP2_IP_4!=255))
	{
	temp_ip[0]= ETH_TRAP2_IP_1;
	temp_ip[1]= ETH_TRAP2_IP_2;
	temp_ip[2]= ETH_TRAP2_IP_3;
	temp_ip[3]= ETH_TRAP2_IP_4;
	snmp_trap (temp_ip, 6, 3, obj);
	}
if((ETH_TRAP3_IP_1!=255)&&(ETH_TRAP3_IP_2!=255)&&(ETH_TRAP3_IP_3!=255)&&(ETH_TRAP3_IP_4!=255))
	{
	temp_ip[0]= ETH_TRAP3_IP_1;
	temp_ip[1]= ETH_TRAP3_IP_2;
	temp_ip[2]= ETH_TRAP3_IP_3;
	temp_ip[3]= ETH_TRAP3_IP_4;
	snmp_trap (temp_ip, 6, 3, obj);
	} 
if((ETH_TRAP4_IP_1!=255)&&(ETH_TRAP4_IP_2!=255)&&(ETH_TRAP4_IP_3!=255)&&(ETH_TRAP4_IP_4!=255))
	{
	temp_ip[0]= ETH_TRAP4_IP_1;
	temp_ip[1]= ETH_TRAP4_IP_2;
	temp_ip[2]= ETH_TRAP4_IP_3;
	temp_ip[3]= ETH_TRAP4_IP_4;
	snmp_trap (temp_ip, 6, 3, obj);
	}
if((ETH_TRAP5_IP_1!=255)&&(ETH_TRAP5_IP_2!=255)&&(ETH_TRAP5_IP_3!=255)&&(ETH_TRAP5_IP_4!=255))
	{
	temp_ip[0]= ETH_TRAP5_IP_1;
	temp_ip[1]= ETH_TRAP5_IP_2;
	temp_ip[2]= ETH_TRAP5_IP_3;
	temp_ip[3]= ETH_TRAP5_IP_4;
	snmp_trap (temp_ip, 6, 3, obj);
	} 
}