From: Vitaly Cheptsov <cheptsov@ispras.ru>
To: qemu-devel@nongnu.org
Cc: "Vitaly Cheptsov" <cheptsov@ispras.ru>,
"Jason Wang" <jasowang@redhat.com>,
"Daniel P . Berrange" <berrange@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH v2] net: fix multicast support with BSD (macOS) socket implementations
Date: Wed, 18 May 2022 10:39:45 +0300 [thread overview]
Message-ID: <20220518073945.24787-1-cheptsov@ispras.ru> (raw)
Cc: Jason Wang <jasowang@redhat.com>
Cc: Daniel P. Berrange <berrange@redhat.com>
Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Vitaly Cheptsov <cheptsov@ispras.ru>
---
net/socket.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/net/socket.c b/net/socket.c
index bfd8596250..583f788a22 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -239,6 +239,22 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr,
return -1;
}
+#ifdef __APPLE__
+ val = 1;
+ ret = qemu_setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val));
+ if (ret < 0) {
+ error_setg_errno(errp, errno,
+ "can't set socket option SO_REUSEPORT");
+ goto fail;
+ }
+
+ struct sockaddr_in bindaddr;
+ memset(&bindaddr, 0, sizeof(bindaddr));
+ bindaddr.sin_family = AF_INET;
+ bindaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ bindaddr.sin_port = mcastaddr->sin_port;
+ ret = bind(fd, (struct sockaddr *)&bindaddr, sizeof(bindaddr));
+#else
/* Allow multiple sockets to bind the same multicast ip and port by setting
* SO_REUSEADDR. This is the only situation where SO_REUSEADDR should be set
* on windows. Use socket_set_fast_reuse otherwise as it sets SO_REUSEADDR
@@ -253,6 +269,8 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr,
}
ret = bind(fd, (struct sockaddr *)mcastaddr, sizeof(*mcastaddr));
+#endif
+
if (ret < 0) {
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
inet_ntoa(mcastaddr->sin_addr));
--
2.32.1 (Apple Git-133)
next reply other threads:[~2022-05-18 7:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 7:39 Vitaly Cheptsov [this message]
2022-05-18 7:51 ` [PATCH v2] net: fix multicast support with BSD (macOS) socket implementations Vitaly Cheptsov
2022-05-31 7:01 ` Jason Wang
2022-05-31 11:28 ` Vitaly Cheptsov
2022-06-01 2:43 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220518073945.24787-1-cheptsov@ispras.ru \
--to=cheptsov@ispras.ru \
--cc=berrange@redhat.com \
--cc=f4bug@amsat.org \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).