diff --git a/libtransmission/net.c b/libtransmission/net.c index 171e0dd9f..643c9235c 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -170,18 +170,6 @@ tr_pton( const char * src, tr_address * dst ) return dst; } -void -tr_normalizeV4Mapped( tr_address * const addr ) -{ - assert( tr_isAddress( addr ) ); - - if( addr->type == TR_AF_INET6 && IN6_IS_ADDR_V4MAPPED( &addr->addr.addr6 ) ) - { - addr->type = TR_AF_INET; - memcpy( &addr->addr.addr4.s_addr, addr->addr.addr6.s6_addr + 12, 4 ); - } -} - /* * Compare two tr_address structures. * Returns: @@ -428,11 +416,23 @@ isMulticastAddress( const tr_address * addr ) return FALSE; } +static TR_INLINE tr_bool +isIPv4MappedOrCompatAddress( const tr_address * addr ) +{ + if( addr->type == TR_AF_INET6 ) + { + if( IN6_IS_ADDR_V4MAPPED( &addr->addr.addr6 ) || + IN6_IS_ADDR_V4COMPAT( &addr->addr.addr6 ) ) + return TRUE; + } + return FALSE; +} + static TR_INLINE tr_bool isIPv6LinkLocalAddress( const tr_address * addr ) { if( addr->type == TR_AF_INET6 && - IN6_IS_ADDR_LINKLOCAL( &addr->addr.addr6 )) + IN6_IS_ADDR_LINKLOCAL( &addr->addr.addr6 ) ) return TRUE; return FALSE; } @@ -440,7 +440,8 @@ isIPv6LinkLocalAddress( const tr_address * addr ) tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port ) { - if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr ) ) + if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr ) || + isIPv4MappedOrCompatAddress( addr ) ) return FALSE; if( port == 0 ) @@ -461,7 +462,7 @@ tr_netOpenTCP( tr_session * session, assert( tr_isAddress( addr ) ); - if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr )) + if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr ) ) return -EINVAL; if( ( s = createSocket( ( addr->type == TR_AF_INET ? AF_INET : AF_INET6 ), type ) ) < 0 ) diff --git a/libtransmission/net.h b/libtransmission/net.h index 83e114295..0b895fe40 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -86,7 +86,6 @@ tr_address *tr_pton( const char * src, tr_address * dst ); int tr_compareAddresses( const tr_address * a, const tr_address * b); -void tr_normalizeV4Mapped( tr_address * const addr ); tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port ); diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 2a9d3f4d6..472689836 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1830,11 +1830,8 @@ tr_peerMgrPeerStats( const tr_torrent * tor, const tr_peer * peer = peers[i]; const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); tr_peer_stat * stat = ret + i; - tr_address norm_addr; - norm_addr = peer->addr; - tr_normalizeV4Mapped( &norm_addr ); - tr_ntop( &norm_addr, stat->addr, sizeof( stat->addr ) ); + tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) ); tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ), sizeof( stat->client ) ); stat->port = ntohs( peer->port );