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

vlc_getaddrinfo: pass AI_NUMERICSERV explicitly where applicable

parent 16d8d7b7
......@@ -130,9 +130,6 @@ int vlc_getaddrinfo (const char *node, unsigned port,
hints.ai_flags = p_hints->ai_flags & safe_flags;
}
/* We only ever use port *numbers* */
hints.ai_flags |= AI_NUMERICSERV;
/*
* VLC extensions :
* - accept "" as NULL
......
......@@ -127,12 +127,11 @@ int net_Socket (vlc_object_t *p_this, int family, int socktype,
int *net_Listen (vlc_object_t *p_this, const char *psz_host,
int i_port, int type, int protocol)
{
struct addrinfo hints, *res;
memset (&hints, 0, sizeof( hints ));
hints.ai_socktype = type;
hints.ai_protocol = protocol;
hints.ai_flags = AI_PASSIVE;
struct addrinfo hints = {
.ai_socktype = type,
.ai_protocol = protocol,
.ai_flags = AI_PASSIVE | AI_NUMERICSERV,
}, *res;
msg_Dbg (p_this, "net: listening to %s port %d",
(psz_host != NULL) ? psz_host : "*", i_port);
......
......@@ -75,7 +75,6 @@ extern int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
int type, int proto )
{
struct addrinfo hints, *res, *ptr;
const char *psz_realhost;
char *psz_socks;
int i_realport, i_handle = -1;
......@@ -84,10 +83,6 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
if (evfd == -1)
return -1;
memset( &hints, 0, sizeof( hints ) );
hints.ai_socktype = type;
hints.ai_protocol = proto;
psz_socks = var_InheritString( p_this, "socks" );
if( psz_socks != NULL )
{
......@@ -98,7 +93,6 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
psz_realhost = psz_socks;
i_realport = ( psz != NULL ) ? atoi( psz ) : 1080;
hints.ai_flags &= ~AI_NUMERICHOST;
msg_Dbg( p_this, "net: connecting to %s port %d (SOCKS) "
"for %s port %d", psz_realhost, i_realport,
......@@ -137,6 +131,12 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
i_realport );
}
struct addrinfo hints = {
.ai_socktype = type,
.ai_protocol = proto,
.ai_flags = AI_NUMERICSERV,
}, *res;
int val = vlc_getaddrinfo (psz_realhost, i_realport, &hints, &res);
free( psz_socks );
......@@ -151,7 +151,7 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
if (timeout < 0)
timeout = -1;
for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
{
int fd = net_Socket( p_this, ptr->ai_family,
ptr->ai_socktype, ptr->ai_protocol );
......@@ -445,13 +445,15 @@ static int SocksHandshakeTCP( vlc_object_t *p_obj,
if( i_socks_version == 4 )
{
struct addrinfo hints, *res;
/* v4 only support ipv4 */
memset (&hints, 0, sizeof (hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
static const struct addrinfo hints = {
.ai_family = AF_INET,
.ai_socktype = SOCK_STREAM,
.ai_protocol = IPPROTO_TCP,
.ai_flags = 0,
};
struct addrinfo *res;
if (vlc_getaddrinfo (psz_host, 0, &hints, &res))
return VLC_EGENERIC;
......
......@@ -94,7 +94,8 @@ extern int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
int i_protocol );
/* */
static int net_SetupDgramSocket( vlc_object_t *p_obj, int fd, const struct addrinfo *ptr )
static int net_SetupDgramSocket (vlc_object_t *p_obj, int fd,
const struct addrinfo *ptr)
{
#ifdef SO_REUSEPORT
setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, &(int){ 1 }, sizeof (int));
......@@ -137,12 +138,11 @@ static int net_SetupDgramSocket( vlc_object_t *p_obj, int fd, const struct addri
static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
int protocol)
{
struct addrinfo hints, *res;
memset (&hints, 0, sizeof( hints ));
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = protocol;
hints.ai_flags = AI_PASSIVE;
struct addrinfo hints = {
.ai_socktype = SOCK_DGRAM,
.ai_protocol = protocol,
.ai_flags = AI_PASSIVE | AI_NUMERICSERV,
}, *res;
if (host && !*host)
host = NULL;
......@@ -503,17 +503,17 @@ static int net_SetDSCP( int fd, uint8_t dscp )
int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
int i_hlim, int proto )
{
struct addrinfo hints, *res, *ptr;
struct addrinfo hints = {
.ai_socktype = SOCK_DGRAM,
.ai_protocol = proto,
.ai_flags = AI_NUMERICSERV,
}, *res;
int i_handle = -1;
bool b_unreach = false;
if( i_hlim < 0 )
i_hlim = var_InheritInteger( p_this, "ttl" );
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 );
int val = vlc_getaddrinfo (psz_host, i_port, &hints, &res);
......@@ -524,7 +524,7 @@ int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
return -1;
}
for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
{
char *str;
int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
......@@ -601,11 +601,11 @@ int net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
msg_Dbg (obj, "net: connecting to [%s]:%d from [%s]:%d",
psz_server, i_server, psz_bind, i_bind);
struct addrinfo hints, *loc, *rem;
memset (&hints, 0, sizeof (hints));
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = protocol;
struct addrinfo hints = {
.ai_socktype = SOCK_DGRAM,
.ai_protocol = protocol,
.ai_flags = AI_NUMERICSERV,
}, *loc, *rem;
int val = vlc_getaddrinfo (psz_server, i_server, &hints, &rem);
if (val)
......@@ -615,7 +615,7 @@ int net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
return -1;
}
hints.ai_flags = AI_PASSIVE;
hints.ai_flags |= AI_PASSIVE;
val = vlc_getaddrinfo (psz_bind, i_bind, &hints, &loc);
if (val)
{
......
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