anchor.diff:      Header = <<?IP_VERSION:4, HLen:4, DiffServ:8, TotLen:16,
                 ID:16, Flags:3/bits, FragOff:13, TTL:8, Proto:8, 0:16,
                 SrcIP:4/binary, DestIP:4/binary, RestDgram/binary>>,
  -    checksum(Header).
  -
  -checksum(Bin) when is_binary(Bin) ->
  -    lists:foldl(fun checksum/2,
  -                0,
  -                [N || <<N:16/big>> <= Bin]).
  -
  -%% 16 bits Ones complement addition.
  -checksum(A, Sum) ->
  -    case A + Sum of
  -        N when N > 16#FFFF ->
  -            N - 16#10000 + 1;
  -        N when N =< 16#FFFF ->
  -            N
  -    end.
  +    enet_checksum:oc16_sum(Header).
   
   decode_option_type(0,  0) -> eool;
   decode_option_type(0,  1) -> nop;
  
positive.code:     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,
  
negative.code: -module(enet_ipv4).
  
  %% API
  -export([decode_addr/1, encode_addr/1
           ,decode/1, decode/2
           ,encode/1, expand/1
           ,decode_protocol/1, encode_protocol/1
           ,header_checksum/1
           ,addr_len/0
          ]).
  
  -include("types.hrl").
  -define(IP_VERSION, 4).
  