Simple beginner questions
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
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);
(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
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
-Chris
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement