--- gvpe/src/sockinfo.C 2003/04/07 01:12:56 1.8 +++ gvpe/src/sockinfo.C 2005/03/03 07:24:57 1.14 @@ -1,5 +1,6 @@ /* sockinfo.C -- socket address management + Copyright (C) 2003 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +19,6 @@ #include "config.h" -#include #include #include "gettext.h" @@ -26,10 +26,13 @@ #include "sockinfo.h" #include "slog.h" +// all ipv4-based protocols +#define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4 | PROT_DNSv4) + void sockinfo::set (const sockaddr_in *sa, u8 prot_) { host = sa->sin_addr.s_addr; - port = prot_ == PROT_IPv4 ? 0 : sa->sin_port; + port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; prot = prot_; } @@ -39,7 +42,7 @@ host = 0; port = htons (port_); - if (prot & (PROT_UDPv4 | PROT_TCPv4 | PROT_IPv4) + if (prot & PROTv4 && hostname) { struct hostent *he = gethostbyname (hostname); @@ -58,11 +61,15 @@ void sockinfo::set (const conf_node *conf, u8 prot_) { - set (conf->hostname, - prot_ == PROT_UDPv4 ? conf->udp_port - : prot_ == PROT_TCPv4 ? conf->tcp_port - : 0, - prot_); + if (prot_ == PROT_DNSv4) + set (conf->dns_hostname, conf->dns_hostname ? conf->dns_port : 0, prot_); + else + set (conf->hostname, + prot_ == PROT_UDPv4 ? conf->udp_port + : prot_ == PROT_TCPv4 ? conf->tcp_port + : prot_ == PROT_DNSv4 ? conf->dns_port + : 0, + prot_); } const sockaddr * @@ -104,20 +111,26 @@ u8 protocols = prot; if (prot & (PROT_UDPv4 | PROT_TCPv4)) - protocols |= PROT_IPv4; + protocols |= PROT_IPv4 | PROT_ICMPv4; if (conf - && prot & (PROT_IPv4 | PROT_UDPv4 | PROT_TCPv4) + && prot & PROTv4 && conf->protocols & PROT_UDPv4 && conf->udp_port) protocols |= PROT_UDPv4; if (conf - && prot & (PROT_IPv4 | PROT_UDPv4 | PROT_TCPv4) + && prot & PROTv4 && conf->protocols & PROT_TCPv4 && conf->tcp_port) protocols |= PROT_TCPv4; + if (conf + && prot & PROTv4 + && conf->protocols & PROT_DNSv4 + && conf->dns_port) + protocols |= PROT_DNSv4; + return protocols; } @@ -127,10 +140,10 @@ if (prot_ == prot) return true; - if (prot & (PROT_IPv4 | PROT_UDPv4 | PROT_TCPv4) - && prot_ & (PROT_IPv4 | PROT_UDPv4 | PROT_TCPv4)) + if (prot & PROTv4 + && prot_ & PROTv4) { - if (prot_ & PROT_IPv4) + if (prot_ & (PROT_IPv4 | PROT_ICMPv4)) { prot = prot_; port = 0; @@ -156,6 +169,17 @@ port = htons (conf->tcp_port); return true; } + +#if ENABLE_DNS + if (conf + && prot_ & PROT_DNSv4 + && conf->protocols & PROT_DNSv4 + && conf->dns_port) + { + set (::conf.dns_forw_host, ::conf.dns_forw_port, prot_); + return true; + } +#endif } return false;