qemu/include/qemu/sockets.h
<<
>>
Prefs
   1/* headers to use the BSD sockets */
   2
   3#ifndef QEMU_SOCKETS_H
   4#define QEMU_SOCKETS_H
   5
   6#ifdef _WIN32
   7
   8int inet_aton(const char *cp, struct in_addr *ia);
   9
  10#endif /* !_WIN32 */
  11
  12#include "qapi/qapi-types-sockets.h"
  13
  14/* misc helpers */
  15bool fd_is_socket(int fd);
  16int qemu_socket(int domain, int type, int protocol);
  17
  18/**
  19 * qemu_socketpair:
  20 * @domain: specifies a communication domain, such as PF_UNIX
  21 * @type: specifies the socket type.
  22 * @protocol: specifies a particular protocol to be used with the  socket
  23 * @sv: an array to store the pair of socket created
  24 *
  25 * Creates an unnamed pair of connected sockets in the specified domain,
  26 * of the specified type, and using the optionally specified protocol.
  27 * And automatically set the close-on-exec flags on the returned sockets
  28 *
  29 * Return 0 on success.
  30 */
  31int qemu_socketpair(int domain, int type, int protocol, int sv[2]);
  32
  33int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
  34/*
  35 * A variant of send(2) which handles partial send.
  36 *
  37 * Return the number of bytes transferred over the socket.
  38 * Set errno if fewer than `count' bytes are sent.
  39 *
  40 * This function don't work with non-blocking socket's.
  41 * Any of the possibilities with non-blocking socket's is bad:
  42 *   - return a short write (then name is wrong)
  43 *   - busy wait adding (errno == EAGAIN) to the loop
  44 */
  45ssize_t qemu_send_full(int s, const void *buf, size_t count)
  46    G_GNUC_WARN_UNUSED_RESULT;
  47int socket_set_cork(int fd, int v);
  48int socket_set_nodelay(int fd);
  49void qemu_socket_set_block(int fd);
  50int qemu_socket_try_set_nonblock(int fd);
  51void qemu_socket_set_nonblock(int fd);
  52int socket_set_fast_reuse(int fd);
  53
  54#ifdef WIN32
  55/* Windows has different names for the same constants with the same values */
  56#define SHUT_RD   0
  57#define SHUT_WR   1
  58#define SHUT_RDWR 2
  59#endif
  60
  61int inet_ai_family_from_address(InetSocketAddress *addr,
  62                                Error **errp);
  63int inet_parse(InetSocketAddress *addr, const char *str, Error **errp);
  64int inet_connect_saddr(InetSocketAddress *saddr, Error **errp);
  65
  66NetworkAddressFamily inet_netfamily(int family);
  67
  68int unix_listen(const char *path, Error **errp);
  69int unix_connect(const char *path, Error **errp);
  70
  71char *socket_uri(SocketAddress *addr);
  72SocketAddress *socket_parse(const char *str, Error **errp);
  73int socket_connect(SocketAddress *addr, Error **errp);
  74int socket_listen(SocketAddress *addr, int num, Error **errp);
  75void socket_listen_cleanup(int fd, Error **errp);
  76int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
  77
  78/* Old, ipv4 only bits.  Don't use for new code. */
  79int convert_host_port(struct sockaddr_in *saddr, const char *host,
  80                      const char *port, Error **errp);
  81int parse_host_port(struct sockaddr_in *saddr, const char *str,
  82                    Error **errp);
  83int socket_init(void);
  84
  85/**
  86 * socket_sockaddr_to_address:
  87 * @sa: socket address struct
  88 * @salen: size of @sa struct
  89 * @errp: pointer to uninitialized error object
  90 *
  91 * Get the string representation of the socket
  92 * address. A pointer to the allocated address information
  93 * struct will be returned, which the caller is required to
  94 * release with a call qapi_free_SocketAddress() when no
  95 * longer required.
  96 *
  97 * Returns: the socket address struct, or NULL on error
  98 */
  99SocketAddress *
 100socket_sockaddr_to_address(struct sockaddr_storage *sa,
 101                           socklen_t salen,
 102                           Error **errp);
 103
 104/**
 105 * socket_local_address:
 106 * @fd: the socket file handle
 107 * @errp: pointer to uninitialized error object
 108 *
 109 * Get the string representation of the local socket
 110 * address. A pointer to the allocated address information
 111 * struct will be returned, which the caller is required to
 112 * release with a call qapi_free_SocketAddress() when no
 113 * longer required.
 114 *
 115 * Returns: the socket address struct, or NULL on error
 116 */
 117SocketAddress *socket_local_address(int fd, Error **errp);
 118
 119/**
 120 * socket_address_flatten:
 121 * @addr: the socket address to flatten
 122 *
 123 * Convert SocketAddressLegacy to SocketAddress.  Caller is responsible
 124 * for freeing with qapi_free_SocketAddress().
 125 *
 126 * Returns: the argument converted to SocketAddress.
 127 */
 128SocketAddress *socket_address_flatten(SocketAddressLegacy *addr);
 129
 130/**
 131 * socket_address_parse_named_fd:
 132 *
 133 * Modify @addr, replacing a named fd by its corresponding number.
 134 * Needed for callers that plan to pass @addr to a context where the
 135 * current monitor is not available.
 136 *
 137 * Return 0 on success.
 138 */
 139int socket_address_parse_named_fd(SocketAddress *addr, Error **errp);
 140#endif /* QEMU_SOCKETS_H */
 141