]>
Commit | Line | Data |
---|---|---|
6ca957f0 FB |
1 | /* headers to use the BSD sockets */ |
2 | #ifndef QEMU_SOCKET_H | |
3 | #define QEMU_SOCKET_H | |
4 | ||
5 | #ifdef _WIN32 | |
6ca957f0 | 6 | |
03ff3ca3 AL |
7 | int inet_aton(const char *cp, struct in_addr *ia); |
8 | ||
6ca957f0 FB |
9 | #endif /* !_WIN32 */ |
10 | ||
a589569f | 11 | #include "qapi-types.h" |
2af2bf67 | 12 | |
d247d25f | 13 | /* misc helpers */ |
40ff6d7e KW |
14 | int qemu_socket(int domain, int type, int protocol); |
15 | int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); | |
128aa589 | 16 | int socket_set_cork(int fd, int v); |
bf1c852a | 17 | int socket_set_nodelay(int fd); |
f9e8cacc SH |
18 | void qemu_set_block(int fd); |
19 | void qemu_set_nonblock(int fd); | |
606600a1 | 20 | int socket_set_fast_reuse(int fd); |
d247d25f | 21 | |
e1a8c9b6 DDAG |
22 | #ifdef WIN32 |
23 | /* Windows has different names for the same constants with the same values */ | |
24 | #define SHUT_RD 0 | |
25 | #define SHUT_WR 1 | |
26 | #define SHUT_RDWR 2 | |
27 | #endif | |
28 | ||
233aa5c2 OW |
29 | /* callback function for nonblocking connect |
30 | * valid fd on success, negative error code on failure | |
31 | */ | |
533fdaed | 32 | typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque); |
233aa5c2 | 33 | |
f17c90be | 34 | InetSocketAddress *inet_parse(const char *str, Error **errp); |
d247d25f | 35 | int inet_listen(const char *str, char *ostr, int olen, |
029409e5 | 36 | int socktype, int port_offset, Error **errp); |
5db5f44c | 37 | int inet_connect(const char *str, Error **errp); |
233aa5c2 OW |
38 | int inet_nonblocking_connect(const char *str, |
39 | NonBlockingConnectHandler *callback, | |
40 | void *opaque, Error **errp); | |
41 | ||
a589569f | 42 | NetworkAddressFamily inet_netfamily(int family); |
d247d25f | 43 | |
7fc4e63e | 44 | int unix_listen(const char *path, char *ostr, int olen, Error **errp); |
7fc4e63e | 45 | int unix_connect(const char *path, Error **errp); |
1fc05adf PB |
46 | int unix_nonblocking_connect(const char *str, |
47 | NonBlockingConnectHandler *callback, | |
48 | void *opaque, Error **errp); | |
d247d25f | 49 | |
101f9cbc PB |
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); | |
3ecc059d | 54 | int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); |
101f9cbc | 55 | |
d247d25f | 56 | /* Old, ipv4 only bits. Don't use for new code. */ |
5bb7910a | 57 | int parse_host_port(struct sockaddr_in *saddr, const char *str); |
0706a4dc | 58 | int socket_init(void); |
6ca957f0 | 59 | |
559607ea DB |
60 | /** |
61 | * socket_sockaddr_to_address: | |
62 | * @sa: socket address struct | |
63 | * @salen: size of @sa struct | |
64 | * @errp: pointer to uninitialized error object | |
65 | * | |
66 | * Get the string representation of the socket | |
67 | * address. A pointer to the allocated address information | |
68 | * struct will be returned, which the caller is required to | |
69 | * release with a call qapi_free_SocketAddress when no | |
70 | * longer required. | |
71 | * | |
72 | * Returns: the socket address struct, or NULL on error | |
73 | */ | |
74 | SocketAddress * | |
75 | socket_sockaddr_to_address(struct sockaddr_storage *sa, | |
76 | socklen_t salen, | |
77 | Error **errp); | |
78 | ||
17c55dec DB |
79 | /** |
80 | * socket_local_address: | |
81 | * @fd: the socket file handle | |
82 | * @errp: pointer to uninitialized error object | |
83 | * | |
84 | * Get the string representation of the local socket | |
85 | * address. A pointer to the allocated address information | |
86 | * struct will be returned, which the caller is required to | |
87 | * release with a call qapi_free_SocketAddress when no | |
88 | * longer required. | |
89 | * | |
90 | * Returns: the socket address struct, or NULL on error | |
91 | */ | |
92 | SocketAddress *socket_local_address(int fd, Error **errp); | |
93 | ||
94 | /** | |
95 | * socket_remote_address: | |
96 | * @fd: the socket file handle | |
97 | * @errp: pointer to uninitialized error object | |
98 | * | |
99 | * Get the string representation of the remote socket | |
100 | * address. A pointer to the allocated address information | |
101 | * struct will be returned, which the caller is required to | |
102 | * release with a call qapi_free_SocketAddress when no | |
103 | * longer required. | |
104 | * | |
105 | * Returns: the socket address struct, or NULL on error | |
106 | */ | |
107 | SocketAddress *socket_remote_address(int fd, Error **errp); | |
108 | ||
2a8e21c7 DB |
109 | |
110 | void qapi_copy_SocketAddress(SocketAddress **p_dest, | |
111 | SocketAddress *src); | |
112 | ||
6ca957f0 | 113 | #endif /* QEMU_SOCKET_H */ |