package rawlink

  1. Overview
  2. Docs
Portable library to read and write raw packets.

Install

Dune Dependency

Authors

Maintainers

Sources

rawlink-0.6.tbz
sha256=17db83bc9ab52b8c6df53d15700a6ba2a207e423ee682b83e19765eaf843db94
md5=3f7cf16f5e41b14dac3f8e11536f414c

Description

Build Status

Rawlink is an ocaml library for sending and receiving raw packets at the link layer level. Sometimes you need to have full control of the packet, including building the full ethernet frame.

The API is platform independent, it uses BPF on real UNIXes and AF_SOCKET on linux. Some functionality is sacrificed so that the API is portable enough.

Currently BPF and AF_PACKET are implemented, including filtering capabilities. Writing a BPF program is a pain in the ass, so no facilities are provided for it. If you need a BPF filter, I suggest you write a small .c file with a function that returns the BPF program as a string, check rawlink_stubs.c for an example.

Both normal blocking functions as well as Lwt monadic variants are provided.

A typical code for receiving all packets and just sending them back on an specified interface are detailed below:

let link = Rawlink.open_link "eth0" in
let buf = Rawlink.read_packet link in
Printf.printf "got a packet with %d bytes.\n%!" (Cstruct.len buf);
Rawlink.send_packet link buf

Check the mli interface for more options.

Published: 24 Nov 2017

README

Rawlink - portable library to read and write raw packets.

Rawlink is an ocaml library for sending and receiving raw packets at the link layer level. Sometimes you need to have full control of the packet, including building the full ethernet frame.

The API is platform independent, it uses BPF on real UNIXes and AF_SOCKET on linux. Some functionality is sacrificed so that the API is portable enough.

Currently BPF and AF_PACKET are implemented, including filtering capabilities. Writing a BPF program is a pain in the ass, so no facilities are provided for it. If you need a BPF filter, I suggest you write a small .c file with a function that returns the BPF program as a string, check rawlink_stubs.c for an example.

Both normal blocking functions as well as Lwt monadic variants are provided.

A typical code for receiving all packets and just sending them back on an specified interface are detailed below:

let link = Rawlink.open_link "eth0" in
let buf = Rawlink.read_packet link in
Printf.printf "got a packet with %d bytes.\n%!" (Cstruct.len buf);
Rawlink.send_packet link buf

Check the mli interface for more options.

Dependencies (7)

  1. ocamlbuild build & >= "0.11.0"
  2. ppx_cstruct
  3. cstruct >= "3.2.0"
  4. lwt >= "2.4.7" & < "4.0.0"
  5. topkg build
  6. ocamlfind build
  7. ocaml >= "4.03.0" & < "5.0"

Dev Dependencies

None

Conflicts

None

OCaml

Innovation. Community. Security.