From 9957fc7f1ed731e5228089ead3f350341cdd29c0 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 8 Mar 2013 19:58:32 +0100 Subject: MinGW: Replace setsockopt by qemu_setsocketopt Instead of adding missing type casts which are needed by MinGW for the 4th argument, the patch uses qemu_setsockopt which was invented for this purpose. Signed-off-by: Stefan Weil Signed-off-by: Stefan Hajnoczi --- bt-host.c | 2 +- gdbstub.c | 2 +- net/socket.c | 21 ++++++++++----------- slirp/misc.c | 4 ++-- slirp/socket.c | 4 ++-- slirp/tcp_subr.c | 8 ++++---- slirp/udp.c | 2 +- util/qemu-sockets.c | 10 +++++----- 8 files changed, 26 insertions(+), 27 deletions(-) diff --git a/bt-host.c b/bt-host.c index 2092754530..2da3c32204 100644 --- a/bt-host.c +++ b/bt-host.c @@ -171,7 +171,7 @@ struct HCIInfo *bt_host_hci(const char *id) hci_filter_all_ptypes(&flt); hci_filter_all_events(&flt); - if (setsockopt(fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { + if (qemu_setsockopt(fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { fprintf(stderr, "qemu: Can't set HCI filter on socket (%i)\n", errno); return 0; } diff --git a/gdbstub.c b/gdbstub.c index 43b7d4d00f..decb505600 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2887,7 +2887,7 @@ static int gdbserver_open(int port) /* allow fast reuse */ val = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); + qemu_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); sockaddr.sin_family = AF_INET; sockaddr.sin_port = htons(port); diff --git a/net/socket.c b/net/socket.c index 396dc8c0b1..d8b35a23cb 100644 --- a/net/socket.c +++ b/net/socket.c @@ -262,8 +262,7 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr } val = 1; - ret=setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, - (const char *)&val, sizeof(val)); + ret = qemu_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); if (ret < 0) { perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)"); goto fail; @@ -283,8 +282,8 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr imr.imr_interface.s_addr = htonl(INADDR_ANY); } - ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, - (const char *)&imr, sizeof(struct ip_mreq)); + ret = qemu_setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, + &imr, sizeof(struct ip_mreq)); if (ret < 0) { perror("setsockopt(IP_ADD_MEMBERSHIP)"); goto fail; @@ -292,8 +291,8 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr /* Force mcast msgs to loopback (eg. several QEMUs in same host */ loop = 1; - ret=setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, - (const char *)&loop, sizeof(loop)); + ret = qemu_setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, + &loop, sizeof(loop)); if (ret < 0) { perror("setsockopt(SOL_IP, IP_MULTICAST_LOOP)"); goto fail; @@ -301,8 +300,8 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr /* If a bind address is given, only send packets from that address */ if (localaddr != NULL) { - ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, - (const char *)localaddr, sizeof(*localaddr)); + ret = qemu_setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, + localaddr, sizeof(*localaddr)); if (ret < 0) { perror("setsockopt(IP_MULTICAST_IF)"); goto fail; @@ -521,7 +520,7 @@ static int net_socket_listen_init(NetClientState *peer, /* allow fast reuse */ val = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val)); + qemu_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)); if (ret < 0) { @@ -659,8 +658,8 @@ static int net_socket_udp_init(NetClientState *peer, return -1; } val = 1; - ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, - (const char *)&val, sizeof(val)); + ret = qemu_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, + &val, sizeof(val)); if (ret < 0) { perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)"); closesocket(fd); diff --git a/slirp/misc.c b/slirp/misc.c index d4df972d13..6b9c2c405b 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -212,9 +212,9 @@ fork_exec(struct socket *so, const char *ex, int do_pty) } while (so->s < 0 && errno == EINTR); closesocket(s); opt = 1; - setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)); + qemu_setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)); opt = 1; - setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int)); + qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); socket_set_nonblock(so->s); /* Append the telnet options now */ diff --git a/slirp/socket.c b/slirp/socket.c index bb639aed9c..8e8819cf30 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -627,7 +627,7 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, addr.sin_port = hport; if (((s = qemu_socket(AF_INET,SOCK_STREAM,0)) < 0) || - (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) || + (qemu_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)) < 0) || (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) || (listen(s,1) < 0)) { int tmperrno = errno; /* Don't clobber the real reason we failed */ @@ -642,7 +642,7 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, #endif return NULL; } - setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int)); + qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); getsockname(s,(struct sockaddr *)&addr,&addrlen); so->so_fport = addr.sin_port; diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 7b7ad60aea..84a6bb560b 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -338,9 +338,9 @@ int tcp_fconnect(struct socket *so) socket_set_nonblock(s); opt = 1; - setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(opt )); + qemu_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); opt = 1; - setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(opt )); + qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); addr.sin_family = AF_INET; if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) == @@ -427,9 +427,9 @@ void tcp_connect(struct socket *inso) } socket_set_nonblock(s); opt = 1; - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)); + qemu_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)); opt = 1; - setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int)); + qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); socket_set_nodelay(s); so->so_fport = addr.sin_port; diff --git a/slirp/udp.c b/slirp/udp.c index 9286cb7d31..b105f871f3 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -372,7 +372,7 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, udp_detach(so); return NULL; } - setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)); + qemu_setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)); getsockname(so->s,(struct sockaddr *)&addr,&addrlen); so->so_fport = addr.sin_port; diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 83e4e08e85..d70bbf03da 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -156,12 +156,12 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp) continue; } - setsockopt(slisten,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on)); + qemu_setsockopt(slisten, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); #ifdef IPV6_V6ONLY if (e->ai_family == PF_INET6) { /* listen on both ipv4 and ipv6 */ - setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&off, - sizeof(off)); + qemu_setsockopt(slisten, IPPROTO_IPV6, IPV6_V6ONLY, &off, + sizeof(off)); } #endif @@ -229,7 +229,7 @@ static void wait_for_connect(void *opaque) qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); do { - rc = getsockopt(s->fd, SOL_SOCKET, SO_ERROR, (void *) &val, &valsize); + rc = qemu_getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &val, &valsize); } while (rc == -1 && socket_error() == EINTR); /* update rc to contain error */ @@ -456,7 +456,7 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) error_set_errno(errp, errno, QERR_SOCKET_CREATE_FAILED); goto err; } - setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on)); + qemu_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); /* bind socket */ if (bind(sock, local->ai_addr, local->ai_addrlen) < 0) { -- cgit v1.2.3