socket_name.h Source File - ClanLib SDK
Description: socket_name.h Source File

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
44 class SocketName
45 {
46 public:
48
50 SocketName();
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
103 SocketName to_ipv4();
104
106 SocketName to_hostname();
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}
clan::SocketName::SocketName
SocketName(const std::string &address, const std::string &port)
Constructs a SocketName.
clan::SocketName::SocketName
SocketName()
Constructs a new socket name.
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::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::operator<
bool operator<(const SocketName &other_instance) const
Returns true if the other address is less.
clan::SocketName::to_hostname
SocketName to_hostname()
Create socket name that uses the hostname as its address.
clan::SocketName::lookup_ipv4
std::string lookup_ipv4() const
Perform a DNS lookup, if needed, for the IP v4 address.
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::get_address
std::string get_address() const
Returns the address part of the socket name.
clan::SocketName::to_ipv4
SocketName to_ipv4()
Create socket name that uses the IP v4 address as its address.
clan::SocketName::operator>
bool operator>(const SocketName &other_instance) const
Returns true if the other address is greater.
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 objects are the same.
clan::SocketName::get_port
std::string get_port() const
Returns the port part of the socket name.
clan::SocketName::SocketName
SocketName(const std::string &port)
Constructs a SocketName.
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
Definition clanapp.h:36