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

Function BuildResponseMessage

engine/dlib/src/dlib/mdns.cpp:1009–1056  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1007 }
1008
1009 static uint32_t BuildResponseMessage(const RegisteredService& service, const dmSocket::Address* host_address, uint32_t ttl, uint8_t* buffer, uint32_t buffer_size)
1010 {
1011 // RFC 6763 service advertisement record set:
1012 // PTR(<service type>) -> <instance>, then SRV/TXT/A for that instance.
1013 uint32_t offset = 0;
1014 uint16_t answer_count = 0;
1015 ProbeRecord service_records[2];
1016 const uint32_t service_record_count = BuildServiceProbeRecordSet(service, service_records, DM_ARRAY_SIZE(service_records));
1017
1018 if (!WriteU16(buffer, buffer_size, &offset, 0) // id
1019 || !WriteU16(buffer, buffer_size, &offset, DNS_FLAG_RESPONSE)
1020 || !WriteU16(buffer, buffer_size, &offset, 0) // questions
1021 || !WriteU16(buffer, buffer_size, &offset, 0) // answers (patched later)
1022 || !WriteU16(buffer, buffer_size, &offset, 0) // authorities
1023 || !WriteU16(buffer, buffer_size, &offset, 0)) // additionals
1024 {
1025 return 0;
1026 }
1027
1028 if (WriteRecordPtr(buffer, buffer_size, &offset, service.m_ServiceTypeLocal, service.m_FullServiceName, ttl))
1029 ++answer_count;
1030
1031 for (uint32_t i = 0; i < service_record_count; ++i)
1032 {
1033 if (WriteCanonicalRecord(buffer, buffer_size, &offset,
1034 service.m_FullServiceName,
1035 service_records[i].m_Type,
1036 (uint16_t) (service_records[i].m_Class | DNS_CLASS_FLUSH),
1037 ttl,
1038 service_records[i].m_RData,
1039 service_records[i].m_RDataLength))
1040 {
1041 ++answer_count;
1042 }
1043 }
1044
1045 const dmSocket::Address& service_address = host_address ? *host_address : service.m_HostAddress;
1046 if (WriteRecordA(buffer, buffer_size, &offset, service, service_address, ttl))
1047 ++answer_count;
1048
1049 if (answer_count == 0)
1050 return 0;
1051
1052 buffer[6] = (uint8_t) ((answer_count >> 8) & 0xff);
1053 buffer[7] = (uint8_t) (answer_count & 0xff);
1054
1055 return offset;
1056 }
1057
1058 static bool ShouldIncludeKnownAnswer(const BrowserService& service, uint64_t now)
1059 {

Callers 1

HandleAnnounceResponseFunction · 0.85

Calls 5

WriteRecordPtrFunction · 0.85
WriteCanonicalRecordFunction · 0.85
WriteRecordAFunction · 0.85
WriteU16Function · 0.70

Tested by

no test coverage detected