1 /* headers to use the BSD sockets */
7 int inet_aton(const char *cp
, struct in_addr
*ia
);
11 #include "qapi-types.h"
14 int qemu_socket(int domain
, int type
, int protocol
);
15 int qemu_accept(int s
, struct sockaddr
*addr
, socklen_t
*addrlen
);
16 int socket_set_cork(int fd
, int v
);
17 int socket_set_nodelay(int fd
);
18 void qemu_set_block(int fd
);
19 void qemu_set_nonblock(int fd
);
20 int socket_set_fast_reuse(int fd
);
23 /* Windows has different names for the same constants with the same values */
29 /* callback function for nonblocking connect
30 * valid fd on success, negative error code on failure
32 typedef void NonBlockingConnectHandler(int fd
, Error
*err
, void *opaque
);
34 InetSocketAddress
*inet_parse(const char *str
, Error
**errp
);
35 int inet_listen(const char *str
, char *ostr
, int olen
,
36 int socktype
, int port_offset
, Error
**errp
);
37 int inet_connect(const char *str
, Error
**errp
);
38 int inet_nonblocking_connect(const char *str
,
39 NonBlockingConnectHandler
*callback
,
40 void *opaque
, Error
**errp
);
42 NetworkAddressFamily
inet_netfamily(int family
);
44 int unix_listen(const char *path
, char *ostr
, int olen
, Error
**errp
);
45 int unix_connect(const char *path
, Error
**errp
);
46 int unix_nonblocking_connect(const char *str
,
47 NonBlockingConnectHandler
*callback
,
48 void *opaque
, Error
**errp
);
50 SocketAddress
*socket_parse(const char *str
, Error
**errp
);
51 int socket_connect(SocketAddress
*addr
, Error
**errp
,
52 NonBlockingConnectHandler
*callback
, void *opaque
);
53 int socket_listen(SocketAddress
*addr
, Error
**errp
);
54 void socket_listen_cleanup(int fd
, Error
**errp
);
55 int socket_dgram(SocketAddress
*remote
, SocketAddress
*local
, Error
**errp
);
57 /* Old, ipv4 only bits. Don't use for new code. */
58 int parse_host_port(struct sockaddr_in
*saddr
, const char *str
);
59 int socket_init(void);
62 * socket_sockaddr_to_address:
63 * @sa: socket address struct
64 * @salen: size of @sa struct
65 * @errp: pointer to uninitialized error object
67 * Get the string representation of the socket
68 * address. A pointer to the allocated address information
69 * struct will be returned, which the caller is required to
70 * release with a call qapi_free_SocketAddress when no
73 * Returns: the socket address struct, or NULL on error
76 socket_sockaddr_to_address(struct sockaddr_storage
*sa
,
81 * socket_local_address:
82 * @fd: the socket file handle
83 * @errp: pointer to uninitialized error object
85 * Get the string representation of the local socket
86 * address. A pointer to the allocated address information
87 * struct will be returned, which the caller is required to
88 * release with a call qapi_free_SocketAddress when no
91 * Returns: the socket address struct, or NULL on error
93 SocketAddress
*socket_local_address(int fd
, Error
**errp
);
96 * socket_remote_address:
97 * @fd: the socket file handle
98 * @errp: pointer to uninitialized error object
100 * Get the string representation of the remote socket
101 * address. A pointer to the allocated address information
102 * struct will be returned, which the caller is required to
103 * release with a call qapi_free_SocketAddress when no
106 * Returns: the socket address struct, or NULL on error
108 SocketAddress
*socket_remote_address(int fd
, Error
**errp
);
111 * socket_address_to_string:
112 * @addr: the socket address struct
113 * @errp: pointer to uninitialized error object
115 * Get the string representation of the socket
116 * address. A pointer to the char array containing
117 * string format will be returned, the caller is
118 * required to release the returned value when no
119 * longer required with g_free.
121 * Returns: the socket address in string format, or NULL on error
123 char *socket_address_to_string(struct SocketAddress
*addr
, Error
**errp
);
124 #endif /* QEMU_SOCKET_H */