Binding socket to specific network interface#64
Binding socket to specific network interface#64JaewonAC wants to merge 1 commit intoBloodevil:developfrom
Conversation
| # 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')) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
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.