--- gvpe/src/sockinfo.C 2003/03/28 04:05:10 1.1 +++ gvpe/src/sockinfo.C 2003/04/05 02:32:40 1.4 @@ -1,5 +1,5 @@ /* - sockinfo.c -- socket address management + sockinfo.C -- socket address management 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 +18,8 @@ #include "config.h" -#include "arpa/inet.h" +#include +#include #include "gettext.h" @@ -33,12 +34,15 @@ } void -sockinfo::set (const conf_node *conf) +sockinfo::set (const conf_node *conf, u8 prot_) { + prot = prot_; host = 0; - port = htons (conf->udp_port); + port = prot == PROT_UDPv4 ? htons (conf->udp_port) + : prot == PROT_TCPv4 ? htons (conf->tcp_port) + : 0; - if (conf->hostname) + if (prot && conf->hostname) { struct hostent *he = gethostbyname (conf->hostname); @@ -48,7 +52,6 @@ //sa->sin_family = he->h_addrtype; memcpy (&host, he->h_addr_list[0], 4); - prot = PROT_UDPv4 | PROT_IPv4; } else slog (L_NOTICE, _("unable to resolve host '%s'"), conf->hostname); @@ -68,7 +71,7 @@ return (const sockaddr *)&sa; } -static char hostport[15 + 1 + 5 + 1]; // IPv4 : port +static char hostport[10 + 15 + 1 + 5 + 1]; // protype / IPv4 : port const char * sockinfo::ntoa () const @@ -84,8 +87,22 @@ { in_addr ia = { host }; - sprintf (hostport, "%.15s:%d", inet_ntoa (ia), ntohs (port) & 0xffff); + sprintf (hostport, "%s/%.15s:%d", strprotocol (prot), inet_ntoa (ia), ntohs (port) & 0xffff); return hostport; } +bool +operator == (const sockinfo &a, const sockinfo &b) +{ + return a.host == b.host && a.port == b.port && a.prot == b.prot; +} + +bool +operator < (const sockinfo &a, const sockinfo &b) +{ + return a.host < b.host + || (a.host == b.host && (a.port < b.port + || (a.port == b.port && a.prot < b.prot))); +} +