From: Simon Kuenzer Date: Tue, 6 Feb 2024 11:54:56 +0000 (+0100) Subject: gethostbyname: Option to use lwIPs `gethostbyname()` X-Git-Tag: RELEASE-0.16.2 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=082ca89fad935172e0e5f83313993c7752395f32;p=unikraft%2Flibs%2Fmusl.git gethostbyname: Option to use lwIPs `gethostbyname()` This commit introduces redirecting `gethostbyname()` (and family) calls to lwIP's implementation. This is only enabled if musl is configured to forward DNS related requests to lwIP. Signed-off-by: Simon Kuenzer Reviewed-by: Stefan Jumarea Reviewed-by: Mihnea Firoiu Reviewed-by: Razvan Deaconescu Approved-by: Razvan Deaconescu GitHub-Closes: #74 --- diff --git a/Makefile.uk.musl.network b/Makefile.uk.musl.network index 8914fbf..485dd70 100644 --- a/Makefile.uk.musl.network +++ b/Makefile.uk.musl.network @@ -68,16 +68,17 @@ ifeq ($(filter y,$(CONFIG_LIBMUSL_NETWORK_LWIP_DNS)),) LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getaddrinfo.c LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/freeaddrinfo.c LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getnameinfo.c +LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname.c +LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2.c +LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2_r.c +LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname_r.c else LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL_BASE)/lwip/getaddrinfo.c LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL_BASE)/lwip/getnameinfo.c +LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL_BASE)/lwip/gethostbyname.c endif LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyaddr.c LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyaddr_r.c -LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname.c -LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2.c -LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2_r.c -LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname_r.c LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getifaddrs.c LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getservbyname.c LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getservbyname_r.c diff --git a/lwip/gethostbyname.c b/lwip/gethostbyname.c new file mode 100644 index 0000000..16c1732 --- /dev/null +++ b/lwip/gethostbyname.c @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors. + * Licensed under the BSD-3-Clause License (the "License"). + * You may not use this file except in compliance with the License. + */ + +#define _GNU_SOURCE /* Enables h_errno and constants */ +#include +#include +#include +#include + +struct hostent *gethostbyname(const char *name) { + return lwip_gethostbyname(name); +} + +struct hostent *gethostbyname2(const char *name __unused, int af __unused) { + /* Not supported by lwip, but the function is deprecated anyways + * (like the other gethostbyname() variants) + */ + UK_WARN_STUBBED(); + + h_errno = NO_RECOVERY; + return NULL; +} + +int gethostbyname_r(const char *name, struct hostent *ret, char *buf, + size_t buflen, struct hostent **result, int *h_errnop) +{ + return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); +} + +int gethostbyname2_r(const char *name __unused, int af __unused, + struct hostent *ret __unused, char *buf __unused, + size_t buflen __unused, struct hostent **result __unused, + int *h_errnop __unused) +{ + /* Not supported by lwip */ + UK_WARN_STUBBED(); + + if (h_errnop) + *h_errnop = NO_RECOVERY; + return -1; +}