=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/snmp/snmpc.c,v retrieving revision 1.7 retrieving revision 1.8 diff -c -r1.7 -r1.8 *** src/usr.bin/snmp/snmpc.c 2019/08/14 14:40:23 1.7 --- src/usr.bin/snmp/snmpc.c 2019/09/18 09:44:38 1.8 *************** *** 1,4 **** ! /* $OpenBSD: snmpc.c,v 1.7 2019/08/14 14:40:23 deraadt Exp $ */ /* * Copyright (c) 2019 Martijn van Duren --- 1,4 ---- ! /* $OpenBSD: snmpc.c,v 1.8 2019/09/18 09:44:38 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren *************** *** 45,50 **** --- 45,51 ---- int snmpc_walk(int, char *[]); int snmpc_trap(int, char *[]); int snmpc_mibtree(int, char *[]); + struct snmp_agent *snmpc_connect(char *, char *); int snmpc_parseagent(char *, char *); int snmpc_print(struct ber_element *); __dead void snmpc_printerror(enum snmp_error, char *); *************** *** 304,312 **** if (argc < 2) usage(); ! agent = snmp_connect_v12(snmpc_parseagent(argv[0], "161"), version, ! community); ! if (agent == NULL) err(1, "%s", snmp_app->name); agent->timeout = timeout; agent->retries = retries; --- 305,311 ---- if (argc < 2) usage(); ! if ((agent = snmpc_connect(argv[0], "161")) == NULL) err(1, "%s", snmp_app->name); agent->timeout = timeout; agent->retries = retries; *************** *** 372,379 **** usage(); oids = argc == 1 ? mib : argv[1]; ! agent = snmp_connect_v12(snmpc_parseagent(argv[0], "161"), version, community); ! if (agent == NULL) err(1, "%s", snmp_app->name); agent->timeout = timeout; agent->retries = retries; --- 371,377 ---- usage(); oids = argc == 1 ? mib : argv[1]; ! if ((agent = snmpc_connect(argv[0], "161"))== NULL) err(1, "%s", snmp_app->name); agent->timeout = timeout; agent->retries = retries; *************** *** 495,503 **** if (version == SNMP_V1) errx(1, "trap is not supported for snmp v1"); ! agent = snmp_connect_v12(snmpc_parseagent(argv[0], "162"), ! version, community); ! if (agent == NULL) err(1, "%s", snmp_app->name); if (pledge("stdio", NULL) == -1) --- 493,499 ---- if (version == SNMP_V1) errx(1, "trap is not supported for snmp v1"); ! if ((agent = snmpc_connect(argv[0], "162")) == NULL) err(1, "%s", snmp_app->name); if (pledge("stdio", NULL) == -1) *************** *** 691,696 **** --- 687,704 ---- printf("%s\n", buf); } return 0; + } + + struct snmp_agent * + snmpc_connect(char *host, char *port) + { + switch (version) { + case SNMP_V1: + case SNMP_V2C: + return snmp_connect_v12(snmpc_parseagent(host, port), version, + community); + } + return NULL; } int