xref: /illumos-kvm-cmd/qemu_socket.h (revision 68396ea9)
1*68396ea9SRobert Mustacchi /* headers to use the BSD sockets */
2*68396ea9SRobert Mustacchi #ifndef QEMU_SOCKET_H
3*68396ea9SRobert Mustacchi #define QEMU_SOCKET_H
4*68396ea9SRobert Mustacchi 
5*68396ea9SRobert Mustacchi #ifdef _WIN32
6*68396ea9SRobert Mustacchi #include <windows.h>
7*68396ea9SRobert Mustacchi #include <winsock2.h>
8*68396ea9SRobert Mustacchi #include <ws2tcpip.h>
9*68396ea9SRobert Mustacchi 
10*68396ea9SRobert Mustacchi #define socket_error() WSAGetLastError()
11*68396ea9SRobert Mustacchi #undef EINTR
12*68396ea9SRobert Mustacchi #define EWOULDBLOCK WSAEWOULDBLOCK
13*68396ea9SRobert Mustacchi #define EINTR       WSAEINTR
14*68396ea9SRobert Mustacchi #define EINPROGRESS WSAEINPROGRESS
15*68396ea9SRobert Mustacchi 
16*68396ea9SRobert Mustacchi int inet_aton(const char *cp, struct in_addr *ia);
17*68396ea9SRobert Mustacchi 
18*68396ea9SRobert Mustacchi #else
19*68396ea9SRobert Mustacchi 
20*68396ea9SRobert Mustacchi #include <sys/types.h>
21*68396ea9SRobert Mustacchi #include <sys/socket.h>
22*68396ea9SRobert Mustacchi #include <netinet/in.h>
23*68396ea9SRobert Mustacchi #include <netinet/tcp.h>
24*68396ea9SRobert Mustacchi #include <arpa/inet.h>
25*68396ea9SRobert Mustacchi #include <netdb.h>
26*68396ea9SRobert Mustacchi #include <sys/un.h>
27*68396ea9SRobert Mustacchi 
28*68396ea9SRobert Mustacchi #define socket_error() errno
29*68396ea9SRobert Mustacchi #define closesocket(s) close(s)
30*68396ea9SRobert Mustacchi 
31*68396ea9SRobert Mustacchi #endif /* !_WIN32 */
32*68396ea9SRobert Mustacchi 
33*68396ea9SRobert Mustacchi #include "qemu-option.h"
34*68396ea9SRobert Mustacchi 
35*68396ea9SRobert Mustacchi /* misc helpers */
36*68396ea9SRobert Mustacchi int qemu_socket(int domain, int type, int protocol);
37*68396ea9SRobert Mustacchi int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
38*68396ea9SRobert Mustacchi void socket_set_nonblock(int fd);
39*68396ea9SRobert Mustacchi int send_all(int fd, const void *buf, int len1);
40*68396ea9SRobert Mustacchi 
41*68396ea9SRobert Mustacchi /* New, ipv6-ready socket helper functions, see qemu-sockets.c */
42*68396ea9SRobert Mustacchi int inet_listen_opts(QemuOpts *opts, int port_offset);
43*68396ea9SRobert Mustacchi int inet_listen(const char *str, char *ostr, int olen,
44*68396ea9SRobert Mustacchi                 int socktype, int port_offset);
45*68396ea9SRobert Mustacchi int inet_connect_opts(QemuOpts *opts);
46*68396ea9SRobert Mustacchi int inet_connect(const char *str, int socktype);
47*68396ea9SRobert Mustacchi int inet_dgram_opts(QemuOpts *opts);
48*68396ea9SRobert Mustacchi const char *inet_strfamily(int family);
49*68396ea9SRobert Mustacchi 
50*68396ea9SRobert Mustacchi int unix_listen_opts(QemuOpts *opts);
51*68396ea9SRobert Mustacchi int unix_listen(const char *path, char *ostr, int olen);
52*68396ea9SRobert Mustacchi int unix_connect_opts(QemuOpts *opts);
53*68396ea9SRobert Mustacchi int unix_connect(const char *path);
54*68396ea9SRobert Mustacchi 
55*68396ea9SRobert Mustacchi /* Old, ipv4 only bits.  Don't use for new code. */
56*68396ea9SRobert Mustacchi int parse_host_port(struct sockaddr_in *saddr, const char *str);
57*68396ea9SRobert Mustacchi int parse_host_src_port(struct sockaddr_in *haddr,
58*68396ea9SRobert Mustacchi                         struct sockaddr_in *saddr,
59*68396ea9SRobert Mustacchi                         const char *str);
60*68396ea9SRobert Mustacchi int socket_init(void);
61*68396ea9SRobert Mustacchi 
62*68396ea9SRobert Mustacchi #endif /* QEMU_SOCKET_H */