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
rcdiscover::SocketWindows::enableNonBlockingImpl
void enableNonBlockingImpl()
Enables non-blocking operation for this socket.
Definition: socket_windows.cc:303
rcdiscover::SocketWindows::createAndBindForAllInterfaces
static std::vector< SocketWindows > createAndBindForAllInterfaces(uint16_t port)
Creates sockets for all interfaces and binds them to the respective interface.
Definition: socket_windows.cc:88
rcdiscover::SocketWindows::SocketWindows
SocketWindows(int domain, int type, int protocol, ULONG dst_ip, uint16_t port, std::string iface_name)
Constructor.
Definition: socket_windows.cc:201
rcdiscover::SocketWindows::getBroadcastAddr
static const ULONG & getBroadcastAddr()
Returns the broadcast address.
Definition: socket_windows.cc:47
rcdiscover::SocketWindows::create
static SocketWindows create(ULONG dst_ip, uint16_t port, std::string iface_name)
Create a new socket.
Definition: socket_windows.cc:53
rcdiscover::SocketWindows::dst_addr_
sockaddr_in dst_addr_
Definition: socket_windows.h:126
rcdiscover::SocketWindows
Definition: socket_windows.h:46
rcdiscover
Definition: deviceinfo.cc:40
rcdiscover::SocketWindows::enableBroadcastImpl
void enableBroadcastImpl()
Enables broadcast for this socket.
Definition: socket_windows.cc:289
rcdiscover::SocketWindows::~SocketWindows
~SocketWindows()
Definition: socket_windows.cc:236
rcdiscover::SocketWindows::sock_
SOCKET sock_
Definition: socket_windows.h:125
socket.h
rcdiscover::SocketWindows::sendImpl
void sendImpl(const std::vector< uint8_t > &sendbuf)
Sends data.
Definition: socket_windows.cc:259
rcdiscover::SocketWindows::getHandleImpl
const SOCKET & getHandleImpl() const
Returns the native socket handle.
Definition: socket_windows.cc:244
rcdiscover::SocketWindows::bindImpl
void bindImpl(const sockaddr_in &addr)
Binds the socket to a specific sockaddr.
Definition: socket_windows.cc:249
rcdiscover::SocketWindows::SocketType
SOCKET SocketType
Type representing the native socket handle type.
Definition: socket_windows.h:54
rcdiscover::Socket
CRTP class for platform specific socket implementation.
Definition: socket.h:52
rcdiscover::SocketWindows::operator=
SocketWindows & operator=(SocketWindows &&other)
Definition: socket_windows.cc:230


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Thu Aug 1 2024 02:55:56