FreeNOS
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
UDP Class Reference

User Datagram Protocol (UDP) More...

#include <UDP.h>

Inheritance diagram for UDP:
NetworkProtocol Directory File

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...
 
UDPSocketcreateSocket (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 Filelookup (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

UDPFactorym_factory
 Factory for creating new UDP sockets. More...
 
Index< UDPSocket, MaxUdpSocketsm_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
NetworkServerm_server
 Network server instance. More...
 
NetworkDevicem_device
 Network device instance. More...
 
NetworkProtocolm_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...
 

Detailed Description

User Datagram Protocol (UDP)

Definition at line 41 of file UDP.h.

Member Typedef Documentation

◆ Header

typedef struct UDP::Header UDP::Header

Packet header format.

Constructor & Destructor Documentation

◆ UDP()

UDP::UDP ( NetworkServer server,
NetworkDevice device,
NetworkProtocol parent 
)

Constructor.

Parameters
serverReference to the NetworkServer instance
deviceReference to the NetworkDevice instance
parentParent upper-layer protocol

Definition at line 25 of file UDP.cpp.

◆ ~UDP()

UDP::~UDP ( )
virtual

Destructor.

Definition at line 32 of file UDP.cpp.

Member Function Documentation

◆ bind()

FileSystem::Result UDP::bind ( UDPSocket sock,
const u16  port 
)

Bind to UDP port.

Parameters
sockUDP socket
portThe port to bind to
Returns
Result code

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().

◆ calculateSum()

const ulong UDP::calculateSum ( const u16 ptr,
const Size  bytes 
)
staticprivate

Calculate sum of artibrary data.

Parameters
ptrPointer to the data to sum
bytesNumber of bytes to add to the sum
Returns
Sum value for the input data

Definition at line 202 of file UDP.cpp.

References read16(), and read8().

Referenced by checksum().

◆ checksum()

const u16 UDP::checksum ( const IPV4::Header ip,
const Header header,
const Size  datalen 
)
static

Calculate ICMP checksum.

Parameters
ipPointer to the IPV4 header to use
headerICMP header
datalenTotal number of bytes of the payload data
Returns
ICMP checksum value for the given header

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().

◆ createSocket()

UDPSocket * UDP::createSocket ( String path,
const ProcessID  pid 
)

◆ initialize()

FileSystem::Result UDP::initialize ( )
virtual

◆ process()

FileSystem::Result UDP::process ( const NetworkQueue::Packet pkt,
const Size  offset 
)
virtual

Process incoming network packet.

Parameters
pktIncoming packet pointer
offsetOffset for processing
Returns
Result code

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().

◆ sendPacket()

FileSystem::Result UDP::sendPacket ( const NetworkClient::SocketInfo src,
const NetworkClient::SocketInfo dest,
IOBuffer buffer,
const Size  size,
const Size  offset 
)

◆ unregisterSockets()

void UDP::unregisterSockets ( const ProcessID  pid)

Field Documentation

◆ m_factory

UDPFactory* UDP::m_factory
private

Factory for creating new UDP sockets.

Definition at line 163 of file UDP.h.

Referenced by initialize().

◆ m_ports

HashTable<u16, UDPSocket *> UDP::m_ports
private

Maps UDP ports to UDP sockets.

Definition at line 169 of file UDP.h.

Referenced by bind(), process(), and unregisterSockets().

◆ m_sockets

Index<UDPSocket, MaxUdpSockets> UDP::m_sockets
private

Contains all UDP sockets.

Definition at line 166 of file UDP.h.

Referenced by createSocket(), and unregisterSockets().

◆ MaxUdpSockets

const Size UDP::MaxUdpSockets = 128u
staticprivate

Definition at line 45 of file UDP.h.

Referenced by unregisterSockets().


The documentation for this class was generated from the following files: