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 
45 {
48 
49 public:
51 
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 
117 
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 
std::string lookup_hostname() const
Perform a DNS lookup, if needed, for the hostname.
std::string get_port() const
Returns the port part of the socket name.
SocketName(const std::string &address, const std::string &port)
Constructs a SocketName.
void set_port(const std::string &port)
Set the IP port.
SocketName to_hostname()
Create socket name that uses the hostname as its address.
std::string lookup_ipv4() const
Perform a DNS lookup, if needed, for the IP v4 address.
void set_address(const std::string &address)
Set the IP address.
SocketName(const std::string &port)
Constructs a SocketName.
SocketName()
Constructs a new socket name.
void from_sockaddr(int domain, sockaddr *addr, int len)
Get the socket name from a C sockets sockaddr structure.
void set_name(const std::string &hostname, const std::string &port)
Set the socket name using a hostname and port.
Socket name; container class for an IP address and port.
Definition: socket_name.h:45
SocketName to_ipv4()
Create socket name that uses the IP v4 address as its address.
Definition: clanapp.h:36
bool operator>(const SocketName &other_instance) const
Returns true if the other address is greater.
void to_sockaddr(int domain, sockaddr *addr, int len) const
Fill the socket name into a C sockets sockaddr structure.
bool operator==(const SocketName &other_instance) const
Returns true if objects are the same.
bool operator<(const SocketName &other_instance) const
Returns true if the other address is less.
std::string get_address() const
Returns the address part of the socket name.