[PATCH] util: recognize all of 127.0.0.0/8 as loopback addresses
Jeremy Allison
jra at samba.org
Mon Nov 14 23:49:34 UTC 2016
On Fri, Nov 11, 2016 at 01:15:39PM +0100, Björn Jacke wrote:
> sorry that was a previous non-compiling patch, here's the right one
OK, Sorry if I'm being dumb but I don't understand this change.
Can you explain the use of the: 0x01000000 constant ?
Also, shouldn't these be set via htonl(), not directly
assigned ?
RFC1122 says:
(g) { 127, <any> }
Internal host loopback address. Addresses of this form
MUST NOT appear outside a host.
So how does this new code check that the net
is 127.x.x.x ?
Jeremy.
> From 90b3d08d794bed01850c0f950689cba204b3db4d Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= <bj at sernet.de>
> Date: Fri, 11 Nov 2016 11:47:25 +0100
> Subject: [PATCH] util: recognize all of 127.0.0.0/8 as loopback addresses
>
> BUG: https://bugzilla.samba.org/show_bug.cgi?id=12422
> ---
> lib/util/util_net.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lib/util/util_net.c b/lib/util/util_net.c
> index cb238ad..7fd941c 100644
> --- a/lib/util/util_net.c
> +++ b/lib/util/util_net.c
> @@ -595,13 +595,16 @@ bool is_broadcast_addr(const struct sockaddr *pss)
> }
>
> /**
> - * Check if an IPv7 is 127.0.0.1
> + * Check if an IPv4 address is loopback (127.0.0.1/8, see RFC 1122)
> */
> bool is_loopback_ip_v4(struct in_addr ip)
> {
> - struct in_addr a;
> - a.s_addr = htonl(INADDR_LOOPBACK);
> - return(ip.s_addr == a.s_addr);
> + struct in_addr lo_addr;
> + struct in_addr mask_addr;
> +
> + lo_addr.s_addr = 0x01000000;
> + mask_addr.s_addr = 0xff000000;
> + return same_net_v4(ip, lo_addr, mask_addr);
> }
>
> /**
> --
> 2.7.4
>
More information about the samba-technical
mailing list