🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
One more thing about about tcp/ip address...
What header files do I need to include in my project to
use the following code? Where do the data structures come from?
in_addr *getOurInfo(){
HOSTENT *hostEntry; // Pointer to host entry structure // Find the full internet info for this computer. hostEntry = gethostbyname("localhost");
hostEntry = gethostbyname(hostEntry->h_name);
printf("\nHost Name........: %s", hostEntry->h_name);
return (in_addr *)hostEntry->h_addr_list[0];
};
I need to be able to show a player his own TCP address to
he can give it to other players if he wants to host a session.
To get those functions working you need to include the Winsock header file and link to the Winsock library. You can include and use the older Winsock 1.1 library or, if you have it installed, use the newer Winsock 2.0 library.
To use Winsock 1.1, include winsock.h and link to WSOCK32.LIB
To use Winsock 2.0, include winsock2.h and link to WS2_32.LIB
Winsock 2.0 is usually present on the client machine; Windows 98, NT, and 2000 have it by default. If the client is an original Windows 95 machine, then Winsock 2.0 must be installed. You can download Winsock 2.0 for free from Microsoft.
Hope that helps..
// CHRIS
To use Winsock 1.1, include winsock.h and link to WSOCK32.LIB
To use Winsock 2.0, include winsock2.h and link to WS2_32.LIB
Winsock 2.0 is usually present on the client machine; Windows 98, NT, and 2000 have it by default. If the client is an original Windows 95 machine, then Winsock 2.0 must be installed. You can download Winsock 2.0 for free from Microsoft.
Hope that helps..
// CHRIS
To get those functions working you need to include the Winsock header file and link to the Winsock library. You can include and use the older Winsock 1.1 library or, if you have it installed, use the newer Winsock 2.0 library.
To use Winsock 1.1, include winsock.h and link to WSOCK32.LIB
To use Winsock 2.0, include winsock2.h and link to WS2_32.LIB
Winsock 2.0 is usually present on the client machine; Windows 98, NT, and 2000 have it by default. If the client is an original Windows 95 machine, then Winsock 2.0 must be installed. You can download Winsock 2.0 for free from Microsoft.
Hope that helps..
// CHRIS
To use Winsock 1.1, include winsock.h and link to WSOCK32.LIB
To use Winsock 2.0, include winsock2.h and link to WS2_32.LIB
Winsock 2.0 is usually present on the client machine; Windows 98, NT, and 2000 have it by default. If the client is an original Windows 95 machine, then Winsock 2.0 must be installed. You can download Winsock 2.0 for free from Microsoft.
Hope that helps..
// CHRIS
I am having trouble getting this code to work. It compiles but the hostEntry is NULL.
Thanks
int main(int argc, char* argv[])
{
in_addr *addr;
HOSTENT *hostEntry; // Pointer to host entry structure // Find the full internet info for this computer.
hostEntry = gethostbyname("localhost");
hostEntry = gethostbyname(hostEntry->h_name);
printf("\nHost Name........: %s", hostEntry->h_name);
// return (in_addr *)hostEntry->h_addr_list[0];
addr = (in_addr *) hostEntry->h_addr_list[0];
printf("%d.%d.%d.%d\n", addr->S_un.S_un_b.s_b1, addr->S_un.S_un_b.s_b2,
addr->S_un.S_un_b.s_b3, addr->S_un.S_un_b.s_b4);
}
Thanks
int main(int argc, char* argv[])
{
in_addr *addr;
HOSTENT *hostEntry; // Pointer to host entry structure // Find the full internet info for this computer.
hostEntry = gethostbyname("localhost");
hostEntry = gethostbyname(hostEntry->h_name);
printf("\nHost Name........: %s", hostEntry->h_name);
// return (in_addr *)hostEntry->h_addr_list[0];
addr = (in_addr *) hostEntry->h_addr_list[0];
printf("%d.%d.%d.%d\n", addr->S_un.S_un_b.s_b1, addr->S_un.S_un_b.s_b2,
addr->S_un.S_un_b.s_b3, addr->S_un.S_un_b.s_b4);
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement