Permalink
Browse files

bpf: include header length in padding calculation

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...
1 parent e87d6a9 commit de06651ca937f22cc5b79fdcca4fbe69410b4d34 @msantos committed Apr 20, 2011
Showing with 4 additions and 3 deletions.
  1. +3 −0 include/bpf.hrl
  2. +1 −3 src/bpf.erl
View
@@ -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).
View
@@ -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.
@@ -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,

0 comments on commit de06651

Please sign in to comment.