void StandardInMessage::doChecksum() { auto givenChecksum = getU32(); auto size = getRemainingSize(); if(givenChecksum != crypto::adler32(peekRawChunckAs<uint8_t>(size), size)) throw PacketException(); }
boost::asio::mutable_buffers_1 StandardInMessage::parseHeaderAndGetBodyBuffer() { auto bodySize = getU16(); // 8 = adler + 1 xtea frame smallest packet if(bodySize < 8 || bodySize > STANDARD_IN_MESSAGE_MAX_BODY_SIZE) throw PacketException(); setRemainingSize(bodySize); return getBodyBuffer(); }
void StandardInMessage::xteaDecrypt(const crypto::Xtea& xtea) { auto size = getRemainingSize(); if(size%8 != 0) throw PacketException(); xtea.decrypt(peekRawChunckAs<uint32_t>(size), size); setRemainingSize(getU16()); }
// for a given destination address - return the local endpoint address and the gateway address that // will be used for a connection to the destination. // if the local address and the gateway address are the same then the destination is on a local network. void getRouteInfo (net::InetAddress destination, net::InetAddress& localAddr, net::InetAddress& gatewayAddr) { MIB_IPFORWARDROW routeInfo; DWORD res = GetBestRoute(htonl(destination.getIPAddress()), 0, &routeInfo); if (res != NO_ERROR) throw PacketException ("getRouteInfo: Error"); gatewayAddr.set(ntohl(routeInfo.dwForwardNextHop), 0); destination.setPortNumber(123); net::Socket s(SOCK_DGRAM); s.connect(destination); localAddr = s.getLocalAddress(); }