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
08552f39
Commit
08552f39
authored
Jul 03, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/ToString: UnmapV4() returns IPv4Address
parent
27002657
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
ToString.cxx
src/net/ToString.cxx
+9
-7
ToString.hxx
src/net/ToString.hxx
+1
-1
No files found.
src/net/ToString.cxx
View file @
08552f39
/*
* Copyright
(C) 2011-2017
Max Kellermann <max.kellermann@gmail.com>
* Copyright
2011-2019
Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -31,6 +31,7 @@
#include "ToString.hxx"
#include "Features.hxx"
#include "SocketAddress.hxx"
#include "IPv4Address.hxx"
#include <algorithm>
...
...
@@ -84,19 +85,20 @@ LocalAddressToString(const struct sockaddr_un &s_un, size_t size) noexcept
/**
* Convert "::ffff:127.0.0.1" to "127.0.0.1".
*/
static
Socket
Address
UnmapV4
(
SocketAddress
src
,
struct
sockaddr_in
&
buffer
)
noexcept
static
IPv4
Address
UnmapV4
(
SocketAddress
src
)
noexcept
{
assert
(
src
.
IsV4Mapped
());
const
auto
&
src6
=
*
(
const
struct
sockaddr_in6
*
)
src
.
GetAddress
();
memset
(
&
buffer
,
0
,
sizeof
(
buffer
));
struct
sockaddr_in
buffer
{};
buffer
.
sin_family
=
AF_INET
;
memcpy
(
&
buffer
.
sin_addr
,
((
const
char
*
)
&
src6
.
sin6_addr
)
+
12
,
sizeof
(
buffer
.
sin_addr
));
buffer
.
sin_port
=
src6
.
sin6_port
;
return
{
(
const
struct
sockaddr
*
)
&
buffer
,
sizeof
(
buffer
)
}
;
return
buffer
;
}
#endif
...
...
@@ -112,9 +114,9 @@ ToString(SocketAddress address) noexcept
#endif
#if defined(HAVE_IPV6) && defined(IN6_IS_ADDR_V4MAPPED)
struct
sockaddr_in
in
_buffer
;
IPv4Address
ipv4
_buffer
;
if
(
address
.
IsV4Mapped
())
address
=
UnmapV4
(
address
,
in_buffer
);
address
=
ipv4_buffer
=
UnmapV4
(
address
);
#endif
char
host
[
NI_MAXHOST
],
serv
[
NI_MAXSERV
];
...
...
src/net/ToString.hxx
View file @
08552f39
/*
* Copyright
(C) 2011-2017
Max Kellermann <max.kellermann@gmail.com>
* Copyright
2011-2019
Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
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