# how to port linux raw socket to FreeBSD



## freyone (Apr 1, 2022)

I wrote a linux raw socket code that can send and recieve file by network interface directly without ip.how can I port it into Freebsd
there is no "ETH_P_ALL" macro and "struct sockaddr_ll" defined in Freebsd.what can intead of them in Freebsd.I also attached all of the source code that can make directly in linux.


----------



## mark_j (Apr 1, 2022)

Of course you can program in raw sockets with FreeBSD, your only issue is with all the linux-isms you've possibly included in your code.
A quick glance sees quite a bit, so get busy with judicious use of #ifdef et al.
Hint: sys/sockio.h is very useful.
I have no idea about ETH_P_ALL, btw. I don't know what it does and what Linux exposes for it.


----------



## covacat (Apr 1, 2022)

use net/libnet for this kind of stuff


----------



## SirDice (Apr 1, 2022)

While you are certainly porting code, this isn't about creating a new port for the FreeBSD ports system. Thread moved from "Porting new software" to "Userland Programming and scripting". Your question seems to fit that category better, you might get some extra views from coders.


----------



## Bobi B. (Apr 3, 2022)

Take a look at pcap(3) and bpf(4), search for `sockaddr_dl`.

For the former there are plenty of tutorials already.

For the latter basically you

open(2) /dev/bpf,
configure file descriptor with ioctl(2),
use send(2) and recv(2).


----------

