l2ethernet 0.3.1 copy "l2ethernet: ^0.3.1" to clipboard
l2ethernet: ^0.3.1 copied to clipboard

PlatformLinux

Sending raw Ethernet frames in Dart via FFI. Usable for generating WOL packets or non-standard protocols running on Ethernet. Sending only. Linux only.

package:l2ethernet #

Sending raw Ethernet frames in Dart

What is this? #

This is a small Dart package to make it possible to send raw Ethernet frames out. My use-case was to send data to a Colorlight 5A receiver card which expect Ethernet frames and I found no way to do that with Dart. The miss-leadingly named RawSocket class used TCP.

Thus this package was born: via FFI it uses the Linux socket() interface to send out raw Ethernet frames. Can be used to send arbitrary Ethernet packets. WOL packets, ARP spoofing, custom protocols come into mind.

Testing #

Tests contain two parts: one which can be run as non-root and one which requires root (or similar permissions) as it actually opens a raw socket. I do run tcpdump in the background to capture the sent Ethernet packet and verify it's what I expect it to be.

Compiling the shared library #

This is actually simple as the C layer is very short. I added a buildme.sh script. It's that simple.

macOS, Windows, Android, iOS #

Sorry, no support from my side for those.

Limitations #

  • Receiving frames is not currently implemented.
  • This is nor performance optimized: A single frame is sent out synchronously. If performance is required, sendmmsg() should be used.
  • Only Linux supported and the shared library is only available for x86_64 and aarch64. It's very simple to compile the library though (see buildme.sh).

Note on libeth.so for Dart exe and aot #

Dart can use packages (pulled in by dart pub get), but when compiled to exe or aot, it does not look at packages and thus libeth.so will not be found. While it would be nice to statically link it to the executable file (or aot file), this does not work as of Dart 2.16.1 The workaround is to have the needed libeth.so file in ./lib/$march/libeth.so where . is the path of the binary (e.g. sendframe.exe) See also https://github.com/dart-lang/sdk/issues/47718

1
likes
120
pub points
17%
popularity

Publisher

unverified uploader

Sending raw Ethernet frames in Dart via FFI. Usable for generating WOL packets or non-standard protocols running on Ethernet. Sending only. Linux only.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

ffi, path

More

Packages that depend on l2ethernet