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