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
8157ddf3
"README.rst" did not exist on "1385bcf3b2551e8ac58956a746d51c46dfde7431"
Commit
8157ddf3
authored
15 years ago
by
g0dil
Browse files
Options
Downloads
Patches
Plain Diff
Socket: Implement NetdeviceController socket sharing
parent
7f6bb6bb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Socket/NetdeviceController.cc
+33
-12
33 additions, 12 deletions
Socket/NetdeviceController.cc
Socket/NetdeviceController.hh
+14
-4
14 additions, 4 deletions
Socket/NetdeviceController.hh
with
47 additions
and
16 deletions
Socket/NetdeviceController.cc
+
33
−
12
View file @
8157ddf3
...
...
@@ -37,8 +37,8 @@
///////////////////////////////cc.p////////////////////////////////////////
prefix_
senf
::
NetdeviceController
::
NetdeviceController
(
std
::
string
const
&
interface_name
)
:
sockfd_
(
sockfd
())
{
openSocket
();
struct
ifreq
ifr
;
::
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
interface_name
.
copy
(
ifr
.
ifr_name
,
IFNAMSIZ
);
...
...
@@ -47,8 +47,8 @@ prefix_ senf::NetdeviceController::NetdeviceController(std::string const & inter
}
prefix_
senf
::
NetdeviceController
::
NetdeviceController
(
int
interface_index
)
:
sockfd_
(
sockfd
())
{
openSocket
();
ifindex_
=
interface_index
;
}
...
...
@@ -171,14 +171,7 @@ prefix_ int senf::NetdeviceController::interfaceIndex()
prefix_
senf
::
NetdeviceController
::~
NetdeviceController
()
{
close
(
sockfd_
);
}
prefix_
void
senf
::
NetdeviceController
::
openSocket
()
{
sockfd_
=
::
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
sockfd_
<
0
)
SENF_THROW_SYSTEM_EXCEPTION
(
"Could not open socket for NetdeviceController."
);
close
(
sockfd_
->
fd
);
}
prefix_
void
senf
::
NetdeviceController
::
ifrName
(
ifreq
&
ifr
)
...
...
@@ -186,7 +179,7 @@ prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr)
{
::
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
ifr
.
ifr_ifindex
=
ifindex_
;
if
(
::
ioctl
(
sockfd_
,
SIOCGIFNAME
,
&
ifr
)
<
0
)
if
(
::
ioctl
(
sockfd_
->
fd
,
SIOCGIFNAME
,
&
ifr
)
<
0
)
SENF_THROW_SYSTEM_EXCEPTION
(
"NetdeviceController"
)
<<
" could not discover the name of the interface with index "
<<
ifindex_
<<
"."
;
}
...
...
@@ -194,10 +187,38 @@ prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr)
prefix_
void
senf
::
NetdeviceController
::
doIoctl
(
ifreq
&
ifr
,
int
request
)
const
{
if
(
::
ioctl
(
sockfd_
,
request
,
&
ifr
)
<
0
)
if
(
::
ioctl
(
sockfd_
->
fd
,
request
,
&
ifr
)
<
0
)
SENF_THROW_SYSTEM_EXCEPTION
(
"NetdeviceController::doIoctl failed."
);
}
///////////////////////////////////////////////////////////////////////////
// senf::NetdeviceController::SockFd
prefix_
senf
::
NetdeviceController
::
SockFd
::
SockFd
()
:
fd
(
::
socket
(
PF_INET
,
SOCK_DGRAM
,
0
))
{
if
(
fd
<
0
)
SENF_THROW_SYSTEM_EXCEPTION
(
"Could not open socket for NetdeviceController."
);
}
prefix_
senf
::
NetdeviceController
::
SockFd
::~
SockFd
()
{
::
close
(
fd
);
}
prefix_
senf
::
NetdeviceController
::
SockFd
::
ptr
senf
::
NetdeviceController
::
sockfd
()
{
static
boost
::
weak_ptr
<
SockFd
>
sockfd
;
if
(
sockfd
.
expired
())
{
SockFd
::
ptr
newsockfd
(
new
SockFd
());
sockfd
=
newsockfd
;
return
newsockfd
;
}
return
sockfd
.
lock
();
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "NetdeviceController.mpp"
...
...
This diff is collapsed.
Click to expand it.
Socket/NetdeviceController.hh
+
14
−
4
View file @
8157ddf3
...
...
@@ -29,6 +29,8 @@
// Custom includes
#include
<string>
#include
<boost/shared_ptr.hpp>
#include
<boost/weak_ptr.hpp>
#include
"Protocols/Raw/MACAddress.hh"
...
...
@@ -49,9 +51,9 @@ namespace senf {
class
NetdeviceController
{
public:
NetdeviceController
(
std
::
string
const
&
interface_name
);
explicit
NetdeviceController
(
std
::
string
const
&
interface_name
);
///< Construct a new controller for the given interface name.
NetdeviceController
(
int
interface_index
);
explicit
NetdeviceController
(
int
interface_index
);
///< Construct a new controller for the given interface index.
virtual
~
NetdeviceController
();
...
...
@@ -90,11 +92,19 @@ namespace senf {
void
up
();
///< ifconfig up interface
void
down
();
///< ifconfig down interface
struct
SockFd
{
typedef
boost
::
shared_ptr
<
SockFd
>
ptr
;
int
fd
;
SockFd
();
~
SockFd
();
};
static
SockFd
::
ptr
sockfd
();
private
:
void
openSocket
();
void
doIoctl
(
ifreq
&
ifr
,
int
request
)
const
;
void
ifrName
(
ifreq
&
ifr
)
const
;
int
sockfd_
;
SockFd
::
ptr
sockfd_
;
int
ifindex_
;
};
...
...
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