Ignore:
Timestamp:
Dec 1, 2007 8:52:57 AM (16 years ago)
Author:
bennylp
Message:

More ticket #415: more IPv6 and some reorganization of the source codes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/sock_bsd.c

    r1587 r1601  
    124124 
    125125 
    126 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 
    127 #   define SET_LEN(addr,len) (((pj_sockaddr_in*)(addr))->sin_zero_len=(len)) 
    128 #   define RESET_LEN(addr)   (((pj_sockaddr_in*)(addr))->sin_zero_len=0) 
    129 #else 
    130 #   define SET_LEN(addr,len)  
    131 #   define RESET_LEN(addr) 
    132 #endif 
    133  
    134  
    135126/* 
    136127 * Convert 16-bit value from network byte order to host byte order. 
     
    222213    char tempaddr[PJ_INET6_ADDRSTRLEN]; 
    223214 
    224     PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL); 
     215    PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EAFNOTSUP); 
    225216    PJ_ASSERT_RETURN(src && src->slen && dst, PJ_EINVAL); 
    226217 
     
    311302    *dst = '\0'; 
    312303 
    313     PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL); 
     304    PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EAFNOTSUP); 
    314305 
    315306#if defined(PJ_SOCK_HAS_INET_NTOP) && PJ_SOCK_HAS_INET_NTOP != 0 
     
    354345        } else { 
    355346            pj_assert(!"Unsupported address family"); 
    356             return PJ_EINVAL; 
     347            return PJ_EAFNOTSUP; 
    357348        } 
    358349 
     
    387378#endif 
    388379} 
    389  
    390 /* 
    391  * Convert address string with numbers and dots to binary IP address. 
    392  */  
    393 PJ_DEF(pj_in_addr) pj_inet_addr(const pj_str_t *cp) 
    394 { 
    395     pj_in_addr addr; 
    396  
    397     pj_inet_aton(cp, &addr); 
    398     return addr; 
    399 } 
    400  
    401 /* 
    402  * Convert address string with numbers and dots to binary IP address. 
    403  */  
    404 PJ_DEF(pj_in_addr) pj_inet_addr2(const char *cp) 
    405 { 
    406     pj_str_t str = pj_str((char*)cp); 
    407     return pj_inet_addr(&str); 
    408 } 
    409  
    410 /* 
    411  * Set the IP address of an IP socket address from string address,  
    412  * with resolving the host if necessary. The string address may be in a 
    413  * standard numbers and dots notation or may be a hostname. If hostname 
    414  * is specified, then the function will resolve the host into the IP 
    415  * address. 
    416  */ 
    417 PJ_DEF(pj_status_t) pj_sockaddr_in_set_str_addr( pj_sockaddr_in *addr, 
    418                                                  const pj_str_t *str_addr) 
    419 { 
    420     PJ_CHECK_STACK(); 
    421  
    422     PJ_ASSERT_RETURN(!str_addr || str_addr->slen < PJ_MAX_HOSTNAME,  
    423                      (addr->sin_addr.s_addr=PJ_INADDR_NONE, PJ_EINVAL)); 
    424  
    425     RESET_LEN(addr); 
    426     addr->sin_family = AF_INET; 
    427     pj_bzero(addr->sin_zero, sizeof(addr->sin_zero)); 
    428  
    429     if (str_addr && str_addr->slen) { 
    430         addr->sin_addr = pj_inet_addr(str_addr); 
    431         if (addr->sin_addr.s_addr == PJ_INADDR_NONE) { 
    432             pj_hostent he; 
    433             pj_status_t rc; 
    434  
    435             rc = pj_gethostbyname(str_addr, &he); 
    436             if (rc == 0) { 
    437                 addr->sin_addr.s_addr = *(pj_uint32_t*)he.h_addr; 
    438             } else { 
    439                 addr->sin_addr.s_addr = PJ_INADDR_NONE; 
    440                 return rc; 
    441             } 
    442         } 
    443  
    444     } else { 
    445         addr->sin_addr.s_addr = 0; 
    446     } 
    447  
    448     return PJ_SUCCESS; 
    449 } 
    450  
    451 /* 
    452  * Set the IP address and port of an IP socket address. 
    453  * The string address may be in a standard numbers and dots notation or  
    454  * may be a hostname. If hostname is specified, then the function will  
    455  * resolve the host into the IP address. 
    456  */ 
    457 PJ_DEF(pj_status_t) pj_sockaddr_in_init( pj_sockaddr_in *addr, 
    458                                          const pj_str_t *str_addr, 
    459                                          pj_uint16_t port) 
    460 { 
    461     PJ_ASSERT_RETURN(addr, (addr->sin_addr.s_addr=PJ_INADDR_NONE, PJ_EINVAL)); 
    462  
    463     RESET_LEN(addr); 
    464     addr->sin_family = PJ_AF_INET; 
    465     pj_bzero(addr->sin_zero, sizeof(addr->sin_zero)); 
    466     pj_sockaddr_in_set_port(addr, port); 
    467     return pj_sockaddr_in_set_str_addr(addr, str_addr); 
    468 } 
    469  
    470380 
    471381/* 
     
    491401} 
    492402 
    493 /* 
    494  * Get first IP address associated with the hostname. 
    495  */ 
    496 PJ_DEF(pj_in_addr) pj_gethostaddr(void) 
    497 { 
    498     pj_sockaddr_in addr; 
    499     const pj_str_t *hostname = pj_gethostname(); 
    500  
    501     pj_sockaddr_in_set_str_addr(&addr, hostname); 
    502     return addr.sin_addr; 
    503 } 
    504  
    505  
    506403#if defined(PJ_WIN32) 
    507404/* 
     
    583480    PJ_CHECK_STACK(); 
    584481 
    585     SET_LEN(&addr, sizeof(pj_sockaddr_in)); 
     482    PJ_SOCKADDR_SET_LEN(&addr, sizeof(pj_sockaddr_in)); 
    586483    addr.sin_family = PJ_AF_INET; 
    587484    pj_bzero(addr.sin_zero, sizeof(addr.sin_zero)); 
     
    625522        return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); 
    626523    else { 
    627         RESET_LEN(addr); 
     524        PJ_SOCKADDR_RESET_LEN(addr); 
    628525        return PJ_SUCCESS; 
    629526    } 
     
    641538        return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); 
    642539    else { 
    643         RESET_LEN(addr); 
     540        PJ_SOCKADDR_RESET_LEN(addr); 
    644541        return PJ_SUCCESS; 
    645542    } 
     
    727624        return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); 
    728625    else { 
    729         RESET_LEN(from); 
     626        PJ_SOCKADDR_RESET_LEN(from); 
    730627        return PJ_SUCCESS; 
    731628    } 
     
    821718#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 
    822719    if (addr) { 
    823         SET_LEN(addr, *addrlen); 
     720        PJ_SOCKADDR_SET_LEN(addr, *addrlen); 
    824721    } 
    825722#endif 
     
    832729#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 
    833730        if (addr) { 
    834             RESET_LEN(addr); 
     731            PJ_SOCKADDR_RESET_LEN(addr); 
    835732        } 
    836733#endif 
Note: See TracChangeset for help on using the changeset viewer.