From 7076523e482110d59c4456f4a795581a2ca39c41 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Aug 2023 16:08:19 +0200 Subject: nftutils: add and use wrappers for getprotoby{name,number}_r(), getservbyport_r() We should aim to use the thread-safe variants of getprotoby{name,number} and getservbyport(). However, they may not be available with other libc, so it requires a configure check. As that is cumbersome, add wrappers that do that at one place. These wrappers are thread-safe, if libc provides the reentrant versions. Use them. Signed-off-by: Thomas Haller Signed-off-by: Pablo Neira Ayuso --- src/nftutils.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/nftutils.h (limited to 'src/nftutils.h') diff --git a/src/nftutils.h b/src/nftutils.h new file mode 100644 index 00000000..cb584b9c --- /dev/null +++ b/src/nftutils.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef NFTUTILS_H +#define NFTUTILS_H + +#include +#include + +/* The maximum buffer size for (struct protoent).p_name. It is excessively large, + * while still reasonably fitting on the stack. Arbitrarily chosen. */ +#define NFT_PROTONAME_MAXSIZE 1024 + +bool nft_getprotobynumber(int number, char *out_name, size_t name_len); +int nft_getprotobyname(const char *name); + +/* The maximum buffer size for (struct servent).s_name. It is excessively large, + * while still reasonably fitting on the stack. Arbitrarily chosen. */ +#define NFT_SERVNAME_MAXSIZE 1024 + +bool nft_getservbyport(int port, const char *proto, char *out_name, size_t name_len); + +#endif /* NFTUTILS_H */ -- cgit v1.2.3