Lines Matching +full:tv +full:- +full:set
2 * Copyright (c) 2004-2005,2018-2019
5 * Copyright (c) 2001-2003
92 * Prototype table entry. All C-structure produced by the table function must
94 * are compatible with each other in the sense implied by ANSI-C.
128 * Set the error string
136 vsnprintf(sc->error, sizeof(sc->error), fmt, ap); in seterr()
152 while ((w = TAILQ_FIRST(&work->worklist)) != NULL) { in table_free()
153 TAILQ_REMOVE(&work->worklist, w, link); in table_free()
160 while ((e = TAILQ_FIRST(work->table)) != NULL) { in table_free()
161 for (i = 0; work->descr->entries[i].syntax != SNMP_SYNTAX_NULL; in table_free()
163 d = &work->descr->entries[i]; in table_free()
164 if (d->syntax == SNMP_SYNTAX_OCTETSTRING && in table_free()
165 (e->found & ((uint64_t)1 << i))) in table_free()
167 ((u_char *)e + d->offset)); in table_free()
169 TAILQ_REMOVE(work->table, e, link); in table_free()
189 asn_slice_oid(&oid, var, work->descr->table.len + 2, var->len); in table_find()
191 e = TAILQ_FIRST(work->table); in table_find()
192 w = TAILQ_FIRST(&work->worklist); in table_find()
194 if (asn_compare_oid(&w->index, &oid) == 0) in table_find()
201 if ((e = malloc(work->descr->entry_size)) == NULL) { in table_find()
210 w->index = oid; in table_find()
211 memset(e, 0, work->descr->entry_size); in table_find()
214 p = work->descr->table.len + 2; in table_find()
215 for (i = 0; i < work->descr->index_size; i++) { in table_find()
216 switch (work->descr->entries[i].syntax) { in table_find()
219 if (var->len < p + 1) { in table_find()
223 if (var->subs[p] > INT32_MAX) { in table_find()
229 work->descr->entries[i].offset) = var->subs[p++]; in table_find()
233 if (var->len < p + 1) { in table_find()
238 len = var->subs[p++]; in table_find()
239 if (var->len < p + len) { in table_find()
250 if (var->subs[p] > UCHAR_MAX) { in table_find()
256 ptr[j] = var->subs[p++]; in table_find()
260 work->descr->entries[i].offset) = ptr; in table_find()
262 work->descr->entries[i].offset + sizeof(u_char *)) in table_find()
267 if (var->len < p + 1) { in table_find()
272 oid.len = var->subs[p++]; in table_find()
273 if (var->len < p + oid.len) { in table_find()
279 oid.subs[j] = var->subs[p++]; in table_find()
281 work->descr->entries[i].offset) = oid; in table_find()
285 if (var->len < p + 4) { in table_find()
287 "bad index: need ip-address"); in table_find()
291 if (var->subs[p] > 0xff) { in table_find()
297 work->descr->entries[i].offset)[j] = in table_find()
298 var->subs[p++]; in table_find()
303 if (var->len < p + 1) { in table_find()
308 if (var->subs[p] > UINT32_MAX) { in table_find()
314 work->descr->entries[i].offset) = var->subs[p++]; in table_find()
326 e->found |= (uint64_t)1 << i; in table_find()
330 e1 = TAILQ_FIRST(work->table); in table_find()
331 w1 = TAILQ_FIRST(&work->worklist); in table_find()
333 if (asn_compare_oid(&w1->index, &w->index) > 0) in table_find()
339 TAILQ_INSERT_TAIL(work->table, e, link); in table_find()
340 TAILQ_INSERT_TAIL(&work->worklist, w, link); in table_find()
353 for (i = 0; i < work->descr->index_size; i++) { in table_find()
354 if (work->descr->entries[i].syntax == SNMP_SYNTAX_OCTETSTRING && in table_find()
355 (e->found & ((uint64_t)1 << i))) in table_find()
357 work->descr->entries[i].offset)); in table_find()
374 for (i = descr->index_size; in table_value()
375 descr->entries[i].syntax != SNMP_SYNTAX_NULL; i++) in table_value()
376 if (descr->entries[i].subid == in table_value()
377 b->var.subs[descr->table.len + 1]) in table_value()
379 if (descr->entries[i].syntax == SNMP_SYNTAX_NULL) in table_value()
383 if (b->syntax != descr->entries[i].syntax) { in table_value()
384 seterr(&snmp_client, "bad syntax (%u instead of %u)", b->syntax, in table_value()
385 descr->entries[i].syntax); in table_value()
386 return (-1); in table_value()
389 switch (b->syntax) { in table_value()
392 *(int32_t *)(void *)((u_char *)e + descr->entries[i].offset) = in table_value()
393 b->v.integer; in table_value()
397 if ((ptr = malloc(b->v.octetstring.len + 1)) == NULL) { in table_value()
399 return (-1); in table_value()
401 memcpy(ptr, b->v.octetstring.octets, b->v.octetstring.len); in table_value()
402 ptr[b->v.octetstring.len] = '\0'; in table_value()
403 *(u_char **)(void *)((u_char *)e + descr->entries[i].offset) = in table_value()
405 *(size_t *)(void *)((u_char *)e + descr->entries[i].offset + in table_value()
406 sizeof(u_char *)) = b->v.octetstring.len; in table_value()
410 *(struct asn_oid *)(void *)((u_char *)e + descr->entries[i].offset) = in table_value()
411 b->v.oid; in table_value()
415 memcpy((u_char *)e + descr->entries[i].offset, in table_value()
416 b->v.ipaddress, 4); in table_value()
422 *(uint32_t *)(void *)((u_char *)e + descr->entries[i].offset) = in table_value()
423 b->v.uint32; in table_value()
427 *(uint64_t *)(void *)((u_char *)e + descr->entries[i].offset) = in table_value()
428 b->v.counter64; in table_value()
437 e->found |= (uint64_t)1 << i; in table_value()
452 pdu->error_index = 10; in table_init_pdu()
454 if (descr->last_change.len != 0) { in table_init_pdu()
455 pdu->bindings[pdu->nbindings].syntax = SNMP_SYNTAX_NULL; in table_init_pdu()
456 pdu->bindings[pdu->nbindings].var = descr->last_change; in table_init_pdu()
457 pdu->nbindings++; in table_init_pdu()
458 if (pdu->version != SNMP_V1) in table_init_pdu()
459 pdu->error_status++; in table_init_pdu()
461 pdu->bindings[pdu->nbindings].var = descr->table; in table_init_pdu()
462 pdu->bindings[pdu->nbindings].syntax = SNMP_SYNTAX_NULL; in table_init_pdu()
463 pdu->nbindings++; in table_init_pdu()
468 * 0 - End Of Table
469 * -1 - Error
470 * -2 - Last change changed - again
471 * +1 - ok, continue
479 if (resp->error_status != SNMP_ERR_NOERROR) { in table_check_response()
481 resp->error_status == SNMP_ERR_NOSUCHNAME && in table_check_response()
482 resp->error_index == in table_check_response()
483 ((work->descr->last_change.len == 0) ? 1 : 2)) in table_check_response()
488 resp->error_status, resp->error_index); in table_check_response()
489 return (-1); in table_check_response()
492 for (b = resp->bindings; b < resp->bindings + resp->nbindings; b++) { in table_check_response()
493 if (work->descr->last_change.len != 0 && b == resp->bindings) { in table_check_response()
494 if (!asn_is_suboid(&work->descr->last_change, &b->var) || in table_check_response()
495 b->var.len != work->descr->last_change.len + 1 || in table_check_response()
496 b->var.subs[work->descr->last_change.len] != 0) { in table_check_response()
499 return (-1); in table_check_response()
501 if (b->syntax != SNMP_SYNTAX_TIMETICKS) { in table_check_response()
503 "last_change: bad syntax %u", b->syntax); in table_check_response()
504 return (-1); in table_check_response()
506 if (work->first) { in table_check_response()
507 work->last_change = b->v.uint32; in table_check_response()
508 work->first = 0; in table_check_response()
510 } else if (work->last_change != b->v.uint32) { in table_check_response()
511 if (++work->iter >= work->descr->max_iter) { in table_check_response()
514 return (-1); in table_check_response()
517 return (-2); in table_check_response()
522 if (!asn_is_suboid(&work->descr->table, &b->var) || in table_check_response()
523 b->syntax == SNMP_SYNTAX_ENDOFMIBVIEW) in table_check_response()
526 if ((e = table_find(work, &b->var)) == NULL) in table_check_response()
527 return (-1); in table_check_response()
528 if (table_value(work->descr, e, b)) in table_check_response()
529 return (-1); in table_check_response()
542 TAILQ_FOREACH(e, work->table, link) in table_check_cons()
543 if ((e->found & work->descr->req_mask) != in table_check_cons()
544 work->descr->req_mask) { in table_check_cons()
545 if (work->descr->last_change.len == 0) { in table_check_cons()
546 if (++work->iter >= work->descr->max_iter) { in table_check_cons()
549 return (-1); in table_check_cons()
551 return (-2); in table_check_cons()
554 e->found, work->descr->req_mask); in table_check_cons()
555 return (-1); in table_check_cons()
561 * Fetch a table. Returns 0 if ok, -1 on errors.
591 return (-1); in snmp_table_fetch()
597 if (ret == -1) { in snmp_table_fetch()
600 return (-1); in snmp_table_fetch()
602 if (ret == -2) { in snmp_table_fetch()
607 work.pdu.bindings[work.pdu.nbindings - 1].var = in snmp_table_fetch()
608 resp.bindings[resp.nbindings - 1].var; in snmp_table_fetch()
613 if ((ret = table_check_cons(&work)) == -1) { in snmp_table_fetch()
615 return (-1); in snmp_table_fetch()
617 if (ret == -2) { in snmp_table_fetch()
641 work->callback(work->table, work->arg, -1); in table_cb()
650 if ((ret = table_check_cons(work)) == -1) { in table_cb()
653 work->callback(work->table, work->arg, -1); in table_cb()
657 if (ret == -2) { in table_cb()
661 work->first = 1; in table_cb()
662 work->last_change = 0; in table_cb()
663 table_init_pdu(work->descr, &work->pdu); in table_cb()
664 if (snmp_pdu_send(&work->pdu, table_cb, work) == -1) { in table_cb()
665 work->callback(work->table, work->arg, -1); in table_cb()
675 work->callback(work->table, work->arg, 0); in table_cb()
680 if (ret == -1) { in table_cb()
684 work->callback(work->table, work->arg, -1); in table_cb()
689 if (ret == -2) { in table_cb()
697 work->pdu.bindings[work->pdu.nbindings - 1].var = in table_cb()
698 resp->bindings[resp->nbindings - 1].var; in table_cb()
702 if (snmp_pdu_send(&work->pdu, table_cb, work) == -1) { in table_cb()
704 work->callback(work->table, work->arg, -1); in table_cb()
718 return (-1); in snmp_table_fetch_async()
721 work->descr = descr; in snmp_table_fetch_async()
722 work->table = (struct table *)list; in snmp_table_fetch_async()
723 work->iter = 0; in snmp_table_fetch_async()
724 TAILQ_INIT(work->table); in snmp_table_fetch_async()
725 TAILQ_INIT(&work->worklist); in snmp_table_fetch_async()
727 work->callback = func; in snmp_table_fetch_async()
728 work->arg = arg; in snmp_table_fetch_async()
733 work->first = 1; in snmp_table_fetch_async()
734 work->last_change = 0; in snmp_table_fetch_async()
735 table_init_pdu(descr, &work->pdu); in snmp_table_fetch_async()
737 if (snmp_pdu_send(&work->pdu, table_cb, work) == -1) { in snmp_table_fetch_async()
740 return (-1); in snmp_table_fetch_async()
768 if (oid->len + 1 > ASN_MAXOIDLEN) { in snmp_oid_append()
770 ret = -1; in snmp_oid_append()
773 oid->subs[oid->len++] = va_arg(va, asn_subid_t); in snmp_oid_append()
778 if (oid->len + 4 > ASN_MAXOIDLEN) { in snmp_oid_append()
779 warnx("%s: OID too long for ip-addr", __func__); in snmp_oid_append()
780 ret = -1; in snmp_oid_append()
785 oid->subs[oid->len++] = (ina.s_addr >> 24) & 0xff; in snmp_oid_append()
786 oid->subs[oid->len++] = (ina.s_addr >> 16) & 0xff; in snmp_oid_append()
787 oid->subs[oid->len++] = (ina.s_addr >> 8) & 0xff; in snmp_oid_append()
788 oid->subs[oid->len++] = (ina.s_addr >> 0) & 0xff; in snmp_oid_append()
792 /* append a null-terminated string, in snmp_oid_append()
796 if (oid->len + len + 1 > ASN_MAXOIDLEN) { in snmp_oid_append()
798 ret = -1; in snmp_oid_append()
801 oid->subs[oid->len++] = len; in snmp_oid_append()
802 while (len--) in snmp_oid_append()
803 oid->subs[oid->len++] = *str++; in snmp_oid_append()
818 if (oid->len + size > ASN_MAXOIDLEN) { in snmp_oid_append()
820 ret = -1; in snmp_oid_append()
823 while (size--) in snmp_oid_append()
824 oid->subs[oid->len++] = *str++; in snmp_oid_append()
831 if (oid->len + size + 1 > ASN_MAXOIDLEN) { in snmp_oid_append()
833 ret = -1; in snmp_oid_append()
836 oid->subs[oid->len++] = size; in snmp_oid_append()
837 while (size--) in snmp_oid_append()
838 oid->subs[oid->len++] = *str++; in snmp_oid_append()
857 c->version = SNMP_V2c; in snmp_client_init()
858 c->trans = SNMP_TRANS_UDP; in snmp_client_init()
859 c->chost = NULL; in snmp_client_init()
860 c->cport = NULL; in snmp_client_init()
862 strcpy(c->read_community, "public"); in snmp_client_init()
863 strcpy(c->write_community, "private"); in snmp_client_init()
865 c->security_model = SNMP_SECMODEL_USM; in snmp_client_init()
866 strcpy(c->cname, ""); in snmp_client_init()
868 c->timeout.tv_sec = 3; in snmp_client_init()
869 c->timeout.tv_usec = 0; in snmp_client_init()
870 c->retries = 3; in snmp_client_init()
871 c->dump_pdus = 0; in snmp_client_init()
872 c->txbuflen = c->rxbuflen = 10000; in snmp_client_init()
874 c->fd = -1; in snmp_client_init()
876 c->max_reqid = INT32_MAX; in snmp_client_init()
877 c->min_reqid = 0; in snmp_client_init()
878 c->next_reqid = 0; in snmp_client_init()
880 c->engine.max_msg_size = 1500; /* XXX */ in snmp_client_init()
894 /* copy host- and portname */ in open_client_udp()
899 return (-1); in open_client_udp()
906 return (-1); in open_client_udp()
916 return (-1); in open_client_udp()
923 return (-1); in open_client_udp()
941 return (-1); in open_client_udp()
945 if ((snmp_client.fd = socket(res->ai_family, res->ai_socktype, in open_client_udp()
946 res->ai_protocol)) == -1) { in open_client_udp()
947 if ((res = res->ai_next) == NULL) { in open_client_udp()
950 return (-1); in open_client_udp()
952 } else if (connect(snmp_client.fd, res->ai_addr, in open_client_udp()
953 res->ai_addrlen) == -1) { in open_client_udp()
954 if ((res = res->ai_next) == NULL) { in open_client_udp()
958 snmp_client.fd = -1; in open_client_udp()
959 return (-1); in open_client_udp()
988 return (-1); in open_client_local()
995 return (-1); in open_client_local()
1007 if ((snmp_client.fd = socket(PF_LOCAL, stype, 0)) == -1) { in open_client_local()
1009 return (-1); in open_client_local()
1015 if (mkstemp(snmp_client.local_path) == -1) { in open_client_local()
1018 snmp_client.fd = -1; in open_client_local()
1019 return (-1); in open_client_local()
1026 if (bind(snmp_client.fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { in open_client_local()
1029 snmp_client.fd = -1; in open_client_local()
1031 return (-1); in open_client_local()
1038 strncpy(sa.sun_path, snmp_client.chost, sizeof(sa.sun_path) - 1); in open_client_local()
1039 sa.sun_path[sizeof(sa.sun_path) - 1] = '\0'; in open_client_local()
1041 if (connect(snmp_client.fd, (struct sockaddr *)&sa, sa.sun_len) == -1) { in open_client_local()
1044 snmp_client.fd = -1; in open_client_local()
1046 return (-1); in open_client_local()
1061 if (snmp_client.fd != -1) { in snmp_open()
1064 return (-1); in snmp_open()
1080 return (-1); in snmp_open()
1086 return (-1); in snmp_open()
1091 return (-1); in snmp_open()
1096 &tout, sizeof(struct timeval)) == -1) { in snmp_open()
1099 snmp_client.fd = -1; in snmp_open()
1102 return (-1); in snmp_open()
1116 * - function cannot fail
1117 * - clears connection
1118 * - clears list of sent pdus
1130 if (snmp_client.fd != -1) { in snmp_close()
1132 snmp_client.fd = -1; in snmp_close()
1138 if (p1->timeout_id != NULL) in snmp_close()
1139 snmp_client.timeout_stop(p1->timeout_id); in snmp_close()
1156 strlcpy(pdu->community, snmp_client.write_community, in snmp_pdu_create()
1157 sizeof(pdu->community)); in snmp_pdu_create()
1159 strlcpy(pdu->community, snmp_client.read_community, in snmp_pdu_create()
1160 sizeof(pdu->community)); in snmp_pdu_create()
1162 pdu->type = op; in snmp_pdu_create()
1163 pdu->version = snmp_client.version; in snmp_pdu_create()
1164 pdu->error_status = 0; in snmp_pdu_create()
1165 pdu->error_index = 0; in snmp_pdu_create()
1166 pdu->nbindings = 0; in snmp_pdu_create()
1171 pdu->identifier = ++snmp_client.identifier; in snmp_pdu_create()
1172 pdu->engine.max_msg_size = snmp_client.engine.max_msg_size; in snmp_pdu_create()
1173 pdu->flags = 0; in snmp_pdu_create()
1174 pdu->security_model = snmp_client.security_model; in snmp_pdu_create()
1177 memcpy(&pdu->engine, &snmp_client.engine, sizeof(pdu->engine)); in snmp_pdu_create()
1178 memcpy(&pdu->user, &snmp_client.user, sizeof(pdu->user)); in snmp_pdu_create()
1184 memcpy(pdu->context_engine, snmp_client.cengine, in snmp_pdu_create()
1186 pdu->context_engine_len = snmp_client.clen; in snmp_pdu_create()
1188 memcpy(pdu->context_engine, snmp_client.engine.engine_id, in snmp_pdu_create()
1190 pdu->context_engine_len = snmp_client.engine.engine_len; in snmp_pdu_create()
1193 strlcpy(pdu->context_name, snmp_client.cname, in snmp_pdu_create()
1194 sizeof(pdu->context_name)); in snmp_pdu_create()
1208 ret = pdu->nbindings; in snmp_add_binding()
1210 if (pdu->nbindings >= SNMP_MAX_BINDINGS){ in snmp_add_binding()
1212 return (-1); in snmp_add_binding()
1214 pdu->bindings[pdu->nbindings].var = *oid; in snmp_add_binding()
1215 pdu->bindings[pdu->nbindings].syntax = in snmp_add_binding()
1217 pdu->nbindings++; in snmp_add_binding()
1229 i = c->next_reqid; in snmp_next_reqid()
1230 if (c->next_reqid >= c->max_reqid) in snmp_next_reqid()
1231 c->next_reqid = c->min_reqid; in snmp_next_reqid()
1233 c->next_reqid++; in snmp_next_reqid()
1249 return (-1); in snmp_send_packet()
1252 pdu->request_id = snmp_next_reqid(&snmp_client); in snmp_send_packet()
1259 return (-1); in snmp_send_packet()
1265 if ((ret = send(snmp_client.fd, buf, b.asn_ptr - buf, 0)) == -1) { in snmp_send_packet()
1268 return (-1); in snmp_send_packet()
1272 return (pdu->request_id); in snmp_send_packet()
1285 listentry->reqid, listentry->retrycount, snmp_client.retries); in snmp_timeout()
1288 listentry->retrycount++; in snmp_timeout()
1289 if (listentry->retrycount > snmp_client.retries) { in snmp_timeout()
1292 listentry->callback(listentry->pdu, NULL, listentry->arg); in snmp_timeout()
1297 listentry->reqid = snmp_send_packet(listentry->pdu); in snmp_timeout()
1298 listentry->timeout_id = in snmp_timeout()
1312 return (-1); in snmp_pdu_send()
1316 if ((id = snmp_send_packet(pdu)) == -1) { in snmp_pdu_send()
1318 return (-1); in snmp_pdu_send()
1322 listentry->pdu = pdu; in snmp_pdu_send()
1323 if (gettimeofday(&listentry->time, NULL) == -1) in snmp_pdu_send()
1326 listentry->reqid = pdu->request_id; in snmp_pdu_send()
1327 listentry->callback = func; in snmp_pdu_send()
1328 listentry->arg = arg; in snmp_pdu_send()
1329 listentry->retrycount=1; in snmp_pdu_send()
1330 listentry->timeout_id = in snmp_pdu_send()
1342 * tv controls how we wait for a packet: if tv is a NULL pointer,
1343 * the receive blocks forever, if tv points to a structure with all
1344 * members 0 the socket is polled, in all other cases tv specifies the
1348 * -1 on errors
1353 snmp_receive_packet(struct snmp_pdu *pdu, struct timeval *tv) in snmp_receive_packet() argument
1370 return (-1); in snmp_receive_packet()
1374 if (tv != NULL) { in snmp_receive_packet()
1376 if (tv->tv_sec != 0 || tv->tv_usec != 0) { in snmp_receive_packet()
1379 tv, sizeof(*tv)) == -1) { in snmp_receive_packet()
1383 return (-1); in snmp_receive_packet()
1385 optlen = sizeof(*tv); in snmp_receive_packet()
1387 tv, &optlen) == -1) { in snmp_receive_packet()
1391 return (-1); in snmp_receive_packet()
1401 if (tv->tv_sec == 0 && tv->tv_usec == 0) { in snmp_receive_packet()
1404 if ((flags = fcntl(snmp_client.fd, F_GETFL, 0)) == -1) { in snmp_receive_packet()
1408 return (-1); in snmp_receive_packet()
1413 if (fcntl(snmp_client.fd, F_SETFL, flags) == -1) { in snmp_receive_packet()
1417 return (-1); in snmp_receive_packet()
1424 if (tv != NULL) { in snmp_receive_packet()
1431 tv->tv_sec = 0; in snmp_receive_packet()
1432 tv->tv_usec = 0; in snmp_receive_packet()
1434 tv, sizeof(*tv)); in snmp_receive_packet()
1437 if (ret == -1) { in snmp_receive_packet()
1442 return (-1); in snmp_receive_packet()
1450 return (-1); in snmp_receive_packet()
1458 memcpy(&pdu->engine, &snmp_client.engine, sizeof(pdu->engine)); in snmp_receive_packet()
1459 memcpy(&pdu->user, &snmp_client.user, sizeof(pdu->user)); in snmp_receive_packet()
1466 return (-1); in snmp_receive_packet()
1473 snmp_client.engine.engine_time = pdu->engine.engine_time; in snmp_receive_packet()
1474 snmp_client.engine.engine_boots = pdu->engine.engine_boots; in snmp_receive_packet()
1484 if (resp->type != SNMP_PDU_RESPONSE) { in snmp_deliver_packet()
1485 warn("ignoring snmp pdu %u", resp->type); in snmp_deliver_packet()
1486 return (-1); in snmp_deliver_packet()
1490 if (listentry->reqid == resp->request_id) in snmp_deliver_packet()
1493 return (-1); in snmp_deliver_packet()
1496 listentry->callback(listentry->pdu, resp, listentry->arg); in snmp_deliver_packet()
1498 snmp_client.timeout_stop(listentry->timeout_id); in snmp_deliver_packet()
1509 struct timeval tv; in snmp_receive() local
1512 memset(&tv, 0, sizeof(tv)); in snmp_receive()
1517 return (-1) ; in snmp_receive()
1520 if ((ret = snmp_receive_packet(resp, blocking ? NULL : &tv)) <= 0) { in snmp_receive()
1532 * Check a GETNEXT response. Here we have three possible outcomes: -1 an
1536 * syntaxes. This is really only useful to sweep non-sparse tables.
1543 if (resp->version != req->version) { in ok_getnext()
1545 return (-1); in ok_getnext()
1548 if (resp->error_status == SNMP_ERR_NOSUCHNAME) in ok_getnext()
1551 if (resp->error_status != SNMP_ERR_NOERROR) { in ok_getnext()
1552 warnx("SNMP GETNEXT: error %d", resp->error_status); in ok_getnext()
1553 return (-1); in ok_getnext()
1555 if (resp->nbindings != req->nbindings) { in ok_getnext()
1557 return (-1); in ok_getnext()
1559 for (i = 0; i < req->nbindings; i++) { in ok_getnext()
1560 if (!asn_is_suboid(&req->bindings[i].var, in ok_getnext()
1561 &resp->bindings[i].var)) { in ok_getnext()
1567 if (resp->version != SNMP_V1 && in ok_getnext()
1568 resp->bindings[i].syntax == SNMP_SYNTAX_ENDOFMIBVIEW) in ok_getnext()
1571 if (resp->bindings[i].syntax != req->bindings[i].syntax) { in ok_getnext()
1580 * Check a GET response. Here we have three possible outcomes: -1 an
1590 if (resp->version != req->version) { in ok_get()
1592 return (-1); in ok_get()
1595 if (resp->error_status == SNMP_ERR_NOSUCHNAME) in ok_get()
1598 if (resp->error_status != SNMP_ERR_NOERROR) { in ok_get()
1599 warnx("SNMP GET: error %d", resp->error_status); in ok_get()
1600 return (-1); in ok_get()
1603 if (resp->nbindings != req->nbindings) { in ok_get()
1605 return (-1); in ok_get()
1607 for (i = 0; i < req->nbindings; i++) { in ok_get()
1608 if (asn_compare_oid(&req->bindings[i].var, in ok_get()
1609 &resp->bindings[i].var) != 0) { in ok_get()
1611 return (-1); in ok_get()
1614 (resp->bindings[i].syntax == SNMP_SYNTAX_NOSUCHOBJECT || in ok_get()
1615 resp->bindings[i].syntax == SNMP_SYNTAX_NOSUCHINSTANCE)) in ok_get()
1617 if (resp->bindings[i].syntax != req->bindings[i].syntax) { in ok_get()
1619 return (-1); in ok_get()
1626 * Check the response to a SET PDU. We check: - the error status must be 0 -
1627 * the number of bindings must be equal in response and request - the
1628 * syntaxes must be the same in response and request - the OIDs must be the
1636 if (resp->version != req->version) { in ok_set()
1637 warnx("SNMP SET: response has wrong version"); in ok_set()
1638 return (-1); in ok_set()
1641 if (resp->error_status == SNMP_ERR_NOSUCHNAME) { in ok_set()
1642 warnx("SNMP SET: error %d", resp->error_status); in ok_set()
1645 if (resp->error_status != SNMP_ERR_NOERROR) { in ok_set()
1646 warnx("SNMP SET: error %d", resp->error_status); in ok_set()
1647 return (-1); in ok_set()
1650 if (resp->nbindings != req->nbindings) { in ok_set()
1651 warnx("SNMP SET: bad number of bindings in response"); in ok_set()
1652 return (-1); in ok_set()
1654 for (i = 0; i < req->nbindings; i++) { in ok_set()
1655 if (asn_compare_oid(&req->bindings[i].var, in ok_set()
1656 &resp->bindings[i].var) != 0) { in ok_set()
1657 warnx("SNMP SET: wrong OID in response to SET"); in ok_set()
1658 return (-1); in ok_set()
1660 if (resp->bindings[i].syntax != req->bindings[i].syntax) { in ok_set()
1661 warnx("SNMP SET: bad syntax in response"); in ok_set()
1662 return (-1); in ok_set()
1670 * 0=nosuchname or similar, -1=failure, -2=no response at all
1677 return (-2); in snmp_pdu_check()
1679 switch (req->type) { in snmp_pdu_check()
1691 errx(1, "%s: bad pdu type %i", __func__, req->type); in snmp_pdu_check()
1697 struct timeval tv = snmp_client.timeout; in snmp_dialog() local
1718 if ((reqid = snmp_send_packet(&pdu)) == -1) in snmp_dialog()
1719 return (-1); in snmp_dialog()
1721 (void)gettimeofday(&tv, NULL); in snmp_dialog()
1722 if (timercmp(&end, &tv, <=)) in snmp_dialog()
1724 timersub(&end, &tv, &tv); in snmp_dialog()
1725 if ((ret = snmp_receive_packet(resp, &tv)) == 0) in snmp_dialog()
1730 if (reqid == resp->request_id) in snmp_dialog()
1737 return (-1); in snmp_dialog()
1742 return (-1); in snmp_dialog()
1769 if (snmp_dialog(&req, &resp) == -1) in snmp_discover_engine()
1770 return (-1); in snmp_discover_engine()
1774 return (-1); in snmp_discover_engine()
1779 return (-1); in snmp_discover_engine()
1799 return (-1); in snmp_discover_engine()
1815 if (snmp_dialog(&req, &resp) == -1) in snmp_discover_engine()
1816 return (-1); in snmp_discover_engine()
1820 return (-1); in snmp_discover_engine()
1825 return (-1); in snmp_discover_engine()
1843 if (cl->chost != NULL) in snmp_client_set_host()
1844 free(cl->chost); in snmp_client_set_host()
1845 cl->chost = NULL; in snmp_client_set_host()
1848 return (-1); in snmp_client_set_host()
1850 if (cl->chost != NULL) in snmp_client_set_host()
1851 free(cl->chost); in snmp_client_set_host()
1852 cl->chost = np; in snmp_client_set_host()
1863 if (cl->cport != NULL) in snmp_client_set_port()
1864 free(cl->cport); in snmp_client_set_port()
1865 cl->cport = NULL; in snmp_client_set_port()
1868 return (-1); in snmp_client_set_port()
1870 if (cl->cport != NULL) in snmp_client_set_port()
1871 free(cl->cport); in snmp_client_set_port()
1872 cl->cport = np; in snmp_client_set_port()
1890 * \param sc client struct to set errors
1913 return (-1); in get_transp()
1925 seterr(sc, "unknown transport specifier '%.*s'", p - *strp, *strp); in get_transp()
1926 return (-1); in get_transp()
1934 * \param sc client struct to set errors
1950 if (p - *strp > SNMP_COMMUNITY_MAXLEN) { in get_comm()
1952 p - *strp, *strp); in get_comm()
1965 * \param sc client struct to set errors
1986 p - *strp, *strp); in get_ipv6()
1992 if (p - *strp > INET6_ADDRSTRLEN + IF_NAMESIZE) { in get_ipv6()
1993 seterr(sc, "IPv6 address too long '%.*s'", p - *strp, *strp); in get_ipv6()
1997 strncpy(str, *strp + 1, p - (*strp + 1)); in get_ipv6()
1998 str[p - (*strp + 1)] = '\0'; in get_ipv6()
2020 * \param sc client struct to set errors
2035 if (p - *strp > INET_ADDRSTRLEN) { in get_ipv4()
2036 seterr(sc, "IPv4 address too long '%.*s'", p - *strp, *strp); in get_ipv4()
2043 strncpy(str, *strp, p - *strp); in get_ipv4()
2044 str[p - *strp] = '\0'; in get_ipv4()
2060 * \param sc client struct to set errors
2085 * \param sc client struct to set errors
2110 * \param sc client struct to set errors
2120 if ((m = malloc(s[1] - s[0] + 1)) == NULL) { in save_str()
2124 strncpy(m, s[0], s[1] - s[0]); in save_str()
2125 m[s[1] - s[0]] = '\0'; in save_str()
2133 * [<trans>::][<comm>@][<host-or-ip>][:<port>]
2159 * \return 0 on success and -1 on errors
2169 return (-1); in snmp_parse_server()
2179 return (-1); in snmp_parse_server()
2186 return (-1); in snmp_parse_server()
2210 return (-1); in snmp_parse_server()
2214 return (-1); in snmp_parse_server()
2219 printf("comm: %zu %zu\n", comm[0] - orig, comm[1] - orig); in snmp_parse_server()
2220 printf("ipv6: %zu %zu\n", ipv6[0] - orig, ipv6[1] - orig); in snmp_parse_server()
2221 printf("ipv4: %zu %zu\n", ipv4[0] - orig, ipv4[1] - orig); in snmp_parse_server()
2222 printf("host: %zu %zu\n", host[0] - orig, host[1] - orig); in snmp_parse_server()
2223 printf("port: %zu %zu\n", port[0] - orig, port[1] - orig); in snmp_parse_server()
2231 return (-1); in snmp_parse_server()
2237 return (-1); in snmp_parse_server()
2242 return (-1); in snmp_parse_server()
2268 return (-1); in snmp_parse_server()
2272 sc->trans = trans; in snmp_parse_server()
2279 strncpy(sc->read_community, comm[0], comm[1] - comm[0]); in snmp_parse_server()
2280 sc->read_community[comm[1] - comm[0]] = '\0'; in snmp_parse_server()
2281 strncpy(sc->write_community, comm[0], comm[1] - comm[0]); in snmp_parse_server()
2282 sc->write_community[comm[1] - comm[0]] = '\0'; in snmp_parse_server()
2285 free(sc->chost); in snmp_parse_server()
2286 sc->chost = chost; in snmp_parse_server()
2287 free(sc->cport); in snmp_parse_server()
2288 sc->cport = cport; in snmp_parse_server()
2292 printf("trans: %d\n", sc->trans); in snmp_parse_server()
2293 printf("comm: '%s'/'%s'\n", sc->read_community, sc->write_community); in snmp_parse_server()
2294 printf("host: '%s'\n", sc->chost); in snmp_parse_server()
2295 printf("port: '%s'\n", sc->cport); in snmp_parse_server()