socket_windows.h
Go to the documentation of this file.
1 /*
2  * rcdiscover - the network discovery tool for Roboception devices
3  *
4  * Copyright (c) 2017 Roboception GmbH
5  * All rights reserved
6  *
7  * Author: Raphael Schaller
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef RCDISCOVER_SOCKET_WINDOW_H
37 #define RCDISCOVER_SOCKET_WINDOW_H
38 
39 #include "socket.h"
40 
41 #include <winsock2.h>
42 
43 namespace rcdiscover
44 {
45 
46 class SocketWindows : public Socket<SocketWindows>
47 {
48  friend class Socket<SocketWindows>;
49 
50  public:
54  typedef SOCKET SocketType;
55 
56  public:
63  static SocketWindows create(ULONG dst_ip, uint16_t port, std::string iface_name);
64 
71  static std::vector<SocketWindows> createAndBindForAllInterfaces(
72  uint16_t port);
73 
82  SocketWindows(int domain, int type, int protocol,
83  ULONG dst_ip, uint16_t port,
84  std::string iface_name);
88 
93  static const ULONG &getBroadcastAddr();
94 
95  protected:
100  const SOCKET &getHandleImpl() const;
101 
106  void bindImpl(const sockaddr_in &addr);
107 
112  void sendImpl(const std::vector<uint8_t> &sendbuf);
113 
117  void enableBroadcastImpl();
118 
122  void enableNonBlockingImpl();
123 
124  private:
125  SOCKET sock_;
126  sockaddr_in dst_addr_;
127 };
128 
129 }
130 
131 #endif //RCDISCOVER_SOCKET_WINDOW_H
SocketWindows & operator=(SocketWindows &&other)
void bindImpl(const sockaddr_in &addr)
Binds the socket to a specific sockaddr.
void enableNonBlockingImpl()
Enables non-blocking operation for this socket.
static std::vector< SocketWindows > createAndBindForAllInterfaces(uint16_t port)
Creates sockets for all interfaces and binds them to the respective interface.
static const ULONG & getBroadcastAddr()
Returns the broadcast address.
CRTP class for platform specific socket implementation.
Definition: socket.h:52
void enableBroadcastImpl()
Enables broadcast for this socket.
static SocketWindows create(ULONG dst_ip, uint16_t port, std::string iface_name)
Create a new socket.
SocketWindows(int domain, int type, int protocol, ULONG dst_ip, uint16_t port, std::string iface_name)
Constructor.
void sendImpl(const std::vector< uint8_t > &sendbuf)
Sends data.
SOCKET SocketType
Type representing the native socket handle type.
const SOCKET & getHandleImpl() const
Returns the native socket handle.


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Sun Apr 18 2021 02:16:32