Mercurial > illumos > onarm
comparison usr/src/cmd/agents/snmp/agent/pagent.c @ 0:c9caec207d52 b86
Initial porting based on b86
author | Koji Uno <koji.uno@sun.com> |
---|---|
date | Tue, 02 Jun 2009 18:56:50 +0900 |
parents | |
children | 1a15d5aaf794 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c9caec207d52 |
---|---|
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 * Copyright 1996 Sun Microsystems, Inc. All Rights Reserved. | |
23 * Use is subject to license terms. | |
24 */ | |
25 | |
26 #pragma ident "@(#)pagent.c 1.3 05/06/12 SMI" | |
27 | |
28 #include <stdlib.h> | |
29 #include <stdio.h> | |
30 #include <sys/types.h> | |
31 #include <sys/socket.h> | |
32 #include <netinet/in.h> | |
33 #include <arpa/inet.h> | |
34 | |
35 #include "impl.h" | |
36 #include "error.h" | |
37 #include "trace.h" | |
38 #include "pdu.h" | |
39 | |
40 #include "pagent.h" | |
41 #include "subtree.h" | |
42 | |
43 | |
44 /***** STATIC VARIABLES *****/ | |
45 | |
46 /* the agent list */ | |
47 Agent *first_agent = NULL; | |
48 | |
49 | |
50 /***** STATIC FUNCTIONS *****/ | |
51 | |
52 static void agent_free(Agent *ap); | |
53 | |
54 | |
55 /****************************************************************/ | |
56 | |
57 void trace_agents() | |
58 { | |
59 Agent *ap; | |
60 | |
61 | |
62 trace("AGENTS:\n"); | |
63 for(ap = first_agent; ap; ap = ap->next_agent) | |
64 { | |
65 trace("\t%-30s %-30s %8d\n", | |
66 ap->name, | |
67 address_string(&(ap->address)), | |
68 ap->timeout); | |
69 } | |
70 trace("\n"); | |
71 } | |
72 | |
73 | |
74 /****************************************************************/ | |
75 | |
76 /* We must invoke subtree_list_delete() before invoking */ | |
77 /* this function because the first_agent_subtree member */ | |
78 /* of the agent structures should be NULL */ | |
79 | |
80 void agent_list_delete() | |
81 { | |
82 Agent *ap = first_agent; | |
83 Agent *next; | |
84 | |
85 | |
86 while(ap) | |
87 { | |
88 next = ap->next_agent; | |
89 | |
90 agent_free(ap); | |
91 | |
92 ap = next; | |
93 } | |
94 | |
95 first_agent = NULL; | |
96 | |
97 return; | |
98 } | |
99 | |
100 | |
101 /****************************************************************/ | |
102 | |
103 /* The fisrt_agent_subtree member of the agent */ | |
104 /* structure should be NULL */ | |
105 | |
106 static void agent_free(Agent *ap) | |
107 { | |
108 if(ap == NULL) | |
109 { | |
110 return; | |
111 } | |
112 | |
113 if(ap->first_agent_subtree) | |
114 { | |
115 error("BUG: agent_free(): first_agent_subtree not NULL"); | |
116 } | |
117 | |
118 free(ap->name); | |
119 free(ap); | |
120 | |
121 return; | |
122 } | |
123 | |
124 /****************************************************************/ | |
125 | |
126 /* agent_find() is used to check if we have not */ | |
127 /* two SNMP agents registered on the same UDP port */ | |
128 | |
129 Agent *agent_find(Address *address) | |
130 { | |
131 Agent *ap; | |
132 | |
133 | |
134 for(ap = first_agent; ap; ap = ap->next_agent) | |
135 { | |
136 if(ap->address.sin_port == address->sin_port) | |
137 { | |
138 return ap; | |
139 } | |
140 } | |
141 | |
142 return NULL; | |
143 } | |
144 | |
145 | |
146 /****************************************************************/ | |
147 |