socket_name.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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
34struct sockaddr;
35
36namespace clan
37{
40
41 class SocketName_Impl;
42
45 {
46 public:
48
51
55 SocketName(const std::string &port);
56
61 SocketName(const std::string &address, const std::string &port);
62
64 std::string get_address() const;
65
67 std::string get_port() const;
68
70 bool operator == (const SocketName &other_instance) const;
71
73
76 bool operator < (const SocketName &other_instance) const;
77
79
82 bool operator > (const SocketName &other_instance) const;
83
88 void set_name(const std::string &hostname, const std::string &port);
89
91 void set_address(const std::string &address);
92
94 void set_port(const std::string &port);
95
97 std::string lookup_ipv4() const;
98
100 std::string lookup_hostname() const;
101
104
107
109 void to_sockaddr(int domain, sockaddr *addr, int len) const;
110
112 void from_sockaddr(int domain, sockaddr *addr, int len);
113
114 private:
115 std::shared_ptr<SocketName_Impl> impl;
116 };
117
119}
Socket name; container class for an IP address and port.
Definition socket_name.h:45
SocketName(const std::string &address, 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.
std::string lookup_hostname() const
Perform a DNS lookup, if needed, for the hostname.
void set_address(const std::string &address)
Set the IP address.
bool operator<(const SocketName &other_instance) const
Returns true if the other address is less.
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 to_sockaddr(int domain, sockaddr *addr, int len) const
Fill the socket name into a C sockets sockaddr structure.
std::string get_address() const
Returns the address part of the socket name.
SocketName to_ipv4()
Create socket name that uses the IP v4 address as its address.
bool operator>(const SocketName &other_instance) const
Returns true if the other address is greater.
void set_port(const std::string &port)
Set the IP port.
bool operator==(const SocketName &other_instance) const
Returns true if objects are the same.
std::string get_port() const
Returns the port part of the socket name.
SocketName(const std::string &port)
Constructs a SocketName.
void set_name(const std::string &hostname, const std::string &port)
Set the socket name using a hostname and port.
Definition clanapp.h:36