1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2007-2008 Louis Pasteur University
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
21 #include "inet6-socket-address.h"
22 #include "ns3/assert.h"
26 Inet6SocketAddress::Inet6SocketAddress (Ipv6Address ipv6, uint16_t port)
32 Inet6SocketAddress::Inet6SocketAddress (Ipv6Address ipv6)
38 Inet6SocketAddress::Inet6SocketAddress (const char* ipv6, uint16_t port)
39 : m_ipv6(Ipv6Address(ipv6)),
44 Inet6SocketAddress::Inet6SocketAddress (const char* ipv6)
45 : m_ipv6(Ipv6Address(ipv6)),
50 Inet6SocketAddress::Inet6SocketAddress (uint16_t port)
51 : m_ipv6(Ipv6Address::GetAny()),
56 uint16_t Inet6SocketAddress::GetPort (void) const
61 void Inet6SocketAddress::SetPort (uint16_t port)
66 Ipv6Address Inet6SocketAddress::GetIpv6 (void) const
71 void Inet6SocketAddress::SetIpv6 (Ipv6Address ipv6)
76 bool Inet6SocketAddress::IsMatchingType (const Address &addr)
78 return addr.CheckCompatible(GetType(), 18); /* 16 (address) + 2 (port) */
81 Inet6SocketAddress::operator Address (void) const
86 Address Inet6SocketAddress::ConvertTo (void) const
89 m_ipv6.Serialize(buf);
90 buf[16]=m_port & 0xff;
91 buf[17]=(m_port >> 8) &0xff;
92 return Address(GetType(), buf, 18);
95 Inet6SocketAddress Inet6SocketAddress::ConvertFrom (const Address &addr)
97 NS_ASSERT(addr.CheckCompatible(GetType(), 18));
100 Ipv6Address ipv6=Ipv6Address::Deserialize(buf);
101 uint16_t port= buf[16] | (buf[17] << 8);
102 return Inet6SocketAddress(ipv6, port);
105 uint8_t Inet6SocketAddress::GetType (void)
107 static uint8_t type=Address::Register();
111 } /* namespace ns3 */