ipv4_misc.c File Reference

Helper functions for IPv4. More...

#include "core/net.h"
#include "ipv4/ipv4.h"
#include "ipv4/ipv4_misc.h"
#include "mibs/mib2_module.h"
#include "mibs/ip_mib_module.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   IPV4_TRACE_LEVEL
 

Functions

error_t ipv4AddRouterAlertOption (NetBuffer *buffer, size_t *offset)
 Append a Router Alert option to an IPv4 packet. More...
 
error_t ipv4CheckSourceAddr (NetInterface *interface, Ipv4Addr ipAddr)
 Source IPv4 address filtering. More...
 
error_t ipv4CheckDestAddr (NetInterface *interface, Ipv4Addr ipAddr)
 Destination IPv4 address filtering. More...
 
error_t ipv4SelectSourceAddr (NetInterface **interface, Ipv4Addr destAddr, Ipv4Addr *srcAddr)
 IPv4 source address selection. More...
 
error_t ipv4SelectDefaultGateway (NetInterface *interface, Ipv4Addr srcAddr, Ipv4Addr *defaultGatewayAddr)
 Default gateway selection. More...
 
bool_t ipv4IsHostAddrValid (NetInterface *interface)
 Check whether a valid IPv4 address has been assigned to the interface. More...
 
bool_t ipv4IsOnLink (NetInterface *interface, Ipv4Addr ipAddr)
 Check whether an IPv4 address is on-link. More...
 
bool_t ipv4IsBroadcastAddr (NetInterface *interface, Ipv4Addr ipAddr)
 Check whether an IPv4 address is a broadcast address. More...
 
bool_t ipv4IsTentativeAddr (NetInterface *interface, Ipv4Addr ipAddr)
 Check whether an IPv4 address is a tentative address. More...
 
bool_t ipv4IsLocalHostAddr (Ipv4Addr ipAddr)
 Check whether the specified IPv4 is assigned to the host. More...
 
bool_t ipv4CompPrefix (Ipv4Addr ipAddr1, Ipv4Addr ipAddr2, size_t length)
 Compare IPv4 address prefixes. More...
 
uint_t ipv4GetAddrScope (Ipv4Addr ipAddr)
 Retrieve the scope of an IPv4 address. More...
 
uint_t ipv4GetPrefixLength (Ipv4Addr mask)
 Calculate prefix length for a given subnet mask. More...
 
error_t ipv4GetBroadcastAddr (NetInterface *interface, Ipv4Addr *addr)
 Get IPv4 broadcast address. More...
 
bool_t ipv4TrapIgmpPacket (Ipv4Header *header)
 Trap IGMP packets. More...
 
void ipv4UpdateInStats (NetInterface *interface, Ipv4Addr destIpAddr, size_t length)
 Update IPv4 input statistics. More...
 
void ipv4UpdateOutStats (NetInterface *interface, Ipv4Addr destIpAddr, size_t length)
 Update IPv4 output statistics. More...
 
void ipv4UpdateErrorStats (NetInterface *interface, error_t error)
 Update Ethernet error statistics. More...
 

Detailed Description

Helper functions for IPv4.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file ipv4_misc.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   IPV4_TRACE_LEVEL

Definition at line 32 of file ipv4_misc.c.

Function Documentation

◆ ipv4AddRouterAlertOption()

error_t ipv4AddRouterAlertOption ( NetBuffer buffer,
size_t *  offset 
)

Append a Router Alert option to an IPv4 packet.

Parameters
[in]bufferMulti-part buffer containing the payload
[in,out]offsetOffset to the first payload byte
Returns
Error code

Definition at line 53 of file ipv4_misc.c.

◆ ipv4CheckDestAddr()

error_t ipv4CheckDestAddr ( NetInterface interface,
Ipv4Addr  ipAddr 
)

Destination IPv4 address filtering.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrDestination IPv4 address to be checked
Returns
Error code

Definition at line 116 of file ipv4_misc.c.

◆ ipv4CheckSourceAddr()

error_t ipv4CheckSourceAddr ( NetInterface interface,
Ipv4Addr  ipAddr 
)

Source IPv4 address filtering.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrSource IPv4 address to be checked
Returns
Error code

Definition at line 92 of file ipv4_misc.c.

◆ ipv4CompPrefix()

bool_t ipv4CompPrefix ( Ipv4Addr  ipAddr1,
Ipv4Addr  ipAddr2,
size_t  length 
)

Compare IPv4 address prefixes.

Parameters
[in]ipAddr1First IPv4 address
[in]ipAddr2Second IPv4 address
[in]lengthPrefix length
Returns
TRUE if the prefixes match each other, else FALSE

Definition at line 626 of file ipv4_misc.c.

◆ ipv4GetAddrScope()

uint_t ipv4GetAddrScope ( Ipv4Addr  ipAddr)

Retrieve the scope of an IPv4 address.

Parameters
[in]ipAddrIPv4 address
Returns
IPv4 address scope

Definition at line 662 of file ipv4_misc.c.

◆ ipv4GetBroadcastAddr()

error_t ipv4GetBroadcastAddr ( NetInterface interface,
Ipv4Addr addr 
)

Get IPv4 broadcast address.

Parameters
[in]interfacePointer to the desired network interface
[out]addrIPv4 broadcast address

Definition at line 754 of file ipv4_misc.c.

◆ ipv4GetPrefixLength()

uint_t ipv4GetPrefixLength ( Ipv4Addr  mask)

Calculate prefix length for a given subnet mask.

Parameters
[in]maskSubnet mask
Returns
Prefix length

Definition at line 726 of file ipv4_misc.c.

◆ ipv4IsBroadcastAddr()

bool_t ipv4IsBroadcastAddr ( NetInterface interface,
Ipv4Addr  ipAddr 
)

Check whether an IPv4 address is a broadcast address.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrIPv4 address to be checked
Returns
TRUE if the IPv4 address is a broadcast address, else FALSE

Definition at line 476 of file ipv4_misc.c.

◆ ipv4IsHostAddrValid()

bool_t ipv4IsHostAddrValid ( NetInterface interface)

Check whether a valid IPv4 address has been assigned to the interface.

Parameters
[in]interfaceUnderlying network interface
Returns
TRUE if a valid IPv4 address has been assigned, else FALSE

Definition at line 404 of file ipv4_misc.c.

◆ ipv4IsLocalHostAddr()

bool_t ipv4IsLocalHostAddr ( Ipv4Addr  ipAddr)

Check whether the specified IPv4 is assigned to the host.

Parameters
[in]ipAddrIPv4 address to be checked
Returns
TRUE if the IPv4 address matches any address assigned to the host, else FALSE

Definition at line 569 of file ipv4_misc.c.

◆ ipv4IsOnLink()

bool_t ipv4IsOnLink ( NetInterface interface,
Ipv4Addr  ipAddr 
)

Check whether an IPv4 address is on-link.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrIPv4 address to be checked
Returns
TRUE if the IPv4 address is on-link, else FALSE

Definition at line 438 of file ipv4_misc.c.

◆ ipv4IsTentativeAddr()

bool_t ipv4IsTentativeAddr ( NetInterface interface,
Ipv4Addr  ipAddr 
)

Check whether an IPv4 address is a tentative address.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrIPv4 address to be checked
Returns
TRUE if the IPv4 address is a tentative address, else FALSE

Definition at line 530 of file ipv4_misc.c.

◆ ipv4SelectDefaultGateway()

error_t ipv4SelectDefaultGateway ( NetInterface interface,
Ipv4Addr  srcAddr,
Ipv4Addr defaultGatewayAddr 
)

Default gateway selection.

Parameters
[in]interfaceUnderlying network interface
[in]srcAddrSource IPv4 address
[out]defaultGatewayAddrIPv4 address of the gateway
Returns
Error code

Definition at line 363 of file ipv4_misc.c.

◆ ipv4SelectSourceAddr()

error_t ipv4SelectSourceAddr ( NetInterface **  interface,
Ipv4Addr  destAddr,
Ipv4Addr srcAddr 
)

IPv4 source address selection.

This function selects the source address and the relevant network interface to be used in order to join the specified destination address

Parameters
[in,out]interfaceA pointer to a valid network interface may be provided as a hint. The function returns a pointer identifying the interface to be used
[in]destAddrDestination IPv4 address
[out]srcAddrLocal IPv4 address to be used
Returns
Error code

Definition at line 174 of file ipv4_misc.c.

◆ ipv4TrapIgmpPacket()

bool_t ipv4TrapIgmpPacket ( Ipv4Header header)

Trap IGMP packets.

Parameters
[in]headerPointer to the IPv4 header
Returns
TRUE if the IPv4 packet contains an IGMP message, else FALSE

Definition at line 804 of file ipv4_misc.c.

◆ ipv4UpdateErrorStats()

void ipv4UpdateErrorStats ( NetInterface interface,
error_t  error 
)

Update Ethernet error statistics.

Parameters
[in]interfaceUnderlying network interface
[in]errorStatus code describing the error

Definition at line 929 of file ipv4_misc.c.

◆ ipv4UpdateInStats()

void ipv4UpdateInStats ( NetInterface interface,
Ipv4Addr  destIpAddr,
size_t  length 
)

Update IPv4 input statistics.

Parameters
[in]interfaceUnderlying network interface
[in]destIpAddrDestination IP address
[in]lengthLength of the incoming IP packet

Definition at line 834 of file ipv4_misc.c.

◆ ipv4UpdateOutStats()

void ipv4UpdateOutStats ( NetInterface interface,
Ipv4Addr  destIpAddr,
size_t  length 
)

Update IPv4 output statistics.

Parameters
[in]interfaceUnderlying network interface
[in]destIpAddrDestination IP address
[in]lengthLength of the outgoing IP packet

Definition at line 875 of file ipv4_misc.c.