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

Enumerations

enum  IpProtocol { IP_PROTOCOL_TCP = 6, IP_PROTOCOL_UDP = 17 }
 IP supported protocols. More...
 

Functions

error_t ipSendDatagram (NetInterface *interface, IpPseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, uint8_t ttl)
 Send an IP datagram. More...
 
error_t ipSelectSourceAddr (NetInterface **interface, const IpAddr *destAddr, IpAddr *srcAddr)
 IP source address selection. More...
 
bool_t ipCompAddr (const IpAddr *ipAddr1, const IpAddr *ipAddr2)
 Compare IP addresses. More...
 
bool_t ipIsUnspecifiedAddr (const IpAddr *ipAddr)
 Compare an IP address against the unspecified address. 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

Copyright (C) 2010-2018 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.0

Definition in file ip.h.

Enumeration Type Documentation

◆ IpProtocol

enum IpProtocol

IP supported protocols.

Enumerator
IP_PROTOCOL_TCP 
IP_PROTOCOL_UDP 

Definition at line 46 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 685 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 596 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 351 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 471 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 544 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 571 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 155 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 206 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 252 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 302 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 106 of file ip.c.

◆ ipSendDatagram()

error_t ipSendDatagram ( NetInterface interface,
IpPseudoHeader pseudoHeader,
NetBuffer buffer,
size_t  offset,
uint8_t  ttl 
)

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]ttlTTL value. Default Time-To-Live is used when this parameter is zero
Returns
Error code

Definition at line 56 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 641 of file ip.c.

Variable Documentation

◆ IP_ADDR_ANY

const IpAddr IP_ADDR_ANY

Definition at line 42 of file ip.c.

◆ IP_ADDR_UNSPECIFIED

const IpAddr IP_ADDR_UNSPECIFIED

Definition at line 43 of file ip.c.