LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 #include <netinet/in.h> | 2 #include <netinet/in.h> |
3 #include <sys/socket.h> | 3 #include <sys/socket.h> |
4 #include <sys/types.h> | 4 #include <sys/types.h> |
5 #include "ipv4-raw-socket-impl.h" | 5 #include "ipv4-raw-socket-impl.h" |
6 #include "ipv4-l3-protocol.h" | 6 #include "ipv4-l3-protocol.h" |
7 #include "icmpv4.h" | 7 #include "icmpv4.h" |
8 #include "ns3/ipv4-packet-info-tag.h" | 8 #include "ns3/ipv4-packet-info-tag.h" |
9 #include "ns3/inet-socket-address.h" | 9 #include "ns3/inet-socket-address.h" |
10 #include "ns3/node.h" | 10 #include "ns3/node.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 { | 276 { |
277 NS_LOG_DEBUG ("dropped because no outgoing route."); | 277 NS_LOG_DEBUG ("dropped because no outgoing route."); |
278 return -1; | 278 return -1; |
279 } | 279 } |
280 | 280 |
281 Ipv4Header header; | 281 Ipv4Header header; |
282 uint32_t pktSize = p->GetSize (); | 282 uint32_t pktSize = p->GetSize (); |
283 if (!m_iphdrincl) | 283 if (!m_iphdrincl) |
284 { | 284 { |
285 header.SetDestination (dst); | 285 header.SetDestination (dst); |
286 header.SetProtocol (static_cast<uint8_t>(m_protocol)); | 286 header.SetProtocol (static_cast<uint8_t> (m_protocol)); |
287 Ptr<Ipv4Route> route = Create <Ipv4Route> (); | 287 Ptr<Ipv4Route> route = Create <Ipv4Route> (); |
288 route->SetSource (src); | 288 route->SetSource (src); |
289 route->SetDestination (dst); | 289 route->SetDestination (dst); |
290 route->SetOutputDevice (boundNetDevice); | 290 route->SetOutputDevice (boundNetDevice); |
291 ipv4->Send (p, route->GetSource (), dst, static_cast<uint8_t>(m_protoc
ol), route); | 291 ipv4->Send (p, route->GetSource (), dst, static_cast<uint8_t> (m_proto
col), route); |
292 } | 292 } |
293 else | 293 else |
294 { | 294 { |
295 p->RemoveHeader (header); | 295 p->RemoveHeader (header); |
296 dst = header.GetDestination (); | 296 dst = header.GetDestination (); |
297 src = header.GetSource (); | 297 src = header.GetSource (); |
298 pktSize += header.GetSerializedSize (); | 298 pktSize += header.GetSerializedSize (); |
299 Ptr<Ipv4Route> route = Create <Ipv4Route> (); | 299 Ptr<Ipv4Route> route = Create <Ipv4Route> (); |
300 route->SetSource (src); | 300 route->SetSource (src); |
301 route->SetDestination (dst); | 301 route->SetDestination (dst); |
302 route->SetOutputDevice (boundNetDevice); | 302 route->SetOutputDevice (boundNetDevice); |
303 ipv4->SendWithHeader (p, header, route); | 303 ipv4->SendWithHeader (p, header, route); |
304 } | 304 } |
305 NotifyDataSent (pktSize); | 305 NotifyDataSent (pktSize); |
306 NotifySend (GetTxAvailable ()); | 306 NotifySend (GetTxAvailable ()); |
307 return pktSize; | 307 return pktSize; |
308 } | 308 } |
309 | 309 |
310 | 310 |
311 if (ipv4->GetRoutingProtocol ()) | 311 if (ipv4->GetRoutingProtocol ()) |
312 { | 312 { |
313 Ipv4Header header; | 313 Ipv4Header header; |
314 if (!m_iphdrincl) | 314 if (!m_iphdrincl) |
315 { | 315 { |
316 header.SetDestination (dst); | 316 header.SetDestination (dst); |
317 header.SetProtocol (static_cast<uint8_t>(m_protocol)); | 317 header.SetProtocol (static_cast<uint8_t> (m_protocol)); |
318 } | 318 } |
319 else | 319 else |
320 { | 320 { |
321 p->RemoveHeader (header); | 321 p->RemoveHeader (header); |
322 dst = header.GetDestination (); | 322 dst = header.GetDestination (); |
323 src = header.GetSource (); | 323 src = header.GetSource (); |
324 } | 324 } |
325 SocketErrno errno_ = ERROR_NOTERROR; //do not use errno as it is the stand
ard C last error number | 325 SocketErrno errno_ = ERROR_NOTERROR; //do not use errno as it is the stand
ard C last error number |
326 Ptr<Ipv4Route> route; | 326 Ptr<Ipv4Route> route; |
327 Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a so
urce address | 327 Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a so
urce address |
328 if (!oif && src != Ipv4Address::GetAny ()) | 328 if (!oif && src != Ipv4Address::GetAny ()) |
329 { | 329 { |
330 int32_t index = ipv4->GetInterfaceForAddress (src); | 330 int32_t index = ipv4->GetInterfaceForAddress (src); |
331 NS_ASSERT (index >= 0); | 331 NS_ASSERT (index >= 0); |
332 oif = ipv4->GetNetDevice (index); | 332 oif = ipv4->GetNetDevice (index); |
333 NS_LOG_LOGIC ("Set index " << oif << "from source " << src); | 333 NS_LOG_LOGIC ("Set index " << oif << "from source " << src); |
334 } | 334 } |
335 | 335 |
336 // TBD-- we could cache the route and just check its validity | 336 // TBD-- we could cache the route and just check its validity |
337 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_); | 337 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_); |
338 if (route != 0) | 338 if (route != 0) |
339 { | 339 { |
340 NS_LOG_LOGIC ("Route exists"); | 340 NS_LOG_LOGIC ("Route exists"); |
341 uint32_t pktSize = p->GetSize (); | 341 uint32_t pktSize = p->GetSize (); |
342 if (!m_iphdrincl) | 342 if (!m_iphdrincl) |
343 { | 343 { |
344 ipv4->Send (p, route->GetSource (), dst, static_cast<uint8_t>(m_pr
otocol), route); | 344 ipv4->Send (p, route->GetSource (), dst, static_cast<uint8_t> (m_p
rotocol), route); |
345 } | 345 } |
346 else | 346 else |
347 { | 347 { |
348 pktSize += header.GetSerializedSize (); | 348 pktSize += header.GetSerializedSize (); |
349 ipv4->SendWithHeader (p, header, route); | 349 ipv4->SendWithHeader (p, header, route); |
350 } | 350 } |
351 NotifyDataSent (pktSize); | 351 NotifyDataSent (pktSize); |
352 NotifySend (GetTxAvailable ()); | 352 NotifySend (GetTxAvailable ()); |
353 return pktSize; | 353 return pktSize; |
354 } | 354 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 495 } |
496 | 496 |
497 bool | 497 bool |
498 Ipv4RawSocketImpl::GetAllowBroadcast () const | 498 Ipv4RawSocketImpl::GetAllowBroadcast () const |
499 { | 499 { |
500 NS_LOG_FUNCTION (this); | 500 NS_LOG_FUNCTION (this); |
501 return true; | 501 return true; |
502 } | 502 } |
503 | 503 |
504 } // namespace ns3 | 504 } // namespace ns3 |
LEFT | RIGHT |