Skip to content
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

Fix: UDP server bind issue after PR#161 #164

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Changes from 2 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
21 changes: 17 additions & 4 deletions iso15118/secc/transport/udp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import socket
import struct
from asyncio import DatagramTransport
from sys import platform
from typing import Optional, Tuple

from iso15118.shared.messages.v2gtp import V2GTPMessage
Expand Down Expand Up @@ -60,10 +61,22 @@ async def __init__.
# Allows address to be reused
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tropxy marked this conversation as resolved.
Show resolved Hide resolved

# Bind the socket to the predefined port for receiving
# UDP packets (SDP requests)
full_ipv6_address = await get_link_local_full_addr(SDP_SERVER_PORT, iface)
sock.bind(full_ipv6_address)
# Bind the socket to the predefined port on specified interface for receiving
# UDP packets (SDP requests). This is done differently on Mac and Linux.
# Reference:
# https://djangocas.dev/blog/linux/linux-SO_BINDTODEVICE-and-mac-IP_BOUND_IF-to-bind-socket-to-a-network-interface/ # noqa
# https://linux.die.net/man/7/socket
# https://stackoverflow.com/questions/20616029/os-x-equivalent-of-so-bindtodevice # noqa
if platform == "darwin":
full_ipv6_address = await get_link_local_full_addr(SDP_SERVER_PORT, iface)
sock.bind(full_ipv6_address)
else:
sock.setsockopt(
socket.SOL_SOCKET,
socket.SO_BINDTODEVICE,
(iface + "\0").encode("ascii"),
)
sock.bind("", SDP_SERVER_PORT)

# After the regular socket is created and bound to a port, it can be
# added to the multicast group by using setsockopt() to set the
Expand Down