FreeNOS
|
User Datagram Protocol (UDP) More...
#include <UDP.h>
Data Structures | |
struct | Header |
Packet header format. More... | |
Public Types | |
typedef struct UDP::Header | Header |
Packet header format. More... | |
Public Member Functions | |
UDP (NetworkServer &server, NetworkDevice &device, NetworkProtocol &parent) | |
Constructor. More... | |
virtual | ~UDP () |
Destructor. More... | |
virtual FileSystem::Result | initialize () |
Perform initialization. More... | |
UDPSocket * | createSocket (String &path, const ProcessID pid) |
Creates an UDP socket. More... | |
void | unregisterSockets (const ProcessID pid) |
Remove sockets for a process. More... | |
virtual FileSystem::Result | process (const NetworkQueue::Packet *pkt, const Size offset) |
Process incoming network packet. More... | |
FileSystem::Result | bind (UDPSocket *sock, const u16 port) |
Bind to UDP port. More... | |
FileSystem::Result | sendPacket (const NetworkClient::SocketInfo *src, const NetworkClient::SocketInfo *dest, IOBuffer &buffer, const Size size, const Size offset) |
Send packet. More... | |
Public Member Functions inherited from NetworkProtocol | |
NetworkProtocol (NetworkServer &server, NetworkDevice &device, NetworkProtocol &parent) | |
Constructor. More... | |
virtual | ~NetworkProtocol () |
Destructor. More... | |
virtual const Size | getMaximumPacketSize () const |
Get maximum packet size. More... | |
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. More... | |
Public Member Functions inherited from Directory | |
Directory (const u32 inode) | |
Constructor. More... | |
virtual | ~Directory () |
Destructor. More... | |
virtual FileSystem::Result | read (IOBuffer &buffer, Size &size, const Size offset) |
Read directory entries. More... | |
virtual File * | lookup (const char *name) |
Retrieve a File from storage. More... | |
void | insert (FileSystem::FileType type, const char *name) |
Insert a new directory entry. More... | |
void | remove (const char *name) |
Remove a directory entry. More... | |
void | clear () |
Clears the internal list of entries. More... | |
Public Member Functions inherited from File | |
File (const u32 inode, const FileSystem::FileType type=FileSystem::RegularFile, const UserID uid=ZERO, const GroupID gid=ZERO) | |
Constructor function. More... | |
virtual | ~File () |
Destructor function. More... | |
u32 | getInode () const |
Get inode number. More... | |
FileSystem::FileType | getType () const |
Retrieve our filetype. More... | |
virtual FileSystem::Result | write (IOBuffer &buffer, Size &size, const Size offset) |
Write bytes to the file. More... | |
virtual FileSystem::Result | status (FileSystem::FileStat &st) |
Retrieve file statistics. More... | |
virtual bool | canRead () const |
Check if the File has data ready for reading. More... | |
virtual bool | canWrite () const |
Check if the File can be written to. More... | |
Static Public Member Functions | |
static const u16 | checksum (const IPV4::Header *ip, const Header *header, const Size datalen) |
Calculate ICMP checksum. More... | |
Static Private Member Functions | |
static const ulong | calculateSum (const u16 *ptr, const Size bytes) |
Calculate sum of artibrary data. More... | |
Private Attributes | |
UDPFactory * | m_factory |
Factory for creating new UDP sockets. More... | |
Index< UDPSocket, MaxUdpSockets > | m_sockets |
Contains all UDP sockets. More... | |
HashTable< u16, UDPSocket * > | m_ports |
Maps UDP ports to UDP sockets. More... | |
Static Private Attributes | |
static const Size | MaxUdpSockets = 128u |
Additional Inherited Members | |
Protected Types inherited from NetworkProtocol | |
enum | Identifier { Ethernet = 1, IPV4, ARP, ICMP, UDP, TCP } |
List of known network protocol identifiers. More... | |
Protected Attributes inherited from NetworkProtocol | |
NetworkServer & | m_server |
Network server instance. More... | |
NetworkDevice & | m_device |
Network device instance. More... | |
NetworkProtocol & | m_parent |
Parent upper-layer protocol instance. More... | |
Protected Attributes inherited from File | |
const u32 | m_inode |
Inode number. More... | |
const FileSystem::FileType | m_type |
Type of this file. More... | |
UserID | m_uid |
Owner of the file. More... | |
GroupID | m_gid |
Group of the file. More... | |
FileSystem::FileModes | m_access |
Access permissions. More... | |
Size | m_size |
Size of the file, in bytes. More... | |
typedef struct UDP::Header UDP::Header |
Packet header format.
UDP::UDP | ( | NetworkServer & | server, |
NetworkDevice & | device, | ||
NetworkProtocol & | parent | ||
) |
Constructor.
server | Reference to the NetworkServer instance |
device | Reference to the NetworkDevice instance |
parent | Parent upper-layer protocol |
FileSystem::Result UDP::bind | ( | UDPSocket * | sock, |
const u16 | port | ||
) |
Bind to UDP port.
sock | UDP socket |
port | The port to bind to |
Definition at line 188 of file UDP.cpp.
References DEBUG, HashTable< K, V >::insert(), FileSystem::InvalidArgument, m_ports, and FileSystem::Success.
Referenced by UDPSocket::write().
|
static |
Calculate ICMP checksum.
ip | Pointer to the IPV4 header to use |
header | ICMP header |
datalen | Total number of bytes of the payload data |
Definition at line 224 of file UDP.cpp.
References calculateSum(), DEBUG, IPV4::Header::destination, IPV4::PseudoHeader::destination, IPV4::PseudoHeader::length, IPV4::PseudoHeader::protocol, read32(), IPV4::PseudoHeader::reserved, IPV4::Header::source, IPV4::PseudoHeader::source, IPV4::toString(), IPV4::UDP, and writeBe16().
Referenced by sendPacket().
Creates an UDP socket.
Definition at line 47 of file UDP.cpp.
References DEBUG, ERROR, FileSystemServer::getMountPath(), FileSystemServer::getNextInode(), Index< T, N >::insert(), NetworkProtocol::m_server, m_sockets, FileSystemServer::registerFile(), Index< T, N >::remove(), FileSystem::Success, and ZERO.
Referenced by UDPFactory::read().
|
virtual |
Perform initialization.
Implements NetworkProtocol.
Definition at line 36 of file UDP.cpp.
References DEBUG, FileSystemServer::getNextInode(), m_factory, NetworkProtocol::m_server, FileSystemServer::registerDirectory(), FileSystemServer::registerFile(), and FileSystem::Success.
Referenced by NetworkDevice::initialize().
|
virtual |
Process incoming network packet.
pkt | Incoming packet pointer |
offset | Offset for processing |
Implements NetworkProtocol.
Definition at line 117 of file UDP.cpp.
References be16_to_cpu, NetworkQueue::Packet::data, DEBUG, UDP::Header::destPort, HashTable< K, V >::get(), m_ports, FileSystem::NotFound, and FileSystem::Success.
Referenced by IPV4::process().
FileSystem::Result UDP::sendPacket | ( | const NetworkClient::SocketInfo * | src, |
const NetworkClient::SocketInfo * | dest, | ||
IOBuffer & | buffer, | ||
const Size | size, | ||
const Size | offset | ||
) |
Send packet.
Definition at line 137 of file UDP.cpp.
References NetworkClient::SocketInfo::address, UDP::Header::checksum, checksum(), NetworkQueue::Packet::data, DEBUG, UDP::Header::destPort, ERROR, NetworkProtocol::getMaximumPacketSize(), NetworkProtocol::getTransmitPacket(), UDP::Header::length, NetworkProtocol::m_device, NetworkProtocol::m_parent, NetworkClient::SocketInfo::port, IOBuffer::read(), FileSystem::RetryAgain, NetworkQueue::Packet::size, UDP::Header::sourcePort, FileSystem::Success, IPV4::toString(), NetworkDevice::transmit(), NetworkProtocol::UDP, write16(), and writeBe16().
Referenced by UDPSocket::write().
void UDP::unregisterSockets | ( | const ProcessID | pid | ) |
Remove sockets for a process.
pid | ProcessID to remove sockets for |
Definition at line 82 of file UDP.cpp.
References DEBUG, ERROR, NetworkSocket::getProcessID(), HashIterator< K, V >::hasCurrent(), m_ports, NetworkProtocol::m_server, m_sockets, MaxUdpSockets, Index< T, N >::remove(), FileSystem::Success, FileSystemServer::unregisterFile(), and ZERO.
Referenced by NetworkDevice::unregisterSockets().
|
private |
Factory for creating new UDP sockets.
Definition at line 163 of file UDP.h.
Referenced by initialize().
|
private |
Contains all UDP sockets.
Definition at line 166 of file UDP.h.
Referenced by createSocket(), and unregisterSockets().
|
staticprivate |
Definition at line 45 of file UDP.h.
Referenced by unregisterSockets().