Wednesday, September 3, 2008

Windows IPv6 Socket Clients

Just got through building my very first windows IPv6 socket client and server, I am using them for validating that the application I am testing, can detect the IPv6 sockets across machines.  Lots of fun stuff.

In trying to get the code to build on Windows 2003 Server, using Visual Studio, I had to add the following into the include directives to get them fixed.  Since it took me some searching to get this done let me go over some of this.  My code is as follows (and yes its probably not good form, but like I said, this is my first Windows app, I've taken 1 C++ course and read a couple of books and looked at some example code...I'm a total newbie on this).

First the ifdef, I needed to define WIN32 in the project properties under C/C++/PreProcessor Directives

#ifndef WIN32
   
 #else

This pragma was to get rid of a Warning due to a conversion from size_t to int problem where I was holding the result of the bind operation in an int in order to be able to tell what the status was later on.
#pragma warning(disable:4267)
There were problems due to linker errors which are due to ws2_32.lib and iphlpapi.lib not being found on the path, I also needed to add in the libraries to the Visual Studio Platform SDK, and I even placed in the latest Microsoft SDK on my local box, then in the project options under Linker/General/Additional Libraries added the paths to the two SDK's.  I'm still not sure I need both of these or not, but they are there just in case.
#pragma comment(lib, "IPHlpApi")
#pragma comment(lib,"ws2_32")


Because I am trying to use IPv6 operations in these apps, I need the updated winsock library, not the older one that only supports IPv4.
#include
End the if directive.
#endif
A couple of other items I had to add:
  • When trying to build this for IPv6 I kept getting warnings about sprintf being insecure, and deprecated, this was removed by adding _CRT_SECURE_NO_WARNINGS in the PreProcessor directives.
  • I needed the pragma lines because the Linker was having problems with the socket operations and would give me errors regarding LNK2019: unresolved external symbol
That's it for now...I'm sure I'll be getting back to this, I still need to do work on the code, but I definitely need more practice.

No comments: