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