| 240 | } |
| 241 | |
| 242 | static int |
| 243 | cleanup_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 |
| 281 | static int |
no test coverage detected