[vlc-devel] commit: Remove the getaddrinfo transport protocol and socket type hacks ( Rémi Denis-Courmont )

git version control git at videolan.org
Mon Feb 1 22:14:42 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Feb  1 23:13:26 2010 +0200| [3adb049b4bba9e6537940a907cd50ebb52e1a278] | committer: Rémi Denis-Courmont 

Remove the getaddrinfo transport protocol and socket type hacks

That was meant for DCCP and UDP-Lite but it shouldn't be needed.

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

 src/network/io.c  |   29 ++++++-----------------------
 src/network/tcp.c |    7 ++++---
 src/network/udp.c |    9 ++++++---
 3 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/src/network/io.c b/src/network/io.c
index 554b234..a1923c1 100644
--- a/src/network/io.c
+++ b/src/network/io.c
@@ -158,27 +158,9 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
                  int i_port, int protocol)
 {
     struct addrinfo hints, *res;
-    int socktype = SOCK_DGRAM;
-
-    switch( protocol )
-    {
-        case IPPROTO_TCP:
-            socktype = SOCK_STREAM;
-            break;
-        case 33: /* DCCP */
-#ifdef __linux__
-# ifndef SOCK_DCCP
-#  define SOCK_DCCP 6
-# endif
-            socktype = SOCK_DCCP;
-#endif
-            break;
-    }
 
     memset (&hints, 0, sizeof( hints ));
-    /* Since we use port numbers rather than service names, the socket type
-     * does not really matter. */
-    hints.ai_socktype = SOCK_DGRAM;
+    hints.ai_protocol = protocol;
     hints.ai_flags = AI_PASSIVE;
 
     msg_Dbg (p_this, "net: listening to %s port %d", psz_host, i_port);
@@ -196,7 +178,8 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
 
     for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
     {
-        int fd = net_Socket (p_this, ptr->ai_family, socktype, protocol);
+        int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
+                             ptr->ai_protocol);
         if (fd == -1)
         {
             msg_Dbg (p_this, "socket error: %m");
@@ -229,8 +212,8 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
         {
             net_Close (fd);
 #if !defined(WIN32) && !defined(UNDER_CE)
-            fd = rootwrap_bind (ptr->ai_family, socktype,
-                                protocol ? protocol : ptr->ai_protocol,
+            fd = rootwrap_bind (ptr->ai_family, ptr->ai_socktype,
+                                ptr->ai_protocol,
                                 ptr->ai_addr, ptr->ai_addrlen);
             if (fd != -1)
             {
@@ -254,7 +237,7 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
         }
 
         /* Listen */
-        switch (socktype)
+        switch (ptr->ai_socktype)
         {
             case SOCK_STREAM:
             case SOCK_RDM:
diff --git a/src/network/tcp.c b/src/network/tcp.c
index cd5fa02..cc4eb0a 100644
--- a/src/network/tcp.c
+++ b/src/network/tcp.c
@@ -84,7 +84,7 @@ int __net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
         return -1;
 
     memset( &hints, 0, sizeof( hints ) );
-    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_protocol = proto;
 
     psz_socks = var_CreateGetNonEmptyString( p_this, "socks" );
     if( psz_socks != NULL )
@@ -148,8 +148,7 @@ int __net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
     for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
     {
         int fd = net_Socket( p_this, ptr->ai_family,
-                             type ? type : ptr->ai_socktype,
-                             proto ? proto : ptr->ai_protocol );
+                             ptr->ai_socktype, ptr->ai_protocol );
         if( fd == -1 )
         {
             msg_Dbg( p_this, "socket error: %m" );
@@ -464,6 +463,8 @@ static int SocksHandshakeTCP( vlc_object_t *p_obj,
         /* v4 only support ipv4 */
         memset (&hints, 0, sizeof (hints));
         hints.ai_family = AF_INET;
+        hints.ai_socktype = SOCK_STREAM;
+        hints.ai_protocol = IPPROTO_TCP;
         if( vlc_getaddrinfo( p_obj, psz_host, 0, &hints, &p_res ) )
             return VLC_EGENERIC;
 
diff --git a/src/network/udp.c b/src/network/udp.c
index d00b09e..4366df2 100644
--- a/src/network/udp.c
+++ b/src/network/udp.c
@@ -142,6 +142,7 @@ static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
     memset (&hints, 0, sizeof( hints ));
     hints.ai_family = family;
     hints.ai_socktype = SOCK_DGRAM;
+    hints.ai_protocol = protocol;
     hints.ai_flags = AI_PASSIVE;
 
     if (host && !*host)
@@ -163,7 +164,7 @@ static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
     for (const struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
     {
         int fd = net_Socket (obj, ptr->ai_family, ptr->ai_socktype,
-                             protocol ? protocol : ptr->ai_protocol);
+                             ptr->ai_protocol);
         if (fd == -1)
         {
             msg_Dbg (obj, "socket error: %m");
@@ -660,6 +661,7 @@ int __net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
 
     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 );
 
@@ -675,7 +677,7 @@ int __net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
     {
         char *str;
         int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
-                             proto ? proto : ptr->ai_protocol);
+                             ptr->ai_protocol);
         if (fd == -1)
             continue;
 
@@ -764,6 +766,7 @@ int __net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
     memset (&hints, 0, sizeof (hints));
     hints.ai_family = family;
     hints.ai_socktype = SOCK_DGRAM;
+    hints.ai_protocol = protocol;
 
     val = vlc_getaddrinfo (obj, psz_server, i_server, &hints, &rem);
     if (val)
@@ -786,7 +789,7 @@ int __net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
     for (struct addrinfo *ptr = loc; ptr != NULL; ptr = ptr->ai_next)
     {
         int fd = net_Socket (obj, ptr->ai_family, ptr->ai_socktype,
-                             protocol ? protocol : ptr->ai_protocol);
+                             ptr->ai_protocol);
         if (fd == -1)
             continue; // usually, address family not supported
 




More information about the vlc-devel mailing list