Re: [PATCH 1/3] net/utils: Introduce inet_addr_is_any

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2018-02-06 at 11:44 +0200, Sagi Grimberg wrote:
> +bool inet_addr_is_any(struct sockaddr *addr)
> +{
> +	bool ret = false;
> +
> +	if (addr->sa_family == AF_INET6) {
> +		struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr;
> +		const struct sockaddr_in6 in6_any =
> +			{ .sin6_addr = IN6ADDR_ANY_INIT };
> +
> +		if (!memcmp(in6->sin6_addr.s6_addr,
> +			in6_any.sin6_addr.s6_addr, 16))
> +			ret = true;
> +	} else if (addr->sa_family == AF_INET) {
> +		struct sockaddr_in *in = (struct sockaddr_in *)addr;
> +
> +		if (in->sin_addr.s_addr == htonl(INADDR_ANY))
> +			ret = true;
> +	}
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(inet_addr_is_any);

Have you considered to eliminate the local variable 'ret' and to use multiple
return statements? Additionally, should this function trigger a warning if a
socket address is passed with an address family that is not supported by this
function? Should the in6_any local variable be declared static?

Thanks,

Bart.


��.n��������+%������w��{.n����j�����{ay�ʇڙ���f���h������_�(�階�ݢj"��������G����?���&��




[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux