📄 table_sa.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/unxagent/table_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, demoing a table *//* *//**********************************************************************//* * $Log: table_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:58 paul * Update copyright. * * Revision 7.8 2000/03/17 00:14:55 meister * Update copyright message * * Revision 7.7 1998/06/03 21:56:22 sar * Updated code to use common string macros * * Revision 7.6 1998/02/25 04:58:12 sra * Update copyrights. * * Revision 7.5 1997/10/22 23:44:56 sar * Changed a printf format command to match the variable type * * Revision 7.4 1997/10/22 02:59:10 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:21 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.1 1995/11/01 01:01:02 sar * Added pp style argument lists and removed no_pp style stuff * * Revision 6.0 1995/05/31 21:49:54 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.4 1994/05/13 22:02:03 sar * chaned unused field in hdr_blk to be snmp_version. * * 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>typedef struct INDEXLIST_S { int index; int type; } INDEXLIST_T;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/TABLE"extern int errno;#define LM_tableindex 1#define LM_tabledescr 2#define LM_tabletype 3INDEXLIST_T *indexlist;int ilen;char *subagent;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;}int main(int argc, char **argv){int sock, fromlen, cc, i, j;struct sockaddr_un master_name, sa_name, from;char buf[BUFLEN], *vbuf;SA_HEADER_T hdr_blk;INT_32_T eret, groupid = 0;VBL_T vblist, rvblist;VB_T *vbp, *vbl;EBUFFER_T ebuf, rbuf;SA_DEMUX_T demuxer;static OIDC_T tableoidc[] = {1, 3, 6, 1, 4, 1, 12, 8, 1, 1, 0, 0};int tableoidclen = 12;EX_SAADDR_T *cookie;/* Initialize envoy */envoy_init();/* Initialize some of the arguments */vblist.vbl_count = rvblist.vbl_count = 0;vblist.vblist = rvblist.vblist = 0;vblist.vblp = rvblist.vblp = 0;EBufferInitialize(&ebuf);EBufferInitialize(&rbuf);if (argc < 3) { printf("Usage: table_sa sock_name indx1 <indx2 ...>\n"); exit(1); }subagent = argv[1];argc -= 2;argv += 2;/* create the indexlist */ilen = argc;indexlist = (INDEXLIST_T *)SNMP_memory_alloc(argc * sizeof(INDEXLIST_T));if (indexlist == 0) { printf("unable to allocate index list\n"); exit(1); }for(i = 0; i < argc; i++) { indexlist[i].index = atoi(argv[i]); indexlist[i].type = 1; }/* create the vb list, we will build the whole list at once and use the appropriate pieces when required. There will be 3 * argc instances + 3 objects */vbl = (VB_T *)SNMP_memory_alloc(((3 * argc) + 3) * sizeof(VB_T));if (vbl == 0) { printf("unable to allocate vb list\n"); exit(1); }for(i = 1, vbp = vbl; i < 4; i++) { for(j = 0; j < argc + 1; j++, vbp++) { /* flags are always 0, and need to be set (and reset) by the sending code */ vbp->vb_flags = 0; vbp->value_u.v_uinteger32 = 0; vbuf = SNMP_memory_alloc(tableoidclen * sizeof(OIDC_T)); if (vbuf == 0) { printf("Couldn't allocate a vb objectid\n"); exit(1); } MEMCPY(vbuf, tableoidc, tableoidclen * sizeof(OIDC_T)); vbp->vb_obj_id.component_list = (OIDC_T *)vbuf; vbp->vb_obj_id.component_list[tableoidclen - 2] = i; /* install different values depending on which object we are dealing with*/ switch (i) { case 1: /* first group, the index, number and read-only access */ vbp->vb_data_flags_n_type = VT_NUMBER; vbp->vb_access = 0x01; break; case 2: /* second group, the descr, string and read-only access */ vbp->vb_data_flags_n_type = VT_STRING; vbp->vb_access = 0x01; break; case 3: /* third group, the type, number and read-write access */ vbp->vb_data_flags_n_type = VT_NUMBER; vbp->vb_access = 0x03; break; } /* The first one in each group (j == 0), is the object id the rest are instances */ if (j == 0) { vbp->vb_obj_id.num_components = tableoidclen - 1; vbp->sa_flags = SA_INSTANCE_TYPE; } else { vbp->vb_obj_id.num_components = tableoidclen; vbp->vb_obj_id.component_list[tableoidclen - 1] = (OIDC_T)indexlist[j - 1].index; vbp->sa_flags = 0; } } }/* set up the vblist */vblist.vbl_count = (argc * 3) + 3;vblist.vblist = vbl;/* create message */vbl[0].vb_flags = VFLAG_SA_SENDIT;vbl[argc + 1].vb_flags = VFLAG_SA_SENDIT;vbl[(2 * argc) + 2].vb_flags = VFLAG_SA_SENDIT;EBufferInitialize(&demuxer.string);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -