FreeNOS
IPV4.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_IPV4_H
19 #define __LIB_LIBNET_IPV4_H
20 
21 #include <Types.h>
22 #include <String.h>
23 #include "NetworkProtocol.h"
24 
25 class ICMP;
26 class ARP;
27 class UDP;
28 
40 class IPV4 : public NetworkProtocol
41 {
42  public:
43 
47  typedef u32 Address;
48 
52  enum Protocol
53  {
54  ICMP = 1,
55  IGMP = 2,
56  UDP = 17,
57  TCP = 6
58  };
59 
66  typedef struct Header
67  {
78  }
79  PACKED Header;
80 
87  typedef struct PseudoHeader
88  {
94  }
96 
97  public:
98 
106  IPV4(NetworkServer &server,
107  NetworkDevice &device,
108  NetworkProtocol &parent);
109 
113  virtual ~IPV4();
114 
120  virtual FileSystem::Result initialize();
121 
127  void setICMP(::ICMP *icmp);
128 
134  void setARP(::ARP *arp);
135 
141  void setUDP(::UDP *udp);
142 
150  virtual FileSystem::Result getAddress(Address *address);
151 
159  virtual FileSystem::Result setAddress(const Address *address);
160 
168  static const String toString(const Address address);
169 
176  static const Address toAddress(const char *address);
177 
190  const void *address,
191  const Size addressSize,
192  const Identifier protocol,
193  const Size payloadSize);
194 
204  const Size offset);
205 
214  static const u16 checksum(const void *buffer,
215  const Size length);
216 
217  private:
218 
227 
228  private:
229 
232 
235 
238 
241 
244 };
245 
251 #endif /* __LIB_LIBNET_IPV4_H */
IPV4::PseudoHeader::reserved
u8 reserved
Definition: IPV4.h:91
IPV4::process
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition: IPV4.cpp:210
NetworkProtocol
Network protocol abstraction class.
Definition: NetworkProtocol.h:39
IPV4::PseudoHeader
struct IPV4::PseudoHeader PseudoHeader
Pseudo Header.
Types.h
IPV4::Header::fragmentOffset
u16 fragmentOffset
Definition: IPV4.h:72
IPV4::Header::identification
u16 identification
Definition: IPV4.h:71
String
Abstraction of strings.
Definition: String.h:41
NetworkDevice
Network Device abstract class.
Definition: NetworkDevice.h:41
IPV4::checksum
static const u16 checksum(const void *buffer, const Size length)
Calculate IP checksum.
Definition: IPV4.cpp:184
IPV4::Header::source
Address source
Definition: IPV4.h:76
UDP
User Datagram Protocol (UDP)
Definition: UDP.h:41
IPV4::Header
struct IPV4::Header Header
IP network packet header.
NetworkProtocol::IPV4
@ IPV4
Definition: NetworkProtocol.h:49
IPV4::TCP
@ TCP
Definition: IPV4.h:57
IPV4::PseudoHeader::destination
Address destination
Definition: IPV4.h:90
IPV4::Header::length
u16 length
Definition: IPV4.h:70
NetworkProtocol.h
IPV4::m_udp
::UDP * m_udp
UDP instance.
Definition: IPV4.h:240
PACKED
#define PACKED
Ensures strict minimum memory requirements.
Definition: Macros.h:159
IPV4::PseudoHeader
Pseudo Header.
Definition: IPV4.h:87
IPV4::m_address
Address m_address
Current IP address.
Definition: IPV4.h:231
IPV4::Header::versionIHL
u8 versionIHL
Version and header length (IHL)
Definition: IPV4.h:68
NetworkServer
Networking server.
Definition: NetworkServer.h:40
IPV4::PseudoHeader::length
u16 length
Definition: IPV4.h:93
IPV4::Header::protocol
u8 protocol
Definition: IPV4.h:74
IPV4::PseudoHeader::protocol
u8 protocol
Definition: IPV4.h:92
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h: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
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
IPV4::Header::timeToLive
u8 timeToLive
Definition: IPV4.h:73
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
IPV4::setARP
void setARP(::ARP *arp)
Set ARP instance.
Definition: IPV4.cpp:60
IPV4
Internet Protocol Version 4.
Definition: IPV4.h:40
IPV4::Header
IP network packet header.
Definition: IPV4.h:66
IPV4::initialize
virtual FileSystem::Result initialize()
Perform initialization.
Definition: IPV4.cpp:45
IPV4::toString
static const String toString(const Address address)
Convert address to string.
Definition: IPV4.cpp:82
IPV4::~IPV4
virtual ~IPV4()
Destructor.
Definition: IPV4.cpp:41
IPV4::setUDP
void setUDP(::UDP *udp)
Set UDP instance.
Definition: IPV4.cpp:65
IPV4::setICMP
void setICMP(::ICMP *icmp)
Set ICMP instance.
Definition: IPV4.cpp:55
IPV4::getProtocolByIdentifier
Protocol getProtocolByIdentifier(const NetworkProtocol::Identifier id) const
Convert protocol identifier.
Definition: IPV4.cpp:120
IPV4::getTransmitPacket
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: IPV4.cpp:133
IPV4::m_id
u16 m_id
Packet ID for IPV4.
Definition: IPV4.h:243
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
IPV4::Header::typeOfService
u8 typeOfService
Definition: IPV4.h:69
IPV4::getAddress
virtual FileSystem::Result getAddress(Address *address)
Get current IP address.
Definition: IPV4.cpp:70
String.h
IPV4::PseudoHeader::source
Address source
Definition: IPV4.h:89
IPV4::Header::destination
Address destination
Definition: IPV4.h:77
IPV4::m_arp
::ARP * m_arp
ARP instance.
Definition: IPV4.h:237
IPV4::m_icmp
::ICMP * m_icmp
ICMP instance.
Definition: IPV4.h:234
IPV4::Header::checksum
u16 checksum
Definition: IPV4.h:75
NetworkQueue::Packet
Represents a network packet.
Definition: NetworkQueue.h:50
ARP
Address Resolution Protocol.
Definition: ARP.h:42
IPV4::IGMP
@ IGMP
Definition: IPV4.h:55
IPV4::Protocol
Protocol
Protocol types.
Definition: IPV4.h:52
NetworkProtocol::Identifier
Identifier
List of known network protocol identifiers.
Definition: NetworkProtocol.h:46
length
u32 length
Definition: IntelACPI.h:64
ICMP
Internet Control Message Protocol (ICMP)
Definition: ICMP.h:42