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

📄 nvutils.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 5 页
字号:
TB_T entlogical_tokens[] = { {TENTLOGICINDEX, "index"},                             {TENTLOGICDESCR, "descr"},                             {TENTLOGICTYPE,  "type"},                             {TENTLOGICCOMMUNITY, "community"},                             {TENTLOGICTADDRESS, "taddress"},                             {TENTLOGICTDOMAIN, "tdomain"},                             {TENTLOGICCONID, "context_engine_id"},                             {TENTLOGICCONNAME, "context_name"}, {0, ""}                           };                            /* roots of various modification lists */MODS_T *view_mod_list = 0;MODS_T *user_mod_list = 0;MODS_T *group_mod_list = 0;MODS_T *access_mod_list = 0;MODS_T *taddr_mod_list = 0;MODS_T *tparam_mod_list = 0;MODS_T *notify_mod_list = 0;MODS_T *nprof_mod_list = 0;MODS_T *nfilt_mod_list = 0;MODS_T *proxy_mod_list = 0;MODS_T *community_mod_list = 0;#if (INSTALL_ENVOY_SNMP_V3_TARGET) && (INSTALL_ENVOY_SNMP_V3_NOTIFY)SNMPV3_TRAP_T *trap_root = 0;#endif/****************************************************************************NAME: s2oidPURPOSE: String to oid translation, without any symbolic names.         Fills in the passed OID buffer and returns the number of         components needed for the OID.PARAMETERS:        char   *        The string to translate        OIDC_T *        OID Buffer to fill        int             Length of OID bufferRETURNS: int    0 = failure                otherwise the number of components needed for the OID.****************************************************************************/int  s2oid(char   *name,        OIDC_T *oid,        int     oidlen){int count = 0;while (*name) {    if (count < oidlen)        oid[count] = atol(name);    while (isdigit(*name))        name++;    if (*name == '.')        name++;    count++;    }return (count);}/****************************************************************************NAME: oid2sPURPOSE: Oid to string translation, without any symbolic names.         Fills in the passed buf with a printable version of the OID.         The length of the string is returned.  If too long then as much         as fits is put in the buffer and the length needed is         returned.PARAMETERS:        OIDC_T *        OID name to translate        int             Length of OID buffer        char   *        Buffer to receive the string        int             length of string bufferRETURNS: int    The length of the string****************************************************************************/int  oid2s(OIDC_T *oid,        int     oidlen,        char   *buf,        int     buflen){static char numpfsb[] = ".%lu";char numbuf[11], *numpfs, *cp ;int plen = 0, numlen, i;numpfs = &numpfsb[1];while(oidlen--) {    sprintf(numbuf, numpfs, (unsigned long)*oid++);    numpfs = numpfsb;    numlen = STRLEN(numbuf);    if (plen + numlen >= buflen) {        for(cp = buf + plen, i = 0; i < (buflen - plen); cp++)	    *cp = numbuf[i];        buf[buflen - 1] = '\0';        }    else        STRCPY(buf + plen, numbuf);    plen += numlen;    }return (plen);}/****************************************************************************NAME: tokenizerPURPOSE: Given a string and a list of tokens determine which token         starts the string.  The string must be of the form          "token = arguments".  The list will be an array of token blocks.PARAMETERS:         char  *        The string to tokenize         TB_T  *        The list of tokens to match         RETURNS: int    0 = failure                otherwise a pointer to the token block****************************************************************************/TB_T *  tokenizer(char *buf,            TB_T *tokenlist){char *cp;TB_T *tbp;if ((*buf == ' ') || (*buf == '\t')) {    printf("String can't start with whitespace\n%s\n", buf);    return(0);    }for (cp = buf; *cp != '='; cp++)    if (*cp == '\n') {        printf("Improperly formatted string, '=' not found\n%s\n", buf);        return(0);        }/* Turn the '=' sign into a space so it can be skipped later */*cp = ' ';/* Find the first character after the token, it may be a whitespace character   or the '=' sign, in either case make it a null so the stricmp will work */for (; (*cp == ' ') || (*cp == '\t'); cp--)    ;cp++;*cp = 0;for (tbp = tokenlist; tbp->token_tag != 0; tbp++)    if (STRICMP(buf, tbp->token_string) == 0)        return(tbp);printf("Unknown option: %s\n", buf);return(0);}/****************************************************************************NAME: section_checkPURPOSE: Determine if the string is the proper format to begin a block,         if the section name is correct and if we have a token to         associate with the token namePARAMETERS:        char * the name of the section        char * the line we are examining        TB_T * the list of possible to tokens        RETURNS: int    0 = failure                otherwise a pointer to the token block****************************************************************************/TB_T *  section_check(char *sname,                 char *buf,                TB_T *tokens){char *cp1, *cp2;TB_T *tbp;/* Does the line start with a '[' */if (*buf != '[')    return(0);/* Is the section name correct */if (STRNICMP(buf + 1, sname, STRLEN(sname)) != 0) {    printf("Section name incorrect wanted %s, got %s\n", sname, buf + 1);    return(0);    }/* Jump over any white space to the start of the token */for (cp1 = buf + STRLEN(sname) + 1; (*cp1 == '\t') || (*cp1 == ' '); cp1++)    ;/* find the end of the token */for (cp2 = cp1; *cp2 != ']'; cp2++)    if (*cp2 == '\n') {        printf("Improperly formatted section line, ']' not found\n");        return(0);        }/* replace the ']' with a null terminator so we can use stricmp */*cp2 = 0;for (tbp = tokens; tbp->token_tag != 0; tbp++)    if (STRICMP(cp1, tbp->token_string) == 0)        return(tbp);return(0);}/****************************************************************************NAME: SNMP_NV_Add_ModPURPOSE: Add the given entries to the modification listPARAMETERS:	ptr_t       * old entry	ptr_t       * new entry	MODS_T     ** list to add the entry to RETURNS: sbits32_t    0 = success, other = failure****************************************************************************/sbits32_t  SNMP_NV_Add_Mod(ptr_t      *oldentry,		  ptr_t      *newentry,		  sbits32_t   flags,		  MODS_T    **mod_list){MODS_T *mod_entry;mod_entry = (MODS_T *)SNMP_memory_alloc(sizeof(MODS_T));if (mod_entry == 0)    return(RESOURCE_UNAVAILABLE);mod_entry->data    = oldentry;mod_entry->newdata = newentry;mod_entry->flags   = flags;mod_entry->next    = *mod_list;*mod_list          = mod_entry;/*sar*/if (SNMP_NV_Write(1))    return(RESOURCE_UNAVAILABLE);return(NO_ERROR);}#if (INSTALL_ENVOY_SNMP_DYNAMIC_VIEWS)/****************************************************************************NAME: view_writePURPOSE: If required write the information from the view out to the         given file.  If nlen == 0 use rfc1445 style (identity = <oidc>)	 otherwise use rfc2275 style (identity = <name>:<oidc>).PARAMETERS:         VIEWLEAF_T *   the view to store	 bits8_t        the name of the view (for 2275)	 ALENGTH_T      the length of the name (or 0 if 1445)         OIDC_T      *  the id for the view         int            the length of the id for the view         FILE        *  the file to store the view inRETURNS: int    0 = success                other = failure****************************************************************************/int  view_write(VIEWLEAF_T *view,	     bits8_t    *name,	     ALENGTH_T   nlen,             OIDC_T     *idoidc,             int         idoidclen,             FILE       *outstream){char buf[100], *cp;int slen, status;if (outstream == 0)    return(0);status = SNMP_View_Get_Status(view);if (status == ETC_RS_CAGO)    status = ETC_RS_ACTIVE;/* see if we should output the view anyway */if (((status != ETC_RS_NIS) && (status != ETC_RS_ACTIVE)) ||    ((SNMP_View_Get_StorageType(view) != ETC_STO_NONVOL) &&     (SNMP_View_Get_StorageType(view) != ETC_STO_PERM) &&     (SNMP_View_Get_StorageType(view) != ETC_STO_RONLY)))    return(0);/* output the identity */oid2s(idoidc, idoidclen, buf, sizeof(buf));fprintf(outstream, "identity = ");if (nlen) {    for(;nlen;nlen--, name++)        fputc((int)*name, outstream);    fputc(':', outstream);    }fprintf(outstream, "%s\n", buf);/* output the status, storage & type */fprintf(outstream, "status = %d\n", status);fprintf(outstream, "storage = %d\n", SNMP_View_Get_StorageType(view));fprintf(outstream, "type = %d\n", SNMP_View_Get_Type(view));/* if necessary (if the mask length is non zero) output the mask */if ((slen = SNMP_View_Get_MaskLen(view)) != 0) {    fprintf(outstream, "mask = ");    for (cp = (char *)SNMP_View_Get_Mask(view);         slen > 0;         slen--, cp++)        fprintf(outstream, "%02x", *cp & 0xFF);    fputc('\n', outstream);    }fputc('\n', outstream);return(0);}#endif /* #if (INSTALL_ENVOY_SNMP_DYNAMIC_VIEWS) */#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)/****************************************************************************NAME: SNMP_NV_View_Add_ModPURPOSE: Add the given view to the view modification listPARAMETERS:        VIEWLEAF_T * the view to add to the modification list        INT_32_T        flags for the mod list                        Destroy is the only one currently defined	bits8_t    * the name of the view (if using rfc2275)	ALENGTH_T    length of the name 0 if not used RETURNS: int    0 = success                other = failure****************************************************************************/int  SNMP_NV_View_Add_Mod(VIEWLEAF_T *view,                       INT_32_T    flags){MODS_T *mod_entry;if ((mod_entry = (MODS_T *)SNMP_memory_alloc(sizeof(MODS_T))) == 0)    return(-1);mod_entry->data = (PTR_T)view;mod_entry->next = view_mod_list;mod_entry->flags = flags;view_mod_list = mod_entry;/*sar*/if (SNMP_NV_Write(1))    return(-1);return(TPROC_GOOD);}/****************************************************************************NAME: read_viewsPURPOSE: Read the view information from the configuration.  We read         information until we hit a statement starting with a '[' or         an end of file (both probably successful or we          hit an unknown token (a failure)PARAMETERS:        FILE *  input file (file to read from)RETURNS: int    0 = success                other = failure****************************************************************************/int  read_views(FILE *instream){TB_T *tbp;char buf[100], buf2[100], *cp, *cp2, *error_cp = 0;VIEWLEAF_T *view;OIDC_T idoidc[MAX_OID_COUNT];int idoidclen = 0, i, j;int value;while(1) {    /* We are done if we have found the end of the file or       a new section is starting */    if ((fgets(buf, sizeof(buf), instream) == 0) || (*buf == '['))        return(0);    if ((*buf == ';') || (*buf == '\n'))        continue;    if ((tbp = tokenizer(buf, view_tokens)) == 0)        return(1);    if (tbp->token_tag != TVID) {        printf("View block: first token must be id (index and subtree)\n");        return(1);        }    cp = buf + STRLEN(tbp->token_string) + 1;    /* remove white space before the arguments */    while((*cp == ' ') || (*cp == '\t'))        cp++;    /* then determine the length of the agrument and terminate it with a 0 */    for (cp2 = cp; (*cp2 != '\n') && (*cp2 != ' ') && (*cp2 != '\t'); cp2++)        ;    *cp2 = 0;    idoidclen = s2oid(cp, idoidc, sizeof(idoidc));    break;    }if ((view = SNMP_View_Create(idoidc + 1, idoidclen - 1)) == 0) {    printf("Error creating view\n");    return(1);    }

⌨️ 快捷键说明

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