-
-
Save creationix/7a68795b342af82aacbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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