FreeNOS
Ethernet.h
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#ifndef __LIB_LIBNET_ETHERNET_H
19#define __LIB_LIBNET_ETHERNET_H
20
21#include <Types.h>
22#include <Macros.h>
23#include <Log.h>
24#include <String.h>
25#include "NetworkProtocol.h"
26
27class ARP;
28class IPV4;
29class ICMP;
30
43{
44 public:
45
47 static const Size CRCSize = 4;
48
52 typedef struct Address
53 {
54 u8 addr[6];
55 }
57
71
76 {
77 IPV4 = 0x0800u,
78 IPV6 = 0x86ddu,
79 ARP = 0x0806u
80 };
81
82 public:
83
90 Ethernet(NetworkServer &server,
91 NetworkDevice &device);
92
96 virtual ~Ethernet();
97
104
112 virtual FileSystem::Result getAddress(Address *address);
113
121 virtual FileSystem::Result setAddress(const Address *address);
122
135 const void *address,
136 const Size addressSize,
137 const Identifier protocol,
138 const Size payloadSize);
139
146 static const String toString(const Address address);
147
153 void setARP(::ARP *arp);
154
160 void setIP(::IPV4 *ip);
161
171 const Size offset);
172
173 private:
174
177
180
183};
184
185Log & operator << (Log &log, const Ethernet::Address & addr);
186
192#endif /* __LIB_LIBNET_ETHERNET_H */
Address Resolution Protocol.
Definition ARP.h:43
Ethernet networking protocol.
Definition Ethernet.h:43
void setARP(::ARP *arp)
Set ARP instance.
Definition Ethernet.cpp:66
virtual FileSystem::Result setAddress(const Address *address)
Set Ethernet address.
Definition Ethernet.cpp:55
static const String toString(const Address address)
Convert address to string.
Definition Ethernet.cpp:76
::ARP * m_arp
ARP protocol.
Definition Ethernet.h:179
virtual FileSystem::Result getAddress(Address *address)
Retrieve Ethernet address.
Definition Ethernet.cpp:49
void setIP(::IPV4 *ip)
Set IPV4 instance.
Definition Ethernet.cpp:71
virtual FileSystem::Result initialize()
Perform initialization.
Definition Ethernet.cpp:39
virtual ~Ethernet()
Destructor.
Definition Ethernet.cpp:35
struct Ethernet::Address Address
Ethernet network address.
struct Ethernet::Header Header
Ethernet network packet header.
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition Ethernet.cpp:126
virtual FileSystem::Result getTransmitPacket(NetworkQueue::Packet **pkt, const void *address, const Size addressSize, const Identifier protocol, const Size payloadSize)
Get a new packet for transmission.
Definition Ethernet.cpp:91
PayloadType
List of ethernet payload types.
Definition Ethernet.h:76
@ IPV6
Internet protocol v6.
Definition Ethernet.h:78
static const Size CRCSize
Size of the CRC checksum (which is set after the payload)
Definition Ethernet.h:47
::IPV4 * m_ipv4
IPV4 protocol.
Definition Ethernet.h:182
Address m_address
Current ethernet address.
Definition Ethernet.h:176
Internet Control Message Protocol (ICMP)
Definition ICMP.h:43
Internet Protocol Version 4.
Definition IPV4.h:41
Logging class.
Definition Log.h:97
Network Device abstract class.
Network protocol abstraction class.
Identifier
List of known network protocol identifiers.
Networking server.
Abstraction of strings.
Definition String.h:42
Log & operator<<(Log &log, const Ethernet::Address &addr)
Definition Ethernet.cpp:154
unsigned long Address
A memory address.
Definition Types.h:131
#define PACKED
Ensures strict minimum memory requirements.
Definition Macros.h:159
unsigned short u16
Unsigned 16-bit number.
Definition Types.h:56
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
Ethernet network address.
Definition Ethernet.h:53
Ethernet network packet header.
Definition Ethernet.h:65
u16 type
payload type
Definition Ethernet.h:68
Address destination
packet destination address
Definition Ethernet.h:66
Address source
packet source address
Definition Ethernet.h:67
Represents a network packet.