Jump to content
  • Advertisement
Sign in to follow this  
bengaltgrs

Simple beginner questions

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When creating the client side socket using WinSock, how do I input an actual IP where "ip" is in the following: htonl(ip). I tried putting in a few different formats but say I wanted to put in the IP, "198.162.0.1" how would I go about converting that into a format that the htonl() function can read? Also, I tried using telnet in the command promt with windows xp and got no connection every time, why can it not connect to anything? -Chris

Share this post


Link to post
Share on other sites
Advertisement
htons is for your port, not the ip.

(in this case szServer is a null terminated C style string containing the ip address)

sockaddr_in servAddr;
(...)
servAddr.sin_addr.s_addr=inet_addr(szServer);
servAddr.sin_port=htons(iPort);

Share this post


Link to post
Share on other sites
I see, I read a networking sample somewhere that said to use htons() for port and htonl() for ip, does it make a difference if I use inet_addr() in place of htonl() or will it be pretty much the same thing?

-Chris

Share this post


Link to post
Share on other sites
inet_addr() takes a string, and returns a properly-formatted address.

htonl() takes a long, and returns a properly formatted long (which can be used as the address).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!