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

Binding socket to specific network interface #64

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

JaewonAC
Copy link

Hello. Thanks a lot for wonderful library.

I'm using it in my Raspberry pi
My RPi's
eth0 is connected to company network
wlan0 is connected to A5100 sony mirrorless camera

I guess ControlPoint's socket is kinda stick to eth0.
So I modified ControlPoint to support binding socket socket to specific interface.

I hope this may helpful.

self.addr, self.port = addr, port
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(0.1)
# Set the socket to broadcast mode.
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
if interface:
sock.setsockopt(socket.SOL_SOCKET, 25, str(interface + '\0').encode('utf-8'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extremely minor nitpick: Everything else in this file looks like it uses 4 spaces for indentation, but you've only got 2 spaces here.

What does 25 mean in the setsockopt call?

Copy link
Owner

@Bloodevil Bloodevil Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use 4 spaces like other line.

is that 25 optname...?
socket.setsockopt(level, optname, value: int)
socket.setsockopt(level, optname, value: buffer)
socket.setsockopt(level, optname, None, optlen: int)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happened to dig into this myself the other day, 25 is indeed optname and at least in terms of Linux based sockets, it refers to SO_BINDTODEVICE as seen here: https://github.com/torvalds/linux/blob/169e77764adc041b1dacba84ea90516a895d43b2/include/uapi/asm-generic/socket.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants