Changeset 4759:10a753806fd5 in roaraudio


Ignore:
Timestamp:
02/06/11 03:16:06 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Added IPv6 support

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4756 r4759  
    66        * Added time display to roarvorbis (Closes: #102) 
    77        * Added support to roarshout to read password form user or file (Closes: #101) 
     8        * Added IPv6 support 
    89 
    910v. 0.4beta3 - Wed Jan 26 2011 23:26 CET 
  • configure

    r4751 r4759  
    14941494test_func_defmake ROAR_HAVE_GETSOCKOPT getsockopt 'getsockopt(0, 0, 0, (void*)0, (void*)0)' -- sys/types.h sys/socket.h 
    14951495test_func_defmake ROAR_HAVE_SETSOCKOPT setsockopt 'setsockopt(0, 0, 0, (void*)0, (void*)0)' -- sys/types.h sys/socket.h 
     1496test_func_defmake ROAR_HAVE_GETADDRINFO getaddrinfo 'getaddrinfo((void*)0, (void*)0, (void*)0, (void**)0)' -- sys/types.h sys/socket.h netdb.h 
    14961497test_func_defmake ROAR_HAVE_RAND      rand      'rand()'                     -- stdlib.h 
    14971498test_func_defmake ROAR_HAVE_RAND_R    rand_r    'rand_r((unsigned int*)0)'   -- stdlib.h 
  • libroar/socket.c

    r4708 r4759  
    512512#endif 
    513513 } socket_addr; 
     514 socklen_t addrlen; 
    514515#endif 
    515516#if defined(ROAR_HAVE_IPV4) || defined(ROAR_HAVE_IPV6) 
     
    529530 char * del; 
    530531#endif 
     532 int af_guessed = 0; 
     533#ifdef ROAR_HAVE_GETADDRINFO 
     534 struct addrinfo hints, *res = NULL; 
     535 char port_as_string[32]; 
     536#endif 
    531537 
    532538 ROAR_DBG("roar_socket_open(mode=%i, type=%i, host='%s', port=%i) = ?", mode, type, host, port); 
     
    536542 
    537543 if ( type == ROAR_SOCKET_TYPE_UNKNOWN ) { 
     544  af_guessed = 1; 
    538545  type = ROAR_SOCKET_TYPE_INET; 
    539546  if ( *host == '/' ) { 
     
    614621  ROAR_DBG("roar_socket_open(*): type=INET|INET6, host='%s', port=%i", host, port); 
    615622 
     623#ifdef ROAR_HAVE_GETADDRINFO 
     624  memset(&hints, 0, sizeof(hints)); 
     625  hints.ai_socktype = SOCK_STREAM; 
     626  if ( af_guessed ) { 
     627   hints.ai_family   = AF_UNSPEC; 
     628  } else { 
     629   hints.ai_family   = type == ROAR_SOCKET_TYPE_INET ? AF_INET : AF_INET6; 
     630  } 
     631 
     632  snprintf(port_as_string, sizeof(port_as_string), "%i", port); 
     633 
     634  if ( getaddrinfo(host, port_as_string, &hints, &res) != 0 ) 
     635   return -1; 
     636 
     637  if ( af_guessed ) { 
     638   type = res->ai_family == AF_INET ? ROAR_SOCKET_TYPE_INET : ROAR_SOCKET_TYPE_INET6; 
     639  } 
     640 
     641  if ( type == ROAR_SOCKET_TYPE_INET ) { 
     642   fh = roar_socket_new_tcp(); 
     643  } else { 
     644   fh = roar_socket_new_tcp6(); 
     645  } 
     646 
     647  memcpy(&(socket_addr.sa), res->ai_addr, res->ai_addrlen); 
     648  addrlen = res->ai_addrlen; 
     649 
     650  if ( res != NULL ) 
     651   freeaddrinfo(res); 
     652#else 
    616653  if ( (he = gethostbyname(host)) == NULL ) { 
    617654   ROAR_ERR("roar_socket_open(*): Can\'t resolve host name '%s'", 
     
    622659   ROAR_DBG("roar_socket_open(*): he=%p", he); 
    623660 
    624    memcpy((struct in_addr *)&socket_addr.in.sin_addr, he->h_addr, sizeof(struct in_addr)); 
     661   memcpy((struct in_addr *)&(socket_addr.in.sin_addr), he->h_addr, sizeof(struct in_addr)); 
    625662 
    626663   /* set the connect information */ 
     
    629666 
    630667  fh = roar_socket_new_tcp(); 
     668  addrlen = sizeof(struct sockaddr_in); 
     669#endif 
    631670 
    632671  ROAR_DBG("roar_socket_open(*): fh=%i", fh); 
     
    641680  ROAR_DBG("roar_socket_open(*): fh=%i", fh); 
    642681 
    643    if ( mode_func(fh, (struct sockaddr *)&socket_addr.in, sizeof(struct sockaddr_in)) == -1 ) { 
     682   if ( mode_func(fh, (struct sockaddr *)&socket_addr.sa, addrlen) == -1 ) { 
    644683    ROAR_DBG("roar_socket_open(*): Can not connect/bind: %s", strerror(errno)); 
    645684    close(fh); 
Note: See TracChangeset for help on using the changeset viewer.