X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2FLibraries%2Flibpsocket.so_src%2Fgetaddrinfo.c;h=d4d6ce8d0b01f2efbb2f3171c75dbc5f83e3da65;hb=8cf9dc88c488ba959a211f1ec653a366d16e1531;hp=57120f0d0f181121c912ac9227efc484db6137c2;hpb=8d2115456c8c70e6c73d713853a8c32826543601;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c b/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c index 57120f0d..d4d6ce8d 100644 --- a/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c +++ b/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c @@ -10,14 +10,20 @@ #include // Net_ParseAddress #include // malloc #include // memcpy +#include // strtol #include // === CODE === int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { - static const struct addrinfo defhints = {.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG}; + static const struct addrinfo defhints = { + .ai_family = AF_UNSPEC, + .ai_flags = AI_V4MAPPED | AI_ADDRCONFIG + }; struct addrinfo *ret = NULL; + _SysDebug("getaddrinfo('%s','%s',%p,%p)", node, service, hints, res); + // Error checks if( !node && !service ) return EAI_NONAME; @@ -66,6 +72,7 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi // - No luck with above, and hints->ai_flags doesn't have AI_NUMERICHOST set if( !ret && !(hints->ai_flags & AI_NUMERICHOST) ) { + _SysDebug("getaddrinfo: TODO DNS Lookups"); // TODO: DNS Lookups // ? /Acess/Conf/Nameservers // ? /Acess/Conf/Hosts @@ -78,14 +85,37 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi } } - int default_socktype = 0; - int default_protocol = 0; + int default_socktype = hints->ai_socktype; + int default_protocol = hints->ai_protocol; int default_port = 0; + #if 0 + if( default_protocol == 0 ) + { + switch(default_socktype) + { + case SOCK_DGRAM: + default_protocol = + } + } + #endif + // Convert `node` into types if( service ) { - // TODO: Read something like /Acess/Conf/services + char *end; + + default_port = strtol(service, &end, 0); + if( *end != '\0' && !(hints->ai_flags & AI_NUMERICSERV) ) + { + // TODO: Read something like /Acess/Conf/services + _SysDebug("getaddrinfo: TODO Service translation"); + } + + if( *end != '\0' ) + { + return EAI_NONAME; + } } struct addrinfo *ai; @@ -106,10 +136,16 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi case AF_INET: if( in->sin_port == 0 ) in->sin_port = default_port; + _SysDebug("%p: IPv4 [%s]:%i %i,%i", + ai, Net_PrintAddress(4, &in->sin_addr), + in->sin_port, ai->ai_socktype, ai->ai_protocol); break; case AF_INET6: if( in6->sin6_port == 0 ) in6->sin6_port = default_port; + _SysDebug("%p: IPv6 [%s]:%i %i,%i", + ai, Net_PrintAddress(6, &in6->sin6_addr), + in6->sin6_port, ai->ai_socktype, ai->ai_protocol); break; default: _SysDebug("getaddrinfo: Unknown address family %i (setting port)", ai->ai_family); @@ -126,6 +162,45 @@ void freeaddrinfo(struct addrinfo *res) } +int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) +{ + // Determine hostname + if( host ) + { + if( hostlen == 0 ) + return EAI_OVERFLOW; + host[0] = '\0'; + if( !(flags & NI_NUMERICHOST) ) + { + // Handle NI_NOFQDN + } + // Numeric hostname or the hostname was unresolvable + if( host[0] == '\0' ) + { + if( (flags & NI_NAMEREQD) ) + return EAI_NONAME; + } + } + + // Determine service name + if( serv ) + { + if( servlen == 0 ) + return EAI_OVERFLOW; + serv[0] = '\0'; + if( !(flags & NI_NUMERICSERV) ) + { + // Handle NI_DGRAM + } + if( serv[0] == '\0' ) + { + + } + } + return EAI_SUCCESS; +} + + const char *gai_strerror(int errnum) { switch(errnum)