Skip to main content
gamedev.net
🔒 Locked

Simple beginner questions

Started by smittix Aug 25, 2005 at 8:13 PM 2 replies 850+ views
Original Post
smittix
smittix
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
Horatius83
Horatius83
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);
"Think you Disco Duck, think!" Professor Farnsworth
smittix
smittix
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
hplus0603
hplus0603
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).
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.