]> git.sesse.net Git - vlc/blobdiff - src/network/getaddrinfo.c
Removes trailing spaces. Removes tabs.
[vlc] / src / network / getaddrinfo.c
index f5603f49f987de9baef416b80d14fce8afd72f20..d5514d2d6c4cc0e3cbc78faf87cb070a6317440d 100644 (file)
@@ -118,7 +118,7 @@ static int WSAAPI
 getnameinfo (const struct sockaddr *sa, socklen_t salen,
              char *host, DWORD hostlen, char *serv, DWORD servlen, int flags)
 #else
-static int 
+static int
 getnameinfo (const struct sockaddr *sa, socklen_t salen,
              char *host, int hostlen, char *serv, int servlen, int flags)
 #endif
@@ -398,7 +398,7 @@ getaddrinfo (const char *node, const char *service,
         port = 0;
     else
     {
-        long d;
+        unsigned long d;
         char *end;
 
         d = strtoul (service, &end, 0);
@@ -490,7 +490,7 @@ static WSAAPI int _ws2_getnameinfo_bind( const struct sockaddr FAR * sa, socklen
     if (entry == NULL)
     {
         /* not found, use replacement API instead */
-       entry = getnameinfo;
+    entry = getnameinfo;
 
     }
     /* call API before replacing function pointer to avoid crash */
@@ -514,8 +514,8 @@ static WSAAPI int _ws2_getaddrinfo_bind(const char FAR *node, const char FAR *se
     if ((entry == NULL) ||  (freentry == NULL))
     {
         /* not found, use replacement API instead */
-       entry = getaddrinfo;
-       freentry = freeaddrinfo;
+    entry = getaddrinfo;
+    freentry = freeaddrinfo;
     }
     /* call API before replacing function pointer to avoid crash */
     result = entry (node, service, hints, res);
@@ -558,6 +558,7 @@ int vlc_getnameinfo( const struct sockaddr *sa, int salen,
     return i_val;
 }
 
+
 int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
                      int i_port, const struct addrinfo *p_hints,
                      struct addrinfo **res )
@@ -580,18 +581,38 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
 
     /* Check if we have to force ipv4 or ipv6 */
     memset (&hints, 0, sizeof (hints));
-    if( p_hints != NULL )
+    if (p_hints != NULL)
     {
-        int ai_flags = AI_NUMERICHOST|AI_PASSIVE;
-        if( node )
-            ai_flags |= AI_CANONNAME;
+        const int safe_flags =
+            AI_PASSIVE |
+            AI_CANONNAME |
+            AI_NUMERICHOST |
+#ifdef AI_NUMERICSERV
+            AI_NUMERICSERV |
+#endif
+#ifdef AI_ALL
+            AI_ALL |
+#endif
+#ifdef AI_ADDRCONFIG
+            AI_ADDRCONFIG |
+#endif
+#ifdef AI_V4MAPPED
+            AI_V4MAPPED |
+#endif
+            0;
+
         hints.ai_family = p_hints->ai_family;
         hints.ai_socktype = p_hints->ai_socktype;
         hints.ai_protocol = p_hints->ai_protocol;
-        hints.ai_flags = p_hints->ai_flags & (ai_flags);
+        /* Unfortunately, some flags chang the layout of struct addrinfo, so
+         * they cannot be copied blindly from p_hints to &hints. Therefore, we
+         * only copy flags that we know for sure are "safe".
+         */
+        hints.ai_flags = p_hints->ai_flags & safe_flags;
     }
+
 #ifdef AI_NUMERICSERV
-    /* we only ever use port *numbers* */
+    /* We only ever use port *numbers* */
     hints.ai_flags |= AI_NUMERICSERV;
 #endif
 
@@ -620,7 +641,6 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
     if( ( node == NULL ) || (node[0] == '\0' ) )
     {
         psz_node = NULL;
-        hints.ai_flags &= ~AI_CANONNAME;
     }
     else
     {