ruby - Receive UDP datagram on raw socket? -
i'm trying write own implementation of udp in ruby educational purposes using raw sockets.
here's have far:
require 'socket' addr = socket.pack_sockaddr_in(4567, '127.0.0.1') socket = socket.new( socket::pf_inet, socket::sock_raw, socket::ipproto_raw ) socket.bind(addr) socket.recvfrom(1024)
i testing so:
require 'socket' udp = udpsocket.new udp.send "hello world", 0, "127.0.0.1", 4567
but call recvfrom
blocking indefinitely.
if change this:
socket = socket.new( socket::pf_inet, socket::sock_dgram, socket::ipproto_udp )
it of course works because system-level way accept udp packets.
how can receive udp packets on raw socket?
clear: want handle actual udp protocol (decoding datagram & doing checksum) myself!
raw sockets work @ ip level. cannot bind raw socket port. can bind local address bind or interface setting proper socket options (i don't know how in ruby, in c call setsockopt. instead of ipproto_raw should use ipproto_udp in protocol.you receive udp datagrams received on ip address or interface if socket bound it.
Comments
Post a Comment