420 remove patch (sparse package) support from svr4 pkg
[illumos-gate.git] / usr / src / cmd / agents / snmp / agent / pagent.c
blobe1fd55e248529cb19f165bc42f61a2912fba2aa9
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 * Copyright 1996 Sun Microsystems, Inc. All Rights Reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
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>
35 #include "impl.h"
36 #include "error.h"
37 #include "trace.h"
38 #include "pdu.h"
40 #include "pagent.h"
41 #include "subtree.h"
44 /***** STATIC VARIABLES *****/
46 /* the agent list */
47 Agent *first_agent = NULL;
50 /***** STATIC FUNCTIONS *****/
52 static void agent_free(Agent *ap);
55 /****************************************************************/
57 void trace_agents()
59 Agent *ap;
62 trace("AGENTS:\n");
63 for(ap = first_agent; ap; ap = ap->next_agent)
65 trace("\t%-30s %-30s %8d\n",
66 ap->name,
67 address_string(&(ap->address)),
68 ap->timeout);
70 trace("\n");
74 /****************************************************************/
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 */
80 void agent_list_delete()
82 Agent *ap = first_agent;
83 Agent *next;
86 while(ap)
88 next = ap->next_agent;
90 agent_free(ap);
92 ap = next;
95 first_agent = NULL;
97 return;
101 /****************************************************************/
103 /* The fisrt_agent_subtree member of the agent */
104 /* structure should be NULL */
106 static void agent_free(Agent *ap)
108 if(ap == NULL)
110 return;
113 if(ap->first_agent_subtree)
115 error("BUG: agent_free(): first_agent_subtree not NULL");
118 free(ap->name);
119 free(ap);
121 return;
124 /****************************************************************/
126 /* agent_find() is used to check if we have not */
127 /* two SNMP agents registered on the same UDP port */
129 Agent *agent_find(Address *address)
131 Agent *ap;
134 for(ap = first_agent; ap; ap = ap->next_agent)
136 if(ap->address.sin_port == address->sin_port)
138 return ap;
142 return NULL;
146 /****************************************************************/