GCC Code Coverage Report


Directory: src/gate/
File: src/gate/system/cxx_netconfigs.cpp
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 84 105 80.0%
Functions: 29 34 85.3%
Branches: 13 36 36.1%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/system/netconfigs.hpp"
30 #include "gate/exceptions.hpp"
31 #include "gate/memalloc.hpp"
32
33 namespace gate
34 {
35 namespace sys
36 {
37
38 NetAddress::NetAddress() noexcept
39 {
40 Mem::clear(this->impl);
41 }
42 3 NetAddress::NetAddress(gate_netconfig_address_t const& src) noexcept
43 {
44 3 Mem::copy(this->impl, src);
45 3 }
46 3 NetAddress::NetAddress(NetAddress const& src) noexcept
47 {
48 3 Mem::copy(this->impl, src.impl);
49 3 }
50 NetAddress& NetAddress::operator=(NetAddress const& src) noexcept
51 {
52 if (this != &src)
53 {
54 Mem::copy(this->impl, src.impl);
55 }
56 return *this;
57 }
58 6 NetAddress::~NetAddress() noexcept
59 {
60 6 }
61
62 3 gate_netconfig_address_t const& NetAddress::c_impl() const noexcept
63 {
64 3 return this->impl;
65 }
66
67 3 String NetAddress::Address() const
68 {
69 3 return String(this->impl.address);
70 }
71
72 3 String NetAddress::Mask() const
73 {
74 3 return String(this->impl.mask);
75 }
76
77 3 enumint_t NetAddress::AddressType() const
78 {
79 3 return this->impl.addrtype;
80 }
81
82 3 enumint_t NetAddress::Flags() const
83 {
84 3 return this->impl.flags;
85 }
86
87
88
89 1 NetInterface::NetInterface() noexcept
90 {
91 1 Mem::clear(this->impl);
92 1 }
93
94 2 NetInterface::NetInterface(gate_netconfig_nif_t const& src) noexcept
95 {
96 2 Mem::copy(this->impl, src);
97 2 }
98
99
100 2 NetInterface::NetInterface(NetInterface const& src) noexcept
101 {
102 2 Mem::copy(this->impl, src.impl);
103 2 }
104 2 NetInterface& NetInterface::operator=(NetInterface const& src) noexcept
105 {
106
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (this != &src)
107 {
108 2 Mem::copy(this->impl, src.impl);
109 }
110 2 return *this;
111 }
112
113 5 NetInterface::~NetInterface() noexcept
114 {
115 5 }
116
117 2 String NetInterface::Uid() const
118 {
119 2 return String(this->impl.uid);
120 }
121
122 2 String NetInterface::Name() const
123 {
124 2 return String(this->impl.name);
125 }
126
127 2 String NetInterface::DevicePath() const
128 {
129 2 return String(this->impl.device_path);
130 }
131
132 2 String NetInterface::Address() const
133 {
134 2 return String(this->impl.address);
135 }
136
137 2 size_t NetInterface::Index() const
138 {
139 2 return this->impl.index;
140 }
141
142 2 NetInterface::TypeEnum NetInterface::Type() const
143 {
144 2 return TypeEnum(this->impl.type);
145 }
146
147 2 String NetInterface::TypeText() const
148 {
149 2 return String::createStatic(gate_netconfig_print_type(this->impl.type));
150 }
151
152 4 enumint_t NetInterface::Status() const
153 {
154 4 return this->impl.status;
155 }
156
157 2 String NetInterface::printStatusBit(enumint_t status)
158 {
159 2 return String::createStatic(gate_netconfig_print_status(status));
160 }
161
162 2 gate_netconfig_nif_t& NetInterface::c_impl()
163 {
164 2 return this->impl;
165 }
166
167 gate_netconfig_nif_t const& NetInterface::c_impl() const
168 {
169 return this->impl;
170 }
171
172 3 static gate_bool_t NetInterface_enumNetAddresses_cb(gate_netconfig_address_t const* addr, void* userparam)
173 {
174 3 NetInterface::EnumNetAddressCallback const* ptr_cb = static_cast<NetInterface::EnumNetAddressCallback const*>(userparam);
175 3 NetAddress address(*addr);
176 3 gate_bool_t ret = true;
177
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 ptr_cb->invoke(address, ret);
178 6 return ret;
179 }
180
181 2 void NetInterface::enumNetAddresses(NetInterface::EnumNetAddressCallback const& callback)
182 {
183 2 void* param = const_cast<void*>(static_cast<void const*>(&callback));
184 2 result_t result = gate_netconfig_enum_addresses(&this->impl, &NetInterface_enumNetAddresses_cb, param);
185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
186 2 }
187
188 struct GATE_API_LOCAL AddressListing
189 {
190 ArrayList<NetAddress> addresses;
191
192 3 void cb(NetAddress const& addr, bool_t& continueIteration)
193 {
194 3 this->addresses.add(addr);
195 3 continueIteration = true;
196 3 }
197
198 };
199
200 2 Array<NetAddress> NetInterface::listNetAddresses()
201 {
202
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 AddressListing listing;
203
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 EnumNetAddressCallback cb(&listing, &AddressListing::cb);
204
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 this->enumNetAddresses(cb);
205
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 return listing.addresses.toArray();
206 }
207
208
209
210 static gate_bool_t nifDispatcherCallback(gate_netconfig_nif_t const* nif, void* userparam)
211 {
212 bool_t ret = true;
213 NetConfig::EnumNetInterfaceCallback* ptrCb = static_cast<NetConfig::EnumNetInterfaceCallback*>(userparam);
214 if (ptrCb)
215 {
216 NetInterface const obj(*nif);
217 ptrCb->invoke(obj, ret);
218 }
219 return ret;
220 }
221
222 void NetConfig::enumNetInterfaces(EnumNetInterfaceCallback const& callback)
223 {
224 void* param = const_cast<EnumNetInterfaceCallback*>(&callback);
225 result_t result = gate_netconfig_enum_nifs(&nifDispatcherCallback, param);
226 GATEXX_CHECK_EXCEPTION(result);
227 }
228
229 2 static gate_bool_t nifListCallback(gate_netconfig_nif_t const* nif, void* userparam)
230 {
231 2 ArrayList<NetInterface>* ptrList = static_cast<ArrayList<NetInterface>*>(userparam);
232
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (ptrList)
233 {
234 4 NetInterface obj(*nif);
235
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 ptrList->add(obj);
236 }
237 2 return true;
238 }
239
240 1 Array<NetInterface> NetConfig::findAllNetInterfaces()
241 {
242
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 ArrayList<NetInterface> ret;
243
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_netconfig_enum_nifs(&nifListCallback, &ret);
244
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
245
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return ret.toArray();
246 }
247
248 } // end of namespace sys
249 } // end of namespace gate
250
251