RawINetSocketHandle.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 
14 #include "RawINetSocketHandle.hh"
15 
16 // Custom includes
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <sys/ioctl.h>
20 
21 #include <senf/Utils/Exception.hh>
22 
23 //#include "UDPSocketHandle.mpp"
24 #define prefix_
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 // senf::RawV4SocketProtocol
29 
31  const
32 {
33  init_client(IPPROTO_RAW);
34 }
35 
36 prefix_ void
38  const
39 {
40  int sock = ::socket(PF_INET, SOCK_RAW, protocol);
41  if (sock < 0)
42  SENF_THROW_SYSTEM_EXCEPTION("could not open RawV4Socket");
43  fd(sock);
44 }
45 
46 prefix_ void
47 senf::RawV4SocketProtocol::init_client(int const & protocol, INet4SocketAddress const & address)
48  const
49 {
50  init_client(protocol);
51  clientHandle().bind(address);
52 }
53 
54 //-/////////////////////////////////////////////////////////////////////////////////////////////////
55 // senf::RawV6SocketProtocol::
56 
58  const
59 {
60  init_client(IPPROTO_RAW);
61 }
62 
64  const
65 {
66  int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
67  if (sock < 0)
68  SENF_THROW_SYSTEM_EXCEPTION("could not open RawV6Socket");
69  fd(sock);
70 }
71 
72 prefix_ void
73 senf::RawV6SocketProtocol::init_client(int const & protocol, INet6SocketAddress const & address)
74  const
75 {
76  init_client(protocol);
77  clientHandle().bind(address);
78 }
79 
80 //-/////////////////////////////////////////////////////////////////////////////////////////////////
81 #undef prefix_
82 //#include "RawINetSocketHandle.mpp"
83 
84 
85 // Local Variables:
86 // mode: c++
87 // fill-column: 100
88 // comment-column: 40
89 // c-file-style: "senf"
90 // indent-tabs-mode: nil
91 // ispell-local-dictionary: "american"
92 // compile-command: "scons -u test"
93 // End:
ClientSocketHandle< Policy > clientHandle() const
Get client handle for associated socket.
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
IPv6 socket address.
int fd() const
Get file descriptor.
IPv4 socket address.
void init_client() const
Create unconnected client socket for IPPROTO_RAW.
#define prefix_
void init_client() const
Create unconnected client socket for IPPROTO_RAW.