Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
socket_addr.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_address/target_posix/roc_address/socket_addr.h
10
//! @brief Socket address.
11
12
#ifndef ROC_ADDRESS_SOCKET_ADDR_H_
13
#define ROC_ADDRESS_SOCKET_ADDR_H_
14
15
#include <netinet/in.h>
16
#include <sys/socket.h>
17
18
#include "
roc_address/addr_family.h
"
19
#include "
roc_core/attributes.h
"
20
#include "
roc_core/stddefs.h
"
21
22
namespace
roc
{
23
namespace
address
{
24
25
//! Socket address.
26
class
SocketAddr
{
27
public
:
28
//! Construct empty address.
29
SocketAddr
();
30
31
//! Clear address.
32
void
clear
();
33
34
//! Check whether host and port are set.
35
bool
has_host_port
()
const
;
36
37
//! Set host address.
38
ROC_ATTR_NODISCARD
bool
set_host_port
(
AddrFamily
type,
const
char
* host,
int
port
);
39
40
//! Set host address, auto-detect family.
41
ROC_ATTR_NODISCARD
bool
set_host_port_auto
(
const
char
* host,
int
port
);
42
43
//! Set address from sockaddr struct.
44
ROC_ATTR_NODISCARD
bool
set_host_port_saddr
(
const
sockaddr* sa);
45
46
//! Get IP version (IPv4 or IPv6).
47
AddrFamily
family
()
const
;
48
49
//! Check whether this is multicast address.
50
bool
multicast
()
const
;
51
52
//! Get host IP address.
53
ROC_ATTR_NODISCARD
bool
get_host
(
char
* buf,
size_t
bufsz)
const
;
54
55
//! Get address port.
56
int
port
()
const
;
57
58
//! Get sockaddr struct.
59
sockaddr*
saddr
();
60
61
//! Get sockaddr struct.
62
const
sockaddr*
saddr
()
const
;
63
64
//! Get sockaddr struct length.
65
socklen_t
slen
()
const
;
66
67
//! Get maximum allowed sockaddr struct length.
68
socklen_t
max_slen
()
const
;
69
70
//! Convert to bool.
71
operator
const
struct
unspecified_bool *()
const
;
72
73
//! Compare addresses.
74
bool
operator==
(
const
SocketAddr
& other)
const
;
75
76
//! Compare addresses.
77
bool
operator!=
(
const
SocketAddr
& other)
const
;
78
79
enum
{
80
// An estimate maximum length of a string representation of an address.
81
MaxStrLen = 196
82
};
83
84
private
:
85
static
socklen_t saddr_size_(sa_family_t
family
);
86
87
sa_family_t saddr_family_()
const
;
88
89
bool
set_host_port_ipv4_(
const
char
* ip,
int
port
);
90
bool
set_host_port_ipv6_(
const
char
* ip,
int
port
);
91
92
union
{
93
sockaddr_in addr4;
94
sockaddr_in6 addr6;
95
} saddr_;
96
};
97
98
}
// namespace address
99
}
// namespace roc
100
101
#endif
// ROC_ADDRESS_SOCKET_ADDR_H_
addr_family.h
Address family.
attributes.h
Compiler attributes.
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition
attributes.h:31
roc::address::SocketAddr::operator==
bool operator==(const SocketAddr &other) const
Compare addresses.
roc::address::SocketAddr::saddr
sockaddr * saddr()
Get sockaddr struct.
roc::address::SocketAddr::family
AddrFamily family() const
Get IP version (IPv4 or IPv6).
roc::address::SocketAddr::port
int port() const
Get address port.
roc::address::SocketAddr::operator!=
bool operator!=(const SocketAddr &other) const
Compare addresses.
roc::address::SocketAddr::set_host_port_auto
ROC_ATTR_NODISCARD bool set_host_port_auto(const char *host, int port)
Set host address, auto-detect family.
roc::address::SocketAddr::has_host_port
bool has_host_port() const
Check whether host and port are set.
roc::address::SocketAddr::set_host_port
ROC_ATTR_NODISCARD bool set_host_port(AddrFamily type, const char *host, int port)
Set host address.
roc::address::SocketAddr::SocketAddr
SocketAddr()
Construct empty address.
roc::address::SocketAddr::max_slen
socklen_t max_slen() const
Get maximum allowed sockaddr struct length.
roc::address::SocketAddr::slen
socklen_t slen() const
Get sockaddr struct length.
roc::address::SocketAddr::set_host_port_saddr
ROC_ATTR_NODISCARD bool set_host_port_saddr(const sockaddr *sa)
Set address from sockaddr struct.
roc::address::SocketAddr::clear
void clear()
Clear address.
roc::address::SocketAddr::get_host
ROC_ATTR_NODISCARD bool get_host(char *buf, size_t bufsz) const
Get host IP address.
roc::address::SocketAddr::saddr
const sockaddr * saddr() const
Get sockaddr struct.
roc::address::SocketAddr::multicast
bool multicast() const
Check whether this is multicast address.
roc::address
URIs and addresses.
roc::address::AddrFamily
AddrFamily
Address family.
Definition
addr_family.h:19
roc
Root namespace.
stddefs.h
Commonly used types and functions.
roc_address
target_posix
roc_address
socket_addr.h
Generated by
1.17.0