PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
8.0KB

  1. /**************************************************************************
  2. *
  3. * Copyright 2008-2018 by Andrey Butok. FNET Community.
  4. *
  5. ***************************************************************************
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. * not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. ***************************************************************************
  20. *
  21. * Address-conversion functions API.
  22. *
  23. ***************************************************************************/
  24. #ifndef _FNET_INET_H_
  25. #define _FNET_INET_H_
  26. /*! @addtogroup fnet_socket
  27. */
  28. /*! @{ */
  29. #if defined(__cplusplus)
  30. extern "C" {
  31. #endif
  32. /***************************************************************************/ /*!
  33. *
  34. * @brief Converts an IPv4 address into a string in Internet
  35. * standard dotted-decimal format.
  36. *
  37. *
  38. * @param addr Structure that represents an Internet address.
  39. *
  40. * @param res_str Pointer to a character buffer will contain the resulting
  41. * text address in standard "." notation.@n
  42. * The @c res_str buffer must be at least 16 bytes long
  43. * (@ref FNET_IP4_ADDR_STR_SIZE).
  44. *
  45. *
  46. *
  47. * @return This function always returns the @c res_str.
  48. *
  49. * @see fnet_inet_aton(), fnet_inet_ntop(), fnet_inet_pton()
  50. *
  51. ******************************************************************************
  52. *
  53. * This function takes an Internet address structure, specified by the @c addr
  54. * parameter, and returns a null-terminated ASCII string, representing the
  55. * address in "." (dot) notation as in "a.b.c.d" into buffer pointed to by the
  56. * @c res_str.
  57. *
  58. * @note
  59. * fnet_inet_ntop() extends the fnet_inet_ntoa() function to support multiple
  60. * address families. @n
  61. * fnet_inet_ntoa() is now considered to be deprecated.
  62. *
  63. ******************************************************************************/
  64. fnet_char_t *fnet_inet_ntoa( struct fnet_in_addr addr, fnet_char_t *res_str );
  65. /***************************************************************************/ /*!
  66. *
  67. * @brief Converts the string in the standard dotted-decimal notation
  68. * to an integer value, suitable for use as an IPv4 address.
  69. *
  70. *
  71. * @param cp Null-terminated character string representing a number
  72. * expressed in the Internet standard "." (dotted) notation.
  73. *
  74. * @param addr Pointer to an integer will contain a suitable
  75. * binary representation of the Internet address @c cp.
  76. *
  77. * @return This function returns:
  78. * - @ref FNET_OK if no error occurs.
  79. * - @ref FNET_ERR if the string in the @c cp parameter does not contain
  80. * a legitimate Internet address.
  81. *
  82. * @see fnet_inet_aton(), fnet_inet_ntop(), fnet_inet_pton()
  83. *
  84. ******************************************************************************
  85. *
  86. * This function interprets the character string specified by the @c cp
  87. * parameter. This string represents a numeric Internet address expressed
  88. * in the Internet standard "." notation. The value returned, pointed to by the @c addr,
  89. * is a number suitable for use as an Internet address.@n
  90. * @note
  91. * fnet_inet_pton() extends the fnet_inet_aton() function to support multiple
  92. * address families. @n
  93. * fnet_inet_aton() is now considered to be deprecated.
  94. *
  95. ******************************************************************************/
  96. fnet_return_t fnet_inet_aton( fnet_char_t *cp, struct fnet_in_addr *addr );
  97. /***************************************************************************/ /*!
  98. *
  99. * @brief Converts IPv4 or IPv6 address from binary to text form.
  100. *
  101. *
  102. * @param family The address family (@ref AF_INET or @ref AF_INET6).
  103. *
  104. * @param addr Pointer to the IP address in network-byte order.
  105. *
  106. * @param str Pointer to a buffer in which to store the NULL-terminated
  107. * string representation of the IP address.@n
  108. * For an IPv4 address, the @c str buffer must be at least 16 bytes long
  109. * (@ref FNET_IP4_ADDR_STR_SIZE).@n
  110. * For an IPv6 address, the @c str buffer must be at least 46 bytes long
  111. * (@ref FNET_IP6_ADDR_STR_SIZE).@n
  112. *
  113. * @param str_len Length of the @c str buffer.
  114. *
  115. *
  116. * @return This function returns:
  117. * - pointer to a buffer containing the string representation of IP
  118. * address (the @c str), if no error occurs,
  119. * - @ref FNET_NULL if an error occurs.
  120. *
  121. * @see fnet_inet_pton()
  122. *
  123. ******************************************************************************
  124. *
  125. * This function converts the network address structure, specified by the @c addr
  126. * parameter, in the @c addr_family address family into a character string.
  127. * The resulting string is copied to the buffer pointed to by @c str.
  128. *
  129. * @note
  130. * fnet_inet_ntop() extends the fnet_inet_ntoa() function to support multiple
  131. * address families. @n
  132. * fnet_inet_ntoa() is now considered to be deprecated.
  133. *
  134. ******************************************************************************/
  135. fnet_char_t *fnet_inet_ntop(fnet_address_family_t family, const void *addr, fnet_char_t *str, fnet_size_t str_len);
  136. /***************************************************************************/ /*!
  137. *
  138. * @brief Converts IPv4 and IPv6 addresses from text to binary form.
  139. *
  140. *
  141. * @param family The address family (@ref AF_INET or @ref AF_INET6).
  142. *
  143. * @param str Null-terminated character string that contains the text
  144. * representation of the IP address to convert to numeric
  145. * binary form.
  146. *
  147. * @param addr Pointer to a buffer in which to store the numeric binary
  148. * representation of the IP address @c str.
  149. *
  150. * @param addr_len Length of the @c addr buffer.
  151. *
  152. * @return This function returns:
  153. * - @ref FNET_OK if no error occurs.
  154. * - @ref FNET_ERR if the string in the @c str parameter does not contain
  155. * a legitimate Internet address.
  156. *
  157. * @see fnet_inet_ntop()
  158. *
  159. ******************************************************************************
  160. *
  161. * This function converts the character string @c src into a network address
  162. * structure in the @c addr_family address family, then copies the network
  163. * address structure to the @c addr buffer.
  164. *
  165. * @note
  166. * fnet_inet_pton() extends the fnet_inet_aton() function to support multiple
  167. * address families. @n
  168. * fnet_inet_aton() is now considered to be deprecated.
  169. *
  170. ******************************************************************************/
  171. fnet_return_t fnet_inet_pton (fnet_address_family_t family, const fnet_char_t *str, void *addr, fnet_size_t addr_len);
  172. /***************************************************************************/ /*!
  173. *
  174. * @brief Converts IPv4 and IPv6 addresses from text to socket-address structure.
  175. *
  176. * @param str Null-terminated character string that contains the text
  177. * representation of the IP address to convert to socket-address
  178. * structure. The @c sa_port is set to zero.
  179. *
  180. * @param addr Pointer to a socket-address structure to be filled.
  181. *
  182. * @return This function returns:
  183. * - @ref FNET_OK if no error occurs.
  184. * - @ref FNET_ERR if the string in the @c str parameter does not contain
  185. * a legitimate Internet address.
  186. *
  187. * @see fnet_inet_pton()
  188. *
  189. ******************************************************************************
  190. *
  191. * This function converts the character string @c src into a socket-address
  192. * structure.
  193. *
  194. ******************************************************************************/
  195. fnet_return_t fnet_inet_ptos (const fnet_char_t *str, struct fnet_sockaddr *addr);
  196. #if defined(__cplusplus)
  197. }
  198. #endif
  199. /*! @} */
  200. #endif /* _FNET_INET_H_ */