View | Details | Raw Unified | Return to bug 400
Collapse All | Expand All

(-)a/src/internet-stack/ipv4-l3-protocol.cc (+1 lines)
 Lines 852-857   Ipv4L3Protocol::DoForward (uint32_t ifIn Link Here 
852
          Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
852
          Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
853
          icmp->SendTimeExceededTtl (ipHeader, packet);
853
          icmp->SendTimeExceededTtl (ipHeader, packet);
854
        }
854
        }
855
      NS_LOG_WARN ("TTL exceeded.  Drop.");
855
      m_dropTrace (packet);
856
      m_dropTrace (packet);
856
      return;
857
      return;
857
    }  
858
    }  
(-)a/src/internet-stack/udp-socket-impl.cc (-9 / +28 lines)
 Lines 349-356   UdpSocketImpl::DoSendTo (Ptr<Packet> p, Link Here 
349
      }
349
      }
350
  }
350
  }
351
  //
351
  //
352
  // If dest is sent to the limited broadcast address (all ones),
352
  // If dest is set to the limited broadcast address (all ones),
353
  // convert it to send a copy of the packet out of every interface
353
  // convert it to send a copy of the packet out of every 
354
  // interface as a subnet-directed broadcast.
355
  // Exception:  if the interface has a /32 address, there is no
356
  // valid subnet-directed broadcast, so send it as limited broadcast
357
  // Note also that some systems will only send limited broadcast packets
358
  // out of the "default" interface; here we send it out all interfaces
354
  //
359
  //
355
  if (dest.IsBroadcast ())
360
  if (dest.IsBroadcast ())
356
    {
361
    {
 Lines 359-371   UdpSocketImpl::DoSendTo (Ptr<Packet> p, Link Here 
359
        {
364
        {
360
          Ipv4Address addri = ipv4->GetAddress (i);
365
          Ipv4Address addri = ipv4->GetAddress (i);
361
          Ipv4Mask maski = ipv4->GetNetworkMask (i);
366
          Ipv4Mask maski = ipv4->GetNetworkMask (i);
362
          Ipv4Address bcast = addri.GetSubnetDirectedBroadcast (maski);
367
          if (maski == Ipv4Mask::GetOnes ())
363
          NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << bcast
368
            {
364
                        << " (mask is " << maski << ")");
369
              // if the network mask is 255.255.255.255, do not convert dest
365
          m_udp->Send (p->Copy (), addri, bcast,
370
              NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << dest
366
                       m_endPoint->GetLocalPort (), port);
371
                            << " (mask is " << maski << ")");
367
          NotifyDataSent (p->GetSize ());
372
              m_udp->Send (p->Copy (), addri, dest,
368
          NotifySend (GetTxAvailable ());
373
                           m_endPoint->GetLocalPort (), port);
374
              NotifyDataSent (p->GetSize ());
375
              NotifySend (GetTxAvailable ());
376
            }
377
          else
378
            {
379
              // Convert to subnet-directed broadcast
380
              Ipv4Address bcast = addri.GetSubnetDirectedBroadcast (maski);
381
              NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << bcast
382
                            << " (mask is " << maski << ")");
383
              m_udp->Send (p->Copy (), addri, bcast,
384
                           m_endPoint->GetLocalPort (), port);
385
              NotifyDataSent (p->GetSize ());
386
              NotifySend (GetTxAvailable ());
387
            }
369
        }
388
        }
370
      NS_LOG_LOGIC ("Limited broadcast end.");
389
      NS_LOG_LOGIC ("Limited broadcast end.");
371
      return p->GetSize();
390
      return p->GetSize();
(-)a/src/node/ipv4-address.cc (-1 / +16 lines)
 Lines 77-83   Ipv4Mask::IsEqual (Ipv4Mask other) const Link Here 
77
  }
77
  }
78
}
78
}
79
79
80
81
bool 
80
bool 
82
Ipv4Mask::IsMatch (Ipv4Address a, Ipv4Address b) const
81
Ipv4Mask::IsMatch (Ipv4Address a, Ipv4Address b) const
83
{
82
{
 Lines 125-130   Ipv4Mask::GetZero (void) Link Here 
125
{
124
{
126
  static Ipv4Mask zero = Ipv4Mask ("0.0.0.0");
125
  static Ipv4Mask zero = Ipv4Mask ("0.0.0.0");
127
  return zero;
126
  return zero;
127
}
128
Ipv4Mask
129
Ipv4Mask::GetOnes (void)
130
{
131
  static Ipv4Mask ones = Ipv4Mask ("255.255.255.255");
132
  return ones;
128
}
133
}
129
134
130
Ipv4Address::Ipv4Address ()
135
Ipv4Address::Ipv4Address ()
 Lines 164-175   Ipv4Address Link Here 
164
Ipv4Address 
169
Ipv4Address 
165
Ipv4Address::GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const
170
Ipv4Address::GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const
166
{
171
{
172
  if (mask == Ipv4Mask::GetOnes ())
173
    {
174
      NS_ASSERT_MSG (false, "Trying to get subnet-directed broadcast address with an all-ones netmask");
175
    }
167
  return Ipv4Address (Get () | mask.GetInverse ());
176
  return Ipv4Address (Get () | mask.GetInverse ());
168
}
177
}
169
178
170
bool
179
bool
171
Ipv4Address::IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const
180
Ipv4Address::IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const
172
{
181
{
182
  if (mask == Ipv4Mask::GetOnes ())
183
    {
184
      // If the mask is 255.255.255.255, there is no subnet directed
185
      // broadcast for this address.
186
      return false;
187
    }
173
  return ( (Get () | mask.GetInverse ()) == Get () );
188
  return ( (Get () | mask.GetInverse ()) == Get () );
174
}
189
}
175
190
(-)a/src/node/ipv4-address.h (-9 / +79 lines)
 Lines 91-97   public: Link Here 
91
  void Serialize (uint8_t buf[4]) const;
91
  void Serialize (uint8_t buf[4]) const;
92
  /**
92
  /**
93
   * \param buf buffer to read address from
93
   * \param buf buffer to read address from
94
   * \returns an Ipv4Address
94
   * \return an Ipv4Address
95
   * 
95
   * 
96
   * The input address is expected to be in network byte order format.
96
   * The input address is expected to be in network byte order format.
97
   */
97
   */
 Lines 103-110   public: Link Here 
103
   * \param os The output stream to which this Ipv4Address is printed
103
   * \param os The output stream to which this Ipv4Address is printed
104
   */
104
   */
105
  void Print (std::ostream &os) const;
105
  void Print (std::ostream &os) const;
106
106
  /**
107
    * \return true if address is 255.255.255.255; false otherwise
108
    */
107
  bool IsBroadcast (void) const;
109
  bool IsBroadcast (void) const;
110
  /**
111
    * \return true only if address is in the range 224.0.0.0 - 239.255.255.255
112
    */
108
  bool IsMulticast (void) const;
113
  bool IsMulticast (void) const;
109
  /**
114
  /**
110
   * \brief Combine this address with a network mask
115
   * \brief Combine this address with a network mask
 Lines 120-139   public: Link Here 
120
   * \brief Generate subnet-directed broadcast address corresponding to mask
125
   * \brief Generate subnet-directed broadcast address corresponding to mask
121
   *
126
   *
122
   * The subnet-directed broadcast address has the host bits set to all
127
   * The subnet-directed broadcast address has the host bits set to all
123
   * ones.
128
   * ones.  If this method is called with a mask of 255.255.255.255,
129
   * (i.e., the address is a /32 address), the program will assert, since
130
   * there is no subnet associated with a /32 address.
124
   *
131
   *
125
   * \param mask a network mask 
132
   * \param mask a network mask 
126
   */
133
   */
127
  Ipv4Address GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const;
134
  Ipv4Address GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const;
135
  /**
136
   * \brief Generate subnet-directed broadcast address corresponding to mask
137
   * 
138
   * The subnet-directed broadcast address has the host bits set to all
139
   * ones.  If this method is called with a mask of 255.255.255.255,
140
   * (i.e., the address is a /32 address), the program will assert, since
141
   * there is no subnet associated with a /32 address.
142
   *
143
   * \param mask a network mask 
144
   * \return true if the address, when combined with the input mask, has all
145
   * of its host bits set to one
146
   */
128
  bool IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const;
147
  bool IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const;
129
148
  /**
149
   * \param address an address to compare type with
150
   *
151
   * \return true if the type of the address stored internally
152
   * is compatible with the type of the input address, false otherwise.
153
   */
130
  static bool IsMatchingType (const Address &address);
154
  static bool IsMatchingType (const Address &address);
155
  /**
156
   * Convert an instance of this class to a polymorphic Address instance.
157
   *
158
   * \return a new Address instance
159
   */
131
  operator Address () const;
160
  operator Address () const;
161
  /**
162
   * \param address a polymorphic address
163
   * \return a new Ipv4Address from the polymorphic address
164
   *
165
   * This function performs a type check and asserts if the
166
   * type of the input address is not compatible with an
167
   * Ipv4Address.
168
   */
132
  static Ipv4Address ConvertFrom (const Address &address);
169
  static Ipv4Address ConvertFrom (const Address &address);
133
170
  /**
171
   * \return the 0.0.0.0 address
172
   */
134
  static Ipv4Address GetZero (void);
173
  static Ipv4Address GetZero (void);
174
  /**
175
   * \return the 0.0.0.0 address
176
   */
135
  static Ipv4Address GetAny (void);
177
  static Ipv4Address GetAny (void);
178
  /**
179
   * \return the 255.255.255.255 address
180
   */
136
  static Ipv4Address GetBroadcast (void);
181
  static Ipv4Address GetBroadcast (void);
182
  /**
183
   * \return the 127.0.0.1 address
184
   */
137
  static Ipv4Address GetLoopback (void);
185
  static Ipv4Address GetLoopback (void);
138
186
139
private:
187
private:
 Lines 156-164   public: Link Here 
156
  Ipv4Mask ();
204
  Ipv4Mask ();
157
  Ipv4Mask (uint32_t mask);
205
  Ipv4Mask (uint32_t mask);
158
  Ipv4Mask (char const *mask);
206
  Ipv4Mask (char const *mask);
159
207
  /**
208
   * \param a first address to compare
209
   * \param b second address to compare
210
   * \return true if both addresses are equal in their masked bits, 
211
   * corresponding to this mask
212
   */
160
  bool IsMatch (Ipv4Address a, Ipv4Address b) const;
213
  bool IsMatch (Ipv4Address a, Ipv4Address b) const;
161
214
  /**
215
   * \param other a mask to compare 
216
   * \return true if the mask equals the mask passed as input parameter
217
   */
162
  bool IsEqual (Ipv4Mask other) const;
218
  bool IsEqual (Ipv4Mask other) const;
163
  /** 
219
  /** 
164
   * Get the host-order 32-bit IP mask
220
   * Get the host-order 32-bit IP mask
 Lines 174-184   public: Link Here 
174
   * \brief Return the inverse mask in host order. 
230
   * \brief Return the inverse mask in host order. 
175
   */
231
   */
176
  uint32_t GetInverse (void) const;
232
  uint32_t GetInverse (void) const;
177
233
  /**
234
   * \brief Print this mask to the given output stream
235
   *
236
   * The print format is in the typical "255.255.255.0"
237
   * \param os The output stream to which this Ipv4Address is printed
238
   */
178
  void Print (std::ostream &os) const;
239
  void Print (std::ostream &os) const;
179
240
  /**
241
   * \return the 255.0.0.0 mask corresponding to a typical loopback address
242
   */
180
  static Ipv4Mask GetLoopback (void);
243
  static Ipv4Mask GetLoopback (void);
244
  /**
245
   * \return the 0.0.0.0 mask
246
   */
181
  static Ipv4Mask GetZero (void);
247
  static Ipv4Mask GetZero (void);
248
  /**
249
   * \return the 255.255.255.255 mask
250
   */
251
  static Ipv4Mask GetOnes (void);
182
252
183
private:
253
private:
184
  uint32_t m_mask;
254
  uint32_t m_mask;

Return to bug 400