force_ip.cc
Go to the documentation of this file.
1 /*
2 * Roboception GmbH
3 * Munich, Germany
4 * www.roboception.com
5 *
6 * Copyright (c) 2017 Roboception GmbH
7 * All rights reserved
8 *
9 * Author: Raphael Schaller
10 */
11 #include "force_ip.h"
12 
13 #include "socket_exception.h"
14 #include "gige_request_counter.h"
15 
16 namespace rcdiscover
17 {
18 
20  sockets_(SocketType::createAndBindForAllInterfaces(3956))
21 {
22  for (auto &socket : sockets_)
23  {
24  socket.enableBroadcast();
25  socket.enableNonBlocking();
26  }
27 }
28 
29 void ForceIP::sendCommand(const uint64_t mac, const uint32_t ip,
30  const uint32_t subnet, const uint32_t gateway)
31 {
32  std::vector<std::uint8_t> force_ip_command(64);
33  force_ip_command[0] = 0x42;
34  force_ip_command[1] = 0x00; // flags
35  force_ip_command[2] = 0x00; // command: FORCEIP_CMD: 0x0004
36  force_ip_command[3] = 0x04; // command: FORCEIP_CMD: 0x0004
37  force_ip_command[4] = 0x00; // length
38  force_ip_command[5] = 64 - 8; // length
39 
40  force_ip_command[10] = static_cast<std::uint8_t>(mac >> 40); // MAC address
41  force_ip_command[11] = static_cast<std::uint8_t>(mac >> 32); // MAC address
42  force_ip_command[12] = static_cast<std::uint8_t>(mac >> 24); // MAC address
43  force_ip_command[13] = static_cast<std::uint8_t>(mac >> 16); // MAC address
44  force_ip_command[14] = static_cast<std::uint8_t>(mac >> 8); // MAC address
45  force_ip_command[15] = static_cast<std::uint8_t>(mac >> 0); // MAC address
46 
47  force_ip_command[28] = static_cast<std::uint8_t>(ip >> 24); // IP address
48  force_ip_command[29] = static_cast<std::uint8_t>(ip >> 16); // IP address
49  force_ip_command[30] = static_cast<std::uint8_t>(ip >> 8); // IP address
50  force_ip_command[31] = static_cast<std::uint8_t>(ip >> 0); // IP address
51 
52  force_ip_command[44] = static_cast<std::uint8_t>(subnet >> 24); // subnet
53  force_ip_command[45] = static_cast<std::uint8_t>(subnet >> 16); // subnet
54  force_ip_command[46] = static_cast<std::uint8_t>(subnet >> 8); // subnet
55  force_ip_command[47] = static_cast<std::uint8_t>(subnet >> 0); // subnet
56 
57  force_ip_command[60] = static_cast<std::uint8_t>(gateway >> 24); // gateway
58  force_ip_command[61] = static_cast<std::uint8_t>(gateway >> 16); // gateway
59  force_ip_command[62] = static_cast<std::uint8_t>(gateway >> 8); // gateway
60  force_ip_command[63] = static_cast<std::uint8_t>(gateway >> 0); // gateway
61 
62  for (auto &socket : sockets_)
63  {
64  std::tie(force_ip_command[6], force_ip_command[7]) =
66 
67  try
68  {
69  socket.send(force_ip_command);
70  }
71  catch(const NetworkUnreachableException &)
72  {
73  continue;
74  }
75  }
76 }
77 
78 }
void sendCommand(std::uint64_t mac, std::uint32_t ip, std::uint32_t subnet, std::uint32_t gateway)
Send FORCEIP_CMD.
Definition: force_ip.cc:29
std::vector< SocketType > sockets_
Definition: force_ip.h:55
ForceIP()
Constructor.
Definition: force_ip.cc:19
Exception representing a Network Unreachable error (code 101 on Unix).
Socket implementation for Linux.
Definition: socket_linux.h:51
static std::tuple< uint8_t, uint8_t > getNext()
Returns the next request number.


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