本文整理汇总了C++中qemu_socket函数的典型用法代码示例。如果您正苦于以下问题:C++ qemu_socket函数的具体用法?C++ qemu_socket怎么用?C++ qemu_socket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qemu_socket函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: vsock_listen_saddr
static int vsock_listen_saddr(VsockSocketAddress *vaddr,
Error **errp)
{
struct sockaddr_vm svm;
int slisten;
if (!vsock_parse_vaddr_to_sockaddr(vaddr, &svm, errp)) {
return -1;
}
slisten = qemu_socket(AF_VSOCK, SOCK_STREAM, 0);
if (slisten < 0) {
error_setg_errno(errp, errno, "Failed to create socket");
return -1;
}
if (bind(slisten, (const struct sockaddr *)&svm, sizeof(svm)) != 0) {
error_setg_errno(errp, errno, "Failed to bind socket");
closesocket(slisten);
return -1;
}
if (listen(slisten, 1) != 0) {
error_setg_errno(errp, errno, "Failed to listen on socket");
closesocket(slisten);
return -1;
}
return slisten;
}
开发者ID:Marshalzxy,项目名称:qemu,代码行数:29,代码来源:qemu-sockets.c
示例2: unix_connect_opts
int unix_connect_opts(QemuOpts *opts)
{
struct sockaddr_un un;
const char *path = qemu_opt_get(opts, "path");
int sock;
if (NULL == path) {
fprintf(stderr, "unix connect: no path specified\n");
return -1;
}
sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
perror("socket(unix)");
return -1;
}
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
if (connect(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {
fprintf(stderr, "connect(unix:%s): %s\n", path, strerror(errno));
return -1;
}
if (sockets_debug)
fprintf(stderr, "connect(unix:%s): OK\n", path);
return sock;
}
开发者ID:16aug,项目名称:nvmeqemu,代码行数:29,代码来源:qemu-sockets.c
示例3: inet_connect_addr
static int inet_connect_addr(struct addrinfo *addr, Error **errp)
{
int sock, rc;
sock = qemu_socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (sock < 0) {
error_setg_errno(errp, errno, "Failed to create socket");
return -1;
}
socket_set_fast_reuse(sock);
/* connect to peer */
do {
rc = 0;
if (connect(sock, addr->ai_addr, addr->ai_addrlen) < 0) {
rc = -errno;
}
} while (rc == -EINTR);
if (rc < 0) {
error_setg_errno(errp, errno, "Failed to connect socket");
closesocket(sock);
return -1;
}
return sock;
}
开发者ID:Marshalzxy,项目名称:qemu,代码行数:27,代码来源:qemu-sockets.c
示例4: vsock_connect_addr
static int vsock_connect_addr(const struct sockaddr_vm *svm, Error **errp)
{
int sock, rc;
sock = qemu_socket(AF_VSOCK, SOCK_STREAM, 0);
if (sock < 0) {
error_setg_errno(errp, errno, "Failed to create socket");
return -1;
}
/* connect to peer */
do {
rc = 0;
if (connect(sock, (const struct sockaddr *)svm, sizeof(*svm)) < 0) {
rc = -errno;
}
} while (rc == -EINTR);
if (rc < 0) {
error_setg_errno(errp, errno, "Failed to connect socket");
closesocket(sock);
return -1;
}
return sock;
}
开发者ID:Marshalzxy,项目名称:qemu,代码行数:26,代码来源:qemu-sockets.c
示例5: vsock_connect_addr
static int vsock_connect_addr(const struct sockaddr_vm *svm, bool *in_progress,
ConnectState *connect_state, Error **errp)
{
int sock, rc;
*in_progress = false;
sock = qemu_socket(AF_VSOCK, SOCK_STREAM, 0);
if (sock < 0) {
error_setg_errno(errp, errno, "Failed to create socket");
return -1;
}
if (connect_state != NULL) {
qemu_set_nonblock(sock);
}
/* connect to peer */
do {
rc = 0;
if (connect(sock, (const struct sockaddr *)svm, sizeof(*svm)) < 0) {
rc = -errno;
}
} while (rc == -EINTR);
if (connect_state != NULL && QEMU_SOCKET_RC_INPROGRESS(rc)) {
connect_state->fd = sock;
qemu_set_fd_handler(sock, NULL, wait_for_connect, connect_state);
*in_progress = true;
} else if (rc < 0) {
error_setg_errno(errp, errno, "Failed to connect socket");
closesocket(sock);
return -1;
}
return sock;
}
开发者ID:m000,项目名称:panda,代码行数:34,代码来源:qemu-sockets.c
示例6: icmp_send
static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
{
struct ip *ip = mtod(m, struct ip *);
struct sockaddr_in addr;
so->s = qemu_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
if (so->s == -1) {
return -1;
}
so->so_m = m;
so->so_faddr = ip->ip_dst;
so->so_laddr = ip->ip_src;
so->so_iptos = ip->ip_tos;
so->so_type = IPPROTO_ICMP;
so->so_state = SS_ISFCONNECTED;
so->so_expire = curtime + SO_EXPIRE;
addr.sin_family = AF_INET;
addr.sin_addr = so->so_faddr;
insque(so, &so->slirp->icmp);
if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0,
(struct sockaddr *)&addr, sizeof(addr)) == -1) {
DEBUG_MISC((dfd, "icmp_input icmp sendto tx errno = %d-%s\n",
errno, strerror(errno)));
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
icmp_detach(so);
}
return 0;
}
开发者ID:0bliv10n,项目名称:s2e,代码行数:33,代码来源:ip_icmp.c
示例7: inet_connect_addr
static int inet_connect_addr(struct addrinfo *addr, bool *in_progress,
ConnectState *connect_state, Error **errp)
{
int sock, rc;
*in_progress = false;
sock = qemu_socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (sock < 0) {
error_setg_errno(errp, errno, "Failed to create socket");
return -1;
}
socket_set_fast_reuse(sock);
if (connect_state != NULL) {
qemu_set_nonblock(sock);
}
/* connect to peer */
do {
rc = 0;
if (connect(sock, addr->ai_addr, addr->ai_addrlen) < 0) {
rc = -errno;
}
} while (rc == -EINTR);
if (connect_state != NULL && QEMU_SOCKET_RC_INPROGRESS(rc)) {
connect_state->fd = sock;
qemu_set_fd_handler(sock, NULL, wait_for_connect, connect_state);
*in_progress = true;
} else if (rc < 0) {
error_setg_errno(errp, errno, "Failed to connect socket");
closesocket(sock);
return -1;
}
return sock;
}
开发者ID:m000,项目名称:panda,代码行数:35,代码来源:qemu-sockets.c
示例8: unix_connect_opts
int unix_connect_opts(QemuOpts *opts, Error **errp,
NonBlockingConnectHandler *callback, void *opaque)
{
struct sockaddr_un un;
const char *path = qemu_opt_get(opts, "path");
ConnectState *connect_state = NULL;
int sock, rc;
if (path == NULL) {
error_setg(errp, "unix connect: no path specified");
return -1;
}
sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
error_setg_errno(errp, errno, "Failed to create socket");
return -1;
}
if (callback != NULL) {
connect_state = g_malloc0(sizeof(*connect_state));
connect_state->callback = callback;
connect_state->opaque = opaque;
qemu_set_nonblock(sock);
}
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
/* connect to peer */
do {
rc = 0;
if (connect(sock, (struct sockaddr *) &un, sizeof(un)) < 0) {
rc = -socket_error();
}
} while (rc == -EINTR);
if (connect_state != NULL && QEMU_SOCKET_RC_INPROGRESS(rc)) {
connect_state->fd = sock;
qemu_set_fd_handler2(sock, NULL, NULL, wait_for_connect,
connect_state);
return sock;
} else if (rc >= 0) {
/* non blocking socket immediate success, call callback */
if (callback != NULL) {
callback(sock, NULL, opaque);
}
}
if (rc < 0) {
error_setg_errno(errp, -rc, "Failed to connect socket");
close(sock);
sock = -1;
}
g_free(connect_state);
return sock;
}
开发者ID:kashifqazi,项目名称:qemu,代码行数:58,代码来源:qemu-sockets.c
示例9: create_fast_reuse_socket
static int create_fast_reuse_socket(struct addrinfo *e)
{
int slisten = qemu_socket(e->ai_family, e->ai_socktype, e->ai_protocol);
if (slisten < 0) {
return -1;
}
socket_set_fast_reuse(slisten);
return slisten;
}
开发者ID:Marshalzxy,项目名称:qemu,代码行数:9,代码来源:qemu-sockets.c
示例10: udp_attach
int
udp_attach(struct socket *so)
{
if((so->s = qemu_socket(AF_INET,SOCK_DGRAM,0)) != -1) {
so->so_expire = curtime + SO_EXPIRE;
insque(so, &so->slirp->udb);
}
return(so->s);
}
开发者ID:AbnerChang,项目名称:RiscVQemuPcat,代码行数:9,代码来源:udp.c
示例11: net_socket_udp_init
static int net_socket_udp_init(NetClientState *peer,
const char *model,
const char *name,
const char *rhost,
const char *lhost)
{
NetSocketState *s;
int fd, val, ret;
struct sockaddr_in laddr, raddr;
if (parse_host_port(&laddr, lhost) < 0) {
return -1;
}
if (parse_host_port(&raddr, rhost) < 0) {
return -1;
}
fd = qemu_socket(PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
perror("socket(PF_INET, SOCK_DGRAM)");
return -1;
}
val = 1;
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
(const char *)&val, sizeof(val));
if (ret < 0) {
perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)");
closesocket(fd);
return -1;
}
ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
if (ret < 0) {
perror("bind");
closesocket(fd);
return -1;
}
s = net_socket_fd_init(peer, model, name, fd, 0);
if (!s) {
return -1;
}
s->dgram_dst = raddr;
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
"socket: udp=%s:%d",
inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
return 0;
}
开发者ID:AlexWWW,项目名称:qemu-linaro-clone,代码行数:50,代码来源:socket.c
示例12: net_socket_connect_init
static int net_socket_connect_init(NetClientState *peer,
const char *model,
const char *name,
const char *host_str)
{
NetSocketState *s;
int fd, connected, ret, err;
struct sockaddr_in saddr;
if (parse_host_port(&saddr, host_str) < 0)
return -1;
fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
return -1;
}
socket_set_nonblock(fd);
connected = 0;
for(;;) {
ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret < 0) {
err = socket_error();
if (err == EINTR || err == EWOULDBLOCK) {
} else if (err == EINPROGRESS) {
break;
#ifdef _WIN32
} else if (err == WSAEALREADY || err == WSAEINVAL) {
break;
#endif
} else {
perror("connect");
closesocket(fd);
return -1;
}
} else {
connected = 1;
break;
}
}
s = net_socket_fd_init(peer, model, name, fd, connected);
if (!s)
return -1;
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
"socket: connect to %s:%d",
inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
return 0;
}
开发者ID:AlexWWW,项目名称:qemu-linaro-clone,代码行数:49,代码来源:socket.c
示例13: unix_listen_opts
int unix_listen_opts(QemuOpts *opts)
{
struct sockaddr_un un;
const char *path = qemu_opt_get(opts, "path");
int sock, fd;
sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
perror("socket(unix)");
return -1;
}
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
if (path && strlen(path)) {
snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
} else {
char *tmpdir = getenv("TMPDIR");
snprintf(un.sun_path, sizeof(un.sun_path), "%s/qemu-socket-XXXXXX",
tmpdir ? tmpdir : "/tmp");
/*
* This dummy fd usage silences the mktemp() unsecure warning.
* Using mkstemp() doesn't make things more secure here
* though. bind() complains about existing files, so we have
* to unlink first and thus re-open the race window. The
* worst case possible is bind() failing, i.e. a DoS attack.
*/
fd = mkstemp(un.sun_path); close(fd);
qemu_opt_set(opts, "path", un.sun_path);
}
unlink(un.sun_path);
if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {
fprintf(stderr, "bind(unix:%s): %s\n", un.sun_path, strerror(errno));
goto err;
}
if (listen(sock, 1) < 0) {
fprintf(stderr, "listen(unix:%s): %s\n", un.sun_path, strerror(errno));
goto err;
}
if (sockets_debug)
fprintf(stderr, "bind(unix:%s): OK\n", un.sun_path);
return sock;
err:
closesocket(sock);
return -1;
}
开发者ID:16aug,项目名称:nvmeqemu,代码行数:49,代码来源:qemu-sockets.c
示例14: unix_connect_saddr
static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
{
struct sockaddr_un un;
int sock, rc;
size_t pathlen;
if (saddr->path == NULL) {
error_setg(errp, "unix connect: no path specified");
return -1;
}
sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
error_setg_errno(errp, errno, "Failed to create socket");
return -1;
}
pathlen = strlen(saddr->path);
if (pathlen > sizeof(un.sun_path)) {
error_setg(errp, "UNIX socket path '%s' is too long", saddr->path);
error_append_hint(errp, "Path must be less than %zu bytes\n",
sizeof(un.sun_path));
goto err;
}
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
memcpy(un.sun_path, saddr->path, pathlen);
/* connect to peer */
do {
rc = 0;
if (connect(sock, (struct sockaddr *) &un, sizeof(un)) < 0) {
rc = -errno;
}
} while (rc == -EINTR);
if (rc < 0) {
error_setg_errno(errp, -rc, "Failed to connect socket %s",
saddr->path);
goto err;
}
return sock;
err:
close(sock);
return -1;
}
开发者ID:OSLL,项目名称:qemu-xtensa,代码行数:49,代码来源:qemu-sockets.c
示例15: net_socket_listen_init
static int net_socket_listen_init(VLANState *vlan,
const char *model,
const char *name,
const char *host_str)
{
NetSocketListenState *s;
int fd, val, ret;
struct sockaddr_in saddr;
if (parse_host_port(&saddr, host_str) < 0)
return -1;
s = g_malloc0(sizeof(NetSocketListenState));
fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
g_free(s);
return -1;
}
socket_set_nonblock(fd);
/* allow fast reuse */
val = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val));
ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret < 0) {
perror("bind");
g_free(s);
closesocket(fd);
return -1;
}
ret = listen(fd, 0);
if (ret < 0) {
perror("listen");
g_free(s);
closesocket(fd);
return -1;
}
s->vlan = vlan;
s->model = g_strdup(model);
s->name = name ? g_strdup(name) : NULL;
s->fd = fd;
qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
return 0;
}
开发者ID:MatzeB,项目名称:qemu-fixes,代码行数:47,代码来源:socket.c
示例16: net_socket_listen_init
static int net_socket_listen_init(NetClientState *peer,
const char *model,
const char *name,
const char *host_str)
{
NetClientState *nc;
NetSocketState *s;
struct sockaddr_in saddr;
int fd, val, ret;
if (parse_host_port(&saddr, host_str) < 0)
return -1;
fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
return -1;
}
socket_set_nonblock(fd);
/* allow fast reuse */
val = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val));
ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret < 0) {
perror("bind");
closesocket(fd);
return -1;
}
ret = listen(fd, 0);
if (ret < 0) {
perror("listen");
closesocket(fd);
return -1;
}
nc = qemu_new_net_client(&net_socket_info, peer, model, name);
s = DO_UPCAST(NetSocketState, nc, nc);
s->fd = -1;
s->listen_fd = fd;
s->nc.link_down = true;
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
return 0;
}
开发者ID:AlexWWW,项目名称:qemu-linaro-clone,代码行数:46,代码来源:socket.c
示例17: udp_listen
struct socket *
udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
u_int lport, int flags)
{
struct sockaddr_in addr;
struct socket *so;
socklen_t addrlen = sizeof(struct sockaddr_in);
so = socreate(slirp);
if (!so) {
return NULL;
}
so->s = qemu_socket(AF_INET,SOCK_DGRAM,0);
so->so_expire = curtime + SO_EXPIRE;
insque(so, &slirp->udb);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = haddr;
addr.sin_port = hport;
if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) {
udp_detach(so);
return NULL;
}
socket_set_fast_reuse(so->s);
getsockname(so->s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
if (addr.sin_addr.s_addr == 0 ||
addr.sin_addr.s_addr == loopback_addr.s_addr) {
so->so_faddr = slirp->vhost_addr;
} else {
so->so_faddr = addr.sin_addr;
}
so->so_lport = lport;
so->so_laddr.s_addr = laddr;
if (flags != SS_FACCEPTONCE)
so->so_expire = 0;
so->so_state &= SS_PERSISTENT_MASK;
so->so_state |= SS_ISFCONNECTED | flags;
return so;
}
开发者ID:AbnerChang,项目名称:RiscVQemuPcat,代码行数:44,代码来源:udp.c
示例18: connect_to_qemu
static int
connect_to_qemu(
const char *host,
const char *port
) {
struct addrinfo hints;
struct addrinfo *server;
int ret;
sock = qemu_socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
/* Error */
fprintf(stderr, "Error opening socket!\n");
return -1;
}
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0;
hints.ai_protocol = 0; /* Any protocol */
ret = getaddrinfo(host, port, &hints, &server);
if (ret != 0) {
/* Error */
fprintf(stderr, "getaddrinfo failed\n");
return -1;
}
if (connect(sock, server->ai_addr, server->ai_addrlen) < 0) {
/* Error */
fprintf(stderr, "Could not connect\n");
return -1;
}
if (verbose) {
printf("Connected (sizeof Header=%zd)!\n", sizeof(VSCMsgHeader));
}
return sock;
}
开发者ID:BernardXiong,项目名称:qemu,代码行数:40,代码来源:vscclient.c
示例19: unix_start_incoming_migration
int unix_start_incoming_migration(const char *path)
{
struct sockaddr_un un;
int sock;
DPRINTF("Attempting to start an incoming migration\n");
sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
fprintf(stderr, "Could not open unix socket: %s\n", strerror(errno));
return -EINVAL;
}
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
unlink(un.sun_path);
if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {
fprintf(stderr, "bind(unix:%s): %s\n", un.sun_path, strerror(errno));
goto err;
}
if (listen(sock, 1) < 0) {
fprintf(stderr, "listen(unix:%s): %s\n", un.sun_path, strerror(errno));
goto err;
}
qemu_set_fd_handler2(sock, NULL, unix_accept_incoming_migration, NULL,
(void *)(intptr_t)sock);
return 0;
err:
close(sock);
return -EINVAL;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:37,代码来源:migration-unix.c
示例20: inet_connect_addr
static int inet_connect_addr(struct addrinfo *addr, bool *in_progress,
ConnectState *connect_state, Error **errp)
{
int sock, rc;
*in_progress = false;
sock = qemu_socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (sock < 0) {
error_set_errno(errp, errno, QERR_SOCKET_CREATE_FAILED);
return -1;
}
qemu_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (connect_state != NULL) {
socket_set_nonblock(sock);
}
/* connect to peer */
do {
rc = 0;
if (connect(sock, addr->ai_addr, addr->ai_addrlen) < 0) {
rc = -socket_error();
}
} while (rc == -EINTR);
if (connect_state != NULL && QEMU_SOCKET_RC_INPROGRESS(rc)) {
connect_state->fd = sock;
qemu_set_fd_handler2(sock, NULL, NULL, wait_for_connect,
connect_state);
*in_progress = true;
} else if (rc < 0) {
error_set_errno(errp, errno, QERR_SOCKET_CONNECT_FAILED);
closesocket(sock);
return -1;
}
return sock;
}
开发者ID:evanchueng,项目名称:qemu,代码行数:36,代码来源:qemu-sockets.c
注:本文中的qemu_socket函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论