Choco OS  V.0.16.9.0
Join to the chocolate world
Network

Network types, definitions and low level functions. More...

Data Structures

struct  oC_Net_HardwareAddress_t
 stores hardware address More...
 
struct  PACKED
 stores IPv6 address More...
 
union  oC_Net_Packet_t
 stores network packet More...
 
struct  oC_Net_Frame_t
 stores informations about the frame to send More...
 
struct  oC_Net_QueueStatus_t
 stores status of network queue More...
 
struct  oC_Net_Address_t
 stores network address More...
 
struct  oC_Net_Ipv4Info_t
 stores network interface IPv4 informations More...
 
struct  oC_Net_Ipv6Info_t
 stores network interface IPv6 informations More...
 
struct  oC_Net_Info_t
 stores network interface informations More...
 

Typedefs

typedef uint8_t oC_Net_MacAddress_t[MAC_ADDRESS_LENGTH]
 stores MAC address
 
typedef uint32_t oC_Net_Ipv4_t
 stores IPv4 address More...
 
typedef struct PACKED oC_Net_Ipv6_t
 stores IPv6 address More...
 
typedef struct PACKED oC_Net_Ipv4PacketHeader_t
 contains IPv4 packet header More...
 
typedef struct PACKED oC_Net_Ipv6PacketHeader_t
 contains IPv6 packet header More...
 
typedef struct PACKED oC_Net_Ipv4Packet_t
 stores IPv4 packet More...
 
typedef struct PACKED oC_Net_Ipv6Packet_t
 stores IPv6 packet More...
 
typedef uint32_t oC_Net_InterfaceIndex_t
 stores index of the interface More...
 
typedef char oC_Net_InterfaceName_t[IFNAMSIZ]
 stores name of the network interface More...
 
typedef uint16_t oC_Net_Port_t
 Port of the network address. More...
 
typedef uint32_t oC_Net_Cost_t
 stores cost of the network connection
 

Enumerations

Functions

static uint16_t oC_Net_ConvertUint16ToNetworkEndianess (uint16_t v)
 converts uint16_t to network byte order
 
static uint32_t oC_Net_ConvertUint32ToNetworkEndianess (uint32_t v)
 converts uint32_t to network byte order
 
static uint16_t oC_Net_ConvertUint16FromNetworkEndianess (uint16_t v)
 converts uint16_t from network byte order
 
static uint32_t oC_Net_ConvertUint32FromNetworkEndianess (uint32_t v)
 converts uint32_t from network byte order
 
static void oC_Net_ConvertBufferToNetworkEndianess (void *Buffer, uint16_t Size)
 converts buffer to network endianess
 
static void oC_Net_ConvertBufferFromNetworkEndianess (void *Buffer, uint16_t Size)
 converts buffer from network endianess
 
static int oC_Net_PrepareInterfaceName (oC_Net_InterfaceName_t *outName, const char *Prefix, oC_Net_InterfaceIndex_t Index)
 prepares interface name string More...
 
static int oC_Net_MacAddressFromString (const char *MacAddressString, oC_Net_MacAddress_t outMacAddress)
 reads MAC address from the string More...
 
static oC_ErrorCode_t oC_Net_HardwareAddressToString (const oC_Net_HardwareAddress_t *HardwareAddress, oC_Net_HardwareType_t Type, char *outString, oC_MemorySize_t Size)
 prints HW address to the string More...
 
static oC_ErrorCode_t oC_Net_Ipv4AddressToString (oC_Net_Ipv4_t Address, char *outString, oC_MemorySize_t Size)
 prints IPv4 address to the string More...
 
static oC_ErrorCode_t oC_Net_AddressToString (const oC_Net_Address_t *Address, char *outString, oC_MemorySize_t Size)
 prints IP to the string More...
 
static oC_ErrorCode_t oC_Net_AddressFromString (const char *Address, oC_Net_Address_t *outAddress)
 reads IP address from the string More...
 
static bool oC_Net_IsAddressCorrect (const oC_Net_Address_t *Address)
 returns true if the given address is correct More...
 
static bool oC_Net_IsAddressEmpty (const oC_Net_Address_t *Address)
 returns true if the given address is empty More...
 
static bool oC_Net_Ipv4_IsAddressInSubnet (oC_Net_Ipv4_t IP, oC_Net_Ipv4_t Subnet, oC_Net_Ipv4_t Mask)
 checks if the IPv4 address belongs to the given subnetwork More...
 
static bool oC_Net_IsAddressInSubnet (const oC_Net_Address_t *Address, const oC_Net_Address_t *Subnet, const oC_Net_Address_t *Mask)
 checks if the address is in subnet More...
 
static bool oC_Net_AreAddressesTheSame (const oC_Net_Address_t *Address1, const oC_Net_Address_t *Address2)
 returns true if both pointers stores the same address More...
 
static uint16_t oC_Net_GetMaximumPacketDataSize (oC_Net_PacketType_t Type)
 returns maximum size of the packet data
 
static uint16_t oC_Net_GetPacketSize (const oC_Net_Packet_t *Packet, bool WithHeader)
 returns size of the packet More...
 
static bool oC_Net_ConvertHeaderToNetworkEndianess (oC_Net_Packet_t *Packet)
 converts header to network endianess
 
static bool oC_Net_ConvertHeaderFromNetworkEndianess (oC_Net_Packet_t *Packet)
 converts header from network endianess
 
static oC_MemorySize_t oC_Net_GetHardwareAddressSize (oC_Net_HardwareType_t Type)
 returns size of the hardware address (in bytes)
 
static oC_MemorySize_t oC_Net_GetAddressSize (const oC_Net_Address_t *Address)
 returns size of IP address
 
static const char * oC_Net_GetHardwareTypeName (oC_Net_HardwareType_t Type)
 returns name of the hardware type
 
static oC_ErrorCode_t oC_Net_ReadLayerName (oC_Net_Layer_t Layer, char *outName, oC_MemorySize_t Size)
 reads network layer name
 
static oC_ErrorCode_t oC_Net_ReadLayerByName (oC_Net_Layer_t *outLayer, const char *Name)
 returns network OSI layer according to its name
 
static bool oC_Net_IsMainLayer (oC_Net_Layer_t Layer, oC_Net_Layer_t MainLayer)
 returns true if Layer is part of the MainLayer
 
static oC_Net_PacketType_t oC_Net_Packet_GetType (const oC_Net_Packet_t *Packet)
 returns type of the packet More...
 
static bool oC_Net_Packet_SetSize (oC_Net_Packet_t *Packet, uint16_t Size)
 sets size of the packet
 
static void * oC_Net_Packet_GetDataReference (oC_Net_Packet_t *Packet)
 returns reference to the payload in the packet
 
static void oC_Net_Packet_SetAddress (oC_Net_Packet_t *Packet, const oC_Net_Address_t *Source, const oC_Net_Address_t *Destination)
 sets addresses in the packet
 
static void oC_Net_Packet_SetData (oC_Net_Packet_t *Packet, const void *Data, uint16_t Size)
 sets payload in the packet
 
static oC_Net_Packet_toC_Net_Packet_New (Allocator_t Allocator, oC_Net_PacketType_t Type, void *Data, uint16_t Size)
 allocates memory for a packet
 
static bool oC_Net_Packet_Delete (oC_Net_Packet_t **Packet)
 releases memory allocated for a packet
 
static uint16_t oC_Net_CalculateChecksum (const void *Buffer, uint16_t Size, uint16_t InitialValue, bool ConvertEndianess, bool PrepareChecksumToSend)
 
static uint16_t oC_Net_Packet_CalculateChecksum (oC_Net_Packet_t *Packet)
 calculates checksum for a packet (it only calculates it and does not fill it!)
 

Detailed Description

The module is for storing low level definitions of the network. You are probably looking for #Netif object

Typedef Documentation

typedef uint32_t oC_Net_InterfaceIndex_t

The type is for storing index of the given interface in the network driver. It can be used for creating the interface name

Definition at line 374 of file oc_net.h.

typedef char oC_Net_InterfaceName_t[IFNAMSIZ]

The type is for storing name of the interface. It is just to make it shorter and easier to manipulate

Definition at line 384 of file oc_net.h.

typedef uint32_t oC_Net_Ipv4_t

The type is for storing IP address in ver. 4

Definition at line 132 of file oc_net.h.

typedef struct PACKED oC_Net_Ipv4Packet_t

The type is for storing packets in IPv4 format

The type stores IPv4 packet header.

typedef struct PACKED oC_Net_Ipv6_t

The type is for storing IP address in ver. 6

typedef struct PACKED oC_Net_Ipv6Packet_t

The type is for storing packets in IPv6 format

The type is for storing IPv6 packet header

typedef uint16_t oC_Net_Port_t

The type is for storing port of the network address (e.x. 192.168.1.1:80, where 80 is the port)

Definition at line 417 of file oc_net.h.

Enumeration Type Documentation

The type is for storing type of a network address for oC_Net_Address_t structure.

Enumerator
oC_Net_AddressType_IPv4 

IP address in version 4.

oC_Net_AddressType_IPv6 

IP address in version 6.

Definition at line 427 of file oc_net.h.

The type is for storing frame type. The values can be used to the EtherType field in ethernet headers.

Enumerator
oC_Net_FrameType_IPv4 

Frame stores IPv4 packet.

oC_Net_FrameType_IPv6 

Frame stores IPv6 packet.

oC_Net_FrameType_ARP 

Address resolution packet.

Definition at line 189 of file oc_net.h.

Enumerator
oC_Net_HardwareType_Invalid 

Invalid type.

oC_Net_HardwareType_Ethernet 

Ethernet.

Definition at line 202 of file oc_net.h.

Enumerator
oC_Net_Layer_Physical 

In the seven-layer OSI model of computer networking, the physical layer or layer 1 is the first and lowest layer.

[1] The implementation of this layer is often termed PHY.

oC_Net_Layer_DataLink 

The data link layer or layer 2 is the second layer of the seven-layer OSI model of computer networking.

This layer is the protocol layer that transfers data between adjacent network nodes in a wide area network (WAN) or between nodes on the same local area network (LAN) segment. The data link layer provides the functional and procedural means to transfer data between network entities and might provide the means to detect and possibly correct errors that may occur in the physical layer.

oC_Net_Layer_Network 

In the seven-layer OSI model of computer networking, the network layer is layer 3.

The network layer is responsible for packet forwarding including routing through intermediate routers, since it knows the address of neighboring network nodes, and it also manages quality of service (QoS), and recognizes and forwards local host domain messages to the Transport layer (layer 4). The data link layer (layer 2) is responsible for media access control, flow control and error checking.

oC_Net_Layer_Transport 

In computer networking, the transport layer is a conceptual division of methods in the layered architecture of protocols in the network stack in the Internet Protocol Suite and the Open Systems Interconnection (OSI).

The protocols of the layer provide host-to-host communication services for applications. It provides services such as connection-oriented data stream support, reliability, flow control, and multiplexing.

oC_Net_Layer_Session 

In the seven-layer OSI model of computer networking, the session layer is layer 5.

The session layer provides the mechanism for opening, closing and managing a session between end-user application processes, i.e., a semi-permanent dialogue. Communication sessions consist of requests and responses that occur between applications. Session-layer services are commonly used in application environments that make use of remote procedure calls (RPCs).

oC_Net_Layer_Presentation 

In the seven-layer OSI model of computer networking, the presentation layer is layer 6 and serves as the data translator for the network.

It is sometimes called the syntax layer.

oC_Net_Layer_Application 

An application layer is an abstraction layer that specifies the shared protocols and interface methods used by hosts in a communications network.

The application layer abstraction is used in both of the standard models of computer networking: the Internet Protocol Suite (TCP/IP) and the Open Systems Interconnection model (OSI model).

oC_Net_Layer_MainLayerMask 

Mask to get the main layer of the OSI model.

oC_Net_Layer_SubLayerMask 

Mask to get the sublayer of the OSI model.

oC_Net_Layer_PHY 

PHY layer.

oC_Net_Layer_LLC 

Logical link control sublayer - The uppermost sublayer, LLC, multiplexes protocols running atop the data link layer, and optionally provides flow control, acknowledgment, and error notification.

oC_Net_Layer_MAC 

MAC may refer to the sublayer that determines who is allowed to access the media at any one time (e.g.

CSMA/CD). Other times it refers to a frame structure delivered based on MAC addresses inside.

oC_Net_Layer_Netif 

Network interface layer - sublayer of the Network layer.

Definition at line 333 of file oc_net.h.

Enumerator
oC_Net_LinkStatus_Down 

Network interface is UP (cable is connected)

oC_Net_LinkStatus_Up 

Network interface is DOWN (cable is not connected)

Definition at line 360 of file oc_net.h.

The type is for storing packet type. The values can be used to the Version field in IP headers.

Enumerator
oC_Net_PacketType_Invalid 

Invalid value.

oC_Net_PacketType_IPv4 

Packet in type IPv4.

oC_Net_PacketType_IPv6 

Packet in type IPv6.

Definition at line 174 of file oc_net.h.

Enumerator
oC_Net_Protocol_ICMP 

Internet Control Message Protocol.

oC_Net_Protocol_IGMP 

Internet Group Management Protocol.

oC_Net_Protocol_TCP 

Transmission Control Protocol.

oC_Net_Protocol_UDP 

User Datagram Protocol.

oC_Net_Protocol_ENCAP 

IPv6 encapsulation protocol.

oC_Net_Protocol_OSPF 

Open Shortest Path First.

oC_Net_Protocol_SCTP 

Stream Control Transmission Protocol.

Definition at line 155 of file oc_net.h.

Function Documentation

static oC_ErrorCode_t oC_Net_AddressFromString ( const char *  Address,
oC_Net_Address_t outAddress 
)
inlinestatic

The function is for reading IP address from a string to a oC_Net_Address_t structure.

Parameters
AddressString with IP address in format IPv4 or IPv6
outAddressDestination for the IP address
Returns
code of error or oC_ErrorCode_None if success

Definition at line 847 of file oc_net.h.

static oC_ErrorCode_t oC_Net_AddressToString ( const oC_Net_Address_t Address,
char *  outString,
oC_MemorySize_t  Size 
)
inlinestatic

The function is for printing IP to the string

Parameters
AddressAddress to print
outStringDestination for a string
Sizesize of the destination buffer
Returns
code of error or oC_ErrorCode_None if success

Definition at line 807 of file oc_net.h.

static bool oC_Net_AreAddressesTheSame ( const oC_Net_Address_t Address1,
const oC_Net_Address_t Address2 
)
inlinestatic

The function compares 2 addresses and returns true if they are the same.

Parameters
Address1Address 1 to compare
Address2Address 2 to compare
Returns
true if Address1 is the same as Address2

Definition at line 1033 of file oc_net.h.

static uint16_t oC_Net_CalculateChecksum ( const void *  Buffer,
uint16_t  Size,
uint16_t  InitialValue,
bool  ConvertEndianess,
bool  PrepareChecksumToSend 
)
inlinestatic

Calculates network checksum for a buffer

Definition at line 1581 of file oc_net.h.

static uint16_t oC_Net_GetPacketSize ( const oC_Net_Packet_t Packet,
bool  WithHeader 
)
inlinestatic

The function returns size of the packet (with header size)

Parameters
PacketPointer to the packet to check
Returns
size that is required to allocate for the packet

Definition at line 1076 of file oc_net.h.

static oC_ErrorCode_t oC_Net_HardwareAddressToString ( const oC_Net_HardwareAddress_t HardwareAddress,
oC_Net_HardwareType_t  Type,
char *  outString,
oC_MemorySize_t  Size 
)
inlinestatic

The function is for printing HW address to the string

Parameters
HardwareAddressHardware address to print
TypeType of the address filled in the HardwareAddress structure
outStringDestination buffer for a HW-Address string
SizeSize of the destination buffer
Returns
code of error or oC_ErrorCode_None if success

Definition at line 725 of file oc_net.h.

static bool oC_Net_Ipv4_IsAddressInSubnet ( oC_Net_Ipv4_t  IP,
oC_Net_Ipv4_t  Subnet,
oC_Net_Ipv4_t  Mask 
)
inlinestatic

The function checks if the given IPv4 address belongs to the given subnetwork

Parameters
IPIP to check
SubnetSubnetwork IP
MaskSubnetwork mask
Returns
true if the IP address belongs to the subnetwork

Definition at line 982 of file oc_net.h.

static oC_ErrorCode_t oC_Net_Ipv4AddressToString ( oC_Net_Ipv4_t  Address,
char *  outString,
oC_MemorySize_t  Size 
)
inlinestatic

The function is for printing IP to the string

Parameters
AddressAddress to print
outStringDestination for a string
Sizesize of the destination buffer
Returns
code of error or oC_ErrorCode_None if success

Definition at line 772 of file oc_net.h.

static bool oC_Net_IsAddressCorrect ( const oC_Net_Address_t Address)
inlinestatic

The function returns true if the IP address is correct

Parameters
AddressPointer to the structure with network IP address
Returns
true if the address is correct

Definition at line 918 of file oc_net.h.

static bool oC_Net_IsAddressEmpty ( const oC_Net_Address_t Address)
inlinestatic

The function returns true if the IP address is empty (0)

Parameters
AddressPointer to the structure with network IP address
Returns
true if the address is empty

Definition at line 949 of file oc_net.h.

static bool oC_Net_IsAddressInSubnet ( const oC_Net_Address_t Address,
const oC_Net_Address_t Subnet,
const oC_Net_Address_t Mask 
)
inlinestatic

The function checks if the given address belongs to the subnet.

Parameters
AddressAddress to check
SubnetAddress of the network
Masknetwork mask
Returns
true if address belongs to the given network

Definition at line 1001 of file oc_net.h.

static int oC_Net_MacAddressFromString ( const char *  MacAddressString,
oC_Net_MacAddress_t  outMacAddress 
)
inlinestatic

The function is for reading MAC address in format 'FF:FF:FF:FF:FF:FF' from string to the oC_Net_MacAddress_t type array.

Parameters
MacAddressStringString with MAC address
outMacAddressDestination for the macAddress
Returns
code of error or oC_ErrorCode_None if success

Definition at line 677 of file oc_net.h.

static oC_Net_PacketType_t oC_Net_Packet_GetType ( const oC_Net_Packet_t Packet)
inlinestatic

The function returns type of the packet.

Parameters
PacketPointer to the packet to check
Returns
type of the given packet

Definition at line 1370 of file oc_net.h.

static int oC_Net_PrepareInterfaceName ( oC_Net_InterfaceName_t outName,
const char *  Prefix,
oC_Net_InterfaceIndex_t  Index 
)
inlinestatic

The function is for preparation of the interface name according to prefix and index. In general it is designed for drivers usage, but it can also be useful in the other network related modules and programs. The function is defined to provide the same network interface name standard in each network driver.

Parameters
outNameName destination buffer
PrefixPrefix of the interface name (for example 'eth')
IndexUnique index of the adapter in the network driver
Returns
code of error or oC_ErrorCode_None if success

Definition at line 659 of file oc_net.h.