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
28class UDPFactory;
29
41class UDP : public NetworkProtocol
42{
43 private:
44
45 static const Size MaxUdpSockets = 128u;
46
47 public:
48
60
61 public:
62
70 UDP(NetworkServer &server,
71 NetworkDevice &device,
72 NetworkProtocol &parent);
73
77 virtual ~UDP();
78
85
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 */
SystemDescriptorHeader header
Definition IntelACPI.h:0
u8 checksum
Definition IntelACPI.h:1
Efficient key -> value lookups.
Definition HashTable.h:45
Abstract Input/Output buffer.
Definition IOBuffer.h:38
Index is a N-sized array of pointers to items of type T.
Definition Index.h:37
Network Device abstract class.
Network protocol abstraction class.
Networking server.
Abstraction of strings.
Definition String.h:42
User Datagram Protocol (UDP).
Definition UDPFactory.h:39
User Datagram Protocol (UDP) socket.
Definition UDPSocket.h:43
User Datagram Protocol (UDP)
Definition UDP.h:42
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 * m_factory
Factory for creating new UDP sockets.
Definition UDP.h:163
UDPSocket * createSocket(String &path, const ProcessID pid)
Creates an UDP socket.
Definition UDP.cpp:47
static const ulong calculateSum(const u16 *ptr, const Size bytes)
Calculate sum of artibrary data.
Definition UDP.cpp:202
void unregisterSockets(const ProcessID pid)
Remove sockets for a process.
Definition UDP.cpp:82
FileSystem::Result bind(UDPSocket *sock, const u16 port)
Bind to UDP port.
Definition UDP.cpp:188
virtual FileSystem::Result initialize()
Perform initialization.
Definition UDP.cpp:36
Index< UDPSocket, MaxUdpSockets > m_sockets
Contains all UDP sockets.
Definition UDP.h:166
struct UDP::Header Header
Packet header format.
virtual ~UDP()
Destructor.
Definition UDP.cpp:32
static const Size MaxUdpSockets
Definition UDP.h:45
HashTable< u16, UDPSocket * > m_ports
Maps UDP ports to UDP sockets.
Definition UDP.h:169
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition UDP.cpp:117
u32 ProcessID
Process Identification Number.
Definition Types.h:140
unsigned long ulong
Unsigned long number.
Definition Types.h:47
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
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
IP network packet header.
Definition IPV4.h:67
Socket information.
Represents a network packet.
Packet header format.
Definition UDP.h:53
u16 checksum
Definition UDP.h:57
u16 sourcePort
Definition UDP.h:54
u16 length
Definition UDP.h:56
u16 destPort
Definition UDP.h:55