blob: c8ca07ea7d65a58a61dfba633f627a069e5a64ba [file] [log] [blame]
bellard6ca957f2006-04-30 22:53:25 +00001/* headers to use the BSD sockets */
2#ifndef QEMU_SOCKET_H
3#define QEMU_SOCKET_H
4
5#ifdef _WIN32
ths4fddf622007-12-17 04:42:29 +00006#define WIN32_LEAN_AND_MEAN
aliguorid247d252008-11-11 20:46:40 +00007#define WINVER 0x0501 /* needed for ipv6 bits */
bellard6ca957f2006-04-30 22:53:25 +00008#include <windows.h>
9#include <winsock2.h>
10#include <ws2tcpip.h>
11
12#define socket_error() WSAGetLastError()
13#undef EINTR
14#define EWOULDBLOCK WSAEWOULDBLOCK
15#define EINTR WSAEINTR
16#define EINPROGRESS WSAEINPROGRESS
17
aliguori03ff3ca2008-09-15 15:51:35 +000018int inet_aton(const char *cp, struct in_addr *ia);
19
bellard6ca957f2006-04-30 22:53:25 +000020#else
21
22#include <sys/socket.h>
23#include <netinet/in.h>
24#include <netinet/tcp.h>
aliguori03ff3ca2008-09-15 15:51:35 +000025#include <arpa/inet.h>
26#include <netdb.h>
thsffd843b2006-12-21 19:46:43 +000027#include <sys/un.h>
bellard6ca957f2006-04-30 22:53:25 +000028
29#define socket_error() errno
30#define closesocket(s) close(s)
31
32#endif /* !_WIN32 */
33
aliguorid247d252008-11-11 20:46:40 +000034/* misc helpers */
bellard6ca957f2006-04-30 22:53:25 +000035void socket_set_nonblock(int fd);
aliguorid247d252008-11-11 20:46:40 +000036int send_all(int fd, const void *buf, int len1);
37
38/* New, ipv6-ready socket helper functions, see qemu-sockets.c */
39int inet_listen(const char *str, char *ostr, int olen,
40 int socktype, int port_offset);
41int inet_connect(const char *str, int socktype);
42
43int unix_listen(const char *path, char *ostr, int olen);
44int unix_connect(const char *path);
45
46/* Old, ipv4 only bits. Don't use for new code. */
aliguori5bb79102008-10-13 03:12:02 +000047int parse_host_port(struct sockaddr_in *saddr, const char *str);
aliguori0e82f342008-10-31 18:44:40 +000048int parse_host_src_port(struct sockaddr_in *haddr,
49 struct sockaddr_in *saddr,
50 const char *str);
bellard6ca957f2006-04-30 22:53:25 +000051
52#endif /* QEMU_SOCKET_H */