Skip to content

Commit

Permalink
bpf: include header length in padding calculation
Browse files Browse the repository at this point in the history
The bpf man page states when calculating the start of the next packet,
use:

    p = (char *)p + BPF_WORDALIGN(p->bh_hdrlen + p->bh_caplen)

Add a BPF_WORDALIGN macro for compat use.
  • Loading branch information
msantos committed Apr 20, 2011
1 parent e87d6a9 commit de06651
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/bpf.hrl
Expand Up @@ -74,7 +74,10 @@
-define(SIZEOF_STRUCT_BPF_DLTLIST,
(?SIZEOF_U_INT + ?SIZEOF_U_INT + 4)).

%% #define BPF_ALIGNMENT sizeof(int32_t)
-define(BPF_ALIGNMENT, ?SIZEOF_INT32_T).
%% #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
-define(BPF_WORDALIGN(X), bpf:align(X)).

-define(IOC_IN, 16#80000000).
-define(IOC_OUT, 16#40000000).
Expand Down
4 changes: 1 addition & 3 deletions src/bpf.erl
Expand Up @@ -225,8 +225,6 @@ bool(<<0:32>>) -> false.
%% On 32-bit, struct timeval32: 4 bytes tv_sec, 4 bytes tv_usec
%% On 64-bit, struct timeval: 8 bytes tv_sec, 4 bytes tv_usec

%% #define BPF_ALIGNMENT sizeof(int32_t)
%% #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
pad(Len) ->
align(Len) - Len.

Expand All @@ -245,7 +243,7 @@ data(Data) when is_binary(Data) ->

Time = {Sec div 1000000, Sec rem 1000000, Usec},

Pad = pad(Caplen),
Pad = pad(Hdrlen + Caplen),

% Include the padding
<<_Hdr:Hdrlen/bytes,
Expand Down

0 comments on commit de06651

Please sign in to comment.