Re: getaddrinfo in XP,9x,etc - how?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.


.



Relevant Pages

  • Re: Header and Footer missing: Word 2003 doc edited in Word 2000
    ... Is it possible that you have Word 2000 opening in "Normal View" and Word ... Normal view does not show headers and footers. ... I'm starting to guess there is compatibility issues between Word 2k and Word ...
    (microsoft.public.word.docmanagement)
  • Re: Maximum swap size
    ... but I find the whole IPv6 concept seriously flawed ... Alas, too much time was spent trying to maintain compatibility with IPv4, ... degrading devices are few and far between, and almost all IPv6 traffic is ...
    (alt.os.linux.suse)
  • Create live link to text
    ... redo this task in 2003 for compatibility with another person. ... I have a report with a Title on the first page, and headers throughout the ... I read forums on Bookmarks, but it did not work for me. ...
    (microsoft.public.word.pagelayout)
  • Re: C portability is a myth
    ... > Randy Howard wrote: ... you may see yourself including a lot of headers that don't ... everyC function listed in MSDN has a compatibility section ...
    (comp.lang.c)
  • Re: Pan crashing in libgnuregex after -pthread switchover
    ... > Idea that library must match headers used is pretty natural. ... the ports which expects _binary_ compatibility between ... our headers and some 3rd party library are broken initially. ...
    (freebsd-current)