]>
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 KW |
16 | int qemu_socket(int domain, int type, int protocol); |
17 | int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); | |
128aa589 | 18 | int socket_set_cork(int fd, int v); |
bf1c852a | 19 | int socket_set_nodelay(int fd); |
f9e8cacc SH |
20 | void qemu_set_block(int fd); |
21 | void qemu_set_nonblock(int fd); | |
606600a1 | 22 | int socket_set_fast_reuse(int fd); |
d247d25f | 23 | |
e1a8c9b6 DDAG |
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 | ||
c1b412f1 DB |
31 | int inet_ai_family_from_address(InetSocketAddress *addr, |
32 | Error **errp); | |
0785bd7a | 33 | int inet_parse(InetSocketAddress *addr, const char *str, Error **errp); |
5db5f44c | 34 | int inet_connect(const char *str, Error **errp); |
b2587932 | 35 | int inet_connect_saddr(InetSocketAddress *saddr, Error **errp); |
233aa5c2 | 36 | |
a589569f | 37 | NetworkAddressFamily inet_netfamily(int family); |
d247d25f | 38 | |
62473511 | 39 | int unix_listen(const char *path, Error **errp); |
7fc4e63e | 40 | int unix_connect(const char *path, Error **errp); |
d247d25f | 41 | |
bd269ebc | 42 | SocketAddress *socket_parse(const char *str, Error **errp); |
b2587932 | 43 | int socket_connect(SocketAddress *addr, Error **errp); |
bd269ebc | 44 | int socket_listen(SocketAddress *addr, Error **errp); |
74b6ce43 | 45 | void socket_listen_cleanup(int fd, Error **errp); |
bd269ebc | 46 | int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); |
101f9cbc | 47 | |
d247d25f | 48 | /* Old, ipv4 only bits. Don't use for new code. */ |
bcd4dfd6 MZ |
49 | int parse_host_port(struct sockaddr_in *saddr, const char *str, |
50 | Error **errp); | |
0706a4dc | 51 | int socket_init(void); |
6ca957f0 | 52 | |
559607ea DB |
53 | /** |
54 | * socket_sockaddr_to_address: | |
55 | * @sa: socket address struct | |
56 | * @salen: size of @sa struct | |
57 | * @errp: pointer to uninitialized error object | |
58 | * | |
59 | * Get the string representation of the socket | |
60 | * address. A pointer to the allocated address information | |
61 | * struct will be returned, which the caller is required to | |
bd269ebc | 62 | * release with a call qapi_free_SocketAddress() when no |
559607ea DB |
63 | * longer required. |
64 | * | |
65 | * Returns: the socket address struct, or NULL on error | |
66 | */ | |
bd269ebc | 67 | SocketAddress * |
559607ea DB |
68 | socket_sockaddr_to_address(struct sockaddr_storage *sa, |
69 | socklen_t salen, | |
70 | Error **errp); | |
71 | ||
17c55dec DB |
72 | /** |
73 | * socket_local_address: | |
74 | * @fd: the socket file handle | |
75 | * @errp: pointer to uninitialized error object | |
76 | * | |
77 | * Get the string representation of the local socket | |
78 | * address. A pointer to the allocated address information | |
79 | * struct will be returned, which the caller is required to | |
bd269ebc | 80 | * release with a call qapi_free_SocketAddress() when no |
17c55dec DB |
81 | * longer required. |
82 | * | |
83 | * Returns: the socket address struct, or NULL on error | |
84 | */ | |
bd269ebc | 85 | SocketAddress *socket_local_address(int fd, Error **errp); |
17c55dec DB |
86 | |
87 | /** | |
88 | * socket_remote_address: | |
89 | * @fd: the socket file handle | |
90 | * @errp: pointer to uninitialized error object | |
91 | * | |
92 | * Get the string representation of the remote socket | |
93 | * address. A pointer to the allocated address information | |
94 | * struct will be returned, which the caller is required to | |
bd269ebc | 95 | * release with a call qapi_free_SocketAddress() when no |
17c55dec DB |
96 | * longer required. |
97 | * | |
98 | * Returns: the socket address struct, or NULL on error | |
99 | */ | |
bd269ebc | 100 | SocketAddress *socket_remote_address(int fd, Error **errp); |
17c55dec | 101 | |
bd269ebc MA |
102 | /** |
103 | * socket_address_flatten: | |
104 | * @addr: the socket address to flatten | |
105 | * | |
106 | * Convert SocketAddressLegacy to SocketAddress. Caller is responsible | |
107 | * for freeing with qapi_free_SocketAddress(). | |
108 | * | |
109 | * Returns: the argument converted to SocketAddress. | |
110 | */ | |
111 | SocketAddress *socket_address_flatten(SocketAddressLegacy *addr); | |
112 | ||
121d0712 | 113 | #endif /* QEMU_SOCKETS_H */ |