when i’m filling out a SOCKADDR_IN struct for the connect function, i tend to fill it out with the exact ip address, but let’s say i wanted to set up a dynamic domain name online to represent an occasionally changing ip address? I’m not quite sure how i would fill out the struct, given a domain name. What i do now is this:
#define DEFAULT_PORT 12345
SOCKADDR_IN serverInfo;
serverInfo.sin_port=htons(DEFAULT_PORT);
serverInfo.sin_family=AF_INET;
serverInfo.sin_addr.s_addr= inet_addr("127.0.0.1"); // actual ip normally here
but how do you resolve domain names to get the ip of the server for this struct?
You want to use the
gethostbynamefunctionhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms738524%28v=vs.85%29.aspx