qemu/include/qemu/sockets.h
<<
>>
Prefs
   1/* headers to use the BSD sockets */
   2#ifndef QEMU_SOCKET_H
   3#define QEMU_SOCKET_H
   4
   5#ifdef _WIN32
   6
   7int inet_aton(const char *cp, struct in_addr *ia);
   8
   9#endif /* !_WIN32 */
  10
  11#include "qapi-types.h"
  12
  13/* misc helpers */
  14int qemu_socket(int domain, int type, int protocol);
  15int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
  16ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags);
  17ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags);
  18int socket_set_cork(int fd, int v);
  19int socket_set_nodelay(int fd);
  20void qemu_set_block(int fd);
  21void qemu_set_nonblock(int fd);
  22int socket_set_fast_reuse(int fd);
  23
  24#ifdef WIN32
  25/* Windows has different names for the same constants with the same values */
  26#define SHUT_RD   0
  27#define SHUT_WR   1
  28#define SHUT_RDWR 2
  29#endif
  30
  31/* callback function for nonblocking connect
  32 * valid fd on success, negative error code on failure
  33 */
  34typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque);
  35
  36InetSocketAddress *inet_parse(const char *str, Error **errp);
  37int inet_listen(const char *str, char *ostr, int olen,
  38                int socktype, int port_offset, Error **errp);
  39int inet_connect(const char *str, Error **errp);
  40int inet_nonblocking_connect(const char *str,
  41                             NonBlockingConnectHandler *callback,
  42                             void *opaque, Error **errp);
  43
  44NetworkAddressFamily inet_netfamily(int family);
  45
  46int unix_listen(const char *path, char *ostr, int olen, Error **errp);
  47int unix_connect(const char *path, Error **errp);
  48int unix_nonblocking_connect(const char *str,
  49                             NonBlockingConnectHandler *callback,
  50                             void *opaque, Error **errp);
  51
  52SocketAddress *socket_parse(const char *str, Error **errp);
  53int socket_connect(SocketAddress *addr, Error **errp,
  54                   NonBlockingConnectHandler *callback, void *opaque);
  55int socket_listen(SocketAddress *addr, Error **errp);
  56int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
  57
  58/* Old, ipv4 only bits.  Don't use for new code. */
  59int parse_host_port(struct sockaddr_in *saddr, const char *str);
  60int socket_init(void);
  61
  62/**
  63 * socket_sockaddr_to_address:
  64 * @sa: socket address struct
  65 * @salen: size of @sa struct
  66 * @errp: pointer to uninitialized error object
  67 *
  68 * Get the string representation of the socket
  69 * address. A pointer to the allocated address information
  70 * struct will be returned, which the caller is required to
  71 * release with a call qapi_free_SocketAddress when no
  72 * longer required.
  73 *
  74 * Returns: the socket address struct, or NULL on error
  75 */
  76SocketAddress *
  77socket_sockaddr_to_address(struct sockaddr_storage *sa,
  78                           socklen_t salen,
  79                           Error **errp);
  80
  81/**
  82 * socket_local_address:
  83 * @fd: the socket file handle
  84 * @errp: pointer to uninitialized error object
  85 *
  86 * Get the string representation of the local socket
  87 * address. A pointer to the allocated address information
  88 * struct will be returned, which the caller is required to
  89 * release with a call qapi_free_SocketAddress when no
  90 * longer required.
  91 *
  92 * Returns: the socket address struct, or NULL on error
  93 */
  94SocketAddress *socket_local_address(int fd, Error **errp);
  95
  96/**
  97 * socket_remote_address:
  98 * @fd: the socket file handle
  99 * @errp: pointer to uninitialized error object
 100 *
 101 * Get the string representation of the remote socket
 102 * address. A pointer to the allocated address information
 103 * struct will be returned, which the caller is required to
 104 * release with a call qapi_free_SocketAddress when no
 105 * longer required.
 106 *
 107 * Returns: the socket address struct, or NULL on error
 108 */
 109SocketAddress *socket_remote_address(int fd, Error **errp);
 110
 111
 112void qapi_copy_SocketAddress(SocketAddress **p_dest,
 113                             SocketAddress *src);
 114
 115#endif /* QEMU_SOCKET_H */
 116