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
49 typedef struct _Target {
50 struct _Target *next_target;
51 char name[100];
52 } Target;
53
54
55 /***** STATIC VARIABLES *****/
56
57 static int snmp_session_num = 0;
58
59 static Target *first_target = NULL;
60
61
62 /****** STATIC FUNCTIONS *****/
63
64 static int target_add(char *name, char *error_label);
65
66
67 /**************************************************************/
68
target_add(char * name,char * error_label)69 static 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
snmp_callback(int operation,SNMP_session * session,int request_id,int predefined_id,SNMP_pdu * response,void * snmp_callback_magic)103 static 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 if(mtaGroupAssociationEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, -1, error_label))
270 {
271 fprintf(stderr, "mtaGroupAssociationEntry_send_request(%s) failed: %s\n\n",
272 session->peername, error_label);
273 snmp_session_close(session, error_label);
274 snmp_session_num--;
275 }
276 }
277 else
278 {
279 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
280 request_name, session->peername, error_label);
281 trace_snmp_pdu(response);
282
283 snmp_session_close(session, error_label);
284 snmp_session_num--;
285 }
286 }
287 else
288 {
289 mtaGroupEntry_print(mtaGroupEntry);
290 if(mtaGroupEntry_send_request(session, GETNEXT_REQ_MSG, mtaGroupEntry->applIndex, mtaGroupEntry->mtaGroupIndex, error_label))
291 {
292 fprintf(stderr, "mtaGroupEntry_send_request(%s) failed: %s\n\n",
293 session->peername, error_label);
294 snmp_session_close(session, error_label);
295 snmp_session_num--;
296 }
297 mtaGroupEntry_free(mtaGroupEntry);
298 }
299
300 break;
301
302
303 case MTA_GROUP_ASSOCIATION_ENTRY_REQ:
304 mtaGroupAssociationEntry = mtaGroupAssociationEntry_process_response(session, response, error_label);
305 if(mtaGroupAssociationEntry == NULL)
306 {
307 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
308 {
309 fprintf(stderr, MSG_END_OF_TABLE,
310 request_name, session->peername);
311
312 if(dsaOpsEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label))
313 {
314 fprintf(stderr, "dsaOpsEntry_send_request(%s) failed: %s\n\n",
315 session->peername, error_label);
316 snmp_session_close(session, error_label);
317 snmp_session_num--;
318 }
319 }
320 else
321 {
322 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
323 request_name, session->peername, error_label);
324 trace_snmp_pdu(response);
325
326 snmp_session_close(session, error_label);
327 snmp_session_num--;
328 }
329 }
330 else
331 {
332 mtaGroupAssociationEntry_print(mtaGroupAssociationEntry);
333 if(mtaGroupAssociationEntry_send_request(session, GETNEXT_REQ_MSG, mtaGroupAssociationEntry->applIndex, mtaGroupAssociationEntry->mtaGroupIndex, mtaGroupAssociationEntry->mtaGroupAssociationIndex, error_label))
334 {
335 fprintf(stderr, "mtaGroupAssociationEntry_send_request(%s) failed: %s\n\n",
336 session->peername, error_label);
337 snmp_session_close(session, error_label);
338 snmp_session_num--;
339 }
340 mtaGroupAssociationEntry_free(mtaGroupAssociationEntry);
341 }
342
343 break;
344
345
346 case DSA_OPS_ENTRY_REQ:
347 dsaOpsEntry = dsaOpsEntry_process_response(session, response, error_label);
348 if(dsaOpsEntry == NULL)
349 {
350 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
351 {
352 fprintf(stderr, MSG_END_OF_TABLE,
353 request_name, session->peername);
354
355 if(dsaEntriesEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label))
356 {
357 fprintf(stderr, "dsaEntriesEntry_send_request(%s) failed: %s\n\n",
358 session->peername, error_label);
359 snmp_session_close(session, error_label);
360 snmp_session_num--;
361 }
362 }
363 else
364 {
365 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
366 request_name, session->peername, error_label);
367 trace_snmp_pdu(response);
368
369 snmp_session_close(session, error_label);
370 snmp_session_num--;
371 }
372 }
373 else
374 {
375 dsaOpsEntry_print(dsaOpsEntry);
376 if(dsaOpsEntry_send_request(session, GETNEXT_REQ_MSG, dsaOpsEntry->applIndex, error_label))
377 {
378 fprintf(stderr, "dsaOpsEntry_send_request(%s) failed: %s\n\n",
379 session->peername, error_label);
380 snmp_session_close(session, error_label);
381 snmp_session_num--;
382 }
383 dsaOpsEntry_free(dsaOpsEntry);
384 }
385
386 break;
387
388
389 case DSA_ENTRIES_ENTRY_REQ:
390 dsaEntriesEntry = dsaEntriesEntry_process_response(session, response, error_label);
391 if(dsaEntriesEntry == NULL)
392 {
393 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
394 {
395 fprintf(stderr, MSG_END_OF_TABLE,
396 request_name, session->peername);
397
398 if(dsaIntEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, error_label))
399 {
400 fprintf(stderr, "dsaIntEntry_send_request(%s) failed: %s\n\n",
401 session->peername, error_label);
402 snmp_session_close(session, error_label);
403 snmp_session_num--;
404 }
405 }
406 else
407 {
408 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
409 request_name, session->peername, error_label);
410 trace_snmp_pdu(response);
411
412 snmp_session_close(session, error_label);
413 snmp_session_num--;
414 }
415 }
416 else
417 {
418 dsaEntriesEntry_print(dsaEntriesEntry);
419 if(dsaEntriesEntry_send_request(session, GETNEXT_REQ_MSG, dsaEntriesEntry->applIndex, error_label))
420 {
421 fprintf(stderr, "dsaEntriesEntry_send_request(%s) failed: %s\n\n",
422 session->peername, error_label);
423 snmp_session_close(session, error_label);
424 snmp_session_num--;
425 }
426 dsaEntriesEntry_free(dsaEntriesEntry);
427 }
428
429 break;
430
431
432 case DSA_INT_ENTRY_REQ:
433 dsaIntEntry = dsaIntEntry_process_response(session, response, error_label);
434 if(dsaIntEntry == NULL)
435 {
436 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
437 {
438 fprintf(stderr, MSG_END_OF_TABLE,
439 request_name, session->peername);
440
441 if(x4msMtaEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label))
442 {
443 fprintf(stderr, "x4msMtaEntry_send_request(%s) failed: %s\n\n",
444 session->peername, error_label);
445 snmp_session_close(session, error_label);
446 snmp_session_num--;
447 }
448 }
449 else
450 {
451 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
452 request_name, session->peername, error_label);
453 trace_snmp_pdu(response);
454
455 snmp_session_close(session, error_label);
456 snmp_session_num--;
457 }
458 }
459 else
460 {
461 dsaIntEntry_print(dsaIntEntry);
462 if(dsaIntEntry_send_request(session, GETNEXT_REQ_MSG, dsaIntEntry->applIndex, dsaIntEntry->dsaIntIndex, error_label))
463 {
464 fprintf(stderr, "dsaIntEntry_send_request(%s) failed: %s\n\n",
465 session->peername, error_label);
466 snmp_session_close(session, error_label);
467 snmp_session_num--;
468 }
469 dsaIntEntry_free(dsaIntEntry);
470 }
471
472 break;
473
474
475 case X4MS_MTA_ENTRY_REQ:
476 x4msMtaEntry = x4msMtaEntry_process_response(session, response, error_label);
477 if(x4msMtaEntry == NULL)
478 {
479 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
480 {
481 fprintf(stderr, MSG_END_OF_TABLE,
482 request_name, session->peername);
483
484 if(x4msUserEntryPart1_send_request(session, GETNEXT_REQ_MSG, -1, error_label))
485 {
486 fprintf(stderr, "x4msUserEntryPart1_send_request(%s) failed: %s\n\n",
487 session->peername, error_label);
488 snmp_session_close(session, error_label);
489 snmp_session_num--;
490 }
491 }
492 else
493 {
494 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
495 request_name, session->peername, error_label);
496 trace_snmp_pdu(response);
497
498 snmp_session_close(session, error_label);
499 snmp_session_num--;
500 }
501 }
502 else
503 {
504 x4msMtaEntry_print(x4msMtaEntry);
505 if(x4msMtaEntry_send_request(session, GETNEXT_REQ_MSG, x4msMtaEntry->x4msMtaIndex, error_label))
506 {
507 fprintf(stderr, "x4msMtaEntry_send_request(%s) failed: %s\n\n",
508 session->peername, error_label);
509 snmp_session_close(session, error_label);
510 snmp_session_num--;
511 }
512 x4msMtaEntry_free(x4msMtaEntry);
513 }
514
515 break;
516
517
518 case X4MS_USER_ENTRY_PART1_REQ:
519 x4msUserEntryPart1 = x4msUserEntryPart1_process_response(session, response, error_label);
520 if(x4msUserEntryPart1 == NULL)
521 {
522 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
523 {
524 fprintf(stderr, MSG_END_OF_TABLE,
525 request_name, session->peername);
526
527 if(x4msUserAssociationEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, error_label))
528 {
529 fprintf(stderr, "x4msUserAssociationEntry_send_request(%s) failed: %s\n\n",
530 session->peername, error_label);
531 snmp_session_close(session, error_label);
532 snmp_session_num--;
533 }
534 }
535 else
536 {
537 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
538 request_name, session->peername, error_label);
539 trace_snmp_pdu(response);
540
541 snmp_session_close(session, error_label);
542 snmp_session_num--;
543 }
544 }
545 else
546 {
547 x4msUserEntryPart1_print(x4msUserEntryPart1);
548
549 if(x4msUserEntryPart2_send_request(session, GET_REQ_MSG, x4msUserEntryPart1->x4msUserIndex, error_label))
550 {
551 fprintf(stderr, "x4msUserEntryPart2_send_request(%s) failed: %s\n\n",
552 session->peername, error_label);
553 snmp_session_close(session, error_label);
554 snmp_session_num--;
555 }
556
557 if(x4msUserEntryPart1_send_request(session, GETNEXT_REQ_MSG, x4msUserEntryPart1->x4msUserIndex, error_label))
558 {
559 fprintf(stderr, "x4msUserEntryPart1_send_request(%s) failed: %s\n\n",
560 session->peername, error_label);
561 snmp_session_close(session, error_label);
562 snmp_session_num--;
563 }
564
565 x4msUserEntryPart1_free(x4msUserEntryPart1);
566 }
567
568 break;
569
570
571 case X4MS_USER_ENTRY_PART2_REQ:
572 x4msUserEntryPart2 = x4msUserEntryPart2_process_response(session, response, error_label);
573 if(x4msUserEntryPart2 == NULL)
574 {
575 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
576 request_name, session->peername, error_label);
577 trace_snmp_pdu(response);
578
579 snmp_session_close(session, error_label);
580 snmp_session_num--;
581 }
582 else
583 {
584 x4msUserEntryPart2_print(x4msUserEntryPart2);
585 x4msUserEntryPart2_free(x4msUserEntryPart2);
586 }
587
588 break;
589
590
591 case X4MS_USER_ASSOCIATION_ENTRY_REQ:
592 x4msUserAssociationEntry = x4msUserAssociationEntry_process_response(session, response, error_label);
593 if(x4msUserAssociationEntry == NULL)
594 {
595 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
596 {
597 fprintf(stderr, MSG_END_OF_TABLE,
598 request_name, session->peername);
599
600 if(x4grpEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label))
601 {
602 fprintf(stderr, "x4grpEntry_send_request(%s) failed: %s\n\n",
603 session->peername, error_label);
604 snmp_session_close(session, error_label);
605 snmp_session_num--;
606 }
607 }
608 else
609 {
610 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
611 request_name, session->peername, error_label);
612 trace_snmp_pdu(response);
613
614 snmp_session_close(session, error_label);
615 snmp_session_num--;
616 }
617 }
618 else
619 {
620 x4msUserAssociationEntry_print(x4msUserAssociationEntry);
621 if(x4msUserAssociationEntry_send_request(session, GETNEXT_REQ_MSG, x4msUserAssociationEntry->x4msUserIndex, x4msUserAssociationEntry->x4msUserAssociationIndex, error_label))
622 {
623 fprintf(stderr, "x4msUserAssociationEntry_send_request(%s) failed: %s\n\n",
624 session->peername, error_label);
625 snmp_session_close(session, error_label);
626 snmp_session_num--;
627 }
628 x4msUserAssociationEntry_free(x4msUserAssociationEntry);
629 }
630
631 break;
632
633 case X4GRP_ENTRY_REQ:
634 x4grpEntry = x4grpEntry_process_response(session, response, error_label);
635 if(x4grpEntry == NULL)
636 {
637 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
638 {
639 fprintf(stderr, MSG_END_OF_TABLE,
640 request_name, session->peername);
641
642 if(x4grpMappingEntry_send_request(session, GETNEXT_REQ_MSG, -1, -1, -1, error_label))
643 {
644 fprintf(stderr, "x4grpMappingEntry_send_request(%s) failed: %s\n\n",
645 session->peername, error_label);
646 snmp_session_close(session, error_label);
647 snmp_session_num--;
648 }
649 }
650 else
651 {
652 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
653 request_name, session->peername, error_label);
654 trace_snmp_pdu(response);
655
656 snmp_session_close(session, error_label);
657 snmp_session_num--;
658 }
659 }
660 else
661 {
662 x4grpEntry_print(x4grpEntry);
663 if(x4grpEntry_send_request(session, GETNEXT_REQ_MSG, x4grpEntry->x4grpIndex, error_label))
664 {
665 fprintf(stderr, "x4grpEntry_send_request(%s) failed: %s\n\n",
666 session->peername, error_label);
667 snmp_session_close(session, error_label);
668 snmp_session_num--;
669 }
670 x4grpEntry_free(x4grpEntry);
671 }
672
673 break;
674
675
676 case X4GRP_MAPPING_ENTRY_REQ:
677 x4grpMappingEntry = x4grpMappingEntry_process_response(session, response, error_label);
678 if(x4grpMappingEntry == NULL)
679 {
680 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
681 {
682 fprintf(stderr, MSG_END_OF_TABLE,
683 request_name, session->peername);
684
685 if(x5dsaReferenceEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label))
686 {
687 fprintf(stderr, "x5dsaReferenceEntry_send_request(%s) failed: %s\n\n",
688 session->peername, error_label);
689 snmp_session_close(session, error_label);
690 snmp_session_num--;
691 }
692 }
693 else
694 {
695 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
696 request_name, session->peername, error_label);
697 trace_snmp_pdu(response);
698
699 snmp_session_close(session, error_label);
700 snmp_session_num--;
701 }
702 }
703 else
704 {
705 x4grpMappingEntry_print(x4grpMappingEntry);
706 if(x4grpMappingEntry_send_request(session, GETNEXT_REQ_MSG, x4grpMappingEntry->x4grpIndex, x4grpMappingEntry->x4grpMappingMSIndex, x4grpMappingEntry->x4grpMappingMTAIndex, error_label))
707 {
708 fprintf(stderr, "x4grpMappingEntry_send_request(%s) failed: %s\n\n",
709 session->peername, error_label);
710 snmp_session_close(session, error_label);
711 snmp_session_num--;
712 }
713 x4grpMappingEntry_free(x4grpMappingEntry);
714 }
715
716 break;
717
718
719 case X5DSA_REFERENCE_ENTRY_REQ:
720 x5dsaReferenceEntry = x5dsaReferenceEntry_process_response(session, response, error_label);
721 if(x5dsaReferenceEntry == NULL)
722 {
723 if(snmp_errno == SNMP_ERR_NOSUCHNAME)
724 {
725 fprintf(stderr, MSG_END_OF_TABLE,
726 request_name, session->peername);
727
728 snmp_session_close(session, error_label);
729 snmp_session_num--;
730 }
731 else
732 {
733 fprintf(stderr, ERR_MSG_REQUEST_FAILED,
734 request_name, session->peername, error_label);
735 trace_snmp_pdu(response);
736
737 snmp_session_close(session, error_label);
738 snmp_session_num--;
739 }
740 }
741 else
742 {
743 x5dsaReferenceEntry_print(x5dsaReferenceEntry);
744 if(x5dsaReferenceEntry_send_request(session, GETNEXT_REQ_MSG, x5dsaReferenceEntry->x5dsaReferenceIndex, error_label))
745 {
746 fprintf(stderr, "x5dsaReferenceEntry_send_request(%s) failed: %s\n\n",
747 session->peername, error_label);
748 snmp_session_close(session, error_label);
749 snmp_session_num--;
750 }
751 x5dsaReferenceEntry_free(x5dsaReferenceEntry);
752 }
753
754 break;
755
756
757 default:
758 fprintf(stderr, "unknown pdu received %d from %s\n\n",
759 predefined_id, session->peername);
760
761 trace_snmp_pdu(response);
762
763 snmp_session_close(session, error_label);
764 snmp_session_num--;
765
766 break;
767 }
768
769 break;
770
771
772 case TIMED_OUT:
773 switch(predefined_id)
774 {
775 case APPL_ENTRY_REQ:
776 case ASSOC_ENTRY_REQ:
777 case MTA_ENTRY_REQ:
778 case MTA_GROUP_ENTRY_REQ:
779 case MTA_GROUP_ASSOCIATION_ENTRY_REQ:
780 case X4MS_MTA_ENTRY_REQ:
781 case X4MS_USER_ENTRY_PART1_REQ:
782 case X4MS_USER_ENTRY_PART2_REQ:
783 case X4MS_USER_ASSOCIATION_ENTRY_REQ:
784 case X4GRP_ENTRY_REQ:
785 case X4GRP_MAPPING_ENTRY_REQ:
786 case X5DSA_REFERENCE_ENTRY_REQ:
787 fprintf(stderr, "the request %s on %s TIMED OUT\n\n",
788 request_name, session->peername);
789 break;
790
791 default:
792 fprintf(stderr, "an unknown request %d on %s TIMED OUT\n\n",
793 predefined_id, session->peername);
794 break;
795 }
796
797 snmp_session_close(session, error_label);
798 snmp_session_num--;
799
800 break;
801 }
802
803 if(snmp_session_num == 0)
804 {
805 exit(0);
806 }
807 }
808
809
810 /**************************************************************/
811
main(int argc,char ** argv)812 main(int argc, char **argv)
813 {
814 int numfds;
815 fd_set fdset;
816 int count;
817 struct timeval timeout;
818 char targets[1000];
819 char target[1000];
820 char c;
821 char *ptr;
822 int i = 0;
823 Target *t;
824
825
826 while((c = getopt(argc, argv, "t:v"))!= -1)
827 {
828 switch(c)
829 {
830 case 't':
831 strcpy(targets, optarg);
832 break;
833 case 'v':
834 trace_flags = 0xFFFF;
835 }
836 }
837
838
839 i = 0;
840 for(ptr = targets; *ptr; ptr++)
841 {
842 if(isspace(*ptr))
843 {
844 if(i == 0)
845 {
846 continue;
847 }
848 }
849
850 target[i++] = *ptr;
851
852 if( (*(ptr + 1) == '\0') || isspace(*(ptr + 1)) )
853 {
854 target[i] = '\0';
855
856 if(target_add(target, error_label))
857 {
858 fprintf(stderr, "target_add(%s) failed: %s\n\n",
859 target, error_label);
860 }
861
862 i = 0;
863 }
864 }
865
866
867 for(t = first_target; t; t = t->next_target)
868 {
869 SNMP_session *session;
870
871
872 session = snmp_session_open_default(t->name, snmp_callback, NULL, error_label);
873 if(session == NULL)
874 {
875 fprintf(stderr, "snmp_session_open_default(%s) failed: %s\n\n",
876 t->name, error_label);
877 continue;
878 }
879 snmp_session_num++;
880
881 if(applEntry_send_request(session, GETNEXT_REQ_MSG, -1, error_label))
882 {
883 fprintf(stderr, "applEntry_send_request(%s) failed: %s\n\n",
884 session->peername, error_label);
885 snmp_session_close(session, error_label);
886 snmp_session_num--;
887 }
888 }
889
890
891 if(snmp_session_num == 0)
892 {
893 exit(0);
894 }
895
896
897 while(1)
898 {
899 numfds = 0;
900 FD_ZERO(&fdset);
901
902 timeout.tv_sec = 10;
903 timeout.tv_usec = 0;
904
905 snmp_session_select_info(&numfds, &fdset, &timeout);
906
907 count = select(numfds, &fdset, 0, 0, &timeout);
908 if(count > 0)
909 {
910 snmp_session_read(&fdset);
911 }
912 else
913 {
914 switch(count)
915 {
916 case 0:
917 snmp_session_timeout();
918 break;
919
920 case -1:
921 if(errno == EINTR)
922 {
923 continue;
924 }
925 else
926 {
927 fprintf(stderr, "select() failed %s\n",
928 errno_string());
929 }
930 }
931 }
932 }
933 }
934
935
936