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);
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;
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 )
{
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,
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 );
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 );
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;
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));
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;
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);
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,
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)
return -1;
}
- hints.ai_flags = AI_PASSIVE;
+ hints.ai_flags |= AI_PASSIVE;
val = vlc_getaddrinfo (psz_bind, i_bind, &hints, &loc);
if (val)
{