FreeNOS
UDP.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_UDP_H
19 #define __LIB_LIBNET_UDP_H
20 
21 #include <Types.h>
22 #include <Index.h>
23 #include <String.h>
24 #include <HashTable.h>
25 #include "NetworkProtocol.h"
26 #include "UDPSocket.h"
27 
28 class UDPFactory;
29 
41 class UDP : public NetworkProtocol
42 {
43  private:
44 
45  static const Size MaxUdpSockets = 128u;
46 
47  public:
48 
52  typedef struct Header
53  {
58  }
59  Header;
60 
61  public:
62 
70  UDP(NetworkServer &server,
71  NetworkDevice &device,
72  NetworkProtocol &parent);
73 
77  virtual ~UDP();
78 
85 
91  UDPSocket * createSocket(String & path,
92  const ProcessID pid);
93 
99  void unregisterSockets(const ProcessID pid);
100 
110  const Size offset);
111 
121  const u16 port);
122 
129  const NetworkClient::SocketInfo *dest,
130  IOBuffer & buffer,
131  const Size size,
132  const Size offset);
133 
143  static const u16 checksum(const IPV4::Header *ip,
144  const Header *header,
145  const Size datalen);
146 
147  private:
148 
157  static const ulong calculateSum(const u16 *ptr,
158  const Size bytes);
159 
160  private:
161 
164 
167 
170 };
171 
177 #endif /* __LIB_LIBNET_UDP_H */
UDP::m_ports
HashTable< u16, UDPSocket * > m_ports
Maps UDP ports to UDP sockets.
Definition: UDP.h:169
UDP::~UDP
virtual ~UDP()
Destructor.
Definition: UDP.cpp:32
NetworkProtocol
Network protocol abstraction class.
Definition: NetworkProtocol.h:39
HashTable< u16, UDPSocket * >
UDP::Header
struct UDP::Header Header
Packet header format.
ulong
unsigned long ulong
Unsigned long number.
Definition: Types.h:47
Types.h
UDP::sendPacket
FileSystem::Result sendPacket(const NetworkClient::SocketInfo *src, const NetworkClient::SocketInfo *dest, IOBuffer &buffer, const Size size, const Size offset)
Send packet.
Definition: UDP.cpp:137
UDPFactory
User Datagram Protocol (UDP).
Definition: UDPFactory.h:38
Index.h
UDP::calculateSum
static const ulong calculateSum(const u16 *ptr, const Size bytes)
Calculate sum of artibrary data.
Definition: UDP.cpp:202
String
Abstraction of strings.
Definition: String.h:41
HashTable.h
NetworkDevice
Network Device abstract class.
Definition: NetworkDevice.h:41
UDP::m_sockets
Index< UDPSocket, MaxUdpSockets > m_sockets
Contains all UDP sockets.
Definition: UDP.h:166
UDP
User Datagram Protocol (UDP)
Definition: UDP.h:41
Index< UDPSocket, MaxUdpSockets >
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
NetworkProtocol::UDP
@ UDP
Definition: NetworkProtocol.h:52
UDP::createSocket
UDPSocket * createSocket(String &path, const ProcessID pid)
Creates an UDP socket.
Definition: UDP.cpp:47
NetworkProtocol.h
UDP::process
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition: UDP.cpp:117
NetworkServer
Networking server.
Definition: NetworkServer.h:40
UDP::unregisterSockets
void unregisterSockets(const ProcessID pid)
Remove sockets for a process.
Definition: UDP.cpp:82
header
SystemDescriptorHeader header
Definition: IntelACPI.h:63
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
UDP::Header
Packet header format.
Definition: UDP.h:52
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
UDP::Header::destPort
u16 destPort
Definition: UDP.h:55
UDP::Header::sourcePort
u16 sourcePort
Definition: UDP.h:54
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
UDP::bind
FileSystem::Result bind(UDPSocket *sock, const u16 port)
Bind to UDP port.
Definition: UDP.cpp:188
UDP::Header::checksum
u16 checksum
Definition: UDP.h:57
UDP::m_factory
UDPFactory * m_factory
Factory for creating new UDP sockets.
Definition: UDP.h:163
IPV4::Header
IP network packet header.
Definition: IPV4.h:66
NetworkClient::SocketInfo
Socket information.
Definition: NetworkClient.h:65
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
String.h
UDP::MaxUdpSockets
static const Size MaxUdpSockets
Definition: UDP.h:45
UDP::checksum
static const u16 checksum(const IPV4::Header *ip, const Header *header, const Size datalen)
Calculate ICMP checksum.
Definition: UDP.cpp:224
NetworkQueue::Packet
Represents a network packet.
Definition: NetworkQueue.h:50
UDP::Header::length
u16 length
Definition: UDP.h:56
UDPSocket.h
UDP::initialize
virtual FileSystem::Result initialize()
Perform initialization.
Definition: UDP.cpp:36
UDPSocket
User Datagram Protocol (UDP) socket.
Definition: UDPSocket.h:42