… | |
… | |
25 | |
25 | |
26 | #include "sockinfo.h" |
26 | #include "sockinfo.h" |
27 | #include "slog.h" |
27 | #include "slog.h" |
28 | |
28 | |
29 | // all ipv4-based protocols |
29 | // all ipv4-based protocols |
30 | #define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4) |
30 | #define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4 | PROT_DNSv4) |
31 | |
31 | |
32 | void sockinfo::set (const sockaddr_in *sa, u8 prot_) |
32 | void sockinfo::set (const sockaddr_in *sa, u8 prot_) |
33 | { |
33 | { |
34 | host = sa->sin_addr.s_addr; |
34 | host = sa->sin_addr.s_addr; |
35 | port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; |
35 | port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; |
… | |
… | |
59 | } |
59 | } |
60 | |
60 | |
61 | void |
61 | void |
62 | sockinfo::set (const conf_node *conf, u8 prot_) |
62 | sockinfo::set (const conf_node *conf, u8 prot_) |
63 | { |
63 | { |
64 | set (conf->hostname, |
64 | set (prot_ == PROT_DNSv4 ? ::conf.dns_forw_host |
|
|
65 | : conf->hostname, |
65 | prot_ == PROT_UDPv4 ? conf->udp_port |
66 | prot_ == PROT_UDPv4 ? conf->udp_port |
66 | : prot_ == PROT_TCPv4 ? conf->tcp_port |
67 | : prot_ == PROT_TCPv4 ? conf->tcp_port |
67 | : prot_ == PROT_DNSv4 ? conf->dns_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 | { |
… | |
… | |
122 | && conf->tcp_port) |
123 | && conf->tcp_port) |
123 | protocols |= PROT_TCPv4; |
124 | protocols |= PROT_TCPv4; |
124 | |
125 | |
125 | if (conf |
126 | if (conf |
126 | && prot & PROTv4 |
127 | && prot & PROTv4 |
127 | && conf->protocols & PROT_DNSv4) |
128 | && conf->protocols & PROT_DNSv4 |
|
|
129 | && conf->dns_port) |
128 | protocols |= PROT_DNSv4; |
130 | protocols |= PROT_DNSv4; |
129 | |
131 | |
130 | return protocols; |
132 | return protocols; |
131 | } |
133 | } |
132 | |
134 | |
… | |
… | |
163 | { |
165 | { |
164 | prot = prot_; |
166 | prot = prot_; |
165 | port = htons (conf->tcp_port); |
167 | port = htons (conf->tcp_port); |
166 | return true; |
168 | return true; |
167 | } |
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 | } |
168 | } |
179 | } |
169 | |
180 | |
170 | return false; |
181 | return false; |
171 | } |
182 | } |
172 | |
183 | |