MCPcopy Create free account
hub / github.com/defold/defold / DecodeIncomingProbeRecord

Function DecodeIncomingProbeRecord

engine/dlib/src/dlib/mdns.cpp:918–954  ·  view source on GitHub ↗

Decodes an incoming authority claim into the same canonical form used for locally generated records. SRV names are uncompressed before comparison.

Source from the content-addressed store, hash-verified

916 // Decodes an incoming authority claim into the same canonical form used for
917 // locally generated records. SRV names are uncompressed before comparison.
918 static bool DecodeIncomingProbeRecord(const uint8_t* data, uint32_t size, uint16_t type, uint16_t klass,
919 uint32_t rdata_offset, uint16_t rdlength, ProbeRecord* record)
920 {
921 memset(record, 0, sizeof(*record));
922 record->m_Type = type;
923 record->m_Class = klass;
924
925 if (rdlength > sizeof(record->m_RData))
926 return false;
927
928 memcpy(record->m_RData, data + rdata_offset, rdlength);
929 record->m_RDataLength = rdlength;
930
931 if (type == DNS_TYPE_SRV)
932 {
933 uint32_t parse_offset = rdata_offset;
934 uint16_t priority = 0;
935 uint16_t weight = 0;
936 uint16_t port = 0;
937 char target[256];
938 uint32_t canonical_offset = 0;
939 if (!ReadU16(data, size, &parse_offset, &priority)
940 || !ReadU16(data, size, &parse_offset, &weight)
941 || !ReadU16(data, size, &parse_offset, &port)
942 || !ReadName(data, size, &parse_offset, target, sizeof(target))
943 || !WriteU16(record->m_RData, sizeof(record->m_RData), &canonical_offset, priority)
944 || !WriteU16(record->m_RData, sizeof(record->m_RData), &canonical_offset, weight)
945 || !WriteU16(record->m_RData, sizeof(record->m_RData), &canonical_offset, port)
946 || !WriteName(record->m_RData, sizeof(record->m_RData), &canonical_offset, target))
947 {
948 return false;
949 }
950 record->m_RDataLength = (uint16_t) canonical_offset;
951 }
952
953 return true;
954 }
955
956 // Writes a canonical record header plus already-encoded rdata. Probes and
957 // responses both use this so SRV/TXT bytes are built in one place.

Callers 2

CollectProbeClaimsFunction · 0.85

Calls 4

ReadU16Function · 0.70
ReadNameFunction · 0.70
WriteU16Function · 0.70
WriteNameFunction · 0.70

Tested by

no test coverage detected