ip.c File Reference

IPv4 and IPv6 common routines. More...

#include "core/net.h"
#include "core/ethernet.h"
#include "core/ip.h"
#include "ipv4/ipv4.h"
#include "ipv4/ipv4_multicast.h"
#include "ipv4/ipv4_misc.h"
#include "ipv6/ipv6.h"
#include "ipv6/ipv6_multicast.h"
#include "ipv6/ipv6_misc.h"
#include "debug.h"
#include "ipsec/ipsec.h"
#include "ah/ah.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   IP_TRACE_LEVEL
 

Functions

error_t ipSendDatagram (NetInterface *interface, const IpPseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
 Send an IP datagram. More...
 
error_t ipSelectSourceAddr (NetInterface **interface, const IpAddr *destAddr, IpAddr *srcAddr)
 IP source address selection. More...
 
bool_t ipIsUnspecifiedAddr (const IpAddr *ipAddr)
 Compare an IP address against the unspecified address. More...
 
bool_t ipIsLinkLocalAddr (const IpAddr *ipAddr)
 Determine whether an IP address is a link-local address. More...
 
bool_t ipIsMulticastAddr (const IpAddr *ipAddr)
 Determine whether an IP address is a multicast address. More...
 
bool_t ipIsBroadcastAddr (const IpAddr *ipAddr)
 Determine whether an IP address is a broadcast address. More...
 
bool_t ipCompAddr (const IpAddr *ipAddr1, const IpAddr *ipAddr2)
 Compare IP addresses. More...
 
bool_t ipCompPrefix (const IpAddr *ipAddr1, const IpAddr *ipAddr2, size_t length)
 Compare IP address prefixes. More...
 
void ipUpdateMulticastFilter (NetInterface *interface, const IpAddr *groupAddr)
 Update IP multicast filter table. More...
 
uint16_t ipCalcChecksum (const void *data, size_t length)
 IP checksum calculation. More...
 
uint16_t ipCalcChecksumEx (const NetBuffer *buffer, size_t offset, size_t length)
 Calculate IP checksum over a multi-part buffer. More...
 
uint16_t ipCalcUpperLayerChecksum (const void *pseudoHeader, size_t pseudoHeaderLen, const void *data, size_t dataLen)
 Calculate IP upper-layer checksum. More...
 
uint16_t ipCalcUpperLayerChecksumEx (const void *pseudoHeader, size_t pseudoHeaderLen, const NetBuffer *buffer, size_t offset, size_t length)
 Calculate IP upper-layer checksum over a multi-part buffer. More...
 
NetBufferipAllocBuffer (size_t length, size_t *offset)
 Allocate a buffer to hold an IP packet. More...
 
error_t ipStringToAddr (const char_t *str, IpAddr *ipAddr)
 Convert a string representation of an IP address to a binary IP address. More...
 
char_tipAddrToString (const IpAddr *ipAddr, char_t *str)
 Convert a binary IP address to a string representation. More...
 

Variables

const IpAddr IP_ADDR_ANY = {0}
 
const IpAddr IP_ADDR_UNSPECIFIED = {0}
 

Detailed Description

IPv4 and IPv6 common routines.

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 ip.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   IP_TRACE_LEVEL

Definition at line 32 of file ip.c.

Function Documentation

◆ ipAddrToString()

char_t* ipAddrToString ( const IpAddr ipAddr,
char_t str 
)

Convert a binary IP address to a string representation.

Parameters
[in]ipAddrBinary representation of the IP address
[out]strNULL-terminated string representing the IP address
Returns
Pointer to the formatted string

Definition at line 805 of file ip.c.

◆ ipAllocBuffer()

NetBuffer* ipAllocBuffer ( size_t  length,
size_t *  offset 
)

Allocate a buffer to hold an IP packet.

Parameters
[in]lengthDesired payload length
[out]offsetOffset to the first byte of the payload
Returns
The function returns a pointer to the newly allocated buffer. If the system is out of resources, NULL is returned

Definition at line 711 of file ip.c.

◆ ipCalcChecksum()

uint16_t ipCalcChecksum ( const void *  data,
size_t  length 
)

IP checksum calculation.

Parameters
[in]dataPointer to the data over which to calculate the IP checksum
[in]lengthNumber of bytes to process
Returns
Checksum value

Definition at line 466 of file ip.c.

◆ ipCalcChecksumEx()

uint16_t ipCalcChecksumEx ( const NetBuffer buffer,
size_t  offset,
size_t  length 
)

Calculate IP checksum over a multi-part buffer.

Parameters
[in]bufferPointer to the multi-part buffer
[in]offsetOffset from the beginning of the buffer
[in]lengthNumber of bytes to process
Returns
Checksum value

Definition at line 586 of file ip.c.

◆ ipCalcUpperLayerChecksum()

uint16_t ipCalcUpperLayerChecksum ( const void *  pseudoHeader,
size_t  pseudoHeaderLen,
const void *  data,
size_t  dataLen 
)

Calculate IP upper-layer checksum.

Parameters
[in]pseudoHeaderPointer to the pseudo header
[in]pseudoHeaderLenPseudo header length
[in]dataPointer to the upper-layer data
[in]dataLenUpper-layer data length
Returns
Checksum value

Definition at line 659 of file ip.c.

◆ ipCalcUpperLayerChecksumEx()

uint16_t ipCalcUpperLayerChecksumEx ( const void *  pseudoHeader,
size_t  pseudoHeaderLen,
const NetBuffer buffer,
size_t  offset,
size_t  length 
)

Calculate IP upper-layer checksum over a multi-part buffer.

Parameters
[in]pseudoHeaderPointer to the pseudo header
[in]pseudoHeaderLenPseudo header length
[in]bufferMulti-part buffer containing the upper-layer data
[in]offsetOffset from the first data byte to process
[in]lengthNumber of data bytes to process
Returns
Checksum value

Definition at line 686 of file ip.c.

◆ ipCompAddr()

bool_t ipCompAddr ( const IpAddr ipAddr1,
const IpAddr ipAddr2 
)

Compare IP addresses.

Parameters
[in]ipAddr1First IP address
[in]ipAddr2Second IP address
Returns
Comparison result

Definition at line 317 of file ip.c.

◆ ipCompPrefix()

bool_t ipCompPrefix ( const IpAddr ipAddr1,
const IpAddr ipAddr2,
size_t  length 
)

Compare IP address prefixes.

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

Definition at line 370 of file ip.c.

◆ ipIsBroadcastAddr()

bool_t ipIsBroadcastAddr ( const IpAddr ipAddr)

Determine whether an IP address is a broadcast address.

Parameters
[in]ipAddrIP address
Returns
TRUE if the IP address is a broadcast address, else FALSE

Definition at line 288 of file ip.c.

◆ ipIsLinkLocalAddr()

bool_t ipIsLinkLocalAddr ( const IpAddr ipAddr)

Determine whether an IP address is a link-local address.

Parameters
[in]ipAddrIP address
Returns
TRUE if the IP address is a link-local address, else FALSE

Definition at line 212 of file ip.c.

◆ ipIsMulticastAddr()

bool_t ipIsMulticastAddr ( const IpAddr ipAddr)

Determine whether an IP address is a multicast address.

Parameters
[in]ipAddrIP address
Returns
TRUE if the IP address is a multicast address, else FALSE

Definition at line 250 of file ip.c.

◆ ipIsUnspecifiedAddr()

bool_t ipIsUnspecifiedAddr ( const IpAddr ipAddr)

Compare an IP address against the unspecified address.

Parameters
[in]ipAddrIP address
Returns
TRUE if the IP address is unspecified, else FALSE

Definition at line 167 of file ip.c.

◆ ipSelectSourceAddr()

error_t ipSelectSourceAddr ( NetInterface **  interface,
const IpAddr destAddr,
IpAddr srcAddr 
)

IP 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 IP address
[out]srcAddrLocal IP address to be used
Returns
Error code

Definition at line 119 of file ip.c.

◆ ipSendDatagram()

error_t ipSendDatagram ( NetInterface interface,
const IpPseudoHeader pseudoHeader,
NetBuffer buffer,
size_t  offset,
NetTxAncillary ancillary 
)

Send an IP datagram.

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderIP pseudo header
[in]bufferMulti-part buffer containing the payload
[in]offsetOffset to the first payload byte
[in]ancillaryAdditional options passed to the stack along with the packet
Returns
Error code

Definition at line 68 of file ip.c.

◆ ipStringToAddr()

error_t ipStringToAddr ( const char_t str,
IpAddr ipAddr 
)

Convert a string representation of an IP address to a binary IP address.

Parameters
[in]strNULL-terminated string representing the IP address
[out]ipAddrBinary representation of the IP address
Returns
Error code

Definition at line 761 of file ip.c.

◆ ipUpdateMulticastFilter()

void ipUpdateMulticastFilter ( NetInterface interface,
const IpAddr groupAddr 
)

Update IP multicast filter table.

Parameters
[in]interfaceUnderlying network interface
[in]groupAddrIP multicast address
Returns
Error code

Definition at line 410 of file ip.c.

Variable Documentation

◆ IP_ADDR_ANY

const IpAddr IP_ADDR_ANY = {0}

Definition at line 53 of file ip.c.

◆ IP_ADDR_UNSPECIFIED

const IpAddr IP_ADDR_UNSPECIFIED = {0}

Definition at line 54 of file ip.c.