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.2 by pcg, Wed Apr 2 03:25:17 2003 UTC vs.
Revision 1.4 by pcg, Sat Apr 5 02:32:40 2003 UTC

1/* 1/*
2 sockinfo.c -- socket address management 2 sockinfo.C -- socket address management
3 3
4 This program is free software; you can redistribute it and/or modify 4 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 5 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 6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version. 7 (at your option) any later version.
32 port = prot_ == PROT_IPv4 ? 0 : sa->sin_port; 32 port = prot_ == PROT_IPv4 ? 0 : sa->sin_port;
33 prot = prot_; 33 prot = prot_;
34} 34}
35 35
36void 36void
37sockinfo::set (const conf_node *conf) 37sockinfo::set (const conf_node *conf, u8 prot_)
38{ 38{
39 prot = prot_;
39 host = 0; 40 host = 0;
40 port = htons (conf->udp_port); 41 port = prot == PROT_UDPv4 ? htons (conf->udp_port)
42 : prot == PROT_TCPv4 ? htons (conf->tcp_port)
43 : 0;
41 44
42 if (conf->hostname) 45 if (prot && conf->hostname)
43 { 46 {
44 struct hostent *he = gethostbyname (conf->hostname); 47 struct hostent *he = gethostbyname (conf->hostname);
45 48
46 if (he 49 if (he
47 && he->h_addrtype == AF_INET && he->h_length == 4 && he->h_addr_list[0]) 50 && he->h_addrtype == AF_INET && he->h_length == 4 && he->h_addr_list[0])
48 { 51 {
49 //sa->sin_family = he->h_addrtype; 52 //sa->sin_family = he->h_addrtype;
50 memcpy (&host, he->h_addr_list[0], 4); 53 memcpy (&host, he->h_addr_list[0], 4);
51 54
52 prot = PROT_UDPv4 | PROT_IPv4;
53 } 55 }
54 else 56 else
55 slog (L_NOTICE, _("unable to resolve host '%s'"), conf->hostname); 57 slog (L_NOTICE, _("unable to resolve host '%s'"), conf->hostname);
56 } 58 }
57} 59}
67 sa.sin_addr.s_addr = host; 69 sa.sin_addr.s_addr = host;
68 70
69 return (const sockaddr *)&sa; 71 return (const sockaddr *)&sa;
70} 72}
71 73
72static char hostport[15 + 1 + 5 + 1]; // IPv4 : port 74static char hostport[10 + 15 + 1 + 5 + 1]; // protype / IPv4 : port
73 75
74const char * 76const char *
75sockinfo::ntoa () const 77sockinfo::ntoa () const
76{ 78{
77 in_addr ia = { host }; 79 in_addr ia = { host };
83 85
84sockinfo::operator const char *() const 86sockinfo::operator const char *() const
85{ 87{
86 in_addr ia = { host }; 88 in_addr ia = { host };
87 89
88 sprintf (hostport, "%.15s:%d", inet_ntoa (ia), ntohs (port) & 0xffff); 90 sprintf (hostport, "%s/%.15s:%d", strprotocol (prot), inet_ntoa (ia), ntohs (port) & 0xffff);
89 91
90 return hostport; 92 return hostport;
91} 93}
92 94
95bool
96operator == (const sockinfo &a, const sockinfo &b)
97{
98 return a.host == b.host && a.port == b.port && a.prot == b.prot;
99}
100
101bool
102operator < (const sockinfo &a, const sockinfo &b)
103{
104 return a.host < b.host
105 || (a.host == b.host && (a.port < b.port
106 || (a.port == b.port && a.prot < b.prot)));
107}
108

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines