ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/sockinfo.C
(Generate patch)

Comparing gvpe/src/sockinfo.C (file contents):
Revision 1.24 by root, Tue Feb 8 23:11:36 2011 UTC vs.
Revision 1.27 by root, Tue Jan 17 21:25:50 2012 UTC

40 40
41#include <cstring> 41#include <cstring>
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 | PROT_IPv42)
46 46
47void 47void
48sockinfo::set (const sockaddr_in *sa, u8 prot_) 48sockinfo::set (const sockaddr_in *sa, u8 prot_)
49{ 49{
50 host = sa->sin_addr.s_addr; 50 host = sa->sin_addr.s_addr;
51 port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; 51 port = prot_ & (PROT_IPv4 | PROT_ICMPv4 | PROT_IPv42) ? 0 : sa->sin_port;
52 prot = prot_; 52 prot = prot_;
53} 53}
54 54
55void 55void
56sockinfo::set (const char *hostname, u16 port_, u8 prot_) 56sockinfo::set (const char *hostname, u16 port_, u8 prot_)
113 sprintf (hostport, "%.15s", inet_ntoa (ia)); 113 sprintf (hostport, "%.15s", inet_ntoa (ia));
114 114
115 return hostport; 115 return hostport;
116} 116}
117 117
118bool
119sockinfo::valid () const
120{
121 return (prot & THISNODE->protocols) && host;
122}
123
118sockinfo::operator const char *() const 124sockinfo::operator const char *() const
119{ 125{
120 in_addr ia = { host }; 126 in_addr ia = { host };
121 127
122 sprintf (hostport, "%s/%.15s:%d", strprotocol (prot), inet_ntoa (ia), ntohs (port) & 0xffff); 128 sprintf (hostport, "%s/%.15s:%d", strprotocol (prot), inet_ntoa (ia), ntohs (port) & 0xffff);
127u8 133u8
128sockinfo::supported_protocols (conf_node *conf) 134sockinfo::supported_protocols (conf_node *conf)
129{ 135{
130 u8 protocols = prot; 136 u8 protocols = prot;
131 137
132 if (prot & (PROT_UDPv4 | PROT_TCPv4)) 138 if (prot & (PROT_IPv4 | PROT_ICMPv4 | PROT_UDPv4 | PROT_TCPv4 | PROT_IPv42))
133 protocols |= PROT_IPv4 | PROT_ICMPv4; 139 protocols |= PROT_IPv4 | PROT_ICMPv4 | PROT_IPv42;
134 140
135 if (conf
136 && prot & PROTv4 141 if (conf && prot & PROTv4)
137 && conf->protocols & PROT_UDPv4 142 {
138 && conf->udp_port) 143 if (conf->protocols & PROT_UDPv4 && conf->udp_port)
139 protocols |= PROT_UDPv4; 144 protocols |= PROT_UDPv4;
140 145
141 if (conf 146 if (conf->protocols & PROT_TCPv4 && conf->tcp_port)
142 && prot & PROTv4
143 && conf->protocols & PROT_TCPv4
144 && conf->tcp_port)
145 protocols |= PROT_TCPv4; 147 protocols |= PROT_TCPv4;
146 148
147 if (conf 149 if (conf->protocols & PROT_DNSv4 && conf->dns_port)
148 && prot & PROTv4
149 && conf->protocols & PROT_DNSv4
150 && conf->dns_port)
151 protocols |= PROT_DNSv4; 150 protocols |= PROT_DNSv4;
151 }
152 152
153 return protocols; 153 return protocols;
154} 154}
155 155
156bool 156bool
160 return true; 160 return true;
161 161
162 if (prot & PROTv4 162 if (prot & PROTv4
163 && prot_ & PROTv4) 163 && prot_ & PROTv4)
164 { 164 {
165 if (prot_ & (PROT_IPv4 | PROT_ICMPv4)) 165 if (prot_ & (PROT_IPv4 | PROT_ICMPv4 | PROT_IPv42))
166 { 166 {
167 prot = prot_; 167 prot = prot_;
168 port = 0; 168 port = 0;
169 return true; 169 return true;
170 } 170 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines