217
213
/* skip first variable if necessary */
218
214
if (pdu->errindex == i) {
219
var = var->next_variable;
215
var = var->next_variable;
222
218
if (var != NULL) {
224
/* VAR is the first uncopied variable */
226
/* Clone this variable */
227
newpdu->variables = snmp_var_clone(var);
228
if (newpdu->variables == NULL) {
229
snmp_pdu_free(newpdu);
234
newvar = newpdu->variables;
236
/* VAR has been copied to NEWVAR. */
237
while (var->next_variable) {
239
/* Skip the item that was bad */
240
if (++i == pdu->errindex) {
241
var = var->next_variable;
245
newvar->next_variable = snmp_var_clone(var->next_variable);
246
if (newvar->next_variable == NULL) {
247
snmp_pdu_free(newpdu);
250
/* Move to the next one */
251
newvar = newvar->next_variable;
252
var = var->next_variable;
255
newvar->next_variable = NULL;
220
/* VAR is the first uncopied variable */
222
/* Clone this variable */
223
newpdu->variables = snmp_var_clone(var);
224
if (newpdu->variables == NULL) {
225
snmp_pdu_free(newpdu);
230
newvar = newpdu->variables;
232
/* VAR has been copied to NEWVAR. */
233
while (var->next_variable) {
235
/* Skip the item that was bad */
236
if (++i == pdu->errindex) {
237
var = var->next_variable;
241
newvar->next_variable = snmp_var_clone(var->next_variable);
242
if (newvar->next_variable == NULL) {
243
snmp_pdu_free(newpdu);
246
/* Move to the next one */
247
newvar = newvar->next_variable;
248
var = var->next_variable;
251
newvar->next_variable = NULL;
257
253
/* If we didn't copy anything, free the new pdu. */
258
254
if (i < pdu->errindex || copied == 0) {
259
snmp_free_pdu(newpdu);
260
snmp_set_api_error(SNMPERR_UNABLE_TO_FIX);
255
snmp_free_pdu(newpdu);
256
snmp_set_api_error(SNMPERR_UNABLE_TO_FIX);
264
260
snmplib_debug(8, "PDU %x: Fixed PDU is %x\n",
265
(unsigned int) pdu, (unsigned int) newpdu);
261
(unsigned int) pdu, (unsigned int) newpdu);
358
354
/* ASN.1 Header */
359
355
switch (PDU->command) {
361
/**********************************************************************/
357
/**********************************************************************/
362
358
#ifdef TRP_REQ_MSG
363
359
case TRP_REQ_MSG:
368
bufp = asn_build_objid(DestBuf, DestBufLen,
369
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID),
370
(oid *) PDU->enterprise, PDU->enterprise_length);
375
bufp = asn_build_string(bufp, DestBufLen,
376
(u_char) (SMI_IPADDRESS | ASN_PRIMITIVE),
377
(u_char *) & PDU->agent_addr.sin_addr.s_addr,
378
sizeof(PDU->agent_addr.sin_addr.s_addr));
383
bufp = asn_build_int(bufp, DestBufLen,
384
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
385
(int *) &PDU->trap_type, sizeof(PDU->trap_type));
390
bufp = asn_build_int(bufp, DestBufLen,
391
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
392
(int *) &PDU->specific_type,
393
sizeof(PDU->specific_type));
398
bufp = asn_build_unsigned_int(bufp, DestBufLen,
399
(u_char) (SMI_TIMETICKS | ASN_PRIMITIVE),
400
&PDU->time, sizeof(PDU->time));
364
bufp = asn_build_objid(DestBuf, DestBufLen,
365
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID),
366
(oid *) PDU->enterprise, PDU->enterprise_length);
371
bufp = asn_build_string(bufp, DestBufLen,
372
(u_char) (SMI_IPADDRESS | ASN_PRIMITIVE),
373
(u_char *) & PDU->agent_addr.sin_addr.s_addr,
374
sizeof(PDU->agent_addr.sin_addr.s_addr));
379
bufp = asn_build_int(bufp, DestBufLen,
380
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
381
(int *) &PDU->trap_type, sizeof(PDU->trap_type));
386
bufp = asn_build_int(bufp, DestBufLen,
387
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
388
(int *) &PDU->specific_type,
389
sizeof(PDU->specific_type));
394
bufp = asn_build_unsigned_int(bufp, DestBufLen,
395
(u_char) (SMI_TIMETICKS | ASN_PRIMITIVE),
396
&PDU->time, sizeof(PDU->time));
406
/**********************************************************************/
402
/**********************************************************************/
408
404
case SNMP_PDU_GETBULK:
410
/* SNMPv2 Bulk Request */
413
bufp = asn_build_int(DestBuf, DestBufLen,
414
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
415
&PDU->reqid, sizeof(PDU->reqid));
420
bufp = asn_build_int(bufp, DestBufLen,
421
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
423
sizeof(PDU->non_repeaters));
427
/* max-repetitions */
428
bufp = asn_build_int(bufp, DestBufLen,
429
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
430
&PDU->max_repetitions,
431
sizeof(PDU->max_repetitions));
436
/**********************************************************************/
406
/* SNMPv2 Bulk Request */
409
bufp = asn_build_int(DestBuf, DestBufLen,
410
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
411
&PDU->reqid, sizeof(PDU->reqid));
416
bufp = asn_build_int(bufp, DestBufLen,
417
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
419
sizeof(PDU->non_repeaters));
423
/* max-repetitions */
424
bufp = asn_build_int(bufp, DestBufLen,
425
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
426
&PDU->max_repetitions,
427
sizeof(PDU->max_repetitions));
432
/**********************************************************************/
440
/* Normal PDU Encoding */
443
#ifdef DEBUG_PDU_ENCODE
444
snmplib_debug(8, "PDU: Request ID %d (0x%x)\n", PDU->reqid, DestBuf);
446
bufp = asn_build_int(DestBuf, DestBufLen,
447
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
448
&PDU->reqid, sizeof(PDU->reqid));
453
#ifdef DEBUG_PDU_ENCODE
454
snmplib_debug(8, "PDU: Error Status %d (0x%x)\n", PDU->errstat, bufp);
456
bufp = asn_build_int(bufp, DestBufLen,
457
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
458
&PDU->errstat, sizeof(PDU->errstat));
463
#ifdef DEBUG_PDU_ENCODE
464
snmplib_debug(8, "PDU: Error index %d (0x%x)\n", PDU->errindex, bufp);
466
bufp = asn_build_int(bufp, DestBufLen,
467
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
468
&PDU->errindex, sizeof(PDU->errindex));
436
/* Normal PDU Encoding */
439
#ifdef DEBUG_PDU_ENCODE
440
snmplib_debug(8, "PDU: Request ID %d (0x%x)\n", PDU->reqid, DestBuf);
442
bufp = asn_build_int(DestBuf, DestBufLen,
443
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
444
&PDU->reqid, sizeof(PDU->reqid));
449
#ifdef DEBUG_PDU_ENCODE
450
snmplib_debug(8, "PDU: Error Status %d (0x%x)\n", PDU->errstat, bufp);
452
bufp = asn_build_int(bufp, DestBufLen,
453
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
454
&PDU->errstat, sizeof(PDU->errstat));
459
#ifdef DEBUG_PDU_ENCODE
460
snmplib_debug(8, "PDU: Error index %d (0x%x)\n", PDU->errindex, bufp);
462
bufp = asn_build_int(bufp, DestBufLen,
463
(u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
464
&PDU->errindex, sizeof(PDU->errindex));
472
468
} /* End of encoding */
508
504
#ifdef TRP_REQ_MSG
509
505
case TRP_REQ_MSG:
511
/* SNMPv1 Trap Message */
514
PDU->enterprise_length = MAX_NAME_LEN;
515
bufp = asn_parse_objid(bufp, Length,
516
&ASNType, objid, &PDU->enterprise_length);
518
ASN_PARSE_ERROR(NULL);
520
PDU->enterprise = (oid *) xmalloc(PDU->enterprise_length * sizeof(oid));
521
if (PDU->enterprise == NULL) {
522
snmp_set_api_error(SNMPERR_OS_ERR);
525
xmemcpy((char *) PDU->enterprise, (char *) objid,
526
PDU->enterprise_length * sizeof(oid));
530
bufp = asn_parse_string(bufp, Length,
532
(u_char *) & PDU->agent_addr.sin_addr.s_addr,
535
ASN_PARSE_ERROR(NULL);
538
bufp = asn_parse_int(bufp, Length,
540
(int *) &PDU->trap_type,
541
sizeof(PDU->trap_type));
543
ASN_PARSE_ERROR(NULL);
546
bufp = asn_parse_int(bufp, Length,
548
(int *) &PDU->specific_type,
549
sizeof(PDU->specific_type));
551
ASN_PARSE_ERROR(NULL);
554
bufp = asn_parse_unsigned_int(bufp, Length,
556
&PDU->time, sizeof(PDU->time));
558
ASN_PARSE_ERROR(NULL);
507
/* SNMPv1 Trap Message */
510
PDU->enterprise_length = MAX_NAME_LEN;
511
bufp = asn_parse_objid(bufp, Length,
512
&ASNType, objid, &PDU->enterprise_length);
514
ASN_PARSE_ERROR(NULL);
516
PDU->enterprise = (oid *) xmalloc(PDU->enterprise_length * sizeof(oid));
517
if (PDU->enterprise == NULL) {
518
snmp_set_api_error(SNMPERR_OS_ERR);
521
xmemcpy((char *) PDU->enterprise, (char *) objid,
522
PDU->enterprise_length * sizeof(oid));
526
bufp = asn_parse_string(bufp, Length,
528
(u_char *) & PDU->agent_addr.sin_addr.s_addr,
531
ASN_PARSE_ERROR(NULL);
534
bufp = asn_parse_int(bufp, Length,
536
(int *) &PDU->trap_type,
537
sizeof(PDU->trap_type));
539
ASN_PARSE_ERROR(NULL);
542
bufp = asn_parse_int(bufp, Length,
544
(int *) &PDU->specific_type,
545
sizeof(PDU->specific_type));
547
ASN_PARSE_ERROR(NULL);
550
bufp = asn_parse_unsigned_int(bufp, Length,
552
&PDU->time, sizeof(PDU->time));
554
ASN_PARSE_ERROR(NULL);
562
/**********************************************************************/
558
/**********************************************************************/
564
560
case SNMP_PDU_GETBULK:
566
/* SNMPv2 Bulk Request */
569
bufp = asn_parse_int(bufp, Length,
571
&PDU->reqid, sizeof(PDU->reqid));
573
ASN_PARSE_ERROR(NULL);
576
bufp = asn_parse_int(bufp, Length,
578
&PDU->non_repeaters, sizeof(PDU->non_repeaters));
580
ASN_PARSE_ERROR(NULL);
582
/* max-repetitions */
583
bufp = asn_parse_int(bufp, Length,
585
&PDU->max_repetitions, sizeof(PDU->max_repetitions));
587
ASN_PARSE_ERROR(NULL);
590
/**********************************************************************/
562
/* SNMPv2 Bulk Request */
565
bufp = asn_parse_int(bufp, Length,
567
&PDU->reqid, sizeof(PDU->reqid));
569
ASN_PARSE_ERROR(NULL);
572
bufp = asn_parse_int(bufp, Length,
574
&PDU->non_repeaters, sizeof(PDU->non_repeaters));
576
ASN_PARSE_ERROR(NULL);
578
/* max-repetitions */
579
bufp = asn_parse_int(bufp, Length,
581
&PDU->max_repetitions, sizeof(PDU->max_repetitions));
583
ASN_PARSE_ERROR(NULL);
586
/**********************************************************************/
594
/* Normal PDU Encoding */
597
bufp = asn_parse_int(bufp, Length,
599
&PDU->reqid, sizeof(PDU->reqid));
601
ASN_PARSE_ERROR(NULL);
603
#ifdef DEBUG_PDU_DECODE
604
snmplib_debug(8, "PDU Request ID: %d\n", PDU->reqid);
608
bufp = asn_parse_int(bufp, Length,
610
&PDU->errstat, sizeof(PDU->errstat));
612
ASN_PARSE_ERROR(NULL);
614
#ifdef DEBUG_PDU_DECODE
615
snmplib_debug(8, "PDU Error Status: %d\n", PDU->errstat);
619
bufp = asn_parse_int(bufp, Length,
621
&PDU->errindex, sizeof(PDU->errindex));
623
ASN_PARSE_ERROR(NULL);
625
#ifdef DEBUG_PDU_DECODE
626
snmplib_debug(8, "PDU Error Index: %d\n", PDU->errindex);
590
/* Normal PDU Encoding */
593
bufp = asn_parse_int(bufp, Length,
595
&PDU->reqid, sizeof(PDU->reqid));
597
ASN_PARSE_ERROR(NULL);
599
#ifdef DEBUG_PDU_DECODE
600
snmplib_debug(8, "PDU Request ID: %d\n", PDU->reqid);
604
bufp = asn_parse_int(bufp, Length,
606
&PDU->errstat, sizeof(PDU->errstat));
608
ASN_PARSE_ERROR(NULL);
610
#ifdef DEBUG_PDU_DECODE
611
snmplib_debug(8, "PDU Error Status: %d\n", PDU->errstat);
615
bufp = asn_parse_int(bufp, Length,
617
&PDU->errindex, sizeof(PDU->errindex));
619
ASN_PARSE_ERROR(NULL);
621
#ifdef DEBUG_PDU_DECODE
622
snmplib_debug(8, "PDU Error Index: %d\n", PDU->errindex);