/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include namespace AzNetworking { namespace Platform { void InitIpAddress(uint32_t& ipv4Address, uint16_t& port, const char* hostname, const char* service, ProtocolType type); } IpAddress::IpAddress(const char* hostname, const char* service, ProtocolType type) { Platform::InitIpAddress(m_ipv4Address, m_port, hostname, service, type); } IpAddress::IpAddress(const char* hostname, uint16_t port, ProtocolType type) : IpAddress(hostname, nullptr, type) { m_port = port; } IpAddress::IpAddress(uint8_t quadA, uint8_t quadB, uint8_t quadC, uint8_t quadD, uint16_t port) : m_ipv4Address((quadA << 24) | (quadB << 16) | (quadC << 8) | quadD) , m_port(port) { ; } IpAddress::IpAddress(ByteOrder byteOrder, uint32_t address, uint16_t port) : m_ipv4Address((byteOrder == ByteOrder::Network) ? ntohl(address) : address) , m_port((byteOrder == ByteOrder::Network) ? ntohs(port) : port) { ; } uint32_t IpAddress::GetAddress(ByteOrder byteOrder) const { return (byteOrder == ByteOrder::Network) ? htonl(m_ipv4Address) : m_ipv4Address; } uint16_t IpAddress::GetPort(ByteOrder byteOrder) const { return (byteOrder == ByteOrder::Network) ? htons(m_port) : m_port; } IpAddress::IpString IpAddress::GetString() const { return IpString::format("%hhu.%hhu.%hhu.%hhu:%hu", GetQuadA(), GetQuadB(), GetQuadC(), GetQuadD(), GetPort(ByteOrder::Host)); } IpAddress::IpString IpAddress::GetIpString() const { return IpString::format("%hhu.%hhu.%hhu.%hhu", GetQuadA(), GetQuadB(), GetQuadC(), GetQuadD()); } bool IpAddress::Serialize(ISerializer& serializer) { serializer.Serialize(m_ipv4Address, "Ipv4Address"); serializer.Serialize(m_port, "Port"); return serializer.IsValid(); } }