Changeset 7f432665c1ce3f5fc981129f9f8fc16a0591460c

Show
Ignore:
Timestamp:
26/06/05 11:12:36 (3 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1119777156 +0000
git-parent:

[1a57857cc63dde28543a6065c78c487343c6e172]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1119777156 +0000
Message:

Use integer rather than strings for UDP/TCP port numbers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/network.h

    r7f95200 r7f43266  
    389389#  define NI_MAXSERV 32 
    390390# endif 
     391# define NI_MAXNUMERICHOST 48 
    391392 
    392393# ifndef NI_NUMERICHOST 
     
    422423 
    423424VLC_EXPORT( const char *, vlc_gai_strerror, ( int ) ); 
    424 VLC_EXPORT( int, vlc_getnameinfo, ( vlc_object_t *, const struct sockaddr *, int, char *, int, char *, int, int ) ); 
    425 VLC_EXPORT( int, vlc_getaddrinfo, ( vlc_object_t *, const char *, const char *, const struct addrinfo *, struct addrinfo ** ) ); 
     425VLC_EXPORT( int, vlc_getnameinfo, ( vlc_object_t *, const struct sockaddr *, int, char *, int, int *, int ) ); 
     426VLC_EXPORT( int, vlc_getaddrinfo, ( vlc_object_t *, const char *, int, const struct addrinfo *, struct addrinfo ** ) ); 
    426427VLC_EXPORT( void, vlc_freeaddrinfo, ( struct addrinfo * ) ); 
    427428 
  • include/vlc_symbols.h

    r2a5f4e0 r7f43266  
    367367    mtime_t (*vout_SynchroDate_inner) (vout_synchro_t *); 
    368368    void (*vout_SynchroNewPicture_inner) (vout_synchro_t *, int, int, mtime_t, mtime_t, int, vlc_bool_t); 
    369     int (*vlc_getaddrinfo_inner) (vlc_object_t *, const char *, const char *, const struct addrinfo *, struct addrinfo **); 
    370     int (*vlc_getnameinfo_inner) (vlc_object_t *, const struct sockaddr *, int, char *, int, char *, int, int); 
     369    int (*vlc_getaddrinfo_inner) (vlc_object_t *, const char *, int, const struct addrinfo *, struct addrinfo **); 
     370    int (*vlc_getnameinfo_inner) (vlc_object_t *, const struct sockaddr *, int, char *, int, int *, int); 
    371371    void (*InitMD5_inner) (struct md5_s *); 
    372372    void (*EndMD5_inner) (struct md5_s *); 
  • modules/access/ftp.c

    rec08d03 r7f43266  
    241241    if( ftp_ReadCommand( p_access, &i_answer, NULL ) == 2 ) 
    242242    { 
    243         char hostaddr[NI_MAXHOST]; 
     243        char hostaddr[NI_MAXNUMERICHOST]; 
    244244        struct sockaddr_storage addr; 
    245245        socklen_t len = sizeof (addr); 
     
    252252 
    253253        i_answer = vlc_getnameinfo( p_this, (struct sockaddr *)&addr, len, 
    254                                     hostaddr, sizeof( hostaddr ), NULL, 0, 
     254                                    hostaddr, sizeof( hostaddr ), NULL, 
    255255                                    NI_NUMERICHOST ); 
    256256        if( i_answer ) 
  • src/misc/getaddrinfo.c

    rc903b7d r7f43266  
    495495 
    496496int vlc_getnameinfo( vlc_object_t *p_this, const struct sockaddr *sa, int salen, 
    497                      char *host, int hostlen, char *serv, int servlen, int flags ) 
    498 
     497                     char *host, int hostlen, int *portnum, int flags ) 
     498
     499    char psz_servbuf[6], *psz_serv; 
     500    int i_servlen, i_val; 
     501 
     502    flags |= NI_NUMERICSERV; 
     503    if( portnum != NULL ) 
     504    { 
     505        psz_serv = psz_servbuf; 
     506        i_servlen = sizeof( psz_servbuf ); 
     507    } 
     508    else 
     509    { 
     510        psz_serv = NULL; 
     511        i_servlen = 0; 
     512    } 
    499513#ifdef WIN32 
    500514    /* 
     
    515529        if( ws2_getnameinfo != NULL ) 
    516530        { 
    517             int i_val; 
    518  
    519             i_val = ws2_getnameinfo( sa, salen, host, hostlen, serv, servlen, 
    520                                      flags ); 
     531            i_val = ws2_getnameinfo( sa, salen, host, hostlen, psz_serv, 
     532                                     i_servlen, flags ); 
    521533            FreeLibrary( wship6_module ); 
     534 
     535            if( portnum != NULL ) 
     536                *portnum = atoi( psz_serv ); 
    522537            return i_val; 
    523538        } 
     
    527542#endif 
    528543#if HAVE_GETNAMEINFO 
    529     return getnameinfo( sa, salen, host, hostlen, serv, servlen, flags ); 
     544    i_val = getnameinfo( sa, salen, host, hostlen, psz_serv, i_servlen, 
     545                         flags ); 
    530546#else 
    531 
    532     vlc_value_t lock; 
    533     int i_val; 
    534  
    535     /* my getnameinfo implementation is not thread-safe as it uses 
    536      * gethostbyaddr and the likes */ 
    537     var_Create( p_this->p_libvlc, "getnameinfo_mutex", VLC_VAR_MUTEX ); 
    538     var_Get( p_this->p_libvlc, "getnameinfo_mutex", &lock ); 
    539     vlc_mutex_lock( lock.p_address ); 
    540  
    541     i_val = __getnameinfo( sa, salen, host, hostlen, serv, servlen, flags ); 
    542     vlc_mutex_unlock( lock.p_address ); 
     547    { 
     548        vlc_value_t lock; 
     549     
     550        /* my getnameinfo implementation is not thread-safe as it uses 
     551        * gethostbyaddr and the likes */ 
     552        var_Create( p_this->p_libvlc, "getnameinfo_mutex", VLC_VAR_MUTEX ); 
     553        var_Get( p_this->p_libvlc, "getnameinfo_mutex", &lock ); 
     554        vlc_mutex_lock( lock.p_address ); 
     555     
     556        i_val = __getnameinfo( sa, salen, host, hostlen, psz_serv, i_servlen, 
     557                               flags ); 
     558        vlc_mutex_unlock( lock.p_address ); 
     559    } 
     560#endif 
     561 
     562    if( portnum != NULL ) 
     563        *portnum = atoi( psz_serv ); 
     564 
    543565    return i_val; 
    544 } 
    545 #endif 
    546566} 
    547567 
     
    549569/* TODO: support for setting sin6_scope_id */ 
    550570int vlc_getaddrinfo( vlc_object_t *p_this, const char *node, 
    551                      const char *service, const struct addrinfo *p_hints, 
     571                     int i_port, const struct addrinfo *p_hints, 
    552572                     struct addrinfo **res ) 
    553573{ 
    554574    struct addrinfo hints; 
    555     char psz_buf[NI_MAXHOST], *psz_node; 
     575    char psz_buf[NI_MAXHOST], *psz_node, psz_service[6]; 
     576 
     577    /* 
     578     * In VLC, we always use port number as integer rather than strings 
     579     * for historical reasons (and portability). 
     580     */ 
     581    if( ( i_port > 65535 ) || ( i_port < 0 ) ) 
     582    { 
     583        msg_Err( p_this, "invalid port number %d specified", i_port ); 
     584        return EAI_SERVICE; 
     585    } 
     586 
     587    /* cannot overflow */ 
     588    snprintf( psz_service, 6, "%d", i_port ); 
    556589 
    557590    /* Check if we have to force ipv4 or ipv6 */ 
     
    586619    { 
    587620        psz_node = NULL; 
    588         if( service == NULL ) 
    589             service = ""; 
    590621    } 
    591622    else 
     
    608639        } 
    609640    } 
    610  
    611     if( ( service != NULL ) && ( *service == '\0' ) ) 
    612         /* We could put NULL, but you can't have both node and service NULL */ 
    613         service = "0"; 
    614641 
    615642#ifdef WIN32 
     
    641668#endif 
    642669#if HAVE_GETADDRINFO 
    643     return getaddrinfo( psz_node, service, &hints, res ); 
     670    return getaddrinfo( psz_node, psz_service, &hints, res ); 
    644671#else 
    645672{ 
  • src/misc/net.c

    r6eeb0d1 r7f43266  
    8686    struct addrinfo hints, *res, *ptr; 
    8787    const char      *psz_realhost; 
    88     char            *psz_realport, *psz_socks; 
    89     int             i_val, i_handle = -1; 
    90  
    91     if( ( i_port < 0 ) || ( i_port > 65535 ) ) 
    92         return -1; /* I don't expect the next TCP version shortly */ 
     88    char            *psz_socks; 
     89    int             i_realport, i_val, i_handle = -1; 
     90 
    9391    if( i_port == 0 ) 
    9492        i_port = 80; /* historical VLC thing */ 
     
    106104 
    107105        psz_realhost = psz_socks; 
    108         psz_realport = strdup( ( psz != NULL ) ? psz : "1080" )
    109  
    110         msg_Dbg( p_this, "net: connecting to '%s:%s' for '%s:%d'", 
    111                  psz_realhost, psz_realport, psz_host, i_port ); 
     106        i_realport = ( psz != NULL ) ? atoi( psz ) : 1080
     107 
     108        msg_Dbg( p_this, "net: connecting to '%s:%d' for '%s:%d'", 
     109                 psz_realhost, i_realport, psz_host, i_port ); 
    112110    } 
    113111    else 
    114112    { 
    115113        psz_realhost = psz_host; 
    116         psz_realport = malloc( 6 ); 
    117         if( psz_realport == NULL ) 
    118         { 
    119             free( psz_socks ); 
    120             return -1; 
    121         } 
    122  
    123         sprintf( psz_realport, "%d", i_port ); 
    124         msg_Dbg( p_this, "net: connecting to '%s:%s'", psz_realhost, 
    125                  psz_realport ); 
    126     } 
    127  
    128     i_val = vlc_getaddrinfo( p_this, psz_realhost, psz_realport, &hints, 
    129                              &res ); 
    130     free( psz_realport ); 
     114        i_realport = i_port; 
     115 
     116        msg_Dbg( p_this, "net: connecting to '%s:%d'", psz_realhost, 
     117                 i_realport ); 
     118    } 
     119 
     120    i_val = vlc_getaddrinfo( p_this, psz_realhost, i_realport, &hints, &res ); 
    131121    if( i_val ) 
    132122    { 
    133         msg_Err( p_this, "cannot resolve '%s' : %s", psz_realhost, 
    134                  vlc_gai_strerror( i_val ) ); 
     123        msg_Err( p_this, "cannot resolve '%s:%d' : %s", psz_realhost, 
     124                 i_realport, vlc_gai_strerror( i_val ) ); 
    135125        free( psz_socks ); 
    136126        return -1; 
     
    323313    struct addrinfo hints, *res, *ptr; 
    324314    int             i_val, *pi_handles, i_size; 
    325     char            *psz_port; 
    326  
    327     if( ( i_port < 0 ) || ( i_port > 65535 ) ) 
    328         return NULL; /* I don't expect the next TCP version shortly */ 
    329     if( i_port == 0 ) 
    330         i_port = 80; /* historical VLC thing */ 
    331315 
    332316    memset( &hints, 0, sizeof( hints ) ); 
     
    334318    hints.ai_flags = AI_PASSIVE; 
    335319 
    336     psz_port = malloc( 6 ); 
    337     if( psz_port == NULL ) 
    338         return NULL; 
    339  
    340     sprintf( psz_port, "%d", i_port ); 
    341     msg_Dbg( p_this, "net: listening to '%s:%s'", psz_host, psz_port ); 
    342  
    343     i_val = vlc_getaddrinfo( p_this, psz_host, psz_port, &hints, &res ); 
    344     free( psz_port ); 
     320    msg_Dbg( p_this, "net: listening to '%s:%d'", psz_host, i_port ); 
     321 
     322    i_val = vlc_getaddrinfo( p_this, psz_host, i_port, &hints, &res ); 
    345323    if( i_val ) 
    346324    { 
    347         msg_Err( p_this, "cannot resolve '%s' : %s", psz_host, 
     325        msg_Err( p_this, "cannot resolve '%s:%d' : %s", psz_host, i_port, 
    348326                 vlc_gai_strerror( i_val ) ); 
    349327        return NULL; 
     
    11111089        /* v4 only support ipv4 */ 
    11121090        hints.ai_family = PF_INET; 
    1113         if( vlc_getaddrinfo( p_obj, psz_host, NULL, &hints, &p_res ) ) 
     1091        if( vlc_getaddrinfo( p_obj, psz_host, 0, &hints, &p_res ) ) 
    11141092            return VLC_EGENERIC; 
    11151093 
  • src/stream_output/sap.c

    r70702c3 r7f43266  
    296296        hints.ai_flags = AI_NUMERICHOST; 
    297297 
    298         i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, NULL
     298        i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0
    299299                             &hints, &res ); 
    300300        if( i == 0 ) 
    301301            i = vlc_getnameinfo( (vlc_object_t *)p_sap, res->ai_addr, 
    302302                                 res->ai_addrlen, psz_buf, sizeof( psz_buf ), 
    303                                  NULL, 0, NI_NUMERICHOST ); 
     303                                 NULL, NI_NUMERICHOST ); 
    304304        if( i ) 
    305305        { 
     
    585585    int64_t i_sdp_id = mdate(); 
    586586    int     i_sdp_version = 1 + p_sap->i_sessions + (rand()&0xfff); 
    587     char *psz_group, *psz_name, psz_uribuf[48], *psz_uri; 
     587    char *psz_group, *psz_name, psz_uribuf[NI_MAXNUMERICHOST], *psz_uri; 
    588588    char ipv; 
    589589