Skip to content

Commit

Permalink
extmod/network_lwip.c: Allow using the CIDR notation for addr4.
Browse files Browse the repository at this point in the history
There was a little omisssion in the code.

Signed-off-by: robert-hh <robert@hammelrath.com>
  • Loading branch information
robert-hh authored and felixdoerre committed Mar 28, 2024
1 parent c8101c8 commit 08758f3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extmod/network_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,15 @@ mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_o
to_copy = split - addr_str;
}
memcpy(plain_ip, addr_str, to_copy);
plain_ip[to_copy] = '\0';
mp_obj_t prefix_obj = mp_parse_num_integer(split + 1, strlen(split + 1), 10, NULL);
prefix_bits = mp_obj_get_int(prefix_obj);
}
if (mp_obj_str_get_qstr(args[0]) == MP_QSTR_addr4) {
uint32_t mask = -(1u << (32 - prefix_bits));
ip_addr_set_ip4_u32_val(netmask, ((mask & 0xFF) << 24) | ((mask & 0xFF00) << 8) | ((mask >> 8) & 0xFF00) | ((mask >> 24) & 0xFF));
}
if (!ipaddr_aton(addr_str, &ip_addr)) {
if (!ipaddr_aton(plain_ip, &ip_addr)) {
mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments"));
}
if ((mp_obj_str_get_qstr(args[0]) == MP_QSTR_addr6) != IP_IS_V6(&ip_addr)
Expand Down

0 comments on commit 08758f3

Please sign in to comment.