1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* 23 * Copyright 1996 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26#pragma ident "%Z%%M% %I% %E% SMI" 27 28 29#include "stdio.h" 30#include "errno.h" 31#include "sys/types.h" 32#include "sys/socket.h" 33#include "netinet/in.h" 34 35#include "snmp_msg.h" 36#include "error.h" 37#include "trace.h" 38#include "madman_api.h" 39 40 41/***** NEW CONSTANTS *****/ 42 43#define MSG_END_OF_TABLE "end of table for request %s on %s\n\n" 44#define ERR_MSG_REQUEST_FAILED "the request %s on %s failed: %s\n\n" 45 46 47/***** NEW TYPES *****/ 48 49typedef struct _Target { 50 struct _Target *next_target; 51 char name[100]; 52} Target; 53 54 55/***** STATIC VARIABLES *****/ 56 57static int snmp_session_num = 0; 58 59static Target *first_target = NULL; 60 61 62/****** STATIC FUNCTIONS *****/ 63 64static int target_add(char *name, char *error_label); 65 66 67/**************************************************************/ 68 69static int target_add(char *name, char *error_label) 70{ 71 Target *new; 72 73 74 error_label[0] = '\0'; 75 76 if(name == NULL) 77 { 78 sprintf(error_label, "BUG: name is NULL"); 79 return -1; 80 } 81 82 new = (Target *) malloc(sizeof(Target)); 83 if(new == NULL) 84 { 85 sprintf(error_label, ERR_MSG_ALLOC); 86 return -1; 87 } 88 89 strcpy(new->name, name); 90 91 new->next_target = first_target; 92 first_target = new; 93 94 return 0; 95} 96 97 98/**************************************************************/ 99/* 100 * do not free response! 101 */ 102 103static void snmp_callback(int operation, SNMP_session *session, int request_id, int predefined_id, SNMP_pdu *response, void *snmp_callback_magic) 104{ 105 struct itimerval itimeout; 106 ApplEntry *applEntry = NULL; 107 AssocEntry *assocEntry = NULL; 108 MtaEntry *mtaEntry = NULL; 109 MtaGroupEntry *mtaGroupEntry = NULL; 110 MtaGroupAssociationEntry *mtaGroupAssociationEntry = NULL; 111 DsaOpsEntry *dsaOpsEntry = NULL; 112 DsaEntriesEntry *dsaEntriesEntry = NULL; 113 DsaIntEntry *dsaIntEntry = NULL; 114 X4msMtaEntry *x4msMtaEntry = NULL; 115 X4msUserEntryPart1 *x4msUserEntryPart1 = NULL; 116 X4msUserEntryPart2 *x4msUserEntryPart2 = NULL; 117 X4msUserAssociationEntry *x4msUserAssociationEntry = NULL; 118 X4grpEntry *x4grpEntry = NULL; 119 X4grpMappingEntry *x4grpMappingEntry = NULL; 120 X5dsaReferenceEntry *x5dsaReferenceEntry = NULL; 121 char *request_name = NULL; 122 123 124 request_name = predefined_request_string(predefined_id); 125 126 switch(operation) 127 { 128 case RECEIVED_MESSAGE: 129 switch(predefined_id) 130 { 131 case APPL_ENTRY_REQ: 132 applEntry = applEntry_process_response(session, response, error_label); 133 if(applEntry == NULL) 134 { 135 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 136 { 137 fprintf(stderr, MSG_END_OF_TABLE, 138 request_name, session->peername); 139 140 if(assocEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, error_label)) 141 { 142 fprintf(stderr, "assocEntry_send_request(%s) failed: %s\n\n", 143 session->peername, error_label); 144 snmp_session_close(session, error_label); 145 snmp_session_num--; 146 } 147 } 148 else 149 { 150 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 151 request_name, session->peername, error_label); 152 trace_snmp_pdu(response); 153 154 snmp_session_close(session, error_label); 155 snmp_session_num--; 156 } 157 } 158 else 159 { 160 applEntry_print(applEntry); 161 if(applEntry_send_request(session, GETNEXT_REQ_MSG, applEntry->applIndex, error_label)) 162 { 163 fprintf(stderr, "applEntry_send_request(%s) failed: %s\n\n", 164 session->peername, error_label); 165 snmp_session_close(session, error_label); 166 snmp_session_num--; 167 } 168 applEntry_free(applEntry); 169 } 170 171 break; 172 173 174 case ASSOC_ENTRY_REQ: 175 assocEntry = assocEntry_process_response(session, response, error_label); 176 if(assocEntry == NULL) 177 { 178 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 179 { 180 fprintf(stderr, MSG_END_OF_TABLE, 181 request_name, session->peername); 182 183 if(mtaEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label)) 184 { 185 fprintf(stderr, "mtaEntry_send_request(%s) failed: %s\n\n", 186 session->peername, error_label); 187 snmp_session_close(session, error_label); 188 snmp_session_num--; 189 } 190 } 191 else 192 { 193 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 194 request_name, session->peername, error_label); 195 trace_snmp_pdu(response); 196 197 snmp_session_close(session, error_label); 198 snmp_session_num--; 199 } 200 } 201 else 202 { 203 assocEntry_print(assocEntry); 204 if(assocEntry_send_request(session, GETNEXT_REQ_MSG, assocEntry->applIndex, assocEntry->assocIndex, error_label)) 205 { 206 fprintf(stderr, "assocEntry_send_request(%s) failed: %s\n\n", 207 session->peername, error_label); 208 snmp_session_close(session, error_label); 209 snmp_session_num--; 210 } 211 assocEntry_free(assocEntry); 212 } 213 214 break; 215 216 217 case MTA_ENTRY_REQ: 218 mtaEntry = mtaEntry_process_response(session, response, error_label); 219 if(mtaEntry == NULL) 220 { 221 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 222 { 223 fprintf(stderr, MSG_END_OF_TABLE, 224 request_name, session->peername); 225 226 if(mtaGroupEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, error_label)) 227 { 228 fprintf(stderr, "mtaGroupEntry_send_request(%s) failed: %s\n\n", 229 session->peername, error_label); 230 snmp_session_close(session, error_label); 231 snmp_session_num--; 232 } 233 } 234 else 235 { 236 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 237 request_name, session->peername, error_label); 238 trace_snmp_pdu(response); 239 240 snmp_session_close(session, error_label); 241 snmp_session_num--; 242 } 243 } 244 else 245 { 246 mtaEntry_print(mtaEntry); 247 if(mtaEntry_send_request(session, GETNEXT_REQ_MSG, mtaEntry->applIndex, error_label)) 248 { 249 fprintf(stderr, "mtaEntry_send_request(%s) failed: %s\n\n", 250 session->peername, error_label); 251 snmp_session_close(session, error_label); 252 snmp_session_num--; 253 } 254 mtaEntry_free(mtaEntry); 255 } 256 257 break; 258 259 260 case MTA_GROUP_ENTRY_REQ: 261 mtaGroupEntry = mtaGroupEntry_process_response(session, response, error_label); 262 if(mtaGroupEntry == NULL) 263 { 264 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 265 { 266 fprintf(stderr, MSG_END_OF_TABLE, 267 request_name, session->peername); 268 } 269 else 270 { 271 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 272 request_name, session->peername, error_label); 273 trace_snmp_pdu(response); 274 275 snmp_session_close(session, error_label); 276 snmp_session_num--; 277 } 278 } 279 else 280 { 281 mtaGroupEntry_print(mtaGroupEntry); 282 mtaGroupEntry_free(mtaGroupEntry); 283 } 284 285 break; 286 287 288 case MTA_GROUP_ASSOCIATION_ENTRY_REQ: 289 mtaGroupAssociationEntry = mtaGroupAssociationEntry_process_response(session, response, error_label); 290 if(mtaGroupAssociationEntry == NULL) 291 { 292 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 293 { 294 fprintf(stderr, MSG_END_OF_TABLE, 295 request_name, session->peername); 296 297 if(dsaOpsEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label)) 298 { 299 fprintf(stderr, "dsaOpsEntry_send_request(%s) failed: %s\n\n", 300 session->peername, error_label); 301 snmp_session_close(session, error_label); 302 snmp_session_num--; 303 } 304 } 305 else 306 { 307 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 308 request_name, session->peername, error_label); 309 trace_snmp_pdu(response); 310 311 snmp_session_close(session, error_label); 312 snmp_session_num--; 313 } 314 } 315 else 316 { 317 mtaGroupAssociationEntry_print(mtaGroupAssociationEntry); 318 if(mtaGroupAssociationEntry_send_request(session, GETNEXT_REQ_MSG, mtaGroupAssociationEntry->applIndex, mtaGroupAssociationEntry->mtaGroupIndex, mtaGroupAssociationEntry->mtaGroupAssociationIndex, error_label)) 319 { 320 fprintf(stderr, "mtaGroupAssociationEntry_send_request(%s) failed: %s\n\n", 321 session->peername, error_label); 322 snmp_session_close(session, error_label); 323 snmp_session_num--; 324 } 325 mtaGroupAssociationEntry_free(mtaGroupAssociationEntry); 326 } 327 328 break; 329 330 331 case DSA_OPS_ENTRY_REQ: 332 dsaOpsEntry = dsaOpsEntry_process_response(session, response, error_label); 333 if(dsaOpsEntry == NULL) 334 { 335 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 336 { 337 fprintf(stderr, MSG_END_OF_TABLE, 338 request_name, session->peername); 339 340 if(dsaEntriesEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label)) 341 { 342 fprintf(stderr, "dsaEntriesEntry_send_request(%s) failed: %s\n\n", 343 session->peername, error_label); 344 snmp_session_close(session, error_label); 345 snmp_session_num--; 346 } 347 } 348 else 349 { 350 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 351 request_name, session->peername, error_label); 352 trace_snmp_pdu(response); 353 354 snmp_session_close(session, error_label); 355 snmp_session_num--; 356 } 357 } 358 else 359 { 360 dsaOpsEntry_print(dsaOpsEntry); 361 if(dsaOpsEntry_send_request(session, GETNEXT_REQ_MSG, dsaOpsEntry->applIndex, error_label)) 362 { 363 fprintf(stderr, "dsaOpsEntry_send_request(%s) failed: %s\n\n", 364 session->peername, error_label); 365 snmp_session_close(session, error_label); 366 snmp_session_num--; 367 } 368 dsaOpsEntry_free(dsaOpsEntry); 369 } 370 371 break; 372 373 374 case DSA_ENTRIES_ENTRY_REQ: 375 dsaEntriesEntry = dsaEntriesEntry_process_response(session, response, error_label); 376 if(dsaEntriesEntry == NULL) 377 { 378 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 379 { 380 fprintf(stderr, MSG_END_OF_TABLE, 381 request_name, session->peername); 382 383 if(dsaIntEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, error_label)) 384 { 385 fprintf(stderr, "dsaIntEntry_send_request(%s) failed: %s\n\n", 386 session->peername, error_label); 387 snmp_session_close(session, error_label); 388 snmp_session_num--; 389 } 390 } 391 else 392 { 393 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 394 request_name, session->peername, error_label); 395 trace_snmp_pdu(response); 396 397 snmp_session_close(session, error_label); 398 snmp_session_num--; 399 } 400 } 401 else 402 { 403 dsaEntriesEntry_print(dsaEntriesEntry); 404 if(dsaEntriesEntry_send_request(session, GETNEXT_REQ_MSG, dsaEntriesEntry->applIndex, error_label)) 405 { 406 fprintf(stderr, "dsaEntriesEntry_send_request(%s) failed: %s\n\n", 407 session->peername, error_label); 408 snmp_session_close(session, error_label); 409 snmp_session_num--; 410 } 411 dsaEntriesEntry_free(dsaEntriesEntry); 412 } 413 414 break; 415 416 417 case DSA_INT_ENTRY_REQ: 418 dsaIntEntry = dsaIntEntry_process_response(session, response, error_label); 419 if(dsaIntEntry == NULL) 420 { 421 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 422 { 423 fprintf(stderr, MSG_END_OF_TABLE, 424 request_name, session->peername); 425 426 if(x4msMtaEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label)) 427 { 428 fprintf(stderr, "x4msMtaEntry_send_request(%s) failed: %s\n\n", 429 session->peername, error_label); 430 snmp_session_close(session, error_label); 431 snmp_session_num--; 432 } 433 } 434 else 435 { 436 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 437 request_name, session->peername, error_label); 438 trace_snmp_pdu(response); 439 440 snmp_session_close(session, error_label); 441 snmp_session_num--; 442 } 443 } 444 else 445 { 446 dsaIntEntry_print(dsaIntEntry); 447 if(dsaIntEntry_send_request(session, GETNEXT_REQ_MSG, dsaIntEntry->applIndex, dsaIntEntry->dsaIntIndex, error_label)) 448 { 449 fprintf(stderr, "dsaIntEntry_send_request(%s) failed: %s\n\n", 450 session->peername, error_label); 451 snmp_session_close(session, error_label); 452 snmp_session_num--; 453 } 454 dsaIntEntry_free(dsaIntEntry); 455 } 456 457 break; 458 459 460 case X4MS_MTA_ENTRY_REQ: 461 x4msMtaEntry = x4msMtaEntry_process_response(session, response, error_label); 462 if(x4msMtaEntry == NULL) 463 { 464 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 465 { 466 fprintf(stderr, MSG_END_OF_TABLE, 467 request_name, session->peername); 468 469 if(x4msUserEntryPart1_send_request(session, GETNEXT_REQ_MSG, -1, error_label)) 470 { 471 fprintf(stderr, "x4msUserEntryPart1_send_request(%s) failed: %s\n\n", 472 session->peername, error_label); 473 snmp_session_close(session, error_label); 474 snmp_session_num--; 475 } 476 } 477 else 478 { 479 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 480 request_name, session->peername, error_label); 481 trace_snmp_pdu(response); 482 483 snmp_session_close(session, error_label); 484 snmp_session_num--; 485 } 486 } 487 else 488 { 489 x4msMtaEntry_print(x4msMtaEntry); 490 if(x4msMtaEntry_send_request(session, GETNEXT_REQ_MSG, x4msMtaEntry->x4msMtaIndex, error_label)) 491 { 492 fprintf(stderr, "x4msMtaEntry_send_request(%s) failed: %s\n\n", 493 session->peername, error_label); 494 snmp_session_close(session, error_label); 495 snmp_session_num--; 496 } 497 x4msMtaEntry_free(x4msMtaEntry); 498 } 499 500 break; 501 502 503 case X4MS_USER_ENTRY_PART1_REQ: 504 x4msUserEntryPart1 = x4msUserEntryPart1_process_response(session, response, error_label); 505 if(x4msUserEntryPart1 == NULL) 506 { 507 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 508 { 509 fprintf(stderr, MSG_END_OF_TABLE, 510 request_name, session->peername); 511 512 if(x4msUserAssociationEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, error_label)) 513 { 514 fprintf(stderr, "x4msUserAssociationEntry_send_request(%s) failed: %s\n\n", 515 session->peername, error_label); 516 snmp_session_close(session, error_label); 517 snmp_session_num--; 518 } 519 } 520 else 521 { 522 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 523 request_name, session->peername, error_label); 524 trace_snmp_pdu(response); 525 526 snmp_session_close(session, error_label); 527 snmp_session_num--; 528 } 529 } 530 else 531 { 532 x4msUserEntryPart1_print(x4msUserEntryPart1); 533 534 if(x4msUserEntryPart2_send_request(session, GET_REQ_MSG, x4msUserEntryPart1->x4msUserIndex, error_label)) 535 { 536 fprintf(stderr, "x4msUserEntryPart2_send_request(%s) failed: %s\n\n", 537 session->peername, error_label); 538 snmp_session_close(session, error_label); 539 snmp_session_num--; 540 } 541 542 if(x4msUserEntryPart1_send_request(session, GETNEXT_REQ_MSG, x4msUserEntryPart1->x4msUserIndex, error_label)) 543 { 544 fprintf(stderr, "x4msUserEntryPart1_send_request(%s) failed: %s\n\n", 545 session->peername, error_label); 546 snmp_session_close(session, error_label); 547 snmp_session_num--; 548 } 549 550 x4msUserEntryPart1_free(x4msUserEntryPart1); 551 } 552 553 break; 554 555 556 case X4MS_USER_ENTRY_PART2_REQ: 557 x4msUserEntryPart2 = x4msUserEntryPart2_process_response(session, response, error_label); 558 if(x4msUserEntryPart2 == NULL) 559 { 560 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 561 request_name, session->peername, error_label); 562 trace_snmp_pdu(response); 563 564 snmp_session_close(session, error_label); 565 snmp_session_num--; 566 } 567 else 568 { 569 x4msUserEntryPart2_print(x4msUserEntryPart2); 570 x4msUserEntryPart2_free(x4msUserEntryPart2); 571 } 572 573 break; 574 575 576 case X4MS_USER_ASSOCIATION_ENTRY_REQ: 577 x4msUserAssociationEntry = x4msUserAssociationEntry_process_response(session, response, error_label); 578 if(x4msUserAssociationEntry == NULL) 579 { 580 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 581 { 582 fprintf(stderr, MSG_END_OF_TABLE, 583 request_name, session->peername); 584 585 if(x4grpEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label)) 586 { 587 fprintf(stderr, "x4grpEntry_send_request(%s) failed: %s\n\n", 588 session->peername, error_label); 589 snmp_session_close(session, error_label); 590 snmp_session_num--; 591 } 592 } 593 else 594 { 595 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 596 request_name, session->peername, error_label); 597 trace_snmp_pdu(response); 598 599 snmp_session_close(session, error_label); 600 snmp_session_num--; 601 } 602 } 603 else 604 { 605 x4msUserAssociationEntry_print(x4msUserAssociationEntry); 606 if(x4msUserAssociationEntry_send_request(session, GETNEXT_REQ_MSG, x4msUserAssociationEntry->x4msUserIndex, x4msUserAssociationEntry->x4msUserAssociationIndex, error_label)) 607 { 608 fprintf(stderr, "x4msUserAssociationEntry_send_request(%s) failed: %s\n\n", 609 session->peername, error_label); 610 snmp_session_close(session, error_label); 611 snmp_session_num--; 612 } 613 x4msUserAssociationEntry_free(x4msUserAssociationEntry); 614 } 615 616 break; 617 618 case X4GRP_ENTRY_REQ: 619 x4grpEntry = x4grpEntry_process_response(session, response, error_label); 620 if(x4grpEntry == NULL) 621 { 622 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 623 { 624 fprintf(stderr, MSG_END_OF_TABLE, 625 request_name, session->peername); 626 627 if(x4grpMappingEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, -1, error_label)) 628 { 629 fprintf(stderr, "x4grpMappingEntry_send_request(%s) failed: %s\n\n", 630 session->peername, error_label); 631 snmp_session_close(session, error_label); 632 snmp_session_num--; 633 } 634 } 635 else 636 { 637 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 638 request_name, session->peername, error_label); 639 trace_snmp_pdu(response); 640 641 snmp_session_close(session, error_label); 642 snmp_session_num--; 643 } 644 } 645 else 646 { 647 x4grpEntry_print(x4grpEntry); 648 if(x4grpEntry_send_request(session, GETNEXT_REQ_MSG, x4grpEntry->x4grpIndex, error_label)) 649 { 650 fprintf(stderr, "x4grpEntry_send_request(%s) failed: %s\n\n", 651 session->peername, error_label); 652 snmp_session_close(session, error_label); 653 snmp_session_num--; 654 } 655 x4grpEntry_free(x4grpEntry); 656 } 657 658 break; 659 660 661 case X4GRP_MAPPING_ENTRY_REQ: 662 x4grpMappingEntry = x4grpMappingEntry_process_response(session, response, error_label); 663 if(x4grpMappingEntry == NULL) 664 { 665 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 666 { 667 fprintf(stderr, MSG_END_OF_TABLE, 668 request_name, session->peername); 669 670 if(x5dsaReferenceEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label)) 671 { 672 fprintf(stderr, "x5dsaReferenceEntry_send_request(%s) failed: %s\n\n", 673 session->peername, error_label); 674 snmp_session_close(session, error_label); 675 snmp_session_num--; 676 } 677 } 678 else 679 { 680 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 681 request_name, session->peername, error_label); 682 trace_snmp_pdu(response); 683 684 snmp_session_close(session, error_label); 685 snmp_session_num--; 686 } 687 } 688 else 689 { 690 x4grpMappingEntry_print(x4grpMappingEntry); 691 if(x4grpMappingEntry_send_request(session, GETNEXT_REQ_MSG, x4grpMappingEntry->x4grpIndex, x4grpMappingEntry->x4grpMappingMSIndex, x4grpMappingEntry->x4grpMappingMTAIndex, error_label)) 692 { 693 fprintf(stderr, "x4grpMappingEntry_send_request(%s) failed: %s\n\n", 694 session->peername, error_label); 695 snmp_session_close(session, error_label); 696 snmp_session_num--; 697 } 698 x4grpMappingEntry_free(x4grpMappingEntry); 699 } 700 701 break; 702 703 704 case X5DSA_REFERENCE_ENTRY_REQ: 705 x5dsaReferenceEntry = x5dsaReferenceEntry_process_response(session, response, error_label); 706 if(x5dsaReferenceEntry == NULL) 707 { 708 if(snmp_errno == SNMP_ERR_NOSUCHNAME) 709 { 710 fprintf(stderr, MSG_END_OF_TABLE, 711 request_name, session->peername); 712 713 snmp_session_close(session, error_label); 714 snmp_session_num--; 715 } 716 else 717 { 718 fprintf(stderr, ERR_MSG_REQUEST_FAILED, 719 request_name, session->peername, error_label); 720 trace_snmp_pdu(response); 721 722 snmp_session_close(session, error_label); 723 snmp_session_num--; 724 } 725 } 726 else 727 { 728 x5dsaReferenceEntry_print(x5dsaReferenceEntry); 729 if(x5dsaReferenceEntry_send_request(session, GETNEXT_REQ_MSG, x5dsaReferenceEntry->x5dsaReferenceIndex, error_label)) 730 { 731 fprintf(stderr, "x5dsaReferenceEntry_send_request(%s) failed: %s\n\n", 732 session->peername, error_label); 733 snmp_session_close(session, error_label); 734 snmp_session_num--; 735 } 736 x5dsaReferenceEntry_free(x5dsaReferenceEntry); 737 } 738 739 break; 740 741 742 default: 743 fprintf(stderr, "unknown pdu received %d from %s\n\n", 744 predefined_id, session->peername); 745 746 trace_snmp_pdu(response); 747 748 snmp_session_close(session, error_label); 749 snmp_session_num--; 750 751 break; 752 } 753 754 break; 755 756 757 case TIMED_OUT: 758 switch(predefined_id) 759 { 760 case APPL_ENTRY_REQ: 761 case ASSOC_ENTRY_REQ: 762 case MTA_ENTRY_REQ: 763 case MTA_GROUP_ENTRY_REQ: 764 case MTA_GROUP_ASSOCIATION_ENTRY_REQ: 765 case X4MS_MTA_ENTRY_REQ: 766 case X4MS_USER_ENTRY_PART1_REQ: 767 case X4MS_USER_ENTRY_PART2_REQ: 768 case X4MS_USER_ASSOCIATION_ENTRY_REQ: 769 case X4GRP_ENTRY_REQ: 770 case X4GRP_MAPPING_ENTRY_REQ: 771 case X5DSA_REFERENCE_ENTRY_REQ: 772 fprintf(stderr, "the request %s on %s TIMED OUT\n\n", 773 request_name, session->peername); 774 break; 775 776 default: 777 fprintf(stderr, "an unknown request %d on %s TIMED OUT\n\n", 778 predefined_id, session->peername); 779 break; 780 } 781 782 snmp_session_close(session, error_label); 783 snmp_session_num--; 784 785 break; 786 } 787 788 if(snmp_session_num == 0) 789 { 790 exit(0); 791 } 792} 793 794 795/**************************************************************/ 796 797main(int argc, char **argv) 798{ 799 int numfds; 800 fd_set fdset; 801 int count; 802 struct timeval timeout; 803 char targets[1000]; 804 char target[1000]; 805 char c; 806 char *ptr; 807 int i = 0; 808 Target *t; 809 810 811 while((c = getopt(argc, argv, "t:v"))!= -1) 812 { 813 switch(c) 814 { 815 case 't': 816 strcpy(targets, optarg); 817 break; 818 case 'v': 819 trace_flags = 0xFFFF; 820 } 821 } 822 823 824 i = 0; 825 for(ptr = targets; *ptr; ptr++) 826 { 827 if(isspace(*ptr)) 828 { 829 if(i == 0) 830 { 831 continue; 832 } 833 } 834 835 target[i++] = *ptr; 836 837 if( (*(ptr + 1) == '\0') || isspace(*(ptr + 1)) ) 838 { 839 target[i] = '\0'; 840 841 if(target_add(target, error_label)) 842 { 843 fprintf(stderr, "target_add(%s) failed: %s\n\n", 844 target, error_label); 845 } 846 847 i = 0; 848 } 849 } 850 851 852 for(t = first_target; t; t = t->next_target) 853 { 854 SNMP_session *session; 855 856 857 session = snmp_session_open_default(t->name, snmp_callback, NULL, error_label); 858 if(session == NULL) 859 { 860 fprintf(stderr, "snmp_session_open_default(%s) failed: %s\n\n", 861 t->name, error_label); 862 continue; 863 } 864 snmp_session_num++; 865 866 if(mtaGroupEntry_send_request(session, GET_REQ_MSG, 1, 1009, error_label)) 867 { 868 fprintf(stderr, "mtaGroupEntry_send_request(%s) failed: %s\n\n", 869 session->peername, error_label); 870 snmp_session_close(session, error_label); 871 snmp_session_num--; 872 } 873 } 874 875 876 if(snmp_session_num == 0) 877 { 878 exit(0); 879 } 880 881 882 while(1) 883 { 884 numfds = 0; 885 FD_ZERO(&fdset); 886 887 timeout.tv_sec = 10; 888 timeout.tv_usec = 0; 889 890 snmp_session_select_info(&numfds, &fdset, &timeout); 891 892 count = select(numfds, &fdset, 0, 0, &timeout); 893 if(count > 0) 894 { 895 snmp_session_read(&fdset); 896 } 897 else 898 { 899 switch(count) 900 { 901 case 0: 902 snmp_session_timeout(); 903 break; 904 905 case -1: 906 if(errno == EINTR) 907 { 908 continue; 909 } 910 else 911 { 912 fprintf(stderr, "select() failed %s\n", 913 errno_string()); 914 } 915 } 916 } 917 } 918} 919 920 921