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
dfc1f634
Commit
dfc1f634
authored
Aug 21, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/SocketAddress: add IsV4Mapped()
parent
94092f1f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
13 deletions
+14
-13
SocketAddress.cxx
src/net/SocketAddress.cxx
+6
-0
SocketAddress.hxx
src/net/SocketAddress.hxx
+6
-0
ToString.cxx
src/net/ToString.cxx
+2
-13
No files found.
src/net/SocketAddress.cxx
View file @
dfc1f634
...
...
@@ -82,6 +82,12 @@ SocketAddress::IsV6Any() const noexcept
return
GetFamily
()
==
AF_INET6
&&
IPv6Address
(
*
this
).
IsAny
();
}
bool
SocketAddress
::
IsV4Mapped
()
const
noexcept
{
return
GetFamily
()
==
AF_INET6
&&
IPv6Address
(
*
this
).
IsV4Mapped
();
}
unsigned
SocketAddress
::
GetPort
()
const
noexcept
{
...
...
src/net/SocketAddress.hxx
View file @
dfc1f634
...
...
@@ -115,6 +115,12 @@ public:
bool
IsV6Any
()
const
noexcept
;
/**
* Is this an IPv4 address mapped inside struct sockaddr_in6?
*/
gcc_pure
bool
IsV4Mapped
()
const
noexcept
;
/**
* Extract the port number. Returns 0 if not applicable.
*/
gcc_pure
...
...
src/net/ToString.cxx
View file @
dfc1f634
...
...
@@ -81,24 +81,13 @@ LocalAddressToString(const struct sockaddr_un &s_un, size_t size) noexcept
#if defined(HAVE_IPV6) && defined(IN6_IS_ADDR_V4MAPPED)
gcc_pure
static
bool
IsV4Mapped
(
SocketAddress
address
)
noexcept
{
if
(
address
.
GetFamily
()
!=
AF_INET6
)
return
false
;
const
auto
&
a6
=
*
(
const
struct
sockaddr_in6
*
)
address
.
GetAddress
();
return
IN6_IS_ADDR_V4MAPPED
(
&
a6
.
sin6_addr
);
}
/**
* Convert "::ffff:127.0.0.1" to "127.0.0.1".
*/
static
SocketAddress
UnmapV4
(
SocketAddress
src
,
struct
sockaddr_in
&
buffer
)
noexcept
{
assert
(
IsV4Mapped
(
src
));
assert
(
src
.
IsV4Mapped
(
));
const
auto
&
src6
=
*
(
const
struct
sockaddr_in6
*
)
src
.
GetAddress
();
memset
(
&
buffer
,
0
,
sizeof
(
buffer
));
...
...
@@ -124,7 +113,7 @@ ToString(SocketAddress address) noexcept
#if defined(HAVE_IPV6) && defined(IN6_IS_ADDR_V4MAPPED)
struct
sockaddr_in
in_buffer
;
if
(
IsV4Mapped
(
address
))
if
(
address
.
IsV4Mapped
(
))
address
=
UnmapV4
(
address
,
in_buffer
);
#endif
...
...
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