<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Hi All,<br><br>Excuse-me to talk about it again, because it becomes more interesting now, as I can see the deep functions provided by Erlang.<br><br>As I said previously, <a href="https://github.com/msantos/epcap.git">https://github.com/msantos/epcap.git</a> is solving my need.<br><br>Anyway, I tried all the suggestions of Lukasz:<br><br>1/[WORKING] Unix-Domain + gen_udp/gen_tcp:<br>{ok, Server} = gen_udp:open(0, [{ifaddr,{local,"/tmp/socket"}}])<br>gen_udp:send(UnixSock, {local, "/tmp/socket"}, 0, "Hello Unix-Domain World").<br>%% it's pretty useful.<br><br>2/[WORKING] Allocate a named pipe by mkfifo and listen/send in Erlang:<br>mkfifo dump.unix<br>open_port("dump.unix", [eof]).<br>port_command(HelloFifo, <<"Hey! Hello again\n">>).<br>%% I can even pipe the output of tcpdump, which is doing all the job for me, and I can get all data from Erlang, Great!! :-)<br>%% This was solving my need as well!<br><br>3/ Anyway, I hope I did not misunderstood, but I was undesrtanding that it was feasible to connect to an existing named pipe "allocated by mkfifo" via gen_udp/gen_tcp?<br>because for this, I always fail, since the named pipe has the same name as my unix-domain socket.<br><br>{error, eaddrinuse} when listen , {error, econnrefused} when send<br><br></div><div dir="ltr" class="gmail_attr">==> So my question is, How do you connect to an existing named pipe allocated by mkfifo, via gen_udp/gen_tcp, not using open_port?<br></div><div dir="ltr" class="gmail_attr"><br></div><div dir="ltr" class="gmail_attr">Thank you!</div><div dir="ltr" class="gmail_attr"><br></div><div dir="ltr" class="gmail_attr">
PS: I will try to understand socat and cap_net_raw as well later on :-p</div><div dir="ltr" class="gmail_attr"><br></div><div dir="ltr" class="gmail_attr">Best Regards,</div><div dir="ltr" class="gmail_attr"><br></div><div dir="ltr" class="gmail_attr">Le mar. 11 août 2020 à 18:52, Łukasz Niemier <<a href="mailto:lukasz@niemier.pl">lukasz@niemier.pl</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> To make a direct pipe, I'm getting from 'tcpdump' and 'replay' on the other side like below:<br>
> <br>
> # tcdump -i eth0 -w -'..... | tcpreplay -i eth1 - ....<br>
<br>
This is "unnamed pipe", what I meant is named pipe:<br>
<br>
$ mkfifo dump.pcap<br>
$ # start VM that will read from `dump.pcap`<br>
# tcpdump -i eth0 -w dump.pcap<br>
<br>
Alternatively you can use socat and UNIX socket<br>
<br>
# tcpdump -i eth0 -w - | socat stdin unix-sendto:dump.unix # it will use datagram UNIX socket, use unix-listen for stream socket<br>
$ # start VM and connect to the dump.unix via gen_udp/gen_tcp<br>
<br>
You can also use socat for sending data to the named pipe if you want using pipe:dump.pcap. In that form you will not need to run VM with any raised privileges, just regular user that can read named pipe/UNIX socket.<br>
<br>
--<br>
<br>
Łukasz Niemier<br>
<a href="mailto:lukasz@niemier.pl" target="_blank">lukasz@niemier.pl</a><br>
<br>
</blockquote></div></div>