summaryrefslogtreecommitdiff
path: root/userland/libc/netdb
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/netdb')
-rw-r--r--userland/libc/netdb/gai_strerror.c36
-rw-r--r--userland/libc/netdb/getaddrinfo.c6
2 files changed, 37 insertions, 5 deletions
diff --git a/userland/libc/netdb/gai_strerror.c b/userland/libc/netdb/gai_strerror.c
new file mode 100644
index 0000000..81457cb
--- /dev/null
+++ b/userland/libc/netdb/gai_strerror.c
@@ -0,0 +1,36 @@
+#include <assert.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+const char *gai_strerror(int errcode) {
+ switch (errcode) {
+ case EAI_AGAIN:
+ return "The name could not be resolved at this time. Future attempts may "
+ "succeed.";
+ case EAI_BADFLAGS:
+ return "The flags had an invalid value.";
+ case EAI_FAIL:
+ return "A non-recoverable error occurred.";
+ case EAI_FAMILY:
+ return "The address family was not recognized or the address length was "
+ "invalid for the specified family.";
+ case EAI_MEMORY:
+ return "There was a memory allocation failure.";
+ case EAI_NONAME:
+ return "The name does not resolve for the supplied parameters. NI_NAMEREQD "
+ "is set and the host's name cannot be located, or both nodename and "
+ "servname were null.";
+ case EAI_SERVICE:
+ return "The service passed was not recognized for the specified socket "
+ "type.";
+ case EAI_SOCKTYPE:
+ return "The intended socket type was not recognized.";
+ case EAI_SYSTEM:
+ return "A system error occurred. The error code can be found in errno.";
+ case EAI_OVERFLOW:
+ return "An argument buffer overflowed.";
+ default:
+ return "Invalid gai error code, no error string found.";
+ }
+}
diff --git a/userland/libc/netdb/getaddrinfo.c b/userland/libc/netdb/getaddrinfo.c
index f7e89c0..f19d11a 100644
--- a/userland/libc/netdb/getaddrinfo.c
+++ b/userland/libc/netdb/getaddrinfo.c
@@ -1,6 +1,7 @@
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
+#include <netdb.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -88,11 +89,6 @@ int connect_dns(void) {
hints.ai_next = NULL;
*/
-#define EAI_AGAIN 1
-#define EAI_FAIL 2
-#define EAI_NONAME 3
-#define EAI_MEMORY 4
-
u16 service_to_port(const char *service) {
int is_number = 0;
for (int i = 0; service[i]; i++) {