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

Issue with Adding Multicast Membership Sock Opt in python3 #1678

Closed
ZacBlanco opened this issue Feb 9, 2017 · 11 comments
Closed

Issue with Adding Multicast Membership Sock Opt in python3 #1678

ZacBlanco opened this issue Feb 9, 2017 · 11 comments

Comments

@ZacBlanco
Copy link

Please use the following bug reporting template to help produce actionable and reproducible issues. Please try to ensure that the reproduction is minimal so that the team can go through more bugs!

Python code

import socket
import struct

bsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
bsock.settimeout(0.1)
ttl = struct.pack('b', 1)
bsock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
# Borrowed from python examples
bsock.bind( ('', 9090) ) # Bind to port
group_bin = socket.inet_pton(socket.AF_INET, '224.1.1.1')
mreq = group_bin + struct.pack('=I', socket.INADDR_ANY)
print(group_bin)
print(mreq)
bsock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
bsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
bsock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 0)
  • A brief description

Attempt to create a socket for multicast receiving with python3 on bash on windows. When executing with python for windows installed on normal cmd.exe the script runs with no errors, socket seems to be created just fine.

However when attempting to set the sockopt for IP_ADD_MEMBERSHIP, the sockopt fails with invalid argument error.

  • Expected results

Script should finish and socket options should all be able to be set

Output from cmd.exe

C:\Users\zacbl\Desktop>python mcast.py
b'\xe0\x01\x01\x01'
b'\xe0\x01\x01\x01\x00\x00\x00\x00'
  • Actual results (with terminal output if applicable)

Output from bash.exe

zac@ZB-XPS13:/mnt/c/Users/zacbl/Desktop$ python3 mcast.py
b'\xe0\x01\x01\x01'
b'\xe0\x01\x01\x01\x00\x00\x00\x00'
Traceback (most recent call last):
  File "mcast.py", line 14, in <module>
    bsock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
OSError: [Errno 22] Invalid argument
  • Your Windows build number

15025

  • Steps / All commands required to reproduce the error from a brand new installation

Copy the python code above to a python file. Attempt to run with cmd.exe and bash.exe

  • Strace of the failing command
Traceback (most recent call last):
  File "mcast.py", line 14, in <module>
    bsock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
OSError: [Errno 22] Invalid argument
  • Required packages and commands to install

python 3.5.2 (Haven't attempted other versions)

See our contributing instructions for assistance.

@ZacBlanco
Copy link
Author

@jackchammons Any update on this?

@sunilmut
Copy link
Member

sunilmut commented Mar 2, 2017

Thanks @ZacBlanco for the report and apologize for the slow response. I can confirm that currently WSL does not support the IP_ADD_MEMBERSHIP & IP_MULTICAST_LOOP socket options. I have opened a task internally to track this. Unable to give an ETA at this time.

@ZacBlanco
Copy link
Author

No problem! Glad to hear it's on the list.
Appreciate the response

@sunilmut
Copy link
Member

sunilmut commented Mar 7, 2017

Just an update that both *IP(V6)_ADD_MEMBERSHIP & IP(V6)_MULTICAST_LOOP socket options are now *supported in the dev branch. The fix should make it to the release branch soon. Looking ahead, if there are other IP_MULTICAST_xxxxx socket options that are being exercised by your application, let us know and we can prioritize those as well.

*IP(V6)_ADD_MEMBERSHIP - The code does not support a non-zero value for the imr_ifindex field because of lack of underlying native support from Windows. If that is important to your application, we would like to know.

@ZacBlanco
Copy link
Author

Great! Thank you!

Hopefully I'll pick it up from windows update soon. I will report back if any issues persist.

@nernst
Copy link

nernst commented Apr 12, 2017

@sunilmut, will the inbound fix also address issues with the socket option IP_MULTICAST_IF? I've an app using multicast that fails with the following snippet from strace:

218 6550 socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
219 6550 bind(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
220 6550 getsockname(3, {sa_family=AF_INET, sin_port=htons(62168), sin_addr=inet_addr("0.0.0.0")}, [16]) = 0
221 6550 ioctl(3, SIOCGIFADDR, {ifr_name="192.168.1.159"}) = -1 ENODEV (No such device)
222 6550 setsockopt(3, SOL_IP, IP_MULTICAST_IF, [-1627281216], 4) = -1 ENOPROTOOPT (Protocol not available)

If the inbound fix does not address this, should I create a new issue?

@sunilmut
Copy link
Member

@nernst - Thanks for your post. IP_MULTICAST_IF is discussed in #990 and a fix for that is inbound (hopefully, next insider build).

Meanwhile, IP(V6)_ADD_MEMBERSHIP is fixed in insider build 16170

@nernst
Copy link

nernst commented Apr 12, 2017

Awesome, @sunilmut! Thanks for the prompt reply.

@sunilmut
Copy link
Member

This should be fixed in Insider build 16176.

@ZacBlanco
Copy link
Author

ZacBlanco commented Apr 19, 2017

@sunilmut I just received build 16176. I tried running the code in the original comment. Fortunately it advances past the third-to-last line (which is where it errored before)

However this time I'm getting another OSError invalid argument on the next line. The code still runs properly when done through the native windows python installation.

bsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
b'\xe0\x01\x01\x01'
b'\xe0\x01\x01\x01\x00\x00\x00\x00'
Traceback (most recent call last):
  File "mcast.py", line 15, in <module>
    bsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
OSError: [Errno 22] Invalid argument

Should I open another issue for this?

@sunilmut
Copy link
Member

@ZacBlanco Thanks for validating. Looks like you are running into #1419. Feel free to pile on there with you request. Unfortunately, Windows does not natively implement the SO_REUSEADDR socket option. And consequently we can't give you an ETA. We are working with the Windows networking team to get these options implemented. I will close this issue out.

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

No branches or pull requests

5 participants