Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
c7114f5c
Commit
c7114f5c
authored
Oct 12, 2018
by
Dominik Charousset
Committed by
Dominik Charousset
Oct 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use socket guard instead of calling close manually
parent
9bf9af2f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
+22
-4
libcaf_core/src/get_mac_addresses.cpp
libcaf_core/src/get_mac_addresses.cpp
+22
-4
No files found.
libcaf_core/src/get_mac_addresses.cpp
View file @
c7114f5c
#include "caf/config.hpp"
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/get_mac_addresses.hpp"
#include "caf/detail/get_mac_addresses.hpp"
#include "caf/config.hpp"
#include "caf/detail/socket_guard.hpp"
#if defined(CAF_MACOS) || defined(CAF_BSD) || defined(CAF_IOS)
#if defined(CAF_MACOS) || defined(CAF_BSD) || defined(CAF_IOS)
#include <sys/types.h>
#include <sys/types.h>
...
@@ -110,6 +130,7 @@ std::vector<iface_info> get_mac_addresses() {
...
@@ -110,6 +130,7 @@ std::vector<iface_info> get_mac_addresses() {
perror
(
"socket"
);
perror
(
"socket"
);
return
{};
return
{};
}
}
socket_guard
guard
{
sck
};
// query available interfaces
// query available interfaces
char
buf
[
1024
]
=
{
0
};
char
buf
[
1024
]
=
{
0
};
ifconf
ifc
;
ifconf
ifc
;
...
@@ -117,7 +138,6 @@ std::vector<iface_info> get_mac_addresses() {
...
@@ -117,7 +138,6 @@ std::vector<iface_info> get_mac_addresses() {
ifc
.
ifc_buf
=
buf
;
ifc
.
ifc_buf
=
buf
;
if
(
ioctl
(
sck
,
SIOCGIFCONF
,
&
ifc
)
<
0
)
{
if
(
ioctl
(
sck
,
SIOCGIFCONF
,
&
ifc
)
<
0
)
{
perror
(
"ioctl(SIOCGIFCONF)"
);
perror
(
"ioctl(SIOCGIFCONF)"
);
close
(
sck
);
return
{};
return
{};
}
}
std
::
vector
<
iface_info
>
result
;
std
::
vector
<
iface_info
>
result
;
...
@@ -132,7 +152,6 @@ std::vector<iface_info> get_mac_addresses() {
...
@@ -132,7 +152,6 @@ std::vector<iface_info> get_mac_addresses() {
// get mac address
// get mac address
if
(
ioctl
(
sck
,
SIOCGIFHWADDR
,
item
)
<
0
)
{
if
(
ioctl
(
sck
,
SIOCGIFHWADDR
,
item
)
<
0
)
{
perror
(
"ioctl(SIOCGIFHWADDR)"
);
perror
(
"ioctl(SIOCGIFHWADDR)"
);
close
(
sck
);
return
{};
return
{};
}
}
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
...
@@ -149,7 +168,6 @@ std::vector<iface_info> get_mac_addresses() {
...
@@ -149,7 +168,6 @@ std::vector<iface_info> get_mac_addresses() {
result
.
push_back
({
item
->
ifr_name
,
std
::
move
(
addr
)});
result
.
push_back
({
item
->
ifr_name
,
std
::
move
(
addr
)});
}
}
}
}
close
(
sck
);
return
result
;
return
result
;
}
}
...
...
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