A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
inet6-socket-address.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2008 Louis Pasteur University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 */
8
10
11#include "ns3/assert.h"
12#include "ns3/log.h"
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("Inet6SocketAddress");
18
20 : m_ipv6(ipv6),
21 m_port(port)
22{
23 NS_LOG_FUNCTION(this << ipv6 << port);
24}
25
27 : m_ipv6(ipv6),
28 m_port(0)
29{
30 NS_LOG_FUNCTION(this << ipv6);
31}
32
34 : m_ipv6(Ipv6Address(ipv6)),
35 m_port(port)
36{
37 NS_LOG_FUNCTION(this << ipv6 << port);
38}
39
41 : m_ipv6(Ipv6Address(ipv6)),
42 m_port(0)
43{
44 NS_LOG_FUNCTION(this << ipv6);
45}
46
48 : m_ipv6(Ipv6Address::GetAny()),
49 m_port(port)
50{
51 NS_LOG_FUNCTION(this << port);
52}
53
54uint16_t
56{
57 NS_LOG_FUNCTION(this);
58 return m_port;
59}
60
61void
63{
64 NS_LOG_FUNCTION(this << port);
65 m_port = port;
66}
67
70{
71 NS_LOG_FUNCTION(this);
72 return m_ipv6;
73}
74
75void
77{
78 NS_LOG_FUNCTION(this << ipv6);
79 m_ipv6 = ipv6;
80}
81
82bool
84{
85 NS_LOG_FUNCTION(&addr);
86 return addr.CheckCompatible(GetType(), 18); /* 16 (address) + 2 (port) */
87}
88
89Inet6SocketAddress::operator Address() const
90{
91 return ConvertTo();
92}
93
96{
97 NS_LOG_FUNCTION(this);
98 uint8_t buf[18];
99 m_ipv6.Serialize(buf);
100 buf[16] = m_port & 0xff;
101 buf[17] = (m_port >> 8) & 0xff;
102 return Address(GetType(), buf, 18);
103}
104
107{
108 NS_LOG_FUNCTION(&addr);
109 NS_ASSERT(addr.CheckCompatible(GetType(), 18));
110 uint8_t buf[18];
111 addr.CopyTo(buf);
113 uint16_t port = buf[16] | (buf[17] << 8);
114 return Inet6SocketAddress(ipv6, port);
115}
116
117uint8_t
119{
121 static uint8_t type = Address::Register();
122 return type;
123}
124
125} /* namespace ns3 */
a polymophic address class
Definition address.h:90
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition address.cc:118
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition address.cc:135
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition address.cc:75
An Inet6 address class.
static uint8_t GetType()
Get the type.
void SetPort(uint16_t port)
Set the port.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
uint16_t GetPort() const
Get the port.
Inet6SocketAddress(Ipv6Address ipv6, uint16_t port)
Constructor.
void SetIpv6(Ipv6Address ipv6)
Set the IPv6 address.
static bool IsMatchingType(const Address &addr)
If the address match.
Ipv6Address GetIpv6() const
Get the IPv6 address.
Address ConvertTo() const
Convert to Address.
Ipv6Address m_ipv6
The IPv6 address.
Describes an IPv6 address.
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
uint16_t port
Definition dsdv-manet.cc:33
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.