[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Help Understanding Ruby/C Bindings

Bryan Richardson

2/13/2008 12:32:00 AM

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
--
Posted via http://www.ruby-....

2 Answers

Jason Roelofs

2/13/2008 1:06:00 AM

0

On Feb 12, 2008 7:32 PM, Bryan Richardson <btrichardson@gmail.com> wrote:
> 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
> --
> Posted via http://www.ruby-....
>
>

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...

Jason

Bryan Richardson

2/13/2008 1:53:00 PM

0

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

Bryan

On 2/12/08, Jason Roelofs <jameskilton@gmail.com> wrote:
> On Feb 12, 2008 7:32 PM, Bryan Richardson <btrichardson@gmail.com> wrote:
> > 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
> > --
> > Posted via http://www.ruby-....
> >
> >
>
> 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...
>
> Jason
>
>