Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
ede74349
Commit
ede74349
authored
Aug 21, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/SocketAddress: add GetSteadyPart()
parent
ba3b422c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
SocketAddress.cxx
src/net/SocketAddress.cxx
+37
-0
SocketAddress.hxx
src/net/SocketAddress.hxx
+11
-0
No files found.
src/net/SocketAddress.cxx
View file @
ede74349
...
...
@@ -107,4 +107,41 @@ SocketAddress::GetPort() const noexcept
}
}
static
constexpr
ConstBuffer
<
void
>
GetSteadyPart
(
const
struct
sockaddr_in
&
address
)
noexcept
{
return
{
&
address
.
sin_addr
,
sizeof
(
address
.
sin_addr
)};
}
static
constexpr
ConstBuffer
<
void
>
GetSteadyPart
(
const
struct
sockaddr_in6
&
address
)
noexcept
{
return
{
&
address
.
sin6_addr
,
sizeof
(
address
.
sin6_addr
)};
}
#endif
ConstBuffer
<
void
>
SocketAddress
::
GetSteadyPart
()
const
noexcept
{
if
(
IsNull
())
return
nullptr
;
switch
(
GetFamily
())
{
#ifdef HAVE_UN
case
AF_LOCAL
:
return
GetLocalRaw
().
ToVoid
();
#endif
#ifdef HAVE_TCP
case
AF_INET
:
return
::
GetSteadyPart
(
*
(
const
struct
sockaddr_in
*
)(
const
void
*
)
GetAddress
());
case
AF_INET6
:
return
::
GetSteadyPart
(
*
(
const
struct
sockaddr_in6
*
)(
const
void
*
)
GetAddress
());
#endif
default
:
return
nullptr
;
}
}
src/net/SocketAddress.hxx
View file @
ede74349
...
...
@@ -41,6 +41,7 @@
#include <sys/socket.h>
#endif
template
<
typename
T
>
struct
ConstBuffer
;
struct
StringView
;
/**
...
...
@@ -127,6 +128,16 @@ public:
unsigned
GetPort
()
const
noexcept
;
#endif
/**
* Return a buffer pointing to the "steady" portion of the
* address, i.e. without volatile parts like the port number.
* This buffer is useful for hashing the address, but not so
* much for anything else. Returns nullptr if the address is
* not supported.
*/
gcc_pure
ConstBuffer
<
void
>
GetSteadyPart
()
const
noexcept
;
gcc_pure
bool
operator
==
(
const
SocketAddress
other
)
const
noexcept
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment