INetSocketProtocol.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #include "INetSocketProtocol.hh"
18 //#include "INetSocketProtocol.ih"
19 
20 // Custom includes
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <net/if.h>
24 #include <senf/Utils/Exception.hh>
25 
26 //#include "INetSocketProtocol.mpp"
27 #define prefix_
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 // senf::INetSocketProtocol
32 
33 prefix_ void senf::INetSocketProtocol::bindInterface(std::string const & iface)
34  const
35 {
36  if (::setsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface.c_str(), iface.size()) < 0)
37  SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(SO_BINDTODEVICE)");
38 }
39 
41 {
42  char iface[IFNAMSIZ];
43  socklen_t size (sizeof(iface));
44  ::memset(iface, 0, sizeof(iface));
45  if (::getsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface, &size) < 0)
46  SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(SO_BINDTODEVICE)");
47  iface[size < IFNAMSIZ ? size : IFNAMSIZ-1] = 0;
48  return iface;
49 }
50 
51 //-/////////////////////////////////////////////////////////////////////////////////////////////////
52 // senf::IPv4SocketProtocol
53 
54 //-/////////////////////////////////////////////////////////////////////////////////////////////////
55 // senf::IPv6SocketProtocol
56 
57 //-/////////////////////////////////////////////////////////////////////////////////////////////////
58 #undef prefix_
59 //#include "INetSocketProtocol.mpp"
60 
61 
62 // Local Variables:
63 // mode: c++
64 // fill-column: 100
65 // c-file-style: "senf"
66 // indent-tabs-mode: nil
67 // ispell-local-dictionary: "american"
68 // compile-command: "scons -u test"
69 // comment-column: 40
70 // End:
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
int fd() const
Get file descriptor.
#define prefix_
IPv[46]Protocol public header.
std::string bindInterface()
Get bound interface.