Permalink
Browse files

Represent unused fields in #dns_opt_owner{} as empty binaries

  • Loading branch information...
1 parent 5715d8c commit 1ff4bde2e067bc75e6cea8d0dde0dd796b7cba5b @andrewtj andrewtj committed Mar 7, 2012
Showing with 9 additions and 6 deletions.
  1. +4 −2 include/dns_tests.hrl
  2. +5 −4 src/dns.erl
View
@@ -226,9 +226,11 @@ decode_encode_optdata_owner_test_() ->
password = crypto:rand_bytes(4)},
#dns_opt_owner{seq = crypto:rand_uniform(0, 255),
primary_mac = crypto:rand_bytes(6),
- wakeup_mac = crypto:rand_bytes(6)},
+ wakeup_mac = crypto:rand_bytes(6),
+ _ = <<>>},
#dns_opt_owner{seq = crypto:rand_uniform(0, 255),
- primary_mac = crypto:rand_bytes(6)} ],
+ primary_mac = crypto:rand_bytes(6),
+ _ = <<>>} ],
[ ?_assertEqual([Case], decode_optrrdata(encode_optrrdata([Case])))
|| Case <- Cases ].
View
@@ -1274,10 +1274,11 @@ decode_optrrdata(?DNS_EOPTCODE_LLQ, <<1:16, OC:16, EC:16, Id:64, LeaseLife:32>>)
decode_optrrdata(?DNS_EOPTCODE_NSID, Data) ->
#dns_opt_nsid{data = Data};
decode_optrrdata(?DNS_EOPTCODE_OWNER, <<0:8, S:8, PMAC:6/binary>>) ->
- #dns_opt_owner{seq = S, primary_mac = PMAC};
+ #dns_opt_owner{seq = S, primary_mac = PMAC, _ = <<>>};
decode_optrrdata(?DNS_EOPTCODE_OWNER,
<<0:8, S:8, PMAC:6/binary, WMAC:6/binary>>) ->
- #dns_opt_owner{seq = S, primary_mac = PMAC, wakeup_mac = WMAC};
+ #dns_opt_owner{seq = S, primary_mac = PMAC, wakeup_mac = WMAC,
+ password = <<>>};
decode_optrrdata(?DNS_EOPTCODE_OWNER, <<0:8, S:8, PMAC:6/binary, WMAC:6/binary,
Password/binary>>) ->
#dns_opt_owner{seq = S, primary_mac = PMAC, wakeup_mac = WMAC,
@@ -1302,10 +1303,10 @@ encode_optrrdata(#dns_opt_owner{seq = S, primary_mac = PMAC, wakeup_mac = WMAC,
Bin = <<0:8, S:8, PMAC/binary, WMAC/binary, Password/binary>>,
{?DNS_EOPTCODE_OWNER, Bin};
encode_optrrdata(#dns_opt_owner{seq = S, primary_mac = PMAC, wakeup_mac = WMAC,
- password = undefined})
+ password = <<>>})
when byte_size(PMAC) =:= 6 andalso byte_size(WMAC) =:= 6 ->
{?DNS_EOPTCODE_OWNER, <<0:8, S:8, PMAC/binary, WMAC/binary>>};
-encode_optrrdata(#dns_opt_owner{seq = S, primary_mac = PMAC, _ = undefined})
+encode_optrrdata(#dns_opt_owner{seq = S, primary_mac = PMAC, _ = <<>>})
when byte_size(PMAC) =:= 6 ->
{?DNS_EOPTCODE_OWNER, <<0:8, S:8, PMAC/binary>>};
encode_optrrdata(#dns_opt_unknown{id = Id, bin = Data})

0 comments on commit 1ff4bde

Please sign in to comment.