📄 snmptalk.c
字号:
#if INSTALL_ENVOY_SNMP_VERSION_2 && INSTALL_ENVOY_SNMP_VERSION_3 "2 and 3",#elif INSTALL_ENVOY_SNMP_VERSION_2 "2",#elif INSTALL_ENVOY_SNMP_VERSION_3 "3", #else "none supported",#endif /* v2 and v3 */#endif /* INSTALL_ENVOY_SNMP_VERSION_1 */ SNMPTalk_SNMP_Version); else sty_printf(sty, "command `%s' not found\n", argv[1]); } } return (1);}static void do_dest_got_answer(struct sty *sty, char *name, ipaddr_t *addr){ if (addr == 0) { if (batch_mode) sty_putc(sty, '|'); sty_printf(sty, "Can not locate host `%s'\n", name); } else { set_destination(name, addr); } command_next(sty);}boolean_t do_dest(struct sty *sty, enum help_level help, int argc, char *argv[]){ switch (help) { case help_short: sty_puts(sty, "dest <host> - set the remote SNMP agent\n"); break; case help_long: sty_puts(sty, "\The 'dest <host>' command sets the IP hostname or address of\n\the remote SNMP agent to use.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_printf(sty, "`dest' command needs `hostname' as argument\n"); return (1); } else { md_hostname_to_addr(sty, argv[1], do_dest_got_answer); return (0); } } return(1);}#if INSTALL_SNMP_DEMO_AGENT_IPV6boolean_t do_destv6(struct sty *sty, enum help_level help, int argc, char *argv[]){ switch (help) { case help_short: sty_puts(sty, "destv6 <host> - set the remote SNMP agent\n"); break; case help_long: sty_puts(sty, "\The 'destv6 <host>' command sets the IPv6 hostname or address of\n\the remote SNMP agent to use.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_printf(sty, "`destv6' command needs `hostname' as argument\n"); return (1); } else { md_hostname_to_v6_addr(sty, argv[1], do_dest_got_answer); return (0); } } return(1);}boolean_t do_scopev6(struct sty *sty, enum help_level help, int argc, char *argv[]){ switch (help) { case help_short: sty_puts(sty, "scopev6 <value> - set the IPv6 scope ID\n"); break; case help_long: sty_puts(sty, "\The 'scopev6 <value>' command sets the IPv6 scope ID to be used\n\when contacting the remote SNMP agent.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_printf(sty, "`scopev6' command needs `value' as argument\n"); return (1); } else { v6_scope = atoi(argv[1]); } } return(1);}#endifboolean_t do_port(struct sty *sty, enum help_level help, int argc, char *argv[]){ switch (help) { case help_short: sty_puts(sty, "port <number> - change the UDP port number\n"); break; case help_long: sty_puts(sty, "\The 'port <number>' command changes the UDP port number used\n\by snmptalk to communicate with the Agent.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_puts(sty, "`port' command needs `port-number' as argument\n"); } else { udp_port = atoi(argv[1]); } } return (1);}boolean_t do_read_comm(struct sty *sty, enum help_level help, int argc, char *argv[]){ switch (help) { case help_short: sty_puts(sty, "\read-comm <string> - set the community string for reading\n"); break; case help_long: sty_puts(sty, "\The 'read-comm <string>' command sets the community string to\n\use when doing SNMP GETs and GET-NEXTs.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_puts(sty, "Command `read-comm' needs a string for the community nanme\n"); } else { read_community = etc_strdup(argv[1]); } } return (1);}boolean_t do_write_comm(struct sty *sty, enum help_level help, int argc, char *argv[]){ switch (help) { case help_short: sty_puts(sty, "\write-comm <string> - set the community string for writing\n"); break; case help_long: sty_puts(sty, "\The 'write-comm <string>' command sets the community string\n\to use when doing SNMP SETs.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_puts(sty, "Command `write-comm' needs a string for the community nanme\n"); } else write_community = etc_strdup(argv[1]); } return (1);}boolean_t do_packet_dump(struct sty *sty, enum help_level help, int argc, char *argv[]){ switch (help) { case help_short: sty_puts(sty, "\packet-dump <number> - turn packet dumping on (1) or off (0)\n"); break; case help_long: sty_puts(sty, "\The 'packet-dump <number>' command sets the variable that controls\n\if packets are dumped.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_puts(sty, "`packet_dump' command needs '0' (off) or '1' (on) as argument\n"); } else packet_dump = atoi(argv[1]); } return (1);}boolean_t do_status(struct sty *sty, enum help_level help, int argc, char *argv[]){ extern int SNMPTalk_SNMP_Version; int i; switch (help) { case help_short: sty_puts(sty, "status - print out various internal variables\n"); break; case help_long: sty_puts(sty, "\The 'status' command prints out internal variables for debugging purposes\n"); break; case help_none: if (destination) {#if INSTALL_SNMP_DEMO_AGENT_IPV6 if (dest_addr.type == IPV4) { sty_printf(sty, "dest: %s (%u.%u.%u.%u) at port %u\n", destination, dest_addr.addr[0], dest_addr.addr[1], dest_addr.addr[2], dest_addr.addr[3], udp_port); } else { sty_printf(sty, "dest: %s \n\t(%x", destination, dest_addr.addr[0]); for (i = 1; i < 16; i++) sty_printf(sty, ":%u", dest_addr.addr[i]); sty_printf(sty, "),\n\tscope id: %u at port %u\n", v6_scope, udp_port); }#else sty_printf(sty, "dest: %s (%u.%u.%u.%u) at port %u\n", destination, dest_addr.addr[0], dest_addr.addr[1], dest_addr.addr[2], dest_addr.addr[3], udp_port);#endif } else sty_puts(sty, "dest: <<none>>\n"); switch (SNMPTalk_SNMP_Version) {#if (INSTALL_ENVOY_SNMP_VERSION_1 || INSTALL_ENVOY_SNMP_VERSION_2) case 1: case 2: sty_printf(sty, "read: %s write: %s\n", read_community, write_community); break;#endif /* (INSTALL_ENVOY_SNMP_VERSION_1 || .. )*/#if INSTALL_ENVOY_SNMP_VERSION_3 case 3: { sty_printf(sty, "tos: %d, user name: %s, context name: %s\n", v3_tos_flags, v3_sec_name, v3_con_name); sty_printf(sty, "security id (%d):", v3_sec_id_len); for(i = 0; i < v3_sec_id_len; i++) sty_printf(sty, " %02x", v3_sec_id[i]); sty_printf(sty, "\n"); sty_printf(sty, "context id (%d):", v3_con_id_len); for(i = 0; i < v3_con_id_len; i++) sty_printf(sty, " %02x", v3_con_id[i]); sty_printf(sty, "\n"); break; }#endif#if INSTALL_ENVOY_SNMP_VERSION_USEC case 4: sty_printf(sty, "agentid: %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n", usec_agentid[0], usec_agentid[1], usec_agentid[2], usec_agentid[3], usec_agentid[4], usec_agentid[5], usec_agentid[6], usec_agentid[7], usec_agentid[8], usec_agentid[9], usec_agentid[10], usec_agentid[11]); sty_printf(sty, "qos: %d, user: %s, context: %s\n", usec_qos & 0xff, read_community, usec_context); break;#endif default: sty_printf(sty, "unknown SNMP version %d\n", SNMPTalk_SNMP_Version); } sty_printf(sty, "timeout: %d retry count: %d\n", snmp_timeout, retry_count); } return (1);}boolean_t do_remove(struct sty *sty, enum help_level help, int argc, char *argv[]){#if INSTALL_ATTACHE OIDC_T oid_buf[40]; OBJ_ID_T oid; MIBNODE_T *np; switch (help) { case help_short: sty_puts(sty, "remove <node-name-1> - remove a node\n"); break; case help_long: sty_puts(sty, "\The 'remove <node-name-1>' command removes the node in the mib\n\tree named by node-name-1.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_puts(sty, "`remove' command needs `node-name-1' as argument\n"); return (1); } oid.num_components = string2oid(argv[1], oid_buf, sizeof(oid_buf)/sizeof(OIDC_T)); oid.component_list = oid_buf; if ((np = Remove_Node(&oid)) == (MIBNODE_T *)0) sty_printf(sty, "No mib entry `%s'.\n", argv[1]); else { sty_printf(sty, "Found `%s'.\n", argv[1]); sty_printf(sty, "\tflags: %0x\n", np->node_type); } }#else sty_puts(sty, "\This copy of snmptalk wasn't built as an agent, so it can't remove nodes.\n");#endif return (1);}boolean_t do_find(struct sty *sty, enum help_level help, int argc, char *argv[]){#if INSTALL_ATTACHE OIDC_T oid_buf[40]; OBJ_ID_T oid; MIBNODE_T *np; MIBARC_T *ap; switch (help) { case help_short: sty_puts(sty, "find <node-name-1> - find a node\n"); break; case help_long: sty_puts(sty, "\The 'find <node-name-1>' command finds the node in the mib\n\tree named by node-name-1 and prints out a description of it.\n"); break; case help_none: if (argc < 2) { if (batch_mode) sty_putc(sty, '|'); sty_puts(sty, "`find' command needs `node-name-1' as argument\n"); return (1); } oid.num_components = string2oid(argv[1], oid_buf, sizeof(oid_buf)/sizeof(OIDC_T)); oid.component_list = oid_buf; if (Find_Node(&oid, &np) == 2) sty_printf(sty, "No mib entry `%s'.\n", argv[1]); else { sty_printf(sty, "Found `%s'.\n", argv[1]); sty_printf(sty, "\tflags: %0x\n", np->node_type); if ((np->node_type & NODE_TYPE) == INNER_NODE) { sty_puts(sty, "\tarcs:"); for (ap = np->arcs; (MIBNODE_T *)(ap->nodep) != (MIBNODE_T *)0; ap++) sty_printf(sty, "\t\t%ld\n", ap->id); } else { sty_puts(sty, "Leaf node\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -