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

Function cleanup_xaddrs_inet

lib/ff_route.c:242–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242static int
243cleanup_xaddrs_inet(struct rt_addrinfo *info)
244{
245 struct sockaddr_in *dst_sa, *mask_sa;
246
247 /* Check & fixup dst/netmask combination first */
248 dst_sa = (struct sockaddr_in *)info->rti_info[RTAX_DST];
249 mask_sa = (struct sockaddr_in *)info->rti_info[RTAX_NETMASK];
250
251 struct in_addr mask = {
252 .s_addr = mask_sa ? mask_sa->sin_addr.s_addr : INADDR_BROADCAST,
253 };
254 struct in_addr dst = {
255 .s_addr = htonl(ntohl(dst_sa->sin_addr.s_addr) & ntohl(mask.s_addr))
256 };
257
258 if (dst_sa->sin_len < sizeof(struct sockaddr_in)) {
259 printf("dst sin_len too small\n");
260 return (EINVAL);
261 }
262 if (mask_sa && mask_sa->sin_len < sizeof(struct sockaddr_in)) {
263 printf("mask sin_len too small\n");
264 return (EINVAL);
265 }
266 fill_sockaddr_inet(dst_sa, dst);
267
268 if (mask.s_addr != INADDR_BROADCAST)
269 fill_sockaddr_inet(mask_sa, mask);
270 else
271 remove_netmask(info);
272
273 /* Check gateway */
274 if (info->rti_info[RTAX_GATEWAY] != NULL)
275 return (cleanup_xaddrs_gateway(info));
276
277 return (0);
278}
279
280#ifdef INET6
281static int

Callers 1

cleanup_xaddrsFunction · 0.70

Calls 4

printfFunction · 0.70
fill_sockaddr_inetFunction · 0.70
remove_netmaskFunction · 0.70
cleanup_xaddrs_gatewayFunction · 0.70

Tested by

no test coverage detected