2 Copyright 2004-2005 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, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vompclientrrproc.h"
23 #include "udpreplier.h"
25 UDPReplier::UDPReplier()
31 UDPReplier::~UDPReplier()
36 int UDPReplier::shutdown()
38 if (threadIsActive()) threadCancel();
40 if (message) delete[] message;
45 int UDPReplier::run(USHORT port, char* serverName, USHORT serverPort)
47 if (threadIsActive()) return 1;
50 VOMP Discovery Protocol V1
52 Client transmits: "VDP-0001\0<6-byte MAC>"...
53 ... for IPv4: broadcasts on ports 51051-51055
54 ... for IPv6: multicasts to ff15:766f:6d70:2064:6973:636f:7665:7279 port 51051
58 Field 1 p0: 9 bytes "VDP-0002\0"
63 4 = first 4 bytes of field 3 are IPv4 address of server
64 6 = field 3 16 bytes are IPv6 address of server
66 Field 3, p10, 16 bytes:
67 As described above. If field 2 is 0, this should be all zeros. If this is an IPv4 address, remaining bytes should be zeros.
73 VOMP protocol version (defined in vdr.cc)
75 Field 6 p32, variable length
76 String of server name, null terminated
79 messageLen = strlen(serverName) + 33;
80 message = new char[messageLen];
81 memset(message, 0, messageLen);
82 // by zeroing the packet, this sets no ip address return information
84 strcpy(message, "VDP-0002");
86 USHORT temp = htons(serverPort);
87 memcpy(&message[26], &temp, 2);
89 ULONG temp2 = htonl(VompClientRRProc::getProtocolVersionMin());
90 memcpy(&message[28], &temp2, 4);
92 strcpy(&message[32], serverName);
93 // Fix Me add also the maximum version somewhere
106 Log::getInstance()->log("UDPReplier", Log::DEBUG, "UDP replier started");
110 void UDPReplier::threadMethod()
115 retval = ds.waitforMessage(0);
116 if (retval == 1) continue;
118 if (!strncmp(ds.getData(), "VDP-0001", 8))
120 Log::getInstance()->log("UDPReplier", Log::DEBUG, "UDP request from %s", ds.getFromIPA());
121 ds.send(ds.getFromIPA(), ds.getFromPort(), message, messageLen);