Skip to content

Instantly share code, notes, and snippets.

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

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
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")
local raw = uv.new_udp()
raw:send("test", "", 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.