# Problems calling build\_tcp from Ruby libnet

**URL:** <https://www.ruby-forum.com/t/problems-calling-build-tcp-from-ruby-libnet/92919>\
**Category:** Ruby\
**Created:** [April 25, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/problems-calling-build-tcp-from-ruby-libnet/92919 "2007-04-25T17:55:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anansi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9fc348/32.png) [@anansi](https://www.ruby-forum.com/u/anansi)\
**Post date:** [April 25, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/problems-calling-build-tcp-from-ruby-libnet/92919/1 "2007-04-25T17:55:32Z")

</div>

Hi,  
I installed ruby-libnet (SVN):  
[http://rubyforge.org/projects/ruby-libnet/](http://rubyforge.org/projects/ruby-libnet/) and want to send a TCP packet  
with it. Building TCP packets is done with build\_tcp from ruby-libnet.c  
:

/\*

- 
  - @param sp source port

- 
  - @param dp destination port

- 
  - @param seq sequence number

- 
  - @param ack acknowledgement number

- 
  - @param control control flags

- 
  - @param win window size

- 
  - @param sum checksum (0 for libnet to autofill)

- 
  - @param urg urgent pointer

- 
  - @parama len total length of the TCP packet (for checksum  
calculation)

- 
  - @param payload\_s payload length or 0

- 
  - @param ptag protocol tag to modify an existing header, 0 to build  
a new one

- 
  - @return protocol tag value on success, -1 on error

- 

\*/  
static VALUE rb\_libnet\_build\_tcp(VALUE self,  
VALUE sp,  
VALUE dp,  
VALUE seq,  
VALUE ack,  
VALUE control,  
VALUE win,  
VALUE csum,  
VALUE urg,  
VALUE len,  
VALUE payload,  
VALUE payload\_s,  
VALUE tag)

I wanna send a TCP SYN packet with this code:

#!/usr/bin/ruby -w

require ‘libnet’

l = Libnet.new  
l.build\_tcp(?!?,7000, 80, 100,0, “SYN”, 4, 0, 0,24,0,0)  
l.auto\_build\_ipv4(Libnet::LIBNET\_TCP\_H + Libnet::LIBNET\_IPV4\_H,  
Libnet::IPPROTO\_TCP, “192.168.0.255”)  
l.auto\_build\_ethernet(l.hex\_aton(“00:11:11:94:D4:F5”),Libnet::ETHERTYPE\_IP)  
ret = l.write

but something goes wrong. I get this error when executing:  
SYN.rb:4:in `build\_tcp’: can’t convert Fixnum into String (TypeError)  
from SYN.rb:4

I think I’m missing this: “VALUE self” as first argument but I don’t  
know what it is or where to take it. Can someone help me? I really don’t  
know how to set the first argument. But something others most also be  
wrong because of the error message you see above. But ruby doesn’t show  
which argument is bad. I did them like this:

VALUE sp,  
VALUE sp, —\>7000  
VALUE dp, —\> 80  
VALUE seq, —\>100  
VALUE ack, —\>0  
VALUE control, —\> “SYN”  
VALUE win, ----\> 4  
VALUE csum, ----\> 0  
VALUE urg, ----\> 0  
VALUE len, ----\> 24  
VALUE payload, ----\> 0  
VALUE payload\_s, —\> falls away if  
VALUE payload is set to 0  
VALUE tag) -----\> 0

any help is welcome 🙂

–  
greets  
(  
)  
(  
/\ .-“”“-. /  
//\/ , //\  
|/| ,;;;;;, |/|  
//\;-”“”-;///\  
// / . / \  
(| ,-_| \ | / |_-, |)  
//` __\.-.-./__ `\  
// /.-(() ())-.\ \  
(\ |) ‘—’ (| /)  
`(| |)`  
jgs ) (/

one must still have chaos in oneself to be able to give birth to a  
dancing star
