# Socket::Constants incomplete?

**URL:** <https://www.ruby-forum.com/t/socket-constants-incomplete/133723>\
**Category:** Ruby\
**Created:** [April 2, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/socket-constants-incomplete/133723 "2008-04-02T23:23:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcampbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@mcampbell](https://www.ruby-forum.com/u/mcampbell)\
**Post date:** [April 2, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/socket-constants-incomplete/133723/1 "2008-04-02T23:23:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mcampbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@mcampbell](https://www.ruby-forum.com/u/mcampbell)\
**Post date:** [April 2, 2008, 11:41pm UTC](https://www.ruby-forum.com/t/socket-constants-incomplete/133723/2 "2008-04-02T23:41:51Z")

</div>

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.
