From feb96d8ea4ddbe44447f177d2cab0e21a2fea207 Mon Sep 17 00:00:00 2001 From: Don McCaughey Date: Tue, 8 Nov 2022 16:43:25 -0800 Subject: [PATCH] Add `sa_bind()` and `sa_connect()` inline wrappers. These are convenience wrappers for calling `bind()` and `connect()`. --- src/libood/ood/inet/socket.c | 2 +- src/sa/sa.c | 6 ++++++ src/sa/sa.h | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libood/ood/inet/socket.c b/src/libood/ood/inet/socket.c index 16e0893..cc99d53 100644 --- a/src/libood/ood/inet/socket.c +++ b/src/libood/ood/inet/socket.c @@ -116,7 +116,7 @@ ood_inet_socket_listen(struct ood_inet_socket *listener, int backlog) return ood_error; } - int result = bind(listener->fd, &listener->address->generic, sizeof listener->address->ipv4); + int result = sa_bind(listener->fd, listener->address); if (result < 0) { close_socket(listener); return ood_error; diff --git a/src/sa/sa.c b/src/sa/sa.c index 2b28ac4..9498976 100644 --- a/src/sa/sa.c +++ b/src/sa/sa.c @@ -129,3 +129,9 @@ sa_str(struct sa_address const *address) default: return "(unsupported)"; } } + +extern int +sa_bind(int socket, struct sa_address const *address); + +extern int +sa_connect(int socket, struct sa_address const *address); diff --git a/src/sa/sa.h b/src/sa/sa.h index bdee648..969b69e 100644 --- a/src/sa/sa.h +++ b/src/sa/sa.h @@ -67,4 +67,17 @@ char const * sa_str(struct sa_address const *address); +inline int +sa_bind(int socket, struct sa_address const *address) +{ + return bind(socket, &address->generic, sa_len(address)); +} + +inline int +sa_connect(int socket, struct sa_address const *address) +{ + return connect(socket, &address->generic, sa_len(address)); +} + + #endif -- 2.45.2