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
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);
48 }
49
50 IPV4::Address addr = IPV4::toAddress("127.0.0.1");
51 m_ipv4->setAddress(&addr);
52
54}
55
63
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
81
82 // Done
83 return result;
84}
u32 Address
IP-address.
Definition IPV4.h:47
virtual FileSystem::Result setAddress(const Address *address)
Set current IP address.
Definition IPV4.cpp:76
static const Address toAddress(const char *address)
Convert string to IPV4 address.
Definition IPV4.cpp:94
virtual ~Loopback()
Destructor.
Definition Loopback.cpp:34
virtual FileSystem::Result transmit(NetworkQueue::Packet *pkt)
Transmit one network packet.
Definition Loopback.cpp:72
Loopback(const u32 inode, NetworkServer &server)
Constructor.
Definition Loopback.cpp:20
Ethernet::Address m_address
Ethernet address for the loopback device.
Definition Loopback.h:89
virtual FileSystem::Result getAddress(Ethernet::Address *address)
Read ethernet address.
Definition Loopback.cpp:56
virtual FileSystem::Result initialize()
Initialize the device.
Definition Loopback.cpp:39
virtual FileSystem::Result setAddress(const Ethernet::Address *address)
Set ethernet address.
Definition Loopback.cpp:64
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
Network Device abstract class.
virtual FileSystem::Result process(const NetworkQueue::Packet *packet, const Size offset=0)
Process a received network packet.
virtual FileSystem::Result initialize()
Initialize the device.
NetworkQueue m_transmit
void release(Packet *packet)
Put unused packet back.
Networking server.
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
#define ERROR(msg)
Output an error message.
Definition Log.h:61
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
Ethernet network address.
Definition Ethernet.h:53
Represents a network packet.