[vlc-commits] vlc_getaddrinfo: pass AI_NUMERICSERV explicitly where applicable

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Aug 19 16:29:53 2012 +0300| [81f563019ba3ebb92984010014030e5eac8471ec] | committer: Rémi Denis-Courmont

vlc_getaddrinfo: pass AI_NUMERICSERV explicitly where applicable

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

 src/network/getaddrinfo.c |    3 ---
 src/network/io.c          |   11 +++++------
 src/network/tcp.c         |   28 +++++++++++++++-------------
 src/network/udp.c         |   38 +++++++++++++++++++-------------------
 4 files changed, 39 insertions(+), 41 deletions(-)

diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c
index f0b9d44..ea5bd94 100644
--- a/src/network/getaddrinfo.c
+++ b/src/network/getaddrinfo.c
@@ -131,9 +131,6 @@ int vlc_getaddrinfo (const char *node, unsigned port,
         hints.ai_flags = p_hints->ai_flags & safe_flags;
     }
 
-    /* We only ever use port *numbers* */
-    hints.ai_flags |= AI_NUMERICSERV;
-
     /*
      * VLC extensions :
      * - accept "" as NULL
diff --git a/src/network/io.c b/src/network/io.c
index d469ffd..d5b854b 100644
--- a/src/network/io.c
+++ b/src/network/io.c
@@ -127,12 +127,11 @@ int net_Socket (vlc_object_t *p_this, int family, int socktype,
 int *net_Listen (vlc_object_t *p_this, const char *psz_host,
                  int i_port, int type, int protocol)
 {
-    struct addrinfo hints, *res;
-
-    memset (&hints, 0, sizeof( hints ));
-    hints.ai_socktype = type;
-    hints.ai_protocol = protocol;
-    hints.ai_flags = AI_PASSIVE;
+    struct addrinfo hints = {
+        .ai_socktype = type,
+        .ai_protocol = protocol,
+        .ai_flags = AI_PASSIVE | AI_NUMERICSERV,
+    }, *res;
 
     msg_Dbg (p_this, "net: listening to %s port %d",
              (psz_host != NULL) ? psz_host : "*", i_port);
diff --git a/src/network/tcp.c b/src/network/tcp.c
index 8ea3339..7ba76ef 100644
--- a/src/network/tcp.c
+++ b/src/network/tcp.c
@@ -75,7 +75,6 @@ extern int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
 int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
                  int type, int proto )
 {
-    struct addrinfo hints, *res, *ptr;
     const char      *psz_realhost;
     char            *psz_socks;
     int             i_realport, i_handle = -1;
@@ -84,10 +83,6 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
     if (evfd == -1)
         return -1;
 
-    memset( &hints, 0, sizeof( hints ) );
-    hints.ai_socktype = type;
-    hints.ai_protocol = proto;
-
     psz_socks = var_InheritString( p_this, "socks" );
     if( psz_socks != NULL )
     {
@@ -98,7 +93,6 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
 
         psz_realhost = psz_socks;
         i_realport = ( psz != NULL ) ? atoi( psz ) : 1080;
-        hints.ai_flags &= ~AI_NUMERICHOST;
 
         msg_Dbg( p_this, "net: connecting to %s port %d (SOCKS) "
                  "for %s port %d", psz_realhost, i_realport,
@@ -137,6 +131,12 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
                  i_realport );
     }
 
+    struct addrinfo hints = {
+        .ai_socktype = type,
+        .ai_protocol = proto,
+        .ai_flags = AI_NUMERICSERV,
+    }, *res;
+
     int val = vlc_getaddrinfo (psz_realhost, i_realport, &hints, &res);
     free( psz_socks );
 
@@ -151,7 +151,7 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
     if (timeout < 0)
         timeout = -1;
 
-    for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
+    for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
     {
         int fd = net_Socket( p_this, ptr->ai_family,
                              ptr->ai_socktype, ptr->ai_protocol );
@@ -445,13 +445,15 @@ static int SocksHandshakeTCP( vlc_object_t *p_obj,
 
     if( i_socks_version == 4 )
     {
-        struct addrinfo hints, *res;
-
         /* v4 only support ipv4 */
-        memset (&hints, 0, sizeof (hints));
-        hints.ai_family = AF_INET;
-        hints.ai_socktype = SOCK_STREAM;
-        hints.ai_protocol = IPPROTO_TCP;
+        static const struct addrinfo hints = {
+            .ai_family = AF_INET,
+            .ai_socktype = SOCK_STREAM,
+            .ai_protocol = IPPROTO_TCP,
+            .ai_flags = 0,
+        };
+        struct addrinfo *res;
+
         if (vlc_getaddrinfo (psz_host, 0, &hints, &res))
             return VLC_EGENERIC;
 
diff --git a/src/network/udp.c b/src/network/udp.c
index ffa10d5..19a47ba 100644
--- a/src/network/udp.c
+++ b/src/network/udp.c
@@ -94,7 +94,8 @@ extern int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
                        int i_protocol );
 
 /* */
-static int net_SetupDgramSocket( vlc_object_t *p_obj, int fd, const struct addrinfo *ptr )
+static int net_SetupDgramSocket (vlc_object_t *p_obj, int fd,
+                                 const struct addrinfo *ptr)
 {
 #ifdef SO_REUSEPORT
     setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, &(int){ 1 }, sizeof (int));
@@ -137,12 +138,11 @@ static int net_SetupDgramSocket( vlc_object_t *p_obj, int fd, const struct addri
 static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
                              int protocol)
 {
-    struct addrinfo hints, *res;
-
-    memset (&hints, 0, sizeof( hints ));
-    hints.ai_socktype = SOCK_DGRAM;
-    hints.ai_protocol = protocol;
-    hints.ai_flags = AI_PASSIVE;
+    struct addrinfo hints = {
+        .ai_socktype = SOCK_DGRAM,
+        .ai_protocol = protocol,
+        .ai_flags = AI_PASSIVE | AI_NUMERICSERV,
+    }, *res;
 
     if (host && !*host)
         host = NULL;
@@ -503,17 +503,17 @@ static int net_SetDSCP( int fd, uint8_t dscp )
 int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
                       int i_hlim, int proto )
 {
-    struct addrinfo hints, *res, *ptr;
+    struct addrinfo hints = {
+        .ai_socktype = SOCK_DGRAM,
+        .ai_protocol = proto,
+        .ai_flags = AI_NUMERICSERV,
+    }, *res;
     int       i_handle = -1;
     bool      b_unreach = false;
 
     if( i_hlim < 0 )
         i_hlim = var_InheritInteger( p_this, "ttl" );
 
-    memset( &hints, 0, sizeof( hints ) );
-    hints.ai_socktype = SOCK_DGRAM;
-    hints.ai_protocol = proto;
-
     msg_Dbg( p_this, "net: connecting to [%s]:%d", psz_host, i_port );
 
     int val = vlc_getaddrinfo (psz_host, i_port, &hints, &res);
@@ -524,7 +524,7 @@ int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
         return -1;
     }
 
-    for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
+    for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
     {
         char *str;
         int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
@@ -601,11 +601,11 @@ int net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
     msg_Dbg (obj, "net: connecting to [%s]:%d from [%s]:%d",
              psz_server, i_server, psz_bind, i_bind);
 
-    struct addrinfo hints, *loc, *rem;
-
-    memset (&hints, 0, sizeof (hints));
-    hints.ai_socktype = SOCK_DGRAM;
-    hints.ai_protocol = protocol;
+    struct addrinfo hints = {
+        .ai_socktype = SOCK_DGRAM,
+        .ai_protocol = protocol,
+        .ai_flags = AI_NUMERICSERV,
+    }, *loc, *rem;
 
     int val = vlc_getaddrinfo (psz_server, i_server, &hints, &rem);
     if (val)
@@ -615,7 +615,7 @@ int net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
         return -1;
     }
 
-    hints.ai_flags = AI_PASSIVE;
+    hints.ai_flags |= AI_PASSIVE;
     val = vlc_getaddrinfo (psz_bind, i_bind, &hints, &loc);
     if (val)
     {



More information about the vlc-commits mailing list