From: | "Chuck McDevitt" <cmcdevitt(at)greenplum(dot)com> |
---|---|
To: | pgsql-patches(at)postgresql(dot)org |
Cc: | "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Proposed patch to getaddrinfo.c to support IPv6 on Windows |
Date: | 2005-08-24 19:01:32 |
Message-ID: | BB05A27C22288540A3A3E8F3749B45AB0159CB30@MI8NYCMAIL06.Mi8.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
I'm proposing this change to /src/port/getaddrinfo.c to support IPv6
under windows.
10a11,14
> * Windows may or may not have these routines, so we handle Windows
special
> * by dynamically checking for their existence. If they already
exist, we
> * use the Windows native routines, but if not, we use our own.
> *
31a36,121
>
> #ifdef WIN32
>
> #define WIN32_LEAN_AND_MEAN
> /* Bring in windows.h for LoadLibrary, FreeLibrary, and GetProcAddress
routines */
> #include <windows.h>
>
> /*
> * The native routines may or may not exist on the Windows platform we
are on,
> * so we dynamically look up the routines, and call them via function
pointers.
> * Here we need to declare what the function pointers look like
> */
> typedef
> int
> (__stdcall * getaddrinfo_ptr_t)(const char * nodename, const char *
servname,
> const struct addrinfo * hints, struct addrinfo ** res);
>
> typedef
> void
> (__stdcall * freeaddrinfo_ptr_t)(struct addrinfo * ai);
>
> typedef
> int
> (__stdcall * getnameinfo_ptr_t)(const struct sockaddr * sa, int salen,
> char * host, int hostlen, char * serv, int servlen, int flags);
>
> /* static pointers to the native Windows IPv6 routines, so we only do
the lookup once. */
> static getaddrinfo_ptr_t getaddrinfo_ptr = NULL;
> static freeaddrinfo_ptr_t freeaddrinfo_ptr = NULL;
> static getnameinfo_ptr_t getnameinfo_ptr = NULL;
>
> static
> bool haveNativeWindowsIPv6routines(void)
> {
> void * hLibrary = NULL;
> static bool alreadyLookedForIpv6routines = FALSE;
>
> if (alreadyLookedForIpv6routines)
> return (getaddrinfo_ptr != NULL);
>
> /*
> * For Windows XP and Windows 2003 (and longhorn/vista), the IPv6
> * routines are present the WinSock 2 library (ws2_32.dll). Try
that first
> */
>
> hLibrary = LoadLibraryA("ws2_32");
>
> if (hLibrary == NULL || GetProcAddress(hLibrary, "getaddrinfo") ==
NULL)
> {
> /* Well, ws2_32 doesn't exist, or more likely doesn't have
getaddrinfo. */
> if (hLibrary != NULL)
> FreeLibrary(hLibrary);
>
> /* In Windows 2000, there was only the IPv6 Technology
Preview
> * look in the IPv6 WinSock library (wship6.dll).
> */
>
> hLibrary = LoadLibraryA("wship6");
> }
>
> /* If hLibrary is null, we couldn't find a dll that supports the
functions */
> if (hLibrary != NULL)
> {
> /* We found a dll, so now get the addresses of the routines
*/
>
> getaddrinfo_ptr = GetProcAddress(hLibrary, "getaddrinfo");
> freeaddrinfo_ptr = GetProcAddress(hLibrary, "freeaddrinfo");
> getnameinfo_ptr = GetProcAddress(hLibrary, "getnameinfo");
>
> /* If any one of the routines is missing, let's play it safe
and ignore them all */
> if (getaddrinfo_ptr == NULL || freeaddrinfo_ptr == NULL ||
getnameinfo_ptr == NULL)
> {
> FreeLibrary(hLibrary);
> hLibrary = NULL;
> getaddrinfo_ptr = NULL;
> freeaddrinfo_ptr = NULL;
> getnameinfo_ptr = NULL;
> }
> }
>
> alreadyLookedForIpv6routines = TRUE;
> return (getaddrinfo_ptr != NULL);
> }
> #endif
>
>
49a140,148
> #ifdef WIN32
> /*
> * If Windows has native IPv6 support, use the native Windows
routine.
> * Otherwise, fall through and use our own code.
> */
> if (haveNativeWindowsIPv6routines())
> return (*getaddrinfo_ptr)(node,service,hintp,res);
> #endif
>
162a262,272
> #ifdef WIN32
> /*
> * If Windows has native IPv6 support, use the native
Windows routine.
> * Otherwise, fall through and use our own code.
> */
> if (haveNativeWindowsIPv6routines())
> {
> (*freeaddrinfo_ptr)(node,service,hintp,res);
> return;
> }
> #endif
218a329,338
>
> #ifdef WIN32
> /*
> * If Windows has native IPv6 support, use the native Windows
routine.
> * Otherwise, fall through and use our own code.
> */
> if (haveNativeWindowsIPv6routines())
> return
(*getnameinfo_ptr)(sa,salen,node,nodelen,service,servicelen,flags);
> #endif
>
Attachment | Content-Type | Size |
---|---|---|
getaddrinfo.patch | application/octet-stream | 4.1 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2005-08-24 19:07:30 | Re: Proposed patch to getaddrinfo.c to support IPv6 on Windows |
Previous Message | John Hansen | 2005-08-24 18:53:47 | Re: FreeBSD ICU was Win32 unicode vs ICU |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2005-08-24 19:07:30 | Re: Proposed patch to getaddrinfo.c to support IPv6 on Windows |
Previous Message | Kevin McArthur | 2005-08-24 16:58:59 | FreeBSD ICU was Win32 unicode vs ICU |