Skip to content

Instantly share code, notes, and snippets.

@creationix
Last active September 23, 2015 16:09
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 creationix/7a68795b342af82aacbd to your computer and use it in GitHub Desktop.
Save creationix/7a68795b342af82aacbd to your computer and use it in GitHub Desktop.
local ffi = require 'ffi'
local uv = require 'uv'
-- Darwin
local AF_INET = 2
local SOCK_RAW = 3
local IPPROTO_RAW = 255
ffi.cdef[[
int socket(int socket_family, int socket_type, int protocol);
]]
-- Raw socket - if you use IPPROTO_ICMP, then kernel will fill in the correct
-- ICMP header checksum, if IPPROTO_RAW, then it wont.
local sockfd = ffi.C.socket(AF_INET, SOCK_RAW, IPPROTO_RAW)
assert(sockfd >= 0, "Failed to create socket")
p(sockfd)
local raw = uv.new_udp()
assert(raw:open(sockfd))
p(raw)
raw:send("test", "23.253.227.83", 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment