Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Last active November 13, 2015 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorickpeterse/7e8677207ef28f8df10f to your computer and use it in GitHub Desktop.
Save yorickpeterse/7e8677207ef28f8df10f to your computer and use it in GitHub Desktop.
require 'socket'
server = Socket.new(:INET, :DGRAM)
client = Socket.new(:INET, :DGRAM)
server.bind(Socket.sockaddr_in(0, '127.0.0.1'))
client.connect(Socket.sockaddr_in(server.connect_address.ip_port, '127.0.0.1'))
client.write('hello world how are you doing')
msg, addr, flags, *controls = server.recvmsg
found = Socket.constants.grep(/^MSG_/).map do |name|
flags & Socket.const_get(name)
end
p flags # => 1073741824
p found # => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment