A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
inet-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) 2005 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "inet-socket-address.h"
22 #include "ns3/assert.h"
23 
24 namespace ns3 {
25 
27  : m_ipv4 (ipv4),
28  m_port (port)
29 {
30 }
32  : m_ipv4 (ipv4),
33  m_port (0)
34 {
35 }
36 InetSocketAddress::InetSocketAddress (const char *ipv4, uint16_t port)
37  : m_ipv4 (Ipv4Address (ipv4)),
38  m_port (port)
39 {
40 }
42  : m_ipv4 (Ipv4Address (ipv4)),
43  m_port (0)
44 {
45 }
47  : m_ipv4 (Ipv4Address::GetAny ()),
48  m_port (port)
49 {
50 }
51 uint16_t
53 {
54  return m_port;
55 }
58 {
59  return m_ipv4;
60 }
61 
62 void
64 {
65  m_port = port;
66 }
67 void
69 {
70  m_ipv4 = address;
71 }
72 
73 bool
75 {
76  return address.CheckCompatible (GetType (), 6);
77 }
78 
79 InetSocketAddress::operator Address () const
80 {
81  return ConvertTo ();
82 }
83 
84 Address
86 {
87  uint8_t buf[6];
88  m_ipv4.Serialize (buf);
89  buf[4] = m_port & 0xff;
90  buf[5] = (m_port >> 8) & 0xff;
91  return Address (GetType (), buf, 6);
92 }
95 {
96  NS_ASSERT (address.CheckCompatible (GetType (), 6));
97  uint8_t buf[6];
98  address.CopyTo (buf);
100  uint16_t port = buf[4] | (buf[5] << 8);
101  return InetSocketAddress (ipv4, port);
102 }
103 uint8_t
105 {
106  static uint8_t type = Address::Register ();
107  return type;
108 }
109 
110 } // namespace ns3