Skip to content

Commit 09a6c90

Browse files
committed
Fix bogus freeaddrinfo() call in WIN32 code, extend gai_strerror to
cover more error codes. Per Petr Jelinek.
1 parent 1a33436 commit 09a6c90

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

src/include/getaddrinfo.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
1717
*
18-
* $PostgreSQL: pgsql/src/include/getaddrinfo.h,v 1.15 2005/07/27 12:44:10 neilc Exp $
18+
* $PostgreSQL: pgsql/src/include/getaddrinfo.h,v 1.16 2005/08/25 17:50:59 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -31,6 +31,7 @@
3131
/* Various macros that ought to be in <netdb.h>, but might not be */
3232

3333
#ifndef EAI_FAIL
34+
#ifndef WIN32
3435
#define EAI_BADFLAGS (-1)
3536
#define EAI_NONAME (-2)
3637
#define EAI_AGAIN (-3)
@@ -40,7 +41,18 @@
4041
#define EAI_SERVICE (-8)
4142
#define EAI_MEMORY (-10)
4243
#define EAI_SYSTEM (-11)
43-
#endif
44+
#else /* WIN32 */
45+
#define EAI_AGAIN WSATRY_AGAIN
46+
#define EAI_BADFLAGS WSAEINVAL
47+
#define EAI_FAIL WSANO_RECOVERY
48+
#define EAI_FAMILY WSAEAFNOSUPPORT
49+
#define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
50+
#define EAI_NODATA WSANO_DATA
51+
#define EAI_NONAME WSAHOST_NOT_FOUND
52+
#define EAI_SERVICE WSATYPE_NOT_FOUND
53+
#define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
54+
#endif /* !WIN32 */
55+
#endif /* !EAI_FAIL */
4456

4557
#ifndef AI_PASSIVE
4658
#define AI_PASSIVE 0x0001

src/port/getaddrinfo.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/port/getaddrinfo.c,v 1.18 2005/08/24 22:13:23 tgl Exp $
19+
* $PostgreSQL: pgsql/src/port/getaddrinfo.c,v 1.19 2005/08/25 17:51:01 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -103,9 +103,12 @@ haveNativeWindowsIPv6routines(void)
103103
{
104104
/* We found a dll, so now get the addresses of the routines */
105105

106-
getaddrinfo_ptr = GetProcAddress(hLibrary, "getaddrinfo");
107-
freeaddrinfo_ptr = GetProcAddress(hLibrary, "freeaddrinfo");
108-
getnameinfo_ptr = GetProcAddress(hLibrary, "getnameinfo");
106+
getaddrinfo_ptr = (getaddrinfo_ptr_t) GetProcAddress(hLibrary,
107+
"getaddrinfo");
108+
freeaddrinfo_ptr = (freeaddrinfo_ptr_t) GetProcAddress(hLibrary,
109+
"freeaddrinfo");
110+
getnameinfo_ptr = (getnameinfo_ptr_t) GetProcAddress(hLibrary,
111+
"getnameinfo");
109112

110113
/*
111114
* If any one of the routines is missing, let's play it safe and
@@ -277,7 +280,7 @@ freeaddrinfo(struct addrinfo * res)
277280
*/
278281
if (haveNativeWindowsIPv6routines())
279282
{
280-
(*freeaddrinfo_ptr) (node, service, hintp, res);
283+
(*freeaddrinfo_ptr) (res);
281284
return;
282285
}
283286
#endif
@@ -310,15 +313,40 @@ gai_strerror(int errcode)
310313
}
311314

312315
return hstrerror(hcode);
313-
#else /* !HAVE_HSTRERROR */
316+
317+
#else /* !HAVE_HSTRERROR */
314318

315319
switch (errcode)
316320
{
317321
case EAI_NONAME:
318322
return "Unknown host";
319323
case EAI_AGAIN:
320324
return "Host name lookup failure";
321-
case EAI_FAIL:
325+
/* Errors below are probably WIN32 only */
326+
#ifdef EAI_BADFLAGS
327+
case EAI_BADFLAGS:
328+
return "Invalid argument";
329+
#endif
330+
#ifdef EAI_FAMILY
331+
case EAI_FAMILY:
332+
return "Address family not supported";
333+
#endif
334+
#ifdef EAI_MEMORY
335+
case EAI_MEMORY:
336+
return "Not enough memory";
337+
#endif
338+
#ifdef EAI_NODATA
339+
case EAI_NODATA:
340+
return "No host data of that type was found";
341+
#endif
342+
#ifdef EAI_SERVICE
343+
case EAI_SERVICE:
344+
return "Class type not found";
345+
#endif
346+
#ifdef EAI_SOCKTYPE
347+
case EAI_SOCKTYPE:
348+
return "Socket type not supported";
349+
#endif
322350
default:
323351
return "Unknown server error";
324352
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy