Skip to content
Browse files

bpf: force evaluation order of macros

  • Loading branch information...
1 parent 0f8df89 commit e01409a45297a8f3dd2d0740b59c83e21d5781a0 @msantos committed
Showing with 14 additions and 12 deletions.
  1. +13 −11 include/bpf.hrl
  2. +1 −1 src/bpf.erl
View
24 include/bpf.hrl
@@ -48,20 +48,21 @@
%% u_char jf;
%% bpf_u_int32 k;
%% };
--define(SIZEOF_STRUCT_BPF_PROGRAM, 2 + 1 + 1 + ?SIZEOF_U_INT).
+-define(SIZEOF_STRUCT_BPF_PROGRAM,
+ (2 + 1 + 1 + ?SIZEOF_U_INT)).
%% struct bpf_stat {
%% u_int bs_recv;
%% u_int bs_drop;
%% };
-define(SIZEOF_STRUCT_BPF_STAT,
- ?SIZEOF_U_INT + ?SIZEOF_U_INT).
+ (?SIZEOF_U_INT + ?SIZEOF_U_INT)).
%% struct bpf_version {
%% u_short bv_major;
%% u_short bv_minor;
%% };
--define(SIZEOF_STRUCT_BPF_VERSION, 2 + 2).
+-define(SIZEOF_STRUCT_BPF_VERSION, (2 + 2)).
%% struct bpf_dltlist {
%% u_int32_t bfl_len;
@@ -71,7 +72,7 @@
%% } bfl_u;
%% };
-define(SIZEOF_STRUCT_BPF_DLTLIST,
- ?SIZEOF_U_INT + ?SIZEOF_U_INT + 4).
+ (?SIZEOF_U_INT + ?SIZEOF_U_INT + 4)).
-define(BPF_ALIGNMENT, ?SIZEOF_INT32_T).
@@ -103,6 +104,7 @@
-define(BIOCSDLT, bpf:iow($B, 120, ?SIZEOF_U_INT)).
-define(BIOCGDLTLIST, bpf:iowr($B, 121, ?SIZEOF_STRUCT_BPF_DLTLIST)).
+%% Datalink types
-define(DLT_NULL, 0).
-define(DLT_EN10MB, 1).
-define(DLT_EN3MB, 2).
@@ -137,7 +139,7 @@
%%-------------------------------------------------------------------------
%% instruction classes
--define(BPF_CLASS(Code), Code band 16#07).
+-define(BPF_CLASS(Code), (Code band 16#07)).
-define(BPF_LD, 16#00).
-define(BPF_LDX, 16#01).
-define(BPF_ST, 16#02).
@@ -148,11 +150,11 @@
-define(BPF_MISC, 16#07).
%% ld/ldx fields
--define(BPF_SIZE(Code), Code band 16#18).
+-define(BPF_SIZE(Code), (Code band 16#18)).
-define(BPF_W, 16#00).
-define(BPF_H, 16#08).
-define(BPF_B, 16#10).
--define(BPF_MODE(Code), Code band 16#e0).
+-define(BPF_MODE(Code), (Code band 16#e0)).
-define(BPF_IMM, 16#00).
-define(BPF_ABS, 16#20).
-define(BPF_IND, 16#40).
@@ -161,7 +163,7 @@
-define(BPF_MSH, 16#a0).
%% alu/jmp fields
--define(BPF_OP(Code), Code band 16#f0).
+-define(BPF_OP(Code), (Code band 16#f0)).
-define(BPF_ADD, 16#00).
-define(BPF_SUB, 16#10).
-define(BPF_MUL, 16#20).
@@ -176,16 +178,16 @@
-define(BPF_JGT, 16#20).
-define(BPF_JGE, 16#30).
-define(BPF_JSET, 16#40).
--define(BPF_SRC(Code), Code band 16#08).
+-define(BPF_SRC(Code), (Code band 16#08)).
-define(BPF_K, 16#00).
-define(BPF_X, 16#08).
%% ret - BPF_K and BPF_X also apply
--define(BPF_RVAL(Code), Code band 16#18).
+-define(BPF_RVAL(Code), (Code band 16#18)).
-define(BPF_A, 16#10).
%% misc
--define(BPF_MISCOP(Code), Code band 16#f8).
+-define(BPF_MISCOP(Code), (Code band 16#f8)).
-define(BPF_TAX, 16#00).
-define(BPF_TXA, 16#80).
View
2 src/bpf.erl
@@ -185,7 +185,7 @@ ctl(Socket, seesent, Bool) when Bool == true; Bool == false ->
procket:ioctl(Socket, ?BIOCSSEESENT, bool(Bool));
ctl(Socket, setf, []) ->
- procket:ioctl(Socket, ?BIOCSETF, <<0:((?SIZEOF_STRUCT_BPF_PROGRAM)*8)>>);
+ procket:ioctl(Socket, ?BIOCSETF, <<0:(?SIZEOF_STRUCT_BPF_PROGRAM*8)>>);
ctl(Socket, setf, Insn) when is_list(Insn) ->
% struct bpf_program
{ok, Code, [Res]} = procket:alloc([

0 comments on commit e01409a

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