Skip to content

Commit 6971992

Browse files
MrJake222dpgeorge
authored andcommitted
extmod/modlwip: Add support for leaving multicast groups.
1 parent 01514e8 commit 6971992

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

extmod/modlwip.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
// All socket options should be globally distinct,
6767
// because we ignore option levels for efficiency.
6868
#define IP_ADD_MEMBERSHIP 0x400
69+
#define IP_DROP_MEMBERSHIP 0x401
6970

7071
// For compatibilily with older lwIP versions.
7172
#ifndef ip_set_option
@@ -1376,15 +1377,21 @@ STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) {
13761377
}
13771378

13781379
// level: IPPROTO_IP
1379-
case IP_ADD_MEMBERSHIP: {
1380+
case IP_ADD_MEMBERSHIP:
1381+
case IP_DROP_MEMBERSHIP: {
13801382
mp_buffer_info_t bufinfo;
13811383
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
13821384
if (bufinfo.len != sizeof(ip_addr_t) * 2) {
13831385
mp_raise_ValueError(NULL);
13841386
}
13851387

13861388
// POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
1387-
err_t err = igmp_joingroup((ip_addr_t *)bufinfo.buf + 1, bufinfo.buf);
1389+
err_t err;
1390+
if (opt == IP_ADD_MEMBERSHIP) {
1391+
err = igmp_joingroup((ip_addr_t *)bufinfo.buf + 1, bufinfo.buf);
1392+
} else {
1393+
err = igmp_leavegroup((ip_addr_t *)bufinfo.buf + 1, bufinfo.buf);
1394+
}
13881395
if (err != ERR_OK) {
13891396
mp_raise_OSError(error_lookup_table[-err]);
13901397
}
@@ -1769,6 +1776,7 @@ STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
17691776

17701777
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_IP), MP_ROM_INT(0) },
17711778
{ MP_ROM_QSTR(MP_QSTR_IP_ADD_MEMBERSHIP), MP_ROM_INT(IP_ADD_MEMBERSHIP) },
1779+
{ MP_ROM_QSTR(MP_QSTR_IP_DROP_MEMBERSHIP), MP_ROM_INT(IP_DROP_MEMBERSHIP) },
17721780
};
17731781

17741782
STATIC MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy