blob: c253b324156be8316aa6a1ad9b1b81f19d92eb73 [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
bellard6ca957f2006-04-30 22:53:25 +00006#include <windows.h>
7#include <winsock2.h>
8#include <ws2tcpip.h>
9
10#define socket_error() WSAGetLastError()
11#undef EINTR
12#define EWOULDBLOCK WSAEWOULDBLOCK
13#define EINTR WSAEINTR
14#define EINPROGRESS WSAEINPROGRESS
15
aliguori03ff3ca2008-09-15 15:51:35 +000016int inet_aton(const char *cp, struct in_addr *ia);
17
bellard6ca957f2006-04-30 22:53:25 +000018#else
19
20#include <sys/socket.h>
21#include <netinet/in.h>
22#include <netinet/tcp.h>
aliguori03ff3ca2008-09-15 15:51:35 +000023#include <arpa/inet.h>
24#include <netdb.h>
thsffd843b2006-12-21 19:46:43 +000025#include <sys/un.h>
bellard6ca957f2006-04-30 22:53:25 +000026
27#define socket_error() errno
28#define closesocket(s) close(s)
29
30#endif /* !_WIN32 */
31
Gerd Hoffmann2af2bf62009-09-10 10:58:37 +020032#include "qemu-option.h"
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 */
Gerd Hoffmanne5bc7762009-09-10 10:58:41 +020039int inet_listen_opts(QemuOpts *opts, int port_offset);
aliguorid247d252008-11-11 20:46:40 +000040int inet_listen(const char *str, char *ostr, int olen,
41 int socktype, int port_offset);
Gerd Hoffmannf4c94c72009-09-10 10:58:40 +020042int inet_connect_opts(QemuOpts *opts);
aliguorid247d252008-11-11 20:46:40 +000043int inet_connect(const char *str, int socktype);
Gerd Hoffmann7e1b35b2009-09-10 10:58:51 +020044int inet_dgram_opts(QemuOpts *opts);
aliguorid247d252008-11-11 20:46:40 +000045
Gerd Hoffmann62b6adf2009-09-10 10:58:38 +020046int unix_listen_opts(QemuOpts *opts);
aliguorid247d252008-11-11 20:46:40 +000047int unix_listen(const char *path, char *ostr, int olen);
Gerd Hoffmann2af2bf62009-09-10 10:58:37 +020048int unix_connect_opts(QemuOpts *opts);
aliguorid247d252008-11-11 20:46:40 +000049int unix_connect(const char *path);
50
51/* Old, ipv4 only bits. Don't use for new code. */
aliguori5bb79102008-10-13 03:12:02 +000052int parse_host_port(struct sockaddr_in *saddr, const char *str);
aliguori0e82f342008-10-31 18:44:40 +000053int parse_host_src_port(struct sockaddr_in *haddr,
54 struct sockaddr_in *saddr,
55 const char *str);
bellard6ca957f2006-04-30 22:53:25 +000056
57#endif /* QEMU_SOCKET_H */