anchor.diff:        lager:debug("Backend: ~p", [Backend]),
         SrcAddr = IP#ipv4.saddr,
         SrcPort = TCP#tcp.sport,
  -      NewSrcAddr = get_src_addr(SrcAddr, BackendIP),
  +      NewSrcAddr = get_src_addr(SrcAddr, BackendIP, LocalAddresses),
         Mapping = #mapping{orig_src_ip = SrcAddr,
           orig_src_port = SrcPort,
           orig_dst_ip = DstAddr,
  
positive.code: -include("enfhackery.hrl").
  -define(SERVER, ?MODULE).
  
  -record(state, {socket}).
  
  %%%===================================================================
  %%% API
  %%%===================================================================
  
  handle(Payload) ->
    catch gen_server:call(?SERVER, {handle_payload, Payload}).
  
negative.code:         new_src_port = SrcPort - 31743,
          new_dst_ip = BackendIP,
          new_dst_port = BackendPort},
        {ok, Mapping};
  
      Else ->
        lager:debug("Could not map connection"),
        {error, {no_backend, Else}}
    end.
  
  
  
  -ifdef(TEST).
  
  local_to_foreign_test() ->
    Payload = <<>>,
    TCP = #tcp{sport = 55000, dport = 1000},
    IPv4 = #ipv4{daddr = {1,1,1,1}},
    Packet = <<(pkt:ipv4(IPv4))/binary, (pkt:tcp(TCP))/binary, Payload/binary>>,
    {ok, InetIfaddrs} = inet:getifaddrs(),
    InetIfaddrsSet = inet_ifaddrs_to_set(InetIfaddrs),
    meck:new(minuteman_vip_server),
    meck:expect(minuteman_vip_server, get_backend, fun({1,1,1,1}, 1000) ->  {ok, {{8,8,8,8},31421}} end),
    ExpectedMapping = #mapping{
      orig_src_ip = {127,0,0,1},
      orig_src_port = 55000,
      orig_dst_ip = {1,1,1,1},
      orig_dst_port = 1000,
      new_src_ip = {127,0,0,1},
      new_src_port = 23257,
      new_dst_ip = {8,8,8,8},
      new_dst_port = 31421},
    ?assertEqual({ok, ExpectedMapping}, to_mapping(Packet, InetIfaddrsSet)),
    meck:unload(minuteman_vip_server).
  
  foreign_to_foreign_test() ->
    Payload = <<>>,
    TCP = #tcp{sport = 55000, dport = 1000},
    IPv4 = #ipv4{saddr = {8,8,4,4}, daddr = {1,1,1,1}},
    Packet = <<(pkt:ipv4(IPv4))/binary, (pkt:tcp(TCP))/binary, Payload/binary>>,
    {ok, InetIfaddrs} = inet:getifaddrs(),
    InetIfaddrsSet = inet_ifaddrs_to_set(InetIfaddrs),
    meck:new(minuteman_vip_server),
    meck:expect(minuteman_vip_server, get_backend, fun({1,1,1,1}, 1000) ->  {ok, {{8,8,8,8},31421}} end),
    meck:new(minuteman_routes),
    meck:expect(minuteman_routes, get_route, fun({8,8,8,8}) -> {ok, [{prefsrc, {9,9,9,9}}]} end),
    ExpectedMapping = #mapping{
      orig_src_ip = {8,8,4,4},
      orig_src_port = 55000,
      orig_dst_ip = {1,1,1,1},
      orig_dst_port = 1000,
      new_src_ip = {9,9,9,9},
      new_src_port = 23257,
      new_dst_ip = {8,8,8,8},
      new_dst_port = 31421},
    ?assertEqual({ok, ExpectedMapping}, to_mapping(Packet, InetIfaddrsSet)),
    meck:unload(minuteman_vip_server),
    meck:unload(minuteman_routes).
  -endif.
  