summaryrefslogtreecommitdiffstats
path: root/lib/libc/asr/getaddrinfo.c
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2012-09-08 11:08:21 +0000
committereric <eric@openbsd.org>2012-09-08 11:08:21 +0000
commit8082e013b3e34cd58819c630b3b36d768ac74f45 (patch)
tree9f6394f45e093439ea2bd2b395eab64d13064813 /lib/libc/asr/getaddrinfo.c
parentadd const where missing (diff)
downloadwireguard-openbsd-8082e013b3e34cd58819c630b3b36d768ac74f45.tar.xz
wireguard-openbsd-8082e013b3e34cd58819c630b3b36d768ac74f45.zip
split asr_resolver.c into different files to overlay the libc/net
resolver implementation.
Diffstat (limited to 'lib/libc/asr/getaddrinfo.c')
-rw-r--r--lib/libc/asr/getaddrinfo.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/libc/asr/getaddrinfo.c b/lib/libc/asr/getaddrinfo.c
new file mode 100644
index 00000000000..84b11ce5b80
--- /dev/null
+++ b/lib/libc/asr/getaddrinfo.c
@@ -0,0 +1,50 @@
+/* $OpenBSD: getaddrinfo.c,v 1.1 2012/09/08 11:08:21 eric Exp $ */
+/*
+ * Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#include <errno.h>
+#include <resolv.h>
+
+#include "asr.h"
+
+int
+getaddrinfo(const char *hostname, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res)
+{
+ struct async *as;
+ struct async_res ar;
+ int saved_errno = errno;
+
+ as = getaddrinfo_async(hostname, servname, hints, NULL);
+ if (as == NULL) {
+ if (errno == ENOMEM) {
+ errno = saved_errno;
+ return (EAI_MEMORY);
+ }
+ return (EAI_SYSTEM);
+ }
+
+ async_run_sync(as, &ar);
+
+ *res = ar.ar_addrinfo;
+ if (ar.ar_gai_errno == EAI_SYSTEM)
+ errno = ar.ar_errno;
+
+ return (ar.ar_gai_errno);
+}