Commit 986744e6 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

implement net_ConnectUDP() (yet to be used) to create a connected UDP socket,

and stop doing different things with net_OpenUDP()
parent 69392aa4
......@@ -358,8 +358,9 @@ static inline char *vlc_b64_encode( char *src )
}
/* Portable networking layer communication */
#define net_OpenTCP(a, b, c) __net_OpenTCP(VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __net_OpenTCP, ( vlc_object_t *p_this, const char *psz_host, int i_port ) );
#define net_ConnectTCP(a, b, c) __net_ConnectTCP(VLC_OBJECT(a), b, c)
#define net_OpenTCP(a, b, c) __net_ConnectTCP(VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __net_ConnectTCP, ( vlc_object_t *p_this, const char *psz_host, int i_port ) );
#define net_ListenTCP(a, b, c) __net_ListenTCP(VLC_OBJECT(a), b, c)
VLC_EXPORT( int *, __net_ListenTCP, ( vlc_object_t *, const char *, int ) );
......@@ -367,6 +368,9 @@ VLC_EXPORT( int *, __net_ListenTCP, ( vlc_object_t *, const char *, int ) );
#define net_Accept(a, b, c) __net_Accept(VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __net_Accept, ( vlc_object_t *, int *, mtime_t ) );
#define net_ConnectUDP(a, b, c, d ) __net_ConnectUDP(VLC_OBJECT(a), b, c, d)
VLC_EXPORT( int, __net_ConnectUDP, ( vlc_object_t *p_this, const char *psz_host, int i_port, int hlim ) );
#define net_OpenUDP(a, b, c, d, e ) __net_OpenUDP(VLC_OBJECT(a), b, c, d, e)
VLC_EXPORT( int, __net_OpenUDP, ( vlc_object_t *p_this, const char *psz_bind, int i_bind, const char *psz_server, int i_server ) );
......
......@@ -69,6 +69,7 @@ int playlist_LockItemToNode (playlist_t *,playlist_item_t *);
void spu_Destroy (spu_t *);
int osd_Icon (vlc_object_t *, spu_t *, int, int, int, short);
char* httpd_ServerIP (httpd_client_t *cl, char *psz_ip);
int __net_ConnectUDP (vlc_object_t *p_this, const char *psz_host, int i_port, int hlim);
int spu_Init (spu_t *);
void httpd_HostDelete (httpd_host_t *);
int __aout_VolumeGet (vlc_object_t *, audio_volume_t *);
......@@ -180,7 +181,7 @@ int playlist_Enable (playlist_t *, playlist_item_t *);
playlist_item_t* __playlist_ItemCopy (vlc_object_t *,playlist_item_t*);
char * vlc_strdup (const char *s);
playlist_item_t* __playlist_ItemNew (vlc_object_t *,const char *,const char *);
int __net_OpenTCP (vlc_object_t *p_this, const char *psz_host, int i_port);
int __net_ConnectTCP (vlc_object_t *p_this, const char *psz_host, int i_port);
int __var_Get (vlc_object_t *, const char *, vlc_value_t *);
void tls_ServerDelete (tls_server_t *);
unsigned int aout_FormatNbChannels (const audio_sample_format_t * p_format);
......@@ -513,7 +514,7 @@ struct module_symbols_t
void (*date_Move_inner) (date_t *, mtime_t);
mtime_t (*date_Increment_inner) (date_t *, uint32_t);
void *net_ConvertIPv4_deprecated;
int (*__net_OpenTCP_inner) (vlc_object_t *p_this, const char *psz_host, int i_port);
int (*__net_ConnectTCP_inner) (vlc_object_t *p_this, const char *psz_host, int i_port);
int * (*__net_ListenTCP_inner) (vlc_object_t *, const char *, int);
int (*__net_Accept_inner) (vlc_object_t *, int *, mtime_t);
int (*__net_OpenUDP_inner) (vlc_object_t *p_this, const char *psz_bind, int i_bind, const char *psz_server, int i_server);
......@@ -849,6 +850,7 @@ struct module_symbols_t
char * (*config_GetUserDir_inner) (void);
char * (*FromUTF32_inner) (const wchar_t *);
void (*__input_Read_inner) (vlc_object_t *, input_item_t *, vlc_bool_t);
int (*__net_ConnectUDP_inner) (vlc_object_t *p_this, const char *psz_host, int i_port, int hlim);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -923,7 +925,7 @@ struct module_symbols_t
# define date_Get (p_symbols)->date_Get_inner
# define date_Move (p_symbols)->date_Move_inner
# define date_Increment (p_symbols)->date_Increment_inner
# define __net_OpenTCP (p_symbols)->__net_OpenTCP_inner
# define __net_ConnectTCP (p_symbols)->__net_ConnectTCP_inner
# define __net_ListenTCP (p_symbols)->__net_ListenTCP_inner
# define __net_Accept (p_symbols)->__net_Accept_inner
# define __net_OpenUDP (p_symbols)->__net_OpenUDP_inner
......@@ -1259,6 +1261,7 @@ struct module_symbols_t
# define config_GetUserDir (p_symbols)->config_GetUserDir_inner
# define FromUTF32 (p_symbols)->FromUTF32_inner
# define __input_Read (p_symbols)->__input_Read_inner
# define __net_ConnectUDP (p_symbols)->__net_ConnectUDP_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1336,7 +1339,7 @@ struct module_symbols_t
((p_symbols)->date_Get_inner) = date_Get; \
((p_symbols)->date_Move_inner) = date_Move; \
((p_symbols)->date_Increment_inner) = date_Increment; \
((p_symbols)->__net_OpenTCP_inner) = __net_OpenTCP; \
((p_symbols)->__net_ConnectTCP_inner) = __net_ConnectTCP; \
((p_symbols)->__net_ListenTCP_inner) = __net_ListenTCP; \
((p_symbols)->__net_Accept_inner) = __net_Accept; \
((p_symbols)->__net_OpenUDP_inner) = __net_OpenUDP; \
......@@ -1672,6 +1675,7 @@ struct module_symbols_t
((p_symbols)->config_GetUserDir_inner) = config_GetUserDir; \
((p_symbols)->FromUTF32_inner) = FromUTF32; \
((p_symbols)->__input_Read_inner) = __input_Read; \
((p_symbols)->__net_ConnectUDP_inner) = __net_ConnectUDP; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
# endif /* __PLUGIN__ */
......
......@@ -123,11 +123,11 @@ static int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
}
/*****************************************************************************
* __net_OpenTCP:
* __net_ConnectTCP:
*****************************************************************************
* Open a TCP connection and return a handle
*****************************************************************************/
int __net_OpenTCP( vlc_object_t *p_this, const char *psz_host, int i_port )
int __net_ConnectTCP( vlc_object_t *p_this, const char *psz_host, int i_port )
{
struct addrinfo hints, *res, *ptr;
const char *psz_realhost;
......@@ -204,7 +204,7 @@ int __net_OpenTCP( vlc_object_t *p_this, const char *psz_host, int i_port )
if( errno != EINPROGRESS )
{
if( errno == ENETUNREACH )
b_unreach = VLC_FALSE;
b_unreach = VLC_TRUE;
else
msg_Warn( p_this, "connection to %s port %d : %s", psz_host,
i_port, strerror( errno ) );
......@@ -379,7 +379,7 @@ int *__net_ListenTCP( vlc_object_t *p_this, const char *psz_host, int i_port )
net_Close( fd );
continue;
}
/* Listen */
if( listen( fd, 100 ) == -1 )
{
......@@ -501,6 +501,95 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
return -1;
}
/*****************************************************************************
* __net_ConnectUDP:
*****************************************************************************
* Open a UDP socket to send data to a defined destination, with an optional
* hop limit.
*****************************************************************************/
int __net_ConnectUDP( vlc_object_t *p_this, const char *psz_host, int i_port,
int hlim )
{
struct addrinfo hints, *res, *ptr;
int i_val, i_handle = -1;
vlc_bool_t b_unreach = VLC_FALSE;
if( i_port == 0 )
i_port = 1234; /* historical VLC thing */
memset( &hints, 0, sizeof( hints ) );
hints.ai_socktype = SOCK_DGRAM;
msg_Dbg( p_this, "net: connecting to %s port %d", psz_host, i_port );
i_val = vlc_getaddrinfo( p_this, psz_host, i_port, &hints, &res );
if( i_val )
{
msg_Err( p_this, "cannot resolve %s port %d : %s", psz_host, i_port,
vlc_gai_strerror( i_val ) );
return -1;
}
for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
{
int fd;
fd = net_Socket( p_this, ptr->ai_family, ptr->ai_socktype,
ptr->ai_protocol );
if( fd == -1 )
continue;
#if !defined( SYS_BEOS )
else
{
int i_val;
/* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
* packet loss caused by scheduling problems */
i_val = 0x80000;
setsockopt( i_handle, SOL_SOCKET, SO_RCVBUF, (void *)&i_val,
sizeof( i_val ) );
i_val = 0x80000;
setsockopt( i_handle, SOL_SOCKET, SO_SNDBUF, (void *)&i_val,
sizeof( i_val ) );
}
#endif
if( connect( fd, ptr->ai_addr, ptr->ai_addrlen ) == 0 )
{
/* success */
i_handle = fd;
break;
}
#if defined( WIN32 ) || defined( UNDER_CE )
if( WSAGetLastError () == WSAENETUNREACH )
#else
if( errno == ENETUNREACH )
#endif
b_unreach = VLC_TRUE;
else
{
msg_Warn( p_this, "%s port %d : %s", psz_host, i_port,
strerror( errno ) );
net_Close( fd );
continue;
}
}
vlc_freeaddrinfo( res );
if( i_handle == -1 )
{
if( b_unreach )
msg_Err( p_this, "Host %s port %d is unreachable", psz_host,
i_port );
return -1;
}
return i_handle;
}
/*****************************************************************************
* __net_OpenUDP:
*****************************************************************************
......@@ -514,6 +603,13 @@ int __net_OpenUDP( vlc_object_t *p_this, const char *psz_bind, int i_bind,
network_socket_t sock;
module_t *p_network = NULL;
if( ( psz_server != NULL ) && ( psz_server[0] == '\0' ) )
msg_Warn( p_this, "calling net_OpenUDP with an explicit destination "
"is obsolete - use net_ConnectUDP instead" );
if( i_server != 0 )
msg_Warn( p_this, "calling net_OpenUDP with an explicit destination "
"port is obsolete - use __net_ConnectUDP instead" );
if( psz_server == NULL ) psz_server = "";
if( psz_bind == NULL ) psz_bind = "";
......@@ -1041,7 +1137,7 @@ static int SocksNegociate( vlc_object_t *p_obj,
buffer[2] = 0x00; /* - No auth required */
i_len = 3;
}
if( net_Write( p_obj, fd, NULL, buffer, i_len ) != i_len )
return VLC_EGENERIC;
if( net_Read( p_obj, fd, NULL, buffer, 2, VLC_TRUE ) != 2 )
......@@ -1232,7 +1328,7 @@ int inet_pton(int af, const char *src, void *dst)
case AF_INET6:
memcpy( dst, &((struct sockaddr_in6 *)&addr)->sin6_addr, 16 );
break;
case AF_INET:
memcpy( dst, &((struct sockaddr_in *)&addr)->sin_addr, 4 );
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment