Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

gethostbyname() problem under Windows 7.

$
0
0

I have an application that was written for Windows XP.  It has a full set of unit tests.  When I run the unit tests under Windows 7, several of the tests fail.  All unit tests passed under XP.

I am calling gethostbyname() with an invalid host name ("badhostname") to test the failure scenario.  Under XP, gethostbyname() returns NULL, as documented.  Under Windows 7, gethostbyname() returns a valid pointer to a hostent structure.  That structure contains a valid pointer to the h_addr_list[] array, which contains garbage for an IP address, but the string at h_addr_list[] includes the bad host name appended with ".Home".

BTW - I get the same thing if I try to ping the bad host name - "pinging badhostname.Home [198.105.251.23] ..."

I know gethostbyname() has been deprecated, but I wouldn't expect the functionality to have changed.

Code snippet:

struct hostent const *const p_host_entry = gethostbyname ( "badhostname" );
if ( p_host_entry == 0 )
{
    // throw an exception - but this exception is never thrown.
}



Viewing all articles
Browse latest Browse all 15302

Trending Articles