Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
ee045250
Commit
ee045250
authored
Jul 31, 2017
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
extmod/modlwip: Implement setsockopt(IP_ADD_MEMBERSHIP).
Allows to join multicast groups.
parent
55f33240
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
extmod/modlwip.c
+29
-3
29 additions, 3 deletions
extmod/modlwip.c
with
29 additions
and
3 deletions
extmod/modlwip.c
+
29
−
3
View file @
ee045250
...
...
@@ -45,6 +45,7 @@
//#include "lwip/raw.h"
#include
"lwip/dns.h"
#include
"lwip/tcp_impl.h"
#include
"lwip/igmp.h"
#if 0 // print debugging info
#define DEBUG_printf DEBUG_printf
...
...
@@ -52,6 +53,10 @@
#define DEBUG_printf(...) (void)0
#endif
// All socket options should be globally distinct,
// because we ignore option levels for efficiency.
#define IP_ADD_MEMBERSHIP 0x400
// For compatibilily with older lwIP versions.
#ifndef ip_set_option
#define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt))
...
...
@@ -1079,10 +1084,10 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
return
mp_const_none
;
}
// Integer options
mp_int_t
val
=
mp_obj_get_int
(
args
[
3
]);
switch
(
opt
)
{
case
SOF_REUSEADDR
:
// level: SOL_SOCKET
case
SOF_REUSEADDR
:
{
mp_int_t
val
=
mp_obj_get_int
(
args
[
3
]);
// Options are common for UDP and TCP pcb's.
if
(
val
)
{
ip_set_option
(
socket
->
pcb
.
tcp
,
SOF_REUSEADDR
);
...
...
@@ -1090,6 +1095,24 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
ip_reset_option
(
socket
->
pcb
.
tcp
,
SOF_REUSEADDR
);
}
break
;
}
// level: IPPROTO_IP
case
IP_ADD_MEMBERSHIP
:
{
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
args
[
3
],
&
bufinfo
,
MP_BUFFER_READ
);
if
(
bufinfo
.
len
!=
sizeof
(
ip_addr_t
)
*
2
)
{
mp_raise_ValueError
(
NULL
);
}
// POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
err_t
err
=
igmp_joingroup
((
ip_addr_t
*
)
bufinfo
.
buf
+
1
,
bufinfo
.
buf
);
if
(
err
!=
ERR_OK
)
{
mp_raise_OSError
(
error_lookup_table
[
-
err
]);
}
break
;
}
default:
printf
(
"Warning: lwip.setsockopt() not implemented
\n
"
);
}
...
...
@@ -1342,6 +1365,9 @@ STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
{
MP_ROM_QSTR
(
MP_QSTR_SOL_SOCKET
),
MP_ROM_INT
(
1
)
},
{
MP_ROM_QSTR
(
MP_QSTR_SO_REUSEADDR
),
MP_ROM_INT
(
SOF_REUSEADDR
)
},
{
MP_ROM_QSTR
(
MP_QSTR_IPPROTO_IP
),
MP_ROM_INT
(
0
)
},
{
MP_ROM_QSTR
(
MP_QSTR_IP_ADD_MEMBERSHIP
),
MP_ROM_INT
(
IP_ADD_MEMBERSHIP
)
},
};
STATIC
MP_DEFINE_CONST_DICT
(
mp_module_lwip_globals
,
mp_module_lwip_globals_table
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment