]>
Commit | Line | Data |
---|---|---|
189935b1 | 1 | /* - Internet Relay Chat, include/listener.h |
2 | * Copyright (C) 1999 Thomas Helvey <tomh@inxpress.net> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 1, or (at your option) | |
7 | * any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
17 | */ | |
18 | /** @file | |
19 | * @brief Interface and declarations for handling listening sockets. | |
dd9731c9 | 20 | * @version $Id: listener.h,v 1.6.2.2 2006/12/07 05:14:51 entrope Exp $ |
189935b1 | 21 | */ |
22 | #ifndef INCLUDED_listener_h | |
23 | #define INCLUDED_listener_h | |
24 | #ifndef INCLUDED_ircd_defs_h | |
25 | #include "ircd_defs.h" /* HOSTLEN */ | |
26 | #endif | |
27 | #ifndef INCLUDED_ircd_events_h | |
28 | #include "ircd_events.h" | |
29 | #endif | |
30 | #ifndef INCLUDED_res_h | |
31 | #include "res.h" | |
32 | #endif | |
dd9731c9 | 33 | #ifndef INCLUDED_client_h |
34 | #include "client.h" /* flagset stuff. oh well. */ | |
35 | #endif | |
189935b1 | 36 | #ifndef INCLUDED_sys_types_h |
37 | #include <sys/types.h> /* size_t, broken BSD system headers */ | |
38 | #define INCLUDED_sys_types_h | |
39 | #endif | |
40 | ||
41 | struct Client; | |
42 | struct StatDesc; | |
43 | ||
dd9731c9 | 44 | enum ListenerFlag { |
45 | /** Port is currently accepting connections. */ | |
46 | LISTEN_ACTIVE, | |
47 | /** Port is hidden from /STATS P output. */ | |
48 | LISTEN_HIDDEN, | |
49 | /** Port accepts only server connections. */ | |
50 | LISTEN_SERVER, | |
51 | /** Port listens for IPv4 connections. */ | |
52 | LISTEN_IPV4, | |
53 | /** Port listens for IPv6 connections. */ | |
54 | LISTEN_IPV6, | |
55 | /** Sentinel for counting listener flags. */ | |
56 | LISTEN_LAST_FLAG | |
57 | }; | |
58 | ||
59 | DECLARE_FLAGSET(ListenerFlags, LISTEN_LAST_FLAG); | |
60 | ||
189935b1 | 61 | /** Describes a single listening port. */ |
62 | struct Listener { | |
63 | struct Listener* next; /**< list node pointer */ | |
dd9731c9 | 64 | struct ListenerFlags flags; /**< on-off flags for listener */ |
65 | int fd_v4; /**< file descriptor for IPv4 */ | |
66 | int fd_v6; /**< file descriptor for IPv6 */ | |
189935b1 | 67 | int ref_count; /**< number of connection references */ |
189935b1 | 68 | unsigned char mask_bits; /**< number of bits in mask address */ |
69 | int index; /**< index into poll array */ | |
70 | time_t last_accept; /**< last time listener accepted */ | |
71 | struct irc_sockaddr addr; /**< virtual address and port */ | |
72 | struct irc_in_addr mask; /**< listener hostmask */ | |
dd9731c9 | 73 | struct Socket socket_v4; /**< describe IPv4 socket to event system */ |
74 | struct Socket socket_v6; /**< describe IPv6 socket to event system */ | |
189935b1 | 75 | }; |
76 | ||
dd9731c9 | 77 | #define listener_server(LISTENER) FlagHas(&(LISTENER)->flags, LISTEN_SERVER) |
78 | #define listener_active(LISTENER) FlagHas(&(LISTENER)->flags, LISTEN_ACTIVE) | |
79 | ||
189935b1 | 80 | extern void add_listener(int port, const char* vaddr_ip, |
dd9731c9 | 81 | const char* mask, |
82 | const struct ListenerFlags *flags); | |
189935b1 | 83 | extern void close_listener(struct Listener* listener); |
84 | extern void close_listeners(void); | |
85 | extern void count_listener_memory(int* count_out, size_t* size_out); | |
86 | extern const char* get_listener_name(const struct Listener* listener); | |
87 | extern void mark_listeners_closing(void); | |
88 | extern void show_ports(struct Client* client, const struct StatDesc* sd, | |
89 | char* param); | |
90 | extern void release_listener(struct Listener* listener); | |
91 | ||
92 | #endif /* INCLUDED_listener_h */ | |
93 |