Skip to content

Fix UDP multicast interface on MacOS #1940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion can/interfaces/udp_multicast/bus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import errno
import logging
import platform
import select
import socket
import struct
Expand All @@ -21,6 +22,8 @@
ioctl_supported = False
pass

# All ioctls aren't supported on MacOS.
is_macos = platform.system() == "Darwin"

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -275,6 +278,10 @@ def _create_socket(self, address_family: socket.AddressFamily) -> socket.socket:
# Allow multiple programs to access that address + port
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

# Option not supported on Windows.
if hasattr(socket, "SO_REUSEPORT"):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

# set how to receive timestamps
try:
sock.setsockopt(socket.SOL_SOCKET, SO_TIMESTAMPNS, 1)
Expand Down Expand Up @@ -401,7 +408,7 @@ def recv(
self.max_buffer
)

if ioctl_supported:
if ioctl_supported and not is_macos:
result_buffer = ioctl(
self._socket.fileno(),
SIOCGSTAMP,
Expand Down
Loading