[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

variable corruption when using ioctl?

A Sussex

6/20/2008 2:18:00 PM

I'm attempting to read the address assigned to an interface. After
calling ioctl(SIOCGIFADDR) - which is 0x8915 on my system - I find
that the destination buffer is corrupted and contains random garbage.
Here I do this twice, with different results:

irb(main):008:0> buf = ['eth0',''].pack('a16h16')
=> "eth0\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
irb(main):009:0> s.ioctl(0x8915, buf)
=> 0
irb(main):010:0> buf
=> "eth0\000\000\000\000\000\000\000\000\000\000\000\000\002\000\000\000\300\250\n\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\211\000\000\000\230n\b\b\370D\352\267Keiju
ISHITSUKA(keiju@ruby-lang.org)\n\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\021"
irb(main):011:0>

...

irb(main):025:0> buf = ['eth0',''].pack('a16h16')
=> "eth0\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
irb(main):026:0> s.ioctl(0x8915, buf)
=> 0
irb(main):027:0> buf
=> "eth0\000\000\000\000\000\000\000\000\000\000\000\000\002\000\000\000\300\250\n\020\000\000\000\000\000\000\000\000\230\025\016\b\370D\352\267
:op\n\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\251\002\000\000\300\035\n\b\370D\352\267ex_state
= EXPR_BEG\n\000*rest)\n\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\021"
irb(main):028:0>


Is this a bug?

I'm using irb / Ruby 1.8.2-1 on Debian Etch.

--
Andrew