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

Don't require a vlc_object_t in net_Get(Sock|Peer)Address

(will be needed by a later commit)
parent 31e2f2b1
......@@ -32,7 +32,6 @@
# include <winsock2.h>
# include <ws2tcpip.h>
#else
# include <errno.h>
# include <netdb.h>
#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
......@@ -506,37 +505,26 @@ static inline vlc_bool_t net_AddressIsMulticast( vlc_object_t *p_object, char *p
return b_multicast;
}
#define net_GetSockAddress(a,b,c,d) __net_GetAddress(VLC_OBJECT(a),VLC_FALSE,b,c,d)
#define net_GetPeerAddress(a,b,c,d) __net_GetAddress(VLC_OBJECT(a),VLC_TRUE,b,c,d)
static inline int __net_GetAddress( vlc_object_t *p_this, vlc_bool_t peer, int fd,
char *address, int *port )
static inline int net_GetSockAddress( int fd, char *address, int *port )
{
struct sockaddr_storage addr;
socklen_t addrlen = sizeof( addr );
int val;
val = peer ? getpeername( fd, (struct sockaddr *)&addr, &addrlen )
: getsockname( fd, (struct sockaddr *)&addr, &addrlen );
return getpeername( fd, (struct sockaddr *)&addr, &addrlen )
|| vlc_getnameinfo( (struct sockaddr *)&addr, addrlen, address,
NI_MAXNUMERICHOST, port, NI_NUMERICHOST )
? VLC_EGENERIC : 0;
}
if (val)
{
#if defined(WIN32) || defined (UNDER_CE)
msg_Err( p_this, "socket address error : %d", WSAGetLastError( ) );
#else
msg_Err( p_this, "socket address error : %s", strerror( errno ) );
#endif
return val;
}
static inline int net_GetPeerAddress( int fd, char *address, int *port )
{
struct sockaddr_storage addr;
socklen_t addrlen = sizeof( addr );
val = vlc_getnameinfo( (struct sockaddr *)&addr, addrlen,
address, NI_MAXNUMERICHOST, port, NI_NUMERICHOST );
if( val )
{
msg_Err( p_this, "socket address error : %s",
vlc_gai_strerror( val ) );
}
return 0;
return getpeername( fd, (struct sockaddr *)&addr, &addrlen )
|| vlc_getnameinfo( (struct sockaddr *)&addr, addrlen, address,
NI_MAXNUMERICHOST, port, NI_NUMERICHOST )
? VLC_EGENERIC : 0;
}
#endif
......@@ -250,8 +250,7 @@ static int Open( vlc_object_t *p_this )
if( ftp_ReadCommand( p_access, &i_answer, NULL ) == 2 )
{
if( net_GetPeerAddress( p_access, p_sys->fd_cmd, p_sys->sz_epsv_ip,
NULL ) )
if( net_GetPeerAddress( p_sys->fd_cmd, p_sys->sz_epsv_ip, NULL ) )
goto exit_error;
}
else
......
......@@ -490,8 +490,8 @@ static int MMSOpen( access_t *p_access, vlc_url_t *p_url, int i_proto )
/* *** Bind port if UDP protocol is selected *** */
if( b_udp )
{
if( net_GetSockAddress( p_access, p_sys->i_handle_tcp,
p_sys->sz_bind_addr, NULL ) )
if( net_GetSockAddress( p_sys->i_handle_tcp, p_sys->sz_bind_addr,
NULL ) )
{
net_Close( p_sys->i_handle_tcp );
return VLC_EGENERIC;
......
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