LCOV - code coverage report
Current view: top level - lib/dnssd/minimal_mdns/responders - IP.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 28 28 100.0 %
Date: 2024-02-15 08:20:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2020 Project CHIP Authors
       4             :  *
       5             :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6             :  *    you may not use this file except in compliance with the License.
       7             :  *    You may obtain a copy of the License at
       8             :  *
       9             :  *        http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  *    Unless required by applicable law or agreed to in writing, software
      12             :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13             :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  *    See the License for the specific language governing permissions and
      15             :  *    limitations under the License.
      16             :  */
      17             : #include "IP.h"
      18             : 
      19             : #include <assert.h>
      20             : 
      21             : #include <lib/dnssd/minimal_mdns/AddressPolicy.h>
      22             : #include <lib/dnssd/minimal_mdns/records/IP.h>
      23             : 
      24             : namespace mdns {
      25             : namespace Minimal {
      26             : 
      27             : using chip::Platform::UniquePtr;
      28             : 
      29         102 : void IPv4Responder::AddAllResponses(const chip::Inet::IPPacketInfo * source, ResponderDelegate * delegate,
      30             :                                     const ResponseConfiguration & configuration)
      31             : {
      32             : #if INET_CONFIG_ENABLE_IPV4
      33         102 :     if (!delegate->ShouldSend(*this))
      34             :     {
      35          10 :         return;
      36             :     }
      37             : 
      38             :     chip::Inet::IPAddress addr;
      39             :     UniquePtr<IpAddressIterator> ips =
      40          92 :         GetAddressPolicy()->GetIpAddressesForEndpoint(source->Interface, chip::Inet::IPAddressType::kIPv4);
      41          92 :     VerifyOrDie(ips);
      42             : 
      43         167 :     while (ips->Next(addr))
      44             :     {
      45          75 :         assert(addr.IsIPv4());
      46             : 
      47          75 :         IPResourceRecord record(GetQName(), addr);
      48             :         // We're the only thing around with our hostname, so we should set the
      49             :         // cache-flush bit.
      50          75 :         record.SetCacheFlush(true);
      51          75 :         configuration.Adjust(record);
      52          75 :         delegate->AddResponse(record);
      53          75 :     }
      54          92 :     delegate->ResponsesAdded(*this);
      55             : #endif
      56          92 : }
      57             : 
      58         102 : void IPv6Responder::AddAllResponses(const chip::Inet::IPPacketInfo * source, ResponderDelegate * delegate,
      59             :                                     const ResponseConfiguration & configuration)
      60             : {
      61         102 :     if (!delegate->ShouldSend(*this))
      62             :     {
      63          10 :         return;
      64             :     }
      65             : 
      66             :     chip::Inet::IPAddress addr;
      67             :     UniquePtr<IpAddressIterator> ips =
      68          92 :         GetAddressPolicy()->GetIpAddressesForEndpoint(source->Interface, chip::Inet::IPAddressType::kIPv6);
      69          92 :     VerifyOrDie(ips);
      70             : 
      71         167 :     while (ips->Next(addr))
      72             :     {
      73          75 :         assert(addr.IsIPv6());
      74             : 
      75          75 :         IPResourceRecord record(GetQName(), addr);
      76             :         // We're the only thing around with our hostname, so we should set the
      77             :         // cache-flush bit.
      78          75 :         record.SetCacheFlush(true);
      79          75 :         configuration.Adjust(record);
      80          75 :         delegate->AddResponse(record);
      81          75 :     }
      82          92 :     delegate->ResponsesAdded(*this);
      83          92 : }
      84             : 
      85             : } // namespace Minimal
      86             : } // namespace mdns

Generated by: LCOV version 1.14