Socket::Constants incomplete?

Hi,

today I tried to use ruby to read data from an ax25 socket using the
socket api.

I think, that some definitions/constants are missing. There are no
constants
for AF_AX25, AF_PACKET and the method htons is missing also.

I have attached two (ugly, undocumented, unportable :wink: files, one
containing a small c example, the other the correspoding ruby code.

Output of listen.c

af_packet: 17, sock_packet: 10, htons( AX25): 512
received: 101 bytes
� � h � r � � � � � � � � � � @ � � � � b @ � � ` � � @ �
� � � � d @ c � = 4 9 3 2 . 2 3 N / 0 0 8 2 2
. 7 0 E _ . . . / . . . g . . . t 0 4 9 r 0 0 0 p 0 0 0 R 0 0 0 h 5 6 b
1 0 2 3 0

Output of listen.rb

socket: #Socket:0xb7cd8748
received: 101 bytes
� � h � r � � � � � � � � � � @ � � � � b @ � � ` � � @ � �
� � � d @ c � = 4 9 3 2 . 2 3 N / 0 0 8 2 2 .
7 0 E _ . . . / . . . g . . . t 0 4 9 r 0 0 0 p 0 0 0 R 0 0 0 h 5 6 b 1
0 2 3 0

Is the incomplete ruby socket api a bug or do I have make something
wrong ?

My dpkg (debian packet tool) says

ii ruby1.8 1.8.6.114-2 Interpreter of object-oriented
scripting lan

Regards

  Michael C.

Michael C. wrote:

Hi,

today I tried to use ruby to read data from an ax25 socket using the
socket api.

I think, that some definitions/constants are missing. There are no
constants
for AF_AX25, AF_PACKET and the method htons is missing also.

Hm, AF_AX25 should get defined in ruby if it is available in C:

[ruby/src/ruby/ext/socket] grep AF_AX *
socket.c:#ifdef AF_AX25
socket.c: sock_define_const(“AF_AX25”, AF_AX25);

Maybe socket.c isn’t including the right header file, in which case it
might be a bug in the extconf.rb.

Dunno about AF_PACKET–it doesn’t seem to be referenced anywhere in the
socket extension.

For htons(), you can use String#unpack and Array#pack.