Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
senf
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
wiback
senf
Commits
e0139e03
Commit
e0139e03
authored
17 years ago
by
jkaeber
Browse files
Options
Downloads
Patches
Plain Diff
Implemented void hardwareAddress(const MACAddress &newAddress)
parent
8bc82c36
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
Socket/NetdeviceController.cc
+8
-0
8 additions, 0 deletions
Socket/NetdeviceController.cc
Socket/NetdeviceController.hh
+10
-5
10 additions, 5 deletions
Socket/NetdeviceController.hh
Socket/NetdeviceController.test.cc
+25
-4
25 additions, 4 deletions
Socket/NetdeviceController.test.cc
with
43 additions
and
9 deletions
Socket/NetdeviceController.cc
+
8
−
0
View file @
e0139e03
...
...
@@ -68,6 +68,14 @@ prefix_ senf::MACAddress senf::NetdeviceController::hardwareAddress()
return
senf
::
MACAddress
::
from_data
(
ifr
.
ifr_hwaddr
.
sa_data
);
}
prefix_
void
senf
::
NetdeviceController
::
hardwareAddress
(
const
MACAddress
&
newAddress
)
{
struct
ifreq
ifr
;
ifrName
(
ifr
);
ifr
.
ifr_hwaddr
.
sa_family
=
1
;
// TODO: lookup named constant; PF_LOCAL ???
std
::
copy
(
newAddress
.
begin
(),
newAddress
.
end
(),
ifr
.
ifr_hwaddr
.
sa_data
);
doIoctl
(
ifr
,
SIOCSIFHWADDR
);
}
prefix_
int
senf
::
NetdeviceController
::
mtu
()
const
{
...
...
This diff is collapsed.
Click to expand it.
Socket/NetdeviceController.hh
+
10
−
5
View file @
e0139e03
...
...
@@ -50,12 +50,17 @@ namespace senf {
NetdeviceController
(
int
interface_index
);
virtual
~
NetdeviceController
();
MACAddress
hardwareAddress
()
const
;
std
::
string
interfaceName
()
const
;
int
interfaceIndex
()
const
;
///< return the interface index of the interface
int
mtu
()
const
;
void
mtu
(
int
new_mtu
)
const
;
int
interfaceIndex
()
const
;
///< return the interface index
MACAddress
hardwareAddress
()
const
;
///< return hardware address
void
hardwareAddress
(
const
MACAddress
&
newAddress
);
///< set hardware address
std
::
string
interfaceName
()
const
;
///< return interface name
void
interfaceName
(
const
std
::
string
&
newName
)
const
;
///< set interface name
int
mtu
()
const
;
///< return the Maximum Transmission Unit
void
mtu
(
int
new_mtu
)
const
;
//< set the Maximum Transmission Unit
private:
void
openSocket
();
void
doIoctl
(
ifreq
&
ifr
,
int
request
)
const
;
...
...
This diff is collapsed.
Click to expand it.
Socket/NetdeviceController.test.cc
+
25
−
4
View file @
e0139e03
...
...
@@ -27,6 +27,7 @@
// Custom includes
#include
"NetdeviceController.hh"
#include
"Protocols/Raw/MACAddress.hh"
#include
"../Utils/auto_unit_test.hh"
#include
<boost/test/test_tools.hpp>
...
...
@@ -34,10 +35,30 @@
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST
(
NetdeviceController
)
{
// senf::NetdeviceController ctrl ("eth0");
// std::cout << ctrl.hardwareAddress() << "\n";
BOOST_AUTO_UNIT_TEST
(
NetdeviceController
)
{
senf
::
NetdeviceController
ctrl
(
"wlan0"
);
std
::
cout
<<
"name: "
<<
ctrl
.
interfaceName
()
<<
"
\n
"
;
senf
::
MACAddress
oldAddr
(
ctrl
.
hardwareAddress
());
int
oldMTU
=
ctrl
.
mtu
();
std
::
cout
<<
"hw addr: "
<<
oldAddr
<<
"
\n
"
;
std
::
cout
<<
"mtu: "
<<
oldMTU
<<
"
\n
"
;
if
(
getuid
()
!=
0
)
{
BOOST_WARN_MESSAGE
(
false
,
"Cannot run some tests of senf::NetdeviceController as non-root user"
);
return
;
}
ctrl
.
mtu
(
oldMTU
-
16
);
std
::
cout
<<
"new mtu: "
<<
ctrl
.
mtu
()
<<
"
\n
"
;
ctrl
.
mtu
(
oldMTU
);
senf
::
MACAddress
newAddr
(
senf
::
MACAddress
::
from_string
(
"00:18:de:2e:ec:00"
));
ctrl
.
hardwareAddress
(
newAddr
);
std
::
cout
<<
"new hw addr: "
<<
ctrl
.
hardwareAddress
()
<<
"
\n
"
;
ctrl
.
hardwareAddress
(
oldAddr
);
}
///////////////////////////////cc.e////////////////////////////////////////
...
...
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