Skip to content

Instantly share code, notes, and snippets.

@benner

benner/udp.cr Secret

Created October 9, 2015 18:12
Show Gist options
  • Save benner/1b71ec1c345753f37d81 to your computer and use it in GitHub Desktop.
Save benner/1b71ec1c345753f37d81 to your computer and use it in GitHub Desktop.
require "socket"
lib LibC
ifdef darwin
else
SO_BINDTODEVICE = 25
end
end
server = UDPSocket.new
iface = "lo"
res = LibC.setsockopt(server.fd, LibC::SOL_SOCKET, LibC::SO_BINDTODEVICE, pointerof(iface) as Void*, iface.size)
# % strace -qq -f -e trace=setsockopt -e 'signal=!all' crystal run udp.cr
# [pid 25840] setsockopt(8, SOL_SOCKET, SO_BINDTODEVICE, "\270x", 2) = -1 EPERM (Operation not permitted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment