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.9 by pcg, Tue Apr 8 02:00:54 2003 UTC vs.
Revision 1.14 by pcg, Thu Mar 3 07:24:57 2005 UTC

1/* 1/*
2 sockinfo.C -- socket address management 2 sockinfo.C -- socket address management
3 Copyright (C) 2003 Marc Lehmann <pcg@goof.com>
3 4
4 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version. 8 (at your option) any later version.
16 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 18*/
18 19
19#include "config.h" 20#include "config.h"
20 21
21#include <arpa/inet.h>
22#include <netdb.h> 22#include <netdb.h>
23 23
24#include "gettext.h" 24#include "gettext.h"
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
32void sockinfo::set (const sockaddr_in *sa, u8 prot_) 32void 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
61void 61void
62sockinfo::set (const conf_node *conf, u8 prot_) 62sockinfo::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
71const sockaddr * 75const sockaddr *
72sockinfo::sav4() const 76sockinfo::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
127bool 137bool
128sockinfo::upgrade_protocol (u8 prot_, conf_node *conf) 138sockinfo::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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines