blob: 30ae6af8b8cc7c496883c89fceb38005118534eb [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()
bellard6ca957f2006-04-30 22:53:25 +000011
aliguori03ff3ca2008-09-15 15:51:35 +000012int inet_aton(const char *cp, struct in_addr *ia);
13
bellard6ca957f2006-04-30 22:53:25 +000014#else
15
Blue Swirl80bb8cb2010-09-22 19:51:33 +030016#include <sys/types.h>
bellard6ca957f2006-04-30 22:53:25 +000017#include <sys/socket.h>
18#include <netinet/in.h>
19#include <netinet/tcp.h>
aliguori03ff3ca2008-09-15 15:51:35 +000020#include <arpa/inet.h>
21#include <netdb.h>
thsffd843b2006-12-21 19:46:43 +000022#include <sys/un.h>
bellard6ca957f2006-04-30 22:53:25 +000023
24#define socket_error() errno
25#define closesocket(s) close(s)
26
27#endif /* !_WIN32 */
28
Gerd Hoffmann2af2bf62009-09-10 10:58:37 +020029#include "qemu-option.h"
Amos Konga6ba35b2012-05-11 00:28:16 +080030#include "error.h"
31#include "qerror.h"
Gerd Hoffmann2af2bf62009-09-10 10:58:37 +020032
aliguorid247d252008-11-11 20:46:40 +000033/* misc helpers */
Kevin Wolf40ff6d72009-12-02 12:24:42 +010034int qemu_socket(int domain, int type, int protocol);
35int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
Paolo Bonzini128aa582011-09-21 12:36:48 +020036int socket_set_cork(int fd, int v);
Paolo Bonzini154b9a02011-10-05 09:17:32 +020037void socket_set_block(int fd);
bellard6ca957f2006-04-30 22:53:25 +000038void socket_set_nonblock(int fd);
aliguorid247d252008-11-11 20:46:40 +000039int send_all(int fd, const void *buf, int len1);
40
41/* New, ipv6-ready socket helper functions, see qemu-sockets.c */
Amos Kong029409e2012-05-11 00:28:26 +080042int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
aliguorid247d252008-11-11 20:46:40 +000043int inet_listen(const char *str, char *ostr, int olen,
Amos Kong029409e2012-05-11 00:28:26 +080044 int socktype, int port_offset, Error **errp);
Luiz Capitulino02a08fe2012-08-01 13:42:47 -030045int inet_connect_opts(QemuOpts *opts, bool *in_progress, Error **errp);
46int inet_connect(const char *str, bool block, bool *in_progress, Error **errp);
Gerd Hoffmann7e1b35b2009-09-10 10:58:51 +020047int inet_dgram_opts(QemuOpts *opts);
Luiz Capitulinoc9c4b342010-01-20 11:42:38 -020048const char *inet_strfamily(int family);
aliguorid247d252008-11-11 20:46:40 +000049
Gerd Hoffmann62b6adf2009-09-10 10:58:38 +020050int unix_listen_opts(QemuOpts *opts);
aliguorid247d252008-11-11 20:46:40 +000051int unix_listen(const char *path, char *ostr, int olen);
Gerd Hoffmann2af2bf62009-09-10 10:58:37 +020052int unix_connect_opts(QemuOpts *opts);
aliguorid247d252008-11-11 20:46:40 +000053int unix_connect(const char *path);
54
55/* Old, ipv4 only bits. Don't use for new code. */
aliguori5bb79102008-10-13 03:12:02 +000056int parse_host_port(struct sockaddr_in *saddr, const char *str);
Paolo Bonzini0706a4d2010-04-01 19:57:08 +020057int socket_init(void);
bellard6ca957f2006-04-30 22:53:25 +000058
59#endif /* QEMU_SOCKET_H */