diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/xhost/inet.c | 88 | ||||
-rw-r--r-- | apps/xhost/makefile | 29 | ||||
-rw-r--r-- | apps/xhost/xhost.c | 21 |
3 files changed, 128 insertions, 10 deletions
diff --git a/apps/xhost/inet.c b/apps/xhost/inet.c new file mode 100644 index 000000000..e6c0a1554 --- /dev/null +++ b/apps/xhost/inet.c @@ -0,0 +1,88 @@ +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#ifdef WIN32 +#include <X11/Xwinsock.h> +#endif + +#include <stdio.h> +#include <stdlib.h> + +#if NTDDI_VERSION < NTDDI_VISTA +const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) +{ + if (af == AF_INET) + { + struct sockaddr_in in; + memset(&in, 0, sizeof(in)); + in.sin_family = AF_INET; + memcpy(&in.sin_addr, src, sizeof(struct in_addr)); + if (getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST) != 0) + { + errno = WSAGetLastError(); + return NULL; + } + else return dst; + } + else if (af == AF_INET6) + { + struct sockaddr_in6 in; + memset(&in, 0, sizeof(in)); + in.sin6_family = AF_INET6; + memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); + if (getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST) != 0) + { + errno = WSAGetLastError(); + return NULL; + } + else return dst; + } + errno = WSAEAFNOSUPPORT; + return NULL; +} + +int inet_pton(int af, const char *src, void *dst) +{ + struct sockaddr_storage ss; + int sslen = sizeof(ss); + if (af == AF_INET) + { + struct in_addr out; + char buffer[INET_ADDRSTRLEN + 1]; + strncpy (buffer, src, INET_ADDRSTRLEN); + buffer [INET_ADDRSTRLEN] = '\0'; + if (WSAStringToAddressA(buffer, AF_INET, NULL, (struct sockaddr*)&ss, &sslen) == SOCKET_ERROR) + { + errno = WSAGetLastError(); + return 0; + } + else + { + out = ((struct sockaddr_in *)&ss)->sin_addr; + memcpy (dst, &out, sizeof(struct in_addr)); + return 1; + } + } + else if (af == AF_INET6) + { + struct in6_addr out6; + char buffer6[INET6_ADDRSTRLEN + 1]; + strncpy (buffer6, src, INET6_ADDRSTRLEN); + buffer6 [INET6_ADDRSTRLEN] = '\0'; + if (WSAStringToAddressA(buffer6, AF_INET6, NULL, (struct sockaddr*)&ss, &sslen) == SOCKET_ERROR) + { + errno = WSAGetLastError(); + return 0; + } + else + { + out6 = ((struct sockaddr_in6 *)&ss)->sin6_addr; + memcpy (dst, &out6, sizeof(struct in6_addr)); + return 1; + } + } + errno = WSAEAFNOSUPPORT; + return -1; +} +#endif diff --git a/apps/xhost/makefile b/apps/xhost/makefile new file mode 100644 index 000000000..357b93fb3 --- /dev/null +++ b/apps/xhost/makefile @@ -0,0 +1,29 @@ +DEFINES += BAD_ARPAINET TCPCONN IPv6 + +TTYAPP = xhost + +INCLUDELIBFILES = \ + $(MHMAKECONF)\libX11\src\xkb\$(OBJDIR)\libxkb.lib \ + $(MHMAKECONF)\libX11\src\xlibi18n\$(OBJDIR)\libi18n.lib \ + $(MHMAKECONF)\libX11\modules\lc\xlocale\$(OBJDIR)\libxlocale.lib \ + $(MHMAKECONF)\libX11\modules\lc\utf8\$(OBJDIR)\libxlcUTF8Load.lib \ + $(MHMAKECONF)\libX11\modules\lc\def\$(OBJDIR)\libxlcDef.lib \ + $(MHMAKECONF)\libX11\modules\om\generic\$(OBJDIR)\libxomGeneric.lib \ + $(MHMAKECONF)\libX11\modules\lc\gen\$(OBJDIR)\liblcGenConvLoad.lib \ + $(MHMAKECONF)\libX11\modules\im\ximcp\$(OBJDIR)\libximcp.lib \ + $(MHMAKECONF)\libxcb\src\$(OBJDIR)\libxcb.lib \ + $(MHMAKECONF)\libxau\$(OBJDIR)\libXau.lib \ + $(MHMAKECONF)\libXmu\src\$(OBJDIR)\libXmu.lib \ + $(MHMAKECONF)\libX11\src\$(OBJDIR)\libx11.lib \ + +LIBDIRS=$(dir $(INCLUDELIBFILES)) + +load_makefile $(LIBDIRS:%$(OBJDIR)\=%makefile MAKESERVER=0 DEBUG=$(DEBUG);) + +ifeq ($(DEBUG),1) +LINKLIBS += $(MHMAKECONF)\pthreads\pthreadVC2d.lib +else +LINKLIBS += $(MHMAKECONF)\pthreads\pthreadVC2.lib +endif + +CSRCS = xhost.c inet.c diff --git a/apps/xhost/xhost.c b/apps/xhost/xhost.c index c7faeff6b..5724e945e 100644 --- a/apps/xhost/xhost.c +++ b/apps/xhost/xhost.c @@ -163,6 +163,16 @@ static volatile int nameserver_timedout; static char *ProgramName; +#ifdef WIN32 +#define alarm(arg) + +void sethostent(int x) +{} + +void endhostent() +{} +#endif + #ifdef NEEDSOCKETS static int XFamily(int af) @@ -791,7 +801,7 @@ get_hostname(XHostAddress *ha) sa.sa_handler = nameserver_lost; sa.sa_flags = 0; /* don't restart syscalls */ sigaction(SIGALRM, &sa, NULL); -#else +#elif !defined(WIN32) signal(SIGALRM, nameserver_lost); #endif alarm(NAMESERVER_TIMEOUT); @@ -969,12 +979,3 @@ local_xerror(Display *dpy, XErrorEvent *rep) XmuPrintDefaultErrorMessage (dpy, rep, stderr); return 0; } - -#ifdef __CYGWIN__ -void sethostent(int x) -{} - -void endhostent() -{} -#endif - |