2 connlist.c -- connection list management
3 Copyright (C) 2000 Guus Sliepen <guus@sliepen.warande.net>,
4 2000 Ivo Timmermans <itimmermans@bigfoot.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: connlist.c,v 1.1.2.2 2000/10/11 22:00:58 guus Exp $
28 #include "net.h" /* Don't ask. */
30 /* Root of the connection list */
32 conn_list_t *conn_list = NULL;
33 conn_list_t *myself = NULL;
35 /* Creation and deletion of conn_list elements */
37 conn_list_t *new_conn_list(void)
39 conn_list_t *p = (conn_list_t *)xmalloc(sizeof(*p));
41 /* initialise all those stupid pointers at once */
42 memset(p, '\0', sizeof(*p));
47 void free_conn_list(conn_list_t *p)
58 free_key(p->public_key);
65 remove all marked connections
67 void prune_conn_list(void)
69 conn_list_t *p, *prev = NULL, *next = NULL;
71 for(p = conn_list; p != NULL; )
93 free all elements of conn_list
95 void destroy_conn_list(void)
97 conn_list_t *p, *next;
99 for(p = conn_list; p != NULL; )
102 free_conn_element(p);
110 /* Linked list management */
112 void conn_list_add(conn_list_t *cl)
115 cl->next = conn_list;
122 void conn_list_del(conn_list_t *cl)
126 cl->prev->next = cl->next;
128 conn_list = cl->next;
130 cl->next->prev = cl->prev;
135 /* Lookup functions */
137 conn_list_t *lookup_id(char *name)
141 for(p = conn_list; p != NULL; p = p->next)
142 if(strcmp(name, p->name) == 0)
148 conn_list_t *lookup_conn_list_mac(mac_t address)
152 for(p = conn_list; p != NULL; p = p->next)
153 if(lookup_subnet_mac(p->subnets, address))
159 conn_list_t *lookup_conn_list_ipv4(ipv4_t address)
163 for(p = conn_list; p != NULL; p = p->next)
164 if(lookup_subnet_ipv4(p->subnets, address))
170 conn_list_t *lookup_conn_list_ipv6(ipv6_t address)
174 for(p = conn_list; p != NULL; p = p->next)
175 if(lookup_subnet_ipv6(p->subnets, address))
183 void dump_conn_list(void)
189 syslog(LOG_DEBUG, _("Connection list:"));
191 for(p = conn_list; p != NULL; p = p->next)
193 syslog(LOG_DEBUG, _("%s at %s port %hd flags %d sockets %d, %d status %04x"),
194 p->name, p->hostname, p->port, p->flags,
195 p->socket, p->meta_socket, p->status);
196 for(s = p->subnets; s != NULL; s = s->next)
199 syslog(LOG_DEBUG, ": %s", netstr);
204 syslog(LOG_DEBUG, _("End of connection list."));