views:

447

answers:

1

i'm trying to create a raw sockets using ruby .... the problem is there isn't any thing called raw socket there ,and on the other hand the socket class itself is not fully documented .... do any body have some code samples for that kind of sockets in ruby ?? or maybe some kind of a documentation for that ???

By the way i already know very well how to work with TCPSocket and TCPServer classes ,and what i need is particularly a raw socket.

thanx any way ....

+2  A: 

Google brings up the following result: http://www.ruby-forum.com/topic/90408

Short version:

require 'socket'

rsock = Socket.open(Socket::PF_INET, Socket::SOCK_RAW, Socket::IPPROTO_RAW)

rsock.send(string, flags)

rsock.recv(1024)

More documentation on the various Socket classes: http://www.rubycentral.com/pickaxe/lib%5Fnetwork.html

(The whole raw sockets thing is rather nasty on unices since it usually requires root access. I did not test this code. You may need to construct the whole packet yourself if you're not using IPSocket)

hhaamu
Thanx dude ..... but i already seen this "http://www.ruby-forum.com/topic/90408" ,it's useless crap, and it's full of mistakes.the Pickaxe 3rd edition was the most useful thing, thanx again.
Raafat