From 60681129e75d75696288049c2bbfa80b9428d5d5 Mon Sep 17 00:00:00 2001 From: Kevin Schoedel <67607049+kpschoedel@users.noreply.github.com> Date: Thu, 21 Oct 2021 09:15:11 -0400 Subject: [PATCH] Convert to enum class in src/inet (#10504) * Convert to enum class in src/inet #### Problem Working toward #7715 Virtualize System and Inet interfaces #### Change overview - Convert `enum` to `enum class`, and use `BitFlags` for flag sets. - DNSResolver::State - IPAddressType - IPv6MulticastFlag - IPEndPointBasis::State - TCPEndPoint::State - Rename `kMaxIPAddressStringLength` to `IPAddress::kMaxStringLength` #### Testing CI; no changes to functionality intended. * add misssed flag * restyle * fixes * comment change to kick CI * review --- .../chip-tool/commands/discover/Commands.h | 2 +- .../DiscoverCommissionablesCommand.cpp | 2 +- .../commands/pairing/PairingCommand.cpp | 2 +- examples/minimal-mdns/AllInterfaceListener.h | 4 +- src/app/server/Server.cpp | 15 +- .../tests/integration/chip_im_initiator.cpp | 2 +- .../tests/integration/chip_im_responder.cpp | 2 +- src/controller/CHIPDeviceController.cpp | 9 +- .../CHIPDeviceControllerFactory.cpp | 4 +- ...issionableNodeController-ScriptBinding.cpp | 2 +- .../ChipDeviceController-ScriptBinding.cpp | 2 +- .../python/chip/discovery/NodeResolution.cpp | 2 +- src/controller/tests/TestDevice.cpp | 11 +- src/inet/IPAddress.cpp | 32 +-- src/inet/IPAddress.h | 85 +++---- src/inet/IPEndPointBasis.cpp | 38 +-- src/inet/IPEndPointBasis.h | 37 ++- src/inet/IPPrefix.h | 8 +- src/inet/TCPEndPoint.cpp | 161 ++++++------ src/inet/TCPEndPoint.h | 37 ++- src/inet/UDPEndPoint.cpp | 40 +-- src/inet/tests/TestInetAddress.cpp | 232 +++++++++--------- src/inet/tests/TestInetEndPoint.cpp | 26 +- src/inet/tests/TestInetLayer.cpp | 12 +- src/inet/tests/TestInetLayerMulticast.cpp | 8 +- src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp | 2 +- src/lib/dnssd/AllInterfacesListenIterator.h | 4 +- src/lib/dnssd/Discovery_ImplPlatform.cpp | 8 +- src/lib/dnssd/MinimalMdnsServer.cpp | 4 +- src/lib/dnssd/Resolver.h | 4 +- src/lib/dnssd/minimal_mdns/ResponseSender.cpp | 2 +- src/lib/dnssd/minimal_mdns/Server.cpp | 18 +- src/lib/shell/commands/Dns.cpp | 4 +- src/messaging/tests/echo/echo_requester.cpp | 4 +- src/messaging/tests/echo/echo_responder.cpp | 6 +- src/platform/Darwin/DnssdImpl.cpp | 4 +- src/platform/Linux/DnssdImpl.cpp | 10 +- ...nericThreadStackManagerImpl_OpenThread.cpp | 2 +- src/platform/tests/TestDnssd.cpp | 4 +- src/transport/raw/TCP.h | 14 +- src/transport/raw/UDP.h | 14 +- src/transport/raw/tests/TestTCP.cpp | 4 +- src/transport/raw/tests/TestUDP.cpp | 4 +- 43 files changed, 433 insertions(+), 454 deletions(-) diff --git a/examples/chip-tool/commands/discover/Commands.h b/examples/chip-tool/commands/discover/Commands.h index 8de5d290e644eb..271479a5bf4d92 100644 --- a/examples/chip-tool/commands/discover/Commands.h +++ b/examples/chip-tool/commands/discover/Commands.h @@ -36,7 +36,7 @@ class Resolve : public DiscoverCommand, public chip::Dnssd::ResolverDelegate chip::Dnssd::Resolver::Instance().SetResolverDelegate(this); ChipLogProgress(chipTool, "Dnssd: Searching for NodeId: %" PRIx64 " FabricId: %" PRIx64 " ...", remoteId, fabricId); return chip::Dnssd::Resolver::Instance().ResolveNodeId(chip::PeerId().SetNodeId(remoteId).SetCompressedFabricId(fabricId), - chip::Inet::kIPAddressType_Any); + chip::Inet::IPAddressType::kAny); } void OnNodeIdResolved(const chip::Dnssd::ResolvedNodeData & nodeData) override diff --git a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp index 76231de86be049..af7b276d4554a3 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp +++ b/examples/chip-tool/commands/discover/DiscoverCommissionablesCommand.cpp @@ -47,7 +47,7 @@ void DiscoverCommissionablesCommand::OnDiscoveredDevice(const chip::Dnssd::Disco ChipLogProgress(Discovery, "\tPairing Hint\t\t0x%x", nodeData.pairingHint); for (int i = 0; i < nodeData.numIPs; i++) { - char buf[chip::Inet::kMaxIPAddressStringLength]; + char buf[chip::Inet::IPAddress::kMaxStringLength]; nodeData.ipAddress[i].ToString(buf); ChipLogProgress(Discovery, "\tAddress %d:\t\t%s", i, buf); diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 36ba5a5f830346..b810bdcb46781f 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -430,7 +430,7 @@ void PairingCommand::OnAddressUpdateComplete(NodeId nodeId, CHIP_ERROR err) void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData) { const uint16_t port = nodeData.port; - char buf[chip::Inet::kMaxIPAddressStringLength]; + char buf[chip::Inet::IPAddress::kMaxStringLength]; nodeData.ipAddress[0].ToString(buf); ChipLogProgress(chipTool, "Discovered Device: %s:%u", buf, port); diff --git a/examples/minimal-mdns/AllInterfaceListener.h b/examples/minimal-mdns/AllInterfaceListener.h index 95863379ebb5d4..7a1b31420f6fb3 100644 --- a/examples/minimal-mdns/AllInterfaceListener.h +++ b/examples/minimal-mdns/AllInterfaceListener.h @@ -40,7 +40,7 @@ class AllInterfaces : public mdns::Minimal::ListenIterator { #if INET_CONFIG_ENABLE_IPV4 *id = INET_NULL_INTERFACEID; - *type = chip::Inet::kIPAddressType_IPv4; + *type = chip::Inet::IPAddressType::kIPv4; #endif mState = State::kIpV6; @@ -57,7 +57,7 @@ class AllInterfaces : public mdns::Minimal::ListenIterator } *id = mIterator.GetInterfaceId(); - *type = chip::Inet::kIPAddressType_IPv6; + *type = chip::Inet::IPAddressType::kIPv6; for (mIterator.Next(); SkipCurrentInterface(); mIterator.Next()) { diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index a407410f17d095..5111f3358023c0 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -95,19 +95,16 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint SuccessOrExit(err); // Init transport before operations with secure session mgr. - err = mTransports.Init(UdpListenParameters(&DeviceLayer::InetLayer) - .SetAddressType(IPAddressType::kIPAddressType_IPv6) - .SetListenPort(mSecuredServicePort) + err = mTransports.Init( + UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(IPAddressType::kIPv6).SetListenPort(mSecuredServicePort) #if INET_CONFIG_ENABLE_IPV4 - , - UdpListenParameters(&DeviceLayer::InetLayer) - .SetAddressType(IPAddressType::kIPAddressType_IPv4) - .SetListenPort(mSecuredServicePort) + , + UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(IPAddressType::kIPv4).SetListenPort(mSecuredServicePort) #endif #if CONFIG_NETWORK_LAYER_BLE - , - BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer()) + , + BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer()) #endif ); diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp index c0e9f9888d5485..ea48630d74a0b0 100644 --- a/src/app/tests/integration/chip_im_initiator.cpp +++ b/src/app/tests/integration/chip_im_initiator.cpp @@ -683,7 +683,7 @@ int main(int argc, char * argv[]) InitializeChip(); err = gTransportManager.Init(chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer) - .SetAddressType(chip::Inet::kIPAddressType_IPv6) + .SetAddressType(chip::Inet::IPAddressType::kIPv6) .SetListenPort(IM_CLIENT_PORT)); SuccessOrExit(err); diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp index 2c4e3d467128cf..2caf6de046d6c9 100644 --- a/src/app/tests/integration/chip_im_responder.cpp +++ b/src/app/tests/integration/chip_im_responder.cpp @@ -211,7 +211,7 @@ int main(int argc, char * argv[]) InitializeChip(); err = gTransportManager.Init( - chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::kIPAddressType_IPv6)); + chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::IPAddressType::kIPv6)); SuccessOrExit(err); err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager); diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index cd484653feca2b..ee791fa8988b96 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -328,7 +328,7 @@ CHIP_ERROR DeviceController::UpdateDevice(NodeId deviceId) { #if CHIP_DEVICE_CONFIG_ENABLE_DNSSD return Dnssd::Resolver::Instance().ResolveNodeId(PeerId().SetCompressedFabricId(GetCompressedFabricId()).SetNodeId(deviceId), - chip::Inet::kIPAddressType_Any); + chip::Inet::IPAddressType::kAny); #else return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; #endif // CHIP_DEVICE_CONFIG_ENABLE_DNSSD @@ -631,12 +631,12 @@ CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params) #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY // make this commissioner discoverable mUdcTransportMgr = chip::Platform::New(); ReturnErrorOnFailure(mUdcTransportMgr->Init(Transport::UdpListenParameters(mSystemState->InetLayer()) - .SetAddressType(Inet::kIPAddressType_IPv6) + .SetAddressType(Inet::IPAddressType::kIPv6) .SetListenPort((uint16_t)(mUdcListenPort)) #if INET_CONFIG_ENABLE_IPV4 , Transport::UdpListenParameters(mSystemState->InetLayer()) - .SetAddressType(Inet::kIPAddressType_IPv4) + .SetAddressType(Inet::IPAddressType::kIPv4) .SetListenPort((uint16_t)(mUdcListenPort)) #endif // INET_CONFIG_ENABLE_IPV4 )); @@ -1999,8 +1999,7 @@ void DeviceCommissioner::AdvanceCommissioningStage(CHIP_ERROR err) #if CHIP_DEVICE_CONFIG_ENABLE_DNSSD ChipLogProgress(Controller, "Finding node on operational network"); Dnssd::Resolver::Instance().ResolveNodeId( - PeerId().SetCompressedFabricId(GetCompressedFabricId()).SetNodeId(device->GetDeviceId()), - Inet::IPAddressType::kIPAddressType_Any); + PeerId().SetCompressedFabricId(GetCompressedFabricId()).SetNodeId(device->GetDeviceId()), Inet::IPAddressType::kAny); #endif } break; diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index ed1ed65e47109f..43d629a860e4dd 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -113,10 +113,10 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) stateParams.transportMgr = chip::Platform::New(); ReturnErrorOnFailure(stateParams.transportMgr->Init( - Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::kIPAddressType_IPv6).SetListenPort(mListenPort) + Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::IPAddressType::kIPv6).SetListenPort(mListenPort) #if INET_CONFIG_ENABLE_IPV4 , - Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::kIPAddressType_IPv4).SetListenPort(mListenPort) + Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(mListenPort) #endif #if CONFIG_NETWORK_LAYER_BLE , diff --git a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp index b04de28c562927..c802ded0a16bb2 100644 --- a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp +++ b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp @@ -116,7 +116,7 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp); for (int j = 0; j < dnsSdInfo->numIPs; ++j) { - char buf[chip::Inet::kMaxIPAddressStringLength]; + char buf[chip::Inet::IPAddress::kMaxStringLength]; dnsSdInfo->ipAddress[j].ToString(buf); ChipLogProgress(Discovery, "\tAddress %d:\t\t%s", j, buf); } diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index 99c70ca276467d..106dfcbd2a9866 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -431,7 +431,7 @@ void pychip_DeviceController_PrintDiscoveredDevices(chip::Controller::DeviceComm ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp); for (int j = 0; j < dnsSdInfo->numIPs; ++j) { - char buf[chip::Inet::kMaxIPAddressStringLength]; + char buf[chip::Inet::IPAddress::kMaxStringLength]; dnsSdInfo->ipAddress[j].ToString(buf); ChipLogProgress(Discovery, "\tAddress %d:\t\t%s", j, buf); } diff --git a/src/controller/python/chip/discovery/NodeResolution.cpp b/src/controller/python/chip/discovery/NodeResolution.cpp index 80e453f663814b..dcda6beeae9aee 100644 --- a/src/controller/python/chip/discovery/NodeResolution.cpp +++ b/src/controller/python/chip/discovery/NodeResolution.cpp @@ -98,7 +98,7 @@ extern "C" ChipError::StorageType pychip_discovery_resolve(uint64_t fabricId, ui Resolver::Instance().SetResolverDelegate(&gPythonResolverDelegate); result = Resolver::Instance().ResolveNodeId(chip::PeerId().SetCompressedFabricId(fabricId).SetNodeId(nodeId), - chip::Inet::IPAddressType::kIPAddressType_Any); + chip::Inet::IPAddressType::kAny); }); return result.AsInteger(); diff --git a/src/controller/tests/TestDevice.cpp b/src/controller/tests/TestDevice.cpp index 22e866b59cdfb4..71c202d2c369cb 100644 --- a/src/controller/tests/TestDevice.cpp +++ b/src/controller/tests/TestDevice.cpp @@ -60,15 +60,14 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext systemLayer.Init(); inetLayer.Init(systemLayer, nullptr); - transportMgr.Init( - UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPAddressType_IPv6).SetListenPort(CHIP_PORT) + transportMgr.Init(UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPv6).SetListenPort(CHIP_PORT) #if INET_CONFIG_ENABLE_IPV4 - , - UdpListenParameters(&inetLayer).SetAddressType(Inet::kIPAddressType_IPv4).SetListenPort(CHIP_PORT) + , + UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT) #endif #if CONFIG_NETWORK_LAYER_BLE - , - BleListenParameters(&blelayer) + , + BleListenParameters(&blelayer) #endif ); sessionManager.Init(&systemLayer, &transportMgr, &messageCounterManager); diff --git a/src/inet/IPAddress.cpp b/src/inet/IPAddress.cpp index 019673a4faf36f..259daf7814ba75 100644 --- a/src/inet/IPAddress.cpp +++ b/src/inet/IPAddress.cpp @@ -78,13 +78,13 @@ ip_addr_t IPAddress::ToLwIPAddr(void) const switch (Type()) { #if INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv4: + case IPAddressType::kIPv4: IP_SET_TYPE_VAL(ret, IPADDR_TYPE_V4); *ip_2_ip4(&ret) = IPAddress::ToIPv4(); break; #endif // INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv6: + case IPAddressType::kIPv6: IP_SET_TYPE_VAL(ret, IPADDR_TYPE_V6); *ip_2_ip6(&ret) = IPAddress::ToIPv6(); break; @@ -132,12 +132,12 @@ lwip_ip_addr_type IPAddress::ToLwIPAddrType(IPAddressType typ) switch (typ) { #if INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv4: + case IPAddressType::kIPv4: ret = IPADDR_TYPE_V4; break; #endif // INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv6: + case IPAddressType::kIPv6: ret = IPADDR_TYPE_V6; break; @@ -321,12 +321,12 @@ uint64_t IPAddress::GlobalId() const IPAddressType IPAddress::Type() const { if (Addr[0] == 0 && Addr[1] == 0 && Addr[2] == 0 && Addr[3] == 0) - return kIPAddressType_Any; + return IPAddressType::kAny; #if INET_CONFIG_ENABLE_IPV4 if (Addr[0] == 0 && Addr[1] == 0 && Addr[2] == htonl(0xFFFF)) - return kIPAddressType_IPv4; + return IPAddressType::kIPv4; #endif // INET_CONFIG_ENABLE_IPV4 - return kIPAddressType_IPv6; + return IPAddressType::kIPv6; } // Encode IPAddress to buffer in network byte order. Buffer must have at least 128 bits of available space. @@ -382,10 +382,11 @@ IPAddress IPAddress::MakeLLA(uint64_t interfaceId) return addr; } -IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, +IPAddress IPAddress::MakeIPv6Multicast(IPv6MulticastFlags aFlags, uint8_t aScope, const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES]) { - const uint32_t lFlagsAndScope = (((uint32_t(aFlags) & 0xF) << 20) | ((uint32_t(aScope) & 0xF) << 16)); + const uint32_t lFlagsAndScope = + (((static_cast(aFlags.Raw()) & 0xF) << 20) | ((static_cast(aScope) & 0xF) << 16)); IPAddress addr; addr.Addr[0] = htonl((0xFF000000U | lFlagsAndScope) | (uint32_t(aGroupId[0]) << 8) | (uint32_t(aGroupId[1]) << 0)); @@ -399,7 +400,7 @@ IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, return addr; } -IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, uint32_t aGroupId) +IPAddress IPAddress::MakeIPv6Multicast(IPv6MulticastFlags aFlags, uint8_t aScope, uint32_t aGroupId) { const uint8_t lGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES] = { 0, 0, @@ -421,23 +422,22 @@ IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, uint32_t IPAddress IPAddress::MakeIPv6WellKnownMulticast(uint8_t aScope, uint32_t aGroupId) { - const uint8_t lFlags = 0; + constexpr IPv6MulticastFlags lFlags; return (MakeIPv6Multicast(lFlags, aScope, aGroupId)); } -IPAddress IPAddress::MakeIPv6TransientMulticast(uint8_t aFlags, uint8_t aScope, +IPAddress IPAddress::MakeIPv6TransientMulticast(IPv6MulticastFlags aFlags, uint8_t aScope, const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES]) { - const uint8_t lFlags = (aFlags | kIPv6MulticastFlag_Transient); - - return (MakeIPv6Multicast(lFlags, aScope, aGroupId)); + aFlags.Set(IPv6MulticastFlag::kTransient); + return (MakeIPv6Multicast(aFlags, aScope, aGroupId)); } IPAddress IPAddress::MakeIPv6PrefixMulticast(uint8_t aScope, uint8_t aPrefixLength, const uint64_t & aPrefix, uint32_t aGroupId) { const uint8_t lReserved = 0; - const uint8_t lFlags = kIPv6MulticastFlag_Prefix; + const IPv6MulticastFlags lFlags = IPv6MulticastFlag::kPrefix; const uint8_t lGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES] = { lReserved, aPrefixLength, static_cast((aPrefix & 0xFF00000000000000ULL) >> 56), diff --git a/src/inet/IPAddress.h b/src/inet/IPAddress.h index b300928c01628c..7d426ef7adc449 100644 --- a/src/inet/IPAddress.h +++ b/src/inet/IPAddress.h @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -80,67 +81,53 @@ namespace chip { namespace Inet { /** - * @brief Internet protocol address family - * - * @details - * Values of the \c IPAddressType type are returned by the - * IPAddress::Type() method. They indicate the address family - * entailed by the use of the address. + * Internet protocol address family */ -typedef enum +enum class IPAddressType : uint8_t { - /** Not used. */ - kIPAddressType_Unknown = 0, - + kUnknown = 0, ///< Not used. #if INET_CONFIG_ENABLE_IPV4 - /** Internet protocol version 4. */ - kIPAddressType_IPv4 = 1, -#endif // INET_CONFIG_ENABLE_IPV4 - - /** Internet protocol version 6. */ - kIPAddressType_IPv6 = 2, - - /** The unspecified internet address (independent of protocol version) */ - kIPAddressType_Any = 3 -} IPAddressType; + kIPv4 = 1, ///< Internet protocol version 4. +#endif // INET_CONFIG_ENABLE_IPV4 + kIPv6 = 2, ///< Internet protocol version 6. + kAny = 3 ///< The unspecified internet address (independent of protocol version). +}; /** - * @brief Internet protocol v6 multicast flags + * Internet protocol v6 multicast flags * - * @details - * Values of the \c IPv6MulticastFlag type are used to call the - * IPAddress::MakeIPv6Multicast() methods. They indicate the - * type of IPv6 multicast address to create. These numbers are - * registered by IETF with IANA. + * Values of the \c IPv6MulticastFlag type are used to call the IPAddress::MakeIPv6Multicast() methods. + * They indicate the type of IPv6 multicast address to create. These numbers are registered by IETF with IANA. */ -typedef enum +enum class IPv6MulticastFlag : uint8_t { /** The multicast address is (1) transient (i.e., dynamically-assigned) rather than (0) well-known (i.e, IANA-assigned). */ - kIPv6MulticastFlag_Transient = 0x01, + kTransient = 0x01, /** The multicast address is (1) based on a network prefix. */ - kIPv6MulticastFlag_Prefix = 0x02 -} IPv6MulticastFlag; - -/** - * @brief Maximum length of the string representation of an IP address. - */ -#if CHIP_SYSTEM_CONFIG_USE_LWIP -constexpr uint16_t kMaxIPAddressStringLength = IP6ADDR_STRLEN_MAX; -#else -constexpr uint16_t kMaxIPAddressStringLength = INET6_ADDRSTRLEN; -#endif + kPrefix = 0x02 +}; +using IPv6MulticastFlags = BitFlags; /** - * @brief Internet protocol address + * Internet protocol address * - * @details * The CHIP Inet Layer uses objects of this class to represent Internet * protocol addresses (independent of protocol version). */ class DLL_EXPORT IPAddress { public: + /** + * Maximum length of the string representation of an IP address, including a terminating NUL. + */ +#if CHIP_SYSTEM_CONFIG_USE_LWIP + static constexpr uint16_t kMaxStringLength = IP6ADDR_STRLEN_MAX; +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP +#if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK + static constexpr uint16_t kMaxStringLength = INET6_ADDRSTRLEN; +#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK + IPAddress() = default; /** @@ -283,9 +270,9 @@ class DLL_EXPORT IPAddress * Use this method to return an value of the enumerated type \c * IPAddressType to indicate the type of the IP address. * - * @retval kIPAddressType_IPv4 The address is IPv4. - * @retval kIPAddressType_IPv6 The address is IPv6. - * @retval kIPAddressType_Any The address is the unspecified address. + * @retval IPAddressType::kIPv4 The address is IPv4. + * @retval IPAddressType::kIPv6 The address is IPv6. + * @retval IPAddressType::kAny The address is the unspecified address. */ IPAddressType Type() const; @@ -620,21 +607,21 @@ class DLL_EXPORT IPAddress * * @return The constructed IP address. */ - static IPAddress MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, + static IPAddress MakeIPv6Multicast(IPv6MulticastFlags aFlags, uint8_t aScope, const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES]); /** * @brief Construct an IPv6 multicast address from its parts. * * @details - * Use MakeIPv6Multicast(uint8_t flags, uint8_t scope, + * Use MakeIPv6Multicast(IPv6MulticastFlag flags, uint8_t scope, * uint32_t groupId) to construct an IPv6 multicast * address with \c flags for routing scope \c scope and group * identifier \c groupId. * * @return The constructed IP address. */ - static IPAddress MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, uint32_t aGroupId); + static IPAddress MakeIPv6Multicast(IPv6MulticastFlags aFlags, uint8_t aScope, uint32_t aGroupId); /** * @brief Construct a well-known IPv6 multicast address from its parts. @@ -652,14 +639,14 @@ class DLL_EXPORT IPAddress * @brief Construct a transient IPv6 multicast address from its parts. * * @details - * Use MakeIPv6TransientMulticast(uint8_t flags, uint8_t scope, + * Use MakeIPv6TransientMulticast(IPv6MulticastFlag flags, uint8_t scope, * uint8_t groupId[14]) to construct a transient IPv6 * multicast address with \c flags for routing scope \c scope and * group identifier octets \c groupId. * * @return The constructed IP address. */ - static IPAddress MakeIPv6TransientMulticast(uint8_t aFlags, uint8_t aScope, + static IPAddress MakeIPv6TransientMulticast(IPv6MulticastFlags aFlags, uint8_t aScope, const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES]); /** diff --git a/src/inet/IPEndPointBasis.cpp b/src/inet/IPEndPointBasis.cpp index a052d8874e4d6c..9c3a0075804fab 100644 --- a/src/inet/IPEndPointBasis.cpp +++ b/src/inet/IPEndPointBasis.cpp @@ -246,7 +246,7 @@ CHIP_ERROR IPEndPointBasis::IPv6JoinLeaveMulticastGroupImpl(InterfaceId aInterfa void IPEndPointBasis::HandleDataReceived(System::PacketBufferHandle && aBuffer) { - if ((mState == kState_Listening) && (OnMessageReceived != NULL)) + if ((mState == State::kListening) && (OnMessageReceived != NULL)) { const IPPacketInfo * pktInfo = GetPacketInfo(aBuffer); @@ -504,7 +504,7 @@ CHIP_ERROR IPEndPointBasis::Bind(IPAddressType aAddressType, const IPAddress & a { CHIP_ERROR lRetval = CHIP_NO_ERROR; - if (aAddressType == kIPAddressType_IPv6) + if (aAddressType == IPAddressType::kIPv6) { struct sockaddr_in6 sa; @@ -537,7 +537,7 @@ CHIP_ERROR IPEndPointBasis::Bind(IPAddressType aAddressType, const IPAddress & a #endif // defined(IPV6_MULTICAST_HOPS) } #if INET_CONFIG_ENABLE_IPV4 - else if (aAddressType == kIPAddressType_IPv4) + else if (aAddressType == IPAddressType::kIPv4) { struct sockaddr_in sa; int enable = 1; @@ -642,7 +642,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System: PeerSockAddr peerSockAddr; memset(&peerSockAddr, 0, sizeof(peerSockAddr)); msgHeader.msg_name = &peerSockAddr; - if (mAddrType == kIPAddressType_IPv6) + if (mAddrType == IPAddressType::kIPv6) { peerSockAddr.in6.sin6_family = AF_INET6; peerSockAddr.in6.sin6_port = htons(aPktInfo->DestPort); @@ -675,7 +675,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System: // address, construct an IP_PKTINFO/IPV6_PKTINFO "control message" to that effect // add add it to the message header. If the local OS doesn't support IP_PKTINFO/IPV6_PKTINFO // fail with an error. - if (intfId != INET_NULL_INTERFACEID || aPktInfo->SrcAddress.Type() != kIPAddressType_Any) + if (intfId != INET_NULL_INTERFACEID || aPktInfo->SrcAddress.Type() != IPAddressType::kAny) { #if defined(IP_PKTINFO) || defined(IPV6_PKTINFO) msgHeader.msg_control = controlData; @@ -685,7 +685,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System: #if INET_CONFIG_ENABLE_IPV4 - if (mAddrType == kIPAddressType_IPv4) + if (mAddrType == IPAddressType::kIPv4) { #if defined(IP_PKTINFO) controlHdr->cmsg_level = IPPROTO_IP; @@ -709,7 +709,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System: #endif // INET_CONFIG_ENABLE_IPV4 - if (mAddrType == kIPAddressType_IPv6) + if (mAddrType == IPAddressType::kIPv6) { #if defined(IPV6_PKTINFO) controlHdr->cmsg_level = IPPROTO_IPV6; @@ -753,12 +753,12 @@ CHIP_ERROR IPEndPointBasis::GetSocket(IPAddressType aAddressType, int aType, int switch (aAddressType) { - case kIPAddressType_IPv6: + case IPAddressType::kIPv6: family = PF_INET6; break; #if INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv4: + case IPAddressType::kIPv4: family = PF_INET; break; #endif // INET_CONFIG_ENABLE_IPV4 @@ -799,7 +799,7 @@ CHIP_ERROR IPEndPointBasis::GetSocket(IPAddressType aAddressType, int aType, int // the same port, one for IPv4 and one for IPv6. #ifdef IPV6_V6ONLY - if (aAddressType == kIPAddressType_IPv6) + if (aAddressType == IPAddressType::kIPv6) { res = setsockopt(mSocket, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one)); if (res != 0) @@ -811,7 +811,7 @@ CHIP_ERROR IPEndPointBasis::GetSocket(IPAddressType aAddressType, int aType, int #if INET_CONFIG_ENABLE_IPV4 #ifdef IP_PKTINFO - if (aAddressType == kIPAddressType_IPv4) + if (aAddressType == IPAddressType::kIPv4) { res = setsockopt(mSocket, IPPROTO_IP, IP_PKTINFO, &one, sizeof(one)); if (res != 0) @@ -823,7 +823,7 @@ CHIP_ERROR IPEndPointBasis::GetSocket(IPAddressType aAddressType, int aType, int #endif // INET_CONFIG_ENABLE_IPV4 #ifdef IPV6_RECVPKTINFO - if (aAddressType == kIPAddressType_IPv6) + if (aAddressType == IPAddressType::kIPv6) { res = setsockopt(mSocket, IPPROTO_IPV6, IPV6_RECVPKTINFO, &one, sizeof(one)); if (res != 0) @@ -1011,12 +1011,12 @@ CHIP_ERROR IPEndPointBasis::ConfigureProtocol(IPAddressType aAddressType, const switch (aAddressType) { - case kIPAddressType_IPv6: + case IPAddressType::kIPv6: nw_ip_options_set_version(ipOptions, nw_ip_version_6); break; #if INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv4: + case IPAddressType::kIPv4: nw_ip_options_set_version(ipOptions, nw_ip_version_4); break; #endif // INET_CONFIG_ENABLE_IPV4 @@ -1173,7 +1173,7 @@ CHIP_ERROR IPEndPointBasis::GetEndPoint(nw_endpoint_t & aEndPoint, const IPAddre // Note: aAddress.ToString will return the IPv6 Any address if the address type is Any, but that's not what // we want if the locale endpoint is IPv4. - if (aAddressType == kIPAddressType_IPv4 && aAddress.Type() == kIPAddressType_Any) + if (aAddressType == IPAddressType::kIPv4 && aAddress.Type() == IPAddressType::kAny) { const IPAddress anyAddr = IPAddress::FromIPv4(aAddress.ToIPv4()); anyAddr.ToString(addrStr, sizeof(addrStr)); @@ -1439,13 +1439,13 @@ CHIP_ERROR IPEndPointBasis::JoinMulticastGroup(InterfaceId aInterfaceId, const I { #if INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv4: { + case IPAddressType::kIPv4: { return IPv4JoinLeaveMulticastGroupImpl(aInterfaceId, aAddress, true); } break; #endif // INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv6: { + case IPAddressType::kIPv6: { return IPv6JoinLeaveMulticastGroupImpl(aInterfaceId, aAddress, true); } break; @@ -1471,13 +1471,13 @@ CHIP_ERROR IPEndPointBasis::LeaveMulticastGroup(InterfaceId aInterfaceId, const { #if INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv4: { + case IPAddressType::kIPv4: { return IPv4JoinLeaveMulticastGroupImpl(aInterfaceId, aAddress, false); } break; #endif // INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv6: { + case IPAddressType::kIPv6: { return IPv6JoinLeaveMulticastGroupImpl(aInterfaceId, aAddress, false); } break; diff --git a/src/inet/IPEndPointBasis.h b/src/inet/IPEndPointBasis.h index 328a8e5ea642aa..d21dd7a86a7fe4 100644 --- a/src/inet/IPEndPointBasis.h +++ b/src/inet/IPEndPointBasis.h @@ -52,26 +52,7 @@ class IPPacketInfo; */ class DLL_EXPORT IPEndPointBasis : public EndPointBasis { - friend class InetLayer; - public: - /** - * @brief Basic dynamic state of the underlying endpoint. - * - * @details - * Objects are initialized in the "ready" state, proceed to the "bound" - * state after binding to a local interface address, then proceed to the - * "listening" state when they have continuations registered for handling - * events for reception of ICMP messages. - */ - enum - { - kState_Ready = 0, /**< Endpoint initialized, but not open. */ - kState_Bound = 1, /**< Endpoint bound, but not listening. */ - kState_Listening = 2, /**< Endpoint receiving datagrams. */ - kState_Closed = 3 /**< Endpoint closed, ready for release. */ - } mState; - /** * @brief Type of message text reception event handling function. * @@ -134,6 +115,24 @@ class DLL_EXPORT IPEndPointBasis : public EndPointBasis CHIP_ERROR LeaveMulticastGroup(InterfaceId aInterfaceId, const IPAddress & aAddress); protected: + friend class InetLayer; + + /** + * Basic dynamic state of the underlying endpoint. + * + * Objects are initialized in the "ready" state, proceed to the "bound" + * state after binding to a local interface address, then proceed to the + * "listening" state when they have continuations registered for handling + * events for reception of ICMP messages. + */ + enum class State : uint8_t + { + kReady = 0, /**< Endpoint initialized, but not open. */ + kBound = 1, /**< Endpoint bound, but not listening. */ + kListening = 2, /**< Endpoint receiving datagrams. */ + kClosed = 3 /**< Endpoint closed, ready for release. */ + } mState; + void Init(InetLayer * aInetLayer); /** The endpoint's message reception event handling function delegate. */ diff --git a/src/inet/IPPrefix.h b/src/inet/IPPrefix.h index c255a0aefa459f..124cf0445ac6f4 100644 --- a/src/inet/IPPrefix.h +++ b/src/inet/IPPrefix.h @@ -62,14 +62,14 @@ class IPPrefix * @details * Note well: this field is public, and it is an invariant of this class * that Length <= 32 where the type of \c IPAddr is - * \c kIPAddressType_IPv4 and Length <= 128 where the type of - * \c IPAddr is \c kIPAddressType_IPv6. + * \c IPAddressType::kIPv4 and Length <= 128 where the type of + * \c IPAddr is \c IPAddressType::kIPv6. */ uint8_t Length; /** * A distinguished object where the type of \c IPAddr is - * \c kIPAddressType_Any and Length == 0. + * \c IPAddressType::kAny and Length == 0. */ static IPPrefix Zero; @@ -78,7 +78,7 @@ class IPPrefix * * @details * Note well: a prefix is not equivalent to \c Zero if the type of - * \c IPAddr is not \c kIPAddressType_Any. + * \c IPAddr is not \c IPAddressType::kAny. * * @return \c true if equivalent to \c Zero, else \c false. */ diff --git a/src/inet/TCPEndPoint.cpp b/src/inet/TCPEndPoint.cpp index 137319a5e38fcb..dba5199d5a4dc9 100644 --- a/src/inet/TCPEndPoint.cpp +++ b/src/inet/TCPEndPoint.cpp @@ -133,12 +133,12 @@ CHIP_ERROR TCPEndPoint::BindImpl(IPAddressType addrType, const IPAddress & addr, { ipAddr = addr.ToLwIPAddr(); } - else if (addrType == kIPAddressType_IPv6) + else if (addrType == IPAddressType::kIPv6) { ipAddr = ip6_addr_any; } #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) { ipAddr = ip_addr_any; } @@ -149,13 +149,13 @@ CHIP_ERROR TCPEndPoint::BindImpl(IPAddressType addrType, const IPAddress & addr, #else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) { ip6_addr_t ipv6Addr = addr.ToIPv6(); res = chip::System::MapErrorLwIP(tcp_bind_ip6(mTCP, &ipv6Addr, port)); } #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) { ip_addr_t ipv4Addr = addr.ToIPv4(); res = chip::System::MapErrorLwIP(tcp_bind(mTCP, &ipv4Addr, port)); @@ -199,14 +199,14 @@ CHIP_ERROR TCPEndPoint::ConnectImpl(const IPAddress & addr, uint16_t port, Inter IPAddress intfLLAddr; InetLayer & lInetLayer = Layer(); - if (!addr.IsIPv6LinkLocal() || State == kState_Bound) + if (!addr.IsIPv6LinkLocal() || mState == State::kBound) return CHIP_ERROR_NOT_IMPLEMENTED; res = lInetLayer.GetLinkLocalAddr(intfId, &intfLLAddr); if (res != CHIP_NO_ERROR) return res; - res = Bind(kIPAddressType_IPv6, intfLLAddr, 0, true); + res = Bind(IPAddressType::kIPv6, intfLLAddr, 0, true); if (res != CHIP_NO_ERROR) return res; } @@ -225,13 +225,13 @@ CHIP_ERROR TCPEndPoint::ConnectImpl(const IPAddress & addr, uint16_t port, Inter ip_addr_t lwipAddr = addr.ToLwIPAddr(); res = chip::System::MapErrorLwIP(tcp_connect(mTCP, &lwipAddr, port, LwIPHandleConnectComplete)); #else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) { ip6_addr_t lwipAddr = addr.ToIPv6(); res = chip::System::MapErrorLwIP(tcp_connect_ip6(mTCP, &lwipAddr, port, LwIPHandleConnectComplete)); } #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) { ip_addr_t lwipAddr = addr.ToIPv4(); res = chip::System::MapErrorLwIP(tcp_connect(mTCP, &lwipAddr, port, LwIPHandleConnectComplete)); @@ -253,7 +253,7 @@ CHIP_ERROR TCPEndPoint::ConnectImpl(const IPAddress & addr, uint16_t port, Inter if (res == CHIP_NO_ERROR) { - State = kState_Connecting; + mState = State::kConnecting; Retain(); } } @@ -564,7 +564,7 @@ CHIP_ERROR TCPEndPoint::DriveSendingImpl() if (err == CHIP_NO_ERROR) { // If in the SendShutdown state and the unsent queue is now empty, shutdown the PCB for sending. - if (State == kState_SendShutdown && (RemainingToSend() == 0)) + if (mState == State::kSendShutdown && (RemainingToSend() == 0)) { lwipErr = tcp_shutdown(mTCP, 0, 1); if (lwipErr != ERR_OK) @@ -584,7 +584,7 @@ CHIP_ERROR TCPEndPoint::DriveSendingImpl() void TCPEndPoint::HandleConnectCompleteImpl() {} -void TCPEndPoint::DoCloseImpl(CHIP_ERROR err, int oldState) +void TCPEndPoint::DoCloseImpl(CHIP_ERROR err, State oldState) { // Lock LwIP stack LOCK_TCPIP_CORE(); @@ -593,14 +593,14 @@ void TCPEndPoint::DoCloseImpl(CHIP_ERROR err, int oldState) if (mTCP != NULL) { // If the endpoint was a connection endpoint (vs. a listening endpoint)... - if (oldState != kState_Listening) + if (oldState != State::kListening) { // Prevent further callbacks for incoming data. This has the effect of instructing // LwIP to discard any further data received from the peer. tcp_recv(mTCP, NULL); // If entering the Closed state... - if (State == kState_Closed) + if (mState == State::kClosed) { // Prevent further callbacks to the error handler. // @@ -651,7 +651,7 @@ void TCPEndPoint::DoCloseImpl(CHIP_ERROR err, int oldState) // Unlock LwIP stack UNLOCK_TCPIP_CORE(); - if (State == kState_Closed) + if (mState == State::kClosed) { mUnackedLength = 0; } @@ -739,12 +739,12 @@ CHIP_ERROR TCPEndPoint::GetPCB(IPAddressType addrType) { switch (addrType) { - case kIPAddressType_IPv6: + case IPAddressType::kIPv6: mTCP = tcp_new_ip_type(IPADDR_TYPE_V6); break; #if INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv4: + case IPAddressType::kIPv4: mTCP = tcp_new_ip_type(IPADDR_TYPE_V4); break; #endif // INET_CONFIG_ENABLE_IPV4 @@ -767,13 +767,13 @@ CHIP_ERROR TCPEndPoint::GetPCB(IPAddressType addrType) switch (IP_GET_TYPE(&mTCP->local_ip)) { case IPADDR_TYPE_V6: - if (addrType != kIPAddressType_IPv6) + if (addrType != IPAddressType::kIPv6) return INET_ERROR_WRONG_ADDRESS_TYPE; break; #if INET_CONFIG_ENABLE_IPV4 case IPADDR_TYPE_V4: - if (addrType != kIPAddressType_IPv4) + if (addrType != IPAddressType::kIPv4) return INET_ERROR_WRONG_ADDRESS_TYPE; break; #endif // INET_CONFIG_ENABLE_IPV4 @@ -785,10 +785,10 @@ CHIP_ERROR TCPEndPoint::GetPCB(IPAddressType addrType) #else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 if (mTCP == NULL) { - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) mTCP = tcp_new_ip6(); #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) mTCP = tcp_new(); #endif // INET_CONFIG_ENABLE_IPV4 else @@ -805,9 +805,9 @@ CHIP_ERROR TCPEndPoint::GetPCB(IPAddressType addrType) else { #if INET_CONFIG_ENABLE_IPV4 - const IPAddressType pcbType = PCB_ISIPV6(mTCP) ? kIPAddressType_IPv6 : kIPAddressType_IPv4; + const IPAddressType pcbType = PCB_ISIPV6(mTCP) ? IPAddressType::kIPv6 : IPAddressType::kIPv4; #else // !INET_CONFIG_ENABLE_IPV4 - const IPAddressType pcbType = kIPAddressType_IPv6; + const IPAddressType pcbType = IPAddressType::kIPv6; #endif // !INET_CONFIG_ENABLE_IPV4 if (addrType != pcbType) return INET_ERROR_WRONG_ADDRESS_TYPE; @@ -879,7 +879,7 @@ void TCPEndPoint::HandleDataSent(uint16_t lenSent) DriveSending(); // If in the closing state and the send queue is now empty, attempt to transition to closed. - if ((State == kState_Closing) && (RemainingToSend() == 0)) + if ((mState == State::kClosing) && (RemainingToSend() == 0)) DoClose(CHIP_NO_ERROR, false); } } @@ -887,7 +887,7 @@ void TCPEndPoint::HandleDataSent(uint16_t lenSent) void TCPEndPoint::HandleDataReceived(System::PacketBufferHandle && buf) { // Only receive new data while in the Connected or SendShutdown states. - if (State == kState_Connected || State == kState_SendShutdown) + if (mState == State::kConnected || mState == State::kSendShutdown) { // Mark the connection as being active. MarkActive(); @@ -916,10 +916,10 @@ void TCPEndPoint::HandleDataReceived(System::PacketBufferHandle && buf) // the app to decide whether to keep the send side of the connection open after // the peer has closed. If no OnPeerClose is provided, we assume that the app // wants to close both directions and automatically enter the Closing state. - if (State == kState_Connected && OnPeerClose != NULL) - State = kState_ReceiveShutdown; + if (mState == State::kConnected && OnPeerClose != NULL) + mState = State::kReceiveShutdown; else - State = kState_Closing; + mState = State::kClosing; // Call the app's OnPeerClose. if (OnPeerClose != NULL) @@ -937,7 +937,7 @@ void TCPEndPoint::HandleIncomingConnection(TCPEndPoint * conEP) IPAddress peerAddr; uint16_t peerPort; - if (State == kState_Listening) + if (mState == State::kListening) { // If there's no callback available, fail with an error. if (OnConnectionReceived == NULL) @@ -965,7 +965,7 @@ void TCPEndPoint::HandleIncomingConnection(TCPEndPoint * conEP) void TCPEndPoint::HandleError(CHIP_ERROR err) { - if (State == kState_Listening) + if (mState == State::kListening) { if (OnAcceptError != NULL) OnAcceptError(this, err); @@ -1047,7 +1047,7 @@ err_t TCPEndPoint::LwIPHandleIncomingConnection(void * arg, struct tcp_pcb * tpc if (err == CHIP_NO_ERROR) { // Put the new end point into the Connected state. - conEP->State = kState_Connected; + conEP->mState = State::kConnected; conEP->mTCP = tpcb; conEP->mLwIPEndPointType = LwIPEndPointType::TCP; conEP->Retain(); @@ -1183,7 +1183,7 @@ CHIP_ERROR TCPEndPoint::BindImpl(IPAddressType addrType, const IPAddress & addr, if (res == CHIP_NO_ERROR) { - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) { struct sockaddr_in6 sa; memset(&sa, 0, sizeof(sa)); @@ -1197,7 +1197,7 @@ CHIP_ERROR TCPEndPoint::BindImpl(IPAddressType addrType, const IPAddress & addr, res = CHIP_ERROR_POSIX(errno); } #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) { struct sockaddr_in sa; memset(&sa, 0, sizeof(sa)); @@ -1342,7 +1342,7 @@ CHIP_ERROR TCPEndPoint::ConnectImpl(const IPAddress & addr, uint16_t port, Inter } sa; memset(&sa, 0, sizeof(sa)); - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) { sa.in6.sin6_family = AF_INET6; sa.in6.sin6_port = htons(port); @@ -1353,7 +1353,7 @@ CHIP_ERROR TCPEndPoint::ConnectImpl(const IPAddress & addr, uint16_t port, Inter sockaddrptr = reinterpret_cast(&sa.in6); } #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) { sa.in.sin_family = AF_INET; sa.in.sin_port = htons(port); @@ -1383,7 +1383,7 @@ CHIP_ERROR TCPEndPoint::ConnectImpl(const IPAddress & addr, uint16_t port, Inter if (conRes == 0) { - State = kState_Connected; + mState = State::kConnected; // Wait for ability to read on this endpoint. ReturnErrorOnFailure(static_cast(Layer().SystemLayer())->RequestCallbackOnPendingRead(mWatch)); if (OnConnectComplete != nullptr) @@ -1391,7 +1391,7 @@ CHIP_ERROR TCPEndPoint::ConnectImpl(const IPAddress & addr, uint16_t port, Inter } else { - State = kState_Connecting; + mState = State::kConnecting; // Wait for ability to write on this endpoint. ReturnErrorOnFailure(static_cast(Layer().SystemLayer())->RequestCallbackOnPendingWrite(mWatch)); } @@ -1742,7 +1742,7 @@ CHIP_ERROR TCPEndPoint::DriveSendingImpl() if (err == CHIP_NO_ERROR) { // If we're in the SendShutdown state and the send queue is now empty, shutdown writing on the socket. - if (State == kState_SendShutdown && mSendQueue.IsNull()) + if (mState == State::kSendShutdown && mSendQueue.IsNull()) { if (shutdown(mSocket, SHUT_WR) != 0) err = CHIP_ERROR_POSIX(errno); @@ -1767,7 +1767,7 @@ void TCPEndPoint::HandleConnectCompleteImpl() } } -void TCPEndPoint::DoCloseImpl(CHIP_ERROR err, int oldState) +void TCPEndPoint::DoCloseImpl(CHIP_ERROR err, State oldState) { struct linger lingerStruct; @@ -1777,7 +1777,7 @@ void TCPEndPoint::DoCloseImpl(CHIP_ERROR err, int oldState) // If entering the Closed state // OR if entering the Closing state, and there's no unsent data in the send queue // THEN close the socket. - if (State == kState_Closed || (State == kState_Closing && mSendQueue.IsNull())) + if (mState == State::kClosed || (mState == State::kClosing && mSendQueue.IsNull())) { // If aborting the connection, ensure we send a TCP RST. if (IsConnected(oldState) && err != CHIP_NO_ERROR) @@ -1887,7 +1887,7 @@ CHIP_ERROR TCPEndPoint::BindSrcAddrFromIntf(IPAddressType addrType, InterfaceId // and use that address as the source address for that connection. This is // done in the event that directly binding the connection to the target // interface is not allowed due to insufficient privileges. - VerifyOrReturnError(State != kState_Bound, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + VerifyOrReturnError(mState != State::kBound, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); bool ipAddrFound = false; for (InterfaceAddressIterator addrIter; addrIter.HasCurrent(); addrIter.Next()) @@ -1900,19 +1900,19 @@ CHIP_ERROR TCPEndPoint::BindSrcAddrFromIntf(IPAddressType addrType, InterfaceId // Search for an IPv4 address on the TargetInterface #if INET_CONFIG_ENABLE_IPV4 - if (addrType == kIPAddressType_IPv4) + if (addrType == IPAddressType::kIPv4) { if (curAddr.IsIPv4()) { // Bind to the IPv4 address of the TargetInterface ipAddrFound = true; - ReturnErrorOnFailure(Bind(kIPAddressType_IPv4, curAddr, 0, true)); + ReturnErrorOnFailure(Bind(IPAddressType::kIPv4, curAddr, 0, true)); break; } } #endif // INET_CONFIG_ENABLE_IPV4 - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) { // Select an IPv6 address on the interface that is not // a link local or a multicast address. @@ -1921,7 +1921,7 @@ CHIP_ERROR TCPEndPoint::BindSrcAddrFromIntf(IPAddressType addrType, InterfaceId { // Bind to the IPv6 address of the TargetInterface ipAddrFound = true; - ReturnErrorOnFailure(Bind(kIPAddressType_IPv6, curAddr, 0, true)); + ReturnErrorOnFailure(Bind(IPAddressType::kIPv6, curAddr, 0, true)); break; } @@ -1939,10 +1939,10 @@ CHIP_ERROR TCPEndPoint::GetSocket(IPAddressType addrType) if (mSocket == kInvalidSocketFd) { int family; - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) family = PF_INET6; #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) family = PF_INET; #endif // INET_CONFIG_ENABLE_IPV4 else @@ -1997,7 +1997,7 @@ void TCPEndPoint::HandlePendingIO(System::SocketEvents events) // If in the Listening state, and the app is ready to receive a connection, and there is a connection // ready to be received on the socket, process the incoming connection. - if (State == kState_Listening) + if (mState == State::kListening) { if (OnConnectionReceived != nullptr && events.Has(System::SocketEventFlags::kRead)) { @@ -2006,7 +2006,7 @@ void TCPEndPoint::HandlePendingIO(System::SocketEvents events) } // If in the processes of initiating a connection... - else if (State == kState_Connecting) + else if (mState == State::kConnecting) { // The socket being writable indicates the connection has completed (successfully or otherwise). if (events.Has(System::SocketEventFlags::kWrite)) @@ -2038,7 +2038,7 @@ void TCPEndPoint::HandlePendingIO(System::SocketEvents events) // If in a state were receiving is allowed, and the app is ready to receive data, and data is ready // on the socket, receive inbound data from the connection. - if ((State == kState_Connected || State == kState_SendShutdown) && ReceiveEnabled && OnDataReceived != nullptr && + if ((mState == State::kConnected || mState == State::kSendShutdown) && ReceiveEnabled && OnDataReceived != nullptr && events.Has(System::SocketEventFlags::kRead)) ReceiveData(); } @@ -2141,10 +2141,10 @@ void TCPEndPoint::ReceiveData() // the app to decide whether to keep the send side of the connection open after // the peer has closed. If no OnPeerClose is provided, we assume that the app // wants to close both directions and automatically enter the Closing state. - if (State == kState_Connected && OnPeerClose != nullptr) - State = kState_ReceiveShutdown; + if (mState == State::kConnected && OnPeerClose != nullptr) + mState = State::kReceiveShutdown; else - State = kState_Closing; + mState = State::kClosing; // Do not wait for ability to read on this endpoint. (void) static_cast(Layer().SystemLayer())->ClearCallbackOnPendingRead(mWatch); // Call the app's OnPeerClose. @@ -2247,11 +2247,11 @@ void TCPEndPoint::HandleIncomingConnection() err = static_cast(Layer().SystemLayer())->StartWatchingSocket(conSocket, &conEP->mWatch); if (err == CHIP_NO_ERROR) { - conEP->State = kState_Connected; + conEP->mState = State::kConnected; #if INET_CONFIG_ENABLE_IPV4 - conEP->mAddrType = (sa.any.sa_family == AF_INET6) ? kIPAddressType_IPv6 : kIPAddressType_IPv4; + conEP->mAddrType = (sa.any.sa_family == AF_INET6) ? IPAddressType::kIPv6 : IPAddressType::kIPv4; #else // !INET_CONFIG_ENABLE_IPV4 - conEP->mAddrType = kIPAddressType_IPv6; + conEP->mAddrType = IPAddressType::kIPv6; #endif // !INET_CONFIG_ENABLE_IPV4 conEP->Retain(); @@ -2276,7 +2276,7 @@ void TCPEndPoint::HandleIncomingConnection() close(conSocket); if (conEP != nullptr) { - if (conEP->State == kState_Connected) + if (conEP->mState == State::kConnected) { conEP->Release(); } @@ -2340,17 +2340,17 @@ CHIP_ERROR TCPEndPoint::Bind(IPAddressType addrType, const IPAddress & addr, uin { CHIP_ERROR res = CHIP_NO_ERROR; - if (State != kState_Ready) + if (mState != State::kReady) return CHIP_ERROR_INCORRECT_STATE; - if (addr != IPAddress::Any && addr.Type() != kIPAddressType_Any && addr.Type() != addrType) + if (addr != IPAddress::Any && addr.Type() != IPAddressType::kAny && addr.Type() != addrType) return INET_ERROR_WRONG_ADDRESS_TYPE; res = BindImpl(addrType, addr, port, reuseAddr); if (res == CHIP_NO_ERROR) { - State = kState_Bound; + mState = State::kBound; } return res; @@ -2360,7 +2360,7 @@ CHIP_ERROR TCPEndPoint::Listen(uint16_t backlog) { CHIP_ERROR res = CHIP_NO_ERROR; - if (State != kState_Bound) + if (mState != State::kBound) return CHIP_ERROR_INCORRECT_STATE; res = ListenImpl(backlog); @@ -2370,7 +2370,7 @@ CHIP_ERROR TCPEndPoint::Listen(uint16_t backlog) // Once Listening, bump the reference count. The corresponding call to Release() // [or on LwIP, DeferredRelease()] will happen in DoClose(). Retain(); - State = kState_Listening; + mState = State::kListening; } return res; @@ -2380,7 +2380,7 @@ CHIP_ERROR TCPEndPoint::Connect(const IPAddress & addr, uint16_t port, Interface { CHIP_ERROR res = CHIP_NO_ERROR; - if (State != kState_Ready && State != kState_Bound) + if (mState != State::kReady && mState != State::kBound) return CHIP_ERROR_INCORRECT_STATE; ReturnErrorOnFailure(ConnectImpl(addr, port, intfId)); @@ -2394,7 +2394,7 @@ CHIP_ERROR TCPEndPoint::Send(System::PacketBufferHandle && data, bool push) { CHIP_ERROR res = CHIP_NO_ERROR; - if (State != kState_Connected && State != kState_ReceiveShutdown) + if (mState != State::kConnected && mState != State::kReceiveShutdown) { return CHIP_ERROR_INCORRECT_STATE; } @@ -2448,14 +2448,14 @@ CHIP_ERROR TCPEndPoint::Shutdown() return CHIP_ERROR_INCORRECT_STATE; // If fully connected, enter the SendShutdown state. - if (State == kState_Connected) + if (mState == State::kConnected) { - State = kState_SendShutdown; + mState = State::kSendShutdown; DriveSending(); } // Otherwise, if the peer has already closed their end of the connection, - else if (State == kState_ReceiveShutdown) + else if (mState == State::kReceiveShutdown) err = DoClose(err, false); return err; @@ -2574,9 +2574,10 @@ void TCPEndPoint::TCPConnectTimeoutHandler(chip::System::Layer * aSystemLayer, v tcpEndPoint->DoClose(INET_ERROR_TCP_CONNECT_TIMEOUT, false); } -bool TCPEndPoint::IsConnected(int state) +bool TCPEndPoint::IsConnected(State state) { - return state == kState_Connected || state == kState_SendShutdown || state == kState_ReceiveShutdown || state == kState_Closing; + return state == State::kConnected || state == State::kSendShutdown || state == State::kReceiveShutdown || + state == State::kClosing; } void TCPEndPoint::Init(InetLayer * inetLayer) @@ -2640,7 +2641,7 @@ void TCPEndPoint::DriveReceiving() // If the connection is closing, and the receive queue is now empty, call DoClose() to complete // the process of closing the connection. - if (State == kState_Closing && mRcvQueue.IsNull()) + if (mState == State::kClosing && mRcvQueue.IsNull()) DoClose(CHIP_NO_ERROR, false); } @@ -2655,7 +2656,7 @@ void TCPEndPoint::HandleConnectComplete(CHIP_ERROR err) // Mark the connection as being active. MarkActive(); - State = kState_Connected; + mState = State::kConnected; HandleConnectCompleteImpl(); @@ -2672,7 +2673,7 @@ void TCPEndPoint::HandleConnectComplete(CHIP_ERROR err) CHIP_ERROR TCPEndPoint::DoClose(CHIP_ERROR err, bool suppressCallback) { - int oldState = State; + State oldState = mState; // If in one of the connected states (Connected, LocalShutdown, PeerShutdown or Closing) // AND this is a graceful close (i.e. not prompted by an error) @@ -2680,18 +2681,18 @@ CHIP_ERROR TCPEndPoint::DoClose(CHIP_ERROR err, bool suppressCallback) // ... THEN enter the Closing state, allowing the queued data to drain, // ... OTHERWISE go straight to the Closed state. if (IsConnected() && err == CHIP_NO_ERROR && (!mSendQueue.IsNull() || !mRcvQueue.IsNull())) - State = kState_Closing; + mState = State::kClosing; else - State = kState_Closed; + mState = State::kClosed; - if (oldState != kState_Closed) + if (oldState != State::kClosed) { // Stop the Connect timer in case it is still running. StopConnectTimer(); } // If not making a state transition, return immediately. - if (State == oldState) + if (mState == oldState) { return CHIP_NO_ERROR; } @@ -2704,7 +2705,7 @@ CHIP_ERROR TCPEndPoint::DoClose(CHIP_ERROR err, bool suppressCallback) #endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT // If entering the Closed state... - if (State == kState_Closed) + if (mState == State::kClosed) { // Clear clear the send and receive queues. mSendQueue = nullptr; @@ -2713,13 +2714,13 @@ CHIP_ERROR TCPEndPoint::DoClose(CHIP_ERROR err, bool suppressCallback) // Call the appropriate app callback if allowed. if (!suppressCallback) { - if (oldState == kState_Connecting) + if (oldState == State::kConnecting) { if (OnConnectComplete != nullptr) OnConnectComplete(this, err); } - else if ((oldState == kState_Connected || oldState == kState_SendShutdown || oldState == kState_ReceiveShutdown || - oldState == kState_Closing) && + else if ((oldState == State::kConnected || oldState == State::kSendShutdown || oldState == State::kReceiveShutdown || + oldState == State::kClosing) && OnConnectionClosed != nullptr) OnConnectionClosed(this, err); } @@ -2732,7 +2733,7 @@ CHIP_ERROR TCPEndPoint::DoClose(CHIP_ERROR err, bool suppressCallback) // We achieve this by first preventing further up-calls from LwIP (via the call to tcp_abort() above) // and then queuing the Release() call to happen after all existing events have been processed. // - if (oldState != kState_Ready && oldState != kState_Bound) + if (oldState != State::kReady && oldState != State::kBound) { DeferredFree(kReleaseDeferralErrorTactic_Ignore); } diff --git a/src/inet/TCPEndPoint.h b/src/inet/TCPEndPoint.h index 812c427b24d607..d11fd06ba187c4 100644 --- a/src/inet/TCPEndPoint.h +++ b/src/inet/TCPEndPoint.h @@ -67,25 +67,24 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis bool ReceiveEnabled; /** - * @brief Basic dynamic state of the underlying endpoint. + * Basic dynamic state of the underlying endpoint. * - * @details * Objects are initialized in the "ready" state, proceed to subsequent * states corresponding to a simplification of the states of the TCP * transport state machine. */ - enum + enum class State : uint8_t { - kState_Ready = 0, /**< Endpoint initialized, but not bound. */ - kState_Bound = 1, /**< Endpoint bound, but not listening. */ - kState_Listening = 2, /**< Endpoint receiving connections. */ - kState_Connecting = 3, /**< Endpoint attempting to connect. */ - kState_Connected = 4, /**< Endpoint connected, ready for tx/rx. */ - kState_SendShutdown = 5, /**< Endpoint initiated its half-close. */ - kState_ReceiveShutdown = 6, /**< Endpoint responded to half-close. */ - kState_Closing = 7, /**< Endpoint closing bidirectionally. */ - kState_Closed = 8 /**< Endpoint closed, ready for release. */ - } State; + kReady = 0, /**< Endpoint initialized, but not bound. */ + kBound = 1, /**< Endpoint bound, but not listening. */ + kListening = 2, /**< Endpoint receiving connections. */ + kConnecting = 3, /**< Endpoint attempting to connect. */ + kConnected = 4, /**< Endpoint connected, ready for tx/rx. */ + kSendShutdown = 5, /**< Endpoint initiated its half-close. */ + kReceiveShutdown = 6, /**< Endpoint responded to half-close. */ + kClosing = 7, /**< Endpoint closing bidirectionally. */ + kClosed = 8 /**< Endpoint closed, ready for release. */ + } mState; TCPEndPoint() = default; @@ -105,7 +104,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * \c addrType does not match \c IPVer. * * @retval INET_ERROR_WRONG_ADDRESS_TYPE - * \c addrType is \c kIPAddressType_Any, or the type of \c addr is not + * \c addrType is \c IPAddressType::kAny, or the type of \c addr is not * equal to \c addrType. * * @retval other another system or platform error @@ -127,8 +126,8 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * @retval CHIP_ERROR_INCORRECT_STATE endpoint is already listening. * * @details - * If \c State is already \c kState_Listening, then no operation is - * performed, otherwise the \c State is set to \c kState_Listening and + * If \c mState is already \c State::kListening, then no operation is + * performed, otherwise the \c mState is set to \c State::kListening and * the endpoint is prepared to received TCP messages, according to the * semantics of the platform. * @@ -380,7 +379,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis /** * @brief Extract whether TCP connection is established. */ - bool IsConnected() const { return IsConnected(State); } + bool IsConnected() const { return IsConnected(mState); } /** * Set timeout for Connect to succeed or return an error. @@ -666,7 +665,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis void HandleConnectComplete(CHIP_ERROR err); void HandleAcceptError(CHIP_ERROR err); CHIP_ERROR DoClose(CHIP_ERROR err, bool suppressCallback); - static bool IsConnected(int state); + static bool IsConnected(State state); static void TCPConnectTimeoutHandler(chip::System::Layer * aSystemLayer, void * aAppState); @@ -682,7 +681,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis void InitImpl(); CHIP_ERROR DriveSendingImpl(); void HandleConnectCompleteImpl(); - void DoCloseImpl(CHIP_ERROR err, int oldState); + void DoCloseImpl(CHIP_ERROR err, State oldState); #if CHIP_SYSTEM_CONFIG_USE_LWIP struct BufferOffset diff --git a/src/inet/UDPEndPoint.cpp b/src/inet/UDPEndPoint.cpp index f5a88f353565eb..eaef4fc599a244 100644 --- a/src/inet/UDPEndPoint.cpp +++ b/src/inet/UDPEndPoint.cpp @@ -142,20 +142,20 @@ CHIP_ERROR UDPEndPoint::BindImpl(IPAddressType addrType, const IPAddress & addr, // // We may want to consider having separate AnyV4 and AnyV6 constants // inside CHIP to resolve this ambiguity - if ((addr.Type() == kIPAddressType_Any) && (addrType == kIPAddressType_IPv6)) + if ((addr.Type() == IPAddressType::kAny) && (addrType == IPAddressType::kIPv6)) { ipAddr = *IP6_ADDR_ANY; } res = chip::System::MapErrorLwIP(udp_bind(mUDP, &ipAddr, port)); #else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) { ip6_addr_t ipv6Addr = addr.ToIPv6(); res = chip::System::MapErrorLwIP(udp_bind_ip6(mUDP, &ipv6Addr, port)); } #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) { ip4_addr_t ipv4Addr = addr.ToIPv4(); res = chip::System::MapErrorLwIP(udp_bind(mUDP, &ipv4Addr, port)); @@ -383,7 +383,7 @@ CHIP_ERROR UDPEndPoint::GetPCB(IPAddressType addrType) if (mUDP == NULL) { // Allocate a PCB of the appropriate type. - if (addrType == kIPAddressType_IPv6) + if (addrType == IPAddressType::kIPv6) { #if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 mUDP = udp_new_ip_type(IPADDR_TYPE_V6); @@ -392,7 +392,7 @@ CHIP_ERROR UDPEndPoint::GetPCB(IPAddressType addrType) #endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 } #if INET_CONFIG_ENABLE_IPV4 - else if (addrType == kIPAddressType_IPv4) + else if (addrType == IPAddressType::kIPv4) { #if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 mUDP = udp_new_ip_type(IPADDR_TYPE_V4); @@ -427,11 +427,11 @@ CHIP_ERROR UDPEndPoint::GetPCB(IPAddressType addrType) switch (static_cast(IP_GET_TYPE(&mUDP->local_ip))) { case IPADDR_TYPE_V6: - pcbAddrType = kIPAddressType_IPv6; + pcbAddrType = IPAddressType::kIPv6; break; #if INET_CONFIG_ENABLE_IPV4 case IPADDR_TYPE_V4: - pcbAddrType = kIPAddressType_IPv4; + pcbAddrType = IPAddressType::kIPv4; break; #endif // INET_CONFIG_ENABLE_IPV4 default: @@ -439,9 +439,9 @@ CHIP_ERROR UDPEndPoint::GetPCB(IPAddressType addrType) } #else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 #if INET_CONFIG_ENABLE_IPV4 - pcbAddrType = PCB_ISIPV6(mUDP) ? kIPAddressType_IPv6 : kIPAddressType_IPv4; + pcbAddrType = PCB_ISIPV6(mUDP) ? IPAddressType::kIPv6 : IPAddressType::kIPv4; #else // !INET_CONFIG_ENABLE_IPV4 - pcbAddrType = kIPAddressType_IPv6; + pcbAddrType = IPAddressType::kIPv6; #endif // !INET_CONFIG_ENABLE_IPV4 #endif // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 @@ -640,7 +640,7 @@ void UDPEndPoint::HandlePendingIO(System::SocketEvents events, intptr_t data) void UDPEndPoint::HandlePendingIO(System::SocketEvents events) { - if (mState == kState_Listening && OnMessageReceived != nullptr && events.Has(System::SocketEventFlags::kRead)) + if (mState == State::kListening && OnMessageReceived != nullptr && events.Has(System::SocketEventFlags::kRead)) { const uint16_t lPort = mBoundPort; @@ -712,45 +712,45 @@ void UDPEndPoint::Free() CHIP_ERROR UDPEndPoint::Bind(IPAddressType addrType, const IPAddress & addr, uint16_t port, InterfaceId intfId) { - if (mState != kState_Ready && mState != kState_Bound) + if (mState != State::kReady && mState != State::kBound) { return CHIP_ERROR_INCORRECT_STATE; } - if ((addr != IPAddress::Any) && (addr.Type() != kIPAddressType_Any) && (addr.Type() != addrType)) + if ((addr != IPAddress::Any) && (addr.Type() != IPAddressType::kAny) && (addr.Type() != addrType)) { return INET_ERROR_WRONG_ADDRESS_TYPE; } ReturnErrorOnFailure(BindImpl(addrType, addr, port, intfId)); - mState = kState_Bound; + mState = State::kBound; return CHIP_NO_ERROR; } CHIP_ERROR UDPEndPoint::BindInterface(IPAddressType addrType, InterfaceId intfId) { - if (mState != kState_Ready && mState != kState_Bound) + if (mState != State::kReady && mState != State::kBound) { return CHIP_ERROR_INCORRECT_STATE; } ReturnErrorOnFailure(BindInterfaceImpl(addrType, intfId)); - mState = kState_Bound; + mState = State::kBound; return CHIP_NO_ERROR; } CHIP_ERROR UDPEndPoint::Listen(OnMessageReceivedFunct onMessageReceived, OnReceiveErrorFunct onReceiveError, void * appState) { - if (mState == kState_Listening) + if (mState == State::kListening) { return CHIP_NO_ERROR; } - if (mState != kState_Bound) + if (mState != State::kBound) { return CHIP_ERROR_INCORRECT_STATE; } @@ -761,7 +761,7 @@ CHIP_ERROR UDPEndPoint::Listen(OnMessageReceivedFunct onMessageReceived, OnRecei ReturnErrorOnFailure(ListenImpl()); - mState = kState_Listening; + mState = State::kListening; return CHIP_NO_ERROR; } @@ -790,10 +790,10 @@ CHIP_ERROR UDPEndPoint::SendMsg(const IPPacketInfo * pktInfo, System::PacketBuff void UDPEndPoint::Close() { - if (mState != kState_Closed) + if (mState != State::kClosed) { CloseImpl(); - mState = kState_Closed; + mState = State::kClosed; } } diff --git a/src/inet/tests/TestInetAddress.cpp b/src/inet/tests/TestInetAddress.cpp index bb8fb6c9617deb..6465593a21cb7e 100644 --- a/src/inet/tests/TestInetAddress.cpp +++ b/src/inet/tests/TestInetAddress.cpp @@ -174,43 +174,43 @@ const IPV6MulticastGroup sIPv6WellKnownMulticastGroups[NUM_MCAST_GROUPS] = { const struct IPAddressExpandedContext sIPAddressContext[] = { { - { { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, kIPAddressType_Any, + { { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, IPAddressType::kAny, "::" }, kTestIsIPv6, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x26200001, 0x10e70400, 0xe83fb28f, 0x9c3a1941 }, kIPAddressType_IPv6, + { { 0x26200001, 0x10e70400, 0xe83fb28f, 0x9c3a1941 }, IPAddressType::kIPv6, "2620:1:10e7:400:e83f:b28f:9c3a:1941" } , kTestIsIPv6, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0xfe800000, 0x00000000, 0x8edcd4ff, 0xfe3aebfb }, kIPAddressType_IPv6, + { { 0xfe800000, 0x00000000, 0x8edcd4ff, 0xfe3aebfb }, IPAddressType::kIPv6, "fe80::8edc:d4ff:fe3a:ebfb" }, kTestIsIPv6, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0xff010000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, + { { 0xff010000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff01::1" }, kTestIsIPv6, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0xfd000000, 0x00010001, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, + { { 0xfd000000, 0x00010001, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "fd00:0:1:1::1" }, kTestIsIPv6, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsIPv6ULA, kTestIsNotIPv6LLA, 0x1, 1, 1 }, { - { { 0xfd123456, 0x0001abcd, 0xabcdef00, 0xfedcba09 }, kIPAddressType_IPv6, + { { 0xfd123456, 0x0001abcd, 0xabcdef00, 0xfedcba09 }, IPAddressType::kIPv6, "fd12:3456:1:abcd:abcd:ef00:fedc:ba09" }, kTestIsIPv6, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsIPv6ULA, kTestIsNotIPv6LLA, 0x1234560001, 0xabcd, 0xabcdef00fedcba09 }, { - { { 0xfdffffff, 0xffffffff, 0xffffffff, 0xffffffff }, kIPAddressType_IPv6, + { { 0xfdffffff, 0xffffffff, 0xffffffff, 0xffffffff }, IPAddressType::kIPv6, "fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" }, kTestIsIPv6, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsIPv6ULA, kTestIsNotIPv6LLA, 0xffffffffff, 0xffff, 0xffffffffffffffff @@ -218,13 +218,13 @@ const struct IPAddressExpandedContext sIPAddressContext[] = #if INET_CONFIG_ENABLE_IPV4 // IPv4-only { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xffffff00 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xffffff00 }, IPAddressType::kIPv4, "255.255.255.0" }, kTestIsIPv4, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0x7f000001 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0x7f000001 }, IPAddressType::kIPv4, "127.0.0.1" }, kTestIsIPv4, kTestIsNotIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 @@ -233,286 +233,286 @@ const struct IPAddressExpandedContext sIPAddressContext[] = // IPv4 Local subnetwork multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000000 }, IPAddressType::kIPv4, "224.0.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000001 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000001 }, IPAddressType::kIPv4, "224.0.0.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000080 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000080 }, IPAddressType::kIPv4, "224.0.0.128" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe00000fe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe00000fe }, IPAddressType::kIPv4, "224.0.0.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe00000ff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe00000ff }, IPAddressType::kIPv4, "224.0.0.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IPv4 Internetwork control multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000100 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000100 }, IPAddressType::kIPv4, "224.0.1.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000101 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000101 }, IPAddressType::kIPv4, "224.0.1.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000180 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000180 }, IPAddressType::kIPv4, "224.0.1.128" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe00001fe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe00001fe }, IPAddressType::kIPv4, "224.0.1.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe00001ff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe00001ff }, IPAddressType::kIPv4, "224.0.1.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IPv4 AD-HOC block 1 multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000200 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000200 }, IPAddressType::kIPv4, "224.0.2.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000201 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0000201 }, IPAddressType::kIPv4, "224.0.2.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0008100 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0008100 }, IPAddressType::kIPv4, "224.0.129.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe000fffe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe000fffe }, IPAddressType::kIPv4, "224.0.255.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe000ffff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe000ffff }, IPAddressType::kIPv4, "224.0.255.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IPv4 AD-HOC block 2 multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0030000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0030000 }, IPAddressType::kIPv4, "224.3.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0030001 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0030001 }, IPAddressType::kIPv4, "224.3.0.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0040000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe0040000 }, IPAddressType::kIPv4, "224.4.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe004fffe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe004fffe }, IPAddressType::kIPv4, "224.4.255.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe004ffff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe004ffff }, IPAddressType::kIPv4, "224.4.255.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IPv4 source-specific multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8000000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8000000 }, IPAddressType::kIPv4, "232.0.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8000001 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8000001 }, IPAddressType::kIPv4, "232.0.0.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8800000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8800000 }, IPAddressType::kIPv4, "232.128.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8fffffe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8fffffe }, IPAddressType::kIPv4, "232.255.255.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8ffffff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe8ffffff }, IPAddressType::kIPv4, "232.255.255.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IPv4 GLOP addressing multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9000000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9000000 }, IPAddressType::kIPv4, "233.0.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9000001 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9000001 }, IPAddressType::kIPv4, "233.0.0.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe97e0000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe97e0000 }, IPAddressType::kIPv4, "233.126.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fbfffe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fbfffe }, IPAddressType::kIPv4, "233.251.255.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fbffff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fbffff }, IPAddressType::kIPv4, "233.251.255.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IPv4 AD-HOC block 3 multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fc0000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fc0000 }, IPAddressType::kIPv4, "233.252.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fc0001 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fc0001 }, IPAddressType::kIPv4, "233.252.0.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fe0000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fe0000 }, IPAddressType::kIPv4, "233.254.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fffffe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9fffffe }, IPAddressType::kIPv4, "233.255.255.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9ffffff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xe9ffffff }, IPAddressType::kIPv4, "233.255.255.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IPv4 unicast-prefix-based multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xea000000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xea000000 }, IPAddressType::kIPv4, "234.0.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xea000001 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xea000001 }, IPAddressType::kIPv4, "234.0.0.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xea800000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xea800000 }, IPAddressType::kIPv4, "234.128.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xeafffffe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xeafffffe }, IPAddressType::kIPv4, "234.255.255.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xeaffffff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xeaffffff }, IPAddressType::kIPv4, "234.255.255.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IPv4 administratively scoped multicast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xef000000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xef000000 }, IPAddressType::kIPv4, "239.0.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xef000001 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xef000001 }, IPAddressType::kIPv4, "239.0.0.1" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xef800000 }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xef800000 }, IPAddressType::kIPv4, "239.128.0.0" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xeffffffe }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xeffffffe }, IPAddressType::kIPv4, "239.255.255.254" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xefffffff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xefffffff }, IPAddressType::kIPv4, "239.255.255.255" }, kTestIsIPv4, kTestIsIPv4Multicast, kTestIsNotIPv4Broadcast, kTestIsMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 }, // IP4 and IPv4 broadcast { - { { 0x00000000, 0x00000000, 0x0000ffff, 0xffffffff }, kIPAddressType_IPv4, + { { 0x00000000, 0x00000000, 0x0000ffff, 0xffffffff }, IPAddressType::kIPv4, "255.255.255.255" }, kTestIsIPv4, kTestIsNotIPv4Multicast, kTestIsIPv4Broadcast, kTestIsNotMulticast, kTestIsNotIPv6Multicast, kTestIsNotIPv6ULA, kTestIsNotIPv6LLA, 0x0, 0x0, 0x0 @@ -526,23 +526,23 @@ const IPAddressContext sIPv6WellKnownMulticastContext[] = { // All-nodes in Various Scopes - { { 0xff010000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff01::1" }, - { { 0xff020000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff02::1" }, - { { 0xff030000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff03::1" }, - { { 0xff040000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff04::1" }, - { { 0xff050000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff05::1" }, - { { 0xff080000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff08::1" }, - { { 0xff0e0000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff0e::1" }, + { { 0xff010000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff01::1" }, + { { 0xff020000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff02::1" }, + { { 0xff030000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff03::1" }, + { { 0xff040000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff04::1" }, + { { 0xff050000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff05::1" }, + { { 0xff080000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff08::1" }, + { { 0xff0e0000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff0e::1" }, // All-routers in Various Scopes - { { 0xff010000, 0x00000000, 0x00000000, 0x00000002 }, kIPAddressType_IPv6, "ff01::2" }, - { { 0xff020000, 0x00000000, 0x00000000, 0x00000002 }, kIPAddressType_IPv6, "ff02::2" }, - { { 0xff030000, 0x00000000, 0x00000000, 0x00000002 }, kIPAddressType_IPv6, "ff03::2" }, - { { 0xff040000, 0x00000000, 0x00000000, 0x00000002 }, kIPAddressType_IPv6, "ff04::2" }, - { { 0xff050000, 0x00000000, 0x00000000, 0x00000002 }, kIPAddressType_IPv6, "ff05::2" }, - { { 0xff080000, 0x00000000, 0x00000000, 0x00000002 }, kIPAddressType_IPv6, "ff08::2" }, - { { 0xff0e0000, 0x00000000, 0x00000000, 0x00000002 }, kIPAddressType_IPv6, "ff0e::2" } + { { 0xff010000, 0x00000000, 0x00000000, 0x00000002 }, IPAddressType::kIPv6, "ff01::2" }, + { { 0xff020000, 0x00000000, 0x00000000, 0x00000002 }, IPAddressType::kIPv6, "ff02::2" }, + { { 0xff030000, 0x00000000, 0x00000000, 0x00000002 }, IPAddressType::kIPv6, "ff03::2" }, + { { 0xff040000, 0x00000000, 0x00000000, 0x00000002 }, IPAddressType::kIPv6, "ff04::2" }, + { { 0xff050000, 0x00000000, 0x00000000, 0x00000002 }, IPAddressType::kIPv6, "ff05::2" }, + { { 0xff080000, 0x00000000, 0x00000000, 0x00000002 }, IPAddressType::kIPv6, "ff08::2" }, + { { 0xff0e0000, 0x00000000, 0x00000000, 0x00000002 }, IPAddressType::kIPv6, "ff0e::2" } }; const IPAddressContext sIPv6TransientMulticastContext[] = { @@ -550,23 +550,23 @@ const IPAddressContext sIPv6TransientMulticastContext[] = { // Short Transient Group in Various Scopes - { { 0xff110000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff11::1" }, - { { 0xff120000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff12::1" }, - { { 0xff130000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff13::1" }, - { { 0xff140000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff14::1" }, - { { 0xff150000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff15::1" }, - { { 0xff180000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff18::1" }, - { { 0xff1e0000, 0x00000000, 0x00000000, 0x00000001 }, kIPAddressType_IPv6, "ff1e::1" }, + { { 0xff110000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff11::1" }, + { { 0xff120000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff12::1" }, + { { 0xff130000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff13::1" }, + { { 0xff140000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff14::1" }, + { { 0xff150000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff15::1" }, + { { 0xff180000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff18::1" }, + { { 0xff1e0000, 0x00000000, 0x00000000, 0x00000001 }, IPAddressType::kIPv6, "ff1e::1" }, // Long Transient Group in Various Scopes - { { 0xff11d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, kIPAddressType_IPv6, "ff11:d5d6:2ba2:7847:6452:587a:c955:b5a" }, - { { 0xff12d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, kIPAddressType_IPv6, "ff12:d5d6:2ba2:7847:6452:587a:c955:b5a" }, - { { 0xff13d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, kIPAddressType_IPv6, "ff13:d5d6:2ba2:7847:6452:587a:c955:b5a" }, - { { 0xff14d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, kIPAddressType_IPv6, "ff14:d5d6:2ba2:7847:6452:587a:c955:b5a" }, - { { 0xff15d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, kIPAddressType_IPv6, "ff15:d5d6:2ba2:7847:6452:587a:c955:b5a" }, - { { 0xff18d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, kIPAddressType_IPv6, "ff18:d5d6:2ba2:7847:6452:587a:c955:b5a" }, - { { 0xff1ed5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, kIPAddressType_IPv6, "ff1e:d5d6:2ba2:7847:6452:587a:c955:b5a" } + { { 0xff11d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, IPAddressType::kIPv6, "ff11:d5d6:2ba2:7847:6452:587a:c955:b5a" }, + { { 0xff12d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, IPAddressType::kIPv6, "ff12:d5d6:2ba2:7847:6452:587a:c955:b5a" }, + { { 0xff13d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, IPAddressType::kIPv6, "ff13:d5d6:2ba2:7847:6452:587a:c955:b5a" }, + { { 0xff14d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, IPAddressType::kIPv6, "ff14:d5d6:2ba2:7847:6452:587a:c955:b5a" }, + { { 0xff15d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, IPAddressType::kIPv6, "ff15:d5d6:2ba2:7847:6452:587a:c955:b5a" }, + { { 0xff18d5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, IPAddressType::kIPv6, "ff18:d5d6:2ba2:7847:6452:587a:c955:b5a" }, + { { 0xff1ed5d6, 0x2ba27847, 0x6452587a, 0xc9550b5a }, IPAddressType::kIPv6, "ff1e:d5d6:2ba2:7847:6452:587a:c955:b5a" } }; const IPAddressContext sIPv6PrefixMulticastContext[] = { @@ -574,43 +574,43 @@ const IPAddressContext sIPv6PrefixMulticastContext[] = { // 56-bit Prefix with Short Group in Various Scopes - { { 0xff310038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, kIPAddressType_IPv6, "ff31:38:373a:cba4:d2ad:8d00:1:1" }, - { { 0xff320038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, kIPAddressType_IPv6, "ff32:38:373a:cba4:d2ad:8d00:1:1" }, - { { 0xff330038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, kIPAddressType_IPv6, "ff33:38:373a:cba4:d2ad:8d00:1:1" }, - { { 0xff340038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, kIPAddressType_IPv6, "ff34:38:373a:cba4:d2ad:8d00:1:1" }, - { { 0xff350038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, kIPAddressType_IPv6, "ff35:38:373a:cba4:d2ad:8d00:1:1" }, - { { 0xff380038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, kIPAddressType_IPv6, "ff38:38:373a:cba4:d2ad:8d00:1:1" }, - { { 0xff3e0038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, kIPAddressType_IPv6, "ff3e:38:373a:cba4:d2ad:8d00:1:1" }, + { { 0xff310038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, IPAddressType::kIPv6, "ff31:38:373a:cba4:d2ad:8d00:1:1" }, + { { 0xff320038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, IPAddressType::kIPv6, "ff32:38:373a:cba4:d2ad:8d00:1:1" }, + { { 0xff330038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, IPAddressType::kIPv6, "ff33:38:373a:cba4:d2ad:8d00:1:1" }, + { { 0xff340038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, IPAddressType::kIPv6, "ff34:38:373a:cba4:d2ad:8d00:1:1" }, + { { 0xff350038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, IPAddressType::kIPv6, "ff35:38:373a:cba4:d2ad:8d00:1:1" }, + { { 0xff380038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, IPAddressType::kIPv6, "ff38:38:373a:cba4:d2ad:8d00:1:1" }, + { { 0xff3e0038, 0x373acba4, 0xd2ad8d00, 0x00010001 }, IPAddressType::kIPv6, "ff3e:38:373a:cba4:d2ad:8d00:1:1" }, // 56-bit Prefix with Long Group in Various Scopes - { { 0xff310038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, kIPAddressType_IPv6, "ff31:38:373a:cba4:d2ad:8d00:afff:5258" }, - { { 0xff320038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, kIPAddressType_IPv6, "ff32:38:373a:cba4:d2ad:8d00:afff:5258" }, - { { 0xff330038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, kIPAddressType_IPv6, "ff33:38:373a:cba4:d2ad:8d00:afff:5258" }, - { { 0xff340038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, kIPAddressType_IPv6, "ff34:38:373a:cba4:d2ad:8d00:afff:5258" }, - { { 0xff350038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, kIPAddressType_IPv6, "ff35:38:373a:cba4:d2ad:8d00:afff:5258" }, - { { 0xff380038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, kIPAddressType_IPv6, "ff38:38:373a:cba4:d2ad:8d00:afff:5258" }, - { { 0xff3e0038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, kIPAddressType_IPv6, "ff3e:38:373a:cba4:d2ad:8d00:afff:5258" }, + { { 0xff310038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, IPAddressType::kIPv6, "ff31:38:373a:cba4:d2ad:8d00:afff:5258" }, + { { 0xff320038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, IPAddressType::kIPv6, "ff32:38:373a:cba4:d2ad:8d00:afff:5258" }, + { { 0xff330038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, IPAddressType::kIPv6, "ff33:38:373a:cba4:d2ad:8d00:afff:5258" }, + { { 0xff340038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, IPAddressType::kIPv6, "ff34:38:373a:cba4:d2ad:8d00:afff:5258" }, + { { 0xff350038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, IPAddressType::kIPv6, "ff35:38:373a:cba4:d2ad:8d00:afff:5258" }, + { { 0xff380038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, IPAddressType::kIPv6, "ff38:38:373a:cba4:d2ad:8d00:afff:5258" }, + { { 0xff3e0038, 0x373acba4, 0xd2ad8d00, 0xafff5258 }, IPAddressType::kIPv6, "ff3e:38:373a:cba4:d2ad:8d00:afff:5258" }, // 64-bit Prefix with Short Group in Various Scopes - { { 0xff310040, 0x66643dfb, 0xafa4385b, 0x00010001 }, kIPAddressType_IPv6, "ff31:40:6664:3dfb:afa4:385b:1:1" }, - { { 0xff320040, 0x66643dfb, 0xafa4385b, 0x00010001 }, kIPAddressType_IPv6, "ff32:40:6664:3dfb:afa4:385b:1:1" }, - { { 0xff330040, 0x66643dfb, 0xafa4385b, 0x00010001 }, kIPAddressType_IPv6, "ff33:40:6664:3dfb:afa4:385b:1:1" }, - { { 0xff340040, 0x66643dfb, 0xafa4385b, 0x00010001 }, kIPAddressType_IPv6, "ff34:40:6664:3dfb:afa4:385b:1:1" }, - { { 0xff350040, 0x66643dfb, 0xafa4385b, 0x00010001 }, kIPAddressType_IPv6, "ff35:40:6664:3dfb:afa4:385b:1:1" }, - { { 0xff380040, 0x66643dfb, 0xafa4385b, 0x00010001 }, kIPAddressType_IPv6, "ff38:40:6664:3dfb:afa4:385b:1:1" }, - { { 0xff3e0040, 0x66643dfb, 0xafa4385b, 0x00010001 }, kIPAddressType_IPv6, "ff3e:40:6664:3dfb:afa4:385b:1:1" }, + { { 0xff310040, 0x66643dfb, 0xafa4385b, 0x00010001 }, IPAddressType::kIPv6, "ff31:40:6664:3dfb:afa4:385b:1:1" }, + { { 0xff320040, 0x66643dfb, 0xafa4385b, 0x00010001 }, IPAddressType::kIPv6, "ff32:40:6664:3dfb:afa4:385b:1:1" }, + { { 0xff330040, 0x66643dfb, 0xafa4385b, 0x00010001 }, IPAddressType::kIPv6, "ff33:40:6664:3dfb:afa4:385b:1:1" }, + { { 0xff340040, 0x66643dfb, 0xafa4385b, 0x00010001 }, IPAddressType::kIPv6, "ff34:40:6664:3dfb:afa4:385b:1:1" }, + { { 0xff350040, 0x66643dfb, 0xafa4385b, 0x00010001 }, IPAddressType::kIPv6, "ff35:40:6664:3dfb:afa4:385b:1:1" }, + { { 0xff380040, 0x66643dfb, 0xafa4385b, 0x00010001 }, IPAddressType::kIPv6, "ff38:40:6664:3dfb:afa4:385b:1:1" }, + { { 0xff3e0040, 0x66643dfb, 0xafa4385b, 0x00010001 }, IPAddressType::kIPv6, "ff3e:40:6664:3dfb:afa4:385b:1:1" }, // 64-bit Prefix with Long Group in Various Scopes - { { 0xff310040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, kIPAddressType_IPv6, "ff31:40:6664:3dfb:afa4:385b:afff:5258" }, - { { 0xff320040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, kIPAddressType_IPv6, "ff32:40:6664:3dfb:afa4:385b:afff:5258" }, - { { 0xff330040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, kIPAddressType_IPv6, "ff33:40:6664:3dfb:afa4:385b:afff:5258" }, - { { 0xff340040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, kIPAddressType_IPv6, "ff34:40:6664:3dfb:afa4:385b:afff:5258" }, - { { 0xff350040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, kIPAddressType_IPv6, "ff35:40:6664:3dfb:afa4:385b:afff:5258" }, - { { 0xff380040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, kIPAddressType_IPv6, "ff38:40:6664:3dfb:afa4:385b:afff:5258" }, - { { 0xff3e0040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, kIPAddressType_IPv6, "ff3e:40:6664:3dfb:afa4:385b:afff:5258" } + { { 0xff310040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, IPAddressType::kIPv6, "ff31:40:6664:3dfb:afa4:385b:afff:5258" }, + { { 0xff320040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, IPAddressType::kIPv6, "ff32:40:6664:3dfb:afa4:385b:afff:5258" }, + { { 0xff330040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, IPAddressType::kIPv6, "ff33:40:6664:3dfb:afa4:385b:afff:5258" }, + { { 0xff340040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, IPAddressType::kIPv6, "ff34:40:6664:3dfb:afa4:385b:afff:5258" }, + { { 0xff350040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, IPAddressType::kIPv6, "ff35:40:6664:3dfb:afa4:385b:afff:5258" }, + { { 0xff380040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, IPAddressType::kIPv6, "ff38:40:6664:3dfb:afa4:385b:afff:5258" }, + { { 0xff3e0040, 0x66643dfb, 0xafa4385b, 0xafff5258 }, IPAddressType::kIPv6, "ff3e:40:6664:3dfb:afa4:385b:afff:5258" } }; const size_t kIPv6WellKnownMulticastTestElements = sizeof(sIPv6WellKnownMulticastContext) / sizeof(struct IPAddressContext); @@ -1228,7 +1228,7 @@ void CheckFromSocket(nlTestSuite * inSuite, void * inContext) switch (lCurrent->mAddr.mAddrType) { #if INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv4: + case IPAddressType::kIPv4: memset(&sock_v4, 0, sizeof(struct sockaddr_in)); sock_v4.sin_family = AF_INET; memcpy(&sock_v4.sin_addr.s_addr, &addr[3], sizeof(struct in_addr)); @@ -1236,14 +1236,14 @@ void CheckFromSocket(nlTestSuite * inSuite, void * inContext) break; #endif // INET_CONFIG_ENABLE_IPV4 - case kIPAddressType_IPv6: + case IPAddressType::kIPv6: memset(&sock_v6, 0, sizeof(struct sockaddr_in6)); sock_v6.sin6_family = AF_INET6; memcpy(&sock_v6.sin6_addr.s6_addr, addr, sizeof(struct in6_addr)); test_addr_2 = IPAddress::FromSockAddr(reinterpret_cast(sock_v6)); break; - case kIPAddressType_Any: + case IPAddressType::kAny: memset(&sock_v6, 0, sizeof(struct sockaddr_in6)); sock_v6.sin6_family = 0; memcpy(&sock_v6.sin6_addr.s6_addr, addr, sizeof(struct in6_addr)); @@ -1290,7 +1290,7 @@ void CheckAnyAddress(nlTestSuite * inSuite, void * inContext) const IPAddress test_addr = IPAddress::Any; IPAddressType test_type = test_addr.Type(); - NL_TEST_ASSERT(inSuite, test_type == kIPAddressType_Any); + NL_TEST_ASSERT(inSuite, test_type == IPAddressType::kAny); } /** @@ -1557,7 +1557,7 @@ void CheckMakeIPv6TransientMulticast(nlTestSuite * inSuite, void * inContext) const struct TestContext * lContext = static_cast(inContext); IPAddressContextIterator lCurrent = lContext->mIPv6TransientMulticastContextRange.mBegin; IPAddressContextIterator lEnd = lContext->mIPv6TransientMulticastContextRange.mEnd; - const uint8_t lFlags = 0; + constexpr IPv6MulticastFlags lFlags; size_t lScopeIndex; IPAddress lAddress; diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp index 91d74d67276b0f..3843d076d0343d 100644 --- a/src/inet/tests/TestInetEndPoint.cpp +++ b/src/inet/tests/TestInetEndPoint.cpp @@ -240,32 +240,32 @@ static void TestInetEndPointInternal(nlTestSuite * inSuite, void * inContext) // UdpEndPoint special cases to cover the error branch err = testUDPEP->Listen(nullptr /*OnMessageReceived*/, nullptr /*OnReceiveError*/); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); - err = testUDPEP->Bind(kIPAddressType_Unknown, addr_any, 3000); + err = testUDPEP->Bind(IPAddressType::kUnknown, addr_any, 3000); NL_TEST_ASSERT(inSuite, err == INET_ERROR_WRONG_ADDRESS_TYPE); - err = testUDPEP->Bind(kIPAddressType_Unknown, addr, 3000); + err = testUDPEP->Bind(IPAddressType::kUnknown, addr, 3000); NL_TEST_ASSERT(inSuite, err == INET_ERROR_WRONG_ADDRESS_TYPE); #if INET_CONFIG_ENABLE_IPV4 - err = testUDPEP->Bind(kIPAddressType_IPv4, addr, 3000); + err = testUDPEP->Bind(IPAddressType::kIPv4, addr, 3000); NL_TEST_ASSERT(inSuite, err == INET_ERROR_WRONG_ADDRESS_TYPE); #endif // INET_CONFIG_ENABLE_IPV4 - err = testUDPEP->Bind(kIPAddressType_IPv6, addr, 3000, intId); - err = testUDPEP->BindInterface(kIPAddressType_IPv6, intId); + err = testUDPEP->Bind(IPAddressType::kIPv6, addr, 3000, intId); + err = testUDPEP->BindInterface(IPAddressType::kIPv6, intId); InterfaceId id = testUDPEP->GetBoundInterface(); NL_TEST_ASSERT(inSuite, id == intId); err = testUDPEP->Listen(nullptr /*OnMessageReceived*/, nullptr /*OnReceiveError*/); err = testUDPEP->Listen(nullptr /*OnMessageReceived*/, nullptr /*OnReceiveError*/); - err = testUDPEP->Bind(kIPAddressType_IPv6, addr, 3000, intId); + err = testUDPEP->Bind(IPAddressType::kIPv6, addr, 3000, intId); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); - err = testUDPEP->BindInterface(kIPAddressType_IPv6, intId); + err = testUDPEP->BindInterface(IPAddressType::kIPv6, intId); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); testUDPEP->Free(); err = gInet.NewUDPEndPoint(&testUDPEP); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); #if INET_CONFIG_ENABLE_IPV4 - err = testUDPEP->Bind(kIPAddressType_IPv4, addr_v4, 3000, intId); + err = testUDPEP->Bind(IPAddressType::kIPv4, addr_v4, 3000, intId); NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR); buf = PacketBufferHandle::New(PacketBuffer::kMaxSize); err = testUDPEP->SendTo(addr_v4, 3000, std::move(buf)); @@ -290,17 +290,17 @@ static void TestInetEndPointInternal(nlTestSuite * inSuite, void * inContext) err = testTCPEP1->GetLocalInfo(nullptr, nullptr); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); - err = testTCPEP1->Bind(kIPAddressType_Unknown, addr_any, 3000, true); + err = testTCPEP1->Bind(IPAddressType::kUnknown, addr_any, 3000, true); NL_TEST_ASSERT(inSuite, err == INET_ERROR_WRONG_ADDRESS_TYPE); #if INET_CONFIG_ENABLE_IPV4 - err = testTCPEP1->Bind(kIPAddressType_IPv4, addr, 3000, true); + err = testTCPEP1->Bind(IPAddressType::kIPv4, addr, 3000, true); NL_TEST_ASSERT(inSuite, err == INET_ERROR_WRONG_ADDRESS_TYPE); #endif // INET_CONFIG_ENABLE_IPV4 - err = testTCPEP1->Bind(kIPAddressType_Unknown, addr, 3000, true); + err = testTCPEP1->Bind(IPAddressType::kUnknown, addr, 3000, true); NL_TEST_ASSERT(inSuite, err == INET_ERROR_WRONG_ADDRESS_TYPE); - err = testTCPEP1->Bind(kIPAddressType_IPv6, addr_any, 3000, true); - err = testTCPEP1->Bind(kIPAddressType_IPv6, addr_any, 3000, true); + err = testTCPEP1->Bind(IPAddressType::kIPv6, addr_any, 3000, true); + err = testTCPEP1->Bind(IPAddressType::kIPv6, addr_any, 3000, true); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); err = testTCPEP1->Listen(4); #if INET_CONFIG_ENABLE_IPV4 diff --git a/src/inet/tests/TestInetLayer.cpp b/src/inet/tests/TestInetLayer.cpp index 71b5d7ddd0b57a..cbda0f0ac7e784 100644 --- a/src/inet/tests/TestInetLayer.cpp +++ b/src/inet/tests/TestInetLayer.cpp @@ -570,7 +570,7 @@ static CHIP_ERROR HandleTCPDataReceived(TCPEndPoint * aEndPoint, PacketBufferHan VerifyOrExit(aEndPoint != nullptr, lStatus = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(!aBuffer.IsNull(), lStatus = CHIP_ERROR_INVALID_ARGUMENT); - if (aEndPoint->State != TCPEndPoint::kState_Connected) + if (aEndPoint->mState != TCPEndPoint::State::kConnected) { lStatus = aEndPoint->SetReceivedDataForTesting(std::move(aBuffer)); INET_FAIL_ERROR(lStatus, "TCPEndPoint::PutBackReceivedData failed"); @@ -666,10 +666,10 @@ static bool IsTransportReadyForSend() { if (sTCPIPEndPoint->PendingSendLength() == 0) { - switch (sTCPIPEndPoint->State) + switch (sTCPIPEndPoint->mState) { - case TCPEndPoint::kState_Connected: - case TCPEndPoint::kState_ReceiveShutdown: + case TCPEndPoint::State::kConnected: + case TCPEndPoint::State::kReceiveShutdown: lStatus = true; break; @@ -789,7 +789,7 @@ void DriveSend() static void StartTest() { - IPAddressType lIPAddressType = kIPAddressType_IPv6; + IPAddressType lIPAddressType = IPAddressType::kIPv6; IPAddress lAddress = chip::Inet::IPAddress::Any; CHIP_ERROR lStatus; @@ -799,7 +799,7 @@ static void StartTest() #if INET_CONFIG_ENABLE_IPV4 if (gOptFlags & kOptFlagUseIPv4) { - lIPAddressType = kIPAddressType_IPv4; + lIPAddressType = IPAddressType::kIPv4; if (!gNetworkOptions.LocalIPv6Addr.empty()) lAddress = gNetworkOptions.LocalIPv4Addr[0]; else diff --git a/src/inet/tests/TestInetLayerMulticast.cpp b/src/inet/tests/TestInetLayerMulticast.cpp index 20c6d8f6cf1f71..af9be78791fbbe 100644 --- a/src/inet/tests/TestInetLayerMulticast.cpp +++ b/src/inet/tests/TestInetLayerMulticast.cpp @@ -489,9 +489,7 @@ static IPAddress MakeIPv4Multicast(uint32_t aGroupIdentifier) static IPAddress MakeIPv6Multicast(uint32_t aGroupIdentifier) { - const uint8_t lFlags = kIPv6MulticastFlag_Transient; - - return (IPAddress::MakeIPv6Multicast(lFlags, kIPv6MulticastScope_Site, aGroupIdentifier)); + return (IPAddress::MakeIPv6Multicast(IPv6MulticastFlag::kTransient, kIPv6MulticastScope_Site, aGroupIdentifier)); } static void SetGroup(GroupAddress & aGroupAddress, uint32_t aGroupIdentifier, uint32_t aExpectedRx, uint32_t aExpectedTx) @@ -718,7 +716,7 @@ void DriveSend() static void StartTest() { - IPAddressType lIPAddressType = kIPAddressType_IPv6; + IPAddressType lIPAddressType = IPAddressType::kIPv6; IPVersion lIPVersion = kIPVersion_6; IPAddress lAddress = IPAddress::Any; IPEndPointBasis * lEndPoint = nullptr; @@ -728,7 +726,7 @@ static void StartTest() #if INET_CONFIG_ENABLE_IPV4 if (gOptFlags & kOptFlagUseIPv4) { - lIPAddressType = kIPAddressType_IPv4; + lIPAddressType = IPAddressType::kIPv4; lIPVersion = kIPVersion_4; } #endif // INET_CONFIG_ENABLE_IPV4 diff --git a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp index 6cc4659aeaf4c0..a891b376451c8a 100644 --- a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp @@ -246,7 +246,7 @@ class AdvertiserMinMdns : public ServiceAdvertiser, void AdvertiserMinMdns::OnMdnsPacketData(const BytesRange & data, const chip::Inet::IPPacketInfo * info) { #ifdef DETAIL_LOGGING - char srcAddressString[chip::Inet::kMaxIPAddressStringLength]; + char srcAddressString[chip::Inet::IPAddress::kMaxStringLength]; VerifyOrDie(info->SrcAddress.ToString(srcAddressString) != nullptr); ChipLogDetail(Discovery, "Received an mDNS query from %s", srcAddressString); #endif diff --git a/src/lib/dnssd/AllInterfacesListenIterator.h b/src/lib/dnssd/AllInterfacesListenIterator.h index 66658ec9b22f82..f16a4efe74c2d5 100644 --- a/src/lib/dnssd/AllInterfacesListenIterator.h +++ b/src/lib/dnssd/AllInterfacesListenIterator.h @@ -73,14 +73,14 @@ class AllInterfaces : public mdns::Minimal::ListenIterator if (mState == State::kIpV4) { *id = mIterator.GetInterfaceId(); - *type = chip::Inet::kIPAddressType_IPv4; + *type = chip::Inet::IPAddressType::kIPv4; mState = State::kIpV6; return true; } #endif *id = mIterator.GetInterfaceId(); - *type = chip::Inet::kIPAddressType_IPv6; + *type = chip::Inet::IPAddressType::kIPv6; #if INET_CONFIG_ENABLE_IPV4 mState = State::kIpV4; #endif diff --git a/src/lib/dnssd/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index da7590c3a7cc19..8280575aa49cf2 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -348,7 +348,7 @@ CHIP_ERROR DiscoveryImplPlatform::Advertise(const CommissionAdvertisingParameter service.mInterface = INET_NULL_INTERFACEID; service.mSubTypes = subTypes; service.mSubTypeSize = subTypeSize; - service.mAddressType = Inet::kIPAddressType_Any; + service.mAddressType = Inet::IPAddressType::kAny; error = ChipDnssdPublishService(&service); if (error == CHIP_NO_ERROR) @@ -428,7 +428,7 @@ CHIP_ERROR DiscoveryImplPlatform::Advertise(const OperationalAdvertisingParamete service.mTextEntries = txtEntries; service.mTextEntrySize = textEntrySize; service.mInterface = INET_NULL_INTERFACEID; - service.mAddressType = Inet::kIPAddressType_Any; + service.mAddressType = Inet::IPAddressType::kAny; service.mSubTypes = subTypes; service.mSubTypeSize = subTypeSize; error = ChipDnssdPublishService(&service); @@ -542,7 +542,7 @@ CHIP_ERROR DiscoveryImplPlatform::FindCommissionableNodes(DiscoveryFilter filter char serviceName[kMaxCommisisonableServiceNameSize]; ReturnErrorOnFailure(MakeServiceTypeName(serviceName, sizeof(serviceName), filter, DiscoveryType::kCommissionableNode)); - return ChipDnssdBrowse(serviceName, DnssdServiceProtocol::kDnssdProtocolUdp, Inet::kIPAddressType_Any, INET_NULL_INTERFACEID, + return ChipDnssdBrowse(serviceName, DnssdServiceProtocol::kDnssdProtocolUdp, Inet::IPAddressType::kAny, INET_NULL_INTERFACEID, HandleNodeBrowse, this); } @@ -552,7 +552,7 @@ CHIP_ERROR DiscoveryImplPlatform::FindCommissioners(DiscoveryFilter filter) char serviceName[kMaxCommisisonerServiceNameSize]; ReturnErrorOnFailure(MakeServiceTypeName(serviceName, sizeof(serviceName), filter, DiscoveryType::kCommissionerNode)); - return ChipDnssdBrowse(serviceName, DnssdServiceProtocol::kDnssdProtocolUdp, Inet::kIPAddressType_Any, INET_NULL_INTERFACEID, + return ChipDnssdBrowse(serviceName, DnssdServiceProtocol::kDnssdProtocolUdp, Inet::IPAddressType::kAny, INET_NULL_INTERFACEID, HandleNodeBrowse, this); } diff --git a/src/lib/dnssd/MinimalMdnsServer.cpp b/src/lib/dnssd/MinimalMdnsServer.cpp index a9ae92f8476045..45d5ce1f7519a7 100644 --- a/src/lib/dnssd/MinimalMdnsServer.cpp +++ b/src/lib/dnssd/MinimalMdnsServer.cpp @@ -39,14 +39,14 @@ class AllInterfaces : public ListenIterator if (mState == State::kIpV4) { *id = mIterator.GetInterfaceId(); - *type = chip::Inet::kIPAddressType_IPv4; + *type = chip::Inet::IPAddressType::kIPv4; mState = State::kIpV6; return true; } #endif *id = mIterator.GetInterfaceId(); - *type = chip::Inet::kIPAddressType_IPv6; + *type = chip::Inet::IPAddressType::kIPv6; #if INET_CONFIG_ENABLE_IPV4 mState = State::kIpV4; #endif diff --git a/src/lib/dnssd/Resolver.h b/src/lib/dnssd/Resolver.h index 7d6da9e10a26ea..ffa2f5a00f8ee6 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -40,7 +40,7 @@ struct ResolvedNodeData void LogNodeIdResolved() { #if CHIP_PROGRESS_LOGGING - char addrBuffer[Inet::kMaxIPAddressStringLength + 1]; + char addrBuffer[Inet::IPAddress::kMaxStringLength + 1]; mAddress.ToString(addrBuffer); // Would be nice to log the interface id, but sorting out how to do so // across our differnet InterfaceId implementations is a pain. @@ -183,7 +183,7 @@ struct DiscoveredNodeData for (int j = 0; j < numIPs; j++) { #if CHIP_DETAIL_LOGGING - char buf[Inet::kMaxIPAddressStringLength]; + char buf[Inet::IPAddress::kMaxStringLength]; char * ipAddressOut = ipAddress[j].ToString(buf); ChipLogDetail(Discovery, "\tIP Address #%d: %s", j + 1, ipAddressOut); (void) ipAddressOut; diff --git a/src/lib/dnssd/minimal_mdns/ResponseSender.cpp b/src/lib/dnssd/minimal_mdns/ResponseSender.cpp index 89c1db82d089fb..41d80a89ad4a7f 100644 --- a/src/lib/dnssd/minimal_mdns/ResponseSender.cpp +++ b/src/lib/dnssd/minimal_mdns/ResponseSender.cpp @@ -161,7 +161,7 @@ CHIP_ERROR ResponseSender::FlushReply() if (mResponseBuilder.HasResponseRecords()) { - char srcAddressString[chip::Inet::kMaxIPAddressStringLength]; + char srcAddressString[chip::Inet::IPAddress::kMaxStringLength]; VerifyOrDie(mSendState.GetSourceAddress().ToString(srcAddressString) != nullptr); if (mSendState.SendUnicast()) diff --git a/src/lib/dnssd/minimal_mdns/Server.cpp b/src/lib/dnssd/minimal_mdns/Server.cpp index 049a9c88916f4b..7dc2ba09f0f3da 100644 --- a/src/lib/dnssd/minimal_mdns/Server.cpp +++ b/src/lib/dnssd/minimal_mdns/Server.cpp @@ -80,12 +80,12 @@ CHIP_ERROR JoinMulticastGroup(chip::Inet::InterfaceId interfaceId, chip::Inet::U chip::Inet::IPAddress address; - if (addressType == chip::Inet::IPAddressType::kIPAddressType_IPv6) + if (addressType == chip::Inet::IPAddressType::kIPv6) { BroadcastIpAddresses::GetIpv6Into(address); #if INET_CONFIG_ENABLE_IPV4 } - else if (addressType == chip::Inet::IPAddressType::kIPAddressType_IPv4) + else if (addressType == chip::Inet::IPAddressType::kIPv4) { BroadcastIpAddresses::GetIpv4Into(address); #endif // INET_CONFIG_ENABLE_IPV4 @@ -102,10 +102,10 @@ const char * AddressTypeStr(chip::Inet::IPAddressType addressType) { switch (addressType) { - case chip::Inet::IPAddressType::kIPAddressType_IPv6: + case chip::Inet::IPAddressType::kIPv6: return "IPv6"; #if INET_CONFIG_ENABLE_IPV4 - case chip::Inet::IPAddressType::kIPAddressType_IPv4: + case chip::Inet::IPAddressType::kIPv4: return "IPv4"; #endif // INET_CONFIG_ENABLE_IPV4 default: @@ -239,7 +239,7 @@ CHIP_ERROR ServerBase::BroadcastSend(chip::System::PacketBufferHandle && data, u continue; } - if ((addressType != chip::Inet::kIPAddressType_Any) && (info->addressType != addressType)) + if ((addressType != chip::Inet::IPAddressType::kAny) && (info->addressType != addressType)) { continue; } @@ -251,12 +251,12 @@ CHIP_ERROR ServerBase::BroadcastSend(chip::System::PacketBufferHandle && data, u /// for sending via `CloneData` /// /// TODO: this wastes one copy of the data and that could be optimized away - if (info->addressType == chip::Inet::kIPAddressType_IPv6) + if (info->addressType == chip::Inet::IPAddressType::kIPv6) { err = info->udp->SendTo(mIpv6BroadcastAddress, port, data.CloneData(), info->udp->GetBoundInterface()); } #if INET_CONFIG_ENABLE_IPV4 - else if (info->addressType == chip::Inet::kIPAddressType_IPv4) + else if (info->addressType == chip::Inet::IPAddressType::kIPv4) { err = info->udp->SendTo(mIpv4BroadcastAddress, port, data.CloneData(), info->udp->GetBoundInterface()); } @@ -304,12 +304,12 @@ CHIP_ERROR ServerBase::BroadcastSend(chip::System::PacketBufferHandle && data, u /// for sending via `CloneData` /// /// TODO: this wastes one copy of the data and that could be optimized away - if (info->addressType == chip::Inet::kIPAddressType_IPv6) + if (info->addressType == chip::Inet::IPAddressType::kIPv6) { err = info->udp->SendTo(mIpv6BroadcastAddress, port, data.CloneData(), info->udp->GetBoundInterface()); } #if INET_CONFIG_ENABLE_IPV4 - else if (info->addressType == chip::Inet::kIPAddressType_IPv4) + else if (info->addressType == chip::Inet::IPAddressType::kIPv4) { err = info->udp->SendTo(mIpv4BroadcastAddress, port, data.CloneData(), info->udp->GetBoundInterface()); } diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index ccad6ebd02b2a5..0cc91037c95409 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -106,7 +106,7 @@ class DnsShellResolverDelegate : public Dnssd::ResolverDelegate } private: - char ipAddressBuf[Inet::kMaxIPAddressStringLength]; + char ipAddressBuf[Inet::IPAddress::kMaxStringLength]; }; DnsShellResolverDelegate sDnsShellResolverDelegate; @@ -121,7 +121,7 @@ CHIP_ERROR ResolveHandler(int argc, char ** argv) peerId.SetCompressedFabricId(strtoull(argv[0], NULL, 10)); peerId.SetNodeId(strtoull(argv[1], NULL, 10)); - return Dnssd::Resolver::Instance().ResolveNodeId(peerId, Inet::kIPAddressType_Any); + return Dnssd::Resolver::Instance().ResolveNodeId(peerId, Inet::IPAddressType::kAny); } bool ParseSubType(int argc, char ** argv, Dnssd::DiscoveryFilter & filter) diff --git a/src/messaging/tests/echo/echo_requester.cpp b/src/messaging/tests/echo/echo_requester.cpp index a7ebfb6dbfaa07..a71e3123bc9b76 100644 --- a/src/messaging/tests/echo/echo_requester.cpp +++ b/src/messaging/tests/echo/echo_requester.cpp @@ -228,7 +228,7 @@ int main(int argc, char * argv[]) if (gUseTCP) { err = gTCPManager.Init(chip::Transport::TcpListenParameters(&chip::DeviceLayer::InetLayer) - .SetAddressType(chip::Inet::kIPAddressType_IPv6) + .SetAddressType(chip::Inet::IPAddressType::kIPv6) .SetListenPort(ECHO_CLIENT_PORT)); SuccessOrExit(err); @@ -238,7 +238,7 @@ int main(int argc, char * argv[]) else { err = gUDPManager.Init(chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer) - .SetAddressType(chip::Inet::kIPAddressType_IPv6) + .SetAddressType(chip::Inet::IPAddressType::kIPv6) .SetListenPort(ECHO_CLIENT_PORT)); SuccessOrExit(err); diff --git a/src/messaging/tests/echo/echo_responder.cpp b/src/messaging/tests/echo/echo_responder.cpp index 8a9ade91791728..1e00a5b2acaf6e 100644 --- a/src/messaging/tests/echo/echo_responder.cpp +++ b/src/messaging/tests/echo/echo_responder.cpp @@ -85,9 +85,9 @@ int main(int argc, char * argv[]) { err = gTCPManager.Init(chip::Transport::TcpListenParameters(&chip::DeviceLayer::InetLayer) #if INET_CONFIG_ENABLE_IPV4 - .SetAddressType(chip::Inet::kIPAddressType_IPv4) + .SetAddressType(chip::Inet::IPAddressType::kIPv4) #else - .SetAddressType(chip::Inet::kIPAddressType_IPv6) + .SetAddressType(chip::Inet::IPAddressType::kIPv6) #endif ); SuccessOrExit(err); @@ -98,7 +98,7 @@ int main(int argc, char * argv[]) else { err = gUDPManager.Init( - chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::kIPAddressType_IPv6)); + chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::IPAddressType::kIPv6)); SuccessOrExit(err); err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager); diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index 7a849ea4a6f858..c9e1857f4ecb39 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -433,11 +433,11 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin DNSServiceProtocol protocol; #if INET_CONFIG_ENABLE_IPV4 - if (addressType == chip::Inet::kIPAddressType_IPv4) + if (addressType == chip::Inet::IPAddressType::kIPv4) { protocol = kDNSServiceProtocol_IPv4; } - else if (addressType == chip::Inet::kIPAddressType_IPv6) + else if (addressType == chip::Inet::IPAddressType::kIPv6) { protocol = kDNSServiceProtocol_IPv6; } diff --git a/src/platform/Linux/DnssdImpl.cpp b/src/platform/Linux/DnssdImpl.cpp index 9ef98c21ca3158..c415aeff491032 100644 --- a/src/platform/Linux/DnssdImpl.cpp +++ b/src/platform/Linux/DnssdImpl.cpp @@ -49,11 +49,11 @@ AvahiProtocol ToAvahiProtocol(chip::Inet::IPAddressType addressType) switch (addressType) { #if INET_CONFIG_ENABLE_IPV4 - case chip::Inet::IPAddressType::kIPAddressType_IPv4: + case chip::Inet::IPAddressType::kIPv4: protocol = AVAHI_PROTO_INET; break; #endif - case chip::Inet::IPAddressType::kIPAddressType_IPv6: + case chip::Inet::IPAddressType::kIPv6: protocol = AVAHI_PROTO_INET6; break; default: @@ -72,14 +72,14 @@ chip::Inet::IPAddressType ToAddressType(AvahiProtocol protocol) { #if INET_CONFIG_ENABLE_IPV4 case AVAHI_PROTO_INET: - type = chip::Inet::IPAddressType::kIPAddressType_IPv4; + type = chip::Inet::IPAddressType::kIPv4; break; #endif case AVAHI_PROTO_INET6: - type = chip::Inet::IPAddressType::kIPAddressType_IPv6; + type = chip::Inet::IPAddressType::kIPv6; break; default: - type = chip::Inet::IPAddressType::kIPAddressType_Unknown; + type = chip::Inet::IPAddressType::kUnknown; break; } diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index f2c668d5fbc255..ff0d80f83917d1 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -1919,7 +1919,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::FromOtDnsRespons } mdnsService.mPort = serviceInfo.mPort; mdnsService.mInterface = INET_NULL_INTERFACEID; - mdnsService.mAddressType = Inet::kIPAddressType_IPv6; + mdnsService.mAddressType = Inet::IPAddressType::kIPv6; mdnsService.mAddress = chip::Optional(ToIPAddress(serviceInfo.mHostAddress)); otDnsTxtEntryIterator iterator; diff --git a/src/platform/tests/TestDnssd.cpp b/src/platform/tests/TestDnssd.cpp index 95576cbcd658b5..fe08c6ce6255c2 100644 --- a/src/platform/tests/TestDnssd.cpp +++ b/src/platform/tests/TestDnssd.cpp @@ -60,7 +60,7 @@ static void InitCallback(void * context, CHIP_ERROR error) service.mPort = 80; strcpy(service.mName, "test"); strcpy(service.mType, "_mock"); - service.mAddressType = chip::Inet::kIPAddressType_Any; + service.mAddressType = chip::Inet::IPAddressType::kAny; service.mProtocol = DnssdServiceProtocol::kDnssdProtocolTcp; entry.mKey = key; entry.mData = reinterpret_cast(val); @@ -71,7 +71,7 @@ static void InitCallback(void * context, CHIP_ERROR error) service.mSubTypeSize = 0; NL_TEST_ASSERT(suite, ChipDnssdPublishService(&service) == CHIP_NO_ERROR); - ChipDnssdBrowse("_mock", DnssdServiceProtocol::kDnssdProtocolTcp, chip::Inet::kIPAddressType_Any, INET_NULL_INTERFACEID, + ChipDnssdBrowse("_mock", DnssdServiceProtocol::kDnssdProtocolTcp, chip::Inet::IPAddressType::kAny, INET_NULL_INTERFACEID, HandleBrowse, suite); } diff --git a/src/transport/raw/TCP.h b/src/transport/raw/TCP.h index 5f69a08b432ae3..c09a7f62772d57 100644 --- a/src/transport/raw/TCP.h +++ b/src/transport/raw/TCP.h @@ -74,10 +74,10 @@ class TcpListenParameters } private: - Inet::InetLayer * mLayer = nullptr; ///< Associated inet layer - Inet::IPAddressType mAddressType = Inet::kIPAddressType_IPv6; ///< type of listening socket - uint16_t mListenPort = CHIP_PORT; ///< TCP listen port - Inet::InterfaceId mInterfaceId = INET_NULL_INTERFACEID; ///< Interface to listen on + Inet::InetLayer * mLayer = nullptr; ///< Associated inet layer + Inet::IPAddressType mAddressType = Inet::IPAddressType::kIPv6; ///< type of listening socket + uint16_t mListenPort = CHIP_PORT; ///< TCP listen port + Inet::InterfaceId mInterfaceId = INET_NULL_INTERFACEID; ///< Interface to listen on }; /** @@ -255,9 +255,9 @@ class DLL_EXPORT TCPBase : public Base // @see TCPEndpoint::OnAcceptErrorFunct static void OnAcceptError(Inet::TCPEndPoint * endPoint, CHIP_ERROR err); - Inet::TCPEndPoint * mListenSocket = nullptr; ///< TCP socket used by the transport - Inet::IPAddressType mEndpointType = Inet::IPAddressType::kIPAddressType_Unknown; ///< Socket listening type - State mState = State::kNotReady; ///< State of the TCP transport + Inet::TCPEndPoint * mListenSocket = nullptr; ///< TCP socket used by the transport + Inet::IPAddressType mEndpointType = Inet::IPAddressType::kUnknown; ///< Socket listening type + State mState = State::kNotReady; ///< State of the TCP transport // Number of active and 'pending connection' endpoints size_t mUsedEndPointCount = 0; diff --git a/src/transport/raw/UDP.h b/src/transport/raw/UDP.h index d5628295720321..710300cb8bdc8e 100644 --- a/src/transport/raw/UDP.h +++ b/src/transport/raw/UDP.h @@ -71,10 +71,10 @@ class UdpListenParameters } private: - Inet::InetLayer * mLayer = nullptr; ///< Associated inet layer - Inet::IPAddressType mAddressType = Inet::kIPAddressType_IPv6; ///< type of listening socket - uint16_t mListenPort = CHIP_PORT; ///< UDP listen port - Inet::InterfaceId mInterfaceId = INET_NULL_INTERFACEID; ///< Interface to listen on + Inet::InetLayer * mLayer = nullptr; ///< Associated inet layer + Inet::IPAddressType mAddressType = Inet::IPAddressType::kIPv6; ///< type of listening socket + uint16_t mListenPort = CHIP_PORT; ///< UDP listen port + Inet::InterfaceId mInterfaceId = INET_NULL_INTERFACEID; ///< Interface to listen on }; /** Implements a transport using UDP. */ @@ -125,9 +125,9 @@ class DLL_EXPORT UDP : public Base static void OnUdpReceive(Inet::IPEndPointBasis * endPoint, System::PacketBufferHandle && buffer, const Inet::IPPacketInfo * pktInfo); - Inet::UDPEndPoint * mUDPEndPoint = nullptr; ///< UDP socket used by the transport - Inet::IPAddressType mUDPEndpointType = Inet::IPAddressType::kIPAddressType_Unknown; ///< Socket listening type - State mState = State::kNotReady; ///< State of the UDP transport + Inet::UDPEndPoint * mUDPEndPoint = nullptr; ///< UDP socket used by the transport + Inet::IPAddressType mUDPEndpointType = Inet::IPAddressType::kUnknown; ///< Socket listening type + State mState = State::kNotReady; ///< State of the UDP transport }; } // namespace Transport diff --git a/src/transport/raw/tests/TestTCP.cpp b/src/transport/raw/tests/TestTCP.cpp index 3b5e72cca3afec..b87cf48ec0b589 100644 --- a/src/transport/raw/tests/TestTCP.cpp +++ b/src/transport/raw/tests/TestTCP.cpp @@ -181,13 +181,13 @@ void CheckSimpleInitTest(nlTestSuite * inSuite, void * inContext, Inet::IPAddres #if INET_CONFIG_ENABLE_IPV4 void CheckSimpleInitTest4(nlTestSuite * inSuite, void * inContext) { - CheckSimpleInitTest(inSuite, inContext, kIPAddressType_IPv4); + CheckSimpleInitTest(inSuite, inContext, IPAddressType::kIPv4); } #endif void CheckSimpleInitTest6(nlTestSuite * inSuite, void * inContext) { - CheckSimpleInitTest(inSuite, inContext, kIPAddressType_IPv6); + CheckSimpleInitTest(inSuite, inContext, IPAddressType::kIPv6); } /////////////////////////// Messaging test diff --git a/src/transport/raw/tests/TestUDP.cpp b/src/transport/raw/tests/TestUDP.cpp index 1ad8b735086553..dd997a21f47457 100644 --- a/src/transport/raw/tests/TestUDP.cpp +++ b/src/transport/raw/tests/TestUDP.cpp @@ -98,13 +98,13 @@ void CheckSimpleInitTest(nlTestSuite * inSuite, void * inContext, Inet::IPAddres #if INET_CONFIG_ENABLE_IPV4 void CheckSimpleInitTest4(nlTestSuite * inSuite, void * inContext) { - CheckSimpleInitTest(inSuite, inContext, kIPAddressType_IPv4); + CheckSimpleInitTest(inSuite, inContext, IPAddressType::kIPv4); } #endif void CheckSimpleInitTest6(nlTestSuite * inSuite, void * inContext) { - CheckSimpleInitTest(inSuite, inContext, kIPAddressType_IPv6); + CheckSimpleInitTest(inSuite, inContext, IPAddressType::kIPv6); } /////////////////////////// Messaging test