Permalink
Browse files

Rename bpf parsing functions

Clarify the bpf parsing by renaming them to match the bpf_hdr
structure.

(Should bpf:data/3 really be bpf:cap/3 then?)
  • Loading branch information...
1 parent 21ba173 commit a39e9d39d72ebe6c6a0551b8bec3f76aa2900958 @msantos committed Apr 21, 2011
Showing with 11 additions and 11 deletions.
  1. +11 −11 src/bpf.erl
View
22 src/bpf.erl
@@ -35,7 +35,7 @@
% BPF ioctl
-export([
open/1,
- data/1, hdr/1, packet/3,
+ buf/1, hdr/1, data/3,
ctl/2, ctl/3
]).
% BPF filters
@@ -238,17 +238,17 @@ align(N) ->
(N + (?BPF_ALIGNMENT-1)) band bnot (?BPF_ALIGNMENT-1).
-data(Data) when is_binary(Data) ->
- data_1(hdr(Data), Data).
+buf(Data) when is_binary(Data) ->
+ buf_1(hdr(Data), Data).
-data_1({bpf_hdr, Time, Caplen, Datalen, Hdrlen}, Data) ->
- data_2(Time, Datalen, packet(Hdrlen, Caplen, Data));
-data_1(Error, _) ->
+buf_1({bpf_hdr, Time, Caplen, Datalen, Hdrlen}, Data) ->
+ buf_2(Time, Datalen, data(Hdrlen, Caplen, Data));
+buf_1(Error, _) ->
Error.
-data_2(Time, Datalen, {bpf_packet, Packet, Rest}) ->
- {bpf_data, Time, Datalen, Packet, Rest};
-data_2(_Time, _Datalen, Error) ->
+buf_2(Time, Datalen, {bpf_data, Packet, Rest}) ->
+ {bpf_buf, Time, Datalen, Packet, Rest};
+buf_2(_Time, _Datalen, Error) ->
Error.
@@ -268,7 +268,7 @@ hdr(Data) ->
{error, bad_hdr}
end.
-packet(Hdrlen, Caplen, Data) ->
+data(Hdrlen, Caplen, Data) ->
% FIXME In some cases, 2 bytes of padding is lost or
% FIXME dropped. For example, a packet of 174 bytes
@@ -283,7 +283,7 @@ packet(Hdrlen, Caplen, Data) ->
case Data of
<<_Hdr:Hdrlen/bytes, Packet:Caplen/bytes,
_Pad:Pad/bytes, Rest/binary>> ->
- {bpf_packet, Packet, Rest};
+ {bpf_data, Packet, Rest};
_ ->
{error, bad_data}
end.

0 comments on commit a39e9d3

Please sign in to comment.