Commit 13bd0121 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

vlc_getaddrinfo: port is unsigned, 0 means unspecified

parent fbd30448
...@@ -260,7 +260,8 @@ VLC_API int getnameinfo ( const struct sockaddr *, socklen_t, ...@@ -260,7 +260,8 @@ VLC_API int getnameinfo ( const struct sockaddr *, socklen_t,
#endif #endif
VLC_API int vlc_getnameinfo( const struct sockaddr *, int, char *, int, int *, int ); VLC_API int vlc_getnameinfo( const struct sockaddr *, int, char *, int, int *, int );
VLC_API int vlc_getaddrinfo( vlc_object_t *, const char *, int, const struct addrinfo *, struct addrinfo ** ); VLC_API int vlc_getaddrinfo (vlc_object_t *, const char *, unsigned,
const struct addrinfo *, struct addrinfo **);
#ifdef __OS2__ #ifdef __OS2__
......
...@@ -80,25 +80,30 @@ int vlc_getnameinfo( const struct sockaddr *sa, int salen, ...@@ -80,25 +80,30 @@ int vlc_getnameinfo( const struct sockaddr *sa, int salen,
* On failure, *res is undefined. On success, it must be freed with * On failure, *res is undefined. On success, it must be freed with
* freeaddrinfo(). * freeaddrinfo().
*/ */
int vlc_getaddrinfo( vlc_object_t *p_this, const char *node, int vlc_getaddrinfo (vlc_object_t *p_this, const char *node,
int i_port, const struct addrinfo *p_hints, unsigned port, const struct addrinfo *p_hints,
struct addrinfo **res ) struct addrinfo **res)
{ {
struct addrinfo hints; struct addrinfo hints;
char psz_buf[NI_MAXHOST], psz_service[6]; char psz_buf[NI_MAXHOST], portbuf[6], *servname;
/* /*
* In VLC, we always use port number as integer rather than strings * In VLC, we always use port number as integer rather than strings
* for historical reasons (and portability). * for historical reasons (and portability).
*/ */
if( ( i_port > 65535 ) || ( i_port < 0 ) ) if (port != 0)
{ {
msg_Err( p_this, "invalid port number %d specified", i_port ); if (port > 65535)
return EAI_SERVICE; {
msg_Err (p_this, "invalid port number %u specified", port);
return EAI_SERVICE;
}
/* cannot overflow */
snprintf (portbuf, sizeof (portbuf), "%u", port);
servname = portbuf;
} }
else
/* cannot overflow */ servname = NULL;
snprintf( psz_service, 6, "%d", i_port );
/* Check if we have to force ipv4 or ipv6 */ /* Check if we have to force ipv4 or ipv6 */
memset (&hints, 0, sizeof (hints)); memset (&hints, 0, sizeof (hints));
...@@ -164,7 +169,7 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node, ...@@ -164,7 +169,7 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
if ((hints.ai_flags & AI_NUMERICHOST) == 0) if ((hints.ai_flags & AI_NUMERICHOST) == 0)
{ {
hints.ai_flags |= AI_NUMERICHOST; hints.ai_flags |= AI_NUMERICHOST;
ret = getaddrinfo (node, psz_service, &hints, res); ret = getaddrinfo (node, servname, &hints, res);
if (ret == 0) if (ret == 0)
goto out; goto out;
hints.ai_flags &= ~AI_NUMERICHOST; hints.ai_flags &= ~AI_NUMERICHOST;
...@@ -173,13 +178,13 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node, ...@@ -173,13 +178,13 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
#ifdef AI_IDN #ifdef AI_IDN
/* Run-time I18n Domain Names support */ /* Run-time I18n Domain Names support */
hints.ai_flags |= AI_IDN; hints.ai_flags |= AI_IDN;
ret = getaddrinfo (node, psz_service, &hints, res); ret = getaddrinfo (node, servname, &hints, res);
if (ret != EAI_BADFLAGS) if (ret != EAI_BADFLAGS)
goto out; goto out;
/* IDN not available: disable and retry without it */ /* IDN not available: disable and retry without it */
hints.ai_flags &= ~AI_IDN; hints.ai_flags &= ~AI_IDN;
#endif #endif
ret = getaddrinfo (node, psz_service, &hints, res); ret = getaddrinfo (node, servname, &hints, res);
#if defined(AI_IDN) || defined(WIN32) #if defined(AI_IDN) || defined(WIN32)
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment