]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/address_conf.h
Convert to pure GPL v2 license.
[bacula/bacula] / bacula / src / lib / address_conf.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2004-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *   Written by Meno Abels, June MMIV
31  *
32  *   Version $Id$
33  */
34
35
36 class IPADDR : public SMARTALLOC {
37  public:
38    typedef enum { R_SINGLE, R_SINGLE_PORT, R_SINGLE_ADDR, R_MULTIPLE,
39                   R_DEFAULT, R_EMPTY
40    } i_type;
41    IPADDR(int af);
42    IPADDR(const IPADDR & src);
43  private:
44    IPADDR() {  /* block this construction */ }
45    i_type type;
46    union {
47       struct sockaddr dontuse;
48       struct sockaddr_in dontuse4;
49 #ifdef HAVE_IPV6
50       struct sockaddr_in6 dontuse6;
51 #endif
52    } saddrbuf;
53    struct sockaddr *saddr;
54    struct sockaddr_in *saddr4;
55 #ifdef HAVE_IPV6
56    struct sockaddr_in6 *saddr6;
57 #endif
58  public:
59    void set_type(i_type o);
60    i_type get_type() const;
61    unsigned short get_port_net_order() const;
62    unsigned short get_port_host_order() const
63    {
64       return ntohs(get_port_net_order());
65    }
66    void set_port_net(unsigned short port);
67    int get_family() const;
68    struct sockaddr *get_sockaddr();
69    int get_sockaddr_len();
70    void copy_addr(IPADDR * src);
71    void set_addr_any();
72    void set_addr4(struct in_addr *ip4);
73 #ifdef HAVE_IPV6
74    void set_addr6(struct in6_addr *ip6);
75 #endif
76    const char *get_address(char *outputbuf, int outlen);
77
78    const char *build_address_str(char *buf, int blen);
79
80    /* private */
81    dlink link;
82 };
83
84 extern void store_addresses(LEX * lc, RES_ITEM * item, int index, int pass);
85 extern void free_addresses(dlist * addrs);
86 extern void store_addresses_address(LEX * lc, RES_ITEM * item, int index, int pass);
87 extern void store_addresses_port(LEX * lc, RES_ITEM * item, int index, int pass);
88 extern void init_default_addresses(dlist ** addr, int port);
89
90 extern const char *get_first_address(dlist * addrs, char *outputbuf, int outlen);
91 extern int get_first_port_net_order(dlist * addrs);
92 extern int get_first_port_host_order(dlist * addrs);
93
94 extern const char *build_addresses_str(dlist *addrs, char *buf, int blen);
95
96 extern int sockaddr_get_port_net_order(const struct sockaddr *sa);
97 extern int sockaddr_get_port(const struct sockaddr *sa);
98 extern char *sockaddr_to_ascii(const struct sockaddr *sa, char *buf, int len);
99 #ifdef WIN32
100 #undef HAVE_OLD_SOCKOPT
101 #endif
102 #ifdef HAVE_OLD_SOCKOPT
103 extern int inet_aton(const char *cp, struct in_addr *inp);
104 #endif