anchor.diff:            frag_offset=FragOff,
             ttl=TTL,
             proto=Protocol,
  -          hdr_csum=HdrChkSum,
  +          hdr_csum=check_header_checksum(Dgram, HLen, HdrChkSum),
             src=decode_addr(SrcIP),
             dst=decode_addr(DestIP),
             options=decode_options(Opts),
  -          data=enet_codec:decode(Protocol, Data)};
  -decode(_Dgram) ->
  +          data=enet_codec:decode(Protocol, Data, DecodeOptions)};
  +decode(_Dgram, _) ->
       {error, bad_packet}.
  +
  +expand(Pkt = #ipv4{options=Opts}) when is_list(Opts) ->
  +    expand(Pkt#ipv4{options=encode_options(Opts)});
  +expand(Pkt = #ipv4{hlen=H, options=Opts}) when not is_integer(H), is_binary(Opts) ->
  +    expand(Pkt#ipv4{hlen=5 + (byte_size(Opts) div 4)});
  +expand(Pkt = #ipv4{totlen=T, hlen=H, data=D})
  +  when not is_integer(T), is_integer(H), is_binary(D) ->
  +    expand(Pkt#ipv4{totlen=H + byte_size(D)});
  +expand(Pkt = #ipv4{flags=Flags}) when is_list(Flags) ->
  +    expand(Pkt#ipv4{flags=encode_flags(Flags)});
  +expand(Pkt = #ipv4{src=Src}) when not (is_binary(Src) andalso byte_size(Src) =:= 4) ->
  +    expand(Pkt#ipv4{src=encode_addr(Src)});
  +expand(Pkt = #ipv4{dst=Dst}) when not (is_binary(Dst) andalso byte_size(Dst) =:= 4) ->
  +    expand(Pkt#ipv4{dst=encode_addr(Dst)});
  +expand(Pkt = #ipv4{proto=P}) when not is_integer(P) ->
  +    expand(Pkt#ipv4{proto=encode_protocol(P)});
  +expand(Pkt = #ipv4{hdr_csum=S}) when not is_integer(S) ->
  +    expand(Pkt#ipv4{hdr_csum=header_checksum(Pkt)});
  +expand(Pkt) ->
  +    Pkt.
   
   encode(#ipv4{vsn=?IP_VERSION,
                hlen=HLen,
  
positive.code: %% API
  %%====================================================================
  
  decode(Dgram = <<?IP_VERSION:4, HLen:4, DiffServ:8, TotLen:16,
                  ID:16, Flgs:3/bits, FragOff:13, TTL:8, Proto:8, HdrChkSum:16,
                  SrcIP:4/binary, DestIP:4/binary, RestDgram/binary>>)
    when HLen >= 5, 4*HLen =< byte_size(Dgram) ->
      OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN),
      <<Opts:OptsLen/binary, Data/binary>> = RestDgram,
      Protocol = decode_protocol(Proto),
      #ipv4{vsn=?IP_VERSION,
  
negative.code:              src=SrcIP,
               dst=DestIP,
               options=Options,
               data=Data})
    when is_integer(HLen), is_integer(DiffServ),
         is_integer(TotLen), is_integer(ID),
         is_bitstring(Flags), is_integer(FragOff), is_integer(TTL),
         is_integer(HdrChkSum), is_binary(SrcIP), is_binary(DestIP),
         is_binary(Data), is_binary(Options) ->
      OptsLen = byte_size(Options),
      RestDgram = <<Options:OptsLen/binary, Data/binary>>,
      <<?IP_VERSION:4, HLen:4, DiffServ:8, TotLen:16,
       ID:16, Flags:3/bits, FragOff:13, TTL:8, Proto:8, HdrChkSum:16,
       SrcIP:4/binary, DestIP:4/binary, RestDgram/binary>>;
  encode(Pkt) ->
      encode(expand(Pkt)).
  
  addr_len() -> 4.
  
  