]> git.sesse.net Git - vlc/blob - modules/misc/network/ipv6.c
Compile fix for C++ files
[vlc] / modules / misc / network / ipv6.c
1 /*****************************************************************************
2  * ipv6.c: IPv6 network abstraction layer
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id$
6  *
7  * Authors: Alexis Guillard <alexis.guillard@bt.com>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *          Remco Poortinga <poortinga@telin.nl>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <fcntl.h>
35
36 #include <vlc/vlc.h>
37
38 #ifdef HAVE_UNISTD_H
39 #   include <unistd.h>
40 #elif defined( _MSC_VER ) && defined( _WIN32 )
41 #   include <io.h>
42 #endif
43
44 #ifdef WIN32
45 #   include <winsock2.h>
46 #   include <ws2tcpip.h>
47 #elif !defined( SYS_BEOS ) && !defined( SYS_NTO )
48 #   include <netdb.h>                                         /* hostent ... */
49 #   include <sys/socket.h>
50 #   include <netinet/in.h>
51 #   include <net/if.h>
52 #   ifdef HAVE_ARPA_INET_H
53 #       include <arpa/inet.h>                    /* inet_ntoa(), inet_aton() */
54 #   endif
55 #endif
56
57 #include "network.h"
58
59 #if defined(WIN32)
60 static const struct in6_addr in6addr_any = {{IN6ADDR_ANY_INIT}};
61 /* the following will have to be removed when w32api defines them */
62 #ifndef IPPROTO_IPV6
63 #   define IPPROTO_IPV6 41 
64 #endif
65 #ifndef IPV6_JOIN_GROUP
66 #   define IPV6_JOIN_GROUP 12
67 #endif
68 #ifndef IPV6_MULTICAST_HOPS
69 #   define IPV6_MULTICAST_HOPS 10
70 #endif
71 #ifndef IPV6_UNICAST_HOPS
72 #   define IPV6_UNICAST_HOPS 4
73 #endif
74 #   define close closesocket
75 #endif
76
77 /*****************************************************************************
78  * Local prototypes
79  *****************************************************************************/
80 static int NetOpen( vlc_object_t * );
81
82 /*****************************************************************************
83  * Module descriptor
84  *****************************************************************************/
85 vlc_module_begin();
86     set_description( _("IPv6 network abstraction layer") );
87     set_capability( "network", 40 );
88     set_callbacks( NetOpen, NULL );
89 vlc_module_end();
90
91 /*****************************************************************************
92  * BuildAddr: utility function to build a struct sockaddr_in6
93  *****************************************************************************/
94 static int BuildAddr( vlc_object_t * p_this, struct sockaddr_in6 * p_socket,
95                       const char * psz_bind_address, int i_port )
96 {
97     char * psz_multicast_interface = "";
98     char * psz_backup = strdup(psz_bind_address);
99     char * psz_address = psz_backup;
100
101 #if defined(WIN32)
102     /* Try to get getaddrinfo() and freeaddrinfo() from wship6.dll */
103     typedef int (CALLBACK * GETADDRINFO) ( const char *nodename,
104                                             const char *servname,
105                                             const struct addrinfo *hints,
106                                             struct addrinfo **res );
107     typedef void (CALLBACK * FREEADDRINFO) ( struct addrinfo FAR *ai );
108
109     struct addrinfo hints, *res;
110     GETADDRINFO _getaddrinfo = NULL;
111     FREEADDRINFO _freeaddrinfo = NULL;
112
113     HINSTANCE wship6_dll = LoadLibrary("wship6.dll");
114     if( wship6_dll )
115     {
116         _getaddrinfo = (GETADDRINFO) GetProcAddress( wship6_dll,
117                                                      "getaddrinfo" );
118         _freeaddrinfo = (FREEADDRINFO) GetProcAddress( wship6_dll,
119                                                        "freeaddrinfo" );
120     }
121     if( !_getaddrinfo || !_freeaddrinfo )
122     {
123         msg_Warn( p_this, "no IPv6 stack installed" );
124         if( wship6_dll ) FreeLibrary( wship6_dll );
125         free( psz_backup );
126         return( -1 );
127     }
128 #endif
129
130     /* Reset struct */
131     memset( p_socket, 0, sizeof( struct sockaddr_in6 ) );
132     p_socket->sin6_family = AF_INET6;                              /* family */
133     p_socket->sin6_port = htons( i_port );
134     if( !*psz_address )
135     {
136         p_socket->sin6_addr = in6addr_any;
137     }
138     else if( psz_address[0] == '['
139               && psz_address[strlen(psz_address) - 1] == ']' )
140     {
141         psz_address[strlen(psz_address) - 1] = '\0';
142         psz_address++;
143
144         /* see if there is an interface name in there... */
145         if( (psz_multicast_interface = strchr(psz_address, '%')) != NULL )
146         {
147             *psz_multicast_interface = '\0';
148             psz_multicast_interface++;
149             msg_Dbg( p_this, "Interface name specified: \"%s\"",
150                              psz_multicast_interface );
151
152             /* now convert that interface name to an index */
153 #if defined( WIN32 )
154             /* FIXME ?? */
155             p_socket->sin6_scope_id = atol(psz_multicast_interface);
156 #elif defined( HAVE_IF_NAMETOINDEX )
157             p_socket->sin6_scope_id = if_nametoindex(psz_multicast_interface);
158 #endif
159             msg_Dbg( p_this, " = #%i", p_socket->sin6_scope_id );
160         }
161
162 #if !defined( WIN32 )
163         inet_pton(AF_INET6, psz_address, &p_socket->sin6_addr.s6_addr); 
164
165 #else
166         memset(&hints, 0, sizeof(hints));
167         hints.ai_family = AF_INET6;
168
169         if( _getaddrinfo( psz_address, NULL, &hints, &res ) != 0 )
170         {
171             FreeLibrary( wship6_dll );
172             free( psz_backup );
173             return( -1 );
174         }
175         memcpy( &p_socket->sin6_addr,
176                 &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
177                 sizeof(struct in6_addr) );
178         _freeaddrinfo( res );
179
180 #endif
181     }
182     else
183     {
184 #ifdef HAVE_GETHOSTBYNAME2
185         struct hostent    * p_hostent;
186
187         /* We have a fqdn, try to find its address */
188         if ( (p_hostent = gethostbyname2( psz_address, AF_INET6 )) == NULL )
189         {
190             msg_Warn( p_this, "IPv6 error: unknown host %s", psz_address );
191             free( psz_backup );
192             return( -1 );
193         }
194
195         /* Copy the first address of the host in the socket address */
196         memcpy( &p_socket->sin6_addr, p_hostent->h_addr_list[0],
197                  p_hostent->h_length );
198
199 #elif defined(WIN32)
200         memset(&hints, 0, sizeof(hints));
201         hints.ai_family = AF_INET6;
202
203         if( _getaddrinfo( psz_address, NULL, &hints, &res ) != 0 )
204         {
205             FreeLibrary( wship6_dll );
206             free( psz_backup );
207             return( -1 );
208         }
209         memcpy( &p_socket->sin6_addr,
210                 &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
211                 sizeof(struct in6_addr) );
212         _freeaddrinfo( res );
213
214 #else
215         msg_Warn( p_this, "IPv6 error: IPv6 address %s is invalid",
216                  psz_address );
217         free( psz_backup );
218         return( -1 );
219 #endif
220     }
221
222 #if defined(WIN32)
223     FreeLibrary( wship6_dll );
224 #endif
225
226     free( psz_backup );
227     return 0;
228 }
229
230 /*****************************************************************************
231  * OpenUDP: open a UDP socket
232  *****************************************************************************
233  * psz_bind_addr, i_bind_port : address and port used for the bind()
234  *   system call. If psz_bind_addr == NULL, the socket is bound to
235  *   in6addr_any and broadcast reception is enabled. If i_bind_port == 0,
236  *   1234 is used. If psz_bind_addr is a multicast (class D) address,
237  *   join the multicast group.
238  * psz_server_addr, i_server_port : address and port used for the connect()
239  *   system call. It can avoid receiving packets from unauthorized IPs.
240  *   Its use leads to great confusion and is currently discouraged.
241  * This function returns -1 in case of error.
242  *****************************************************************************/
243 static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
244 {
245     char * psz_bind_addr = p_socket->psz_bind_addr;
246     int i_bind_port = p_socket->i_bind_port;
247     char * psz_server_addr = p_socket->psz_server_addr;
248     int i_server_port = p_socket->i_server_port;
249
250     int i_handle, i_opt;
251     socklen_t i_opt_size;
252     struct sockaddr_in6 sock;
253     vlc_value_t val;
254
255     /* Open a SOCK_DGRAM (UDP) socket, in the AF_INET6 domain, automatic (0)
256      * protocol */
257     if( (i_handle = socket( AF_INET6, SOCK_DGRAM, 0 )) == -1 )
258     {
259         msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) );
260         return( -1 );
261     }
262
263     /* We may want to reuse an already used socket */
264     i_opt = 1;
265     if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR,
266                     (void *) &i_opt, sizeof( i_opt ) ) == -1 )
267     {
268         msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR: %s)",
269                          strerror(errno) );
270         close( i_handle );
271         return( -1 );
272     }
273
274     /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
275      * packet loss caused by scheduling problems */
276     i_opt = 0x80000;
277     if( setsockopt( i_handle, SOL_SOCKET, SO_RCVBUF,
278                     (void *) &i_opt, sizeof( i_opt ) ) == -1 )
279     {
280         msg_Warn( p_this, "cannot configure socket (SO_RCVBUF: %s)",
281                           strerror(errno) );
282     }
283
284     /* Check if we really got what we have asked for, because Linux, etc.
285      * will silently limit the max buffer size to net.core.rmem_max which
286      * is typically only 65535 bytes */
287     i_opt = 0;
288     i_opt_size = sizeof( i_opt );
289     if( getsockopt( i_handle, SOL_SOCKET, SO_RCVBUF,
290                     (void*) &i_opt, &i_opt_size ) == -1 )
291     {
292         msg_Warn( p_this, "cannot query socket (SO_RCVBUF: %s)",
293                           strerror(errno) );
294     }
295     else if( i_opt < 0x80000 )
296     {
297         msg_Warn( p_this, "Socket buffer size is 0x%x instead of 0x%x",
298                           i_opt, 0x80000 );
299     }
300
301     /* Build the local socket */
302     if ( BuildAddr( p_this, &sock, psz_bind_addr, i_bind_port ) == -1 )        
303     {
304         close( i_handle );
305         return( -1 );
306     }
307
308 #if defined(WIN32)
309     /* Under Win32 and for multicasting, we bind to IN6ADDR_ANY */
310     if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) )
311     {
312         struct sockaddr_in6 sockany = sock;
313         sockany.sin6_addr = in6addr_any;
314         sockany.sin6_scope_id = 0;
315
316         /* Bind it */
317         if( bind( i_handle, (struct sockaddr *)&sockany, sizeof( sock ) ) < 0 )
318         {
319             msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) );
320             close( i_handle );
321             return( -1 );
322         }
323     } else
324 #endif
325     /* Bind it */
326     if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 )
327     {
328         msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) );
329         close( i_handle );
330         return( -1 );
331     }
332
333     /* Allow broadcast reception if we bound on in6addr_any */
334     if( !*psz_bind_addr )
335     {
336         i_opt = 1;
337         if( setsockopt( i_handle, SOL_SOCKET, SO_BROADCAST,
338                         (void*) &i_opt, sizeof( i_opt ) ) == -1 )
339         {
340             msg_Warn( p_this, "IPv6 warning: cannot configure socket "
341                               "(SO_BROADCAST: %s)", strerror(errno) );
342         }
343     }
344
345     /* Join the multicast group if the socket is a multicast address */
346 #if defined( WIN32 ) || defined( HAVE_IF_NAMETOINDEX )
347     if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) )
348     {
349         struct ipv6_mreq     imr;
350         int                  res;
351
352         imr.ipv6mr_interface = sock.sin6_scope_id;
353         imr.ipv6mr_multiaddr = sock.sin6_addr;
354         res = setsockopt(i_handle, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void*) &imr,
355 #if defined(WIN32)
356                          sizeof(imr) + 4); /* Doesn't work without this */
357 #else
358                          sizeof(imr));
359 #endif
360
361         if( res == -1 )
362         {
363             msg_Err( p_this, "cannot join multicast group" );
364         } 
365     }
366 #else
367     msg_Warn( p_this, "Multicast IPv6 is not supported on your OS" );
368 #endif
369
370
371     if( *psz_server_addr )
372     {
373         int ttl = p_socket->i_ttl;
374         if( ttl < 1 )
375         {
376             ttl = config_GetInt( p_this, "ttl" );
377         }
378         if( ttl < 1 ) ttl = 1;
379
380         /* Build socket for remote connection */
381         if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) == -1 )
382         {
383             msg_Warn( p_this, "cannot build remote address" );
384             close( i_handle );
385             return( -1 );
386         }
387
388         /* Connect the socket */
389         if( connect( i_handle, (struct sockaddr *) &sock,
390                      sizeof( sock ) ) == (-1) )
391         {
392             msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) );
393             close( i_handle );
394             return( -1 );
395         }
396
397         /* Set the time-to-live */
398         if( ttl > 1 )
399         {
400 #if defined( WIN32 ) || defined( HAVE_IF_NAMETOINDEX )
401             if( IN6_IS_ADDR_MULTICAST(&sock.sin6_addr) )
402             {
403                 if( setsockopt( i_handle, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
404                                 (void *)&ttl, sizeof( ttl ) ) < 0 )
405                 {
406 #ifdef HAVE_ERRNO_H
407                     msg_Err( p_this, "failed to set multicast ttl (%s)",
408                              strerror(errno) );
409 #else
410                     msg_Err( p_this, "failed to set multicast ttl" );
411 #endif
412                 }
413             }
414             else
415 #endif
416             {
417                 if( setsockopt( i_handle, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
418                                 (void *)&ttl, sizeof( ttl ) ) < 0 )
419                 {
420 #ifdef HAVE_ERRNO_H
421                     msg_Err( p_this, "failed to set unicast ttl (%s)",
422                               strerror(errno) );
423 #else
424                     msg_Err( p_this, "failed to set unicast ttl" );
425 #endif
426                 }
427             }
428         }
429     }
430
431     p_socket->i_handle = i_handle;
432
433     var_Create( p_this, "mtu", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
434     var_Get( p_this, "mtu", &val );
435     p_socket->i_mtu = val.i_int;
436
437     return( 0 );
438 }
439
440 /*****************************************************************************
441  * SocketTCP: create a TCP socket
442  *****************************************************************************
443  * This function returns -1 in case of error.
444  *****************************************************************************/
445 static int SocketTCP( vlc_object_t * p_this )
446 {
447     int i_handle;
448     
449     /* Open a SOCK_STREAM (TCP) socket, in the PF_INET6 domain, automatic (0)
450      * protocol */
451     if( (i_handle = socket( PF_INET6, SOCK_STREAM, 0 )) == -1 )
452     {
453 #ifdef HAVE_ERRNO_H
454         msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) );
455 #else
456         msg_Warn( p_this, "cannot create socket" );
457 #endif
458         return -1;
459     }
460
461     /* Set to non-blocking */
462 #if defined( WIN32 ) || defined( UNDER_CE )
463     {
464         unsigned long i_dummy = 1;
465         if( ioctlsocket( i_handle, FIONBIO, &i_dummy ) != 0 )
466         {
467             msg_Err( p_this, "cannot set socket to non-blocking mode" );
468         }
469     }
470 #elif defined( HAVE_ERRNO_H )
471     {
472         int i_flags;
473         if( ( i_flags = fcntl( i_handle, F_GETFL, 0 ) ) < 0 ||
474             fcntl( i_handle, F_SETFL, i_flags | O_NONBLOCK ) < 0 )
475         {
476             msg_Err( p_this, "cannot set socket to non-blocking mode" );
477         }
478     }
479 #endif
480
481     return i_handle;
482 }
483
484 /*****************************************************************************
485  * OpenTCP: open a TCP socket
486  *****************************************************************************
487  * psz_server_addr, i_server_port : address and port used for the connect()
488  *   system call. If i_server_port == 0, 80 is used.
489  * Other parameters are ignored.
490  * This function returns -1 in case of error.
491  *****************************************************************************/
492 static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
493 {
494     char * psz_server_addr = p_socket->psz_server_addr;
495     int i_server_port = p_socket->i_server_port;
496
497     int i_handle;
498     struct sockaddr_in6 sock;
499
500     if( i_server_port == 0 )
501     {
502         i_server_port = 80;
503     }
504
505     if( (i_handle = SocketTCP( p_this )) == -1 )
506         return VLC_EGENERIC;
507
508     /* Build remote address */
509     if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) == -1 )
510         goto error;
511
512     /* Connect the socket */
513     if( connect( i_handle, (struct sockaddr *) &sock, sizeof( sock ) ) == -1 )
514     {
515 #if defined( WIN32 ) || defined( UNDER_CE )
516         if( WSAGetLastError() == WSAEWOULDBLOCK )
517 #elif defined( HAVE_ERRNO_H )
518         if( errno == EINPROGRESS )
519 #else
520         if( 0 )
521 #endif
522         {
523             int i_ret, i_opt, i_opt_size = sizeof( i_opt ), i_max_count;
524             struct timeval timeout;
525             vlc_value_t val;
526             fd_set fds;
527
528             /* FIXME: There is no ipv6-timeout option, so we use ipv4-timeout
529              * instead */
530             if( !var_Type( p_this, "ipv4-timeout" ) )
531             {
532                 var_Create( p_this, "ipv4-timeout",
533                             VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
534             }
535             var_Get( p_this, "ipv4-timeout", &val );
536             i_max_count = val.i_int * 1000 / 100000 /* timeout.tv_usec */;
537
538             msg_Dbg( p_this, "connection in progress" );
539             do
540             {
541                 if( p_this->b_die || i_max_count <= 0 )
542                 {
543                     msg_Dbg( p_this, "connection aborted" );
544                     goto error;
545                 }
546
547                 i_max_count--;
548
549                 /* Initialize file descriptor set */
550                 FD_ZERO( &fds );
551                 FD_SET( i_handle, &fds );
552
553                 /* We'll wait 0.1 second if nothing happens */
554                 timeout.tv_sec = 0;
555                 timeout.tv_usec = 100000;
556
557             } while( ( i_ret = select( i_handle + 1, NULL, &fds, NULL,
558                                        &timeout ) ) == 0 ||
559 #if defined( WIN32 ) || defined( UNDER_CE )
560                      ( i_ret < 0 && WSAGetLastError() == WSAEWOULDBLOCK ) );
561 #elif defined( HAVE_ERRNO_H )
562                      ( i_ret < 0 && errno == EINTR ) );
563 #else
564                      ( i_ret < 0 ) );
565 #endif
566
567             if( i_ret < 0 )
568             {
569                 msg_Warn( p_this, "cannot connect socket (select failed)" );
570                 goto error;
571             }
572
573 #if !defined( SYS_BEOS )
574             if( getsockopt( i_handle, SOL_SOCKET, SO_ERROR, (void*)&i_opt,
575                             &i_opt_size ) == -1 || i_opt != 0 )
576             {
577                 msg_Warn( p_this, "cannot connect socket (SO_ERROR)" );
578                 goto error;
579             }
580 #endif
581         }
582         else
583         {
584 #if defined( HAVE_ERRNO_H )
585             msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) );
586 #else
587             msg_Warn( p_this, "cannot connect socket" );
588 #endif
589             goto error;
590         }
591     }
592
593     p_socket->i_handle = i_handle;
594     p_socket->i_mtu = 0; /* There is no MTU notion in TCP */
595     return VLC_SUCCESS;
596
597 error:
598     close( i_handle );
599     return VLC_EGENERIC;
600 }
601
602 /*****************************************************************************
603  * ListenTCP: open a TCP passive socket (server-side)
604  *****************************************************************************
605  * psz_server_addr, i_server_port : address and port used for the bind()
606  *   system call. If i_server_port == 0, 80 is used.
607  * Other parameters are ignored.
608  * This function returns -1 in case of error.
609  *****************************************************************************/
610 static int ListenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
611 {
612     char * psz_server_addr = p_socket->psz_server_addr;
613     int i_server_port = p_socket->i_server_port;
614
615     int i_handle, i_dummy = 1;
616     struct sockaddr_in6 sock;
617
618     if( (i_handle = SocketTCP( p_this )) == -1 )
619         return VLC_EGENERIC;
620
621     if ( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR,
622                 (void *)&i_dummy, sizeof( i_dummy ) ) == -1 )
623     {
624         msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR)" );
625     }
626
627     /* Build remote address */
628     if ( BuildAddr( p_this, &sock, psz_server_addr, i_server_port ) == -1 )
629     {
630         msg_Dbg( p_this, "could not build local address" );
631         return VLC_EGENERIC;
632     }
633     
634     /* Bind the socket */
635     if( bind( i_handle, (struct sockaddr *) &sock, sizeof( sock )) == -1 )
636     {
637 #ifdef HAVE_ERRNO_H
638         msg_Err( p_this, "cannot bind socket (%s)", strerror(errno) );
639 #else
640         msg_Err( p_this, "cannot bind socket" );
641 #endif
642         goto error;
643     }
644  
645     /* Listen */
646     if( listen( i_handle, 100 ) == -1 )
647     {
648 #ifdef HAVE_ERRNO_H
649          msg_Err( p_this, "cannot bring the socket in listening mode (%s)",
650                   strerror(errno) );
651 #else
652          msg_Err( p_this, "cannot bring the socket in listening mode" );
653 #endif
654          goto error;
655     }
656
657     p_socket->i_handle = i_handle;
658     p_socket->i_mtu = 0; /* There is no MTU notion in TCP */
659     return VLC_SUCCESS;
660
661 error:
662     close( i_handle );
663     return VLC_EGENERIC;
664 }
665
666 /*****************************************************************************
667  * NetOpen: wrapper around OpenUDP, ListenTCP and OpenTCP
668  *****************************************************************************/
669 static int NetOpen( vlc_object_t * p_this )
670 {
671     network_socket_t * p_socket = p_this->p_private;
672
673     if( p_socket->i_type == NETWORK_UDP )
674     {
675         return OpenUDP( p_this, p_socket );
676     }
677     else if( p_socket->i_type == NETWORK_TCP_PASSIVE )
678     {
679         return ListenTCP( p_this, p_socket );
680     }
681     else
682     {
683         return OpenTCP( p_this, p_socket );
684     }
685 }