3 * Written by Meno Abels, June MMIIII
9 Copyright (C) 2004-2005 Kern Sibbald
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.
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.
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,
29 class IPADDR : public SMARTALLOC {
31 typedef enum { R_SINGLE, R_SINGLE_PORT, R_SINGLE_ADDR, R_MULTIPLE,
35 IPADDR(const IPADDR & src);
37 IPADDR() { /* block this construction */ }
40 struct sockaddr dontuse;
41 struct sockaddr_in dontuse4;
43 struct sockaddr_in6 dontuse6;
46 struct sockaddr *saddr;
47 struct sockaddr_in *saddr4;
49 struct sockaddr_in6 *saddr6;
52 void set_type(i_type o);
53 i_type get_type() const;
54 unsigned short get_port_net_order() const;
55 unsigned short get_port_host_order() const
57 return ntohs(get_port_net_order());
59 void set_port_net(unsigned short port);
60 int get_family() const;
61 struct sockaddr *get_sockaddr();
62 int get_sockaddr_len();
63 void copy_addr(IPADDR * src);
65 void set_addr4(struct in_addr *ip4);
67 void set_addr6(struct in6_addr *ip6);
69 const char *get_address(char *outputbuf, int outlen);
71 const char *build_address_str(char *buf, int blen);
77 extern void store_addresses(LEX * lc, RES_ITEM * item, int index, int pass);
78 extern void free_addresses(dlist * addrs);
79 extern void store_addresses_address(LEX * lc, RES_ITEM * item, int index, int pass);
80 extern void store_addresses_port(LEX * lc, RES_ITEM * item, int index, int pass);
81 extern void init_default_addresses(dlist ** addr, int port);
83 extern const char *get_first_address(dlist * addrs, char *outputbuf, int outlen);
84 extern int get_first_port_net_order(dlist * addrs);
85 extern int get_first_port_host_order(dlist * addrs);
87 extern const char *build_addresses_str(dlist *addrs, char *buf, int blen);
89 extern int sockaddr_get_port_net_order(const struct sockaddr *sa);
90 extern int sockaddr_get_port(const struct sockaddr *sa);
91 extern char *sockaddr_to_ascii(const struct sockaddr *sa, char *buf, int len);
93 #undef HAVE_OLD_SOCKOPT
95 #ifdef HAVE_OLD_SOCKOPT
96 extern int inet_aton(const char *cp, struct in_addr *inp);