| 45 | } |
| 46 | |
| 47 | int |
| 48 | parse_ipv4_addr(const char *token, struct in_addr *ipv4, uint32_t *mask) |
| 49 | { |
| 50 | char ip_str[INET_ADDRSTRLEN] = {0}; |
| 51 | char *pch; |
| 52 | |
| 53 | pch = strchr(token, '/'); |
| 54 | if (pch != NULL) { |
| 55 | strlcpy(ip_str, token, |
| 56 | RTE_MIN((unsigned int long)(pch - token + 1), |
| 57 | sizeof(ip_str))); |
| 58 | pch += 1; |
| 59 | if (is_str_num(pch) != 0) |
| 60 | return -EINVAL; |
| 61 | if (mask) |
| 62 | *mask = atoi(pch); |
| 63 | } else { |
| 64 | strlcpy(ip_str, token, sizeof(ip_str)); |
| 65 | if (mask) |
| 66 | *mask = 0; |
| 67 | } |
| 68 | if (strlen(ip_str) >= INET_ADDRSTRLEN) |
| 69 | return -EINVAL; |
| 70 | |
| 71 | if (inet_pton(AF_INET, ip_str, ipv4) != 1) |
| 72 | return -EINVAL; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | int |
| 78 | parse_ipv6_addr(const char *token, struct in6_addr *ipv6, uint32_t *mask) |
no test coverage detected