Go to the documentation of this file.
28 # define VLC_NETWORK_H
40 #include <sys/types.h>
44 # define _NO_OLDNAMES 1
45 # include <winsock2.h>
46 # include <ws2tcpip.h>
47 # define net_errno (WSAGetLastError())
48 # define net_Close(fd) ((void)closesocket((SOCKET)fd))
50 # define IPV6_V6ONLY 27
53 # include <sys/socket.h>
54 # include <netinet/in.h>
56 # define net_errno errno
57 # define net_Close(fd) ((void)vlc_close(fd))
61 # define MSG_NOSIGNAL 0
125 #define net_Connect(a, b, c, d, e) net_Connect(VLC_OBJECT(a), b, c, d, e)
129 #define net_ListenTCP(a, b, c) net_Listen(VLC_OBJECT(a), b, c, \
130 SOCK_STREAM, IPPROTO_TCP)
134 return net_Connect (obj, host, port, SOCK_STREAM, IPPROTO_TCP);
136 #define net_ConnectTCP(a, b, c) net_ConnectTCP(VLC_OBJECT(a), b, c)
141 #define net_Accept(a, b) \
142 net_Accept(VLC_OBJECT(a), b)
145 #define net_ConnectDgram(a, b, c, d, e ) \
146 net_ConnectDgram(VLC_OBJECT(a), b, c, d, e)
154 #define net_OpenDgram( a, b, c, d, e, g ) \
155 net_OpenDgram(VLC_OBJECT(a), b, c, d, e, g)
159 return net_OpenDgram (obj, host, port, NULL, 0, IPPROTO_UDP);
170 #define net_Read(a,b,c,d) net_Read(VLC_OBJECT(a),b,c,d)
172 #define net_Write(a,b,c,d) net_Write(VLC_OBJECT(a),b,c,d)
174 #define net_Gets(a,b) net_Gets(VLC_OBJECT(a),b)
178 #define net_Printf(o,fd,...) net_Printf(VLC_OBJECT(o),fd, __VA_ARGS__)
180 #define net_vaPrintf(a,b,c,d) net_vaPrintf(VLC_OBJECT(a),b,c,d)
187 static inline int vlc_getsockopt(
int s,
int level,
int name,
188 void *val, socklen_t *len)
190 return getsockopt(s, level,
name, (
char *)val, len);
192 #define getsockopt vlc_getsockopt
194 static inline int vlc_setsockopt(
int s,
int level,
int name,
195 const void *val, socklen_t len)
197 return setsockopt(s, level,
name, (
const char *)val, len);
199 #define setsockopt vlc_setsockopt
204 #define NI_MAXNUMERICHOST 64
206 #ifndef AI_NUMERICSERV
207 # define AI_NUMERICSERV 0
214 # if !defined(WINAPI_FAMILY) || WINAPI_FAMILY != WINAPI_FAMILY_APP
216 # define gai_strerror gai_strerrorA
222 const struct addrinfo *,
struct addrinfo **);
224 const struct addrinfo *,
struct addrinfo **);
229 switch (addr->sa_family)
234 const struct sockaddr_in *v4 = (
const struct sockaddr_in *)addr;
235 if ((
size_t)len <
sizeof (*v4))
237 return IN_MULTICAST (ntohl (v4->sin_addr.s_addr)) != 0;
241 #ifdef IN6_IS_ADDR_MULTICAST
244 const struct sockaddr_in6 *v6 = (
const struct sockaddr_in6 *)addr;
245 if ((
size_t)len <
sizeof (*v6))
247 return IN6_IS_ADDR_MULTICAST (&v6->sin6_addr) != 0;
258 struct sockaddr_storage addr;
259 socklen_t addrlen =
sizeof( addr );
261 return getsockname( fd, (
struct sockaddr *)&addr, &addrlen )
269 struct sockaddr_storage addr;
270 socklen_t addrlen =
sizeof( addr );
272 return getpeername( fd, (
struct sockaddr *)&addr, &addrlen )
280 switch (addr->sa_family)
284 return ((
const struct sockaddr_in6 *)addr)->sin6_port;
287 return ((
const struct sockaddr_in *)addr)->sin_port;
292 static inline void net_SetPort (
struct sockaddr *addr, uint16_t port)
294 switch (addr->sa_family)
298 ((
struct sockaddr_in6 *)addr)->sin6_port = port;
302 ((
struct sockaddr_in *)addr)->sin_port = port;
#define VLC_FORMAT(x, y)
Definition: vlc_common.h:100
int net_SetCSCov(int fd, int sendcov, int recvcov)
net_SetCSCov: Sets the send and receive checksum coverage of a socket:
Definition: udp.c:684
#define VLC_API
Definition: fourcc_gen.c:30
int vlc_getnameinfo(const struct sockaddr *, int, char *, int, int *, int)
Definition: getaddrinfo.c:39
#define net_Printf(o, fd,...)
Definition: vlc_network.h:178
#define net_Gets(a, b)
Definition: vlc_network.h:174
static bool net_SockAddrIsMulticast(const struct sockaddr *addr, socklen_t len)
Definition: vlc_network.h:227
#define net_vaPrintf(a, b, c, d)
Definition: vlc_network.h:180
#define net_Connect(a, b, c, d, e)
Definition: vlc_network.h:125
int * net_Listen(vlc_object_t *p_this, const char *psz_host, int i_port, int socktype, int protocol)
Definition: io.c:104
char * vlc_getProxyUrl(const char *)
Determines the network proxy server to use (if any).
Definition: specific.c:315
#define VLC_EGENERIC
Unspecified error.
Definition: vlc_common.h:354
int vlc_getaddrinfo_i11e(const char *, unsigned, const struct addrinfo *, struct addrinfo **)
Definition: getaddrinfo.c:38
static int net_ConnectUDP(vlc_object_t *obj, const char *host, int port, int hlim)
Definition: vlc_network.h:148
int vlc_getaddrinfo(const char *, unsigned, const struct addrinfo *, struct addrinfo **)
Resolves a host name to a list of socket addresses (like getaddrinfo()).
Definition: getaddrinfo.c:77
int net_Subscribe(vlc_object_t *obj, int fd, const struct sockaddr *addr, socklen_t addrlen)
Definition: udp.c:393
int net_Socket(vlc_object_t *obj, int family, int socktype, int proto)
Definition: io.c:53
static uint16_t net_GetPort(const struct sockaddr *addr)
Definition: vlc_network.h:278
#define net_OpenDgram(a, b, c, d, e, g)
Definition: vlc_network.h:154
#define net_ConnectTCP(a, b, c)
Definition: vlc_network.h:136
The main vlc_object_t structure.
Definition: vlc_objects.h:39
#define net_ConnectDgram(a, b, c, d, e)
Definition: vlc_network.h:145
#define VLC_USED
Definition: fourcc_gen.c:31
static int net_GetSockAddress(int fd, char *address, int *port)
Definition: vlc_network.h:256
const char name[16]
Definition: httpd.c:1251
int vlc_close(int)
Closes a file descriptor.
Definition: filesystem.c:88
static int net_ListenUDP1(vlc_object_t *obj, const char *host, int port)
Definition: vlc_network.h:157
#define net_Read(a, b, c, d)
Definition: vlc_network.h:170
static int net_GetPeerAddress(int fd, char *address, int *port)
Definition: vlc_network.h:267
void net_ListenClose(int *fd)
Definition: tcp.c:527
#define net_Write(a, b, c, d)
Definition: vlc_network.h:172
#define net_Accept(a, b)
Definition: vlc_network.h:141
int vlc_socketpair(int pf, int type, int proto, int fds[2], bool nonblock)
Creates a pair of socket file descriptors.
Definition: filesystem.c:323
int vlc_accept(int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock)
Accepts an inbound connection request on a listening socket.
Definition: filesystem.c:333
#define NI_MAXNUMERICHOST
Definition: vlc_network.h:204
static void net_SetPort(struct sockaddr *addr, uint16_t port)
Definition: vlc_network.h:292
int vlc_socket(int pf, int type, int proto, bool nonblock)
Creates a socket file descriptor.
Definition: filesystem.c:315
uint16_t i_port
Definition: keystore.c:210
int net_AcceptSingle(vlc_object_t *obj, int lfd)
Definition: tcp.c:239