Skip to content
Browse files

sniff: support BSD loopback

  • Loading branch information...
1 parent a505414 commit 104ca59a9c041f2106ae7545f0990b61d6aaaf3d @msantos committed
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/sniff.erl
View
11 src/sniff.erl
@@ -84,7 +84,9 @@ handle_info([
{pkthdr, [{time, Time}, {caplen, CapLen}, {len, Len}, {datalink, DLT}]},
{packet, Packet}
], sniffing, _) ->
- [Ether, IP, Hdr, Payload] = pkt:decapsulate(Packet),
+
+ [Ether, IP, Hdr, Payload] = decode(pkt:link_type(DLT), Packet),
+
{Saddr, Daddr, Proto} = case IP of
IP when is_record(IP, ipv4) ->
S = IP#ipv4.saddr,
@@ -211,3 +213,10 @@ tcp_flags(#tcp{cwr = CWR, ece = ECE, urg = URG, ack = ACK,
{fin, FIN}
], V =:= 1 ].
+decode(ether, Packet) ->
+ pkt:decapsulate({ether, Packet});
+decode(null, Packet) ->
+ % Add a fake ethernet header
+ [_Null, IP, Hdr, Payload] = pkt:decapsulate({null, Packet}),
+ [#ether{}, IP, Hdr, Payload].
+

0 comments on commit 104ca59

Please sign in to comment.
Something went wrong with that request. Please try again.