ip.h File Reference

IPv4 and IPv6 common routines. More...

#include "ipv4/ipv4.h"
#include "ipv6/ipv6.h"

Go to the source code of this file.

Data Structures

struct  IpAddr
 IP network address. More...
 
struct  IpPseudoHeader
 IP pseudo header. More...
 

Macros

#define IP_DEFAULT_DF   FALSE
 

Enumerations

enum  IpProtocol { IP_PROTOCOL_TCP = 6 , IP_PROTOCOL_UDP = 17 }
 IP supported protocols. More...
 
enum  IpFlags { IP_FLAG_DONT_ROUTE = 0x0400 , IP_FLAG_TTL = 0x00FF , IP_FLAG_HOP_LIMIT = 0x00FF }
 Flags used by I/O functions. More...
 

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...
 
error_t ipJoinMulticastGroup (NetInterface *interface, const IpAddr *groupAddr)
 Join the specified host group. More...
 
error_t ipLeaveMulticastGroup (NetInterface *interface, const IpAddr *groupAddr)
 Leave the specified host group. 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
 
const IpAddr IP_ADDR_UNSPECIFIED
 

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.0

Definition in file ip.h.

Macro Definition Documentation

◆ IP_DEFAULT_DF

#define IP_DEFAULT_DF   FALSE

Definition at line 40 of file ip.h.

Enumeration Type Documentation

◆ IpFlags

enum IpFlags

Flags used by I/O functions.

Enumerator
IP_FLAG_DONT_ROUTE 
IP_FLAG_TTL 
IP_FLAG_HOP_LIMIT 

Definition at line 66 of file ip.h.

◆ IpProtocol

enum IpProtocol

IP supported protocols.

Enumerator
IP_PROTOCOL_TCP 
IP_PROTOCOL_UDP 

Definition at line 55 of file ip.h.

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 838 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 744 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 499 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 619 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 692 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 719 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 315 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 368 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 286 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 210 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 248 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 165 of file ip.c.

◆ ipJoinMulticastGroup()

error_t ipJoinMulticastGroup ( NetInterface interface,
const IpAddr groupAddr 
)

Join the specified host group.

Parameters
[in]interfaceUnderlying network interface (optional parameter)
[in]groupAddrIP address identifying the host group to join
Returns
Error code

Definition at line 408 of file ip.c.

◆ ipLeaveMulticastGroup()

error_t ipLeaveMulticastGroup ( NetInterface interface,
const IpAddr groupAddr 
)

Leave the specified host group.

Parameters
[in]interfaceUnderlying network interface (optional parameter)
[in]groupAddrIP address identifying the host group to leave
Returns
Error code

Definition at line 454 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 117 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 66 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 794 of file ip.c.

Variable Documentation

◆ IP_ADDR_ANY

const IpAddr IP_ADDR_ANY
extern

Definition at line 51 of file ip.c.

◆ IP_ADDR_UNSPECIFIED

const IpAddr IP_ADDR_UNSPECIFIED
extern

Definition at line 52 of file ip.c.