]>
Commit | Line | Data |
---|---|---|
6ca957f0 | 1 | /* headers to use the BSD sockets */ |
121d0712 MA |
2 | |
3 | #ifndef QEMU_SOCKETS_H | |
4 | #define QEMU_SOCKETS_H | |
6ca957f0 FB |
5 | |
6 | #ifdef _WIN32 | |
6ca957f0 | 7 | |
03ff3ca3 AL |
8 | int inet_aton(const char *cp, struct in_addr *ia); |
9 | ||
6ca957f0 FB |
10 | #endif /* !_WIN32 */ |
11 | ||
9af23989 | 12 | #include "qapi/qapi-types-sockets.h" |
2af2bf67 | 13 | |
d247d25f | 14 | /* misc helpers */ |
58dc31f1 | 15 | bool fd_is_socket(int fd); |
40ff6d7e | 16 | int qemu_socket(int domain, int type, int protocol); |
3c63b4e9 GT |
17 | |
18 | #ifndef WIN32 | |
19 | /** | |
20 | * qemu_socketpair: | |
21 | * @domain: specifies a communication domain, such as PF_UNIX | |
22 | * @type: specifies the socket type. | |
23 | * @protocol: specifies a particular protocol to be used with the socket | |
24 | * @sv: an array to store the pair of socket created | |
25 | * | |
26 | * Creates an unnamed pair of connected sockets in the specified domain, | |
27 | * of the specified type, and using the optionally specified protocol. | |
28 | * And automatically set the close-on-exec flags on the returned sockets | |
29 | * | |
30 | * Return 0 on success. | |
31 | */ | |
32 | int qemu_socketpair(int domain, int type, int protocol, int sv[2]); | |
33 | #endif | |
34 | ||
40ff6d7e | 35 | int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); |
128aa589 | 36 | int socket_set_cork(int fd, int v); |
bf1c852a | 37 | int socket_set_nodelay(int fd); |
ff5927ba MAL |
38 | void qemu_socket_set_block(int fd); |
39 | int qemu_socket_try_set_nonblock(int fd); | |
40 | void qemu_socket_set_nonblock(int fd); | |
606600a1 | 41 | int socket_set_fast_reuse(int fd); |
d247d25f | 42 | |
e1a8c9b6 DDAG |
43 | #ifdef WIN32 |
44 | /* Windows has different names for the same constants with the same values */ | |
45 | #define SHUT_RD 0 | |
46 | #define SHUT_WR 1 | |
47 | #define SHUT_RDWR 2 | |
48 | #endif | |
49 | ||
c1b412f1 DB |
50 | int inet_ai_family_from_address(InetSocketAddress *addr, |
51 | Error **errp); | |
0785bd7a | 52 | int inet_parse(InetSocketAddress *addr, const char *str, Error **errp); |
5db5f44c | 53 | int inet_connect(const char *str, Error **errp); |
b2587932 | 54 | int inet_connect_saddr(InetSocketAddress *saddr, Error **errp); |
233aa5c2 | 55 | |
a589569f | 56 | NetworkAddressFamily inet_netfamily(int family); |
d247d25f | 57 | |
62473511 | 58 | int unix_listen(const char *path, Error **errp); |
7fc4e63e | 59 | int unix_connect(const char *path, Error **errp); |
d247d25f | 60 | |
bd269ebc | 61 | SocketAddress *socket_parse(const char *str, Error **errp); |
b2587932 | 62 | int socket_connect(SocketAddress *addr, Error **errp); |
e5b6353c | 63 | int socket_listen(SocketAddress *addr, int num, Error **errp); |
74b6ce43 | 64 | void socket_listen_cleanup(int fd, Error **errp); |
bd269ebc | 65 | int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); |
101f9cbc | 66 | |
d247d25f | 67 | /* Old, ipv4 only bits. Don't use for new code. */ |
bcd4dfd6 MZ |
68 | int parse_host_port(struct sockaddr_in *saddr, const char *str, |
69 | Error **errp); | |
0706a4dc | 70 | int socket_init(void); |
6ca957f0 | 71 | |
559607ea DB |
72 | /** |
73 | * socket_sockaddr_to_address: | |
74 | * @sa: socket address struct | |
75 | * @salen: size of @sa struct | |
76 | * @errp: pointer to uninitialized error object | |
77 | * | |
78 | * Get the string representation of the socket | |
79 | * address. A pointer to the allocated address information | |
80 | * struct will be returned, which the caller is required to | |
bd269ebc | 81 | * release with a call qapi_free_SocketAddress() when no |
559607ea DB |
82 | * longer required. |
83 | * | |
84 | * Returns: the socket address struct, or NULL on error | |
85 | */ | |
bd269ebc | 86 | SocketAddress * |
559607ea DB |
87 | socket_sockaddr_to_address(struct sockaddr_storage *sa, |
88 | socklen_t salen, | |
89 | Error **errp); | |
90 | ||
17c55dec DB |
91 | /** |
92 | * socket_local_address: | |
93 | * @fd: the socket file handle | |
94 | * @errp: pointer to uninitialized error object | |
95 | * | |
96 | * Get the string representation of the local socket | |
97 | * address. A pointer to the allocated address information | |
98 | * struct will be returned, which the caller is required to | |
bd269ebc | 99 | * release with a call qapi_free_SocketAddress() when no |
17c55dec DB |
100 | * longer required. |
101 | * | |
102 | * Returns: the socket address struct, or NULL on error | |
103 | */ | |
bd269ebc | 104 | SocketAddress *socket_local_address(int fd, Error **errp); |
17c55dec DB |
105 | |
106 | /** | |
107 | * socket_remote_address: | |
108 | * @fd: the socket file handle | |
109 | * @errp: pointer to uninitialized error object | |
110 | * | |
111 | * Get the string representation of the remote socket | |
112 | * address. A pointer to the allocated address information | |
113 | * struct will be returned, which the caller is required to | |
bd269ebc | 114 | * release with a call qapi_free_SocketAddress() when no |
17c55dec DB |
115 | * longer required. |
116 | * | |
117 | * Returns: the socket address struct, or NULL on error | |
118 | */ | |
bd269ebc | 119 | SocketAddress *socket_remote_address(int fd, Error **errp); |
17c55dec | 120 | |
bd269ebc MA |
121 | /** |
122 | * socket_address_flatten: | |
123 | * @addr: the socket address to flatten | |
124 | * | |
125 | * Convert SocketAddressLegacy to SocketAddress. Caller is responsible | |
126 | * for freeing with qapi_free_SocketAddress(). | |
127 | * | |
128 | * Returns: the argument converted to SocketAddress. | |
129 | */ | |
130 | SocketAddress *socket_address_flatten(SocketAddressLegacy *addr); | |
131 | ||
c5423704 VSO |
132 | /** |
133 | * socket_address_parse_named_fd: | |
134 | * | |
135 | * Modify @addr, replacing a named fd by its corresponding number. | |
136 | * Needed for callers that plan to pass @addr to a context where the | |
137 | * current monitor is not available. | |
138 | * | |
139 | * Return 0 on success. | |
140 | */ | |
141 | int socket_address_parse_named_fd(SocketAddress *addr, Error **errp); | |
142 | ||
121d0712 | 143 | #endif /* QEMU_SOCKETS_H */ |