Revision 537b41f5 qemu-nbd.c
b/qemu-nbd.c | ||
---|---|---|
20 | 20 |
#include "block/block.h" |
21 | 21 |
#include "block/nbd.h" |
22 | 22 |
#include "qemu/main-loop.h" |
23 |
#include "qemu/sockets.h" |
|
24 |
#include "qemu/error-report.h" |
|
23 | 25 |
#include "block/snapshot.h" |
24 | 26 |
|
25 | 27 |
#include <stdarg.h> |
... | ... | |
201 | 203 |
qemu_notify_event(); |
202 | 204 |
} |
203 | 205 |
|
206 |
static void combine_addr(char *buf, size_t len, const char* address, |
|
207 |
uint16_t port) |
|
208 |
{ |
|
209 |
/* If the address-part contains a colon, it's an IPv6 IP so needs [] */ |
|
210 |
if (strstr(address, ":")) { |
|
211 |
snprintf(buf, len, "[%s]:%u", address, port); |
|
212 |
} else { |
|
213 |
snprintf(buf, len, "%s:%u", address, port); |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
static int tcp_socket_incoming(const char *address, uint16_t port) |
|
218 |
{ |
|
219 |
char address_and_port[128]; |
|
220 |
Error *local_err = NULL; |
|
221 |
|
|
222 |
combine_addr(address_and_port, 128, address, port); |
|
223 |
int fd = inet_listen(address_and_port, NULL, 0, SOCK_STREAM, 0, &local_err); |
|
224 |
|
|
225 |
if (local_err != NULL) { |
|
226 |
qerror_report_err(local_err); |
|
227 |
error_free(local_err); |
|
228 |
} |
|
229 |
return fd; |
|
230 |
} |
|
231 |
|
|
232 |
static int unix_socket_incoming(const char *path) |
|
233 |
{ |
|
234 |
Error *local_err = NULL; |
|
235 |
int fd = unix_listen(path, NULL, 0, &local_err); |
|
236 |
|
|
237 |
if (local_err != NULL) { |
|
238 |
qerror_report_err(local_err); |
|
239 |
error_free(local_err); |
|
240 |
} |
|
241 |
return fd; |
|
242 |
} |
|
243 |
|
|
244 |
static int unix_socket_outgoing(const char *path) |
|
245 |
{ |
|
246 |
Error *local_err = NULL; |
|
247 |
int fd = unix_connect(path, &local_err); |
|
248 |
|
|
249 |
if (local_err != NULL) { |
|
250 |
qerror_report_err(local_err); |
|
251 |
error_free(local_err); |
|
252 |
} |
|
253 |
return fd; |
|
254 |
} |
|
255 |
|
|
204 | 256 |
static void *show_parts(void *arg) |
205 | 257 |
{ |
206 | 258 |
char *device = arg; |
Also available in: Unified diff