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

📄 snmp_io.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 3 页
字号:
    static CMNTY_TO_VIEW_T  getCmntyViewTbl [] = { {"pub", "two"},						   {"public", "two"},						   {"priv", "two"},						   {"private", "two"},                                                   {"icmp", "two"},						   {NULL, NULL} };                                                 /* community table for gets                                                    NULL entry terminated */    static CMNTY_TO_VIEW_T  setCmntyViewTbl [] = { {"priv", "two"},						   {"private", "two"},                                                   {NULL, NULL} };                                                 /* community table for sets                                                    NULL entry terminated */#else /* If we aren't using 2275 we are using 1445 */    static CMNTY_TO_VIEW_T  getCmntyViewTbl [] = { {"pub", 2}, {"public", 2},						   {"priv", 2}, {"private", 2},                                                   {"icmp", 3}, {NULL, 0} };                                                 /* community table for gets                                                    NULL entry terminated */    static CMNTY_TO_VIEW_T  setCmntyViewTbl [] = { {"priv", 2}, {"private", 2},                                                   {NULL, 0} };                                                 /* community table for sets                                                    NULL entry terminated */#endif/* * This is the second version of the community validation routine. * This one uses the previously defined static table to determine * if a view is known.  It should not be used with the virtual stack * option. */int snmpIoCommunityValidate    (    SNMP_PKT_T *    pPkt,               /* ptr to snmp pkt */    SNMPADDR_T *    pRemoteAddr,        /* remote address */    SNMPADDR_T *    pLocalAddr          /* local address */    )    {    int                     pktCmntyLen;          /* length of community string                                                     in received pkt  */    CMNTY_TO_VIEW_T *       pEntry;               /* ptr to traverse community                                                     to view tables */    char *                  pCmnty;               /* ptr to Cmnty  field */        /* Assume that the packet will be found acceptable and do the     * common work. */    if (snmpIoValidateCommon(pPkt, pRemoteAddr, pLocalAddr) != 0) {        return(1);        }        pktCmntyLen = EBufferUsed (&(pPkt->community));        /* select get or set cmmunity to view table as appropriate */    pEntry = (pPkt->pdu_type == SET_REQUEST_PDU) ? setCmntyViewTbl :                                                   getCmntyViewTbl;    for ( pCmnty = pEntry->Cmnty; pCmnty != NULL;           ++ pEntry, pCmnty = pEntry->Cmnty)        {        if ((strlen (pCmnty) == pktCmntyLen) &&            (memcmp (pCmnty, pPkt->community.start_bp, pktCmntyLen) == 0))            {#if INSTALL_ENVOY_SNMP_RFC2275_VIEWS	    EBufferPreLoad(BFL_IS_STATIC, &pPkt->view_name,			   pEntry->viewIndex, strlen(pEntry->viewIndex));#else /* If we aren't using 2275 we are using 1445 */	    pPkt->view_index = pEntry->viewIndex;#endif            return (0);            }        }             /* Got a bad community if we're here, so increment the     * snmpInBadCommunityNames counter     */    ++ snmp_stats.snmpInBadCommunityNames;            /* An auth fail trap may be sent here */        return (1);    }#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */#if (INSTALL_ENVOY_SNMP_VERSION_3)    /******************************************************************************** snmpIoAddressValidate - sample Address validation routine* * This routine is used to validate the address information in a packet.* The product is shipped with defaults that simply copy the address* information into the packet structure** The agent designer is required to write this function according to* the design of the application.** RETURNS: 0 if the address is acceptable, otherwise 1.*/int snmpIoAddressValidate    (    SNMP_PKT_T *    pPkt,               /* ptr to snmp pkt */    SNMPADDR_T *    pRemoteAddr,        /* remote address */    SNMPADDR_T *    pLocalAddr          /* local address */    )    {    #if INSTALL_SNMP_VXWORKS_VIRTUAL_STACK    int vsNum;    if (pPkt->snmp_version != SNMP_VERSION_3)        {        /* if we are using coexistence then check the community string */        vsNum = communityStringFind (pPkt->community,                                      VIEW_TYPE_GET | VIEW_TYPE_SET, NULL);        }    else        {        /* else, this must be SNMPv3 so check context name */        vsNum = contextNameFind (pPkt->community,                                 VIEW_TYPE_GET | VIEW_TYPE_SET, NULL);        }    if ((vsNum == -1) || (SNMP_SET_VIRTUAL_STACK (vsNum) != OK)) {        /* return ERROR if VS number not found or if we can't set the	 * stack number properly */        return (1);        }#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */    /* And do any common work for all of the validate routines */    return (snmpIoValidateCommon(pPkt, pRemoteAddr, pLocalAddr));    }#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */    /******************************************************************************** snmpdMemoryAlloc - allocate memory for the SNMP agent** This routine allocates memory for the SNMP agent. The required size* of the block is passed in <size>. * This memory must be deallocated later with snmpdMemoryFree().** RETURNS: a pointer to the allocated buffer on success, otherwise NULL.** SEE ALSO: snmpdMemoryFree()*/void *   snmpdMemoryAlloc     (    size_t  size            /* size of memory to be allocated */    )    {    return ((char*) malloc (size));    }/******************************************************************************** snmpdMemoryFree - free memory allocated by the SNMP agent** This routine deallocates memory which was previously allocated by the* SNMP agent with snmpdMemoryAlloc().** RETURNS: N/A** SEE ALSO: snmpdMemoryAlloc()*/void   snmpdMemoryFree    (    void *    pBuf    /* buffer to free */    )    {    free (pBuf);    }#if (INSTALL_ENVOY_AGENTX_MASTER) || (INSTALL_ENVOY_ENTITY_MIB)/********************************************************************************* envoyGetSysUptime - return the sysUpTime for the given context** This routine returns the value for the sysUpTime object in the given* context.  Since we currently only support one context (""), and other* contexts should return a value of 0.** RETURNS: N/A**/bits32_t envoyGetSysUpTime    (    EBUFFER_T *pContext    )    {    if ((pContext == 0) || (EBufferUsed(pContext) == 0))        return (ENVOY_NOW() / 10);    else        return (0);    }#endif#if (INSTALL_ENVOY_SNMP_V3_NOTIFY)/******************************************************************************** envoy_taddress_to_snmpaddr** This routine and its companion envoy_snmpaddr_to_taddress will be* used to convert between an SNMPADDR_T and a TAddress/TDomain pair.* In the case of these demos, the SNMPADDR_T is an opaque structure* equivalent to a (struct sockaddr_in).  For SNMP over UDP, the* TDomain will always be 1.3.6.1.6.1.1, and the TAddress will be 6* bytes long: 4 bytes of address and 2 bytes of port, all in* network order.** RETURNS: 0 on success, -1 on failure.** SEE ALSO: envoy_snmpaddr_to_taddress()*/int   envoy_taddress_to_snmpaddr(SNMPADDR_T *addr,			     OBJ_ID_T   *tdomain,			     EBUFFER_T  *taddress){struct sockaddr_in sock;bits16_t port;bits32_t ipaddr;#if INSTALL_SNMP_VXWORKS_IPV6struct sockaddr_in6 sock6;#endif /* #if INSTALL_SNMP_VXWORKS_IPV6 */if (oidcmp(tdomain->num_components, tdomain->component_list,	   sizeof(udpdomain)/sizeof(OIDC_T), udpdomain) == 1)    {    sock.sin_family = AF_INET;    MEMCPY(&ipaddr, EBufferStart(taddress), 4);    MEMCPY(&port, (EBufferStart(taddress) + 4), 2);    sock.sin_port = port;    sock.sin_addr.s_addr = ipaddr;    MEMCPY(addr, &sock, sizeof(sock));    return 0;    }#if INSTALL_SNMP_VXWORKS_IPV6if (oidcmp(tdomain->num_components, tdomain->component_list,           sizeof(udpipv6domain)/sizeof(OIDC_T), udpipv6domain) == 1)    {    memset (&sock6, 0, sizeof (sock6));    sock6.sin6_family = AF_INET6;    MEMCPY (&sock6.sin6_addr, EBufferStart (taddress), 16);    MEMCPY (&port, EBufferStart (taddress)+16, 2);    sock6.sin6_port = htons (port);    return 0;    }#endif /* #if INSTALL_ENVOY_VXWORKS_IPV6 */return -1;}/******************************************************************************** envoy_snmpaddr_to_taddress** This routine and its companion envoy_taddress_to_snmpaddr will be* used to convert between an SNMPADDR_T and a TAddress/TDomain pair.* In the case of these demos, the SNMPADDR_T is an opaque structure* equivalent to a (struct sockaddr_in).  For SNMP over UDP, the* TDomain will always be 1.3.6.1.6.1.1, and the TAddress will be 6* bytes long: 4 bytes of address and 2 bytes of port, all in* network order.** RETURNS: 0 on success, -1 on failure.** SEE ALSO: envoy_snmpaddr_to_taddress()*/int  envoy_snmpaddr_to_taddress(SNMPADDR_T *addr,			     OBJ_ID_T   *tdomain,			     EBUFFER_T  *taddress){struct sockaddr_in sock;bits16_t port;bits32_t ipaddr;bits8_t tadd[6];#if INSTALL_SNMP_VXWORKS_IPV6struct sockaddr_in6 sock6;bits8_t tadd6[18];#endif /* #if INSTALL_SNMP_VXWORKS_IPV6 */#if INSTALL_SNMP_VXWORKS_IPV6if (((struct sockaddr *) addr)->sa_family == AF_INET6)    {    (void) memcpy ((char *)(&sock6), (char *)addr,                   sizeof(struct sockaddr_in6));    if (build_object_id (sizeof(udpipv6domain)/sizeof(OIDC_T),                         udpipv6domain,                         tdomain))        return -1;    MEMCPY ((char *) tadd6, (char *) &sock6.sin6_addr, 16);    MEMCPY ((char *) tadd6+16, (char *) &sock6.sin6_port, 2);    if (EBufferAllocateLoad (BFL_IS_ALLOC, taddress, tadd6, 18))        {        Clean_Obj_ID (tdomain);        return -1;        }    return 0;    }else if (((struct sockaddr *) addr)->sa_family == AF_INET)    {    (void) memcpy((char *)(&sock), (char *)addr,                  sizeof(struct sockaddr_in));    if (build_object_id(sizeof(udpdomain)/sizeof(OIDC_T), udpdomain, tdomain))        return -1;    ipaddr = sock.sin_addr.s_addr;    port = sock.sin_port;    MEMCPY(tadd, &ipaddr, 4);    MEMCPY(tadd + 4, &port, 2);    if (EBufferAllocateLoad(BFL_IS_ALLOC, taddress, tadd, 6))        {        Clean_Obj_ID(tdomain);        return -1;        }    return 0;    }#else /* #if INSTALL_SNMP_VXWORKS_IPV6 */(void) MEMCPY((char *)(&sock), (char *)addr, sizeof(struct sockaddr_in));if (sock.sin_family == AF_INET) {    if (build_object_id(sizeof(udpdomain)/sizeof(OIDC_T), udpdomain, tdomain))        return -1;    ipaddr = sock.sin_addr.s_addr;    port = sock.sin_port;    MEMCPY(tadd, &ipaddr, 4);    MEMCPY(tadd + 4, &port, 2);    if (EBufferAllocateLoad(BFL_IS_ALLOC, taddress, tadd, 6)) {        Clean_Obj_ID(tdomain);        return -1;        }    return 0;    }#endif /* #if INSTALL_SNMP_VXWORKS_IPV6 */return -1;}#endif /* INSTALL_ENVOY_SNMP_V3_NOTIFY */#if INSTALL_ENVOY_SNMP_V3_PROXY/******************************************************************************** snmpSendProxyPkt** This routine sends a proxy packet to its intended target. ** RETURNS: nothing**/void snmpSendProxyPkt    (    SNMPADDR_T   *pForAddr,    SNMPADDR_T   *pLocAddr,    PTR_T         pPkt,    ALENGTH_T     need    )    {    EBUFFER_T ebuff;    struct sockaddr_in remoteAddr;    struct sockaddr_in localAddr;        EBufferInitialize (&ebuff);    /*     * Just a safety to make sure our sockaddr structures are properly     * aligned...     */    MEMCPY (&remoteAddr, pForAddr, sizeof (struct sockaddr_in));    MEMCPY (&localAddr, pLocAddr, sizeof (struct sockaddr_in));    #if INSTALL_SNMP_VXWORKS_VIRTUAL_STACK    /*     * Set myStackNum to the stack instance we received the packet on,     * else we can't write on the socket. Our stack instance may have changed     * so the method routines can execute in the correct stack instance.     * We don't check to see if the set succeeded as there isn't anything     * we could do if it failed.     */    SNMP_SET_VIRTUAL_STACK (snmpdStackNum);#endif /* INSTALL_SNMP_VXWORKS_VIRTUAL_STACK */    if (SNMP_Process_Finish ((SNMP_PKT_T *) pPkt, &ebuff, need) == 0) {        snmpIoWrite ((void *) &snmpSocket, (char*) ebuff.start_bp,                     need, &remoteAddr, &localAddr);        EBufferClean (&ebuff);        }    }#endif /* INSTALL_ENVOY_SNMP_V3_PROXY */

⌨️ 快捷键说明

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