Changeset 12147


Ignore:
Timestamp:
Mar 13, 2011, 8:15:40 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) use libevent2's portability wrappers for inet_ntop() and inet_pton().

We currently implement our own versions of these on mingw because that platform doesn't have them... but why reinvent the wheel; libevent has already done the same thing. Let's use libevent2's implementation.
has already done it for us.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer-http.c

    r12141 r12147  
    107107    if( ipv6 ) {
    108108        char ipv6_readable[INET6_ADDRSTRLEN];
    109         inet_ntop( AF_INET6, ipv6, ipv6_readable, INET6_ADDRSTRLEN );
     109        evutil_inet_ntop( AF_INET6, ipv6, ipv6_readable, INET6_ADDRSTRLEN );
    110110        evbuffer_add_printf( buf, "&ipv6=");
    111111        tr_http_escape( buf, ipv6_readable, -1, TRUE );
  • trunk/libtransmission/net.c

    r12096 r12147  
    6565const tr_address tr_inaddr_any = { TR_AF_INET, { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } };
    6666
    67 #ifdef WIN32
    68 const char *
    69 inet_ntop( int af, const void * src, char * dst, socklen_t cnt )
    70 {
    71     if (af == AF_INET)
    72     {
    73         struct sockaddr_in in;
    74         memset( &in, 0, sizeof( in ) );
    75         in.sin_family = AF_INET;
    76         memcpy( &in.sin_addr, src, sizeof( struct in_addr ) );
    77         getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in),
    78                     dst, cnt, NULL, 0, NI_NUMERICHOST);
    79         return dst;
    80     }
    81     else if (af == AF_INET6)
    82     {
    83         struct sockaddr_in6 in;
    84         memset( &in, 0, sizeof( in ) );
    85         in.sin6_family = AF_INET6;
    86         memcpy( &in.sin6_addr, src, sizeof( struct in_addr6 ) );
    87         getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6),
    88                     dst, cnt, NULL, 0, NI_NUMERICHOST);
    89         return dst;
    90     }
    91     return NULL;
    92 }
    93 
    94 int
    95 inet_pton( int af, const char * src, void * dst )
    96 {
    97     struct addrinfo hints, *res, *ressave;
    98     struct sockaddr_in * s4;
    99     struct sockaddr_in6 * s6;
    100 
    101     memset( &hints, 0, sizeof( struct addrinfo ));
    102     hints.ai_family = af;
    103     hints.ai_flags = AI_NUMERICHOST;
    104 
    105     if( getaddrinfo( src, NULL, &hints, &res ) ) {
    106         if( WSAGetLastError() == WSAHOST_NOT_FOUND )
    107             return 0;
    108         else {
    109             errno = EAFNOSUPPORT;
    110             return -1;
    111         }
    112     }
    113 
    114     ressave = res;
    115     while( res ) {
    116         switch (res->ai_family) {
    117             case AF_INET:
    118                 s4 = (struct sockaddr_in *) res->ai_addr;
    119                 memcpy( dst, &s4->sin_addr, sizeof( struct in_addr ) );
    120                 break;
    121             case AF_INET6:
    122                 s6 = (struct sockaddr_in6 *) res->ai_addr;
    123                 memcpy( dst, &s6->sin6_addr, sizeof( struct in6_addr ) );
    124                 break;
    125             default: /* AF_UNSPEC, AF_NETBIOS */
    126                 break;
    127         }
    128         res = res->ai_next;
    129     }
    130 
    131     freeaddrinfo(ressave);
    132     return 1;
    133 }
    134 #endif
    135 
    13667void
    13768tr_netInit( void )
     
    16798
    16899    if( src->type == TR_AF_INET )
    169         return inet_ntop( AF_INET, &src->addr, dst, size );
     100        return evutil_inet_ntop( AF_INET, &src->addr, dst, size );
    170101    else
    171         return inet_ntop( AF_INET6, &src->addr, dst, size );
     102        return evutil_inet_ntop( AF_INET6, &src->addr, dst, size );
    172103}
    173104
     
    187118tr_pton( const char * src, tr_address * dst )
    188119{
    189     int retval = inet_pton( AF_INET, src, &dst->addr );
     120    int retval = evutil_inet_pton( AF_INET, src, &dst->addr );
    190121    assert( dst );
    191122    if( retval < 0 )
    192123        return NULL;
    193124    else if( retval == 0 )
    194         retval = inet_pton( AF_INET6, src, &dst->addr );
     125        retval = evutil_inet_pton( AF_INET6, src, &dst->addr );
    195126    else
    196127    {
     
    600531        memset(&sin, 0, sizeof(sin));
    601532        sin.sin_family = AF_INET;
    602         inet_pton(AF_INET, "91.121.74.28", &sin.sin_addr);
     533        evutil_inet_pton(AF_INET, "91.121.74.28", &sin.sin_addr);
    603534        sin.sin_port = htons(6969);
    604535        sa = (struct sockaddr*)&sin;
     
    610541        /* In order for address selection to work right, this should be
    611542           a native IPv6 address, not Teredo or 6to4. */
    612         inet_pton(AF_INET6, "2001:1890:1112:1::20", &sin6.sin6_addr);
     543        evutil_inet_pton(AF_INET6, "2001:1890:1112:1::20", &sin6.sin6_addr);
    613544        sin6.sin6_port = htons(6969);
    614545        sa = (struct sockaddr*)&sin6;
  • trunk/libtransmission/net.h

    r12096 r12147  
    146146#include <ws2tcpip.h>           /* socklen_t */
    147147
    148 /** @brief Missing in Windows and Mingw */
    149 const char *inet_ntop( int af, const void *src, char *dst, socklen_t cnt );
    150 int inet_pton(int af, const char *src, void *dst);
    151148#endif
    152149
  • trunk/libtransmission/tr-lpd.c

    r12093 r12147  
    292292        lpd_mcastAddr.sin_family = AF_INET;
    293293        lpd_mcastAddr.sin_port = htons( lpd_mcastPort );
    294         if( inet_pton( lpd_mcastAddr.sin_family, lpd_mcastGroup,
     294        if( evutil_inet_pton( lpd_mcastAddr.sin_family, lpd_mcastGroup,
    295295                &lpd_mcastAddr.sin_addr ) < 0 )
    296296            goto fail;
Note: See TracChangeset for help on using the changeset viewer.