socket_name.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28
29
30 #pragma once
31
32 #include <memory>
33
34 struct sockaddr;
35
36 namespace clan
37 {
40
41 class SocketName_Impl;
42
44 class SocketName
45 {
48
49 public:
51
53 SocketName();
54
58 SocketName(const std::string &port);
59
64 SocketName(const std::string &address, const std::string &port);
65
69
70 public:
72 std::string get_address() const;
73
75 std::string get_port() const;
76
78 bool operator == (const SocketName &other_instance) const;
79
81
84 bool operator < (const SocketName &other_instance) const;
85
87
90 bool operator > (const SocketName &other_instance) const;
91
95
96 public:
101 void set_name(const std::string &hostname, const std::string &port);
102
104 void set_address(const std::string &address);
105
107 void set_port(const std::string &port);
108
110 std::string lookup_ipv4() const;
111
113 std::string lookup_hostname() const;
114
116 SocketName to_ipv4();
117
119 SocketName to_hostname();
120
122 void to_sockaddr(int domain, sockaddr *addr, int len) const;
123
125 void from_sockaddr(int domain, sockaddr *addr, int len);
126
130
131 private:
132 std::shared_ptr<SocketName_Impl> impl;
134 };
135
136 }
137
clan
Definition: clanapp.h:35
clan::SocketName::operator<
bool operator<(const SocketName &other_instance) const
Returns true if the other address is less.
clan::SocketName::lookup_hostname
std::string lookup_hostname() const
Perform a DNS lookup, if needed, for the hostname.
clan::SocketName::set_address
void set_address(const std::string &address)
Set the IP address.
clan::SocketName::set_name
void set_name(const std::string &hostname, const std::string &port)
Set the socket name using a hostname and port.
clan::SocketName::to_hostname
SocketName to_hostname()
Create socket name that uses the hostname as its address.
clan::SocketName
Socket name; container class for an IP address and port.
Definition: socket_name.h:44
clan::SocketName::lookup_ipv4
std::string lookup_ipv4() const
Perform a DNS lookup, if needed, for the IP v4 address.
clan::StyleTokenType::string
@ keyword
clan::SocketName::get_port
std::string get_port() const
Returns the port part of the socket name.
clan::SocketName::get_address
std::string get_address() const
Returns the address part of the socket name.
clan::SocketName::SocketName
SocketName()
Constructs a new socket name.
clan::SocketName::to_ipv4
SocketName to_ipv4()
Create socket name that uses the IP v4 address as its address.
clan::SocketName::from_sockaddr
void from_sockaddr(int domain, sockaddr *addr, int len)
Get the socket name from a C sockets sockaddr structure.
clan::SocketName::set_port
void set_port(const std::string &port)
Set the IP port.
clan::SocketName::operator>
bool operator>(const SocketName &other_instance) const
Returns true if the other address is greater.
clan::SocketName::to_sockaddr
void to_sockaddr(int domain, sockaddr *addr, int len) const
Fill the socket name into a C sockets sockaddr structure.
clan::SocketName::operator==
bool operator==(const SocketName &other_instance) const
Returns true if objects are the same.