📄 tab2_sa.c
字号:
hdr_blk.opcode1 = SA_REG_INST_REQUEST;hdr_blk.opcode2 = 0;hdr_blk.sa_error = 0;hdr_blk.encoding = SA_ENCODING_ASN1;hdr_blk.snmp_version = 0;hdr_blk.requestid = 0;hdr_blk.sysuptime = 0;hdr_blk.index = groupid;hdr_blk.snmp_error = 0;eret = SA_Encode(&vblist, &hdr_blk, &demuxer, &ebuf);if (eret) { printf("Error creating message %ld\n", eret); exit(1); }if (sendto(sock, EBufferStart(&ebuf), EBufferUsed(&ebuf), 0, (struct sockaddr *)&master_name, sizeof(struct sockaddr_un)) < 0) { printf("Failed trying to send inst registration\n"); exit(1); }/* clean up the buffer */EBufferClean(&ebuf);fromlen = sizeof(struct sockaddr_un);cc = recvfrom(sock, buf, BUFLEN, 0, (struct sockaddr *)&from, &fromlen);eret = SA_Handler((OCTET_T *)buf, (ALENGTH_T)cc, &rbuf, &hdr_blk, &rvblist);if ((eret != 0) || (hdr_blk.sa_error)) { printf("Error with inst registration %d\n", hdr_blk.sa_error); exit(1); }/* Loop waiting for messages. */tstamp = time(0) + packets;while(1) { /* set up the select call and then wait for a packet */ FD_ZERO(&ready); FD_SET(sock, &ready); timeout.tv_sec = 1; timeout.tv_usec = 0; if (select(sock + 1, &ready, 0, 0, &timeout) > 0) { fromlen = sizeof(struct sockaddr_un); cc = recvfrom(sock, buf, BUFLEN, 0, (struct sockaddr *)&from, &fromlen); (void)MEMSET(&hdr_blk, 0, sizeof(SA_HEADER_T)); eret = SA_Handler((OCTET_T *)buf, (ALENGTH_T)cc, &rbuf, &hdr_blk, &rvblist); if (eret != 0) continue; switch(hdr_blk.opcode1) { case SA_QUERY_REQUEST: /* send the reply */ sendto(sock, EBufferStart(&rbuf), EBufferUsed(&rbuf), 0, (struct sockaddr *)&from, fromlen); break; case SA_REG_OBJ_REPLY: printf("Received unexpected reg obj reply\n"); exit(1); case SA_REM_OBJ_REPLY: if (hdr_blk.sa_error) { printf("Error removing objects %d\n", hdr_blk.sa_error); exit(1); } exit(0); case SA_REM_INST_REPLY: if (hdr_blk.sa_error) { printf("Error removing instances %d\n", hdr_blk.sa_error); exit(1); } break; case SA_REG_INST_REPLY: if (hdr_blk.sa_error) { printf("Error adding instances %d\n", hdr_blk.sa_error); exit(1); } break; } } EBufferClean(&rbuf); Clean_vb_list(&rvblist); if (tstamp > time(0)) continue; tstamp = time(0) + packets; /* sw we timed out, we either register or deregister some instances */ (void)MEMSET(&hdr_blk, 0, sizeof(SA_HEADER_T)); hdr_blk.version = 1; hdr_blk.encoding = SA_ENCODING_ASN1; hdr_blk.index = groupid; if (reg1) { hdr_blk.opcode1 = SA_REM_INST_REQUEST; reg1 = 0; } else { hdr_blk.opcode1 = SA_REG_INST_REQUEST; reg1 = 1; } /* send the first instance of each object */ for (i = 0; i < (argc * 3) + 3; i++) vbl[i].vb_flags = 0; vbl[0].vb_flags = VFLAG_SA_SENDIT; vbl[1].vb_flags = VFLAG_SA_SENDIT; vbl[argc + 1].vb_flags = VFLAG_SA_SENDIT; vbl[argc + 2].vb_flags = VFLAG_SA_SENDIT; vbl[(2 * argc) + 2].vb_flags = VFLAG_SA_SENDIT; vbl[(2 * argc) + 3].vb_flags = VFLAG_SA_SENDIT; eret = SA_Encode(&vblist, &hdr_blk, &demuxer, &ebuf); if (eret) { printf("Error creating register or remove message %ld\n", eret); exit(1); } sendto(sock, EBufferStart(&ebuf), EBufferUsed(&ebuf), 0, (struct sockaddr *)&master_name, sizeof(struct sockaddr_un)); EBufferClean(&ebuf); }}void table_free(PTR_T vbptr){return;}/****************************************************************************NAME: sa_table_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 sa_table_test(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ int i; INT_32_T value; value = vbp->value_u.v_number; if ((value < 1) || (value > 10)) { testproc_error(pktp, vbp, WRONG_VALUE); return; } if (tcount != 1) { testproc_error(pktp, vbp, NO_CREATION); return; } for(i = 0; i < ilen; i++) if (indexlist[i].index == *tlist) { vbp->vb_free_priv = table_free; vbp->vb_priv = 0; testproc_good(pktp, vbp); return; } testproc_error(pktp, vbp, NO_CREATION); return;}/****************************************************************************NAME: sa_table_nextPURPOSE: 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 sa_table_next(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ nextproc_no_next(pktp, vbp); return;}/****************************************************************************NAME: sa_table_getPURPOSE: 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 sa_table_get(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ int i; if (tcount != 1) { getproc_nosuchins(pktp, vbp); return; } for(i = 0; i < ilen; i++) if (indexlist[i].index == *tlist) { switch(last_match) { case LM_tableindex: getproc_got_int32(pktp, vbp, (INT_32_T)indexlist[i].index); break; case LM_tabletype: getproc_got_int32(pktp, vbp, (INT_32_T)indexlist[i].type); break; case LM_tabledescr: getproc_got_string(pktp, vbp, STRLEN(subagent), subagent, 0, VT_STRING); break; } return; } getproc_nosuchins(pktp, vbp); return;}/****************************************************************************NAME: sa_table_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 sa_table_set(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ int i; for(i = 0; i < ilen; i++) if (indexlist[i].index == *tlist) indexlist[i].type = VB_GET_INT32(vbp); 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 + -