Skip to content

Conversation

@sneaky-potato
Copy link
Contributor

Move recurring raw socket receive and send pattern in a common place.

Fixes #358

Move recurring raw socket recieve and send
pattern in a common place.

Signed-off-by: Ashwani Kumar Kamal <[email protected]>
Comment on lines +52 to +76
---
-- Creates a scoped receiving raw socket
-- @param ifindex (number) Interface index.
-- @param proto (number) EtherType.
-- @param fn (function) procedure to execute when receiving frames
-- @return Outout of raw packet socket bound for RX.
-- @raise Error if socket.raw.bind() fail.
-- @see socket.raw.bind
function raw.with_rx(ifindex, proto, fn)
local s <close> = raw.bind(ifindex, proto)
return fn(s)
end

---
-- Creates a scoped transmitting raw socket
-- @param ifindex (number) Interface index.
-- @param proto (number) EtherType.
-- @param fn (function) procedure to execute when transmitting frames
-- @return Outout of raw packet socket bound for TX.
-- @raise Error if socket.raw.connect() fail.
-- @see socket.raw.connect
function raw.with_tx(ifindex, proto, fn)
local s <close> = raw.connect(ifindex, proto)
return fn(s)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this.. I'd rather keep it simple.. having only bind and connect

@lneto lneto requested review from carloslack and jperon December 31, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Factor common AF_PACKET RAW socket pattern

2 participants