Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ReadMailReallyFast
code
Commits
d2dd3f94
Commit
d2dd3f94
authored
2 years ago
by
Leon Dietrich
Committed by
Benny Baumann
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: unix socketaddr generation
parent
44e50bf6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/net/sock_address_factory.cpp
+17
-4
17 additions, 4 deletions
src/net/sock_address_factory.cpp
src/net/socketaddress.hpp
+3
-3
3 additions, 3 deletions
src/net/socketaddress.hpp
test/address_tests.cpp
+1
-1
1 addition, 1 deletion
test/address_tests.cpp
with
21 additions
and
8 deletions
src/net/sock_address_factory.cpp
+
17
−
4
View file @
d2dd3f94
...
...
@@ -162,6 +162,17 @@ namespace rmrf::net {
}
std
::
list
<
socketaddr
>
get_socketaddr_list
(
const
std
::
string
&
interface_description
,
const
std
::
string
&
service_or_port
,
const
socket_t
socket_type
)
{
if
(
socket_type
==
socket_t
::
UNIX
)
{
sockaddr_un
storage
;
strncpy
(
storage
.
sun_path
,
interface_description
.
c_str
(),
sizeof
(
storage
.
sun_path
));
// Required as the automatic initialization of sockaddr_un is broken on linux.
// This will be optimized out on platforms where it is not.
((
sockaddr
*
)
&
storage
)
->
sa_family
=
AF_UNIX
;
const
socketaddr
sa
{
storage
};
std
::
list
<
socketaddr
>
l
=
{
sa
};
return
l
;
}
int
port
=
-
1
;
try
{
...
...
@@ -177,9 +188,9 @@ namespace rmrf::net {
return
l
;
}
// Attempt DNS lookup
struct
addrinfo
hints
=
{};
struct
addrinfo
*
addrs
;
struct
addrinfo
*
addrs
=
nullptr
;
hints
.
ai_family
=
AF_INET6
;
hints
.
ai_socktype
=
get_socket_type_hint
(
socket_type
);
...
...
@@ -190,8 +201,10 @@ namespace rmrf::net {
dns_error
=
getaddrinfo
(
interface_description
.
c_str
(),
NULL
,
&
hints
,
&
addrs
);
if
(
dns_error
!=
0
)
{
freeaddrinfo
(
addrs
);
throw
std
::
invalid_argument
(
"Something went wrong with the DNS lookup. Error code: "
+
format_network_error
(
dns_error
));
if
(
addrs
!=
nullptr
)
{
freeaddrinfo
(
addrs
);
}
throw
std
::
invalid_argument
(
"Something went wrong with the DNS lookup. Error: "
+
format_network_error
(
dns_error
));
}
}
...
...
This diff is collapsed.
Click to expand it.
src/net/socketaddress.hpp
+
3
−
3
View file @
d2dd3f94
...
...
@@ -70,7 +70,7 @@ public:
template
<
typename
T
,
typename
std
::
enable_if
<
has_field
<
T
>
::
value
,
T
>::
type
*
=
nullptr
>
explicit
socketaddr
(
T
*
other
)
:
addr
{},
len
{}
{
if
(
other
->*
(
family_map
<
T
>::
sa_family_field
)
!=
family_map
<
T
>::
sa_family
)
{
throw
netio_exception
(
"Address family mismatch in sockaddr structure."
);
throw
netio_exception
(
"
Unable to construct socketaddr object.
Address family mismatch in sockaddr structure."
);
}
memcpy
(
&
addr
,
other
,
sizeof
(
T
));
...
...
@@ -88,7 +88,7 @@ public:
template
<
typename
T
,
typename
std
::
enable_if
<
has_field
<
T
>
::
value
,
T
>::
type
*
=
nullptr
>
explicit
socketaddr
(
const
T
&
other
)
:
addr
{},
len
{}
{
if
(
other
.
*
(
family_map
<
T
>::
sa_family_field
)
!=
family_map
<
T
>::
sa_family
)
{
throw
netio_exception
(
"Address family mismatch in sockaddr structure."
);
throw
netio_exception
(
"
Unable to construct socketaddr object from reference.
Address family mismatch in sockaddr structure."
);
}
memcpy
(
&
addr
,
&
other
,
sizeof
(
T
));
...
...
@@ -98,7 +98,7 @@ public:
template
<
typename
T
>
socketaddr
&
operator
=
(
const
T
*
rhs
)
{
if
(
rhs
->*
(
family_map
<
T
>::
sa_family_field
)
!=
family_map
<
T
>::
sa_family
)
{
throw
netio_exception
(
"Address family mismatch in sockaddr structure."
);
throw
netio_exception
(
"
Unable to construct socketaddr object from rhs.
Address family mismatch in sockaddr structure."
);
}
memcpy
(
&
addr
,
rhs
,
sizeof
(
T
));
...
...
This diff is collapsed.
Click to expand it.
test/address_tests.cpp
+
1
−
1
View file @
d2dd3f94
...
...
@@ -65,5 +65,5 @@ BOOST_AUTO_TEST_CASE(Socketaddr_comparison) {
BOOST_AUTO_TEST_CASE
(
Unix_socket_construction_test
)
{
const
auto
sa
=
get_first_general_socketaddr
(
"/tmp/9Lq7BNBnBycd6nxy.socket"
,
""
,
socket_t
::
UNIX
);
BOOST_CHECK_EQUAL
(
sa
.
str
(),
"FileSocket /tmp/9Lq7BNBnBycd6nxy.socket"
);
BOOST_CHECK_EQUAL
(
sa
.
str
(),
"
SocketAddress:
FileSocket /tmp/9Lq7BNBnBycd6nxy.socket"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment