Skip to content

Instantly share code, notes, and snippets.

@boxofrad
Last active November 4, 2016 13:48
Show Gist options
  • Save boxofrad/e0f67f9886d8063505fcb09b9a275966 to your computer and use it in GitHub Desktop.
Save boxofrad/e0f67f9886d8063505fcb09b9a275966 to your computer and use it in GitHub Desktop.
# https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
UDP_PROTOCOL = 0x11
loop do
data = socket.recv(BUFFER_SIZE).bytes
frame = EthernetFrame.new(data)
next unless frame.ip_packet.protocol == UDP_PROTOCOL &&
frame.ip_packet.udp_datagram.destination_port == 4321
UDPSocket.new.send(
frame.ip_packet.udp_datagram.body.upcase,
0,
frame.ip_packet.source_ip_address,
frame.ip_packet.udp_datagram.source_port
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment