2 Copyright 2007 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 int MVPRelay::shutdown()
34 if (threadIsActive()) threadCancel();
41 if (threadIsActive()) return 1;
45 Log::getInstance()->log("MVPRelay", Log::CRIT, "Could not open UDP 16881");
56 Log::getInstance()->log("MVPRelay", Log::DEBUG, "MVPRelay replier started");
60 void MVPRelay::threadMethod()
65 retval = ds.waitforMessage(0);
66 if (retval == 1) continue;
68 Log::getInstance()->log("MVPRelay", Log::DEBUG, "MVPRelay request from %s", ds.getFromIPA());
70 // TCP::dump((UCHAR*)ds.getData(), ds.getDataLength());
72 UCHAR* in = (UCHAR*)ds.getData();
74 // Check incoming packet magic number
76 ULONG inMagic = ntohl(*(ULONG*)&in[4]);
77 if (inMagic != 0xbabefafe)
79 Log::getInstance()->log("MVPRelay", Log::DEBUG, "inMagic not correct");
84 USHORT peerPort = ntohs(*(USHORT*)&in[20]);
86 // Get my IP for this connection
87 ULONG myIP = ds.getMyIP(*(ULONG*)&in[16]);
88 Log::getInstance()->log("MVPRelay", Log::DEBUG, "Sending my IP as %x", ntohl(myIP));
90 // Required return parameters:
96 // Construct reply packet
101 // Copy sequence number
104 // Return magic number is 0xfafebabe
105 *(ULONG*)&out[4] = htonl(0xfafebabe);
107 // Copy client IP and port to reply
108 memcpy(&out[16], &in[16], 6);
110 // Insert server address
111 *(ULONG*)&out[24] = myIP;
114 ds.send(ds.getFromIPA(), peerPort, (char*)out, 52);
116 // TCP::dump(out, 52);