* vlc_network.h: interface to communicate with network plug-ins
*****************************************************************************
* Copyright (C) 2002-2005 the VideoLAN team
+ * Copyright © 2006-2007 Rémi Denis-Courmont
* $Id$
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
/* Portable networking layer communication */
int net_Socket (vlc_object_t *obj, int family, int socktype, int proto);
-#define net_ConnectTCP(a, b, c) __net_ConnectTCP(VLC_OBJECT(a), b, c)
-#define net_OpenTCP(a, b, c) __net_ConnectTCP(VLC_OBJECT(a), b, c)
-VLC_EXPORT( int, __net_ConnectTCP, ( vlc_object_t *p_this, const char *psz_host, int i_port ) );
+#define net_Connect(a, b, c, d, e) __net_Connect(VLC_OBJECT(a), b, c, d, e)
+VLC_EXPORT( int, __net_Connect, (vlc_object_t *p_this, const char *psz_host, int i_port, int socktype, int protocol) );
-int *net_Listen (vlc_object_t *p_this, const char *psz_host, int i_port,
- int family, int socktype, int protocol);
+VLC_EXPORT( int *, net_Listen, (vlc_object_t *p_this, const char *psz_host, int i_port,
+ int family, int socktype, int protocol) );
VLC_EXPORT( int, net_ListenSingle, (vlc_object_t *p_this, const char *psz_host, int i_port, int family, int socktype, int protocol) );
#define net_ListenTCP(a, b, c) __net_ListenTCP(VLC_OBJECT(a), b, c)
-VLC_EXPORT( int *, __net_ListenTCP, ( vlc_object_t *, const char *, int ) );
+#define net_ConnectTCP(a, b, c) __net_ConnectTCP(VLC_OBJECT(a), b, c)
+
+static inline int *__net_ListenTCP (vlc_object_t *obj, const char *host, int port)
+{
+ return net_Listen (obj, host, port, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP);
+}
+
+static inline int __net_ConnectTCP (vlc_object_t *obj, const char *host, int port)
+{
+ return __net_Connect (obj, host, port, SOCK_STREAM, IPPROTO_TCP);
+}
#define net_Accept(a, b, c) __net_Accept(VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __net_Accept, ( vlc_object_t *, int *, mtime_t ) );
-#define net_ConnectUDP(a, b, c, d ) __net_ConnectUDP(VLC_OBJECT(a), b, c, d)
-VLC_EXPORT( int, __net_ConnectUDP, ( vlc_object_t *p_this, const char *psz_host, int i_port, int hlim ) );
+#define net_ConnectDgram(a, b, c, d, e ) __net_ConnectDgram(VLC_OBJECT(a), b, c, d, e)
+VLC_EXPORT( int, __net_ConnectDgram, ( vlc_object_t *p_this, const char *psz_host, int i_port, int hlim, int proto ) );
+
+static inline int net_ConnectUDP (vlc_object_t *obj, const char *host, int port, int hlim)
+{
+ return net_ConnectDgram (obj, host, port, hlim, IPPROTO_UDP);
+}
static inline int net_ListenUDP1 (vlc_object_t *obj, const char *host, int port)
{
- return net_ListenSingle (obj, host, port, AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP);
+ return net_ListenSingle (obj, host, port, AF_UNSPEC, SOCK_DGRAM, 0);
}
-#define net_OpenUDP(a, b, c, d, e ) __net_OpenUDP(VLC_OBJECT(a), b, c, d, e)
-VLC_EXPORT( int, __net_OpenUDP, ( vlc_object_t *p_this, const char *psz_bind, int i_bind, const char *psz_server, int i_server ) );
+#define net_OpenDgram( a, b, c, d, e, g, h ) __net_OpenDgram(VLC_OBJECT(a), b, c, d, e, g, h)
+VLC_EXPORT( int, __net_OpenDgram, ( vlc_object_t *p_this, const char *psz_bind, int i_bind, const char *psz_server, int i_server, int family, int proto ) );
VLC_EXPORT( void, net_Close, ( int fd ) );
VLC_EXPORT( void, net_ListenClose, ( int *fd ) );
#define net_ReadNonBlock(a,b,c,d,e,f) __net_ReadNonBlock(VLC_OBJECT(a),b,c,d,e,f)
VLC_EXPORT( int, __net_ReadNonBlock, ( vlc_object_t *p_this, int fd, const v_socket_t *, uint8_t *p_data, int i_data, mtime_t i_wait ) );
-#define net_Select(a,b,c,d,e,f,g) __net_Select(VLC_OBJECT(a),b,c,d,e,f,g)
-VLC_EXPORT( int, __net_Select, ( vlc_object_t *p_this, const int *pi_fd, const v_socket_t *const *, int i_fd, uint8_t *p_data, int i_data, mtime_t i_wait ) );
+#define net_Select(a,b,c,d,e,f) __net_Select(VLC_OBJECT(a),b,c,d,e,f)
+VLC_EXPORT( int, __net_Select, ( vlc_object_t *p_this, const int *pi_fd, int i_fd, uint8_t *p_data, int i_data, mtime_t i_wait ) );
#define net_Write(a,b,c,d,e) __net_Write(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_Write, ( vlc_object_t *p_this, int fd, const v_socket_t *, const uint8_t *p_data, int i_data ) );
#ifndef HAVE_INET_PTON
/* only in core, so no need for C++ extern "C" */
-int inet_pton(int af, const char *src, void *dst);
+VLC_EXPORT (int, inet_pton, (int af, const char *src, void *dst) );
+#endif
+
+#ifndef HAVE_POLL
+enum
+{
+ POLLIN=1,
+ POLLOUT=2,
+ POLLPRI=4,
+ POLLERR=8, // unsupported stub
+ POLLHUP=16, // unsupported stub
+ POLLNVAL=32 // unsupported stub
+};
+
+struct pollfd
+{
+ int fd;
+ int events;
+ int revents;
+};
+
+int poll (struct pollfd *fds, unsigned nfds, int timeout);
#endif
? VLC_EGENERIC : 0;
}
+static inline uint16_t net_GetPort (const struct sockaddr *addr)
+{
+ switch (addr->sa_family)
+ {
+#ifdef AF_INET6
+ case AF_INET6:
+ return ((const struct sockaddr_in6 *)addr)->sin6_port;
+#endif
+ case AF_INET:
+ return ((const struct sockaddr_in *)addr)->sin_port;
+ }
+ return 0;
+}
+
+static inline void net_SetPort (struct sockaddr *addr, uint16_t port)
+{
+ switch (addr->sa_family)
+ {
+#ifdef AF_INET6
+ case AF_INET6:
+ ((struct sockaddr_in6 *)addr)->sin6_port = port;
+ break;
+#endif
+ case AF_INET:
+ ((struct sockaddr_in *)addr)->sin_port = port;
+ break;
+ }
+}
# ifdef __cplusplus
}
# endif