Re: getaddrinfo in XP,9x,etc - how?
- From: "Alan J. McFarlane" <alanjmcf@xxxxxxxxxxxxxxxxx>
- Date: Thu, 11 Aug 2005 19:14:10 +0100
In article news:ddfta3$bn7$1@xxxxxxxxxxxxxxx, qfel wrote:
In article news:42FB7311.5EEC412@xxxxxxxxxxxxx, The Other Roger wrote:The most recent MSDN documentation on getaddrinfo http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp states that the function is compatible on client OS's all the way back to Win95. dumpbin on ws2_32.dll in an XP system shows that the function's entry point is #98 however I haven't found this entry point in the ws2_32.dll on Win2K or any earlier system. Is there a way to make getaddrinfo work on systems that precede XP? Note that the documentation for gethostbyname states that it is deprecated and getaddrinfo should be used for new applications.
It is implemented in ws2_32.lib, so unless you define _WIN32_WINNT to 0x0501 or higher it will get linked in your code instead of being imported from ws2_32.dll.
Except that there is also another version! See WSpiApi.h and http://www.developer.com/tech/article.php/10923_3382721_1 Has noone got grep on their systems these days. :-)
In brief, WSpiApi.h attempts to find the exports in ws2_32.dll, and in wship6.dll for the Windows 2000 IPv6 Preview, and if so uses them. Otherwise it uses its inline versions. This is nasty horrible stuff but it is required for backward compatibility with older systems including that IPv6 preview.
Now this kludge is only required if you are targetting such platforms. For solely XP and later it is not required. From WS2tcpip.h: #if !defined(_WIN32_WINNT) || (_WIN32_WINNT <= 0x0500) #include <wspiapi.h> #endif
So check carefully what you--or the environment you inherit--are doing regards _WIN32_WINNT (and WINVER for completeness).
Note that in the previous thread you did: #include <windows.h>
The result of that is the inclusion of the Winsock 'One', and *not* the Winsock2 header file. If one then includes <ws2tcpip.h>, then horrible things happen, resulting in eight thousand errors.
So, to use Winsock2 (don't use Winsock 1) my recommendation is to do either:
1.
#define WIN32_LEAN_AND_MEAN
//
#include <windows.h>
//
#include <winsock2.h>
#include <ws2tcpip.h>
or
2.
#include <winsock2.h>
#include <ws2tcpip.h>
I strongly prefer the former. It is much clearer, imagine what occurs when some fool comes along and adds <windows.h> to the latter. Disaster...
Also no Windows program should be non-Unicode so I also recommend all of the following too.
#define UNICODE //the SDK
#define _UNICODE //the compiler/library
#define STRICT
But that's another discussion.
Anyway, the MSDN words on headers (now with reference to all of those macros, after I complained last time this came up here) are at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/using_the_windows_headers.asp
See how that helps Roger, and take things step by step. Don't go anywhere near MFC, nor, especially Precompiled Headers, until you're happy with Winsock stuff. Also make use of the compiler's ability to show the result of its preprocessing, e.g. /P etc, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_.2f.p.asp
--
Alan J. McFarlane
http://www.alanjmcf.me.uk/
Please follow-up in the newsgroup for the benefit of all.
.
- Follow-Ups:
- Re: getaddrinfo in XP,9x,etc - how?
- From: qfel
- Re: getaddrinfo in XP,9x,etc - how?
- References:
- getaddrinfo in XP,9x,etc - how?
- From: The Other Roger
- Re: getaddrinfo in XP,9x,etc - how?
- From: qfel
- getaddrinfo in XP,9x,etc - how?
- Prev by Date: Re: How can I tell when a remote TCP connection is closed?
- Next by Date: Re: getaddrinfo in XP,9x,etc - how?
- Previous by thread: Re: getaddrinfo in XP,9x,etc - how?
- Next by thread: Re: getaddrinfo in XP,9x,etc - how?
- Index(es):
Relevant Pages
|