Matter SDK Coverage Report
Current view: top level - lib/dnssd/minimal_mdns/responders - IP.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 100.0 % 28 28
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 2 2

            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           96 : void IPv4Responder::AddAllResponses(const chip::Inet::IPPacketInfo * source, ResponderDelegate * delegate,
      30              :                                     const ResponseConfiguration & configuration)
      31              : {
      32              : #if INET_CONFIG_ENABLE_IPV4
      33           96 :     if (!delegate->ShouldSend(*this))
      34              :     {
      35           10 :         return;
      36              :     }
      37              : 
      38              :     chip::Inet::IPAddress addr;
      39              :     UniquePtr<IpAddressIterator> ips =
      40           86 :         GetAddressPolicy()->GetIpAddressesForEndpoint(source->Interface, chip::Inet::IPAddressType::kIPv4);
      41           86 :     VerifyOrDie(ips);
      42              : 
      43          155 :     while (ips->Next(addr))
      44              :     {
      45           69 :         assert(addr.IsIPv4());
      46              : 
      47           69 :         IPResourceRecord record(GetQName(), addr);
      48              :         // We're the only thing around with our hostname, so we should set the
      49              :         // cache-flush bit.
      50           69 :         record.SetCacheFlush(true);
      51           69 :         configuration.Adjust(record);
      52           69 :         delegate->AddResponse(record);
      53           69 :     }
      54           86 :     delegate->ResponsesAdded(*this);
      55              : #endif
      56           86 : }
      57              : 
      58           96 : void IPv6Responder::AddAllResponses(const chip::Inet::IPPacketInfo * source, ResponderDelegate * delegate,
      59              :                                     const ResponseConfiguration & configuration)
      60              : {
      61           96 :     if (!delegate->ShouldSend(*this))
      62              :     {
      63           10 :         return;
      64              :     }
      65              : 
      66              :     chip::Inet::IPAddress addr;
      67              :     UniquePtr<IpAddressIterator> ips =
      68           86 :         GetAddressPolicy()->GetIpAddressesForEndpoint(source->Interface, chip::Inet::IPAddressType::kIPv6);
      69           86 :     VerifyOrDie(ips);
      70              : 
      71          155 :     while (ips->Next(addr))
      72              :     {
      73           69 :         assert(addr.IsIPv6());
      74              : 
      75           69 :         IPResourceRecord record(GetQName(), addr);
      76              :         // We're the only thing around with our hostname, so we should set the
      77              :         // cache-flush bit.
      78           69 :         record.SetCacheFlush(true);
      79           69 :         configuration.Adjust(record);
      80           69 :         delegate->AddResponse(record);
      81           69 :     }
      82           86 :     delegate->ResponsesAdded(*this);
      83           86 : }
      84              : 
      85              : } // namespace Minimal
      86              : } // namespace mdns
        

Generated by: LCOV version 2.0-1