From: Geliang Tang <tanggeliang@xxxxxxxxxx> Similar to network helper connect_to_addr_str(), this patch adds a new helper send_to_addr_str(). It uses make_sockaddr() to make a sockaddr_storage type address from the "family", "addr_str" and "port" parameters and passes it to send_to_addr(). Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx> --- tools/testing/selftests/bpf/network_helpers.c | 16 ++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 311c3a559414..a6c158718267 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -229,6 +229,22 @@ static int send_to_addr(int type, const void *data, size_t datalen, int flags, return fd; } +int send_to_addr_str(int family, int type, const char *addr_str, __u16 port, + const void *data, size_t datalen, int flags, + const struct network_helper_opts *opts) +{ + struct sockaddr_storage addr; + socklen_t addrlen; + + if (!opts) + opts = &default_opts; + + if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) + return -1; + + return send_to_addr(type, data, datalen, flags, &addr, addrlen, opts); +} + int send_to_fd_opts(int server_fd, const void *data, size_t datalen, int flags, const struct network_helper_opts *opts) { diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 19210a234bc1..ebed1fb1bd49 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -76,6 +76,9 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); int send_to_fd_opts(int server_fd, const void *data, size_t datalen, int flags, const struct network_helper_opts *opts); +int send_to_addr_str(int family, int type, const char *addr_str, __u16 port, + const void *data, size_t datalen, int flags, + const struct network_helper_opts *opts); int fastopen_connect(int server_fd, const char *data, unsigned int data_len, int timeout_ms); int make_sockaddr(int family, const char *addr_str, __u16 port, -- 2.43.0