Forget it... found the error Socket::SOCK_DGRAM.. Must use
Socket::SOCK_RAW..


> def inject(interface, packet_bytes)
> 
>    sock = Socket.new(PF_PACKET, Socket::SOCK_DGRAM, ETH_P_ALL)
> 
>    # struct ifreq in net/if.h
>    ifreq = [interface.dup].pack 'a32'
>    sock.ioctl(SIOCGIFINDEX, ifreq)
> 
>    # struct sockaddr_ll in linux/if_packet.h
>    sll = [AF_PACKET].pack 's'
>    sll << ( [ETH_P_ALL].pack 's' )
>    sll << ifreq[16..20]
>    sll << ("\x00" * 12)
>    sock.bind sll
> 
>    sock.write(packet_bytes) # 
> end
-- 
Posted via http://www.ruby-forum.com/.