@@ -297,20 +297,23 @@ mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_o
297
297
char plain_ip [IPADDR_STRLEN_MAX ];
298
298
char * split = strchr (input_str , '/' );
299
299
const char * addr_str = input_str ;
300
+ int to_copy = MIN (sizeof (plain_ip ) - 1 , addr_len );
301
+ memcpy (plain_ip , addr_str , to_copy );
300
302
if (split ) {
301
- int to_copy = sizeof (plain_ip ) - 1 ;
302
303
if (split - addr_str < to_copy ) {
303
304
to_copy = split - addr_str ;
304
305
}
305
- memcpy (plain_ip , addr_str , to_copy );
306
306
mp_obj_t prefix_obj = mp_parse_num_integer (split + 1 , strlen (split + 1 ), 10 , NULL );
307
307
prefix_bits = mp_obj_get_int (prefix_obj );
308
+ if (mp_obj_str_get_qstr (args [0 ]) == MP_QSTR_addr4 ) {
309
+ uint32_t mask = - (1u << (32 - prefix_bits ));
310
+ ip_addr_set_ip4_u32_val (netmask , ((mask & 0xFF ) << 24 ) | ((mask & 0xFF00 ) << 8 ) | ((mask >> 8 ) & 0xFF00 ) | ((mask >> 24 ) & 0xFF ));
311
+ }
312
+ } else {
313
+ netmask = netif -> netmask ;
308
314
}
309
- if (mp_obj_str_get_qstr (args [0 ]) == MP_QSTR_addr4 ) {
310
- uint32_t mask = - (1u << (32 - prefix_bits ));
311
- ip_addr_set_ip4_u32_val (netmask , ((mask & 0xFF ) << 24 ) | ((mask & 0xFF00 ) << 8 ) | ((mask >> 8 ) & 0xFF00 ) | ((mask >> 24 ) & 0xFF ));
312
- }
313
- if (!ipaddr_aton (addr_str , & ip_addr )) {
315
+ plain_ip [to_copy ] = '\0' ;
316
+ if (!ipaddr_aton (plain_ip , & ip_addr )) {
314
317
mp_raise_ValueError (MP_ERROR_TEXT ("invalid arguments" ));
315
318
}
316
319
if ((mp_obj_str_get_qstr (args [0 ]) == MP_QSTR_addr6 ) != IP_IS_V6 (& ip_addr )
0 commit comments