Permalink
Browse files

Clean up IP record pattern matching

  • Loading branch information...
1 parent 058eef4 commit 25944d93e178dca09ceecd1f2750ed61f99e0e2e @msantos committed Mar 13, 2012
Showing with 5 additions and 9 deletions.
  1. +1 −1 README.md
  2. +4 −8 src/sniff.erl
View
@@ -18,7 +18,7 @@ epcap includes a small example program called sniff.
erl -pa ebin deps/*/ebin
- % Start the gen_server
+ % Start the sniffer process
sniff:start_link().
% Use your interface, or leave it out and trust in pcap
View
@@ -84,17 +84,13 @@ handle_info({packet, DLT, Time, Len, Packet}, sniffing, _) ->
[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,
- D = IP#ipv4.daddr,
- P = IP#ipv4.p,
+ #ipv4{saddr = S, daddr = D, p = P} ->
{S,D,P};
- IP when is_record(IP, ipv6) ->
- S = IP#ipv6.saddr,
- D = IP#ipv6.daddr,
- P = IP#ipv6.next,
+
+ #ipv6{saddr = S, daddr = D, next = P} ->
{S,D,P}
end,
+
error_logger:info_report([
{time, timestamp(Time)},
{caplen, byte_size(Packet)},

0 comments on commit 25944d9

Please sign in to comment.