From: Jason Roelofs Date: 2008-02-13T10:06:09+09:00 Subject: Re: Help Understanding Ruby/C Bindings On Feb 12, 2008 7:32 PM, Bryan Richardson 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-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 Jason