Ignore:
Timestamp:
Dec 14, 2009, 2:07:47 AM (12 years ago)
Author:
charles
Message:

(trunk libT) #2667 "Ignore martian addresses in LTEP messages" -- implemented for 1.80

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r9679 r9748  
    634634    return have_ipv6 ? ipv6 : NULL;
    635635}
     636
     637int
     638tr_isMartian( int af, const unsigned char * address )
     639{
     640    static const unsigned char v4prefix[16] =
     641        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
     642    static const unsigned char zeroes[16] =
     643        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
     644
     645    switch( af )
     646    {
     647        case AF_INET:
     648            return (address[0] == 0) ||
     649                   (address[0] == 127) ||
     650                   ((address[0] & 0xE0) == 0xE0);
     651
     652        case AF_INET6:
     653            return (address[0] == 0xFF) ||
     654                   (address[0] == 0xFE && (address[1] & 0xC0) == 0x80) ||
     655                   (memcmp(address, zeroes, 15) == 0 && (address[15] == 0 || address[15] == 1)) ||
     656                   (memcmp(address, v4prefix, 12) == 0);
     657
     658        default:
     659            return FALSE;
     660    }
     661}
Note: See TracChangeset for help on using the changeset viewer.