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
d03e6e19
Commit
d03e6e19
authored
17 years ago
by
tho
Browse files
Options
Downloads
Patches
Plain Diff
first working netdeviceController
parent
d435e489
No related branches found
Branches containing commit
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
+66
-15
66 additions, 15 deletions
Socket/NetdeviceController.cc
Socket/NetdeviceController.hh
+13
-4
13 additions, 4 deletions
Socket/NetdeviceController.hh
Socket/NetdeviceController.test.cc
+54
-0
54 additions, 0 deletions
Socket/NetdeviceController.test.cc
with
133 additions
and
19 deletions
Socket/NetdeviceController.cc
+
66
−
15
View file @
d03e6e19
// $Id
: BufferingPolicy.cc 533 2007-11-23 17:34:30Z g0dil
$
// $Id$
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
...
...
@@ -21,7 +21,7 @@
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
\brief
BufferingPolicy
non-inline non-template implementation
\brief
NetdeviceController
non-inline non-template implementation
*/
#include
"NetdeviceController.hh"
...
...
@@ -31,37 +31,88 @@
#include
<sys/socket.h>
#include
<sys/ioctl.h>
#include
<net/if.h>
#include
<netinet/ether.h>
#include
"../Utils/Exception.hh"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
prefix_
senf
::
NetdeviceController
::
NetdeviceController
(
std
::
string
const
interface_name
)
prefix_
senf
::
NetdeviceController
::
NetdeviceController
(
std
::
string
const
&
interface_name
)
{
sockfd_
=
::
socket
(
PF_PACKET
,
SOCK_DGRAM
,
0
);
if
(
sockfd_
<
0
)
throwErrno
();
interfacename_
=
interface_name
;
openSocket
();
struct
ifreq
ifr
;
::
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
interface_name
.
copy
(
ifr
.
ifr_name
,
IFNAMSIZ
);
doIoctl
(
ifr
,
SIOCGIFINDEX
);
ifindex_
=
ifr
.
ifr_ifindex
;
}
prefix_
senf
::
NetdeviceController
::
NetdeviceController
(
int
interface_index
)
{
openSocket
();
ifindex_
=
interface_index
;
}
prefix_
std
::
string
senf
::
NetdeviceController
::
interfaceName
()
{
struct
ifreq
ifr
;
set_ifr_name
(
ifr
);
return
std
::
string
(
ifr
.
ifr_name
);
}
prefix_
senf
::
MACAddress
senf
::
NetdeviceController
::
hardwareAddress
()
{
struct
ifreq
ifr
;
::
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
interfacename_
.
copy
(
ifr
.
ifr_name
,
IFNAMSIZ
);
if
(
::
ioctl
(
sockfd_
,
SIOCGIFHWADDR
,
&
ifr
)
<
0
)
throwErrno
();
return
senf
::
MACAddress
::
from_string
(
ether_ntoa
(
(
struct
ether_addr
*
)
ifr
.
ifr_hwaddr
.
sa_data
)
);
doIoctl
(
ifr
,
SIOCGIFHWADDR
);
return
senf
::
MACAddress
::
from_data
(
ifr
.
ifr_hwaddr
.
sa_data
);
}
prefix_
int
senf
::
NetdeviceController
::
mtu
()
{
struct
ifreq
ifr
;
set_ifr_name
(
ifr
);
doIoctl
(
ifr
,
SIOCGIFMTU
);
return
ifr
.
ifr_mtu
;
}
prefix_
void
senf
::
NetdeviceController
::
mtu
(
int
new_mtu
)
{
struct
ifreq
ifr
;
set_ifr_name
(
ifr
);
ifr
.
ifr_mtu
=
new_mtu
;
doIoctl
(
ifr
,
SIOCSIFMTU
);
}
prefix_
int
senf
::
NetdeviceController
::
interfaceIndex
()
{
return
ifindex_
;
}
prefix_
senf
::
NetdeviceController
::~
NetdeviceController
()
{
close
(
sockfd_
);
close
(
sockfd_
);
}
prefix_
void
senf
::
NetdeviceController
::
openSocket
()
{
sockfd_
=
::
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
sockfd_
<
0
)
throwErrno
();
}
prefix_
void
senf
::
NetdeviceController
::
set_ifr_name
(
ifreq
&
ifr
)
{
::
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
ifr
.
ifr_ifindex
=
ifindex_
;
if
(
::
ioctl
(
sockfd_
,
SIOCGIFNAME
,
&
ifr
)
<
0
)
throwErrno
();
}
prefix_
void
senf
::
NetdeviceController
::
doIoctl
(
ifreq
&
ifr
,
int
request
)
{
if
(
::
ioctl
(
sockfd_
,
request
,
&
ifr
)
<
0
)
throwErrno
();
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
...
...
This diff is collapsed.
Click to expand it.
Socket/NetdeviceController.hh
+
13
−
4
View file @
d03e6e19
// $Id
: AddressingPolicy.hh 296 2007-07-10 20:39:34Z g0dil
$
// $Id$
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
...
...
@@ -29,8 +29,10 @@
// Custom includes
#include
<string>
#include
<net/if.h>
#include
"Protocols/Raw/MACAddress.hh"
//#include "NetdeviceController.mpp"
///////////////////////////////hh.p////////////////////////////////////////
...
...
@@ -43,15 +45,22 @@ namespace senf {
class
NetdeviceController
{
public:
NetdeviceController
(
std
::
string
const
interface_name
);
NetdeviceController
(
std
::
string
const
&
interface_name
);
NetdeviceController
(
int
interface_index
);
virtual
~
NetdeviceController
();
MACAddress
hardwareAddress
();
std
::
string
interfaceName
();
int
interfaceIndex
();
int
mtu
();
void
mtu
(
int
new_mtu
);
private:
void
openSocket
();
void
doIoctl
(
ifreq
&
ifr
,
int
request
);
void
set_ifr_name
(
ifreq
&
ifr
);
int
sockfd_
;
std
::
str
in
g
i
nterfacename
_
;
in
t
i
findex
_
;
};
}
...
...
This diff is collapsed.
Click to expand it.
Socket/NetdeviceController.test.cc
0 → 100644
+
54
−
0
View file @
d03e6e19
// $Id$
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Unit tests
//#include "NetdeviceController.test.hh"
//#include "NetdeviceController.test.ih"
// Custom includes
#include
"NetdeviceController.hh"
#include
"../Utils/auto_unit_test.hh"
#include
<boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST
(
NetdeviceController
)
{
// senf::NetdeviceController ctrl ("eth0");
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// fill-column: 100
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// comment-column: 40
// End:
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