1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/node/inet6-socket-address.cc Fri Nov 07 11:36:15 2008 -0800
1.3 @@ -0,0 +1,112 @@
1.4 +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
1.5 +/*
1.6 + * Copyright (c) 2007-2008 Louis Pasteur University
1.7 + *
1.8 + * This program is free software; you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License version 2 as
1.10 + * published by the Free Software Foundation;
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License
1.18 + * along with this program; if not, write to the Free Software
1.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.20 + *
1.21 + * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
1.22 + */
1.23 +
1.24 +#include "inet6-socket-address.h"
1.25 +#include "ns3/assert.h"
1.26 +
1.27 +namespace ns3 {
1.28 +
1.29 +Inet6SocketAddress::Inet6SocketAddress (Ipv6Address ipv6, uint16_t port)
1.30 +: m_ipv6(ipv6),
1.31 + m_port(port)
1.32 +{
1.33 +}
1.34 +
1.35 +Inet6SocketAddress::Inet6SocketAddress (Ipv6Address ipv6)
1.36 +: m_ipv6(ipv6),
1.37 + m_port(0)
1.38 +{
1.39 +}
1.40 +
1.41 + Inet6SocketAddress::Inet6SocketAddress (const char* ipv6, uint16_t port)
1.42 +: m_ipv6(Ipv6Address(ipv6)),
1.43 + m_port(port)
1.44 +{
1.45 +}
1.46 +
1.47 + Inet6SocketAddress::Inet6SocketAddress (const char* ipv6)
1.48 +: m_ipv6(Ipv6Address(ipv6)),
1.49 + m_port(0)
1.50 +{
1.51 +}
1.52 +
1.53 + Inet6SocketAddress::Inet6SocketAddress (uint16_t port)
1.54 +: m_ipv6(Ipv6Address::GetAny()),
1.55 + m_port(port)
1.56 +{
1.57 +}
1.58 +
1.59 +uint16_t Inet6SocketAddress::GetPort (void) const
1.60 +{
1.61 + return m_port;
1.62 +}
1.63 +
1.64 +void Inet6SocketAddress::SetPort (uint16_t port)
1.65 +{
1.66 + m_port=port;
1.67 +}
1.68 +
1.69 +Ipv6Address Inet6SocketAddress::GetIpv6 (void) const
1.70 +{
1.71 + return m_ipv6;
1.72 +}
1.73 +
1.74 +void Inet6SocketAddress::SetIpv6 (Ipv6Address ipv6)
1.75 +{
1.76 + m_ipv6=ipv6;
1.77 +}
1.78 +
1.79 +bool Inet6SocketAddress::IsMatchingType (const Address &addr)
1.80 +{
1.81 + return addr.CheckCompatible(GetType(), 18); /* 16 (address) + 2 (port) */
1.82 +}
1.83 +
1.84 +Inet6SocketAddress::operator Address (void) const
1.85 +{
1.86 + return ConvertTo();
1.87 +}
1.88 +
1.89 +Address Inet6SocketAddress::ConvertTo (void) const
1.90 +{
1.91 + uint8_t buf[18];
1.92 + m_ipv6.Serialize(buf);
1.93 + buf[16]=m_port & 0xff;
1.94 + buf[17]=(m_port >> 8) &0xff;
1.95 + return Address(GetType(), buf, 18);
1.96 +}
1.97 +
1.98 +Inet6SocketAddress Inet6SocketAddress::ConvertFrom (const Address &addr)
1.99 +{
1.100 + NS_ASSERT(addr.CheckCompatible(GetType(), 18));
1.101 + uint8_t buf[18];
1.102 + addr.CopyTo(buf);
1.103 + Ipv6Address ipv6=Ipv6Address::Deserialize(buf);
1.104 + uint16_t port= buf[16] | (buf[17] << 8);
1.105 + return Inet6SocketAddress(ipv6, port);
1.106 +}
1.107 +
1.108 +uint8_t Inet6SocketAddress::GetType (void)
1.109 +{
1.110 + static uint8_t type=Address::Register();
1.111 + return type;
1.112 +}
1.113 +
1.114 +} /* namespace ns3 */
1.115 +