A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
inet6-socket-address.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2008 Louis Pasteur University
4  *
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;
8  *
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.
13  *
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
17  *
18  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #include "ns3/assert.h"
22 
23 #include "inet6-socket-address.h"
24 
25 namespace ns3
26 {
27 
29  : m_ipv6 (ipv6),
30  m_port (port)
31 {
32 }
33 
35  : m_ipv6 (ipv6),
36  m_port (0)
37 {
38 }
39 
40 Inet6SocketAddress::Inet6SocketAddress (const char* ipv6, uint16_t port)
41  : m_ipv6 (Ipv6Address (ipv6)),
42  m_port (port)
43 {
44 }
45 
47  : m_ipv6 (Ipv6Address (ipv6)),
48  m_port (0)
49 {
50 }
51 
53  : m_ipv6 (Ipv6Address::GetAny ()),
54  m_port (port)
55 {
56 }
57 
58 uint16_t Inet6SocketAddress::GetPort (void) const
59 {
60  return m_port;
61 }
62 
64 {
65  m_port=port;
66 }
67 
69 {
70  return m_ipv6;
71 }
72 
74 {
75  m_ipv6=ipv6;
76 }
77 
79 {
80  return addr.CheckCompatible (GetType (), 18); /* 16 (address) + 2 (port) */
81 }
82 
83 Inet6SocketAddress::operator Address (void) const
84 {
85  return ConvertTo ();
86 }
87 
89 {
90  uint8_t buf[18];
91  m_ipv6.Serialize (buf);
92  buf[16]=m_port & 0xff;
93  buf[17]=(m_port >> 8) &0xff;
94  return Address (GetType (), buf, 18);
95 }
96 
98 {
99  NS_ASSERT (addr.CheckCompatible (GetType (), 18));
100  uint8_t buf[18];
101  addr.CopyTo (buf);
103  uint16_t port= buf[16] | (buf[17] << 8);
104  return Inet6SocketAddress (ipv6, port);
105 }
106 
108 {
109  static uint8_t type=Address::Register ();
110  return type;
111 }
112 
113 } /* namespace ns3 */
114