InetAddress -> InetSocketAddress
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 30 Jul 2007 13:29:36 +0200
changeset 1171 335886fe4ddd
parent 1170 39ca41540e00
child 1172 2e5b994330c7
InetAddress -> InetSocketAddress
examples/csma-cd-one-subnet.cc
examples/simple-p2p.cc
examples/simple-point-to-point.cc
samples/main-simple.cc
src/internet-node/udp-socket.cc
src/node/inet-address.cc
src/node/inet-address.h
src/node/inet-socket-address.cc
src/node/inet-socket-address.h
src/node/wscript
--- a/examples/csma-cd-one-subnet.cc	Mon Jul 30 11:07:56 2007 +0200
+++ b/examples/csma-cd-one-subnet.cc	Mon Jul 30 13:29:36 2007 +0200
@@ -52,7 +52,7 @@
 #include "ns3/csma-cd-ipv4-topology.h"
 #include "ns3/eui48-address.h"
 #include "ns3/ipv4-address.h"
-#include "ns3/inet-address.h"
+#include "ns3/inet-socket-address.h"
 #include "ns3/ipv4.h"
 #include "ns3/socket.h"
 #include "ns3/ipv4-route.h"
@@ -132,7 +132,7 @@
   // from n0 to n1
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetAddress (Ipv4Address("10.1.1.2"), 80).ConvertTo (), 
+    InetSocketAddress (Ipv4Address("10.1.1.2"), 80).ConvertTo (), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
@@ -143,7 +143,7 @@
   // Create a similar flow from n3 to n0, starting at time 1.1 seconds
   ooff = Create<OnOffApplication> (
     n3, 
-    InetAddress (Ipv4Address("10.1.1.1"), 80).ConvertTo (), 
+    InetSocketAddress (Ipv4Address("10.1.1.1"), 80).ConvertTo (), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
--- a/examples/simple-p2p.cc	Mon Jul 30 11:07:56 2007 +0200
+++ b/examples/simple-p2p.cc	Mon Jul 30 13:29:36 2007 +0200
@@ -57,7 +57,7 @@
 #include "ns3/p2p-channel.h"
 #include "ns3/p2p-net-device.h"
 #include "ns3/ipv4-address.h"
-#include "ns3/inet-address.h"
+#include "ns3/inet-socket-address.h"
 #include "ns3/ipv4.h"
 #include "ns3/socket.h"
 #include "ns3/ipv4-route.h"
@@ -143,7 +143,7 @@
   // 210 bytes at a rate of 448 Kb/s
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetAddress("10.1.3.2", 80).ConvertTo (), 
+    InetSocketAddress("10.1.3.2", 80).ConvertTo (), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
@@ -154,7 +154,7 @@
   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
   ooff = Create<OnOffApplication> (
     n3, 
-    InetAddress("10.1.2.1", 80).ConvertTo (),
+    InetSocketAddress("10.1.2.1", 80).ConvertTo (),
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
--- a/examples/simple-point-to-point.cc	Mon Jul 30 11:07:56 2007 +0200
+++ b/examples/simple-point-to-point.cc	Mon Jul 30 13:29:36 2007 +0200
@@ -58,7 +58,7 @@
 #include "ns3/point-to-point-channel.h"
 #include "ns3/point-to-point-net-device.h"
 #include "ns3/ipv4-address.h"
-#include "ns3/inet-address.h"
+#include "ns3/inet-socket-address.h"
 #include "ns3/ipv4.h"
 #include "ns3/socket.h"
 #include "ns3/ipv4-route.h"
@@ -144,7 +144,7 @@
   // 210 bytes at a rate of 448 Kb/s
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetAddress (Ipv4Address("10.1.3.2"), 80).ConvertTo (), 
+    InetSocketAddress (Ipv4Address("10.1.3.2"), 80).ConvertTo (), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
@@ -155,7 +155,7 @@
   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
   ooff = Create<OnOffApplication> (
     n3, 
-    InetAddress (Ipv4Address("10.1.2.1"), 80).ConvertTo (), 
+    InetSocketAddress (Ipv4Address("10.1.2.1"), 80).ConvertTo (), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
--- a/samples/main-simple.cc	Mon Jul 30 11:07:56 2007 +0200
+++ b/samples/main-simple.cc	Mon Jul 30 13:29:36 2007 +0200
@@ -4,7 +4,7 @@
 #include "ns3/simulator.h"
 #include "ns3/socket-factory.h"
 #include "ns3/socket.h"
-#include "ns3/inet-address.h"
+#include "ns3/inet-socket-address.h"
 #include "ns3/nstime.h"
 
 using namespace ns3;
@@ -45,11 +45,11 @@
   Ptr<SocketFactory> socketFactory = a->QueryInterface<SocketFactory> (iid);
 
   Ptr<Socket> sink = socketFactory->CreateSocket ();
-  InetAddress local = InetAddress (Ipv4Address::GetAny (), 80);
+  InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
   sink->Bind (local.ConvertTo ());
 
   Ptr<Socket> source = socketFactory->CreateSocket ();
-  InetAddress remote = InetAddress (Ipv4Address::GetLoopback (), 80);
+  InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetLoopback (), 80);
   source->Connect (remote.ConvertTo ());
 
   GenerateTraffic (source, 500);
--- a/src/internet-node/udp-socket.cc	Mon Jul 30 11:07:56 2007 +0200
+++ b/src/internet-node/udp-socket.cc	Mon Jul 30 13:29:36 2007 +0200
@@ -19,7 +19,7 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #include "ns3/node.h"
-#include "ns3/inet-address.h"
+#include "ns3/inet-socket-address.h"
 #include "udp-socket.h"
 #include "udp-l4-protocol.h"
 #include "ipv4-end-point.h"
@@ -91,7 +91,7 @@
 int 
 UdpSocket::Bind (const Address &address)
 {
-  InetAddress transport = InetAddress::ConvertFrom (address);
+  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   Ipv4Address ipv4 = transport.GetIpv4 ();
   uint16_t port = transport.GetPort ();
   if (ipv4 == Ipv4Address::GetAny () && port == 0)
@@ -147,7 +147,7 @@
                      ns3::Callback<void, Ptr<Socket> > connectionFailed,
                      ns3::Callback<void, Ptr<Socket> > halfClose)
 {
-  InetAddress transport = InetAddress::ConvertFrom (address);
+  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   m_defaultAddress = transport.GetIpv4 ();
   m_defaultPort = transport.GetPort ();
   if (!connectionSucceeded.IsNull ())
@@ -190,7 +190,7 @@
 UdpSocket::DoSendPacketTo (const Packet &p, const Address &address,
                            ns3::Callback<void, Ptr<Socket>, uint32_t> dataSent)
 {
-  InetAddress transport = InetAddress::ConvertFrom (address);
+  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   Ipv4Address ipv4 = transport.GetIpv4 ();
   uint16_t port = transport.GetPort ();
   return DoSendPacketTo (p, ipv4, port, dataSent);
@@ -241,7 +241,7 @@
     {
       p = Packet (buffer, size);
     }
-  InetAddress transport = InetAddress::ConvertFrom (address);
+  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   Ipv4Address ipv4 = transport.GetIpv4 ();
   uint16_t port = transport.GetPort ();
   return DoSendPacketTo (p, ipv4, port, dataSent);
@@ -265,7 +265,7 @@
       return;
     }
   
-  Address address = InetAddress (ipv4, port).ConvertTo ();
+  Address address = InetSocketAddress (ipv4, port).ConvertTo ();
   Packet p = packet;
   if (!m_dummyRxCallback.IsNull ())
     {
--- a/src/node/inet-address.cc	Mon Jul 30 11:07:56 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-#include "inet-address.h"
-#include "ns3/assert.h"
-
-namespace ns3 {
-
-InetAddress::InetAddress (Ipv4Address ipv4, uint16_t port)
-  : m_ipv4 (ipv4),
-    m_port (port)
-{}
-InetAddress::InetAddress (Ipv4Address ipv4)
-  : m_ipv4 (ipv4),
-    m_port (0)
-{}
-InetAddress::InetAddress (const char *ipv4, uint16_t port)
-  : m_ipv4 (Ipv4Address (ipv4)),
-    m_port (port)
-{}
-InetAddress::InetAddress (const char * ipv4)
-  : m_ipv4 (Ipv4Address (ipv4)),
-    m_port (0)
-{}
-InetAddress::InetAddress (uint16_t port)
-  : m_ipv4 (Ipv4Address::GetAny ()),
-    m_port (port)
-{}
-uint16_t 
-InetAddress::GetPort (void) const
-{
-  return m_port;
-}
-Ipv4Address 
-InetAddress::GetIpv4 (void) const
-{
-  return m_ipv4;
-}
-
-void 
-InetAddress::SetPort (uint16_t port)
-{
-  m_port = port;
-}
-void 
-InetAddress::SetIpv4 (Ipv4Address address)
-{
-  m_ipv4 = address;
-}
-
-Address 
-InetAddress::ConvertTo (void) const
-{
-  uint8_t buf[6];
-  m_ipv4.Serialize (buf);
-  buf[4] = m_port & 0xff;
-  buf[5] = (m_port >> 8) & 0xff;
-  return Address (GetType (), buf, 6);
-}
-InetAddress 
-InetAddress::ConvertFrom (const Address &address)
-{
-  NS_ASSERT (address.CheckCompatible (GetType (), 6));
-  uint8_t buf[6];
-  address.CopyTo (buf);
-  Ipv4Address ipv4 = Ipv4Address::Deserialize (buf);
-  uint16_t port = buf[0] | (buf[1] << 8);
-  return InetAddress (ipv4, port);
-}
-uint8_t 
-InetAddress::GetType (void)
-{
-  static uint8_t type = Address::Register ();
-  return type;
-}
-
-} // namespace ns3
--- a/src/node/inet-address.h	Mon Jul 30 11:07:56 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-#ifndef IPV4_TRANSPORT_ADDRESS_H
-#define IPV4_TRANSPORT_ADDRESS_H
-
-#include "address.h"
-#include "ipv4-address.h"
-#include <stdint.h>
-
-namespace ns3 {
-
-
-/**
- * \brief an Inet address class
- *
- * This class is similar to inet_sockaddr in the BSD socket
- * API. i.e., this class holds an Ipv4Address and a port number
- * to form an ipv4 transport endpoint.
- */
-class InetAddress
-{
-public:
-  /**
-   * \param ipv4 the ipv4 address
-   * \param port the port number
-   */
-  InetAddress (Ipv4Address ipv4, uint16_t port);
-  /**
-   * \param ipv4 the ipv4 address
-   *
-   * The port number is set to zero by default.
-   */
-  InetAddress (Ipv4Address ipv4);
-  /**
-   * \param port the port number
-   *
-   * The ipv4 address is set to the "Any" address by default.
-   */
-  InetAddress (uint16_t port);
-  /**
-   * \param ipv4 string which represents an ipv4 address
-   * \param port the port number
-   */
-  InetAddress (const char *ipv4, uint16_t port);
-  /**
-   * \param ipv4 string which represents an ipv4 address
-   *
-   * The port number is set to zero.
-   */
-  InetAddress (const char *ipv4);
-  /**
-   * \returns the port number
-   */
-  uint16_t GetPort (void) const;
-  /**
-   * \returns the ipv4 address
-   */
-  Ipv4Address GetIpv4 (void) const;
-
-  /**
-   * \param port the new port number.
-   */
-  void SetPort (uint16_t port);
-  /**
-   * \param address the new ipv4 address
-   */
-  void SetIpv4 (Ipv4Address address);
-
-  /**
-   * \returns an Address instance which represents this
-   * InetAddress instance.
-   */
-  Address ConvertTo (void) const;
-  /**
-   * \param address the Address instance to convert from.
-   * \returns an InetAddress which corresponds to the input
-   * Address
-   */
-  static InetAddress ConvertFrom (const Address &address);
-private:
-  static uint8_t GetType (void);
-  Ipv4Address m_ipv4;
-  uint16_t m_port;
-};
-
-} // namespace ns3
-
-
-#endif /* IPV4_TRANSPORT_ADDRESS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/inet-socket-address.cc	Mon Jul 30 13:29:36 2007 +0200
@@ -0,0 +1,74 @@
+#include "inet-socket-address.h"
+#include "ns3/assert.h"
+
+namespace ns3 {
+
+InetSocketAddress::InetSocketAddress (Ipv4Address ipv4, uint16_t port)
+  : m_ipv4 (ipv4),
+    m_port (port)
+{}
+InetSocketAddress::InetSocketAddress (Ipv4Address ipv4)
+  : m_ipv4 (ipv4),
+    m_port (0)
+{}
+InetSocketAddress::InetSocketAddress (const char *ipv4, uint16_t port)
+  : m_ipv4 (Ipv4Address (ipv4)),
+    m_port (port)
+{}
+InetSocketAddress::InetSocketAddress (const char * ipv4)
+  : m_ipv4 (Ipv4Address (ipv4)),
+    m_port (0)
+{}
+InetSocketAddress::InetSocketAddress (uint16_t port)
+  : m_ipv4 (Ipv4Address::GetAny ()),
+    m_port (port)
+{}
+uint16_t 
+InetSocketAddress::GetPort (void) const
+{
+  return m_port;
+}
+Ipv4Address 
+InetSocketAddress::GetIpv4 (void) const
+{
+  return m_ipv4;
+}
+
+void 
+InetSocketAddress::SetPort (uint16_t port)
+{
+  m_port = port;
+}
+void 
+InetSocketAddress::SetIpv4 (Ipv4Address address)
+{
+  m_ipv4 = address;
+}
+
+Address 
+InetSocketAddress::ConvertTo (void) const
+{
+  uint8_t buf[6];
+  m_ipv4.Serialize (buf);
+  buf[4] = m_port & 0xff;
+  buf[5] = (m_port >> 8) & 0xff;
+  return Address (GetType (), buf, 6);
+}
+InetSocketAddress 
+InetSocketAddress::ConvertFrom (const Address &address)
+{
+  NS_ASSERT (address.CheckCompatible (GetType (), 6));
+  uint8_t buf[6];
+  address.CopyTo (buf);
+  Ipv4Address ipv4 = Ipv4Address::Deserialize (buf);
+  uint16_t port = buf[0] | (buf[1] << 8);
+  return InetSocketAddress (ipv4, port);
+}
+uint8_t 
+InetSocketAddress::GetType (void)
+{
+  static uint8_t type = Address::Register ();
+  return type;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/inet-socket-address.h	Mon Jul 30 13:29:36 2007 +0200
@@ -0,0 +1,87 @@
+#ifndef IPV4_TRANSPORT_ADDRESS_H
+#define IPV4_TRANSPORT_ADDRESS_H
+
+#include "address.h"
+#include "ipv4-address.h"
+#include <stdint.h>
+
+namespace ns3 {
+
+
+/**
+ * \brief an Inet address class
+ *
+ * This class is similar to inet_sockaddr in the BSD socket
+ * API. i.e., this class holds an Ipv4Address and a port number
+ * to form an ipv4 transport endpoint.
+ */
+class InetSocketAddress
+{
+public:
+  /**
+   * \param ipv4 the ipv4 address
+   * \param port the port number
+   */
+  InetSocketAddress (Ipv4Address ipv4, uint16_t port);
+  /**
+   * \param ipv4 the ipv4 address
+   *
+   * The port number is set to zero by default.
+   */
+  InetSocketAddress (Ipv4Address ipv4);
+  /**
+   * \param port the port number
+   *
+   * The ipv4 address is set to the "Any" address by default.
+   */
+  InetSocketAddress (uint16_t port);
+  /**
+   * \param ipv4 string which represents an ipv4 address
+   * \param port the port number
+   */
+  InetSocketAddress (const char *ipv4, uint16_t port);
+  /**
+   * \param ipv4 string which represents an ipv4 address
+   *
+   * The port number is set to zero.
+   */
+  InetSocketAddress (const char *ipv4);
+  /**
+   * \returns the port number
+   */
+  uint16_t GetPort (void) const;
+  /**
+   * \returns the ipv4 address
+   */
+  Ipv4Address GetIpv4 (void) const;
+
+  /**
+   * \param port the new port number.
+   */
+  void SetPort (uint16_t port);
+  /**
+   * \param address the new ipv4 address
+   */
+  void SetIpv4 (Ipv4Address address);
+
+  /**
+   * \returns an Address instance which represents this
+   * InetSocketAddress instance.
+   */
+  Address ConvertTo (void) const;
+  /**
+   * \param address the Address instance to convert from.
+   * \returns an InetSocketAddress which corresponds to the input
+   * Address
+   */
+  static InetSocketAddress ConvertFrom (const Address &address);
+private:
+  static uint8_t GetType (void);
+  Ipv4Address m_ipv4;
+  uint16_t m_port;
+};
+
+} // namespace ns3
+
+
+#endif /* IPV4_TRANSPORT_ADDRESS_H */
--- a/src/node/wscript	Mon Jul 30 11:07:56 2007 +0200
+++ b/src/node/wscript	Mon Jul 30 13:29:36 2007 +0200
@@ -8,7 +8,7 @@
     node.source = [
         'address.cc',
         'eui48-address.cc',
-        'inet-address.cc',
+        'inet-socket-address.cc',
         'node.cc',
         'ipv4-address.cc',
         'net-device.cc',
@@ -32,7 +32,7 @@
     headers.source = [
         'address.h',
         'eui48-address.h',
-        'inet-address.h',
+        'inet-socket-address.h',
         'node.h',
         'ipv4-address.h',
         'net-device.h',