📄 snmpconf.c
字号:
#if INSTALL_ENVOY_SNMP_VERSION_3char v3_tos_flags = 0;char *v3_con_name = "";bits8_t v3_con_id[32];ALENGTH_T v3_con_id_len = 0;char *v3_sec_name = "shawn";bits8_t v3_sec_id[32];ALENGTH_T v3_sec_id_len = 0;#endif/* defaults for usec */ #if INSTALL_ENVOY_SNMP_VERSION_USEC/*char *usec_agentid = "\0\0\0\43\200\340\01\225\0\0\0\0";*//*OCTET_T *usec_agentid = "\0\0\0\2\0\0\0\0\21\42\210\75";*/OCTET_T *usec_agentid = "\0\0\0\0\0\0\0\0\0\0\0\2";OCTET_T *usec_context = "\0";OCTET_T usec_qos = 0;#endif/* flag to tell us if the nv config file has been read (1) or not (0) */int SNMPTalk_NV_Read = 0;/* Parses a string of colon separated hex numbers into a byte array */int parse_hex_octet_string_colon(char *string, int buflen, bits8_t *buf){unsigned long value;int count;char *newstring;count = 0;while (*string) { value = STRTOUL(string, &newstring, 16); if (string == newstring) break; /* we didn't make any progress */ else string = newstring; buf[count++] = (unsigned char)(value & 0xFF); if ((count >= buflen) || (*string != ':')) break; string++; }return (count);}/* parse a string of unseperated hex numbers into a byte array */int parse_hex_octet_string(char *string, int buflen, bits8_t *buf){unsigned long value;int count;char nibble[3], *newstring;/* set up the end for strtoul */nibble[2] = 0;for (count = 0; *string && (count < buflen); count++) { if (*(string+1) == 0) return(0); nibble[0] = *string++; nibble[1] = *string++; value = STRTOUL(nibble, &newstring, 16); if (newstring == nibble) break; buf[count] = (unsigned char)(value & 0xFF); }return(count);}/* Execute options out of a parsed command line. Returns the number of * arguments used up as options. */int SNMP_Parse_Opts(int argc, char *argv[], char *where){int count = 0;while ((argc != 0) && (*argv[0] == '-')) { if (STRICMP(argv[0], "-batch") == 0) { batch_mode = 1; argv += 1; argc -= 1; count += 1; continue; } /* Since all options (except -batch) take exactly one argument, * check here. */ if (argc < 2) { fprintf(stderr, "no argument for option '%s' in %s\n", argv[0], where); return -1; } switch (argv[0][1]) { case 'm': /* set the mib file name */ mib_filename = etc_strdup(argv[1]); break; case 'd': /* set the remote host to talk to */ if (destination) etc_strdup_free(destination); destination = etc_strdup(argv[1]); break; case 'p': /* set the destination UDP port */ udp_port = (unsigned)atoi(argv[1]); break; case 'r': /* set the community string to use for reads */ read_community = etc_strdup(argv[1]); break; case 'w': /* set the community string used for writes */ write_community = etc_strdup(argv[1]); break; case 't': /* set the retransmission timeout */ snmp_timeout = atoi(argv[1]); break; case 'c': /* set the retransmission count */ retry_count = atoi(argv[1]); break; case 'a': /* set the retransmission count */ alt_display = atoi(argv[1]); break; default: fprintf(stderr, "Unknown option `%s'\n", argv[0]); break; } /* Here because all options take exactly one agrument */ argv += 2; argc -= 2; count += 2; }return count;}/* Reads the config file (generally etc.ini) to set defaults for the snmp engine. Then, if necessary, reads the nv configuration file to populate the engines database. */int SNMP_Config(){static char *etc_section = "etc envoy";char *value;long tmp_l;struct ini_handle *i_hand;i_hand = ini_open(256); if ((value = ini_lookup(i_hand, etc_section, "mibfile")) != 0) if ((mib_filename = etc_strdup(value)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "read-community")) != 0) if ((read_community = etc_strdup(value)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "write-community")) != 0) if ((write_community = etc_strdup(value)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "timeout")) != 0) { if ((tmp_l = STRTOL(value, 0, 0)) != 0) snmp_timeout = (int)tmp_l; }if ((value = ini_lookup(i_hand, etc_section, "retry-count")) != 0) { if ((tmp_l = STRTOL(value, 0, 0)) != 0) retry_count = (int)tmp_l; }if ((value = ini_lookup(i_hand, etc_section, "udp-port")) != 0) { if ((tmp_l = STRTOL(value, 0, 0)) != 0) udp_port = (unsigned)tmp_l; }if ((value = ini_lookup(i_hand, etc_section, "snmp-version")) != 0) { switch (atoi(value)) {#if INSTALL_ENVOY_SNMP_VERSION_1 case 1: SNMPTalk_SNMP_Version = 1; break;#endif /* INSTALL_ENVOY_SNMP_VERSION_1 */#if INSTALL_ENVOY_SNMP_VERSION_2 case 2: SNMPTalk_SNMP_Version = 2; break;#endif /* INSTALL_ENVOY_SNMP_VERSION_2 */#if INSTALL_ENVOY_SNMP_VERSION_3 case 3: SNMPTalk_SNMP_Version = 3; break;#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */ default: break; } }/* if v3 is installed see what we have for defualts for it. we have the context name and engine id, and the security name and engine id */#if INSTALL_ENVOY_SNMP_VERSION_3 if ((value = ini_lookup(i_hand, etc_section, "v3_context_name")) != 0) if ((v3_con_name = etc_strdup(value)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "v3_context_id")) != 0) if ((v3_con_id_len = parse_hex_octet_string(value, 32, v3_con_id)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "v3_security_name")) != 0) if ((v3_sec_name = etc_strdup(value)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "v3_security_id")) != 0) if ((v3_sec_id_len = parse_hex_octet_string(value, 32, v3_sec_id)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "v3_tos_flags")) != 0) { switch (atoi(value)) { case 0: v3_tos_flags = 0; break; case 1: v3_tos_flags = 1; break; case 3: v3_tos_flags = 3; break; default: break; } }#endif /* INSTALL_ENVOY_SNMP_VERSION_3 *//* See if the configuration file wants to alter the non volatile configuration file defaults, but only if we are compiled for dynamic views or have a version that requires it. After we get the file info from etc.ini we read non volatile configuration into the dabase */#if (INSTALL_ENVOY_SNMP_VERSION_3 || INSTALL_ENVOY_SNMP_DYNAMIC_VIEWS || \ INSTALL_ENVOY_SNMP_VERSION_USEC)if ((value = ini_lookup(i_hand, etc_section, "nv-config-file")) != 0) if ((NV_Config_File = etc_strdup(value)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "nv-config-file-old")) != 0) if ((NV_Old_Config_File = etc_strdup(value)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "nv-config-file-temp")) != 0) if ((NV_Temp_Config_File = etc_strdup(value)) == 0) return(1);if ((value = ini_lookup(i_hand, etc_section, "nv-views-from-config")) != 0) { switch (atoi(value)) { case 0: NV_Views_From_Config = 0; break; case 1: NV_Views_From_Config = 1; break; default: break; } }if ((value = ini_lookup(i_hand, etc_section, "nv-read-only")) != 0) { switch (atoi(value)) { case 0: NV_Read_Only = 0; break; case 1: NV_Read_Only = 1; break; default: break; } }value = ini_lookup(i_hand, etc_section, "v3_engine_id");SNMPTalk_NV_Read = 1;if (SNMP_NV_Config(value)) { return(1); }#endif ini_close(i_hand);return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -