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>" on ports 51051-51055
56 Field 1 p0: 9 bytes "VDP-0002\0"
61 4 = first 4 bytes of field 2 are IPv4 address of server
62 6 = field 2 16 bytes are IPv6 address of server
64 Field 3, p10, 16 bytes:
65 As described above. If field 1 is 0, this should be all zeros. If this is an IPv4 address, remaining bytes should be zeros.
71 VOMP protocol version (defined in vdr.cc)
73 Field 6 p32, variable length
74 String of server name, null terminated
77 messageLen = strlen(serverName) + 33;
78 message = new char[messageLen];
79 memset(message, 0, messageLen);
80 // by zeroing the packet, this sets no ip address return information
82 strcpy(message, "VDP-0002");
84 USHORT temp = htons(serverPort);
85 memcpy(&message[26], &temp, 2);
87 ULONG temp2 = htonl(VompClientRRProc::getProtocolVersionMin());
88 memcpy(&message[28], &temp2, 4);
90 strcpy(&message[32], serverName);
91 // Fix Me add also the maximum version somewhere
104 Log::getInstance()->log("UDPReplier", Log::DEBUG, "UDP replier started");
108 void UDPReplier::threadMethod()
113 retval = ds.waitforMessage(0);
114 if (retval == 1) continue;
116 if (!strncmp(ds.getData(), "VDP-0001", 8))
118 Log::getInstance()->log("UDPReplier", Log::DEBUG, "UDP request from %s", ds.getFromIPA());
119 ds.send(ds.getFromIPA(), ds.getFromPort(), message, messageLen);