val_gethostbyname(3)
ok bestie, this one's from the Programmer's Manual β val_gethostbyname(3) and its whole little friend group. grab a snack, we're doing DNSSEC host lookups π«Ά
β¨ NAME β¨
val_gethostbyname(), val_gethostbyname2(), val_gethostbyname_r(), val_gethostbyname2_r() β get DNSSEC-validated network host entry π
like, it does the host lookup thing, but it also checks the DNSSEC vibes. iconic behavior honestly.
π SYNOPSIS π
#include <validator/validator.h>
extern int h_errno;
struct hostent *val_gethostbyname(const val_context_t *ctx,
const char *name,
val_status_t *val_status);
struct hostent *val_gethostbyname2(const val_context_t *ctx,
const char *name,
int af,
val_status_t *val_status);
int val_gethostbyname_r(const val_context_t *ctx,
const char *name,
struct hostent *ret,
char *buf,
size_t buflen,
struct hostent **result,
int *h_errnop,
val_status_t *val_status);
int val_gethostbyname2_r(const val_context_t *ctx,
const char *name,
int af,
struct hostent *ret,
char *buf,
size_t buflen,
struct hostent **result,
int *h_errnop,
val_status_t *val_status);
struct hostent *val_gethostbyaddr(val_context_t * ctx,
const char *addr,
int len,
int type,
val_status_t * val_status);
int val_gethostbyaddr_r(val_context_t * ctx,
const char *addr,
int len,
int type,
struct hostent *ret,
char *buf,
int buflen,
struct hostent **result,
int *h_errnop,
val_status_t * val_status);
(also can I just say β val_gethostbyaddr() and val_gethostbyaddr_r() are in the synopsis but not in the NAME list. the lore is deeper than the title. iykyk π)
π¦ DESCRIPTION π¦
So. val_gethostbyname(), val_gethostbyname2(), val_gethostbyname_r(), val_gethostbyname2_r(), val_gethostbyaddr() and val_gethostbyaddr_r() all do DNSSEC validation of DNS queries. They hand you back a network host entry of type struct hostent, and they're the DNSSEC-aware glow-ups of gethostbyname(3), gethostbyname2(3), gethostbyname_r(), gethostbyname2_r(), gethostbyaddr() and gethostbyaddr_r() respectively. (if you wanna know what struct hostent even is β go read gethostbyname(3), it's all in there, bestie.)
val_gethostbyname(),val_gethostbyname_r(),val_gethostbyaddr(), andval_gethostbyaddr_r()support only IPv4 addresses.val_gethostbyname2()andval_gethostbyname2_r()support both IPv4 and IPv6 addresses. range, honestly π
And the reentrant versions β val_gethostbyname_r(), val_gethostbyname2_r() and val_gethostbyaddr_r() β are the ones you can safely use in multi-threaded applications. thread-safe queens, no cap π
The ctx parameter is the validation context. You can set it to NULL for default values (see libval(3) and dnsval.conf for the full tea on validation contexts and validation policy).
val_gethostbyname(), val_gethostbyname2() and val_gethostbyaddr() set the global h_errno variable to return the resolver error code. The reentrant versions val_gethostbyname_r(), val_gethostbyname2_r() and val_gethostbyaddr_r() use the h_errnop parameter to return that value instead. That's the whole point β it keeps things thread safe by avoiding the global h_errno variable. π§
Heads up:h_errnopmust NOT beNULL. like, don't do that. π
(see the man page for gethostbyname(3) for possible values of h_errno.)
The name, af, ret, buf, buflen, and result parameters have the same syntax and semantics as the corresponding parameters for the original gethostbyname*() and gethostbyaddr*() functions. Again, gethostbyname(3) has the details on those.
The val_status parameter is where the validator error code comes back β and it must not be NULL. Use val_istrusted() and val_isvalidated() to figure out whether the data is trustworthy, and p_val_status() to display the status value to the user in ASCII format (see libval(3) for more info).
π RETURN VALUES π
val_gethostbyname(),val_gethostbyname2(), andval_gethostbyaddr()return a pointer to ahostentstructure when they can resolve the given host name (with or without DNSSEC validation), andNULLif data was not available. The memory for the returned value is statically allocated by these two functions, so the caller must NOT free the memory for the returned value. do not touch it, it's not yours π«Άval_gethostbyname_r(),val_gethostbyname2_r()andval_gethostbyaddr_r()return0when they can resolve the given host name (with or without DNSSEC validation), and a non-zero error-code on failure.val_gethostbyaddr()andval_gethostbyaddr_r()return0when they can resolve the given host name (with or without DNSSEC validation), and a non-zero error-code on failure.- The
val_statusparameter gives an indication of the trustworthiness of the data. And if the returnedhostentstructure isNULL, this value tells you whether the non-existence of data can be trusted or not. β¨
πΈ EXAMPLE πΈ
#include <stdio.h>
#include <stdlib.h>
#include <validator.h>
int main(int argc, char *argv[])
{
int val_status;
struct hostent *h = NULL;
if (argc < 2) {
printf("Usage: %s <hostname>\n", argv[0]);
exit(1);
}
h = val_gethostbyname(NULL, argv[1], &val_status);
printf("h_errno = %d [%s]\n", h_errno,
hstrerror(h_errno));
if (h) {
printf("Validation Status = %d [%s]\n", val_status,
p_val_status(val_status));
}
return 0;
}
main character energy fr fr π
π NOTES π
- These functions do not currently read the order of lookup from
/etc/hosts.conf. At present, the default order is set to consult the/etc/hostsfile first and then query DNS. that's just how it is rn π - The current versions of these functions do not support NIS lookups.
π COPYRIGHT π
Copyright 2004-2013 SPARTA, Inc. All rights reserved. See the COPYING file included with the DNSSEC-Tools package for details.
β AUTHORS β
Abhijit Hayatnagarkar, Suresh Krishnaswamy.
π SEE ALSO π
gethostbyname(3),gethostbyname2(3),gethostbyname_r(3),gethostbyname2_r(3)val_getaddrinfo(3),val_res_query(3)libval(3)http://www.dnssec-tools.org
ok that's the whole thing, you ate it, congrats π this page was brought to you by perl v5.14.3, dated 2013-03-12, and the letter val_. go validate something, bestie πβ¨π¦
π¦ where this page comes from
- arch rolling: dnssec-tools 2.2.3-16 Β· BSD
- fedora 43: dnssec-tools-libs-devel 2.2.3-30.fc43 Β· LicenseRef-Callaway-BSD
- fedora 43: dnssec-tools-libs-devel 2.2.3-30.fc43 Β· LicenseRef-Callaway-BSD
- fedora 44: dnssec-tools-libs-devel 2.2.3-32.fc44 Β· LicenseRef-Callaway-BSD
- fedora 44: dnssec-tools-libs-devel 2.2.3-32.fc44 Β· LicenseRef-Callaway-BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms