[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Socket::gethostbyname

CarlosRivera

10/3/2004 6:01:00 AM

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.o..., but I don't see enough details. What
exactly is the relationship between Socket and TCPSocket?
5 Answers

ts

10/3/2004 8:08:00 AM

0

>>>>> "C" == CarlosRivera <CarlosRivera@badnamefornospam.to> writes:

C> [~]host www.ebay.com
C> www.ebay.com is an alias for pages.ebay.com.
C> pages.ebay.com has address 66.135.208.101
C> pages.ebay.com has address 66.135.192.87
C> pages.ebay.com has address 66.135.192.88
C> pages.ebay.com has address 66.135.208.88
C> [~]

svg% ruby -rsocket
Socket::gethostbyname("www.ebay.com")[3..-1].each do |ali|
p Socket.unpack_sockaddr_in(ali)
end
^D
[0, "66.135.192.87"]
[0, "66.135.192.88"]
[0, "66.135.208.88"]
[0, "66.135.208.101"]
svg%


Guy Decoux


CarlosRivera

10/3/2004 8:14:00 PM

0

I never would have guessed to have unpacked. Is there a good
explanation of this somewhere? Also, during the unpack, what is the
first element supposed to represent?

For a reference, I am reading the Socket class at:

http://www.ruby-doc.o...

However, there seems to be no documentation on the method return types.
Is something wrong with my browser? I can see detailed information
about Net::HTTP.get().

ts wrote:
>>>>>>"C" == CarlosRivera <CarlosRivera@badnamefornospam.to> writes:
>
>
> C> [~]host www.ebay.com
> C> www.ebay.com is an alias for pages.ebay.com.
> C> pages.ebay.com has address 66.135.208.101
> C> pages.ebay.com has address 66.135.192.87
> C> pages.ebay.com has address 66.135.192.88
> C> pages.ebay.com has address 66.135.208.88
> C> [~]
>
> svg% ruby -rsocket
> Socket::gethostbyname("www.ebay.com")[3..-1].each do |ali|
> p Socket.unpack_sockaddr_in(ali)
> end
> ^D
> [0, "66.135.192.87"]
> [0, "66.135.192.88"]
> [0, "66.135.208.88"]
> [0, "66.135.208.101"]
> svg%
>
>
> Guy Decoux
>
>

Markus

10/3/2004 11:25:00 PM

0



I would guess that it is a wrapper around the system's
gethostbyname (especially since you have to unpack it) so "man
gethostbyname" might give you some hints.

Note: this is only a guess. If you want an authoritative answer (and no
one else here provides it) I'd suggest checking the source code. It
seldom lies, though it is at times coy about divulging its secrets. (To
its credit though, I have found it to be as patient with me as I am with
it. Oh my stars! It's the weekend and I'm channeling Why!)

-- MarkusQ


On Sun, 2004-10-03 at 13:19, CarlosRivera wrote:
> I never would have guessed to have unpacked. Is there a good
> explanation of this somewhere? Also, during the unpack, what is the
> first element supposed to represent?
>
> For a reference, I am reading the Socket class at:
>
> http://www.ruby-doc.o...
>
> However, there seems to be no documentation on the method return types.
> Is something wrong with my browser? I can see detailed information
> about Net::HTTP.get().
>
> ts wrote:
> >>>>>>"C" == CarlosRivera <CarlosRivera@badnamefornospam.to> writes:
> >
> >
> > C> [~]host www.ebay.com
> > C> www.ebay.com is an alias for pages.ebay.com.
> > C> pages.ebay.com has address 66.135.208.101
> > C> pages.ebay.com has address 66.135.192.87
> > C> pages.ebay.com has address 66.135.192.88
> > C> pages.ebay.com has address 66.135.208.88
> > C> [~]
> >
> > svg% ruby -rsocket
> > Socket::gethostbyname("www.ebay.com")[3..-1].each do |ali|
> > p Socket.unpack_sockaddr_in(ali)
> > end
> > ^D
> > [0, "66.135.192.87"]
> > [0, "66.135.192.88"]
> > [0, "66.135.208.88"]
> > [0, "66.135.208.101"]
> > svg%
> >
> >
> > Guy Decoux
> >
> >



Yukihiro Matsumoto

10/3/2004 11:28:00 PM

0

Hi,

In message "Re: Socket::gethostbyname()"
on Sun, 3 Oct 2004 15:04:56 +0900, CarlosRivera <CarlosRivera@badnamefornospam.to> writes:
|
|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:

How about using TCPSocket::gethostbyname instead?

matz.


Gavin Sinclair

10/4/2004 1:54:00 AM

0

On Monday, October 4, 2004, 6:19:55 AM, CarlosRivera wrote:

> I never would have guessed to have unpacked. Is there a good
> explanation of this somewhere? Also, during the unpack, what is the
> first element supposed to represent?

> For a reference, I am reading the Socket class at:

> http://www.ruby-doc.o...

> However, there seems to be no documentation on the method return types.
> Is something wrong with my browser? I can see detailed information
> about Net::HTTP.get().

Nothing wrong with your browser. The standard of docs varies between
packages.

Gavin