socket-util: Replace sockaddr length macros with functions

There's no need for these to be macros, let's just make them regular
functions instead.
This commit is contained in:
Daan De Meyer
2025-05-02 09:41:41 +02:00
parent 256c4203f9
commit a0233fcd86
21 changed files with 78 additions and 81 deletions
+1 -1
View File
@@ -1274,7 +1274,7 @@ int dns_server_is_accessible(DnsServer *s) {
return r;
}
r = RET_NERRNO(connect(fd, &sa.sa, SOCKADDR_LEN(sa)));
r = RET_NERRNO(connect(fd, &sa.sa, sockaddr_len(&sa)));
if (!IN_SET(r,
0,
-ENETUNREACH,
+1 -1
View File
@@ -572,7 +572,7 @@ int dns_stream_new(
if (tfo_address) {
s->tfo_address = *tfo_address;
s->tfo_salen = SOCKADDR_LEN(*tfo_address);
s->tfo_salen = sockaddr_len(tfo_address);
}
*ret = TAKE_PTR(s);
+1 -1
View File
@@ -1322,7 +1322,7 @@ static int manager_dns_stub_fd_extra(Manager *m, DnsStubListenerExtra *l, int ty
log_debug_errno(r, "Failed to enable fragment size reception, ignoring: %m");
}
r = RET_NERRNO(bind(fd, &sa.sa, SOCKADDR_LEN(sa)));
r = RET_NERRNO(bind(fd, &sa.sa, sockaddr_len(&sa)));
if (r < 0)
goto fail;
+2 -2
View File
@@ -111,7 +111,7 @@ static void *tcp_dns_server(void *p) {
assert_se((bindfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)) >= 0);
assert_se(setsockopt(bindfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) >= 0);
assert_se(bind(bindfd, &server_address.sa, SOCKADDR_LEN(server_address)) >= 0);
assert_se(bind(bindfd, &server_address.sa, sockaddr_len(&server_address)) >= 0);
assert_se(listen(bindfd, 1) >= 0);
assert_se((acceptfd = accept(bindfd, NULL, NULL)) >= 0);
server_handle(acceptfd);
@@ -246,7 +246,7 @@ static void test_dns_stream(bool tls) {
assert_se((clientfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)) >= 0);
for (int i = 0; i < 100; i++) {
r = connect(clientfd, &server_address.sa, SOCKADDR_LEN(server_address));
r = connect(clientfd, &server_address.sa, sockaddr_len(&server_address));
if (r >= 0)
break;
usleep_safe(EVENT_TIMEOUT_USEC / 100);