addr_from_stdin.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Common utilities for socket address input interface:
  2. The API get_addr_from_stdin() is mainly used by socket client examples which read IP address from stdin (if configured).
  3. This option is typically used in the CI, but could be enabled in the project configuration.
  4. In that case this component is used to receive a string that is evaluated and processed to output
  5. socket structures to open a connectio
  6. This example code is in the Public Domain (or CC0 licensed, at your option.)
  7. Unless required by applicable law or agreed to in writing, this
  8. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  9. CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #pragma once
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include "lwip/sys.h"
  16. #include <lwip/netdb.h>
  17. #include <arpa/inet.h>
  18. /**
  19. * @brief Read and evaluate IP address from stdin
  20. *
  21. * This API reads stdin and parses the input address using getaddrinfo()
  22. * to fill in struct sockaddr_storage (for both IPv4 and IPv6) used to open
  23. * a socket. IP protocol is guessed from the IP address string.
  24. *
  25. * @param[in] port port number of expected connection
  26. * @param[in] sock_type expected protocol: SOCK_STREAM or SOCK_DGRAM
  27. * @param[out] ip_protocol resultant IP protocol: IPPROTO_IP or IPPROTO_IP6
  28. * @param[out] addr_family resultant address family: AF_INET or AF_INET6
  29. * @param[out] dest_addr sockaddr_storage structure (for both IPv4 and IPv6)
  30. * @return ESP_OK on success, ESP_FAIL otherwise
  31. */
  32. esp_err_t get_addr_from_stdin(int port, int sock_type,
  33. int *ip_protocol,
  34. int *addr_family,
  35. struct sockaddr_storage *dest_addr);
  36. #ifdef __cplusplus
  37. }
  38. #endif