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 
8    Unless required by applicable law or agreed to in writing, this
9    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10    CONDITIONS OF ANY KIND, either express or implied.
11  */
12 
13 #pragma once
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #include "lwip/sys.h"
20 #include <lwip/netdb.h>
21 #include <arpa/inet.h>
22 
23 /**
24  * @brief Read and evaluate IP address from stdin
25  *
26  * This API reads stdin and parses the input address using getaddrinfo()
27  * to fill in struct sockaddr_storage (for both IPv4 and IPv6) used to open
28  * a socket. IP protocol is guessed from the IP address string.
29  *
30  * @param[in] port port number of expected connection
31  * @param[in] sock_type expected protocol: SOCK_STREAM or SOCK_DGRAM
32  * @param[out] ip_protocol resultant IP protocol: IPPROTO_IP or IPPROTO_IP6
33  * @param[out] addr_family resultant address family: AF_INET or AF_INET6
34  * @param[out] dest_addr sockaddr_storage structure (for both IPv4 and IPv6)
35  * @return ESP_OK on success, ESP_FAIL otherwise
36  */
37 esp_err_t get_addr_from_stdin(int port, int sock_type,
38                               int *ip_protocol,
39                               int *addr_family,
40                               struct sockaddr_storage *dest_addr);
41 
42 #ifdef __cplusplus
43 }
44 #endif
45