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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines