# Why is gethostbyname in TCPSocket?

**URL:** <https://www.ruby-forum.com/t/why-is-gethostbyname-in-tcpsocket/80069>\
**Category:** Ruby\
**Created:** [December 21, 2006, 3:01am UTC](https://www.ruby-forum.com/t/why-is-gethostbyname-in-tcpsocket/80069 "2006-12-21T03:01:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [December 21, 2006, 3:01am UTC](https://www.ruby-forum.com/t/why-is-gethostbyname-in-tcpsocket/80069/1 "2006-12-21T03:01:12Z")

</div>

Looking for dns support, I found the gethostbyname method as a class  
method of TCPSocket in the socket library.

Seems like an odd place, considering that gethostbyname is hardly  
specific to TCP protocol alone.

Any idea why it was put there?

Cheers,  
Mike

---

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [December 21, 2006, 4:29am UTC](https://www.ruby-forum.com/t/why-is-gethostbyname-in-tcpsocket/80069/2 "2006-12-21T04:29:21Z")

</div>

On Dec 20, 2006, at 18:00, msoulier wrote:

> Looking for dns support, I found the gethostbyname method as a class  
> method of TCPSocket in the socket library.

$ ruby -rsocket -e ‘p TCPSocket.ancestors’  
[TCPSocket, IPSocket, BasicSocket, IO, File::Constants, Enumerable,  
Object, Kernel]

> Seems like an odd place, considering that gethostbyname is hardly  
> specific to TCP protocol alone.
> 
> Any idea why it was put there?

It wasn’t.

$ ruby -rsocket -e ‘p Socket.gethostbyname(“localhost”)’  
[“localhost”, [], 30, “\000\000\000\000\000\000\000\000\000\000\000  
\000\000\000\000\001”]

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)

I LIT YOUR GEM ON FIRE!

---

<div class="post-metadata">

**Author:** ![msoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@msoulier](https://www.ruby-forum.com/u/msoulier)\
**Post date:** [December 21, 2006, 4:31am UTC](https://www.ruby-forum.com/t/why-is-gethostbyname-in-tcpsocket/80069/3 "2006-12-21T04:31:21Z")

</div>

msoulier ha escrito:

> Looking for dns support, I found the gethostbyname method as a class  
> method of TCPSocket in the socket library.
> 
> Seems like an odd place, considering that gethostbyname is hardly  
> specific to TCP protocol alone.
> 
> Any idea why it was put there?

It wasn’t. It’s part of Socket, which seems rather logical. TCPSocket  
just inherits from Socket.
