]> git.sesse.net Git - vlc/commitdiff
vlc_getaddrinfo: pass AI_NUMERICSERV explicitly where applicable
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 19 Aug 2012 13:29:53 +0000 (16:29 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 19 Aug 2012 13:47:01 +0000 (16:47 +0300)
src/network/getaddrinfo.c
src/network/io.c
src/network/tcp.c
src/network/udp.c

index 35c4a4deb8b23e4e814cada20abca942a8f04edc..b9e4478999f9c90e015cf7c5ba78e3b59a721437 100644 (file)
@@ -130,9 +130,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
index d469ffd54de2387d49f9bc02a40b63e0c4ea6a01..d5b854bbf623c7ac3b7af86512619ffb03953393 100644 (file)
@@ -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);
index 8ea3339f55004c601c8307aa4b47fe4bb85bf76d..7ba76efaf10185167d932dbb16f64c78b914b127 100644 (file)
@@ -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;
 
index ffa10d508e18a4f05e51efe19df5c4bed183fb74..19a47ba508d0eb9a4c1f1605ec6b1c169bdcc0f7 100644 (file)
@@ -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)
     {