sbgECom Library  5.1.708-stable
Interface SBG Systems IMU/AHRS/INS
sbgNetwork.h
Go to the documentation of this file.
1 
47 #ifndef SBG_NETWORK_H
48 #define SBG_NETWORK_H
49 
50 // sbgCommonLib headers
51 #include <sbgCommon.h>
52 
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 //----------------------------------------------------------------------//
59 //- Common IPv4 definitions -//
60 //----------------------------------------------------------------------//
61 #define SBG_IPV4_UNSPECIFIED_ADDR sbgIpAddr(0, 0, 0, 0)
62 #define SBG_IPV4_BROADCAST_ADDR sbgIpAddr(255, 255, 255, 255)
64 #define SBG_NETWORK_IPV4_STRING_SIZE (16)
66 //----------------------------------------------------------------------//
67 //- IP setters / getters -//
68 //----------------------------------------------------------------------//
69 
79 SBG_INLINE sbgIpAddress sbgIpAddr(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
80 {
81 #if SBG_CONFIG_BIG_ENDIAN == 1
82  return (a << 24) | (b << 16) | (c << 8) | d;
83 #else
84  return a | (b << 8) | (c << 16) | (d << 24);
85 #endif
86 }
87 
95 {
96 #if SBG_CONFIG_BIG_ENDIAN == 1
97  return (uint8_t)((ipAddr & 0xFF000000) >> 24);
98 #else
99  return (uint8_t)((ipAddr & 0x000000FF));
100 #endif
101 }
102 
110 {
111 #if SBG_CONFIG_BIG_ENDIAN == 1
112  return (uint8_t)((ipAddr & 0x00FF0000) >> 16);
113 #else
114  return (uint8_t)((ipAddr & 0x0000FF00) >> 8);
115 #endif
116 }
117 
125 {
126 #if SBG_CONFIG_BIG_ENDIAN == 1
127  return (uint8_t)((ipAddr & 0x0000FF00) >> 8);
128 #else
129  return (uint8_t)((ipAddr & 0x00FF0000) >> 16);
130 #endif
131 }
132 
140 {
141 #if SBG_CONFIG_BIG_ENDIAN == 1
142  return (uint8_t)((ipAddr & 0x000000FF));
143 #else
144  return (uint8_t)((ipAddr & 0xFF000000) >> 24);
145 #endif
146 }
147 
148 //----------------------------------------------------------------------//
149 //- IP manipulation methods -//
150 //----------------------------------------------------------------------//
151 
159 SBG_COMMON_LIB_API void sbgNetworkIpToString(sbgIpAddress ipAddr, char *pBuffer, size_t maxSize);
160 
168 
169 //----------------------------------------------------------------------//
170 //- IP operations -//
171 //----------------------------------------------------------------------//
172 
181 {
182  return (ipAddress & netmask);
183 }
184 
193 {
194  return (ipAddress & ~netmask);
195 }
196 
197 //----------------------------------------------------------------------//
198 //- IP validation methods -//
199 //----------------------------------------------------------------------//
200 
208 {
209  if (ipAddress == 0)
210  {
211  return true;
212  }
213  else
214  {
215  return false;
216  }
217 }
218 
226 {
227  //
228  // Check the if A part of the ip address is within 1 and 223
229  //
230  if ((sbgIpAddrGetA(ipAddress) > 0) && (sbgIpAddrGetA(ipAddress) < 224))
231  {
232  return true;
233  }
234  else
235  {
236  return false;
237  }
238 }
239 
248 {
249  //
250  // Just check if the host part is equals to zero
251  //
252  if (sbgIpGetHostAddr(ipAddress, netmask) == 0)
253  {
254  return false;
255  }
256  else
257  {
258  return true;
259  }
260 }
261 
271 {
272  if ((firstIpAddr & netmask) == (secondIpAddr & netmask))
273  {
274  return true;
275  }
276  else
277  {
278  return false;
279  }
280 }
281 
289 
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 
295 #endif // SBG_NETWORK_H
Main header for the SBG Systems common C library.
#define SBG_INLINE
Definition: sbgDefines.h:227
#define SBG_COMMON_LIB_API
Definition: sbgDefines.h:79
SBG_INLINE bool sbgIpAddressValid(sbgIpAddress ipAddress)
Definition: sbgNetwork.h:225
SBG_INLINE sbgIpAddress sbgIpGetNetworkAddr(sbgIpAddress ipAddress, sbgIpAddress netmask)
Definition: sbgNetwork.h:180
SBG_INLINE uint8_t sbgIpAddrGetA(sbgIpAddress ipAddr)
Definition: sbgNetwork.h:94
SBG_COMMON_LIB_API sbgIpAddress sbgNetworkIpFromString(const char *pBuffer)
SBG_INLINE bool sbgIpAddrIsSameNetwork(sbgIpAddress firstIpAddr, sbgIpAddress secondIpAddr, sbgIpAddress netmask)
Definition: sbgNetwork.h:270
SBG_COMMON_LIB_API bool sbgIpNetMaskValid(sbgIpAddress netmask)
SBG_COMMON_LIB_API void sbgNetworkIpToString(sbgIpAddress ipAddr, char *pBuffer, size_t maxSize)
SBG_INLINE sbgIpAddress sbgIpAddrWithinSubnet(sbgIpAddress ipAddress, sbgIpAddress netmask)
Definition: sbgNetwork.h:247
SBG_INLINE uint8_t sbgIpAddrGetB(sbgIpAddress ipAddr)
Definition: sbgNetwork.h:109
SBG_INLINE uint8_t sbgIpAddrGetC(sbgIpAddress ipAddr)
Definition: sbgNetwork.h:124
SBG_INLINE bool sbgIpAddressIsUnspecified(sbgIpAddress ipAddress)
Definition: sbgNetwork.h:207
SBG_INLINE sbgIpAddress sbgIpAddr(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Definition: sbgNetwork.h:79
SBG_INLINE uint8_t sbgIpAddrGetD(sbgIpAddress ipAddr)
Definition: sbgNetwork.h:139
SBG_INLINE sbgIpAddress sbgIpGetHostAddr(sbgIpAddress ipAddress, sbgIpAddress netmask)
Definition: sbgNetwork.h:192
uint32_t sbgIpAddress
Definition: sbgTypes.h:66