--- gvpe/src/sockinfo.C 2003/04/05 02:32:40 1.4 +++ gvpe/src/sockinfo.C 2003/04/06 04:31:51 1.7 @@ -42,7 +42,8 @@ : prot == PROT_TCPv4 ? htons (conf->tcp_port) : 0; - if (prot && conf->hostname) + if (prot & (PROT_UDPv4 | PROT_TCPv4 | PROT_IPv4) + && conf->hostname) { struct hostent *he = gethostbyname (conf->hostname); @@ -51,7 +52,6 @@ { //sa->sin_family = he->h_addrtype; memcpy (&host, he->h_addr_list[0], 4); - } else slog (L_NOTICE, _("unable to resolve host '%s'"), conf->hostname); @@ -92,6 +92,69 @@ return hostport; } +u8 +sockinfo::supported_protocols (conf_node *conf) +{ + u8 protocols = prot; + + if (prot & (PROT_UDPv4 | PROT_TCPv4)) + protocols |= PROT_IPv4; + + if (conf + && prot & (PROT_IPv4 | PROT_UDPv4 | PROT_TCPv4) + && conf->protocols & PROT_UDPv4 + && conf->udp_port) + protocols |= PROT_UDPv4; + + if (conf + && prot & (PROT_IPv4 | PROT_UDPv4 | PROT_TCPv4) + && conf->protocols & PROT_TCPv4 + && conf->tcp_port) + protocols |= PROT_TCPv4; + + return protocols; +} + +bool +sockinfo::upgrade_protocol (u8 prot_, conf_node *conf) +{ + if (prot_ == prot) + return true; + + if (prot & (PROT_IPv4 | PROT_UDPv4 | PROT_TCPv4) + && prot_ & (PROT_IPv4 | PROT_UDPv4 | PROT_TCPv4)) + { + if (prot_ & PROT_IPv4) + { + prot = prot_; + port = 0; + return true; + } + + if (conf + && prot_ & PROT_UDPv4 + && conf->protocols & PROT_UDPv4 + && conf->udp_port) + { + prot = prot_; + port = htons (conf->udp_port); + return true; + } + + if (conf + && prot_ & PROT_TCPv4 + && conf->protocols & PROT_TCPv4 + && conf->tcp_port) + { + prot = prot_; + port = htons (conf->tcp_port); + return true; + } + } + + return false; +} + bool operator == (const sockinfo &a, const sockinfo &b) {