FreeNOS
Loopback.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Loopback.h"
19 
20 Loopback::Loopback(const u32 inode,
21  NetworkServer &server)
22  : NetworkDevice(inode, server)
23 {
24  DEBUG("");
25 
26  m_address.addr[0] = 0x11;
27  m_address.addr[1] = 0x22;
28  m_address.addr[2] = 0x33;
29  m_address.addr[3] = 0x44;
30  m_address.addr[4] = 0x55;
31  m_address.addr[5] = 0x66;
32 }
33 
35 {
36  DEBUG("");
37 }
38 
40 {
41  DEBUG("");
42 
44  if (result != FileSystem::Success)
45  {
46  ERROR("failed to initialize NetworkDevice: result = " << (int) result);
47  return FileSystem::IOError;
48  }
49 
50  IPV4::Address addr = IPV4::toAddress("127.0.0.1");
51  m_ipv4->setAddress(&addr);
52 
53  return FileSystem::Success;
54 }
55 
57 {
58  DEBUG("");
59 
60  MemoryBlock::copy(address, &m_address, sizeof(Ethernet::Address));
61  return FileSystem::Success;
62 }
63 
65 {
66  DEBUG("");
67 
68  MemoryBlock::copy(&m_address, address, sizeof(Ethernet::Address));
69  return FileSystem::Success;
70 }
71 
73 {
74  DEBUG("size = " << pkt->size);
75 
76  // Process the packet by protocols as input (loopback)
77  const FileSystem::Result result = process(pkt);
78 
79  // Release packet buffer
80  m_transmit.release(pkt);
81 
82  // Done
83  return result;
84 }
Loopback::~Loopback
virtual ~Loopback()
Destructor.
Definition: Loopback.cpp:34
MemoryBlock::copy
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
Definition: MemoryBlock.cpp:36
Loopback::m_address
Ethernet::Address m_address
Ethernet address for the loopback device.
Definition: Loopback.h:89
NetworkDevice
Network Device abstract class.
Definition: NetworkDevice.h:41
NetworkQueue::release
void release(Packet *packet)
Put unused packet back.
Definition: NetworkQueue.cpp:87
NetworkDevice::process
virtual FileSystem::Result process(const NetworkQueue::Packet *packet, const Size offset=0)
Process a received network packet.
Definition: NetworkDevice.cpp:92
FileSystem::IOError
@ IOError
Definition: FileSystem.h:58
NetworkQueue::Packet::size
Size size
Definition: NetworkQueue.h:52
FileSystem::Success
@ Success
Definition: FileSystem.h:54
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
NetworkDevice::m_ipv4
IPV4 * m_ipv4
Definition: NetworkDevice.h:150
Loopback::Loopback
Loopback(const u32 inode, NetworkServer &server)
Constructor.
Definition: Loopback.cpp:20
Ethernet::Address
Ethernet network address.
Definition: Ethernet.h:52
NetworkServer
Networking server.
Definition: NetworkServer.h:40
Loopback::transmit
virtual FileSystem::Result transmit(NetworkQueue::Packet *pkt)
Transmit one network packet.
Definition: Loopback.cpp:72
Loopback::getAddress
virtual FileSystem::Result getAddress(Ethernet::Address *address)
Read ethernet address.
Definition: Loopback.cpp:56
IPV4::toAddress
static const Address toAddress(const char *address)
Convert string to IPV4 address.
Definition: IPV4.cpp:94
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Ethernet::Address::addr
u8 addr[6]
Definition: Ethernet.h:54
IPV4::setAddress
virtual FileSystem::Result setAddress(const Address *address)
Set current IP address.
Definition: IPV4.cpp:76
IPV4::Address
u32 Address
IP-address.
Definition: IPV4.h:47
Loopback.h
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
Loopback::initialize
virtual FileSystem::Result initialize()
Initialize the device.
Definition: Loopback.cpp:39
Loopback::setAddress
virtual FileSystem::Result setAddress(const Ethernet::Address *address)
Set ethernet address.
Definition: Loopback.cpp:64
NetworkDevice::m_transmit
NetworkQueue m_transmit
Definition: NetworkDevice.h:142
NetworkQueue::Packet
Represents a network packet.
Definition: NetworkQueue.h:50
NetworkDevice::initialize
virtual FileSystem::Result initialize()
Initialize the device.
Definition: NetworkDevice.cpp:42