Macros | Functions
sbgNetwork.h File Reference

Useful methods for Network handling such as ip addresses. More...

#include <sbgCommon.h>
Include dependency graph for sbgNetwork.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SBG_IPV4_BROADCAST_ADDR   sbgIpAddr(255, 255, 255, 255)
 
#define SBG_IPV4_UNSPECIFIED_ADDR   sbgIpAddr(0, 0, 0, 0)
 

Functions

SBG_INLINE sbgIpAddress sbgIpAddr (uint8_t a, uint8_t b, uint8_t c, uint8_t d)
 
SBG_INLINE bool sbgIpAddressIsUnspecified (sbgIpAddress ipAddress)
 
SBG_INLINE bool sbgIpAddressValid (sbgIpAddress ipAddress)
 
SBG_INLINE uint8_t sbgIpAddrGetA (sbgIpAddress ipAddr)
 
SBG_INLINE uint8_t sbgIpAddrGetB (sbgIpAddress ipAddr)
 
SBG_INLINE uint8_t sbgIpAddrGetC (sbgIpAddress ipAddr)
 
SBG_INLINE uint8_t sbgIpAddrGetD (sbgIpAddress ipAddr)
 
SBG_INLINE bool sbgIpAddrIsSameNetwork (sbgIpAddress firstIpAddr, sbgIpAddress secondIpAddr, sbgIpAddress netmask)
 
SBG_INLINE sbgIpAddress sbgIpAddrWithinSubnet (sbgIpAddress ipAddress, sbgIpAddress netmask)
 
SBG_INLINE sbgIpAddress sbgIpGetHostAddr (sbgIpAddress ipAddress, sbgIpAddress netmask)
 
SBG_INLINE sbgIpAddress sbgIpGetNetworkAddr (sbgIpAddress ipAddress, sbgIpAddress netmask)
 
SBG_COMMON_LIB_API bool sbgIpNetMaskValid (sbgIpAddress netmask)
 
SBG_COMMON_LIB_API sbgIpAddress sbgNetworkIpFromString (const char *pBuffer)
 
SBG_COMMON_LIB_API void sbgNetworkIpToString (sbgIpAddress ipAddr, char *pBuffer, size_t maxSize)
 

Detailed Description

Useful methods for Network handling such as ip addresses.

Author
SBG Systems (Raphael Siryani)
Date
15 September 2015

IP v4 address is stored in memory with a uint32_t. Each address component A.B.C.D is stored in 8 bits using the network endianess ie Big Endian.

We thus have the following memory organisation:

In Little Endian: |LSB| | |MSB| | A | B | C | D |

In Big Endian: |MSB| | |LSB| | A | B | C | D |

Copyright Notice

Copyright (C) 2007-2016, SBG Systems SAS. All rights reserved.

This source code is intended for use only by SBG Systems SAS and those that have explicit written permission to use it from SBG Systems SAS.

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

Definition in file sbgNetwork.h.

Macro Definition Documentation

◆ SBG_IPV4_BROADCAST_ADDR

#define SBG_IPV4_BROADCAST_ADDR   sbgIpAddr(255, 255, 255, 255)

Broadcast IP address used to address all devices within the same network.

Definition at line 51 of file sbgNetwork.h.

◆ SBG_IPV4_UNSPECIFIED_ADDR

#define SBG_IPV4_UNSPECIFIED_ADDR   sbgIpAddr(0, 0, 0, 0)

This represents an undefined IP address.

Definition at line 50 of file sbgNetwork.h.

Function Documentation

◆ sbgIpAddr()

SBG_INLINE sbgIpAddress sbgIpAddr ( uint8_t  a,
uint8_t  b,
uint8_t  c,
uint8_t  d 
)

Build an IP V4 address in the form a.b.c.d

Parameters
[in]aFirst 8 bits IP address.
[in]bSecond 8 bits IP address.
[in]cThird 8 bits IP address.
[in]dLast 8 bits IP address.
Returns
An initialized IP address object.

Definition at line 65 of file sbgNetwork.h.

◆ sbgIpAddressIsUnspecified()

SBG_INLINE bool sbgIpAddressIsUnspecified ( sbgIpAddress  ipAddress)

Returns true if the provided IP address is unspecified ie (0.0.0.0)

Parameters
[in]ipAddressThe ip address to test
Returns
true if the ip address is unspecified or false otherwise.

Definition at line 184 of file sbgNetwork.h.

◆ sbgIpAddressValid()

SBG_INLINE bool sbgIpAddressValid ( sbgIpAddress  ipAddress)

Check if an IpV4 address is valid. The ip address format is A.B.C.D and A should respect 0 < A < 224

Parameters
[in]ipAddressThe ip address stored in an uint32_t (host endianness).
Returns
true if the ip address is valid ie contiguous.

Definition at line 201 of file sbgNetwork.h.

◆ sbgIpAddrGetA()

SBG_INLINE uint8_t sbgIpAddrGetA ( sbgIpAddress  ipAddr)

Return the first A field of of an IP v4 address of the form A.B.C.D

Parameters
[in]ipAddrAn sbgIpAddress to convert.
Returns
The A field of the IP address.

Definition at line 79 of file sbgNetwork.h.

◆ sbgIpAddrGetB()

SBG_INLINE uint8_t sbgIpAddrGetB ( sbgIpAddress  ipAddr)

Return the first B field of of an IP v4 address of the form A.B.C.D

Parameters
[in]ipAddrAn sbgIpAddress to convert.
Returns
The B field of the IP address.

Definition at line 93 of file sbgNetwork.h.

◆ sbgIpAddrGetC()

SBG_INLINE uint8_t sbgIpAddrGetC ( sbgIpAddress  ipAddr)

Return the first C field of of an IP v4 address of the form A.B.C.D

Parameters
[in]ipAddrAn sbgIpAddress to convert.
Returns
The C field of the IP address.

Definition at line 107 of file sbgNetwork.h.

◆ sbgIpAddrGetD()

SBG_INLINE uint8_t sbgIpAddrGetD ( sbgIpAddress  ipAddr)

Return the first D field of of an IP v4 address of the form A.B.C.D

Parameters
[in]ipAddrAn sbgIpAddress to convert.
Returns
The D field of the IP address.

Definition at line 121 of file sbgNetwork.h.

◆ sbgIpAddrIsSameNetwork()

SBG_INLINE bool sbgIpAddrIsSameNetwork ( sbgIpAddress  firstIpAddr,
sbgIpAddress  secondIpAddr,
sbgIpAddress  netmask 
)

Check if two ip addresses are in the same network given the subnet.

Parameters
[in]firstIpAddrThe first IP address to check.
[in]secondIpAddrThe second IP address to check.
[in]netmaskThe netmask of the network.
Returns
true if the two ip addresses are in the same network.

Definition at line 250 of file sbgNetwork.h.

◆ sbgIpAddrWithinSubnet()

SBG_INLINE sbgIpAddress sbgIpAddrWithinSubnet ( sbgIpAddress  ipAddress,
sbgIpAddress  netmask 
)

Given an ip address and the netmask, returns true if this ip address is within the subnet.

Parameters
[in]ipAddressThe ip address stored in an uint32_t (host endianness).
[in]netmaskThe netmask stored in an uint32_t (host endianness).
Returns
true if this ip address is within the subnet or false otherwise.

Definition at line 228 of file sbgNetwork.h.

◆ sbgIpGetHostAddr()

SBG_INLINE sbgIpAddress sbgIpGetHostAddr ( sbgIpAddress  ipAddress,
sbgIpAddress  netmask 
)

Given an ip address and the netmask, returns the host part (ip & ~subnetMask)

Parameters
[in]ipAddressThe ip address stored in an uint32_t (host endianness).
[in]netmaskThe netmask stored in an uint32_t (host endianness).
Returns
The host part of the ip address.

Definition at line 170 of file sbgNetwork.h.

◆ sbgIpGetNetworkAddr()

SBG_INLINE sbgIpAddress sbgIpGetNetworkAddr ( sbgIpAddress  ipAddress,
sbgIpAddress  netmask 
)

Given an ip address and the netmask, returns the network part (ip & subnetMask)

Parameters
[in]ipAddressThe ip address stored in an uint32_t (host endianness).
[in]netmaskThe netmask stored in an uint32_t (host endianness).
Returns
The network part of the ip address.

Definition at line 159 of file sbgNetwork.h.

◆ sbgIpNetMaskValid()

SBG_COMMON_LIB_API bool sbgIpNetMaskValid ( sbgIpAddress  netmask)

Check if an IpV4 netmask is valid, the mask should be contiguous (1111 followed by 0)

Parameters
[in]netmaskThe netmask stored in an uint32_t (host endianness).
Returns
true if the netmask is valid ie contiguous.

Definition at line 81 of file sbgNetwork.c.

◆ sbgNetworkIpFromString()

SBG_COMMON_LIB_API sbgIpAddress sbgNetworkIpFromString ( const char *  pBuffer)

Convert an ip address stored in a string of the form A.B.C.D to an sbgIpAddress object.

Parameters
[in]pBufferIP address as a string of the form A.B.C.D
Returns
IP address parsed from the string or 0.0.0.0 if the IP is invalid.

Definition at line 35 of file sbgNetwork.c.

◆ sbgNetworkIpToString()

SBG_COMMON_LIB_API void sbgNetworkIpToString ( sbgIpAddress  ipAddr,
char *  pBuffer,
size_t  maxSize 
)

Convert an ip to a string of the form A.B.C.D

Parameters
[in]ipAddrIP address to convert to a string.
[out]pBufferPointer on an allocated buffer than can hold ip address as a string.
[in]maxSizeMaximum number of chars that can be stored in pBuffer including the NULL char.

Definition at line 14 of file sbgNetwork.c.



sbg_driver
Author(s): SBG Systems
autogenerated on Sat Sep 3 2022 02:53:36