etherpkt.cc revision 11263
1572SN/A/*
21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
3572SN/A * All rights reserved.
4572SN/A *
5572SN/A * Redistribution and use in source and binary forms, with or without
6572SN/A * modification, are permitted provided that the following conditions are
7572SN/A * met: redistributions of source code must retain the above copyright
8572SN/A * notice, this list of conditions and the following disclaimer;
9572SN/A * redistributions in binary form must reproduce the above copyright
10572SN/A * notice, this list of conditions and the following disclaimer in the
11572SN/A * documentation and/or other materials provided with the distribution;
12572SN/A * neither the name of the copyright holders nor the names of its
13572SN/A * contributors may be used to endorse or promote products derived from
14572SN/A * this software without specific prior written permission.
15572SN/A *
16572SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17572SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18572SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19572SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20572SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21572SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22572SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23572SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24572SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25572SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26572SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665SN/A *
282665SN/A * Authors: Nathan Binkert
29572SN/A */
30572SN/A
3111263Sandreas.sandberg@arm.com#include "dev/net/etherpkt.hh"
3211263Sandreas.sandberg@arm.com
33572SN/A#include <iostream>
34572SN/A
3511263Sandreas.sandberg@arm.com#include "base/inet.hh"
361153SN/A#include "base/misc.hh"
37572SN/A#include "sim/serialize.hh"
38572SN/A
39572SN/Ausing namespace std;
40572SN/A
41572SN/Avoid
4210905SN/AEthPacketData::serialize(const string &base, CheckpointOut &cp) const
43572SN/A{
4410905SN/A    paramOut(cp, base + ".length", length);
4510905SN/A    arrayParamOut(cp, base + ".data", data, length);
46572SN/A}
47572SN/A
48572SN/Avoid
4910905SN/AEthPacketData::unserialize(const string &base, CheckpointIn &cp)
50572SN/A{
5110905SN/A    paramIn(cp, base + ".length", length);
521654SN/A    if (length)
5310905SN/A        arrayParamIn(cp, base + ".data", data, length);
54572SN/A}
5510923SN/A
5610923SN/Avoid
5710923SN/AEthPacketData::packAddress(uint8_t *src_addr,
5810923SN/A                           uint8_t *dst_addr,
5910923SN/A                           unsigned &nbytes)
6010923SN/A{
6110923SN/A    Net::EthHdr *hdr = (Net::EthHdr *)data;
6210923SN/A    assert(hdr->src().size() == hdr->dst().size());
6310923SN/A    if (nbytes < hdr->src().size())
6410923SN/A        panic("EthPacketData::packAddress() Buffer overflow");
6510923SN/A
6610923SN/A    memcpy(dst_addr, hdr->dst().bytes(), hdr->dst().size());
6710923SN/A    memcpy(src_addr, hdr->src().bytes(), hdr->src().size());
6810923SN/A
6910923SN/A    nbytes = hdr->src().size();
7010923SN/A}
7110923SN/A
72