⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toast_sa.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/unxagent/toast_sa.c,v 1.3 2003/01/15 14:04:59 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1994-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//**********************************************************************//*                                                                    *//*  Simple SNMP sub agent, using the toaster mib                      *//*                                                                    *//**********************************************************************//* * $Log: toast_sa.c,v $ * Revision 1.3  2003/01/15 14:04:59  josh * directory structure shifting * * Revision 1.2  2001/11/09 21:48:59  josh * unxagent demo path adjustment, first pass * * Revision 1.1.1.1  2001/11/05 17:49:16  tneale * Tornado shuffle * * Revision 7.9  2001/01/19 22:24:59  paul * Update copyright. * * Revision 7.8  2000/03/17 00:14:55  meister * Update copyright message * * Revision 7.7  1998/06/03 21:56:23  sar * Updated code to use common string macros * * Revision 7.6  1998/02/25 04:58:13  sra * Update copyrights. * * Revision 7.5  1997/10/22 23:44:57  sar * Changed a printf format command to match the variable type * * Revision 7.4  1997/10/22 02:59:11  sar * Removed the declaration of the snmp_coarselock as it is included in * envoy_init, which was added * * Revision 7.3  1997/03/20 06:54:22  sra * DFARS-safe copyright text.  Zap! * * Revision 7.2  1997/02/25 10:58:16  sra * Update copyright notice, dust under the bed. * * Revision 7.1  1997/01/08 22:46:52  sar * Updated copyright and changed include files to use envoy/h where * appropriate * * Revision 7.0  1996/03/15  21:57:35  sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.0  1995/05/31  21:49:56  sra * Release 6.0. * * Revision 5.4  1995/05/29  03:03:22  sar * Added stub routines for time functions * * Revision 5.3  1995/05/25  03:05:33  sar * Changed some sa_handler calls to sa_handler_async * * Revision 5.2  1995/03/21  20:03:28  sar * Updated to use the async api & scheme * * Revision 5.1  1994/10/25  20:09:59  sar * Added an ifdef to allocate SNMP_CoarseLock if we are building a strcit * subagent. * Also modified some fprintf's to use %ld instead of %d * * Revision 5.0  1994/05/16  16:40:08  sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 1.3  1994/05/09  21:09:32  sar * Added a free routine for test purposes. * * Revision 1.2  1994/05/06  20:29:10  sar * Updated use of demuxer, fixed some potential memory leaks. * * Revision 1.1  1994/05/04  22:39:30  sar * Initial revision * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include <wrn/wm/common/config.h>#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/un.h>#include <ctype.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/buildpkt.h>#include <wrn/wm/snmp/engine/subagent.h>#include <wrn/wm/snmp/engine/etimer.h>#include <wrn/wm/common/glue.h>#define LM_toastManf	1#define LM_toastModel	2#define LM_toastControl 3#define LM_toastDone	4#define LM_toastType	5char toaster_manf[] = "Sunbeam";char cd_ModelNumber[] = "Radiant Automatic";INT_32_T toasterstate = 1;INT_32_T toasterdoneness = 1;INT_32_T toasttype = 1;extern int errno;typedef struct EX_SAADDR_S	{	int		   sock;	int		   fromlen;	struct sockaddr_un from;	} EX_SAADDR_T;#define BUFLEN 2000#define MASTER "/tmp/M_AGENT"#define SUBAGENT "/tmp/TOASTER"void  reg_compat(INT_32_T     ecode,	     SA_HEADER_T *hdr_blk,	     VBL_T	 *vblp,	     PTR_T	  cookie){if (ecode) {    printf("Error handling reply to registration request: %ld\n", ecode);    exit(1);    }if (hdr_blk->sa_error) {    printf("Error handling reply to registration request: %d\n",	   hdr_blk->sa_error);    exit(1);    }SNMP_memory_free(cookie);return;}void  err_compat(int	ecode,	     PTR_T	cookie){printf("Received packet generated error %d\n", ecode);SNMP_memory_free(cookie);return;}	void  io_compat(PTR_T	 pktp,	    SA_HEADER_T *hdr_blk,	    PTR_T	 cookie){EBUFFER_T ebuf;EX_SAADDR_T *addr_ptr;addr_ptr = (EX_SAADDR_T *)cookie;EBufferInitialize(&ebuf);if (SA_Handler_Finish(pktp, hdr_blk, &ebuf))    SA_Handler_Cleanup(pktp, hdr_blk);else {    sendto(addr_ptr->sock, EBufferStart(&ebuf), EBufferUsed(&ebuf), 0,	   (struct sockaddr *)&(addr_ptr->from), addr_ptr->fromlen);    SNMP_memory_free(addr_ptr);    EBufferClean(&ebuf);    }return;}intmain(argc, argv)    int argc;    char **argv;{int sock, cc;struct sockaddr_un master_name, sa_name;char buf[BUFLEN], *subagent;SA_HEADER_T hdr_blk;INT_32_T eret;VBL_T vblist;EBUFFER_T ebuf, rbuf;SA_DEMUX_T demuxer;static OIDC_T toastoidc1[] = {1, 3, 6, 1, 4, 1, 12, 2, 1};static OIDC_T toastoidc2[] = {1, 3, 6, 1, 4, 1, 12, 2, 2};static OIDC_T toastoidc3[] = {1, 3, 6, 1, 4, 1, 12, 2, 3};static OIDC_T toastoidc4[] = {1, 3, 6, 1, 4, 1, 12, 2, 4};static OIDC_T toastoidc5[] = {1, 3, 6, 1, 4, 1, 12, 2, 5};VB_T  vb[5];EX_SAADDR_T *cookie;/* Initialize envoy */envoy_init();if (argc > 1)    subagent = argv[1];else    subagent = SUBAGENT;/* Initialize some of the arguments */vblist.vbl_count = 0;vblist.vblist    = 0;vblist.vblp      = 0;EBufferInitialize(&ebuf);EBufferInitialize(&rbuf);/* create message */(void)MEMSET(vb, 0, 5 * sizeof(VB_T));vb[0].vb_flags			= VFLAG_SA_SENDIT;vb[0].vb_obj_id.num_components  = 9;vb[0].vb_obj_id.component_list  = toastoidc1;vb[0].vb_data_flags_n_type	= VT_STRING;vb[0].vb_access			= 0x01;vb[1].vb_flags			= VFLAG_SA_SENDIT;vb[1].vb_obj_id.num_components	= 9;vb[1].vb_obj_id.component_list	= toastoidc2;vb[1].vb_data_flags_n_type	= VT_STRING;vb[1].vb_access			= 0x01;vb[2].vb_flags			= VFLAG_SA_SENDIT;vb[2].vb_obj_id.num_components	= 9;vb[2].vb_obj_id.component_list	= toastoidc3;vb[2].vb_data_flags_n_type	= VT_NUMBER;vb[2].vb_access			= 0x03;vb[3].vb_flags			= VFLAG_SA_SENDIT;vb[3].vb_obj_id.num_components	= 9;vb[3].vb_obj_id.component_list	= toastoidc4;vb[3].vb_data_flags_n_type	= VT_NUMBER;vb[3].vb_access			= 0x03;vb[4].vb_flags			= VFLAG_SA_SENDIT;vb[4].vb_obj_id.num_components	= 9;vb[4].vb_obj_id.component_list	= toastoidc5;vb[4].vb_data_flags_n_type	= VT_NUMBER;vb[4].vb_access			= 0x03;vblist.vbl_count = 5;vblist.vblist    = vb;EBufferInitialize(&demuxer.string);init_object_id(&demuxer.object);(void)MEMSET(&hdr_blk, 0, sizeof(SA_HEADER_T));hdr_blk.version    = 1;hdr_blk.opcode1    = SA_REG_OBJ_REQUEST;hdr_blk.encoding   = SA_ENCODING_ASN1;eret = SA_Encode(&vblist, &hdr_blk, &demuxer, &ebuf);if (eret) {    printf("Error creating message %ld\n", eret);    exit(1);    }/* build socket */sock = socket(AF_UNIX, SOCK_DGRAM, 0);if (sock < 0) {    printf("Error opening datagram socket\n");    exit(1);    }unlink(subagent);sa_name.sun_family = AF_UNIX;STRCPY(sa_name.sun_path, subagent);/* bind the socket to a name */if (bind(sock, (struct sockaddr *)&sa_name, sizeof(struct sockaddr_un))) {    printf("Error binding socket name\n");    exit(1);    }master_name.sun_family = AF_UNIX;STRCPY(master_name.sun_path, MASTER);/* send message */while(sendto(sock, EBufferStart(&ebuf), EBufferUsed(&ebuf), 0,	   (struct sockaddr *)&master_name, sizeof(struct sockaddr_un)) < 0) {    printf("Registration request failed: %d, will try again\n", errno);    }/* clean up the buffer */EBufferClean(&ebuf);/* Loop waiting for messages.  Receive a message, call sa_handler to   process it, then send the reply if required */   while(1) {    cookie = (EX_SAADDR_T *)SNMP_memory_alloc(sizeof(EX_SAADDR_T));    if (cookie == 0) {	printf("Unable to allocate control block\n");	exit(1);	}    cookie->sock = sock;    cookie->fromlen = sizeof(struct sockaddr_un);    cc = recvfrom(sock, buf, BUFLEN, 0, (struct sockaddr *)&(cookie->from),		  &(cookie->fromlen));    SA_Handler_Async((OCTET_T *)buf, (ALENGTH_T)cc, 0,		     io_compat, err_compat, reg_compat,		     (PTR_T)cookie);    }}void  toaster_free(PTR_T vbptr){return;}/****************************************************************************NAME:  toaster_testPURPOSE:  Find the appropriate entry in the sub agent table and attach	  information from it to the vbp using the getproc_got_* functions.	  If we can't find an entry indicate that by calling getproc_nosuchins.PARAMETERS:	OIDC_T		Last component of the object id leading to			the leaf node in the MIB.  This is usually			the identifier for the particular attribute			in the table.	int		Number of components in the unused part of the			object identifier	OIDC_T *	Unused part of the object identifier	SNMP_PKT_T *	SNMP packet currently being processed.	VB_T *		Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void  toaster_test(OIDC_T		 last_match,	       int		 tcount,	       OIDC_T		*tlist,	       SNMP_PKT_T	*pktp,	       VB_T		*vbp){INT_32_T value;value = VB_GET_INT32(vbp);if (value < 1) {    testproc_error(pktp, vbp, WRONG_VALUE);    return;    }switch (last_match) {   case LM_toastControl:	if (value > 2) {	    testproc_error(pktp, vbp, WRONG_VALUE);	    return;	    }	break;    case LM_toastDone:	if (value > 10) {	    testproc_error(pktp, vbp, WRONG_VALUE);	    return;	    }	break;    case LM_toastType:	if (value > 7) {	    testproc_error(pktp, vbp, WRONG_VALUE);	    return;	    }	break;    }if ((tcount != 1) || (*tlist != 0)) {    testproc_error(pktp, vbp, NO_CREATION);    return;    }testproc_good(pktp, vbp);vbp->vb_free_priv = toaster_free;vbp->vb_priv = 0;return;}/****************************************************************************NAME:  toaster_setPURPOSE:  Find the appropriate entry in the sub agent table and attach	  information from it to the vbp using the getproc_got_* functions.	  If we can't find an entry indicate that by calling getproc_nosuchins.PARAMETERS:	OIDC_T		Last component of the object id leading to			the leaf node in the MIB.  This is usually			the identifier for the particular attribute			in the table.	int		Number of components in the unused part of the			object identifier	OIDC_T *	Unused part of the object identifier	SNMP_PKT_T *	SNMP packet currently being processed.	VB_T *		Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void  toaster_set(OIDC_T		 last_match,	      int		 tcount,	      OIDC_T		*tlist,	      SNMP_PKT_T	*pktp,	      VB_T		*vbp){switch (last_match) {    case LM_toastControl:	toasterstate = VB_GET_INT32(vbp);	break;    case LM_toastDone:	toasterdoneness = VB_GET_INT32(vbp);	break;    case LM_toastType:	toasttype = VB_GET_INT32(vbp);	break;    }setproc_good(pktp, vbp);vbp->vb_free_priv = 0;vbp->vb_priv = 0;return;}/* Stub routines to keep from using the versions in sun/agent.c */bits32_t  envoy_now(void){return(0);}void  envoy_call_timer (bits32_t when,		    void (*what)(void)){return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -