My networking code works fine on XP but on vista there seems to be a problem. I am fairly sure that the problem lies with the command 'inet_addr' which converts the IP from decimal to binary. The command seems to fail with INADDR_NONE even when the IP is acceptable.
The documentation suggests to me that vista should work fine with the command since vista is on the list of compatible operating systems but it mentions another method of converting the IP for vista only:
Quote: "On Windows Vista and later, the RtlIpv4StringToAddress function can be used to convert a string representation of an IPv4 address to a binary IPv4 address represented as an IN_ADDR structure. On Windows Vista and later, the RtlIpv6StringToAddress function can be used to convert a string representation of an IPv6 address to a binary IPv6 address represented as an IN6_ADDR structure. "
I wrote a little test that should determine whether or not it is this command that's the problem, I have attached it and it has the following code:
#include <iostream>
#include <winsock2.h>
#include <ws2tcpip.h>
using namespace std;
int main()
{
cout << "TEST 1n";
unsigned long ulNetAddr1 = inet_addr("127.0.0.1");
if(ulNetAddr1 == INADDR_NONE)
{
cout << "Error: INADDR_NONEn";
}
if(ulNetAddr1 == 16777343)
{
cout << "Converted addr is correctn";
}
else
{
cout << "Converted addr is incorrect, should be 16777343n";
}
cout << "Converted addr: '"<<ulNetAddr1<<"'nn";
cout << "TEST 2n";
unsigned long ulNetAddr2 = inet_addr("");
if(ulNetAddr2 == INADDR_NONE)
{
cout << "Error: INADDR_NONEn";
}
if(ulNetAddr2 == 0)
{
cout << "Converted addr is correctn";
}
else
{
cout << "Converted addr is incorrect, should be 0n";
}
cout << "Converted addr: '"<<ulNetAddr2<<"'nn";
int Blank;
cin >> Blank;
}
In summary:
1. Those of you who have vista, could you please download the test and run it; post the results.
2. How can I determine whether the user is using vista or not?
3. Has anyone had trouble with inet_addr in this context?