/* Fill out sockaddr structure with values from abstract address object.  */
int nl_addr_fill_sockaddr(struct nl_addr *addr, struct sockaddr *sa, socklen_t *salen)
/* Fill out sockaddr structure with values from abstract address object.  */
int nl_addr_fill_sockaddr(struct nl_addr *addr, struct sockaddr *sa, socklen_t *salen)
{
	switch (addr->a_family) {
	case AF_INET: {
		struct sockaddr_in *sai = (struct sockaddr_in *) sa;
		if (*salen < sizeof(*sai))
			return -NLE_INVAL;
		sai->sin_family = addr->a_family;
		memcpy(&sai->sin_addr, addr->a_addr, 4);
		*salen = sizeof(*sai);
	}
		break;
	case AF_INET6: {
		struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) sa;
		if (*salen < sizeof(*sa6))
			return -NLE_INVAL;
		sa6->sin6_family = addr->a_family;
		memcpy(&sa6->sin6_addr, addr->a_addr, 16);
		*salen = sizeof(*sa6);
	}
		break;
	default:
		return -NLE_INVAL;
	}
	return 0;
}