aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-02-12 17:09:52 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-02-12 20:47:42 +0100
commitfdbfba8cbf04b587f9bab11b8e6a87afc38556e5 (patch)
tree37a867a670f31469c4fd0388601202aabca3f763
parent0b5e750bea635b167eb03d86c3d9a09bbd43bc06 (diff)
slirp: remove slirp_ prefix for socket wrappers
QEMU wraps the socket functions in os-win32.h, but in commit a9d8b3ec4385793815d71217857304, the header inclusion was dropped, breaking libslirp on Windows. There are already a few socket functions that are wrapped in libslirp, with "slirp_" prefix, but many of them are missing, and we are going to wrap the missing functions in a second patch. Using "slirp_" prefix avoids the conflict with socket function #define wrappers in QEMU os-win32.h, but they are quite intrusive. In the end, the functions should behave the same as original one, but with errno being set. To avoid the churn, and potential confusion, remove the "slirp_" prefix. A series of #undef is necessary until libslirp is made standalone to prevent the #define conflict with QEMU. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20190212160953.29051-2-marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
-rw-r--r--slirp/ip_icmp.c4
-rw-r--r--slirp/misc.c14
-rw-r--r--slirp/slirp.c2
-rw-r--r--slirp/socket.c14
-rw-r--r--slirp/tcp_subr.c10
-rw-r--r--slirp/udp.c2
-rw-r--r--slirp/util.h31
7 files changed, 43 insertions, 34 deletions
diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index ce79c0b051..120108f582 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -114,7 +114,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
void icmp_detach(struct socket *so)
{
so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
- slirp_closesocket(so->s);
+ closesocket(so->s);
sofree(so);
}
@@ -421,7 +421,7 @@ void icmp_receive(struct socket *so)
icp = mtod(m, struct icmp *);
id = icp->icmp_id;
- len = slirp_recv(so->s, icp, M_ROOM(m), 0);
+ len = recv(so->s, icp, M_ROOM(m), 0);
/*
* The behavior of reading SOCK_DGRAM+IPPROTO_ICMP sockets is inconsistent
* between host OSes. On Linux, only the ICMP header and payload is
diff --git a/slirp/misc.c b/slirp/misc.c
index 3f4cd852f8..d9fc586a24 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -98,16 +98,16 @@ slirp_socketpair_with_oob(int sv[2])
goto err;
}
- slirp_closesocket(s);
+ closesocket(s);
return 0;
err:
g_critical("slirp_socketpair(): %s", strerror(errno));
if (s >= 0) {
- slirp_closesocket(s);
+ closesocket(s);
}
if (sv[1] >= 0) {
- slirp_closesocket(sv[1]);
+ closesocket(sv[1]);
}
return -1;
}
@@ -211,16 +211,16 @@ fork_exec(struct socket *so, const char *ex)
if (err) {
g_critical("fork_exec: %s", err->message);
g_error_free(err);
- slirp_closesocket(sp[0]);
- slirp_closesocket(sp[1]);
+ closesocket(sp[0]);
+ closesocket(sp[1]);
return 0;
}
so->s = sp[0];
- slirp_closesocket(sp[1]);
+ closesocket(sp[1]);
slirp_socket_set_fast_reuse(so->s);
opt = 1;
- slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+ setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
slirp_set_nonblock(so->s);
so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
return 1;
diff --git a/slirp/slirp.c b/slirp/slirp.c
index a746c6fd86..55591430dc 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -961,7 +961,7 @@ int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
addr.sin_addr.s_addr == host_addr.s_addr &&
addr.sin_port == port) {
so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
- slirp_closesocket(so->s);
+ closesocket(so->s);
sofree(so);
return 0;
}
diff --git a/slirp/socket.c b/slirp/socket.c
index ce1d6ffa1d..4876ea3f31 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -185,7 +185,7 @@ soread(struct socket *so)
*/
sopreprbuf(so, iov, &n);
- nn = slirp_recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
+ nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
if (nn <= 0) {
if (nn < 0 && (errno == EINTR || errno == EAGAIN))
return 0;
@@ -201,7 +201,7 @@ soread(struct socket *so)
if (getpeername(so->s, paddr, &alen) < 0) {
err = errno;
} else {
- slirp_getsockopt(so->s, SOL_SOCKET, SO_ERROR,
+ getsockopt(so->s, SOL_SOCKET, SO_ERROR,
&err, &elen);
}
}
@@ -231,7 +231,7 @@ soread(struct socket *so)
*/
if (n == 2 && nn == iov[0].iov_len) {
int ret;
- ret = slirp_recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
+ ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
if (ret > 0)
nn += ret;
}
@@ -552,7 +552,7 @@ sorecvfrom(struct socket *so)
*/
len = M_FREEROOM(m);
/* if (so->so_fport != htons(53)) { */
- slirp_ioctlsocket(so->s, FIONREAD, &n);
+ ioctlsocket(so->s, FIONREAD, &n);
if (n > len) {
n = (m->m_data - m->m_dat) + m->m_len + n + 1;
@@ -724,7 +724,7 @@ tcp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, uint32_t laddr,
int tmperrno = errno; /* Don't clobber the real reason we failed */
if (s >= 0) {
- slirp_closesocket(s);
+ closesocket(s);
}
sofree(so);
/* Restore the real errno */
@@ -735,9 +735,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, uint32_t laddr,
#endif
return NULL;
}
- slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+ setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
opt = 1;
- slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int));
+ setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int));
getsockname(s,(struct sockaddr *)&addr,&addrlen);
so->so_ffamily = AF_INET;
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index cda94815f6..262a42d6c8 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -337,7 +337,7 @@ tcp_close(struct tcpcb *tp)
if (so == slirp->tcp_last_so)
slirp->tcp_last_so = &slirp->tcb;
so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
- slirp_closesocket(so->s);
+ closesocket(so->s);
sbfree(&so->so_rcv);
sbfree(&so->so_snd);
sofree(so);
@@ -416,9 +416,9 @@ int tcp_fconnect(struct socket *so, unsigned short af)
so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
slirp_socket_set_fast_reuse(s);
opt = 1;
- slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
+ setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
opt = 1;
- slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
+ setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
addr = so->fhost.ss;
DEBUG_CALL(" connect()ing");
@@ -489,7 +489,7 @@ void tcp_connect(struct socket *inso)
so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
slirp_socket_set_fast_reuse(s);
opt = 1;
- slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+ setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
slirp_socket_set_nodelay(s);
so->fhost.ss = addr;
@@ -499,7 +499,7 @@ void tcp_connect(struct socket *inso)
if (inso->so_state & SS_FACCEPTONCE) {
/* If we only accept once, close the accept() socket */
so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
- slirp_closesocket(so->s);
+ closesocket(so->s);
/* Don't select it yet, even though we have an FD */
/* if it's not FACCEPTONCE, it's already NOFDREF */
diff --git a/slirp/udp.c b/slirp/udp.c
index 29a31e9400..3d9a19b85a 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -292,7 +292,7 @@ void
udp_detach(struct socket *so)
{
so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
- slirp_closesocket(so->s);
+ closesocket(so->s);
sofree(so);
}
diff --git a/slirp/util.h b/slirp/util.h
index 4963747aef..685b5af099 100644
--- a/slirp/util.h
+++ b/slirp/util.h
@@ -81,21 +81,30 @@ struct iovec {
#define ETH_P_NCSI (0x88f8)
#define ETH_P_UNKNOWN (0xffff)
+/* FIXME: remove me when made standalone */
#ifdef _WIN32
+#undef closesocket
+#undef getsockopt
+#undef ioctlsocket
+#undef recv
+#undef setsockopt
+#endif
+
+#ifdef _WIN32
+#define closesocket slirp_closesocket
int slirp_closesocket(int fd);
+#define ioctlsocket slirp_ioctlsocket
int slirp_ioctlsocket(int fd, int req, void *val);
-int inet_aton(const char *cp, struct in_addr *ia);
-#define slirp_getsockopt(sockfd, level, optname, optval, optlen) \
+#define getsockopt(sockfd, level, optname, optval, optlen) \
getsockopt(sockfd, level, optname, (void *)optval, optlen)
-#define slirp_setsockopt(sockfd, level, optname, optval, optlen) \
+#define setsockopt(sockfd, level, optname, optval, optlen) \
setsockopt(sockfd, level, optname, (const void *)optval, optlen)
-#define slirp_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
+#define recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
+
+int inet_aton(const char *cp, struct in_addr *ia);
#else
-#define slirp_setsockopt setsockopt
-#define slirp_getsockopt getsockopt
-#define slirp_recv recv
-#define slirp_closesocket close
-#define slirp_ioctlsocket ioctl
+#define closesocket(s) close(s)
+#define ioctlsocket(s, r, v) ioctl(s, r, v)
#endif
int slirp_socket(int domain, int type, int protocol);
@@ -104,14 +113,14 @@ void slirp_set_nonblock(int fd);
static inline int slirp_socket_set_nodelay(int fd)
{
int v = 1;
- return slirp_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v));
+ return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v));
}
static inline int slirp_socket_set_fast_reuse(int fd)
{
#ifndef _WIN32
int v = 1;
- return slirp_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v));
+ return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v));
#else
/* Enabling the reuse of an endpoint that was used by a socket still in
* TIME_WAIT state is usually performed by setting SO_REUSEADDR. On Windows