I have done the following:
irb(main):103:0> response = Socket::gethostbyname('www.ebay.com')
=> ["pages.ebay.com", [], 2,
"\020\002\000\000B\207\300X\000\000\000\000\000\000\000\000",
"\020\002\000\000B\207\320X\000\000\000\000\000\000\000\000",
"\020\002\000\000B\207\320e\000\000\000\000\000\000\000\000",
"\020\002\000\000B\207\300W\000\000\000\000\000\000\000\000"]
irb(main):104:0>
What exactly are the 4 entries that are after the 2 in the array? From
looking at the man page for gethostbyname(), it should return something
resembling:
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
};
I am thinking that the 4 entries after the '2' is the addr_list. I
would kind of expect them to be in a sub array, but back to the question
as to the format. From the command prompt:
[~]host www.ebay.com
www.ebay.com is an alias for pages.ebay.com.
pages.ebay.com has address 66.135.208.101
pages.ebay.com has address 66.135.192.87
pages.ebay.com has address 66.135.192.88
pages.ebay.com has address 66.135.208.88
[~]
I don't see how any of the above strings corresponds to the 4 ebay
addresses. I can see how parts of the string correspond to the IP address.
irb(main):162:0> a1 = response[3]
=> "\020\002\000\000B\207\320X\000\000\000\000\000\000\000\000"
irb(main):163:0> a1.each_byte {|x| puts x}
16
2
0
0
66
135
208
88
0
....
0
=> "\020\002\000\000B\207\320X\000\000\000\000\000\000\000\000"
irb(main):164:0>
I can see that there is a slightly different call
TCPSocket::gethostbyname that returns what I am looking for:
irb(main):165:0> response = TCPSocket::gethostbyname('www.ebay.com')
=> ["pages.ebay.com", [], 2, "66.135.208.88", "66.135.208.101",
"66.135.192.87", "66.135.192.88"]
irb(main):166:0>
I am new and I am wondering where I would look into the documentation to
get the specifics on this. I tried using
http://www.ruby-doc.org/stdlib/, but I don't see enough details. What
exactly is the relationship between Socket and TCPSocket?