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

Internet Protocol Version 4. More...

#include <IPV4.h>

Inheritance diagram for IPV4:
NetworkProtocol Directory File

Data Structures

struct  Header
 IP network packet header. More...
 
struct  PseudoHeader
 Pseudo Header. More...
 

Public Types

enum  Protocol { ICMP = 1, IGMP = 2, UDP = 17, TCP = 6 }
 Protocol types. More...
 
typedef u32 Address
 IP-address. More...
 
typedef struct IPV4::Header Header
 IP network packet header. More...
 
typedef struct IPV4::PseudoHeader PseudoHeader
 Pseudo Header. More...
 

Public Member Functions

 IPV4 (NetworkServer &server, NetworkDevice &device, NetworkProtocol &parent)
 Constructor. More...
 
virtual ~IPV4 ()
 Destructor. More...
 
virtual FileSystem::Result initialize ()
 Perform initialization. More...
 
void setICMP (::ICMP *icmp)
 Set ICMP instance. More...
 
void setARP (::ARP *arp)
 Set ARP instance. More...
 
void setUDP (::UDP *udp)
 Set UDP instance. More...
 
virtual FileSystem::Result getAddress (Address *address)
 Get current IP address. More...
 
virtual FileSystem::Result setAddress (const Address *address)
 Set current IP address. 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...
 
virtual FileSystem::Result process (const NetworkQueue::Packet *pkt, const Size offset)
 Process incoming network 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...
 
- 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 String toString (const Address address)
 Convert address to string. More...
 
static const Address toAddress (const char *address)
 Convert string to IPV4 address. More...
 
static const u16 checksum (const void *buffer, const Size length)
 Calculate IP checksum. More...
 

Private Member Functions

Protocol getProtocolByIdentifier (const NetworkProtocol::Identifier id) const
 Convert protocol identifier. More...
 

Private Attributes

Address m_address
 Current IP address. More...
 
::ICMPm_icmp
 ICMP instance. More...
 
::ARPm_arp
 ARP instance. More...
 
::UDPm_udp
 UDP instance. More...
 
u16 m_id
 Packet ID for IPV4. More...
 

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

Internet Protocol Version 4.

Definition at line 40 of file IPV4.h.

Member Typedef Documentation

◆ Address

typedef u32 IPV4::Address

IP-address.

Definition at line 47 of file IPV4.h.

◆ Header

typedef struct IPV4::Header IPV4::Header

IP network packet header.

This header is prepended to every IP packet send on the actual physical link.

◆ PseudoHeader

Pseudo Header.

This header can be used by sub-protocols for checksum calculation (e.g. TCP and UDP).

Member Enumeration Documentation

◆ Protocol

Protocol types.

Enumerator
ICMP 
IGMP 
UDP 
TCP 

Definition at line 52 of file IPV4.h.

Constructor & Destructor Documentation

◆ IPV4()

IPV4::IPV4 ( 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 30 of file IPV4.cpp.

References m_address, m_icmp, m_id, and m_udp.

◆ ~IPV4()

IPV4::~IPV4 ( )
virtual

Destructor.

Definition at line 41 of file IPV4.cpp.

Member Function Documentation

◆ checksum()

const u16 IPV4::checksum ( const void *  buffer,
const Size  length 
)
static

Calculate IP checksum.

Parameters
bufferInput buffer for calculating checksum
lengthNumber of bytes in the buffer
Returns
IP checksum value for the given buffer

Definition at line 184 of file IPV4.cpp.

References length, read16(), and readBe16().

Referenced by getTransmitPacket(), NetPing::icmpPing(), and ICMP::sendPacket().

◆ getAddress()

FileSystem::Result IPV4::getAddress ( IPV4::Address address)
virtual

Get current IP address.

Parameters
addressIPV4 address buffer
Returns
Result code

Definition at line 70 of file IPV4.cpp.

References m_address, and FileSystem::Success.

Referenced by ARP::process(), IPV4Address::read(), ARP::sendReply(), and ARP::sendRequest().

◆ getProtocolByIdentifier()

IPV4::Protocol IPV4::getProtocolByIdentifier ( const NetworkProtocol::Identifier  id) const
private

Convert protocol identifier.

Parameters
idNetworkProtocol identifier
Returns
Protocol value for IPV4 header

Definition at line 120 of file IPV4.cpp.

References NetworkProtocol::ICMP, ICMP, TCP, NetworkProtocol::UDP, and UDP.

Referenced by getTransmitPacket().

◆ getTransmitPacket()

FileSystem::Result IPV4::getTransmitPacket ( NetworkQueue::Packet **  pkt,
const void *  address,
const Size  addressSize,
const Identifier  protocol,
const Size  payloadSize 
)
virtual

Get a new packet for transmission.

Parameters
pktOn output contains a pointer to a Packet
addressAddress of the destination of this packet
addressSizeNumber of bytes of the address
protocolIdentifier for the protocol to create the packet for
payloadSizeNumber of payload bytes
Returns
Result code

Reimplemented from NetworkProtocol.

Definition at line 133 of file IPV4.cpp.

References IPV4::Header::checksum, checksum(), IPV4::Header::destination, ERROR, IPV4::Header::fragmentOffset, getProtocolByIdentifier(), NetworkProtocol::getTransmitPacket(), IPV4::Header::identification, NetworkProtocol::IPV4, IPV4::Header::length, ARP::lookupAddress(), m_address, m_arp, m_id, NetworkProtocol::m_parent, IPV4::Header::protocol, FileSystem::RetryAgain, IPV4::Header::source, FileSystem::Success, IPV4::Header::timeToLive, IPV4::Header::typeOfService, IPV4::Header::versionIHL, writeBe16(), and writeBe32().

◆ initialize()

FileSystem::Result IPV4::initialize ( )
virtual

◆ process()

FileSystem::Result IPV4::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 210 of file IPV4.cpp.

References NetworkQueue::Packet::data, DEBUG, IPV4::Header::destination, ICMP, FileSystem::InvalidArgument, m_address, m_icmp, m_udp, FileSystem::NotFound, UDP::process(), ICMP::process(), IPV4::Header::protocol, readBe32(), toString(), and UDP.

Referenced by Ethernet::process().

◆ setAddress()

FileSystem::Result IPV4::setAddress ( const Address address)
virtual

Set current IP address.

Parameters
addressIPV4 address buffer
Returns
Result code

Definition at line 76 of file IPV4.cpp.

References m_address, and FileSystem::Success.

Referenced by Loopback::initialize(), and IPV4Address::write().

◆ setARP()

void IPV4::setARP ( ::ARP arp)

Set ARP instance.

Parameters
arpARP instance

Definition at line 60 of file IPV4.cpp.

References m_arp.

Referenced by NetworkDevice::initialize().

◆ setICMP()

void IPV4::setICMP ( ::ICMP icmp)

Set ICMP instance.

Parameters
icmpICMP instance

Definition at line 55 of file IPV4.cpp.

References m_icmp.

Referenced by NetworkDevice::initialize().

◆ setUDP()

void IPV4::setUDP ( ::UDP udp)

Set UDP instance.

Parameters
udpUDP instance

Definition at line 65 of file IPV4.cpp.

References m_udp.

Referenced by NetworkDevice::initialize().

◆ toAddress()

const IPV4::Address IPV4::toAddress ( const char *  address)
static

Convert string to IPV4 address.

Parameters
addressInput textual IP address in dot notation (xxx.xxx.xxx.xxx)
Returns
IPV4::Address or ZERO if not valid

Definition at line 94 of file IPV4.cpp.

References List< T >::count(), ListIterator< T >::hasCurrent(), String::split(), String::toLong(), and ZERO.

Referenced by NetPing::arpPing(), NetSend::exec(), NetPing::icmpPing(), NetCat::initialize(), Loopback::initialize(), and IPV4Address::write().

◆ toString()

const String IPV4::toString ( const Address  address)
static

Field Documentation

◆ m_address

Address IPV4::m_address
private

Current IP address.

Definition at line 231 of file IPV4.h.

Referenced by getAddress(), getTransmitPacket(), IPV4(), process(), and setAddress().

◆ m_arp

::ARP* IPV4::m_arp
private

ARP instance.

Definition at line 237 of file IPV4.h.

Referenced by getTransmitPacket(), and setARP().

◆ m_icmp

::ICMP* IPV4::m_icmp
private

ICMP instance.

Definition at line 234 of file IPV4.h.

Referenced by IPV4(), process(), and setICMP().

◆ m_id

u16 IPV4::m_id
private

Packet ID for IPV4.

Definition at line 243 of file IPV4.h.

Referenced by getTransmitPacket(), and IPV4().

◆ m_udp

::UDP* IPV4::m_udp
private

UDP instance.

Definition at line 240 of file IPV4.h.

Referenced by IPV4(), process(), and setUDP().


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