2 Copyright 2019 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
22 #include <arpa/inet.h>
24 #include "vompclientrrproc.h"
26 #include "udp6replier.h"
28 UDP6Replier::UDP6Replier()
34 UDP6Replier::~UDP6Replier()
39 int UDP6Replier::shutdown()
41 if (threadIsActive()) threadCancel();
43 if (message) delete[] message;
48 int UDP6Replier::run(USHORT port, char* serverName, USHORT serverPort)
50 if (threadIsActive()) return 1;
53 VOMP Discovery Protocol V1
55 Client transmits: "VDP-0001\0<6-byte MAC>"...
56 ... for IPv4: broadcasts on ports 51051-51055
57 ... for IPv6: multicasts to ff15:766f:6d70:2064:6973:636f:7665:7279 port 51056
61 Field 1 p0: 9 bytes "VDP-0002\0"
66 4 = first 4 bytes of field 3 are IPv4 address of server
67 6 = field 3 16 bytes are IPv6 address of server
69 Field 3, p10, 16 bytes:
70 As described above. If field 2 is 0, this should be all zeros. If this is an IPv4 address, remaining bytes should be zeros.
76 VOMP protocol version (defined in vdr.cc)
78 Field 6 p32, variable length
79 String of server name, null terminated
82 messageLen = strlen(serverName) + 33;
83 message = new char[messageLen];
84 memset(message, 0, messageLen);
85 // by zeroing the packet, this sets no ip address return information
87 strcpy(message, "VDP-0002");
89 USHORT temp = htons(serverPort);
90 memcpy(&message[26], &temp, 2);
92 ULONG temp2 = htonl(VompClientRRProc::getProtocolVersionMin());
93 memcpy(&message[28], &temp2, 4);
95 strcpy(&message[32], serverName);
96 // Fix Me add also the maximum version somewhere
109 Log::getInstance()->log("UDP6Replier", Log::DEBUG, "UDP replier started");
113 void UDP6Replier::threadMethod()
118 retval = ds.waitforMessage(0);
119 if (retval == 1) continue;
121 if (!strncmp(ds.getData(), "VDP-0001", 8))
123 Log::getInstance()->log("UDP6Replier", Log::DEBUG, "UDP6 request from %s", ds.getFromIPA());
124 ds.send(ds.getFromIPA(), ds.getFromPort(), message, messageLen);