return "unknown";
}
-int inet_listen_opts(QemuOpts *opts, int port_offset)
+int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
{
struct addrinfo ai,*res,*e;
const char *addr;
if ((qemu_opt_get(opts, "host") == NULL) ||
(qemu_opt_get(opts, "port") == NULL)) {
fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
return -1;
}
pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
if (rc != 0) {
fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
gai_strerror(rc));
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
return -1;
}
if (slisten < 0) {
fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family), strerror(errno));
+ if (!e->ai_next) {
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
+ }
continue;
}
fprintf(stderr,"%s: bind(%s,%s,%d): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family), uaddr, inet_getport(e),
strerror(errno));
+ if (!e->ai_next) {
+ error_set(errp, QERR_SOCKET_BIND_FAILED);
+ }
}
}
closesocket(slisten);
listen:
if (listen(slisten,1) != 0) {
+ error_set(errp, QERR_SOCKET_LISTEN_FAILED);
perror("listen");
closesocket(slisten);
freeaddrinfo(res);
}
int inet_listen(const char *str, char *ostr, int olen,
- int socktype, int port_offset)
+ int socktype, int port_offset, Error **errp)
{
QemuOpts *opts;
char *optstr;
opts = qemu_opts_create(&dummy_opts, NULL, 0);
if (inet_parse(opts, str) == 0) {
- sock = inet_listen_opts(opts, port_offset);
+ sock = inet_listen_opts(opts, port_offset, errp);
if (sock != -1 && ostr) {
optstr = strchr(str, ',');
if (qemu_opt_get_bool(opts, "ipv6", 0)) {
optstr ? optstr : "");
}
}
+ } else {
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
}
qemu_opts_del(opts);
return sock;
int send_all(int fd, const void *buf, int len1);
/* New, ipv6-ready socket helper functions, see qemu-sockets.c */
-int inet_listen_opts(QemuOpts *opts, int port_offset);
+int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
int inet_listen(const char *str, char *ostr, int olen,
- int socktype, int port_offset);
+ int socktype, int port_offset, Error **errp);
int inet_connect_opts(QemuOpts *opts, Error **errp);
int inet_connect(const char *str, bool block, Error **errp);
int inet_dgram_opts(QemuOpts *opts);
pstrcpy(dpy, 256, "unix:");
vs->lsock = unix_listen(display+5, dpy+5, 256-5);
} else {
- vs->lsock = inet_listen(display, dpy, 256, SOCK_STREAM, 5900);
+ vs->lsock = inet_listen(display, dpy, 256,
+ SOCK_STREAM, 5900, NULL);
}
if (-1 == vs->lsock) {
g_free(dpy);