OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2012 INRIA, 2012 University of Washington | 3 * Copyright (c) 2012 INRIA, 2012 University of Washington |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 401 |
402 // We need to remove the PI header and ignore it | 402 // We need to remove the PI header and ignore it |
403 if (m_encapMode == DIXPI) | 403 if (m_encapMode == DIXPI) |
404 { | 404 { |
405 RemovePIHeader (buf, len); | 405 RemovePIHeader (buf, len); |
406 } | 406 } |
407 | 407 |
408 // | 408 // |
409 // Create a packet out of the buffer we received and free that buffer. | 409 // Create a packet out of the buffer we received and free that buffer. |
410 // | 410 // |
411 Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf),
len); | 411 Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf),
static_cast<uint32_t> (len)); |
412 free (buf); | 412 free (buf); |
413 buf = 0; | 413 buf = 0; |
414 | 414 |
415 // | 415 // |
416 // Trace sinks will expect complete packets, not packets without some of the | 416 // Trace sinks will expect complete packets, not packets without some of the |
417 // headers | 417 // headers |
418 // | 418 // |
419 Ptr<Packet> originalPacket = packet->Copy (); | 419 Ptr<Packet> originalPacket = packet->Copy (); |
420 | 420 |
421 Mac48Address destination; | 421 Mac48Address destination; |
(...skipping 22 matching lines...) Expand all Loading... |
444 isBroadcast = header.GetDestination ().IsBroadcast (); | 444 isBroadcast = header.GetDestination ().IsBroadcast (); |
445 isMulticast = header.GetDestination ().IsGroup (); | 445 isMulticast = header.GetDestination ().IsGroup (); |
446 protocol = header.GetLengthType (); | 446 protocol = header.GetLengthType (); |
447 | 447 |
448 // | 448 // |
449 // If the length/type is less than 1500, it corresponds to a length | 449 // If the length/type is less than 1500, it corresponds to a length |
450 // interpretation packet. In this case, it is an 802.3 packet and | 450 // interpretation packet. In this case, it is an 802.3 packet and |
451 // will also have an 802.2 LLC header. If greater than 1500, we | 451 // will also have an 802.2 LLC header. If greater than 1500, we |
452 // find the protocol number (Ethernet type) directly. | 452 // find the protocol number (Ethernet type) directly. |
453 // | 453 // |
454 if (m_encapMode == LLC and header.GetLengthType () <= 1500) | 454 if (m_encapMode == LLC && header.GetLengthType () <= 1500) |
455 { | 455 { |
456 LlcSnapHeader llc; | 456 LlcSnapHeader llc; |
457 // | 457 // |
458 // Check to see that the packet is long enough to possibly contain the | 458 // Check to see that the packet is long enough to possibly contain the |
459 // header we want to remove before just naively calling. | 459 // header we want to remove before just naively calling. |
460 // | 460 // |
461 if (packet->GetSize () < llc.GetSerializedSize ()) | 461 if (packet->GetSize () < llc.GetSerializedSize ()) |
462 { | 462 { |
463 m_phyRxDropTrace (originalPacket); | 463 m_phyRxDropTrace (originalPacket); |
464 return; | 464 return; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 header.SetDestination (destination); | 548 header.SetDestination (destination); |
549 | 549 |
550 NS_ASSERT_MSG (packet->GetSize () <= m_mtu, "FdNetDevice::SendFrom(): Packet t
oo big " << packet->GetSize ()); | 550 NS_ASSERT_MSG (packet->GetSize () <= m_mtu, "FdNetDevice::SendFrom(): Packet t
oo big " << packet->GetSize ()); |
551 | 551 |
552 if (m_encapMode == LLC) | 552 if (m_encapMode == LLC) |
553 { | 553 { |
554 LlcSnapHeader llc; | 554 LlcSnapHeader llc; |
555 llc.SetType (protocolNumber); | 555 llc.SetType (protocolNumber); |
556 packet->AddHeader (llc); | 556 packet->AddHeader (llc); |
557 | 557 |
558 header.SetLengthType (packet->GetSize ()); | 558 header.SetLengthType (static_cast<uint16_t> (packet->GetSize ())); |
559 } | 559 } |
560 else | 560 else |
561 { | 561 { |
562 header.SetLengthType (protocolNumber); | 562 header.SetLengthType (protocolNumber); |
563 } | 563 } |
564 | 564 |
565 packet->AddHeader (header); | 565 packet->AddHeader (header); |
566 | 566 |
567 // | 567 // |
568 // there's not much meaning associated with the different layers in this | 568 // there's not much meaning associated with the different layers in this |
569 // device, so don't be surprised when they're all stacked together in | 569 // device, so don't be surprised when they're all stacked together in |
570 // essentially one place. We do this for trace consistency across devices. | 570 // essentially one place. We do this for trace consistency across devices. |
571 // | 571 // |
572 m_macTxTrace (packet); | 572 m_macTxTrace (packet); |
573 | 573 |
574 m_promiscSnifferTrace (packet); | 574 m_promiscSnifferTrace (packet); |
575 m_snifferTrace (packet); | 575 m_snifferTrace (packet); |
576 | 576 |
577 NS_LOG_LOGIC ("calling write"); | 577 NS_LOG_LOGIC ("calling write"); |
578 | 578 |
579 | 579 |
580 size_t len = (size_t) packet->GetSize (); | 580 size_t len = (size_t) packet->GetSize (); |
581 uint8_t *buffer = (uint8_t*)malloc (len); | 581 uint8_t *buffer = (uint8_t*)malloc (len); |
582 packet->CopyData (buffer, len); | 582 packet->CopyData (buffer, static_cast<uint32_t> (len)); |
583 | 583 |
584 // We need to add the PI header | 584 // We need to add the PI header |
585 if (m_encapMode == DIXPI) | 585 if (m_encapMode == DIXPI) |
586 { | 586 { |
587 AddPIHeader (buffer, len); | 587 AddPIHeader (buffer, len); |
588 } | 588 } |
589 | 589 |
590 ssize_t written = write (m_fd, buffer, len); | 590 ssize_t written = write (m_fd, buffer, len); |
591 free (buffer); | 591 free (buffer); |
592 | 592 |
593 if (written == -1 || (size_t) written != len) | 593 if (written == -1 || (size_t) written != len) |
594 { | 594 { |
595 m_macTxDropTrace (packet); | 595 m_macTxDropTrace (packet); |
596 return false; | 596 return false; |
597 } | 597 } |
598 | 598 |
599 return true; | 599 return true; |
600 } | 600 } |
601 | 601 |
602 void | 602 void |
603 FdNetDevice::SetFileDescriptor (int fd) | 603 FdNetDevice::SetFileDescriptor (int fd) |
604 { | 604 { |
605 if (m_fd == -1 and fd > 0) | 605 if (m_fd == -1 && fd > 0) |
606 { | 606 { |
607 m_fd = fd; | 607 m_fd = fd; |
608 } | 608 } |
609 } | 609 } |
610 | 610 |
611 void | 611 void |
612 FdNetDevice::SetAddress (Address address) | 612 FdNetDevice::SetAddress (Address address) |
613 { | 613 { |
614 m_address = Mac48Address::ConvertFrom (address); | 614 m_address = Mac48Address::ConvertFrom (address); |
615 } | 615 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 m_promiscRxCallback = cb; | 760 m_promiscRxCallback = cb; |
761 } | 761 } |
762 | 762 |
763 bool | 763 bool |
764 FdNetDevice::SupportsSendFrom (void) const | 764 FdNetDevice::SupportsSendFrom (void) const |
765 { | 765 { |
766 return true; | 766 return true; |
767 } | 767 } |
768 | 768 |
769 } // namespace ns3 | 769 } // namespace ns3 |
OLD | NEW |