… | |
… | |
17 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
18 | */ |
19 | |
19 | |
20 | #include "config.h" |
20 | #include "config.h" |
21 | |
21 | |
22 | #include <arpa/inet.h> |
|
|
23 | #include <netdb.h> |
22 | #include <netdb.h> |
24 | |
23 | |
25 | #include "gettext.h" |
24 | #include "gettext.h" |
26 | |
25 | |
27 | #include "sockinfo.h" |
26 | #include "sockinfo.h" |
28 | #include "slog.h" |
27 | #include "slog.h" |
29 | |
28 | |
30 | // all ipv4-based protocols |
29 | // all ipv4-based protocols |
31 | #define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4) |
30 | #define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4 | PROT_DNSv4) |
32 | |
31 | |
33 | void sockinfo::set (const sockaddr_in *sa, u8 prot_) |
32 | void sockinfo::set (const sockaddr_in *sa, u8 prot_) |
34 | { |
33 | { |
35 | host = sa->sin_addr.s_addr; |
34 | host = sa->sin_addr.s_addr; |
36 | port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; |
35 | port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; |
… | |
… | |
60 | } |
59 | } |
61 | |
60 | |
62 | void |
61 | void |
63 | sockinfo::set (const conf_node *conf, u8 prot_) |
62 | sockinfo::set (const conf_node *conf, u8 prot_) |
64 | { |
63 | { |
65 | set (conf->hostname, |
64 | set (prot_ == PROT_DNSv4 ? ::conf.dns_forw_host |
|
|
65 | : conf->hostname, |
66 | prot_ == PROT_UDPv4 ? conf->udp_port |
66 | prot_ == PROT_UDPv4 ? conf->udp_port |
67 | : prot_ == PROT_TCPv4 ? conf->tcp_port |
67 | : prot_ == PROT_TCPv4 ? conf->tcp_port |
|
|
68 | : prot_ == PROT_DNSv4 ? conf->dns_port |
68 | : 0, |
69 | : 0, |
69 | prot_); |
70 | prot_); |
70 | } |
71 | } |
71 | |
72 | |
72 | const sockaddr * |
73 | const sockaddr * |
73 | sockinfo::sav4() const |
74 | sockinfo::sav4() const |
74 | { |
75 | { |
… | |
… | |
120 | && prot & PROTv4 |
121 | && prot & PROTv4 |
121 | && conf->protocols & PROT_TCPv4 |
122 | && conf->protocols & PROT_TCPv4 |
122 | && conf->tcp_port) |
123 | && conf->tcp_port) |
123 | protocols |= PROT_TCPv4; |
124 | protocols |= PROT_TCPv4; |
124 | |
125 | |
|
|
126 | if (conf |
|
|
127 | && prot & PROTv4 |
|
|
128 | && conf->protocols & PROT_DNSv4 |
|
|
129 | && conf->dns_port) |
|
|
130 | protocols |= PROT_DNSv4; |
|
|
131 | |
125 | return protocols; |
132 | return protocols; |
126 | } |
133 | } |
127 | |
134 | |
128 | bool |
135 | bool |
129 | sockinfo::upgrade_protocol (u8 prot_, conf_node *conf) |
136 | sockinfo::upgrade_protocol (u8 prot_, conf_node *conf) |
… | |
… | |
158 | { |
165 | { |
159 | prot = prot_; |
166 | prot = prot_; |
160 | port = htons (conf->tcp_port); |
167 | port = htons (conf->tcp_port); |
161 | return true; |
168 | return true; |
162 | } |
169 | } |
|
|
170 | |
|
|
171 | if (conf |
|
|
172 | && prot_ & PROT_DNSv4 |
|
|
173 | && conf->protocols & PROT_DNSv4 |
|
|
174 | && conf->dns_port) |
|
|
175 | { |
|
|
176 | set (::conf.dns_forw_host, ::conf.dns_forw_port, prot_); |
|
|
177 | return true; |
|
|
178 | } |
163 | } |
179 | } |
164 | |
180 | |
165 | return false; |
181 | return false; |
166 | } |
182 | } |
167 | |
183 | |