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
11396d4f
Commit
11396d4f
authored
Aug 20, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/SocketAddress: add method GetLocalRaw()
parent
4c6ae4e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
SocketAddress.cxx
src/net/SocketAddress.cxx
+27
-0
SocketAddress.hxx
src/net/SocketAddress.hxx
+13
-0
No files found.
src/net/SocketAddress.cxx
View file @
11396d4f
...
...
@@ -29,9 +29,14 @@
#include "config.h"
#include "SocketAddress.hxx"
#include "util/StringView.hxx"
#include <string.h>
#ifdef HAVE_UN
#include <sys/un.h>
#endif
#ifdef HAVE_TCP
#ifdef _WIN32
#include <ws2tcpip.h>
...
...
@@ -46,6 +51,28 @@ SocketAddress::operator==(SocketAddress other) const noexcept
return
size
==
other
.
size
&&
memcmp
(
address
,
other
.
address
,
size
)
==
0
;
}
#ifdef HAVE_UN
StringView
SocketAddress
::
GetLocalRaw
()
const
noexcept
{
if
(
IsNull
()
||
GetFamily
()
!=
AF_LOCAL
)
/* not applicable */
return
nullptr
;
const
auto
sun
=
(
const
struct
sockaddr_un
*
)
GetAddress
();
const
auto
start
=
(
const
char
*
)
sun
;
const
auto
path
=
sun
->
sun_path
;
const
size_t
header_size
=
path
-
start
;
if
(
size
<
header_size
)
/* malformed address */
return
nullptr
;
return
{
path
,
size
-
header_size
};
}
#endif
#ifdef HAVE_TCP
bool
...
...
src/net/SocketAddress.hxx
View file @
11396d4f
...
...
@@ -41,6 +41,8 @@
#include <sys/socket.h>
#endif
struct
StringView
;
/**
* An OO wrapper for struct sockaddr.
*/
...
...
@@ -94,6 +96,17 @@ public:
return
GetFamily
()
!=
AF_UNSPEC
;
}
#ifdef HAVE_UN
/**
* Extract the local socket path (which may begin with a null
* byte, denoting an "abstract" socket). The return value's
* "size" attribute includes the null terminator. Returns
* nullptr if not applicable.
*/
gcc_pure
StringView
GetLocalRaw
()
const
noexcept
;
#endif
#ifdef HAVE_TCP
/**
* Is this the IPv6 wildcard address (in6addr_any)?
...
...
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