… | |
… | |
42 | #include <cstdio> |
42 | #include <cstdio> |
43 | |
43 | |
44 | // all ipv4-based protocols |
44 | // all ipv4-based protocols |
45 | #define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4 | PROT_DNSv4) |
45 | #define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4 | PROT_DNSv4) |
46 | |
46 | |
|
|
47 | void |
47 | void sockinfo::set (const sockaddr_in *sa, u8 prot_) |
48 | sockinfo::set (const sockaddr_in *sa, u8 prot_) |
48 | { |
49 | { |
49 | host = sa->sin_addr.s_addr; |
50 | host = sa->sin_addr.s_addr; |
50 | port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; |
51 | port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; |
51 | prot = prot_; |
52 | prot = prot_; |
52 | } |
53 | } |
53 | |
54 | |
|
|
55 | void |
54 | void sockinfo::set (const char *hostname, u16 port_, u8 prot_) |
56 | sockinfo::set (const char *hostname, u16 port_, u8 prot_) |
55 | { |
57 | { |
56 | prot = prot_; |
58 | prot = prot_; |
57 | host = 0; |
59 | host = 0; |
58 | port = htons (port_); |
60 | port = htons (port_); |
59 | |
61 | |
… | |
… | |
125 | u8 |
127 | u8 |
126 | sockinfo::supported_protocols (conf_node *conf) |
128 | sockinfo::supported_protocols (conf_node *conf) |
127 | { |
129 | { |
128 | u8 protocols = prot; |
130 | u8 protocols = prot; |
129 | |
131 | |
130 | if (prot & (PROT_UDPv4 | PROT_TCPv4)) |
132 | if (prot & (PROT_IPv4 | PROT_ICMPv4 | PROT_UDPv4 | PROT_TCPv4)) |
131 | protocols |= PROT_IPv4 | PROT_ICMPv4; |
133 | protocols |= PROT_IPv4 | PROT_ICMPv4; |
132 | |
134 | |
133 | if (conf |
|
|
134 | && prot & PROTv4 |
135 | if (conf && prot & PROTv4) |
135 | && conf->protocols & PROT_UDPv4 |
136 | { |
136 | && conf->udp_port) |
137 | if (conf->protocols & PROT_UDPv4 && conf->udp_port) |
137 | protocols |= PROT_UDPv4; |
138 | protocols |= PROT_UDPv4; |
138 | |
139 | |
139 | if (conf |
140 | if (conf->protocols & PROT_TCPv4 && conf->tcp_port) |
140 | && prot & PROTv4 |
|
|
141 | && conf->protocols & PROT_TCPv4 |
|
|
142 | && conf->tcp_port) |
|
|
143 | protocols |= PROT_TCPv4; |
141 | protocols |= PROT_TCPv4; |
144 | |
142 | |
145 | if (conf |
143 | if (conf->protocols & PROT_DNSv4 && conf->dns_port) |
146 | && prot & PROTv4 |
|
|
147 | && conf->protocols & PROT_DNSv4 |
|
|
148 | && conf->dns_port) |
|
|
149 | protocols |= PROT_DNSv4; |
144 | protocols |= PROT_DNSv4; |
|
|
145 | } |
150 | |
146 | |
151 | return protocols; |
147 | return protocols; |
152 | } |
148 | } |
153 | |
149 | |
154 | bool |
150 | bool |