micropython icon indicating copy to clipboard operation
micropython copied to clipboard

IP_ADD_MEMBERSHIP has wrong value for UNIX port (macOS Monterey 12.2.1 with M1 chip)

Open tschudin opened this issue 3 years ago • 1 comments

Joining or leaving a multicast group (with setsockopt) returns an OS error, due to the wrong option values defined in socket.py

MP UNIX port:

% micropython                             
MicroPython v1.18 on 2022-01-16; darwin version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import socket
>>> socket.IP_ADD_MEMBERSHIP
35

macOS:

% grep IP_ADD_MEMBERSHIP /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/netinet/in.h 
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/netinet/in.h:#define IP_ADD_MEMBERSHIP       12   /* ip_mreq; add an IP group membership */

tschudin avatar Mar 27 '22 22:03 tschudin

It looks like you're using micropython-lib's socket.py, which extends unix's built-in usocket module, and adds this constant.

The fix would be one of:

  1. make micropython-lib detect the platform and select the correct value
  2. put this constant in usocket so it takes on the value defined by the system headers

Option (1) doesn't really scale to lots of different platforms and would be hard to get right.

dpgeorge avatar Mar 28 '22 07:03 dpgeorge

I was able to reproduce this issue on macOS Tahoe 26.0.1.

alectric-tr avatar Nov 22 '25 18:11 alectric-tr