Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Nov 2001 16:03:18 -0500 (EST)
From:      Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To:        Ian West <ian@niw.com.au>
Cc:        freebsd-net@FreeBSD.ORG
Subject:   Re: Results from RTM_GET on route socket ?
Message-ID:  <200111062103.fA6L3II11868@khavrinen.lcs.mit.edu>
In-Reply-To: <20011106115119.L34308@rose.niw.com.au>
References:  <20011106075451.E34308@rose.niw.com.au> <200111052156.fA5Lutl92439@khavrinen.lcs.mit.edu> <20011106115119.L34308@rose.niw.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
<<On Tue, 6 Nov 2001 11:51:20 +1030, Ian West <ian@niw.com.au> said:

> Thanks for that, makes sense :-) More questions though, the following is
> a response to a request for 192.168.20.1. The response is a general
> subnet route, how should I interpret the mask field ?  (It is actually
> class C) I can't find a reference to a AF_ type for -1 or 255, but the
> field is a bit small for a sockaddr_in.

Netmasks are literally that: bit masks which indicate which bits
(after the length) in an address are significant.  All of the bits in
the address family are significant, so the corresponding bits in the
netmask are all ones.  Your code must pad the mask out with an
appropriate quantity of zero bits for the type of address being
masked.  Generally speaking, if `cp' points to the beginning of the
mask, and `sa' points to the address which was just read:

	struct sockaddr *mask;
	socklen_t len = max(sa->sa_len, *cp);
	mask = malloc(len);
	assert(mask);
	memset(mask, '\0', len);
	memcpy(mask, cp, *cp);
	mask->sa_len = len;
	mask->sa_family = sa->sa_family;

...is the most general way, although a particular address family might
have more specific requirements.

-GAWollman


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200111062103.fA6L3II11868>