   Help using gethostbyname()...
  Hello again!  I got another easy one for you...I'm trying to use 'gethostbyname()' so users can either type in an IP address or a computer/domain name.  Well, it works all the way up to where I want to put the resulting info into connect().Let's say I have this:hostent* remoteHost;and I'm using this, where 'host_name' is the name of a computer:remoteHost = gethostbyname(host_name);What do I put in this (where 'client_in' is a sockaddr_in struct)?client_in.sin_addr.s_addrI need a valid 's_addr' in order to do a connect(), and I don't know how to get that address from a computer or domain name.  Would anyone help me on this?Thanks in advance for the help!   
  Easier question...How do I get something I can put in this:client_in.sin_addr.s_addrif all I have is the server computer's name?  I can get it to work fine if I have the server's IP address, but I'd like this to work if I can get a value for this when all I have is the computer's name.   ;Quote:Original post by DookieHello again!  I got another easy one for you...I'm trying to use 'gethostbyname()' so users can either type in an IP address or a computer/domain name.  Well, it works all the way up to where I want to put the resulting info into connect().Let's say I have this:hostent* remoteHost;and I'm using this, where 'host_name' is the name of a computer:remoteHost = gethostbyname(host_name);What do I put in this (where 'client_in' is a sockaddr_in struct)?client_in.sin_addr.s_addrI need a valid 's_addr' in order to do a connect(), and I don't know how to get that address from a computer or domain name.  Would anyone help me on this?Thanks in advance for the help!If I am not mistaken:memcpy(&client_in.sin_addr, hostent->h_addr, hostent->h_length);[Edited by - snisarenko on July 26, 2006 8:34:50 PM];  Thanks for the reply, snisarenko.  I tried what you suggested, but it didn't work...  What I'm doing is almost exactly what you see on this website:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/windows_sockets_error_codes_2.aspLook at it and you'll see at the bottom of the webpage that "the remoteHost structure can now be used to access information about the host".  But it doesn't say how to get that info.  So I'm left trying to figure out how to get the website's IP address into my sockaddr_in struct, and am having pretty lousy luck with it. [sad]  Msdn also says to use 'getaddrinfo' instead of 'gethostbyname', but my programming environment is too old and it doesn't support the newer 'getaddrinfo' function.Has anybody else had any luck getting this to work?   ;  OK, I got it to work.  Turned out I had to do some obscure thing to extract the IP address from the 'hostent' struct...struct hostent *remoteHost;...inet_ntoa( *( struct in_addr*)( remoteHost->h_addr))That 'inet_ntoa' turns the IP address info into a string, so all I needed to do was copy its contents into a character array called 'ip_Text'.  Then I plugged it into my sockaddr_in struct like this:client_in.sin_addr.s_addr = inet_addr (ip_Text);Pretty weird, but it works.  Actually it's all weird to me, but I'm still pretty new to all this sockets-n-stuff.Thanks for the help!  I'll probably post something more challenging in the future, so stay tuned! [grin]   