I was looking at OCaml to build some pretty simple vSwitch and so I need to open a RAW socket in order to manage Ethernet frames.
But I’m unable to bind the socket to an interface.
This is how I create the socket
let create_socket iface =
let sock = Lwt_unix.socket Unix.PF_INET Unix.SOCK_RAW 0 in
let sockaddr = .... ? What is supposed to be there? in
bind sock sockaddr;
sock
It is possible to create RAW socket in OCaml?
I’m supposed to wrap some C code like this lib ocaml-rawlink
Thanks,
Gabriele
The problem with this is that the original question was using Lwt, and ChatGPT is using Unix. To someone who is not very familiar with both of these libraries and their differences, this will lead to more confusion.
Before you try to do this with lwt, why not try to do it with straight-up Unix ? That is, the unix library in OCaml? Indeed, first do it with C code, and you can then compare the strace output of your C program to that of your OCaml program written using unix. Once the latter works, you can then switch to lwt.
ETA: what I’m saying is: first get yourself a “known good” (C program version); then “baby-step” to a “known good OCaml version” (the version using unix) and only then baby-step to lwt (your current “known bad”).