00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "inet-socket-address.h"
00022 #include "ns3/assert.h"
00023
00024 namespace ns3 {
00025
00026 InetSocketAddress::InetSocketAddress (Ipv4Address ipv4, uint16_t port)
00027 : m_ipv4 (ipv4),
00028 m_port (port)
00029 {}
00030 InetSocketAddress::InetSocketAddress (Ipv4Address ipv4)
00031 : m_ipv4 (ipv4),
00032 m_port (0)
00033 {}
00034 InetSocketAddress::InetSocketAddress (const char *ipv4, uint16_t port)
00035 : m_ipv4 (Ipv4Address (ipv4)),
00036 m_port (port)
00037 {}
00038 InetSocketAddress::InetSocketAddress (const char * ipv4)
00039 : m_ipv4 (Ipv4Address (ipv4)),
00040 m_port (0)
00041 {}
00042 InetSocketAddress::InetSocketAddress (uint16_t port)
00043 : m_ipv4 (Ipv4Address::GetAny ()),
00044 m_port (port)
00045 {}
00046 uint16_t
00047 InetSocketAddress::GetPort (void) const
00048 {
00049 return m_port;
00050 }
00051 Ipv4Address
00052 InetSocketAddress::GetIpv4 (void) const
00053 {
00054 return m_ipv4;
00055 }
00056
00057 void
00058 InetSocketAddress::SetPort (uint16_t port)
00059 {
00060 m_port = port;
00061 }
00062 void
00063 InetSocketAddress::SetIpv4 (Ipv4Address address)
00064 {
00065 m_ipv4 = address;
00066 }
00067
00068 bool
00069 InetSocketAddress::IsMatchingType (const Address &address)
00070 {
00071 return address.CheckCompatible (GetType (), 6);
00072 }
00073
00074 InetSocketAddress::operator Address () const
00075 {
00076 return ConvertTo ();
00077 }
00078
00079 Address
00080 InetSocketAddress::ConvertTo (void) const
00081 {
00082 uint8_t buf[6];
00083 m_ipv4.Serialize (buf);
00084 buf[4] = m_port & 0xff;
00085 buf[5] = (m_port >> 8) & 0xff;
00086 return Address (GetType (), buf, 6);
00087 }
00088 InetSocketAddress
00089 InetSocketAddress::ConvertFrom (const Address &address)
00090 {
00091 NS_ASSERT (address.CheckCompatible (GetType (), 6));
00092 uint8_t buf[6];
00093 address.CopyTo (buf);
00094 Ipv4Address ipv4 = Ipv4Address::Deserialize (buf);
00095 uint16_t port = buf[4] | (buf[5] << 8);
00096 return InetSocketAddress (ipv4, port);
00097 }
00098 uint8_t
00099 InetSocketAddress::GetType (void)
00100 {
00101 static uint8_t type = Address::Register ();
00102 return type;
00103 }
00104
00105 }