MCPcopy Create free account
hub / github.com/F-Stack/f-stack / parse_ipv4_addr

Function parse_ipv4_addr

dpdk/examples/ipsec-secgw/parser.c:47–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47int
48parse_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
77int
78parse_ipv6_addr(const char *token, struct in6_addr *ipv6, uint32_t *mask)

Callers 4

ipv4_addr_cpyFunction · 0.70
parse_sa_tokensFunction · 0.70
parse_sp4_tokensFunction · 0.70
parse_rt_tokensFunction · 0.70

Calls 4

strchrFunction · 0.85
is_str_numFunction · 0.85
inet_ptonFunction · 0.85
strlcpyFunction · 0.50

Tested by

no test coverage detected