… | |
… | |
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 | if (prot_ == PROT_DNSv4) |
|
|
65 | set (conf->dns_hostname, conf->dns_hostname ? conf->dns_port : 0, prot_); |
|
|
66 | else |
64 | set (conf->hostname, |
67 | set (conf->hostname, |
65 | prot_ == PROT_UDPv4 ? conf->udp_port |
68 | prot_ == PROT_UDPv4 ? conf->udp_port |
66 | : prot_ == PROT_TCPv4 ? conf->tcp_port |
69 | : prot_ == PROT_TCPv4 ? conf->tcp_port |
|
|
70 | : prot_ == PROT_DNSv4 ? conf->dns_port |
67 | : 0, |
71 | : 0, |
68 | prot_); |
72 | prot_); |
69 | } |
73 | } |
70 | |
74 | |
71 | const sockaddr * |
75 | const sockaddr * |
72 | sockinfo::sav4() const |
76 | sockinfo::sav4() const |
73 | { |
77 | { |
… | |
… | |
119 | && prot & PROTv4 |
123 | && prot & PROTv4 |
120 | && conf->protocols & PROT_TCPv4 |
124 | && conf->protocols & PROT_TCPv4 |
121 | && conf->tcp_port) |
125 | && conf->tcp_port) |
122 | protocols |= PROT_TCPv4; |
126 | protocols |= PROT_TCPv4; |
123 | |
127 | |
|
|
128 | if (conf |
|
|
129 | && prot & PROTv4 |
|
|
130 | && conf->protocols & PROT_DNSv4 |
|
|
131 | && conf->dns_port) |
|
|
132 | protocols |= PROT_DNSv4; |
|
|
133 | |
124 | return protocols; |
134 | return protocols; |
125 | } |
135 | } |
126 | |
136 | |
127 | bool |
137 | bool |
128 | sockinfo::upgrade_protocol (u8 prot_, conf_node *conf) |
138 | sockinfo::upgrade_protocol (u8 prot_, conf_node *conf) |
… | |
… | |
157 | { |
167 | { |
158 | prot = prot_; |
168 | prot = prot_; |
159 | port = htons (conf->tcp_port); |
169 | port = htons (conf->tcp_port); |
160 | return true; |
170 | return true; |
161 | } |
171 | } |
|
|
172 | |
|
|
173 | #if ENABLE_DNS |
|
|
174 | if (conf |
|
|
175 | && prot_ & PROT_DNSv4 |
|
|
176 | && conf->protocols & PROT_DNSv4 |
|
|
177 | && conf->dns_port) |
|
|
178 | { |
|
|
179 | set (::conf.dns_forw_host, ::conf.dns_forw_port, prot_); |
|
|
180 | return true; |
|
|
181 | } |
|
|
182 | #endif |
162 | } |
183 | } |
163 | |
184 | |
164 | return false; |
185 | return false; |
165 | } |
186 | } |
166 | |
187 | |