# How to write packets on ethernet card

**URL:** <https://www.ruby-forum.com/t/how-to-write-packets-on-ethernet-card/162560>\
**Category:** Ruby\
**Created:** [March 11, 2009, 11:50am UTC](https://www.ruby-forum.com/t/how-to-write-packets-on-ethernet-card/162560 "2009-03-11T11:50:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stalin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@stalin](https://www.ruby-forum.com/u/stalin)\
**Post date:** [March 11, 2009, 11:50am UTC](https://www.ruby-forum.com/t/how-to-write-packets-on-ethernet-card/162560/1 "2009-03-11T11:50:27Z")

</div>

Hi all,  
I want to write raw packets over the Ethernet card. I don’t  
how to do it in ruby. If anybody knows help me…

---

<div class="post-metadata">

**Author:** ![stalin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@stalin](https://www.ruby-forum.com/u/stalin)\
**Post date:** [March 11, 2009, 1:03pm UTC](https://www.ruby-forum.com/t/how-to-write-packets-on-ethernet-card/162560/2 "2009-03-11T13:03:41Z")

</div>

On Wed, Mar 11, 2009 at 6:48 AM, Stalin Thangaraj  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,  
> I want to write raw packets over the Ethernet card. I don’t  
> how to do it in ruby. If anybody knows help me…

[http://tinyurl.com/cb9p7z](http://tinyurl.com/cb9p7z)

When you have more specific questions, and have researched this a  
little and can show what you have tried so far, post back and I’m sure  
folks will help you.

-greg

---

<div class="post-metadata">

**Author:** ![stalin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@stalin](https://www.ruby-forum.com/u/stalin)\
**Post date:** [March 11, 2009, 1:25pm UTC](https://www.ruby-forum.com/t/how-to-write-packets-on-ethernet-card/162560/3 "2009-03-11T13:25:12Z")

</div>

Stalin Thangaraj wrote:

> ```
> I want to write raw packets over the Ethernet card. I don't
> 
> ```
> 
> how to do it in ruby. If anybody knows help me…

First find out how to do it in C using the Unix sockets API. Suggested  
resource is “Unix Network Programming volume 1” by Richard Stevens, pub  
Addison Wesley. Or you can find existing code which sends raw packets  
and reverse-engineer that. Ask questions on a kernel/networking mailing  
list if you have problems.

Once you know this, you can translate easily to Ruby, since ruby’s  
Socket is a thin layer on top of this.

Google “ruby socket” and the first hit is the socket documentation. Also  
look in the sockets documentation at  
[http://www.ruby-doc.org/books/ProgrammingRuby](http://www.ruby-doc.org/books/ProgrammingRuby) (click on “Network and Web  
Libraries”)

---

<div class="post-metadata">

**Author:** ![stalin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@stalin](https://www.ruby-forum.com/u/stalin)\
**Post date:** [March 12, 2009, 2:22am UTC](https://www.ruby-forum.com/t/how-to-write-packets-on-ethernet-card/162560/4 "2009-03-12T02:22:02Z")

</div>

On 11 Mar 2009, at 12:23, Brian C. wrote:

> list if you have problems.
> 
> Once you know this, you can translate easily to Ruby, since ruby’s  
> Socket is a thin layer on top of this.
> 
> Google “ruby socket” and the first hit is the socket documentation.  
> Also  
> look in the sockets documentation at  
> [http://www.ruby-doc.org/books/ProgrammingRuby](http://www.ruby-doc.org/books/ProgrammingRuby) (click on “Network and  
> Web  
> Libraries”)

Follow the link in my sig and you’ll find some presentations bursting  
with code for UDP and TCP network comms. These aren’t raw packets in  
the fullest sense of the term but depending on your intent they may  
suffice.

Ellie

## Eleanor McHugh Games With Brains [http://slides.games-with-brains.net](http://slides.games-with-brains.net)

raise ArgumentError unless @reality.responds\_to? :reason
