| 1414 | |
| 1415 | #ifdef INET |
| 1416 | static int |
| 1417 | cleanup_xaddrs_inet(struct rt_addrinfo *info) |
| 1418 | { |
| 1419 | struct sockaddr_in *dst_sa, *mask_sa; |
| 1420 | |
| 1421 | /* Check & fixup dst/netmask combination first */ |
| 1422 | dst_sa = (struct sockaddr_in *)info->rti_info[RTAX_DST]; |
| 1423 | mask_sa = (struct sockaddr_in *)info->rti_info[RTAX_NETMASK]; |
| 1424 | |
| 1425 | struct in_addr mask = { |
| 1426 | .s_addr = mask_sa ? mask_sa->sin_addr.s_addr : INADDR_BROADCAST, |
| 1427 | }; |
| 1428 | struct in_addr dst = { |
| 1429 | .s_addr = htonl(ntohl(dst_sa->sin_addr.s_addr) & ntohl(mask.s_addr)) |
| 1430 | }; |
| 1431 | |
| 1432 | if (dst_sa->sin_len < sizeof(struct sockaddr_in)) { |
| 1433 | printf("dst sin_len too small\n"); |
| 1434 | return (EINVAL); |
| 1435 | } |
| 1436 | if (mask_sa && mask_sa->sin_len < sizeof(struct sockaddr_in)) { |
| 1437 | printf("mask sin_len too small\n"); |
| 1438 | return (EINVAL); |
| 1439 | } |
| 1440 | fill_sockaddr_inet(dst_sa, dst); |
| 1441 | |
| 1442 | if (mask.s_addr != INADDR_BROADCAST) |
| 1443 | fill_sockaddr_inet(mask_sa, mask); |
| 1444 | else |
| 1445 | remove_netmask(info); |
| 1446 | |
| 1447 | /* Check gateway */ |
| 1448 | if (info->rti_info[RTAX_GATEWAY] != NULL) |
| 1449 | return (cleanup_xaddrs_gateway(info)); |
| 1450 | |
| 1451 | return (0); |
| 1452 | } |
| 1453 | #endif |
| 1454 | |
| 1455 | #ifdef INET6 |
no test coverage detected