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 #include <sys/types.h>
29 #include <netinet/in.h>
30
31 #include "impl.h"
32 #include "asn1.h"
33 #include "error.h"
34 #include "snmp.h"
35 #include "trap.h"
36 #include "pdu.h"
37 #include "node.h"
38
39 #include "snmpdx_stub.h"
40
41
42
43 /***** agentEntry ********************************/
44
get_agentEntry(int search_type,AgentEntry_t ** agentEntry_data,IndexType * index)45 extern int get_agentEntry(int search_type, AgentEntry_t **agentEntry_data, IndexType *index)
46 {
47
48 int res;
49
50 *agentEntry_data = (AgentEntry_t*)calloc(1,sizeof(AgentEntry_t));
51 if(agentEntry_data == NULL) return SNMP_ERR_GENERR;
52
53 res = get_agentID(
54 search_type,
55 &((*agentEntry_data)->agentID),
56 index);
57 if(res != SNMP_ERR_NOERROR) return res;
58
59 res = get_agentStatus(
60 search_type,
61 &((*agentEntry_data)->agentStatus),
62 index);
63 if(res != SNMP_ERR_NOERROR) return res;
64
65 res = get_agentTimeOut(
66 search_type,
67 &((*agentEntry_data)->agentTimeOut),
68 index);
69 if(res != SNMP_ERR_NOERROR) return res;
70
71 res = get_agentPortNumber(
72 search_type,
73 &((*agentEntry_data)->agentPortNumber),
74 index);
75 if(res != SNMP_ERR_NOERROR) return res;
76
77 res = get_agentPersonalFile(
78 search_type,
79 &((*agentEntry_data)->agentPersonalFile),
80 index);
81 if(res != SNMP_ERR_NOERROR) return res;
82
83 res = get_agentConfigFile(
84 search_type,
85 &((*agentEntry_data)->agentConfigFile),
86 index);
87 if(res != SNMP_ERR_NOERROR) return res;
88
89 res = get_agentExecutable(
90 search_type,
91 &((*agentEntry_data)->agentExecutable),
92 index);
93 if(res != SNMP_ERR_NOERROR) return res;
94
95 res = get_agentVersionNum(
96 search_type,
97 &((*agentEntry_data)->agentVersionNum),
98 index);
99 if(res != SNMP_ERR_NOERROR) return res;
100
101 res = get_agentProcessID(
102 search_type,
103 &((*agentEntry_data)->agentProcessID),
104 index);
105 if(res != SNMP_ERR_NOERROR) return res;
106
107 res = get_agentName(
108 search_type,
109 &((*agentEntry_data)->agentName),
110 index);
111 if(res != SNMP_ERR_NOERROR) return res;
112
113 res = get_agentSystemUpTime(
114 search_type,
115 &((*agentEntry_data)->agentSystemUpTime),
116 index);
117 if(res != SNMP_ERR_NOERROR) return res;
118
119 res = get_agentWatchDogTime(
120 search_type,
121 &((*agentEntry_data)->agentWatchDogTime),
122 index);
123 if(res != SNMP_ERR_NOERROR) return res;
124
125 return res;
126 }
127
128
free_agentEntry(AgentEntry_t * agentEntry)129 void free_agentEntry(AgentEntry_t *agentEntry)
130 {
131 free_agentPersonalFile(&(agentEntry->agentPersonalFile));
132 free_agentConfigFile(&(agentEntry->agentConfigFile));
133 free_agentExecutable(&(agentEntry->agentExecutable));
134 free_agentVersionNum(&(agentEntry->agentVersionNum));
135 free_agentName(&(agentEntry->agentName));
136 }
137
get_agentID(int search_type,Integer * agentID,IndexType * index)138 int get_agentID(int search_type, Integer *agentID, IndexType *index)
139 {
140 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
141 /* this function should modify the index argument to the */
142 /* appropriate value */
143 switch(search_type)
144 {
145 case FIRST_ENTRY:
146 if(index->type == INTEGER){
147
148 /* assume 1 is the first index */
149
150 index->value[0] = 1;
151 index->len = 1;
152 }else{
153
154 /* index type will be array of integer */
155 /* assume that there are two index */
156
157 index->value[0] = 1;
158 index->value[1]= 1;
159 index->len = 2;
160 }
161 break;
162
163 case NEXT_ENTRY:
164 if(index->type == INTEGER){
165 index->value[0]++;
166 }else{
167
168 /* index type will be array of integer */
169 /* assume that there are two index */
170
171 index->value[index->len-1]++;
172 }
173 break;
174
175 case EXACT_ENTRY:
176 break;
177 }
178
179 /*assume that the mib variable has a value of 1 */
180
181 *agentID = 1;
182 return SNMP_ERR_NOERROR;
183 }
184
get_agentStatus(int search_type,Integer * agentStatus,IndexType * index)185 int get_agentStatus(int search_type, Integer *agentStatus, IndexType *index)
186 {
187 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
188 /* this function should modify the index argument to the */
189 /* appropriate value */
190 switch(search_type)
191 {
192 case FIRST_ENTRY:
193 if(index->type == INTEGER){
194
195 /* assume 1 is the first index */
196
197 index->value[0] = 1;
198 index->len = 1;
199 }else{
200
201 /* index type will be array of integer */
202 /* assume that there are two index */
203
204 index->value[0] = 1;
205 index->value[1]= 1;
206 index->len = 2;
207 }
208 break;
209
210 case NEXT_ENTRY:
211 if(index->type == INTEGER){
212 index->value[0]++;
213 }else{
214
215 /* index type will be array of integer */
216 /* assume that there are two index */
217
218 index->value[index->len-1]++;
219 }
220 break;
221
222 case EXACT_ENTRY:
223 break;
224 }
225
226 /*assume that the mib variable has a value of 1 */
227
228 *agentStatus = 1;
229 return SNMP_ERR_NOERROR;
230 }
231
set_agentStatus(int pass,IndexType index,Integer * agentStatus)232 int set_agentStatus(int pass, IndexType index, Integer *agentStatus)
233 {
234 switch(pass)
235 {
236 case FIRST_PASS:
237
238 /* check the existence of the element which */
239 /* corresponding to the given index and */
240 /* check the validity fo the input value */
241 /* if not valid or not exist, */
242
243 return SNMP_ERR_GENERR;
244
245 case SECOND_PASS:
246
247 /* change the following coding, such that */
248 /* the input value will be stored in the */
249 /* corresponding mib variable of the given */
250 /* index */
251 printf("The new value is %d\n",agentStatus);
252 return SNMP_ERR_NOERROR;
253 }
254 }
255
256
get_agentTimeOut(int search_type,Integer * agentTimeOut,IndexType * index)257 int get_agentTimeOut(int search_type, Integer *agentTimeOut, IndexType *index)
258 {
259 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
260 /* this function should modify the index argument to the */
261 /* appropriate value */
262 switch(search_type)
263 {
264 case FIRST_ENTRY:
265 if(index->type == INTEGER){
266
267 /* assume 1 is the first index */
268
269 index->value[0] = 1;
270 index->len = 1;
271 }else{
272
273 /* index type will be array of integer */
274 /* assume that there are two index */
275
276 index->value[0] = 1;
277 index->value[1]= 1;
278 index->len = 2;
279 }
280 break;
281
282 case NEXT_ENTRY:
283 if(index->type == INTEGER){
284 index->value[0]++;
285 }else{
286
287 /* index type will be array of integer */
288 /* assume that there are two index */
289
290 index->value[index->len-1]++;
291 }
292 break;
293
294 case EXACT_ENTRY:
295 break;
296 }
297
298 /*assume that the mib variable has a value of 1 */
299
300 *agentTimeOut = 1;
301 return SNMP_ERR_NOERROR;
302 }
303
set_agentTimeOut(int pass,IndexType index,Integer * agentTimeOut)304 int set_agentTimeOut(int pass, IndexType index, Integer *agentTimeOut)
305 {
306 switch(pass)
307 {
308 case FIRST_PASS:
309
310 /* check the existence of the element which */
311 /* corresponding to the given index and */
312 /* check the validity fo the input value */
313 /* if not valid or not exist, */
314
315 return SNMP_ERR_GENERR;
316
317 case SECOND_PASS:
318
319 /* change the following coding, such that */
320 /* the input value will be stored in the */
321 /* corresponding mib variable of the given */
322 /* index */
323 printf("The new value is %d\n",agentTimeOut);
324 return SNMP_ERR_NOERROR;
325 }
326 }
327
328
get_agentPortNumber(int search_type,Integer * agentPortNumber,IndexType * index)329 int get_agentPortNumber(int search_type, Integer *agentPortNumber, IndexType *index)
330 {
331 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
332 /* this function should modify the index argument to the */
333 /* appropriate value */
334 switch(search_type)
335 {
336 case FIRST_ENTRY:
337 if(index->type == INTEGER){
338
339 /* assume 1 is the first index */
340
341 index->value[0] = 1;
342 index->len = 1;
343 }else{
344
345 /* index type will be array of integer */
346 /* assume that there are two index */
347
348 index->value[0] = 1;
349 index->value[1]= 1;
350 index->len = 2;
351 }
352 break;
353
354 case NEXT_ENTRY:
355 if(index->type == INTEGER){
356 index->value[0]++;
357 }else{
358
359 /* index type will be array of integer */
360 /* assume that there are two index */
361
362 index->value[index->len-1]++;
363 }
364 break;
365
366 case EXACT_ENTRY:
367 break;
368 }
369
370 /*assume that the mib variable has a value of 1 */
371
372 *agentPortNumber = 1;
373 return SNMP_ERR_NOERROR;
374 }
375
set_agentPortNumber(int pass,IndexType index,Integer * agentPortNumber)376 int set_agentPortNumber(int pass, IndexType index, Integer *agentPortNumber)
377 {
378 switch(pass)
379 {
380 case FIRST_PASS:
381
382 /* check the existence of the element which */
383 /* corresponding to the given index and */
384 /* check the validity fo the input value */
385 /* if not valid or not exist, */
386
387 return SNMP_ERR_GENERR;
388
389 case SECOND_PASS:
390
391 /* change the following coding, such that */
392 /* the input value will be stored in the */
393 /* corresponding mib variable of the given */
394 /* index */
395 printf("The new value is %d\n",agentPortNumber);
396 return SNMP_ERR_NOERROR;
397 }
398 }
399
400
get_agentPersonalFile(int search_type,String * agentPersonalFile,IndexType * index)401 int get_agentPersonalFile(int search_type, String *agentPersonalFile, IndexType *index)
402 {
403 u_char *str;
404 int len;
405
406 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
407 /* this function should modify the index argument to the */
408 /* appropriate value */
409 switch(search_type)
410 {
411 case FIRST_ENTRY:
412 if(index->type == INTEGER){
413
414 /* assume 1 is the first index */
415
416 index->value[0] = 1;
417 index->len = 1;
418 }else{
419
420 /* index type will be array of integer */
421 /* assume that there are two index */
422
423 index->value[0] = 1;
424 index->value[1]= 1;
425 index->len = 2;
426 }
427 break;
428
429 case NEXT_ENTRY:
430 if(index->type == INTEGER){
431 index->value[0]++;
432 }else{
433
434 /* index type will be array of integer */
435 /* assume that there are two index */
436
437 index->value[index->len-1]++;
438 }
439 break;
440
441 case EXACT_ENTRY:
442 break;
443 }
444
445 /* It is required to allocate memory to the pointers */
446 /* inside the input argument */
447 /* Here, we assume that "hello" is the value of the mib variable */
448 /* please change it to the real one */
449
450 len = strlen("hello");
451 str = (u_char*)calloc(len,sizeof(char));
452 if(str==NULL){
453 return SNMP_ERR_GENERR;
454 }
455 memcpy(str,"hello",len);
456
457 /*fill in the contents of the argument */
458
459 agentPersonalFile->chars = str;
460 agentPersonalFile->len = len;
461 return SNMP_ERR_NOERROR;
462 }
463
set_agentPersonalFile(int pass,IndexType index,String * agentPersonalFile)464 int set_agentPersonalFile(int pass, IndexType index, String *agentPersonalFile)
465 {
466 char buf[100];
467
468 switch(pass)
469 {
470 case FIRST_PASS:
471
472 /* check the existence of the element which */
473 /* corresponding to the given index and */
474 /* check the validity fo the input value */
475 /* if not valid or not exist, */
476
477 return SNMP_ERR_GENERR;
478
479 case SECOND_PASS:
480
481 /* change the following coding, such that */
482 /* the input value will be stored in the */
483 /* corresponding mib variable of the given */
484 /* index */
485 memcpy(buf,agentPersonalFile->chars,agentPersonalFile->len);
486 buf[agentPersonalFile->len+1] = '\0';
487 printf("The new value is %s\n",buf);
488 return SNMP_ERR_NOERROR;
489 }
490 }
491
492
free_agentPersonalFile(String * agentPersonalFile)493 void free_agentPersonalFile(String *agentPersonalFile)
494 {
495 if(agentPersonalFile->chars!=NULL && agentPersonalFile->len !=0)
496 {
497 free(agentPersonalFile->chars);
498 agentPersonalFile->len = 0;
499 }
500 }
501
get_agentConfigFile(int search_type,String * agentConfigFile,IndexType * index)502 int get_agentConfigFile(int search_type, String *agentConfigFile, IndexType *index)
503 {
504 u_char *str;
505 int len;
506
507 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
508 /* this function should modify the index argument to the */
509 /* appropriate value */
510 switch(search_type)
511 {
512 case FIRST_ENTRY:
513 if(index->type == INTEGER){
514
515 /* assume 1 is the first index */
516
517 index->value[0] = 1;
518 index->len = 1;
519 }else{
520
521 /* index type will be array of integer */
522 /* assume that there are two index */
523
524 index->value[0] = 1;
525 index->value[1]= 1;
526 index->len = 2;
527 }
528 break;
529
530 case NEXT_ENTRY:
531 if(index->type == INTEGER){
532 index->value[0]++;
533 }else{
534
535 /* index type will be array of integer */
536 /* assume that there are two index */
537
538 index->value[index->len-1]++;
539 }
540 break;
541
542 case EXACT_ENTRY:
543 break;
544 }
545
546 /* It is required to allocate memory to the pointers */
547 /* inside the input argument */
548 /* Here, we assume that "hello" is the value of the mib variable */
549 /* please change it to the real one */
550
551 len = strlen("hello");
552 str = (u_char*)calloc(len,sizeof(char));
553 if(str==NULL){
554 return SNMP_ERR_GENERR;
555 }
556 memcpy(str,"hello",len);
557
558 /*fill in the contents of the argument */
559
560 agentConfigFile->chars = str;
561 agentConfigFile->len = len;
562 return SNMP_ERR_NOERROR;
563 }
564
set_agentConfigFile(int pass,IndexType index,String * agentConfigFile)565 int set_agentConfigFile(int pass, IndexType index, String *agentConfigFile)
566 {
567 char buf[100];
568
569 switch(pass)
570 {
571 case FIRST_PASS:
572
573 /* check the existence of the element which */
574 /* corresponding to the given index and */
575 /* check the validity fo the input value */
576 /* if not valid or not exist, */
577
578 return SNMP_ERR_GENERR;
579
580 case SECOND_PASS:
581
582 /* change the following coding, such that */
583 /* the input value will be stored in the */
584 /* corresponding mib variable of the given */
585 /* index */
586 memcpy(buf,agentConfigFile->chars,agentConfigFile->len);
587 buf[agentConfigFile->len+1] = '\0';
588 printf("The new value is %s\n",buf);
589 return SNMP_ERR_NOERROR;
590 }
591 }
592
593
free_agentConfigFile(String * agentConfigFile)594 void free_agentConfigFile(String *agentConfigFile)
595 {
596 if(agentConfigFile->chars!=NULL && agentConfigFile->len !=0)
597 {
598 free(agentConfigFile->chars);
599 agentConfigFile->len = 0;
600 }
601 }
602
get_agentExecutable(int search_type,String * agentExecutable,IndexType * index)603 int get_agentExecutable(int search_type, String *agentExecutable, IndexType *index)
604 {
605 u_char *str;
606 int len;
607
608 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
609 /* this function should modify the index argument to the */
610 /* appropriate value */
611 switch(search_type)
612 {
613 case FIRST_ENTRY:
614 if(index->type == INTEGER){
615
616 /* assume 1 is the first index */
617
618 index->value[0] = 1;
619 index->len = 1;
620 }else{
621
622 /* index type will be array of integer */
623 /* assume that there are two index */
624
625 index->value[0] = 1;
626 index->value[1]= 1;
627 index->len = 2;
628 }
629 break;
630
631 case NEXT_ENTRY:
632 if(index->type == INTEGER){
633 index->value[0]++;
634 }else{
635
636 /* index type will be array of integer */
637 /* assume that there are two index */
638
639 index->value[index->len-1]++;
640 }
641 break;
642
643 case EXACT_ENTRY:
644 break;
645 }
646
647 /* It is required to allocate memory to the pointers */
648 /* inside the input argument */
649 /* Here, we assume that "hello" is the value of the mib variable */
650 /* please change it to the real one */
651
652 len = strlen("hello");
653 str = (u_char*)calloc(len,sizeof(char));
654 if(str==NULL){
655 return SNMP_ERR_GENERR;
656 }
657 memcpy(str,"hello",len);
658
659 /*fill in the contents of the argument */
660
661 agentExecutable->chars = str;
662 agentExecutable->len = len;
663 return SNMP_ERR_NOERROR;
664 }
665
set_agentExecutable(int pass,IndexType index,String * agentExecutable)666 int set_agentExecutable(int pass, IndexType index, String *agentExecutable)
667 {
668 char buf[100];
669
670 switch(pass)
671 {
672 case FIRST_PASS:
673
674 /* check the existence of the element which */
675 /* corresponding to the given index and */
676 /* check the validity fo the input value */
677 /* if not valid or not exist, */
678
679 return SNMP_ERR_GENERR;
680
681 case SECOND_PASS:
682
683 /* change the following coding, such that */
684 /* the input value will be stored in the */
685 /* corresponding mib variable of the given */
686 /* index */
687 memcpy(buf,agentExecutable->chars,agentExecutable->len);
688 buf[agentExecutable->len+1] = '\0';
689 printf("The new value is %s\n",buf);
690 return SNMP_ERR_NOERROR;
691 }
692 }
693
694
free_agentExecutable(String * agentExecutable)695 void free_agentExecutable(String *agentExecutable)
696 {
697 if(agentExecutable->chars!=NULL && agentExecutable->len !=0)
698 {
699 free(agentExecutable->chars);
700 agentExecutable->len = 0;
701 }
702 }
703
get_agentVersionNum(int search_type,String * agentVersionNum,IndexType * index)704 int get_agentVersionNum(int search_type, String *agentVersionNum, IndexType *index)
705 {
706 u_char *str;
707 int len;
708
709 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
710 /* this function should modify the index argument to the */
711 /* appropriate value */
712 switch(search_type)
713 {
714 case FIRST_ENTRY:
715 if(index->type == INTEGER){
716
717 /* assume 1 is the first index */
718
719 index->value[0] = 1;
720 index->len = 1;
721 }else{
722
723 /* index type will be array of integer */
724 /* assume that there are two index */
725
726 index->value[0] = 1;
727 index->value[1]= 1;
728 index->len = 2;
729 }
730 break;
731
732 case NEXT_ENTRY:
733 if(index->type == INTEGER){
734 index->value[0]++;
735 }else{
736
737 /* index type will be array of integer */
738 /* assume that there are two index */
739
740 index->value[index->len-1]++;
741 }
742 break;
743
744 case EXACT_ENTRY:
745 break;
746 }
747
748 /* It is required to allocate memory to the pointers */
749 /* inside the input argument */
750 /* Here, we assume that "hello" is the value of the mib variable */
751 /* please change it to the real one */
752
753 len = strlen("hello");
754 str = (u_char*)calloc(len,sizeof(char));
755 if(str==NULL){
756 return SNMP_ERR_GENERR;
757 }
758 memcpy(str,"hello",len);
759
760 /*fill in the contents of the argument */
761
762 agentVersionNum->chars = str;
763 agentVersionNum->len = len;
764 return SNMP_ERR_NOERROR;
765 }
766
set_agentVersionNum(int pass,IndexType index,String * agentVersionNum)767 int set_agentVersionNum(int pass, IndexType index, String *agentVersionNum)
768 {
769 char buf[100];
770
771 switch(pass)
772 {
773 case FIRST_PASS:
774
775 /* check the existence of the element which */
776 /* corresponding to the given index and */
777 /* check the validity fo the input value */
778 /* if not valid or not exist, */
779
780 return SNMP_ERR_GENERR;
781
782 case SECOND_PASS:
783
784 /* change the following coding, such that */
785 /* the input value will be stored in the */
786 /* corresponding mib variable of the given */
787 /* index */
788 memcpy(buf,agentVersionNum->chars,agentVersionNum->len);
789 buf[agentVersionNum->len+1] = '\0';
790 printf("The new value is %s\n",buf);
791 return SNMP_ERR_NOERROR;
792 }
793 }
794
795
free_agentVersionNum(String * agentVersionNum)796 void free_agentVersionNum(String *agentVersionNum)
797 {
798 if(agentVersionNum->chars!=NULL && agentVersionNum->len !=0)
799 {
800 free(agentVersionNum->chars);
801 agentVersionNum->len = 0;
802 }
803 }
804
get_agentProcessID(int search_type,Integer * agentProcessID,IndexType * index)805 int get_agentProcessID(int search_type, Integer *agentProcessID, IndexType *index)
806 {
807 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
808 /* this function should modify the index argument to the */
809 /* appropriate value */
810 switch(search_type)
811 {
812 case FIRST_ENTRY:
813 if(index->type == INTEGER){
814
815 /* assume 1 is the first index */
816
817 index->value[0] = 1;
818 index->len = 1;
819 }else{
820
821 /* index type will be array of integer */
822 /* assume that there are two index */
823
824 index->value[0] = 1;
825 index->value[1]= 1;
826 index->len = 2;
827 }
828 break;
829
830 case NEXT_ENTRY:
831 if(index->type == INTEGER){
832 index->value[0]++;
833 }else{
834
835 /* index type will be array of integer */
836 /* assume that there are two index */
837
838 index->value[index->len-1]++;
839 }
840 break;
841
842 case EXACT_ENTRY:
843 break;
844 }
845
846 /*assume that the mib variable has a value of 1 */
847
848 *agentProcessID = 1;
849 return SNMP_ERR_NOERROR;
850 }
851
set_agentProcessID(int pass,IndexType index,Integer * agentProcessID)852 int set_agentProcessID(int pass, IndexType index, Integer *agentProcessID)
853 {
854 switch(pass)
855 {
856 case FIRST_PASS:
857
858 /* check the existence of the element which */
859 /* corresponding to the given index and */
860 /* check the validity fo the input value */
861 /* if not valid or not exist, */
862
863 return SNMP_ERR_GENERR;
864
865 case SECOND_PASS:
866
867 /* change the following coding, such that */
868 /* the input value will be stored in the */
869 /* corresponding mib variable of the given */
870 /* index */
871 printf("The new value is %d\n",agentProcessID);
872 return SNMP_ERR_NOERROR;
873 }
874 }
875
876
get_agentName(int search_type,String * agentName,IndexType * index)877 int get_agentName(int search_type, String *agentName, IndexType *index)
878 {
879 u_char *str;
880 int len;
881
882 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
883 /* this function should modify the index argument to the */
884 /* appropriate value */
885 switch(search_type)
886 {
887 case FIRST_ENTRY:
888 if(index->type == INTEGER){
889
890 /* assume 1 is the first index */
891
892 index->value[0] = 1;
893 index->len = 1;
894 }else{
895
896 /* index type will be array of integer */
897 /* assume that there are two index */
898
899 index->value[0] = 1;
900 index->value[1]= 1;
901 index->len = 2;
902 }
903 break;
904
905 case NEXT_ENTRY:
906 if(index->type == INTEGER){
907 index->value[0]++;
908 }else{
909
910 /* index type will be array of integer */
911 /* assume that there are two index */
912
913 index->value[index->len-1]++;
914 }
915 break;
916
917 case EXACT_ENTRY:
918 break;
919 }
920
921 /* It is required to allocate memory to the pointers */
922 /* inside the input argument */
923 /* Here, we assume that "hello" is the value of the mib variable */
924 /* please change it to the real one */
925
926 len = strlen("hello");
927 str = (u_char*)calloc(len,sizeof(char));
928 if(str==NULL){
929 return SNMP_ERR_GENERR;
930 }
931 memcpy(str,"hello",len);
932
933 /*fill in the contents of the argument */
934
935 agentName->chars = str;
936 agentName->len = len;
937 return SNMP_ERR_NOERROR;
938 }
939
set_agentName(int pass,IndexType index,String * agentName)940 int set_agentName(int pass, IndexType index, String *agentName)
941 {
942 char buf[100];
943
944 switch(pass)
945 {
946 case FIRST_PASS:
947
948 /* check the existence of the element which */
949 /* corresponding to the given index and */
950 /* check the validity fo the input value */
951 /* if not valid or not exist, */
952
953 return SNMP_ERR_GENERR;
954
955 case SECOND_PASS:
956
957 /* change the following coding, such that */
958 /* the input value will be stored in the */
959 /* corresponding mib variable of the given */
960 /* index */
961 memcpy(buf,agentName->chars,agentName->len);
962 buf[agentName->len+1] = '\0';
963 printf("The new value is %s\n",buf);
964 return SNMP_ERR_NOERROR;
965 }
966 }
967
968
free_agentName(String * agentName)969 void free_agentName(String *agentName)
970 {
971 if(agentName->chars!=NULL && agentName->len !=0)
972 {
973 free(agentName->chars);
974 agentName->len = 0;
975 }
976 }
977
get_agentSystemUpTime(int search_type,Integer * agentSystemUpTime,IndexType * index)978 int get_agentSystemUpTime(int search_type, Integer *agentSystemUpTime, IndexType *index)
979 {
980 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
981 /* this function should modify the index argument to the */
982 /* appropriate value */
983 switch(search_type)
984 {
985 case FIRST_ENTRY:
986 if(index->type == INTEGER){
987
988 /* assume 1 is the first index */
989
990 index->value[0] = 1;
991 index->len = 1;
992 }else{
993
994 /* index type will be array of integer */
995 /* assume that there are two index */
996
997 index->value[0] = 1;
998 index->value[1]= 1;
999 index->len = 2;
1000 }
1001 break;
1002
1003 case NEXT_ENTRY:
1004 if(index->type == INTEGER){
1005 index->value[0]++;
1006 }else{
1007
1008 /* index type will be array of integer */
1009 /* assume that there are two index */
1010
1011 index->value[index->len-1]++;
1012 }
1013 break;
1014
1015 case EXACT_ENTRY:
1016 break;
1017 }
1018
1019 /*assume that the mib variable has a value of 1 */
1020
1021 *agentSystemUpTime = 1;
1022 return SNMP_ERR_NOERROR;
1023 }
1024
set_agentSystemUpTime(int pass,IndexType index,Integer * agentSystemUpTime)1025 int set_agentSystemUpTime(int pass, IndexType index, Integer *agentSystemUpTime)
1026 {
1027 switch(pass)
1028 {
1029 case FIRST_PASS:
1030
1031 /* check the existence of the element which */
1032 /* corresponding to the given index and */
1033 /* check the validity fo the input value */
1034 /* if not valid or not exist, */
1035
1036 return SNMP_ERR_GENERR;
1037
1038 case SECOND_PASS:
1039
1040 /* change the following coding, such that */
1041 /* the input value will be stored in the */
1042 /* corresponding mib variable of the given */
1043 /* index */
1044 printf("The new value is %d\n",agentSystemUpTime);
1045 return SNMP_ERR_NOERROR;
1046 }
1047 }
1048
1049
get_agentWatchDogTime(int search_type,Integer * agentWatchDogTime,IndexType * index)1050 int get_agentWatchDogTime(int search_type, Integer *agentWatchDogTime, IndexType *index)
1051 {
1052 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
1053 /* this function should modify the index argument to the */
1054 /* appropriate value */
1055 switch(search_type)
1056 {
1057 case FIRST_ENTRY:
1058 if(index->type == INTEGER){
1059
1060 /* assume 1 is the first index */
1061
1062 index->value[0] = 1;
1063 index->len = 1;
1064 }else{
1065
1066 /* index type will be array of integer */
1067 /* assume that there are two index */
1068
1069 index->value[0] = 1;
1070 index->value[1]= 1;
1071 index->len = 2;
1072 }
1073 break;
1074
1075 case NEXT_ENTRY:
1076 if(index->type == INTEGER){
1077 index->value[0]++;
1078 }else{
1079
1080 /* index type will be array of integer */
1081 /* assume that there are two index */
1082
1083 index->value[index->len-1]++;
1084 }
1085 break;
1086
1087 case EXACT_ENTRY:
1088 break;
1089 }
1090
1091 /*assume that the mib variable has a value of 1 */
1092
1093 *agentWatchDogTime = 1;
1094 return SNMP_ERR_NOERROR;
1095 }
1096
set_agentWatchDogTime(int pass,IndexType index,Integer * agentWatchDogTime)1097 int set_agentWatchDogTime(int pass, IndexType index, Integer *agentWatchDogTime)
1098 {
1099 switch(pass)
1100 {
1101 case FIRST_PASS:
1102
1103 /* check the existence of the element which */
1104 /* corresponding to the given index and */
1105 /* check the validity fo the input value */
1106 /* if not valid or not exist, */
1107
1108 return SNMP_ERR_GENERR;
1109
1110 case SECOND_PASS:
1111
1112 /* change the following coding, such that */
1113 /* the input value will be stored in the */
1114 /* corresponding mib variable of the given */
1115 /* index */
1116 printf("The new value is %d\n",agentWatchDogTime);
1117 return SNMP_ERR_NOERROR;
1118 }
1119 }
1120
1121