简体   繁体   中英

WINVER, winsock and htonl()

When I don't define WINVER, my (msvc9) build is peppered with warnings and it says it is defaulting to 0x0600 (Vista) but it builds OK. When I define WINVER = 0x501 (XP), I get this error :-

error C3861: 'htonl': identifier not found

I'd rather use WINVER=0x0501 than 0x0600 but I don't know how to fix it!

I noticed something in http://west-chamber-season-2.googlecode.com/svn-history/r2/trunk/wcs2_cli.c

#ifdef WINVER
#include <winsock.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif

Do I need to do something odd like this? Any ideas?

If you are compiling for windows then #include winsock2.h and ws2tcpip.h and link to ws2_32.lib. Also ensure you call WSAStartup before you try any networking functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM