store length type field in ethernet packets in network order.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2005 INRIA
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
24 #include "ns3/assert.h"
26 #include "ns3/header.h"
27 #include "ethernet-header.h"
28 #include "address-utils.h"
30 NS_LOG_COMPONENT_DEFINE ("EthernetHeader");
34 NS_HEADER_ENSURE_REGISTERED (EthernetHeader);
37 EthernetHeader::GetUid (void)
39 static uint32_t uid = AllocateUid<EthernetHeader> ("EthernetHeader.ns3");
43 EthernetHeader::EthernetHeader (bool hasPreamble)
44 : m_enPreambleSfd (hasPreamble),
48 EthernetHeader::EthernetHeader ()
49 : m_enPreambleSfd (false),
54 EthernetHeader::SetLengthType (uint16_t lengthType)
56 m_lengthType = lengthType;
59 EthernetHeader::GetLengthType (void) const
65 EthernetHeader::SetPreambleSfd (uint64_t preambleSfd)
67 m_preambleSfd = preambleSfd;
70 EthernetHeader::GetPreambleSfd (void) const
76 EthernetHeader::SetSource (Mac48Address source)
81 EthernetHeader::GetSource (void) const
87 EthernetHeader::SetDestination (Mac48Address dst)
92 EthernetHeader::GetDestination (void) const
98 EthernetHeader::GetPacketType (void) const
104 EthernetHeader::GetHeaderSize (void) const
106 return GetSerializedSize();
110 EthernetHeader::GetName (void) const
116 EthernetHeader::Print (std::ostream &os) const
121 os << " preamble/sfd=" << m_preambleSfd << ",";
124 os << " length/type=0x" << std::hex << m_lengthType << std::dec
125 << ", source=" << m_source
126 << ", destination=" << m_destination;
129 EthernetHeader::GetSerializedSize (void) const
133 return PREAMBLE_SIZE + LENGTH_SIZE + 2*MAC_ADDR_SIZE;
137 return LENGTH_SIZE + 2*MAC_ADDR_SIZE;
142 EthernetHeader::Serialize (Buffer::Iterator start) const
144 Buffer::Iterator i = start;
148 i.WriteU64(m_preambleSfd);
150 WriteTo (i, m_destination);
151 WriteTo (i, m_source);
152 i.WriteHtonU16 (m_lengthType);
155 EthernetHeader::Deserialize (Buffer::Iterator start)
157 Buffer::Iterator i = start;
161 m_enPreambleSfd = i.ReadU64 ();
164 ReadFrom (i, m_destination);
165 ReadFrom (i, m_source);
166 m_lengthType = i.ReadNtohU16 ();
168 return GetSerializedSize ();