anchor.diff:  encode_port(Port) ->
       enet_services:encode_port(udp, Port).
   
  +check_sum(16#FFFF, _IPH, _Length, _Data) ->
  +    no_checksum;
   check_sum(Csum, #ipv4_pseudo_hdr{src=Src, dst=Dst, proto=Proto},
  -          Length, Data) ->
  -    Pkt = <<Src:32, Dst:32, 0:8, Proto:8, Length:16,
  +          Length, Data)
  +  when is_integer(Csum), is_binary(Data), is_integer(Length),
  +       is_binary(Src), is_binary(Dst), is_integer(Proto) ->
  +    Pkt = <<Src:4/binary, Dst:4/binary, 0:8, Proto:8/big, Length:16/big,
              Data/binary>>,
  -    enet_checksum:oc16_sum(Pkt, Csum).
  +    enet_checksum:oc16_check(Pkt, Csum).
  +
  +sum(Data, Length, #ipv4_pseudo_hdr{src=Src, dst=Dst, proto=Proto}) ->
  +    Pkt = <<Src:4/binary, Dst:4/binary, 0:8, Proto:8/big, Length:16/big,
  +           Data/binary>>,
  +    enet_checksum:oc16_sum(Pkt).
   
   %%====================================================================
   %% Internal functions
  
positive.code: decode(<<Src:16/big, Dst:16/big,
          Length:16/big, Csum:16/big,
          Data/binary>> = Pkt,
         [IPH = #ipv4_pseudo_hdr{} | _DecodeOpts])
    when byte_size(Data) =:= Length - 8 ->
      case decode_port(Dst) of
          Dns when Dns =:= <<"dns">>; Dns =:= <<"mdns">> ->
              #udp{src_port=decode_port(Src), dst_port=decode_port(Dst),
                   length=Length, csum=check_sum(Csum, IPH, Length, Data),
                   data=enet_dns:decode(Data)};
          _ ->
              #udp{src_port=decode_port(Src), dst_port=decode_port(Dst),
                   length=Length, csum=Csum,
                   data=Data}
      end;
  decode(_Packet, _DecodeOpts) ->
      {error, bad_packet}.
  
  
  expand(Pkt = #udp{length=undefined,
                    data=Data}) when is_binary(Data) ->
      encode(Pkt#udp{length=byte_size(Data)});
  expand(Pkt = #udp{src_port=Src}) when not is_binary(Src) ->
      expand(Pkt#udp{src_port=encode_port(Src)});
  expand(Pkt = #udp{dst_port=Dst}) when not is_binary(Dst) ->
      expand(Pkt#udp{dst_port=encode_port(Dst)});
  expand(Pkt = #udp{src_port=Src,
                    dst_port=Dst,
                    length=Length,
                    csum=Csum,
                    data=Data})
    when is_binary(Src), is_binary(Dst),
         is_integer(Length), is_integer(Csum),
         is_binary(Data) ->
  
negative.code: -module(enet_udp).
  
  %% API
  -export([decode/2
           ,expand/2
           ,encode/2
           ,decode_port/1
           ,encode_port/1
          ]).
  
  -include("types.hrl").
  -define(UDP_HEADER_LEN, 8).
  
  %%====================================================================
  %% API
  