From 67be203adb74a30134d277c346ca2f82e0fe0850 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 26 Apr 2013 13:25:53 +0800 Subject: [PATCH] Usermode/libpsocket - getnameinfo and other definitions --- .../Libraries/libpsocket.so_src/getaddrinfo.c | 39 +++++++++++++++++++ .../libpsocket.so_src/include_exp/netdb.h | 10 ++++- .../include_exp/netinet/in.h | 7 ++++ .../include_exp/netinet/ip.h | 12 ++++++ .../include_exp/sys/socket.h | 25 +++++++++++- 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 Usermode/Libraries/libpsocket.so_src/include_exp/netinet/ip.h diff --git a/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c b/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c index 57120f0d..c26ce321 100644 --- a/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c +++ b/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c @@ -126,6 +126,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) diff --git a/Usermode/Libraries/libpsocket.so_src/include_exp/netdb.h b/Usermode/Libraries/libpsocket.so_src/include_exp/netdb.h index e9cf7883..09681812 100644 --- a/Usermode/Libraries/libpsocket.so_src/include_exp/netdb.h +++ b/Usermode/Libraries/libpsocket.so_src/include_exp/netdb.h @@ -8,6 +8,12 @@ #define AI_ADDRCONFIG 0x004 #define AI_NUMERICHOST 0x008 +#define NI_NAMEREQD (1<<0) +#define NI_DGRAM (1<<1) +#define NI_NOFQDN (1<<2) +#define NI_NUMERICHOST (1<<3) +#define NI_NUMERICSERV (1<<4) + enum { EAI_SUCCESS, @@ -22,7 +28,8 @@ enum EAI_NODATA, EAI_NONAME, EAI_SERVICE, - EAI_SYSTEM + EAI_SYSTEM, + EAI_OVERFLOW }; struct addrinfo @@ -37,6 +44,7 @@ struct addrinfo struct addrinfo *ai_next; }; +extern int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); extern int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); extern void freeaddrinfo(struct addrinfo *res); const char *gai_strerror(int errorcode); diff --git a/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/in.h b/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/in.h index 33e78659..3a289ebf 100644 --- a/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/in.h +++ b/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/in.h @@ -1,3 +1,10 @@ +/* + * Acess2 POSIX Sockets Emulation + * - By John Hodge (thePowersGang) + * + * netinet/in.h + * - ?Addressing? + */ #ifndef _LIBPSOCKET__NETINET__IN_H_ #define _LIBPSOCKET__NETINET__IN_H_ diff --git a/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/ip.h b/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/ip.h new file mode 100644 index 00000000..433b16db --- /dev/null +++ b/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/ip.h @@ -0,0 +1,12 @@ +/* + * Acess2 POSIX Sockets Emulation + * - By John Hodge (thePowersGang) + * + * netinet/ip.h + * - ??? + */ +#ifndef _LIBPSOCKET__NETINET__IP_H_ +#define _LIBPSOCKET__NETINET__IP_H_ + +#endif + diff --git a/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h b/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h index 4d2a1c23..70eafd18 100644 --- a/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h +++ b/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h @@ -9,7 +9,9 @@ #define _SYS_SOCKETS_H_ #include +#ifndef size_t #include // size_t +#endif #include // uint32_t typedef uint32_t socklen_t; @@ -93,7 +95,16 @@ enum enum { SO_REUSEADDR, - SO_LINGER + SO_LINGER, + SO_ERROR +}; + +// shutdown how +enum +{ + SHUT_RD, + SHUT_WR, + SHUT_RDWR }; /** @@ -102,6 +113,11 @@ enum */ extern int socket(int domain, int type, int protocol); +/** + * + */ +extern int shutdown(int socket, int how); + /** * \brief Bind a socket to an address */ @@ -133,5 +149,12 @@ extern int getsockopt(int socket, int level, int option_name, void *option_value extern int getsockname(int socket, struct sockaddr *addr, socklen_t *addrlen); extern int getpeername(int socket, struct sockaddr *addr, socklen_t *addrlen); +extern struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type); +extern void sethostent(int stayopen); +extern void endhostent(void); +extern void herror(const char *s); +extern const char *hstrerror(int err); +extern struct hostent *gethostent(void); + #endif -- 2.20.1