MCPcopy Create free account
hub / github.com/catboost/catboost / CheckPacketIntegrity

Method CheckPacketIntegrity

library/cpp/netliba/v12/udp_socket.cpp:192–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190 }
191
192 bool TUdpSocket::CheckPacketIntegrity(const char* buf, const size_t size, const TSockAddrPair& addr) {
193 // ignore empty or small packets
194 if (size < UDP_LOW_LEVEL_HEADER_SIZE) {
195 return false;
196 }
197
198 if (ReadVersion(buf) != UDP_NETLIBA_VERSION_V12) {
199 fprintf(stderr, "NETLIBA::TUdpSocket: version mismatch\n");
200 return false;
201 }
202
203 const size_t packetDataSize = ReadPacketDataSize(buf);
204 if (packetDataSize + UDP_LOW_LEVEL_HEADER_SIZE > size) {
205 fprintf(stderr, "NETLIBA::TUdpSocket: bad packet size in header\n");
206 return false;
207 }
208
209 const ui64 expectedCrc = *(ui64*)buf;
210
211 const ui64 crc = CalcChecksum(buf + UDP_CRC_SIZE, packetDataSize + (UDP_LOW_LEVEL_HEADER_SIZE - UDP_CRC_SIZE)) + PROTO_REV;
212 if (!CrcMatches(expectedCrc, crc + PortCrc, addr.RemoteAddr)) {
213 fprintf(stderr, "NETLIBA::TUdpSocket: udp packet crc failure %s, expected %" PRIu64 ", %" PRIu64 ", %u \n",
214 GetAddressAsString(GetUdpAddress(addr.RemoteAddr)).c_str(), expectedCrc, crc, PortCrc);
215 return false;
216 }
217 return true;
218 }
219
220 ///////////////////////////////////////////////////////////////////////////////
221

Callers

nothing calls this directly

Calls 7

ReadVersionFunction · 0.85
ReadPacketDataSizeFunction · 0.85
CrcMatchesFunction · 0.85
CalcChecksumFunction · 0.70
GetAddressAsStringFunction · 0.70
GetUdpAddressFunction · 0.70
c_strMethod · 0.45

Tested by

no test coverage detected