about gethostbyname in winsock

Started by
3 comments, last by ironhead 19 years, 5 months ago
I have to program with Winsock recently, and have a problem when using function gethostbyname. I try to get IP by calling the function with domain name like this : gethostbyname("D2004.ddns.lala.com"); then I could get an IP Address. but this one is IP of a ddns server. How can I get the real IP of the server ? Should I try to contact with ddns server or Is there any function work for this purpose ?? Thanks for any help : )
Advertisement
Just call gethostbyname() on whatever the actual name of the server is.

If the actual name of the server is D2004.ddns.lala.com, then whatever is returned by that query, is the record for that server name, and the address you should use. If that doesn't work, then something's wrong on the DDNS side, not in gethostbyname().
enum Bool { True, False, FileNotFound };
Thanks for your reply, I try again and again but it still not work correctly.

This domain name is what I use for testing my program :
D7501.ddns.iview-ddns.com

Using gethostbyname() I will get ip "211.75.21.14", but the real ip I should get is "202.168.200.151".
Its strange because when using IE to connect http::\\D7501.ddns.iview-ddns.com, IE will connect to 202.168.200.151, it work perfectly. And this is why I still try to find another method.

Here is my simple testing code:

bool SocketStartUp(void)
{
WSADATA wsaData;

int Status = WSAStartup(MAKEWORD(2, 0), &wsaData);
if(Status)
return false;
return true;
}

bool SocketShutDown(void)
{
if(WSACleanup() == SOCKET_ERROR)
return false;
return true;
}

int main(int argc, char** argv)
{
if(SocketStartUp())
std::cout << "Start Success !!!" << std::endl;
else
{
std::cout << "Start Failed !!!" << std::endl;
return 1;
}

LPHOSTENT lphost(0);
lphost = gethostbyname("D7501.ddns.iview-ddns.com");
if(lphost)
{
in_addr addr;
std::string name;

addr.S_un.S_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr;
name = inet_ntoa(addr);
std::cout << name << std::endl;

std::cout << lphost->h_addr_list[0] << std::endl;
}

SocketShutDown();
}

Thanks for any Help.
IE will use proxying and redirects to get to the final destination.

If you "ping" that location, where will you end up?

If you run Ethereal on the session where IE connects to that URL (forward slashes, btw!), what happens on the wire?
enum Bool { True, False, FileNotFound };
Thank you very much!!!

I have resolve this problem,
and my program could work correctly now.
After using the tool "Ethereal",
I send some message to server like IE does,
then the message that server replied have real IP I need.

Thank you for mentioning this helpful Tool.

This topic is closed to new replies.

Advertisement