2006-04-30 22:53:25 +00:00
|
|
|
/* headers to use the BSD sockets */
|
|
|
|
#ifndef QEMU_SOCKET_H
|
|
|
|
#define QEMU_SOCKET_H
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
|
|
|
|
#define socket_error() WSAGetLastError()
|
|
|
|
|
2008-09-15 15:51:35 +00:00
|
|
|
int inet_aton(const char *cp, struct in_addr *ia);
|
|
|
|
|
2006-04-30 22:53:25 +00:00
|
|
|
#else
|
|
|
|
|
2010-09-22 16:51:33 +00:00
|
|
|
#include <sys/types.h>
|
2006-04-30 22:53:25 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2008-09-15 15:51:35 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
2006-12-21 19:46:43 +00:00
|
|
|
#include <sys/un.h>
|
2006-04-30 22:53:25 +00:00
|
|
|
|
|
|
|
#define socket_error() errno
|
|
|
|
#define closesocket(s) close(s)
|
|
|
|
|
|
|
|
#endif /* !_WIN32 */
|
|
|
|
|
2012-12-17 17:20:00 +00:00
|
|
|
#include "qemu/option.h"
|
2012-12-17 17:19:43 +00:00
|
|
|
#include "qapi/error.h"
|
2014-06-18 06:43:30 +00:00
|
|
|
#include "qapi-types.h"
|
2009-09-10 08:58:37 +00:00
|
|
|
|
2013-03-15 16:14:24 +00:00
|
|
|
extern QemuOptsList socket_optslist;
|
|
|
|
|
2008-11-11 20:46:40 +00:00
|
|
|
/* misc helpers */
|
2009-12-02 11:24:42 +00:00
|
|
|
int qemu_socket(int domain, int type, int protocol);
|
|
|
|
int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
|
2011-09-21 10:36:48 +00:00
|
|
|
int socket_set_cork(int fd, int v);
|
2013-02-22 03:39:50 +00:00
|
|
|
int socket_set_nodelay(int fd);
|
2013-03-27 09:10:43 +00:00
|
|
|
void qemu_set_block(int fd);
|
|
|
|
void qemu_set_nonblock(int fd);
|
2013-10-02 10:23:12 +00:00
|
|
|
int socket_set_fast_reuse(int fd);
|
2008-11-11 20:46:40 +00:00
|
|
|
int send_all(int fd, const void *buf, int len1);
|
2013-02-27 17:47:53 +00:00
|
|
|
int recv_all(int fd, void *buf, int len1, bool single_read);
|
2008-11-11 20:46:40 +00:00
|
|
|
|
2015-01-08 11:11:30 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
/* Windows has different names for the same constants with the same values */
|
|
|
|
#define SHUT_RD 0
|
|
|
|
#define SHUT_WR 1
|
|
|
|
#define SHUT_RDWR 2
|
|
|
|
#endif
|
|
|
|
|
2012-09-24 11:11:09 +00:00
|
|
|
/* callback function for nonblocking connect
|
|
|
|
* valid fd on success, negative error code on failure
|
|
|
|
*/
|
2014-10-08 12:11:56 +00:00
|
|
|
typedef void NonBlockingConnectHandler(int fd, Error *errp, void *opaque);
|
2012-09-24 11:11:09 +00:00
|
|
|
|
2013-03-15 10:55:29 +00:00
|
|
|
InetSocketAddress *inet_parse(const char *str, Error **errp);
|
2012-05-10 16:28:26 +00:00
|
|
|
int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
|
2008-11-11 20:46:40 +00:00
|
|
|
int inet_listen(const char *str, char *ostr, int olen,
|
2012-05-10 16:28:26 +00:00
|
|
|
int socktype, int port_offset, Error **errp);
|
2012-09-24 11:11:09 +00:00
|
|
|
int inet_connect_opts(QemuOpts *opts, Error **errp,
|
|
|
|
NonBlockingConnectHandler *callback, void *opaque);
|
2012-09-24 11:11:08 +00:00
|
|
|
int inet_connect(const char *str, Error **errp);
|
2012-09-24 11:11:09 +00:00
|
|
|
int inet_nonblocking_connect(const char *str,
|
|
|
|
NonBlockingConnectHandler *callback,
|
|
|
|
void *opaque, Error **errp);
|
|
|
|
|
2012-10-02 07:35:32 +00:00
|
|
|
int inet_dgram_opts(QemuOpts *opts, Error **errp);
|
2014-06-18 06:43:30 +00:00
|
|
|
NetworkAddressFamily inet_netfamily(int family);
|
2008-11-11 20:46:40 +00:00
|
|
|
|
2012-10-02 07:35:32 +00:00
|
|
|
int unix_listen_opts(QemuOpts *opts, Error **errp);
|
|
|
|
int unix_listen(const char *path, char *ostr, int olen, Error **errp);
|
2012-10-03 11:37:46 +00:00
|
|
|
int unix_connect_opts(QemuOpts *opts, Error **errp,
|
|
|
|
NonBlockingConnectHandler *callback, void *opaque);
|
2012-10-02 07:35:32 +00:00
|
|
|
int unix_connect(const char *path, Error **errp);
|
2012-10-03 11:37:46 +00:00
|
|
|
int unix_nonblocking_connect(const char *str,
|
|
|
|
NonBlockingConnectHandler *callback,
|
|
|
|
void *opaque, Error **errp);
|
2008-11-11 20:46:40 +00:00
|
|
|
|
2012-10-23 19:31:53 +00:00
|
|
|
SocketAddress *socket_parse(const char *str, Error **errp);
|
|
|
|
int socket_connect(SocketAddress *addr, Error **errp,
|
|
|
|
NonBlockingConnectHandler *callback, void *opaque);
|
|
|
|
int socket_listen(SocketAddress *addr, Error **errp);
|
2013-02-27 13:10:47 +00:00
|
|
|
int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
|
2012-10-23 19:31:53 +00:00
|
|
|
|
2008-11-11 20:46:40 +00:00
|
|
|
/* Old, ipv4 only bits. Don't use for new code. */
|
2008-10-13 03:12:02 +00:00
|
|
|
int parse_host_port(struct sockaddr_in *saddr, const char *str);
|
2010-04-01 17:57:08 +00:00
|
|
|
int socket_init(void);
|
2006-04-30 22:53:25 +00:00
|
|
|
|
2015-05-01 16:36:20 +00:00
|
|
|
/**
|
|
|
|
* socket_local_address:
|
|
|
|
* @fd: the socket file handle
|
|
|
|
* @errp: pointer to uninitialized error object
|
|
|
|
*
|
|
|
|
* Get the string representation of the local socket
|
|
|
|
* address. A pointer to the allocated address information
|
|
|
|
* struct will be returned, which the caller is required to
|
|
|
|
* release with a call qapi_free_SocketAddress when no
|
|
|
|
* longer required.
|
|
|
|
*
|
|
|
|
* Returns: the socket address struct, or NULL on error
|
|
|
|
*/
|
|
|
|
SocketAddress *socket_local_address(int fd, Error **errp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* socket_remote_address:
|
|
|
|
* @fd: the socket file handle
|
|
|
|
* @errp: pointer to uninitialized error object
|
|
|
|
*
|
|
|
|
* Get the string representation of the remote socket
|
|
|
|
* address. A pointer to the allocated address information
|
|
|
|
* struct will be returned, which the caller is required to
|
|
|
|
* release with a call qapi_free_SocketAddress when no
|
|
|
|
* longer required.
|
|
|
|
*
|
|
|
|
* Returns: the socket address struct, or NULL on error
|
|
|
|
*/
|
|
|
|
SocketAddress *socket_remote_address(int fd, Error **errp);
|
|
|
|
|
2015-08-14 17:18:41 +00:00
|
|
|
|
|
|
|
void qapi_copy_SocketAddress(SocketAddress **p_dest,
|
|
|
|
SocketAddress *src);
|
|
|
|
|
2006-04-30 22:53:25 +00:00
|
|
|
#endif /* QEMU_SOCKET_H */
|