1 /* headers to use the BSD sockets */
8 int inet_aton(const char *cp
, struct in_addr
*ia
);
12 #include "qapi-types.h"
15 int qemu_socket(int domain
, int type
, int protocol
);
16 int qemu_accept(int s
, struct sockaddr
*addr
, socklen_t
*addrlen
);
17 int socket_set_cork(int fd
, int v
);
18 int socket_set_nodelay(int fd
);
19 void qemu_set_block(int fd
);
20 void qemu_set_nonblock(int fd
);
21 int socket_set_fast_reuse(int fd
);
24 /* Windows has different names for the same constants with the same values */
30 /* callback function for nonblocking connect
31 * valid fd on success, negative error code on failure
33 typedef void NonBlockingConnectHandler(int fd
, Error
*err
, void *opaque
);
35 InetSocketAddress
*inet_parse(const char *str
, Error
**errp
);
36 int inet_listen(const char *str
, char *ostr
, int olen
,
37 int socktype
, int port_offset
, Error
**errp
);
38 int inet_connect(const char *str
, Error
**errp
);
39 int inet_nonblocking_connect(const char *str
,
40 NonBlockingConnectHandler
*callback
,
41 void *opaque
, Error
**errp
);
43 NetworkAddressFamily
inet_netfamily(int family
);
45 int unix_listen(const char *path
, char *ostr
, int olen
, Error
**errp
);
46 int unix_connect(const char *path
, Error
**errp
);
47 int unix_nonblocking_connect(const char *str
,
48 NonBlockingConnectHandler
*callback
,
49 void *opaque
, Error
**errp
);
51 SocketAddress
*socket_parse(const char *str
, Error
**errp
);
52 int socket_connect(SocketAddress
*addr
, Error
**errp
,
53 NonBlockingConnectHandler
*callback
, void *opaque
);
54 int socket_listen(SocketAddress
*addr
, Error
**errp
);
55 void socket_listen_cleanup(int fd
, Error
**errp
);
56 int socket_dgram(SocketAddress
*remote
, SocketAddress
*local
, Error
**errp
);
58 /* Old, ipv4 only bits. Don't use for new code. */
59 int parse_host_port(struct sockaddr_in
*saddr
, const char *str
);
60 int socket_init(void);
63 * socket_sockaddr_to_address:
64 * @sa: socket address struct
65 * @salen: size of @sa struct
66 * @errp: pointer to uninitialized error object
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
74 * Returns: the socket address struct, or NULL on error
77 socket_sockaddr_to_address(struct sockaddr_storage
*sa
,
82 * socket_local_address:
83 * @fd: the socket file handle
84 * @errp: pointer to uninitialized error object
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
92 * Returns: the socket address struct, or NULL on error
94 SocketAddress
*socket_local_address(int fd
, Error
**errp
);
97 * socket_remote_address:
98 * @fd: the socket file handle
99 * @errp: pointer to uninitialized error object
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
107 * Returns: the socket address struct, or NULL on error
109 SocketAddress
*socket_remote_address(int fd
, Error
**errp
);
112 * socket_address_to_string:
113 * @addr: the socket address struct
114 * @errp: pointer to uninitialized error object
116 * Get the string representation of the socket
117 * address. A pointer to the char array containing
118 * string format will be returned, the caller is
119 * required to release the returned value when no
120 * longer required with g_free.
122 * Returns: the socket address in string format, or NULL on error
124 char *socket_address_to_string(struct SocketAddress
*addr
, Error
**errp
);
126 #endif /* QEMU_SOCKETS_H */