-
Notifications
You must be signed in to change notification settings - Fork 256
/
address_conf.h
92 lines (81 loc) · 2.84 KB
/
address_conf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2004-2007 Free Software Foundation Europe e.V.
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* Written by Meno Abels, June MMIV
*/
class IPADDR : public SMARTALLOC {
public:
typedef enum { R_SINGLE, R_SINGLE_PORT, R_SINGLE_ADDR, R_MULTIPLE,
R_DEFAULT, R_EMPTY
} i_type;
IPADDR(int af);
IPADDR(const IPADDR & src);
private:
IPADDR() { /* block this construction */ }
i_type type;
union {
struct sockaddr dontuse;
struct sockaddr_in dontuse4;
#ifdef HAVE_IPV6
struct sockaddr_in6 dontuse6;
#endif
} saddrbuf;
struct sockaddr *saddr;
struct sockaddr_in *saddr4;
#ifdef HAVE_IPV6
struct sockaddr_in6 *saddr6;
#endif
public:
void set_type(i_type o);
i_type get_type() const;
unsigned short get_port_net_order() const;
unsigned short get_port_host_order() const
{
return ntohs(get_port_net_order());
}
void set_port_net(unsigned short port);
int get_family() const;
struct sockaddr *get_sockaddr();
int get_sockaddr_len();
void copy_addr(IPADDR * src);
void set_addr_any();
void set_addr4(struct in_addr *ip4);
#ifdef HAVE_IPV6
void set_addr6(struct in6_addr *ip6);
#endif
const char *get_address(char *outputbuf, int outlen);
const char *build_address_str(char *buf, int blen);
/* private */
dlink link;
};
void init_default_addresses(dlist ** addr, const char *port);
void free_addresses(dlist * addrs);
const char *get_first_address(dlist * addrs, char *outputbuf, int outlen);
int get_first_port_net_order(dlist * addrs);
int get_first_port_host_order(dlist * addrs);
int add_address(dlist **out, IPADDR::i_type type, unsigned short defaultport, int family,
const char *hostname_str, const char *port_str, char *buf, int buflen);
const char *build_addresses_str(dlist *addrs, char *buf, int blen);
int sockaddr_get_port_net_order(const struct sockaddr *sa);
int sockaddr_get_port(const struct sockaddr *sa);
char *sockaddr_to_ascii(const struct sockaddr *sa, char *buf, int len);
#ifdef WIN32
#undef HAVE_OLD_SOCKOPT
#endif
#ifdef HAVE_OLD_SOCKOPT
int inet_aton(const char *cp, struct in_addr *inp);
#endif