]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/address_conf.h
Backport from BEE
[bacula/bacula] / bacula / src / lib / address_conf.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2004-2014 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from many
7    others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    Bacula® is a registered trademark of Kern Sibbald.
15 */
16 /*
17  *
18  *   Written by Meno Abels, June MMIV
19  *
20  */
21
22
23 class IPADDR : public SMARTALLOC {
24  public:
25    typedef enum { R_SINGLE, R_SINGLE_PORT, R_SINGLE_ADDR, R_MULTIPLE,
26                   R_DEFAULT, R_EMPTY
27    } i_type;
28    IPADDR(int af);
29    IPADDR(const IPADDR & src);
30  private:
31    IPADDR() {  /* block this construction */ }
32    i_type type;
33    union {
34       struct sockaddr dontuse;
35       struct sockaddr_in dontuse4;
36 #ifdef HAVE_IPV6
37       struct sockaddr_in6 dontuse6;
38 #endif
39    } saddrbuf;
40    struct sockaddr *saddr;
41    struct sockaddr_in *saddr4;
42 #ifdef HAVE_IPV6
43    struct sockaddr_in6 *saddr6;
44 #endif
45  public:
46    void set_type(i_type o);
47    i_type get_type() const;
48    unsigned short get_port_net_order() const;
49    unsigned short get_port_host_order() const
50    {
51       return ntohs(get_port_net_order());
52    }
53    void set_port_net(unsigned short port);
54    int get_family() const;
55    struct sockaddr *get_sockaddr();
56    int get_sockaddr_len();
57    void copy_addr(IPADDR * src);
58    void set_addr_any();
59    void set_addr4(struct in_addr *ip4);
60 #ifdef HAVE_IPV6
61    void set_addr6(struct in6_addr *ip6);
62 #endif
63    const char *get_address(char *outputbuf, int outlen);
64
65    const char *build_address_str(char *buf, int blen);
66
67    /* private */
68    dlink link;
69 };
70
71 extern void store_addresses(LEX * lc, RES_ITEM * item, int index, int pass);
72 extern void free_addresses(dlist * addrs);
73 extern void store_addresses_address(LEX * lc, RES_ITEM * item, int index, int pass);
74 extern void store_addresses_port(LEX * lc, RES_ITEM * item, int index, int pass);
75 extern void init_default_addresses(dlist ** addr, int port);
76
77 extern const char *get_first_address(dlist * addrs, char *outputbuf, int outlen);
78 extern int get_first_port_net_order(dlist * addrs);
79 extern int get_first_port_host_order(dlist * addrs);
80
81 extern const char *build_addresses_str(dlist *addrs, char *buf, int blen);
82
83 extern int sockaddr_get_port_net_order(const struct sockaddr *sa);
84 extern int sockaddr_get_port(const struct sockaddr *sa);
85 extern char *sockaddr_to_ascii(const struct sockaddr *sa, int socklen, char *buf, int buflen);
86 #ifdef WIN32
87 #undef HAVE_OLD_SOCKOPT
88 #endif
89 #ifdef HAVE_OLD_SOCKOPT
90 extern int inet_aton(const char *cp, struct in_addr *inp);
91 #endif