Yes, gethostbyname() should take the string "www.google.com"
Separately, the Host: header does not include the protocol, but it (can) include the port number. Thus, the Host: header should be "www.google.com" or "www.google.com:80" not "http://www.google.com"
I wrote a small library to do exactly what you want to do, and the last version update was 11 years ago. Time flies ... You may want to read the source code: http://www.enchantedage.com/http-get