UDPSocketHandle.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 
18 #include "UDPSocketHandle.hh"
19 //#include "UDPSocketHandle.ih"
20 
21 // Custom includes
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <sys/ioctl.h>
25 
26 #include <senf/Utils/Exception.hh>
27 
28 //#include "UDPSocketHandle.mpp"
29 #define prefix_
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 
32 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 // senf::UDPv4SocketProtocol
34 
36  const
37 {
38  int sock = ::socket(PF_INET,SOCK_DGRAM | SOCK_CLOEXEC, 0);
39  if (sock < 0)
40  SENF_THROW_SYSTEM_EXCEPTION("could not open UDPv4Socket");
41  fd(sock);
42 }
43 
44 prefix_ void
46  const
47 {
48  init_client();
49  reuseaddr(true);
50  clientHandle().bind(address);
51 }
52 
53 //-/////////////////////////////////////////////////////////////////////////////////////////////////
54 // senf::UDPv6SocketProtocol::
55 
57  const
58 {
59  int sock = ::socket(PF_INET6,SOCK_DGRAM | SOCK_CLOEXEC, 0);
60  if (sock < 0)
61  SENF_THROW_SYSTEM_EXCEPTION("could not open UDPv6Socket");
62  fd(sock);
63 }
64 
65 prefix_ void
67  const
68 {
69  init_client();
70  clientHandle().bind(address);
71 }
72 
73 //-/////////////////////////////////////////////////////////////////////////////////////////////////
74 #undef prefix_
75 //#include "UDPSocketHandle.mpp"
76 
77 
78 // Local Variables:
79 // mode: c++
80 // fill-column: 100
81 // c-file-style: "senf"
82 // indent-tabs-mode: nil
83 // ispell-local-dictionary: "american"
84 // compile-command: "scons -u test"
85 // comment-column: 40
86 // End:
ClientSocketHandle< Policy > clientHandle() const
Get client handle for associated socket.
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
IPv6 socket address.
bool reuseaddr() const
Return current reuseaddr state.
int fd() const
Get file descriptor.
IPv4 socket address.
#define prefix_
void init_client() const
Create unconnected client socket.
void init_client() const
Create unconnected client socket.
UDPv4SocketHandle and UDPv6SocketHandle public header.