Surprisingly something as simple as this is eluding me, however I guess this is my first attempt at network programming in *nix.
I'm trying to resolve a host from name (eg: www.google.com) and connect over a TCP connection, however copying the necessary information from the resolved host is apparently not as simple as on Win.
So far this is what I have:
For the record my includes are:
I'm confused as to why it isn't defined as in the man page for gethostbyname(), it is clearly stated h_addr is apart of the hostent struct, I also tried h_addr_list which is also clearly stated on the man page.
Thanks for any help, appreciate it.
I'm trying to resolve a host from name (eg: www.google.com) and connect over a TCP connection, however copying the necessary information from the resolved host is apparently not as simple as on Win.
So far this is what I have:
struct sockaddr_in sAddr; struct hostent sServer; // Set struct sAddr to all zeros. memset(&sAddr, 0, sizeof(sAddr)); // Set family for struct sAddr.sin_family = AF_INET; // Resolve host from address sServer = gethostbyname(sAddress); if (sServer == 0) return false; sAddr.sin_addr.s_addr = *((unsigned long*)sServer->h_addr); // <----- Error here, h_addr isn't defined.
For the record my includes are:
#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h>
I'm confused as to why it isn't defined as in the man page for gethostbyname(), it is clearly stated h_addr is apart of the hostent struct, I also tried h_addr_list which is also clearly stated on the man page.
h_addr The first address in h_addr_list for backward compatibility.
Thanks for any help, appreciate it.