# Help Understanding Ruby/C Bindings

**URL:** <https://www.ruby-forum.com/t/help-understanding-ruby-c-bindings/128964>\
**Category:** Ruby\
**Created:** [February 13, 2008, 1:32am UTC](https://www.ruby-forum.com/t/help-understanding-ruby-c-bindings/128964 "2008-02-13T01:32:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [February 13, 2008, 1:32am UTC](https://www.ruby-forum.com/t/help-understanding-ruby-c-bindings/128964/1 "2008-02-13T01:32:32Z")

</div>

Hello all,

Can anyone walk me through how, for example, the binding between  
libpcap-ruby and libpcap? If I look at pcaplet and pcap\_misc, I notice  
that ‘pcap’ is required. Is this another Ruby file (that I can’t find)  
or is this referencing the libpcap C library directly?

If anyone can explain to me how this works I’d greatly appreciate it.  
There’s a good chance I’ll need to be binding to C code from Ruby in the  
near future and I’d like to understand the best way to go about doing  
so.

–  
Thanks!  
Bryan

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [February 13, 2008, 2:07am UTC](https://www.ruby-forum.com/t/help-understanding-ruby-c-bindings/128964/2 "2008-02-13T02:07:05Z")

</div>

On Feb 12, 2008 7:32 PM, Bryan R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> so.
> 
> ## – Thanks! Bryan
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Kernel#require can load both another Ruby file or a Ruby extension.  
Ruby extensions are shared libraries that are required to have at  
least one certain method in them:

extension.c

void Init\_extension() {  
… initialization code here …  
}

builds into extension.so (on Linux, extension.dll on Windows)

Then you can

require ‘extension’

and start using whatever the library has made available. In the case  
of libpcap-ruby, there’s a pcap.so file somewhere in your system (I’m  
assuming you apt-get installed it, or the related on your system)  
that’s accessible by Ruby.

That’s the gist of it, for more detailed information, go here:  
[http://www.rubycentral.com/pickaxe/ext\_ruby.html](http://www.rubycentral.com/pickaxe/ext_ruby.html)

Jason

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [February 13, 2008, 2:53pm UTC](https://www.ruby-forum.com/t/help-understanding-ruby-c-bindings/128964/3 "2008-02-13T14:53:31Z")

</div>

Thanks Jason for the response. It’s just what I was looking for!

Bryan
