source: vendor/synergy/1.3.1/lib/net/CNetworkAddress.h@ 2749

Last change on this file since 2749 was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 3.0 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2002 Chris Schoeneman
4 *
5 * This package is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef CNETWORKADDRESS_H
16#define CNETWORKADDRESS_H
17
18#include "CString.h"
19#include "BasicTypes.h"
20#include "IArchNetwork.h"
21
22//! Network address type
23/*!
24This class represents a network address.
25*/
26class CNetworkAddress {
27public:
28 /*!
29 Constructs the invalid address
30 */
31 CNetworkAddress();
32
33 /*!
34 Construct the wildcard address with the given port. \c port must
35 not be zero.
36 */
37 CNetworkAddress(int port);
38
39 /*!
40 Construct the network address for the given \c hostname and \c port.
41 If \c hostname can be parsed as a numerical address then that's how
42 it's used, otherwise it's used as a host name. If \c hostname ends
43 in ":[0-9]+" then that suffix is extracted and used as the port,
44 overridding the port parameter. The resulting port must be a valid
45 port number (zero is not a valid port number) otherwise \c XSocketAddress
46 is thrown with an error of \c XSocketAddress::kBadPort. The hostname
47 is not resolved by the c'tor; use \c resolve to do that.
48 */
49 CNetworkAddress(const CString& hostname, int port);
50
51 CNetworkAddress(const CNetworkAddress&);
52
53 ~CNetworkAddress();
54
55 CNetworkAddress& operator=(const CNetworkAddress&);
56
57 //! @name manipulators
58 //@{
59
60 //! Resolve address
61 /*!
62 Resolves the hostname to an address. This can be done any number of
63 times and is done automatically by the c'tor taking a hostname.
64 Throws XSocketAddress if resolution is unsuccessful, after which
65 \c isValid returns false until the next call to this method.
66 */
67 void resolve();
68
69 //@}
70 //! @name accessors
71 //@{
72
73 //! Check address equality
74 /*!
75 Returns true if this address is equal to \p address.
76 */
77 bool operator==(const CNetworkAddress& address) const;
78
79 //! Check address inequality
80 /*!
81 Returns true if this address is not equal to \p address.
82 */
83 bool operator!=(const CNetworkAddress& address) const;
84
85 //! Check address validity
86 /*!
87 Returns true if this is not the invalid address.
88 */
89 bool isValid() const;
90
91 //! Get address
92 /*!
93 Returns the address in the platform's native network address
94 structure.
95 */
96 const CArchNetAddress& getAddress() const;
97
98 //! Get port
99 /*!
100 Returns the port passed to the c'tor as a suffix to the hostname,
101 if that existed, otherwise as passed directly to the c'tor.
102 */
103 int getPort() const;
104
105 //! Get hostname
106 /*!
107 Returns the hostname passed to the c'tor sans any port suffix.
108 */
109 CString getHostname() const;
110
111 //@}
112
113private:
114 void checkPort();
115
116private:
117 CArchNetAddress m_address;
118 CString m_hostname;
119 int m_port;
120};
121
122#endif
Note: See TracBrowser for help on using the repository browser.