Implementation cut over to use Ipv4InterfaceAddress
authorTom Henderson <tomh@tomh.org>
Sun, 12 Apr 2009 22:13:49 -0700
changeset 4375 db81fdcb06e7
parent 4374 2aae35f2287f
child 4376 ac217f25fe70
Implementation cut over to use Ipv4InterfaceAddress
examples/global-routing-slash32.cc
examples/mixed-wireless.cc
examples/static-routing-slash32.cc
src/devices/tap-bridge/tap-bridge.cc
src/helper/ipv4-address-helper.cc
src/helper/ipv4-interface-container.cc
src/helper/ipv4-interface-container.h
src/internet-stack/arp-ipv4-interface.cc
src/internet-stack/arp-l3-protocol.cc
src/internet-stack/icmpv4-l4-protocol.cc
src/internet-stack/ipv4-end-point-demux.cc
src/internet-stack/ipv4-impl.cc
src/internet-stack/ipv4-impl.h
src/internet-stack/ipv4-interface.cc
src/internet-stack/ipv4-interface.h
src/internet-stack/ipv4-l3-protocol.cc
src/internet-stack/ipv4-l3-protocol.h
src/internet-stack/ipv4-raw-socket-impl.cc
src/internet-stack/nsc-tcp-l4-protocol.cc
src/internet-stack/tcp-socket-impl.cc
src/internet-stack/udp-socket-impl.cc
src/node/ipv4.cc
src/node/ipv4.h
src/routing/global-routing/global-router-interface.cc
src/routing/olsr/olsr-agent-impl.cc
src/routing/olsr/olsr-routing-table.cc
--- a/examples/global-routing-slash32.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/examples/global-routing-slash32.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -87,13 +87,13 @@
   int32_t ifIndexA = ipv4A->AddInterface (deviceA);
   int32_t ifIndexC = ipv4C->AddInterface (deviceC);
     
-  ipv4A->SetAddress (ifIndexA, Ipv4Address ("172.16.1.1"));
-  ipv4A->SetNetworkMask (ifIndexA, Ipv4Mask ("255.255.255.255"));
+  Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
+  ipv4A->AddAddress (ifIndexA, ifInAddrA);
   ipv4A->SetMetric (ifIndexA, 1);
   ipv4A->SetUp (ifIndexA);
 
-  ipv4C->SetAddress (ifIndexC, Ipv4Address ("192.168.1.1"));
-  ipv4C->SetNetworkMask (ifIndexC, Ipv4Mask ("255.255.255.255"));
+  Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
+  ipv4C->AddAddress (ifIndexC, ifInAddrC);
   ipv4C->SetMetric (ifIndexC, 1);
   ipv4C->SetUp (ifIndexC);
  
@@ -105,7 +105,7 @@
   // 210 bytes at a rate of 448 Kb/s
   uint16_t port = 9;   // Discard port (RFC 863)
   OnOffHelper onoff ("ns3::UdpSocketFactory", 
-    Address (InetSocketAddress (Ipv4Address("192.168.1.1"), port)));
+    Address (InetSocketAddress (ifInAddrC.GetLocal(), port)));
   onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
   onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
   onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
--- a/examples/mixed-wireless.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/examples/mixed-wireless.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -353,7 +353,7 @@
   uint32_t lastNodeIndex = backboneNodes + backboneNodes*(lanNodes - 1) + backboneNodes*(infraNodes - 1) - 1;
   Ptr<Node> appSink = NodeList::GetNode (lastNodeIndex);  
   // Let's fetch the IP address of the last node, which is on Ipv4Interface 1
-  Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress(1);
+  Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress(1, 0).GetLocal ();
 
   OnOffHelper onoff ("ns3::UdpSocketFactory", 
                      Address (InetSocketAddress (remoteAddr, port)));
--- a/examples/static-routing-slash32.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/examples/static-routing-slash32.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -87,13 +87,13 @@
   int32_t ifIndexA = ipv4A->AddInterface (deviceA);
   int32_t ifIndexC = ipv4C->AddInterface (deviceC);
     
-  ipv4A->SetAddress (ifIndexA, Ipv4Address ("172.16.1.1"));
-  ipv4A->SetNetworkMask (ifIndexA, Ipv4Mask ("255.255.255.255"));
+  Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
+  ipv4A->AddAddress (ifIndexA, ifInAddrA);
   ipv4A->SetMetric (ifIndexA, 1);
   ipv4A->SetUp (ifIndexA);
 
-  ipv4C->SetAddress (ifIndexC, Ipv4Address ("192.168.1.1"));
-  ipv4C->SetNetworkMask (ifIndexC, Ipv4Mask ("255.255.255.255"));
+  Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
+  ipv4C->AddAddress (ifIndexC, ifInAddrC);
   ipv4C->SetMetric (ifIndexC, 1);
   ipv4C->SetUp (ifIndexC);
  
@@ -107,7 +107,7 @@
   // 210 bytes at a rate of 448 Kb/s
   uint16_t port = 9;   // Discard port (RFC 863)
   OnOffHelper onoff ("ns3::UdpSocketFactory", 
-    Address (InetSocketAddress (Ipv4Address("192.168.1.1"), port)));
+    Address (InetSocketAddress (ifInAddrC.GetLocal (), port)));
   onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
   onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
   onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
--- a/src/devices/tap-bridge/tap-bridge.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/devices/tap-bridge/tap-bridge.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -343,12 +343,16 @@
       Ptr<Node> n = nd->GetNode ();
       Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
       uint32_t index = ipv4->FindInterfaceForDevice (nd);
-      Ipv4Address ipv4Address = ipv4->GetAddress (index);
+      if (ipv4->GetNAddresses (index) > 1)
+        {
+          NS_LOG_WARN ("Underlying bridged NetDevice has multiple IP addresses; using first one.");
+        }
+      Ipv4Address ipv4Address = ipv4->GetAddress (index, 0).GetLocal ();
 
       //
       // The net mask is sitting right there next to the ipv4 address.
       //
-      Ipv4Mask ipv4Mask = ipv4->GetNetworkMask (index);
+      Ipv4Mask ipv4Mask = ipv4->GetAddress (index, 0).GetMask ();
 
       //
       // The MAC address should also already be assigned and waiting for us in
--- a/src/helper/ipv4-address-helper.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/helper/ipv4-address-helper.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -139,8 +139,8 @@
     NS_ASSERT_MSG (interface >= 0, "Ipv4AddressHelper::Allocate(): "
       "Interface index not found");
 
-    ipv4->SetAddress (interface, NewAddress ());
-    ipv4->SetNetworkMask (interface, m_mask);
+    Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (NewAddress (), m_mask);
+    ipv4->AddAddress (interface, ipv4Addr);
     ipv4->SetMetric (interface, 1);
     ipv4->SetUp (interface);
     retval.Add (ipv4, interface);
--- a/src/helper/ipv4-interface-container.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/helper/ipv4-interface-container.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -23,12 +23,13 @@
 }
 
 Ipv4Address 
-Ipv4InterfaceContainer::GetAddress (uint32_t i) const
+Ipv4InterfaceContainer::GetAddress (uint32_t i, uint32_t j) const
 {
   Ptr<Ipv4> ipv4 = m_interfaces[i].first;
   uint32_t interface = m_interfaces[i].second;
-  return ipv4->GetAddress (interface);
+  return ipv4->GetAddress (interface, j).GetLocal ();
 }
+
 void 
 Ipv4InterfaceContainer::SetMetric (uint32_t i, uint16_t metric)
 {
--- a/src/helper/ipv4-interface-container.h	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/helper/ipv4-interface-container.h	Sun Apr 12 22:13:49 2009 -0700
@@ -30,7 +30,16 @@
    */
   uint32_t GetN (void) const;
 
-  Ipv4Address GetAddress (uint32_t i) const;
+  /**
+   * \returns the IPv4 address of the j'th address of the interface
+   *  corresponding to index i.
+   * 
+   * If the second parameter is omitted, the zeroth indexed address of 
+   * the interface is returned.  Unless IP aliaising is being used on
+   * the interface, the second parameter may typically be omitted.
+   */
+  Ipv4Address GetAddress (uint32_t i, uint32_t j = 0) const;
+
   void SetMetric (uint32_t i, uint16_t metric);
 
   void Add (Ptr<Ipv4> ipv4, uint32_t interface);
--- a/src/internet-stack/arp-ipv4-interface.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/arp-ipv4-interface.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -106,7 +106,8 @@
   NS_LOG_FUNCTION (this << p << dest);
 
   NS_ASSERT (GetDevice () != 0);
-  if (dest == GetAddress ())
+  // XXX multi-address case
+  if (dest == GetAddress (0).GetLocal ())
     {
       Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
         
@@ -124,9 +125,9 @@
         m_node->GetObject<ArpL3Protocol> ();
       Address hardwareDestination;
       bool found;
-      
+      // XXX multi-address case
       if (dest.IsBroadcast () || 
-          dest.IsSubnetDirectedBroadcast (GetNetworkMask ()) )
+          dest.IsSubnetDirectedBroadcast (GetAddress (0).GetMask ()) )
         {
           NS_LOG_LOGIC ("IsBroadcast");
           hardwareDestination = GetDevice ()->GetBroadcast ();
--- a/src/internet-stack/arp-l3-protocol.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/arp-l3-protocol.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -142,28 +142,29 @@
       NS_LOG_LOGIC ("ARP: Cannot remove ARP header");
       return;
     }
-  
+  // XXX multi-address case  
   NS_LOG_LOGIC ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
             " node="<<m_node->GetId ()<<", got request from " <<
             arp.GetSourceIpv4Address () << " for address " <<
             arp.GetDestinationIpv4Address () << "; we have address " <<
-            cache->GetInterface ()->GetAddress ());
+            cache->GetInterface ()->GetAddress (0).GetLocal ());
 
   /**
    * Note: we do not update the ARP cache when we receive an ARP request
    * from an unknown node. See bug #107
    */
-
+  // XXX multi-address case
   if (arp.IsRequest () && 
-      arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) 
+      arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress (0).GetLocal ()) 
     {
       NS_LOG_LOGIC ("node="<<m_node->GetId () <<", got request from " << 
                 arp.GetSourceIpv4Address () << " -- send reply");
       SendArpReply (cache, arp.GetSourceIpv4Address (),
                     arp.GetSourceHardwareAddress ());
     } 
+  // XXX multi-address case
   else if (arp.IsReply () &&
-           arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) &&
+           arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress (0).GetLocal ()) &&
            arp.GetDestinationHardwareAddress () == device->GetAddress ()) 
     {
       Ipv4Address from = arp.GetSourceIpv4Address ();
@@ -284,11 +285,12 @@
   ArpHeader arp;
   NS_LOG_LOGIC ("ARP: sending request from node "<<m_node->GetId ()<<
             " || src: " << cache->GetDevice ()->GetAddress () <<
-            " / " << cache->GetInterface ()->GetAddress () <<
+            " / " << cache->GetInterface ()->GetAddress (0).GetLocal () <<
             " || dst: " << cache->GetDevice ()->GetBroadcast () <<
             " / " << to);
+  // XXX multi-address case
   arp.SetRequest (cache->GetDevice ()->GetAddress (),
-		  cache->GetInterface ()->GetAddress (), 
+		  cache->GetInterface ()->GetAddress (0).GetLocal (), 
                   cache->GetDevice ()->GetBroadcast (),
                   to);
   Ptr<Packet> packet = Create<Packet> ();
@@ -303,10 +305,11 @@
   ArpHeader arp;
   NS_LOG_LOGIC ("ARP: sending reply from node "<<m_node->GetId ()<<
             "|| src: " << cache->GetDevice ()->GetAddress () << 
-            " / " << cache->GetInterface ()->GetAddress () <<
+            " / " << cache->GetInterface ()->GetAddress (0).GetLocal () <<
             " || dst: " << toMac << " / " << toIp);
+  // XXX multi-address case
   arp.SetReply (cache->GetDevice ()->GetAddress (),
-                cache->GetInterface ()->GetAddress (),
+                cache->GetInterface ()->GetAddress (0).GetLocal (),
                 toMac, toIp);
   Ptr<Packet> packet = Create<Packet> ();
   packet->AddHeader (arp);
--- a/src/internet-stack/icmpv4-l4-protocol.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/icmpv4-l4-protocol.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -68,7 +68,8 @@
       NS_LOG_WARN ("drop icmp message");
       return;
     }
-  Ipv4Address source = ipv4->GetAddress (i);
+  // XXX handle multi-address case
+  Ipv4Address source = ipv4->GetAddress (i, 0).GetLocal ();
   SendMessage (packet, source, dest, type, code);
 }
 
--- a/src/internet-stack/ipv4-end-point-demux.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/ipv4-end-point-demux.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -219,10 +219,11 @@
                         << " does not match packet dport " << dport);
           continue;
         }
+      // XXX handle multi-address case
       bool isBroadcast = (daddr.IsBroadcast () ||
          daddr.IsSubnetDirectedBroadcast (
-             incomingInterface->GetNetworkMask ()));
-      Ipv4Address incomingInterfaceAddr = incomingInterface->GetAddress ();
+             incomingInterface->GetAddress (0).GetMask ()));
+      Ipv4Address incomingInterfaceAddr = incomingInterface->GetAddress (0).GetLocal ();
       NS_LOG_DEBUG ("dest addr " << daddr << " broadcast? " << isBroadcast);
       bool localAddressMatchesWildCard = 
         endP->GetLocalAddress() == Ipv4Address::GetAny();
--- a/src/internet-stack/ipv4-impl.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/ipv4-impl.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -207,28 +207,6 @@
   return m_ipv4->GetNAddresses (interface);
 }
 
-void 
-Ipv4Impl::SetAddress (uint32_t i, Ipv4Address address)
-{
-  m_ipv4->SetAddress (i, address);
-}
-void 
-Ipv4Impl::SetNetworkMask (uint32_t i, Ipv4Mask mask)
-{
-  m_ipv4->SetNetworkMask (i, mask);
-}
-Ipv4Mask 
-Ipv4Impl::GetNetworkMask (uint32_t i) const
-{
-  return m_ipv4->GetNetworkMask (i);
-}
-
-Ipv4Address 
-Ipv4Impl::GetAddress (uint32_t i) const
-{
-  return m_ipv4->GetAddress (i);
-}
-
 void
 Ipv4Impl::SetMetric (uint32_t i, uint16_t metric) 
 {
@@ -250,21 +228,7 @@
 Ipv4Address 
 Ipv4Impl::GetSourceAddress (Ipv4Address destination) const
 {
-  uint32_t interface = 0xffffffff;
-
-  bool result = m_ipv4->GetInterfaceForDestination (destination, interface);
-
-  if (result)
-    {
-      return m_ipv4->GetAddress (interface);
-    }
-  else
-    {
-//
-// If we can't find any address, just leave it 0.0.0.0
-//
-      return Ipv4Address::GetAny ();
-    }
+  return m_ipv4->GetSourceAddress (destination);
 }
 
 uint16_t 
--- a/src/internet-stack/ipv4-impl.h	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/ipv4-impl.h	Sun Apr 12 22:13:49 2009 -0700
@@ -91,10 +91,6 @@
   Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
   uint32_t GetNAddresses (uint32_t interface) const;
 
-  virtual void SetAddress (uint32_t i, Ipv4Address address);
-  virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask);
-  virtual Ipv4Mask GetNetworkMask (uint32_t t) const;
-  virtual Ipv4Address GetAddress (uint32_t i) const;
   virtual void SetMetric (uint32_t i, uint16_t metric);
   virtual uint16_t GetMetric (uint32_t i) const;
   virtual Ipv4Address GetSourceAddress (Ipv4Address destination) const;
--- a/src/internet-stack/ipv4-interface.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/ipv4-interface.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -62,37 +62,6 @@
   Object::DoDispose ();
 }
 
-void 
-Ipv4Interface::SetAddress (Ipv4Address a)
-{
-  NS_LOG_FUNCTION (this << a);
-  m_address = a;
-}
-
-void 
-Ipv4Interface::SetNetworkMask (Ipv4Mask mask)
-{
-  NS_LOG_FUNCTION (this << mask);
-  m_netmask = mask;
-}
-
-Ipv4Address
-Ipv4Interface::GetBroadcast (void) const
-{
-  NS_LOG_FUNCTION_NOARGS ();
-  uint32_t mask = m_netmask.Get ();
-  uint32_t address = m_address.Get ();
-  Ipv4Address broadcast = Ipv4Address (address | (~mask));
-  return broadcast;
-}
-
-Ipv4Mask 
-Ipv4Interface::GetNetworkMask (void) const
-{
-  NS_LOG_FUNCTION_NOARGS ();
-  return m_netmask;
-}
-
 void
 Ipv4Interface::SetMetric (uint16_t metric)
 {
@@ -107,13 +76,6 @@
   return m_metric;
 }
 
-Ipv4Address 
-Ipv4Interface::GetAddress (void) const
-{
-  NS_LOG_FUNCTION_NOARGS ();
-  return m_address;
-}
-
 uint16_t 
 Ipv4Interface::GetMtu (void) const
 {
--- a/src/internet-stack/ipv4-interface.h	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/ipv4-interface.h	Sun Apr 12 22:13:49 2009 -0700
@@ -76,23 +76,6 @@
   virtual Ptr<NetDevice> GetDevice (void) const = 0;
 
   /**
-   * \param a set the ipv4 address of this interface.
-   */
-  void SetAddress (Ipv4Address a);
-  /**
-   * \param mask set the ipv4 netmask of this interface.
-   */
-  void SetNetworkMask (Ipv4Mask mask);
-
-  /**
-   * \returns the broadcast ipv4 address associated to this interface
-   */
-  Ipv4Address GetBroadcast (void) const;
-  /**
-   * \returns the ipv4 netmask of this interface
-   */
-  Ipv4Mask GetNetworkMask (void) const;
-  /**
    * \param metric configured routing metric (cost) of this interface
    */
   void SetMetric (uint16_t metric);
@@ -100,10 +83,6 @@
    * \returns configured routing metric (cost) of this interface
    */
   uint16_t GetMetric (void) const;
-  /**
-   * \returns the ipv4 address of this interface
-   */
-  Ipv4Address GetAddress (void) const;
 
   /**
    * This function a pass-through to NetDevice GetMtu, modulo
@@ -170,8 +149,6 @@
 private:
   virtual void SendTo (Ptr<Packet> p, Ipv4Address dest) = 0;
   bool m_ifup;
-  Ipv4Address m_address;
-  Ipv4Mask m_netmask;
   uint16_t m_metric;
 
   typedef std::list<Ipv4InterfaceAddress> Ipv4InterfaceAddressList;
--- a/src/internet-stack/ipv4-l3-protocol.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/ipv4-l3-protocol.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -175,8 +175,8 @@
 
   Ptr<Ipv4LoopbackInterface> interface = CreateObject<Ipv4LoopbackInterface> ();
   interface->SetNode (m_node);
-  interface->SetAddress (Ipv4Address::GetLoopback ());
-  interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
+  Ipv4InterfaceAddress ifaceAddr = Ipv4InterfaceAddress (Ipv4Address::GetLoopback (), Ipv4Mask::GetLoopback ());
+  interface->AddAddress (ifaceAddr);
   uint32_t index = AddIpv4Interface (interface);
   AddHostRouteTo (Ipv4Address::GetLoopback (), index);
   interface->SetUp ();
@@ -437,9 +437,12 @@
        i != m_interfaces.end (); 
        i++, interface++)
     {
-      if ((*i)->GetAddress () == addr)
+      for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++) 
         {
-          return interface;
+          if ((*i)->GetAddress (j).GetLocal () == addr)
+            {
+              return interface;
+            }
         }
     }
 
@@ -458,9 +461,12 @@
        i != m_interfaces.end (); 
        i++, interface++)
     {
-      if ((*i)->GetAddress ().CombineMask (mask) == addr.CombineMask (mask))
+      for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
         {
-          return interface;
+          if ((*i)->GetAddress (j).GetLocal ().CombineMask (mask) == addr.CombineMask (mask))
+            {
+              return interface;
+            }
         }
     }
 
@@ -642,11 +648,15 @@
            ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
         {
           Ptr<Ipv4Interface> outInterface = *ifaceIter;
-          if (destination.IsSubnetDirectedBroadcast (
-                outInterface->GetNetworkMask ()))
-          {
-            ipHeader.SetTtl (1);
-          }
+          // XXX this logic might not be completely correct for multi-addressed interface
+          for (uint32_t j = 0; j < outInterface->GetNAddresses(); j++)
+            {
+              if (destination.IsSubnetDirectedBroadcast (
+                outInterface->GetAddress (j).GetMask ()))
+                {
+                  ipHeader.SetTtl (1);
+                }
+            }
         }
     }
   if (destination.IsBroadcast ())
@@ -659,9 +669,10 @@
           Ptr<Packet> packetCopy = packet->Copy ();
 
           packetCopy->AddHeader (ipHeader);
+          // XXX Handle multiple address on interface
           if (packetCopy->GetSize () > outInterface->GetMtu () &&
               ipHeader.IsDontFragment () &&
-              IsUnicast (ipHeader.GetDestination (), outInterface->GetNetworkMask ()))
+              IsUnicast (ipHeader.GetDestination (), outInterface->GetAddress (0).GetMask ()))
             {
               Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
               NS_ASSERT (icmp != 0);
@@ -723,9 +734,10 @@
   NS_LOG_LOGIC ("Send via interface " << route.GetInterface ());
 
   Ptr<Ipv4Interface> outInterface = GetInterface (route.GetInterface ());
+  // XXX handle multiple address on interface
   if (packet->GetSize () > outInterface->GetMtu () &&
       ipHeader.IsDontFragment () &&
-      IsUnicast (ipHeader.GetDestination (), outInterface->GetNetworkMask ()))
+      IsUnicast (ipHeader.GetDestination (), outInterface->GetAddress (0).GetMask ()))
     {
       NS_LOG_LOGIC ("Too big: need fragmentation but not allowed");
       Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
@@ -788,10 +800,13 @@
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
        i != m_interfaces.end (); i++) 
     {
-      if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ())) 
+      for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
         {
-          NS_LOG_LOGIC ("For me (destination match)");
-          return false;
+          if ((*i)->GetAddress (j).GetLocal ().IsEqual (ipHeader.GetDestination ())) 
+            {
+              NS_LOG_LOGIC ("For me (destination match)");
+              return false;
+            }
         }
     }
   
@@ -801,7 +816,8 @@
       Ptr<Ipv4Interface> interface = *i;
       if (interface->GetDevice () == device)
 	{
-	  if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) 
+          // XXX multi-address case
+	  if (ipHeader.GetDestination ().IsEqual (interface->GetAddress (0).GetBroadcast ())) 
 	    {
               NS_LOG_LOGIC ("For me (interface broadcast address)");
 	      return false;
@@ -852,9 +868,10 @@
   NS_LOG_FUNCTION (this << interface << packet << ipHeader);
 
   ipHeader.SetTtl (ipHeader.GetTtl () - 1);
+  // XXX handle multi-interfaces
   if (ipHeader.GetTtl () == 0)
     {
-      if (IsUnicast (ipHeader.GetDestination (), GetInterface (interface)->GetNetworkMask ()))
+      if (IsUnicast (ipHeader.GetDestination (), GetInterface (interface)->GetAddress (0).GetMask ()))
         {
           Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
           icmp->SendTimeExceededTtl (ipHeader, packet);
@@ -889,7 +906,8 @@
       case Ipv4L4Protocol::RX_CSUM_FAILED:
         break;
       case Ipv4L4Protocol::RX_ENDPOINT_UNREACH:
-        if (IsUnicast (ip.GetDestination (), incomingInterface->GetNetworkMask ()))
+        // XXX handle multi-interface case
+        if (IsUnicast (ip.GetDestination (), incomingInterface->GetAddress (0).GetMask ()))
           {
             GetIcmp ()->SendDestUnreachPort (ip, copy);
           }
@@ -948,38 +966,6 @@
 }
 
 void 
-Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address)
-{
-  NS_LOG_FUNCTION (this << i << address);
-  Ptr<Ipv4Interface> interface = GetInterface (i);
-  interface->SetAddress (address);
-}
-
-void 
-Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask)
-{
-  NS_LOG_FUNCTION (this << i << mask);
-  Ptr<Ipv4Interface> interface = GetInterface (i);
-  interface->SetNetworkMask (mask);
-}
-
-Ipv4Mask 
-Ipv4L3Protocol::GetNetworkMask (uint32_t i) const
-{
-  NS_LOG_FUNCTION (this << i);
-  Ptr<Ipv4Interface> interface = GetInterface (i);
-  return interface->GetNetworkMask ();
-}
-
-Ipv4Address 
-Ipv4L3Protocol::GetAddress (uint32_t i) const
-{
-  NS_LOG_FUNCTION (this << i);
-  Ptr<Ipv4Interface> interface = GetInterface (i);
-  return interface->GetAddress ();
-}
-
-void 
 Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric)
 {
   NS_LOG_FUNCTION (i << metric);
@@ -1091,11 +1077,13 @@
   // If interface address and network mask have been set, add a route
   // to the network of the interface (like e.g. ifconfig does on a
   // Linux box)
-  if (((interface->GetAddress ()) != (Ipv4Address ()))
-      && (interface->GetNetworkMask ()) != (Ipv4Mask ()))
+  for (uint32_t j = 0; j < interface->GetNAddresses (); j++)
     {
-      AddNetworkRouteTo (interface->GetAddress ().CombineMask (interface->GetNetworkMask ()),
-                         interface->GetNetworkMask (), i);
+      if (((interface->GetAddress (j).GetLocal ()) != (Ipv4Address ()))
+          && (interface->GetAddress (j).GetMask ()) != (Ipv4Mask ()))
+        {
+          AddNetworkRouteTo (interface->GetAddress (j).GetLocal ().CombineMask (interface->GetAddress (j).GetMask ()), interface->GetAddress (j).GetMask (), i);
+        }
     }
 }
 
@@ -1124,4 +1112,36 @@
     }
 }
 
+// Note:  This method will be removed in Ipv4 routing work
+Ipv4Address
+Ipv4L3Protocol::GetSourceAddress (Ipv4Address destination) const
+{
+  uint32_t interface = 0xffffffff;
+
+  bool result = GetInterfaceForDestination (destination, interface);
+
+  if (result)
+    {
+      // if multiple addresses exist, search for the first one on the same subnet
+      for (uint32_t i = 0; i < GetNAddresses (interface); i++)
+        {
+          Ipv4InterfaceAddress ipv4InAddr = GetAddress (interface, i);
+          if (ipv4InAddr.GetLocal().CombineMask(ipv4InAddr.GetMask ()) == destination.CombineMask (ipv4InAddr.GetMask ()))
+            {
+              return ipv4InAddr.GetLocal ();
+            }
+        }
+      // Destination is off-link, so return first address.
+      return GetAddress (interface, 0).GetLocal ();
+    }
+  else
+    {
+//
+// If we can't find any address, just leave it 0.0.0.0
+//
+      return Ipv4Address::GetAny ();
+    }
+}
+
+
 }//namespace ns3
--- a/src/internet-stack/ipv4-l3-protocol.h	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/ipv4-l3-protocol.h	Sun Apr 12 22:13:49 2009 -0700
@@ -191,12 +191,9 @@
   Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
   uint32_t GetNAddresses (uint32_t interface) const;
 
-  void SetAddress (uint32_t i, Ipv4Address address);
-  void SetNetworkMask (uint32_t i, Ipv4Mask mask);
-  Ipv4Mask GetNetworkMask (uint32_t t) const;
-  Ipv4Address GetAddress (uint32_t i) const;
   void SetMetric (uint32_t i, uint16_t metric);
   uint16_t GetMetric (uint32_t i) const;
+  Ipv4Address GetSourceAddress (Ipv4Address destination) const;
   bool GetInterfaceForDestination (Ipv4Address destination, 
                                  uint32_t& interface) const;
   uint16_t GetMtu (uint32_t i) const;
--- a/src/internet-stack/ipv4-raw-socket-impl.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/ipv4-raw-socket-impl.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -173,7 +173,7 @@
   uint32_t localInterface;
   if (ipv4->GetInterfaceForDestination(dst, localInterface))
     {
-      ipv4->Send (p, ipv4->GetAddress (localInterface), dst, m_protocol);
+      ipv4->Send (p, ipv4->GetSourceAddress (dst), dst, m_protocol);
     }
   else
     {
--- a/src/internet-stack/nsc-tcp-l4-protocol.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/nsc-tcp-l4-protocol.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -344,8 +344,9 @@
   // how things _should_ be (once nsc can deal with multiple interfaces...)
   for (uint32_t i = 1; i < nInterfaces; i++)
     {
-      Ipv4Address addr = ip->GetAddress(i);
-      Ipv4Mask mask = ip->GetNetworkMask(i);
+      Ipv4InterfaceAddress ifAddr = ip->GetAddress (i, 0);
+      Ipv4Address addr = ifAddr.GetLocal ();
+      Ipv4Mask mask = ifAddr.GetMask ();
       uint16_t mtu = ip->GetMtu (i);
 
       std::ostringstream addrOss, maskOss;
--- a/src/internet-stack/tcp-socket-impl.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/tcp-socket-impl.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -345,7 +345,7 @@
 
   if (ipv4->GetInterfaceForDestination (m_remoteAddress, localInterface))
     {
-      m_endPoint->SetLocalAddress (ipv4->GetAddress (localInterface));
+      m_endPoint->SetLocalAddress (ipv4->GetSourceAddress (m_remoteAddress));
     }
   else
     {
@@ -832,7 +832,7 @@
       m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
       if (ipv4->GetInterfaceForDestination (m_remoteAddress, localInterface))
         {
-          m_localAddress = ipv4->GetAddress (localInterface);
+          m_localAddress = ipv4->GetSourceAddress (m_remoteAddress);
           m_endPoint->SetLocalAddress (m_localAddress);
           // Leave local addr in the portmap to any, as the path from
           // remote can change and packets can arrive on different interfaces
@@ -1930,8 +1930,8 @@
   node->AddDevice (dev);
   Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
   uint32_t ndid = ipv4->AddInterface (dev);
-  ipv4->SetAddress (ndid, Ipv4Address (ipaddr));
-  ipv4->SetNetworkMask (ndid, Ipv4Mask (netmask));
+  Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address (ipaddr), Ipv4Mask (netmask));
+  ipv4->AddAddress (ndid, ipv4Addr);
   ipv4->SetUp (ndid);
   return dev;
 }
--- a/src/internet-stack/udp-socket-impl.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/internet-stack/udp-socket-impl.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -362,8 +362,10 @@
       NS_LOG_LOGIC ("Limited broadcast start.");
       for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
         {
-          Ipv4Address addri = ipv4->GetAddress (i);
-          Ipv4Mask maski = ipv4->GetNetworkMask (i);
+          // Get the primary address
+          Ipv4InterfaceAddress iaddr = ipv4->GetAddress (i, 0);
+          Ipv4Address addri = iaddr.GetLocal ();
+          Ipv4Mask maski = iaddr.GetMask ();
           if (maski == Ipv4Mask::GetOnes ())
             {
               // if the network mask is 255.255.255.255, do not convert dest
@@ -392,7 +394,7 @@
   else if (ipv4->GetInterfaceForDestination(dest, localInterface))
     {
       NS_LOG_LOGIC ("Route exists");
-      m_udp->Send (p->Copy (), ipv4->GetAddress (localInterface), dest,
+      m_udp->Send (p->Copy (), ipv4->GetSourceAddress (dest), dest,
 		   m_endPoint->GetLocalPort (), port);
       NotifyDataSent (p->GetSize ());
       NotifySend (GetTxAvailable ());
@@ -666,8 +668,8 @@
     rxNode->AddDevice (rxDev1);
     Ptr<Ipv4> ipv4 = rxNode->GetObject<Ipv4> ();
     uint32_t netdev_idx = ipv4->AddInterface (rxDev1);
-    ipv4->SetAddress (netdev_idx, Ipv4Address ("10.0.0.1"));
-    ipv4->SetNetworkMask (netdev_idx, Ipv4Mask (0xffff0000U));
+    Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.1"), Ipv4Mask (0xffff0000U));
+    ipv4->AddAddress (netdev_idx, ipv4Addr);
     ipv4->SetUp (netdev_idx);
   }
 
@@ -677,8 +679,8 @@
     rxNode->AddDevice (rxDev2);
     Ptr<Ipv4> ipv4 = rxNode->GetObject<Ipv4> ();
     uint32_t netdev_idx = ipv4->AddInterface (rxDev2);
-    ipv4->SetAddress (netdev_idx, Ipv4Address ("10.0.1.1"));
-    ipv4->SetNetworkMask (netdev_idx, Ipv4Mask (0xffff0000U));
+    Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.1"), Ipv4Mask (0xffff0000U));
+    ipv4->AddAddress (netdev_idx, ipv4Addr);
     ipv4->SetUp (netdev_idx);
   }
   
@@ -692,8 +694,8 @@
     txNode->AddDevice (txDev1);
     Ptr<Ipv4> ipv4 = txNode->GetObject<Ipv4> ();
     uint32_t netdev_idx = ipv4->AddInterface (txDev1);
-    ipv4->SetAddress (netdev_idx, Ipv4Address ("10.0.0.2"));
-    ipv4->SetNetworkMask (netdev_idx, Ipv4Mask (0xffff0000U));
+    Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.2"), Ipv4Mask (0xffff0000U));
+    ipv4->AddAddress (netdev_idx, ipv4Addr);
     ipv4->SetUp (netdev_idx);
   }
   Ptr<SimpleNetDevice> txDev2;
@@ -703,8 +705,8 @@
     txNode->AddDevice (txDev2);
     Ptr<Ipv4> ipv4 = txNode->GetObject<Ipv4> ();
     uint32_t netdev_idx = ipv4->AddInterface (txDev2);
-    ipv4->SetAddress (netdev_idx, Ipv4Address ("10.0.1.2"));
-    ipv4->SetNetworkMask (netdev_idx, Ipv4Mask (0xffff0000U));
+    Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.2"), Ipv4Mask (0xffff0000U));
+    ipv4->AddAddress (netdev_idx, ipv4Addr);
     ipv4->SetUp (netdev_idx);
   }
 
--- a/src/node/ipv4.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/node/ipv4.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -45,9 +45,13 @@
 {
   for (uint32_t i = 0; i < GetNInterfaces (); i++)
     {
-      if (GetAddress (i).CombineMask(mask) == addr.CombineMask(mask) )
+      for (uint32_t j = 0; j < GetNAddresses (i); j++)
         {
-          return i;
+          Ipv4InterfaceAddress ipv4InAddr = GetAddress (i, j);
+          if (ipv4InAddr.GetLocal ().CombineMask(mask) == addr.CombineMask(mask) )
+            {
+              return i;
+            }
         }
     }
   // Mapping not found
--- a/src/node/ipv4.h	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/node/ipv4.h	Sun Apr 12 22:13:49 2009 -0700
@@ -413,24 +413,6 @@
 
   /**
    * \param i index of ipv4 interface
-   * \param address address to associate to the underlying ipv4 interface
-   */
-  virtual void SetAddress (uint32_t i, Ipv4Address address) = 0;
-
-  /**
-   * \param i index of ipv4 interface
-   * \param mask mask to associate to the underlying ipv4 interface
-   */
-  virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask) = 0;
-
-  /**
-   * \param i index of ipv4 interface
-   * \returns the mask associated to the underlying ipv4 interface
-   */
-  virtual Ipv4Mask GetNetworkMask (uint32_t i) const = 0;
-
-  /**
-   * \param i index of ipv4 interface
    * \param metric routing metric (cost) associated to the underlying 
    *          ipv4 interface
    */
@@ -444,17 +426,6 @@
   virtual uint16_t GetMetric (uint32_t i) const = 0;
 
   /**
-   * \param i index of ipv4 interface
-   * \returns the address associated to the underlying ipv4 interface
-   *
-   * Note that the broadcast address for this interface may be fetched
-   * from the Ipv4Address object returned here using
-   * Ipv4Address::GetSubnetDirectedBroadcast(mask), where the mask for
-   * the interface may be retrived using Ipv4::GetNetworkMask(i).
-   */
-  virtual Ipv4Address GetAddress (uint32_t i) const = 0;
-
-  /**
    * \param destination The IP address of a hypothetical destination.
    * \returns The IP address assigned to the interface that will be used
    * if we were to send a packet to destination.
--- a/src/routing/global-routing/global-router-interface.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/routing/global-routing/global-router-interface.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -704,8 +704,12 @@
   Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
   NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
 
-  Ipv4Address addrLocal = ipv4Local->GetAddress(interfaceLocal);
-  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(interfaceLocal);
+  if (ipv4Local->GetNAddresses (interfaceLocal) > 1)
+    {
+      NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
+    }
+  Ipv4Address addrLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetLocal ();
+  Ipv4Mask maskLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetMask ();
   NS_LOG_LOGIC ("Working with local address " << addrLocal);
   uint16_t metricLocal = ipv4Local->GetMetric (interfaceLocal);
 
@@ -820,8 +824,12 @@
   Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
   NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
 
-  Ipv4Address addrLocal = ipv4Local->GetAddress(interfaceLocal);
-  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(interfaceLocal);
+  if (ipv4Local->GetNAddresses (interfaceLocal) > 1)
+    {
+      NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
+    }
+  Ipv4Address addrLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetLocal ();
+  Ipv4Mask maskLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetMask ();;
   NS_LOG_LOGIC ("Working with local address " << addrLocal);
   uint16_t metricLocal = ipv4Local->GetMetric (interfaceLocal);
 
@@ -962,8 +970,12 @@
   Ptr<Ipv4> ipv4Local = nodeLocal->GetObject<Ipv4> ();
   NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
 
-  Ipv4Address addrLocal = ipv4Local->GetAddress(interfaceLocal);
-  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(interfaceLocal);
+  if (ipv4Local->GetNAddresses (interfaceLocal) > 1)
+    {
+      NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
+    }
+  Ipv4Address addrLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetLocal ();
+  Ipv4Mask maskLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetMask ();
   NS_LOG_LOGIC ("Working with local address " << addrLocal);
   uint16_t metricLocal = ipv4Local->GetMetric (interfaceLocal);
 
@@ -1018,8 +1030,12 @@
   // Now that we have the Ipv4 interface, we can get the (remote) address and
   // mask we need.
   //
-  Ipv4Address addrRemote = ipv4Remote->GetAddress(interfaceRemote);
-  Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(interfaceRemote);
+  if (ipv4Remote->GetNAddresses (interfaceRemote) > 1)
+    {
+      NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
+    }
+  Ipv4Address addrRemote = ipv4Remote->GetAddress (interfaceRemote, 0).GetLocal ();
+  Ipv4Mask maskRemote = ipv4Remote->GetAddress (interfaceRemote, 0).GetMask ();
   NS_LOG_LOGIC ("Working with remote address " << addrRemote);
 
   //
@@ -1076,8 +1092,12 @@
       Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
       NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
 
-      Ipv4Address addrLocal = ipv4Local->GetAddress(interfaceLocal);
-      Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(interfaceLocal);
+      if (ipv4Local->GetNAddresses (interfaceLocal) > 1)
+        {
+          NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
+        }
+      Ipv4Address addrLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetLocal ();
+      Ipv4Mask maskLocal = ipv4Local->GetAddress (interfaceLocal, 0).GetMask ();
 
       GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
       NS_ABORT_MSG_IF (pLSA == 0, "GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
@@ -1128,7 +1148,11 @@
                 }
               else 
                 {
-                  Ipv4Address tempAddr = tempIpv4->GetAddress(tempInterface);
+                  if (tempIpv4->GetNAddresses (tempInterface) > 1)
+                    {
+                      NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
+                    }
+                  Ipv4Address tempAddr = tempIpv4->GetAddress(tempInterface, 0).GetLocal ();
                   pLSA->AddAttachedRouter (tempAddr);
                 }
             }
@@ -1206,7 +1230,11 @@
                       NS_LOG_LOGIC ("Remote side interface " << interfaceOther << " not up");
                       continue;
                     }
-                  Ipv4Address addrOther = ipv4->GetAddress (interfaceOther);
+                  if (ipv4->GetNAddresses (interfaceOther) > 1)
+                    {
+                      NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
+                    }
+                  Ipv4Address addrOther = ipv4->GetAddress (interfaceOther, 0).GetLocal ();
                   desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
                   NS_LOG_LOGIC ("designated router now " << desigRtr);
                 }
@@ -1255,7 +1283,11 @@
                       continue;
                     }
                   NS_LOG_LOGIC ("Found router on net device " << ndOther);
-                  Ipv4Address addrOther = ipv4->GetAddress (interfaceOther);
+                  if (ipv4->GetNAddresses (interfaceOther) > 1)
+                    {
+                      NS_LOG_WARN ("Warning, interface has multiple IP addresses; using only the primary one");
+                    }
+                  Ipv4Address addrOther = ipv4->GetAddress (interfaceOther, 0).GetLocal ();
                   desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
                   NS_LOG_LOGIC ("designated router now " << desigRtr);
                 }
--- a/src/routing/olsr/olsr-agent-impl.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/routing/olsr/olsr-agent-impl.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -237,7 +237,8 @@
       Ipv4Address loopback ("127.0.0.1");
       for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
         {
-          Ipv4Address addr = m_ipv4->GetAddress (i);
+          // Use primary address, if multiple
+          Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
           if (addr != loopback)
             {
               m_mainAddress = addr;
@@ -260,7 +261,7 @@
   Ipv4Address loopback ("127.0.0.1");
   for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
     {
-      Ipv4Address addr = m_ipv4->GetAddress (i);
+      Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
       if (addr == loopback)
         continue;
 
@@ -297,7 +298,7 @@
 
 void AgentImpl::SetMainInterface (uint32_t interface)
 {
-  m_mainAddress = m_ipv4->GetAddress (interface);
+  m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
 }
 
 
@@ -1556,7 +1557,7 @@
   Ipv4Address loopback ("127.0.0.1");
   for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
     {
-      Ipv4Address addr = m_ipv4->GetAddress (i);
+      Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
       if (addr != m_mainAddress && addr != loopback)
         mid.interfaceAddresses.push_back (addr);
     }
--- a/src/routing/olsr/olsr-routing-table.cc	Wed Apr 08 22:32:44 2009 -0700
+++ b/src/routing/olsr/olsr-routing-table.cc	Sun Apr 12 22:13:49 2009 -0700
@@ -210,10 +210,13 @@
   RoutingTableEntry entry;
   for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
     {
-      if (m_ipv4->GetAddress (i) == interfaceAddress)
+      for (uint32_t j = 0; j < m_ipv4->GetNAddresses (i); j++)
         {
-          AddEntry (dest, next, i, distance);
-          return;
+          if (m_ipv4->GetAddress (i,j).GetLocal () == interfaceAddress)
+            {
+              AddEntry (dest, next, i, distance);
+              return;
+            }
         }
     }
   NS_ASSERT (false); // should not be reached