]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/address_conf.h
Merge Meno's IPv6-1 code
[bacula/bacula] / bacula / src / lib / address_conf.h
1 /*
2  *
3  *   Written by Meno Abels, June MMIIII
4  *
5  *   Version $Id$
6  */
7
8 /*
9    Copyright (C) 2004 Kern Sibbald and John Walker
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2 of
14    the License, or (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public
22    License along with this program; if not, write to the Free
23    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24    MA 02111-1307, USA.
25
26  */
27
28
29 class IPADDR {
30  public:
31    typedef enum { R_SINGLE, R_SINGLE_PORT, R_SINGLE_ADDR, R_MULTIPLE,
32       R_DEFAULT, R_EMPTY
33    } i_type;
34    IPADDR(int af);
35    IPADDR(const IPADDR & src);
36  private:
37    IPADDR() {
38       /* block this construction */ 
39    } 
40    i_type type;
41    union {
42       struct sockaddr dontuse;
43       struct sockaddr_in dontuse4;
44 #ifdef HAVE_IPV6
45       struct sockaddr_in6 dontuse6;
46 #endif
47    } buf;
48    struct sockaddr *saddr;
49    struct sockaddr_in *saddr4;
50 #ifdef HAVE_IPV6
51    struct sockaddr_in6 *saddr6;
52 #endif
53  public:
54    void set_type(i_type o);
55    i_type get_type() const;
56    unsigned short get_port() const;
57    void set_port(unsigned short port);
58    int get_family() const;
59    struct sockaddr *get_sockaddr();
60    int get_sockaddr_len();
61    void copy_addr(IPADDR * src);
62    void set_addr_any();
63    void set_addr4(struct in_addr *ip4);
64 #ifdef HAVE_IPV6
65    void set_addr6(struct in6_addr *ip6);
66 #endif
67    const char *get_address(char *outputbuf, int outlen);
68
69    const char *build_address_str(char *buf, int blen) {
70       char tmp[1024];
71       snprintf(buf, blen, "host[%s:%s:%hu] ",
72                 get_family() == AF_INET ? "ipv4" : "ipv6",
73                 get_address(tmp, sizeof(tmp) - 1), ntohs(get_port()));
74       return buf;
75    }
76    /* private */
77    dlink link;
78 };
79
80 extern void store_addresses(LEX * lc, RES_ITEM * item, int index, int pass);
81 extern void free_addresses(dlist * addrs);
82 extern void store_addresses_address(LEX * lc, RES_ITEM * item, int index, int pass);
83 extern void store_addresses_port(LEX * lc, RES_ITEM * item, int index, int pass);
84 extern int add_address(dlist ** out, IPADDR::i_type type, unsigned short defaultport,
85                        int family, const char *hostname_str,
86                        const char *port_str, char **errstr);
87
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(dlist * addrs);
92
93 extern const char *build_addresses_str(dlist *addrs, char *buf, int blen);
94