[vlc-commits] vlc_getaddrinfo: port is unsigned, 0 means unspecified

Rémi Denis-Courmont git at videolan.org
Sun Aug 19 15:44:48 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Aug 19 16:17:49 2012 +0300| [13bd012152046eefaa080d5877d5b2e2f5fc5a10] | committer: Rémi Denis-Courmont

vlc_getaddrinfo: port is unsigned, 0 means unspecified

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=13bd012152046eefaa080d5877d5b2e2f5fc5a10
---

 include/vlc_network.h     |    3 ++-
 src/network/getaddrinfo.c |   31 ++++++++++++++++++-------------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/include/vlc_network.h b/include/vlc_network.h
index 5a4764f..0102bb3 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -260,7 +260,8 @@ VLC_API int  getnameinfo ( const struct sockaddr *, socklen_t,
 #endif
 
 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__
diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c
index b57193b..dfc3242 100644
--- a/src/network/getaddrinfo.c
+++ b/src/network/getaddrinfo.c
@@ -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
  * freeaddrinfo().
  */
-int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
-                     int i_port, const struct addrinfo *p_hints,
-                     struct addrinfo **res )
+int vlc_getaddrinfo (vlc_object_t *p_this, const char *node,
+                     unsigned port, const struct addrinfo *p_hints,
+                     struct addrinfo **res)
 {
     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
      * 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 );
-        return EAI_SERVICE;
+        if (port > 65535)
+        {
+            msg_Err (p_this, "invalid port number %u specified", port);
+            return EAI_SERVICE;
+        }
+        /* cannot overflow */
+        snprintf (portbuf, sizeof (portbuf), "%u", port);
+        servname = portbuf;
     }
-
-    /* cannot overflow */
-    snprintf( psz_service, 6, "%d", i_port );
+    else
+        servname = NULL;
 
     /* Check if we have to force ipv4 or ipv6 */
     memset (&hints, 0, sizeof (hints));
@@ -164,7 +169,7 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
     if ((hints.ai_flags & AI_NUMERICHOST) == 0)
     {
         hints.ai_flags |= AI_NUMERICHOST;
-        ret = getaddrinfo (node, psz_service, &hints, res);
+        ret = getaddrinfo (node, servname, &hints, res);
         if (ret == 0)
             goto out;
         hints.ai_flags &= ~AI_NUMERICHOST;
@@ -173,13 +178,13 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
 #ifdef AI_IDN
     /* Run-time I18n Domain Names support */
     hints.ai_flags |= AI_IDN;
-    ret = getaddrinfo (node, psz_service, &hints, res);
+    ret = getaddrinfo (node, servname, &hints, res);
     if (ret != EAI_BADFLAGS)
         goto out;
     /* IDN not available: disable and retry without it */
     hints.ai_flags &= ~AI_IDN;
 #endif
-    ret = getaddrinfo (node, psz_service, &hints, res);
+    ret = getaddrinfo (node, servname, &hints, res);
 
 #if defined(AI_IDN) || defined(WIN32)
 out:



More information about the vlc-commits mailing list