Skip to content

Instantly share code, notes, and snippets.

@creationix creationix/ping.lua Secret
Last active Sep 23, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.