Skip to content

Commit 0186249

Browse files
committed
net: utils: Allow user to pass NULL as mask_len
If user is not interested in the mask length, the value can be set to NULL so that it is not been returned to the caller. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 4a5a83e commit 0186249

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

subsys/net/ip/utils.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ const char *net_ipaddr_parse_mask(const char *str, size_t str_len,
988988
int parsed_mask_len = -1;
989989
bool ret = false;
990990

991-
if (str == NULL || str_len == 0 || addr == NULL || mask_len == NULL) {
991+
if (str == NULL || str_len == 0 || addr == NULL) {
992992
return NULL;
993993
}
994994

@@ -1019,7 +1019,10 @@ const char *net_ipaddr_parse_mask(const char *str, size_t str_len,
10191019
}
10201020

10211021
str_len = mask_ptr - str;
1022-
*mask_len = (uint8_t)parsed_mask_len;
1022+
1023+
if (mask_len != NULL) {
1024+
*mask_len = (uint8_t)parsed_mask_len;
1025+
}
10231026
}
10241027

10251028
#if defined(CONFIG_NET_IPV4) && defined(CONFIG_NET_IPV6)
@@ -1038,7 +1041,7 @@ const char *net_ipaddr_parse_mask(const char *str, size_t str_len,
10381041
return NULL;
10391042
}
10401043

1041-
if (parsed_mask_len < 0) {
1044+
if (parsed_mask_len < 0 && mask_len != NULL) {
10421045
if (addr->sa_family == AF_INET) {
10431046
*mask_len = 32;
10441047
} else if (addr->sa_family == AF_INET6) {

0 commit comments

Comments
 (0)