I'm presently trying to write something in Ruby which will send data over a raw socket. It may be in part due to a somewhat shaky understanding of sockets, but I feel as though the resources are almost-but-not-quite there.
In particular, I'm trying to convert the following Python code (in case it helps):
#!/usr/bin/env python
from socket import socket, AF_PACKET, SOCK_RAW
s = socket(AF_PACKET, SOCK_RAW)
s.bind(("lo", 0))
geonet_frame = "\x00\x1f\xc6\x51\x07\x07\x07\x07\x07\x07\x07\x07\x07\x07\xc6
\x51\x07\x07\x07\x07\x07\x07\xef\x06\x07\x35\x97\x00\x24\x8c\x7a\xdf\x6f\x08
\x00\x45\x00\x00\x3d\xf3\x7f\x40\x00\x40\x11\x30\xc6\x0a\x01\x01\x68\x0a\x01
\x01\x01\x99\x80\x00\x35\x00\x29\x16\xa5\x01\x76\x01\x00\x00\xff\x00\x00\x01
\x00\x00\x00"
s.send(geonet_frame)
In searching the matter, the results I see most often are this Stack Overflow question, which does not directly provide any workable code examples, and this explanation which seems to do a lot more than I need and also seems to include a file which I cannot access.
I have tried a few things listed in the documentation for the Socket class, but I can never quite seem to achieve the same results even if I can make it work. For example, I might try:
soc = Socket.open(Socket::PF_INET, Socket::SOCK_RAW, Socket::IPPROTO_RAW)
soc.send(mypacket, 0, Socket.pack_sockaddr_in(0, "127.0.0.1"))
...and while it will complete, it does not produce the desired result (in this case, it does not create a DOS on TCPDump as denoted here, while the equivalent Python code would).
Is this more complicated in Ruby than I'm expecting? Or am I just missing some magical combination of functions which would allow me to do this?
Update: Here is a picture of a capture of the desired packet.