File: packet-socket.lua

package info (click to toggle)
lua-posix 36.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,720 kB
  • sloc: ansic: 5,462; makefile: 21; sh: 6
file content (12 lines) | stat: -rw-r--r-- 406 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
#! /usr/bin/env lua

local M = require 'posix.sys.socket'

-- Packet socket loopback test
-- Need CAP_NET_RAW, otherwise get "Operation not permitted"
if M.AF_PACKET ~= nil then
    local fd = assert(M.socket(M.AF_PACKET, M.SOCK_RAW, 0))
    assert(M.bind(fd, {family=M.AF_PACKET, ifindex=M.if_nametoindex("lo")}))
    assert(M.send(fd, string.rep("1", 64)) == 64)
    require 'posix.unistd'.close(fd)
end