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