/*****************************************************************************
* io.c: network I/O functions
*****************************************************************************
- * Copyright (C) 2004-2005 the VideoLAN team
+ * Copyright (C) 2004-2005, 2007 the VideoLAN team
* Copyright © 2005-2006 Rémi Denis-Courmont
* $Id$
*
* Authors: Laurent Aimar <fenrir@videolan.org>
* Rémi Denis-Courmont <rem # videolan.org>
+ * Christophe Mutricy <xtophe at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
# include <poll.h>
#endif
-#include "network.h"
+#include <vlc_network.h>
#ifndef INADDR_ANY
# define INADDR_ANY 0x00000000
memset (&hints, 0, sizeof( hints ));
hints.ai_family = family;
hints.ai_socktype = socktype;
- hints.ai_protocol = protocol;
hints.ai_flags = AI_PASSIVE;
msg_Dbg (p_this, "net: listening to %s port %d", psz_host, i_port);
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);
+ protocol ?: ptr->ai_protocol);
if (fd == -1)
{
msg_Dbg (p_this, "socket error: %s", net_strerror (net_errno));
net_Close (fd);
#if !defined(WIN32) && !defined(UNDER_CE)
fd = rootwrap_bind (ptr->ai_family, ptr->ai_socktype,
- ptr->ai_protocol, ptr->ai_addr,
+ protocol ?: ptr->ai_protocol, ptr->ai_addr,
ptr->ai_addrlen);
if (fd != -1)
{
for (unsigned i = 1; fdv[i] != -1; i++)
{
- msg_Warn (obj, "A socket has been dropped!");
+ msg_Warn (obj, "Multiple sockets opened. Dropping extra ones!");
net_Close (fdv[i]);
}
{
unsigned i;
ssize_t n;
-#ifdef HAVE_POLL
struct pollfd ufd[fdc];
-#else
- int maxfd = -1;
- fd_set set;
-#endif
int delay_ms = 500;
if ((wait_ms != -1) && (wait_ms < 500))
goto error;
}
-#ifdef HAVE_POLL
memset (ufd, 0, sizeof (ufd));
for( i = 0; i < fdc; i++ )
}
n = poll( ufd, fdc, delay_ms );
-#else
- FD_ZERO (&set);
-
- for( i = 0; i < fdc; i++ )
- {
-#if !defined(WIN32) && !defined(UNDER_CE)
- if( fdv[i] >= FD_SETSIZE )
- {
- /* We don't want to overflow select() fd_set */
- msg_Err( p_this, "select set overflow" );
- return -1;
- }
-#endif
- FD_SET( fdv[i], &set );
- if( fdv[i] > maxfd )
- maxfd = fdv[i];
- }
-
- n = select( maxfd + 1, &set, NULL, NULL,
- (wait_ms == -1) ? NULL
- : &(struct timeval){ 0, delay_ms * 1000 } );
-#endif
if( n == -1 )
goto error;
for (i = 0;; i++)
{
-#ifdef HAVE_POLL
if ((i_total > 0) && (ufd[i].revents & POLLERR))
return i_total; // error will be dequeued on next run
if ((ufd[i].revents & POLLIN) == 0)
-#else
- if (!FD_ISSET (fdv[i], &set))
continue;
-#endif
+
fdc = 1;
fdv += i;
vsv += i;
* that has some.
*****************************************************************************/
int __net_Select( vlc_object_t *restrict p_this, const int *restrict pi_fd,
- const v_socket_t *const *restrict pp_vs,
int i_fd, uint8_t *restrict p_data, int i_data,
mtime_t i_wait )
{
- if( pp_vs == NULL )
- {
- const v_socket_t *vsv[i_fd];
- memset( vsv, 0, sizeof (vsv) );
-
- return net_ReadInner( p_this, i_fd, pi_fd, vsv, p_data, i_data,
- i_wait / 1000, VLC_FALSE );
- }
+ const v_socket_t *vsv[i_fd];
+ memset( vsv, 0, sizeof (vsv) );
- return net_ReadInner( p_this, i_fd, pi_fd, pp_vs, p_data, i_data,
+ return net_ReadInner( p_this, i_fd, pi_fd, vsv, p_data, i_data,
i_wait / 1000, VLC_FALSE );
}
return 0;
}
#endif /* HAVE_INET_PTON */
+
+#ifndef HAVE_INET_NTOP
+#ifdef WIN32
+const char *inet_ntop(int af, const void * src,
+ char * dst, socklen_t cnt)
+{
+ switch( af )
+ {
+#ifdef AF_INET6
+ case AF_INET6:
+ {
+ struct sockaddr_in6 addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.sin6_family = AF_INET6;
+ addr.sin6_addr = *((struct in6_addr*)src);
+ if( 0 == WSAAddressToStringA((LPSOCKADDR)&addr,
+ sizeof(struct sockaddr_in6),
+ NULL, dst, &cnt) )
+ {
+ dst[cnt] = '\0';
+ return dst;
+ }
+ errno = WSAGetLastError();
+ return NULL;
+
+ }
+
+#endif
+ case AF_INET:
+ {
+ struct sockaddr_in addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr = *((struct in_addr*)src);
+ if( 0 == WSAAddressToStringA((LPSOCKADDR)&addr,
+ sizeof(struct sockaddr_in),
+ NULL, dst, &cnt) )
+ {
+ dst[cnt] = '\0';
+ return dst;
+ }
+ errno = WSAGetLastError();
+ return NULL;
+
+ }
+ }
+ errno = EAFNOSUPPORT;
+ return NULL;
+}
+#endif
+#endif