ipv4_misc.c File Reference

Helper functions for IPv4. More...

#include <string.h>
#include <ctype.h>
#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 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...
 
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...
 
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...
 
error_t ipv4MapMulticastAddrToMac (Ipv4Addr ipAddr, MacAddr *macAddr)
 Map an host group address to a MAC-layer multicast address. 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-2019 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
1.9.2

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

◆ 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 79 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 55 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 523 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 613 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 587 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 386 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 468 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 351 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 432 of file ipv4_misc.c.

◆ ipv4MapMulticastAddrToMac()

error_t ipv4MapMulticastAddrToMac ( Ipv4Addr  ipAddr,
MacAddr macAddr 
)

Map an host group address to a MAC-layer multicast address.

Parameters
[in]ipAddrIPv4 host group address
[out]macAddrCorresponding MAC-layer multicast address
Returns
Error code

Definition at line 636 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 163 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 755 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 670 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 706 of file ipv4_misc.c.